Revert "HADOOP-13073 RawLocalFileSystem does not react on changing umask. Contributed by Andras Bokor"
This reverts commit 45af585e7a
.
This commit is contained in:
parent
45af585e7a
commit
be26c1b9b0
@ -64,6 +64,8 @@ public class RawLocalFileSystem extends FileSystem {
|
|||||||
// Temporary workaround for HADOOP-9652.
|
// Temporary workaround for HADOOP-9652.
|
||||||
private static boolean useDeprecatedFileStatus = true;
|
private static boolean useDeprecatedFileStatus = true;
|
||||||
|
|
||||||
|
private FsPermission umask;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static void useStatIfAvailable() {
|
public static void useStatIfAvailable() {
|
||||||
useDeprecatedFileStatus = !Stat.isAvailable();
|
useDeprecatedFileStatus = !Stat.isAvailable();
|
||||||
@ -97,6 +99,7 @@ public File pathToFile(Path path) {
|
|||||||
public void initialize(URI uri, Configuration conf) throws IOException {
|
public void initialize(URI uri, Configuration conf) throws IOException {
|
||||||
super.initialize(uri, conf);
|
super.initialize(uri, conf);
|
||||||
setConf(conf);
|
setConf(conf);
|
||||||
|
umask = FsPermission.getUMask(conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************
|
/*******************************************************
|
||||||
@ -230,7 +233,7 @@ private LocalFSFileOutputStream(Path f, boolean append,
|
|||||||
if (permission == null) {
|
if (permission == null) {
|
||||||
this.fos = new FileOutputStream(file, append);
|
this.fos = new FileOutputStream(file, append);
|
||||||
} else {
|
} else {
|
||||||
permission = permission.applyUMask(FsPermission.getUMask(getConf()));
|
permission = permission.applyUMask(umask);
|
||||||
if (Shell.WINDOWS && NativeIO.isAvailable()) {
|
if (Shell.WINDOWS && NativeIO.isAvailable()) {
|
||||||
this.fos = NativeIO.Windows.createFileOutputStreamWithMode(file,
|
this.fos = NativeIO.Windows.createFileOutputStreamWithMode(file,
|
||||||
append, permission.toShort());
|
append, permission.toShort());
|
||||||
@ -507,7 +510,7 @@ protected boolean mkOneDirWithMode(Path p, File p2f, FsPermission permission)
|
|||||||
if (permission == null) {
|
if (permission == null) {
|
||||||
permission = FsPermission.getDirDefault();
|
permission = FsPermission.getDirDefault();
|
||||||
}
|
}
|
||||||
permission = permission.applyUMask(FsPermission.getUMask(getConf()));
|
permission = permission.applyUMask(umask);
|
||||||
if (Shell.WINDOWS && NativeIO.isAvailable()) {
|
if (Shell.WINDOWS && NativeIO.isAvailable()) {
|
||||||
try {
|
try {
|
||||||
NativeIO.Windows.createDirectoryWithMode(p2f, permission.toShort());
|
NativeIO.Windows.createDirectoryWithMode(p2f, permission.toShort());
|
||||||
|
@ -29,10 +29,6 @@
|
|||||||
|
|
||||||
import junit.framework.*;
|
import junit.framework.*;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
|
||||||
import static org.hamcrest.CoreMatchers.not;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class tests the local file system via the FileSystem abstraction.
|
* This class tests the local file system via the FileSystem abstraction.
|
||||||
*/
|
*/
|
||||||
@ -71,9 +67,9 @@ public void testLocalFSDirsetPermission() throws IOException {
|
|||||||
System.out.println("Cannot run test for Windows");
|
System.out.println("Cannot run test for Windows");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LocalFileSystem localfs = FileSystem.getLocal(new Configuration());
|
Configuration conf = new Configuration();
|
||||||
Configuration conf = localfs.getConf();
|
|
||||||
conf.set(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY, "044");
|
conf.set(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY, "044");
|
||||||
|
LocalFileSystem localfs = FileSystem.getLocal(conf);
|
||||||
Path dir = new Path(TEST_PATH_PREFIX + "dir");
|
Path dir = new Path(TEST_PATH_PREFIX + "dir");
|
||||||
localfs.mkdirs(dir);
|
localfs.mkdirs(dir);
|
||||||
try {
|
try {
|
||||||
@ -241,54 +237,6 @@ public void testLocalFSsetOwner() throws IOException {
|
|||||||
finally {cleanup(localfs, f);}
|
finally {cleanup(localfs, f);}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Steps:
|
|
||||||
* 1. Create a directory with default permissions: 777 with umask 022
|
|
||||||
* 2. Check the directory has good permissions: 755
|
|
||||||
* 3. Set the umask to 062.
|
|
||||||
* 4. Create a new directory with default permissions.
|
|
||||||
* 5. For this directory we expect 715 as permission not 755
|
|
||||||
* @throws Exception we can throw away all the exception.
|
|
||||||
*/
|
|
||||||
public void testSetUmaskInRealTime() throws Exception {
|
|
||||||
if (Path.WINDOWS) {
|
|
||||||
System.out.println("Cannot run test for Windows");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalFileSystem localfs = FileSystem.getLocal(new Configuration());
|
|
||||||
Configuration conf = localfs.getConf();
|
|
||||||
conf.set(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY, "022");
|
|
||||||
System.out.println(
|
|
||||||
conf.get(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY));
|
|
||||||
Path dir = new Path(TEST_PATH_PREFIX + "dir");
|
|
||||||
Path dir2 = new Path(TEST_PATH_PREFIX + "dir2");
|
|
||||||
try {
|
|
||||||
assertTrue(localfs.mkdirs(dir));
|
|
||||||
FsPermission initialPermission = getPermission(localfs, dir);
|
|
||||||
assertEquals(
|
|
||||||
"With umask 022 permission should be 755 since the default " +
|
|
||||||
"permission is 777", new FsPermission("755"), initialPermission);
|
|
||||||
|
|
||||||
// Modify umask and create a new directory
|
|
||||||
// and check if new umask is applied
|
|
||||||
conf.set(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY, "062");
|
|
||||||
assertTrue(localfs.mkdirs(dir2));
|
|
||||||
FsPermission finalPermission = localfs.getFileStatus(dir2)
|
|
||||||
.getPermission();
|
|
||||||
assertThat("With umask 062 permission should not be 755 since the " +
|
|
||||||
"default permission is 777", new FsPermission("755"),
|
|
||||||
is(not(finalPermission)));
|
|
||||||
assertEquals(
|
|
||||||
"With umask 062 we expect 715 since the default permission is 777",
|
|
||||||
new FsPermission("715"), finalPermission);
|
|
||||||
} finally {
|
|
||||||
conf.set(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY, "022");
|
|
||||||
cleanup(localfs, dir);
|
|
||||||
cleanup(localfs, dir2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static List<String> getGroups() throws IOException {
|
static List<String> getGroups() throws IOException {
|
||||||
List<String> a = new ArrayList<String>();
|
List<String> a = new ArrayList<String>();
|
||||||
String s = Shell.execCommand(Shell.getGroupsCommand());
|
String s = Shell.execCommand(Shell.getGroupsCommand());
|
||||||
|
Loading…
Reference in New Issue
Block a user