Michal
Michal

Reputation: 1321

Hadoop FileSystem.mkdirs(path, permission) ignores the permission

I am trying to create directory in hdfs programatically. I need the directory to be writable for all users. So I try to pass the perissions to mkdirs like this:

Path dir = new Path("/tmp/mkdir-test");    
fileSystem.mkdirs(dir, new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL));

however, the result is that I get directory with drwxr-xr-x permission. This does not seem to be some overall permission issue, because if I do set them explicitly at next line:

// For some reason the initial permissions are ignored
fileSystem.setPermission(dir, new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL));

the directory ends up properly with drwxrwxrwx as intended.

Why are the permissions passed to mkdirs not honored?

Upvotes: 1

Views: 878

Answers (1)

Michal
Michal

Reputation: 1321

Despite the javadoc of the actual method not mentioning anything, there is static method FileSystem.mkdirs(FileSystem, Path, FsPermission) which provides some explanation:

Create a directory with the provided permission. The permission of the directory is set to be the provided permission as in setPermission, not permission&~umask.

So it turns out that standard mkdirs ANDs the given permission with umask.

The static utility method is implemented as combination of mkdirs and setPermission

Upvotes: 3

Related Questions