HDS-3491. HttpFs does not set permissions correctly (tucu)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1355556 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Alejandro Abdelnur 2012-06-29 20:59:11 +00:00
parent cd9ce99740
commit 34605c9594
7 changed files with 34 additions and 44 deletions

View File

@ -86,7 +86,7 @@ public class HttpFSFileSystem extends FileSystem {
public static final String ACCESS_TIME_PARAM = "accesstime"; public static final String ACCESS_TIME_PARAM = "accesstime";
public static final String RENEWER_PARAM = "renewer"; public static final String RENEWER_PARAM = "renewer";
public static final String DEFAULT_PERMISSION = "default"; public static final Short DEFAULT_PERMISSION = 0755;
public static final String RENAME_JSON = "boolean"; public static final String RENAME_JSON = "boolean";
@ -438,7 +438,7 @@ public class HttpFSFileSystem extends FileSystem {
* @return the Unix string symbolic reprentation. * @return the Unix string symbolic reprentation.
*/ */
public static String permissionToString(FsPermission p) { public static String permissionToString(FsPermission p) {
return (p == null) ? DEFAULT_PERMISSION : Integer.toString(p.toShort(), 8); return Integer.toString((p == null) ? DEFAULT_PERMISSION : p.toShort(), 8);
} }
/* /*

View File

@ -42,25 +42,6 @@ import java.util.Map;
*/ */
public class FSOperations { public class FSOperations {
/**
* Converts a Unix permission octal
* (i.e. 655 or 1777) into a FileSystemAccess permission.
*
* @param str Unix permission symbolic representation.
*
* @return the FileSystemAccess permission. If the given string was
* 'default', it returns <code>FsPermission.getDefault()</code>.
*/
private static FsPermission getPermission(String str) {
FsPermission permission;
if (str.equals(HttpFSFileSystem.DEFAULT_PERMISSION)) {
permission = FsPermission.getDefault();
} else {
permission = new FsPermission(Short.parseShort(str, 8));
}
return permission;
}
@SuppressWarnings({"unchecked", "deprecation"}) @SuppressWarnings({"unchecked", "deprecation"})
private static Map fileStatusToJSONRaw(FileStatus status, boolean emptyPathSuffix) { private static Map fileStatusToJSONRaw(FileStatus status, boolean emptyPathSuffix) {
Map json = new LinkedHashMap(); Map json = new LinkedHashMap();
@ -252,7 +233,7 @@ public class FSOperations {
public static class FSCreate implements FileSystemAccess.FileSystemExecutor<Void> { public static class FSCreate implements FileSystemAccess.FileSystemExecutor<Void> {
private InputStream is; private InputStream is;
private Path path; private Path path;
private String permission; private short permission;
private boolean override; private boolean override;
private short replication; private short replication;
private long blockSize; private long blockSize;
@ -267,7 +248,8 @@ public class FSOperations {
* @param repl the replication factor for the file. * @param repl the replication factor for the file.
* @param blockSize the block size for the file. * @param blockSize the block size for the file.
*/ */
public FSCreate(InputStream is, String path, String perm, boolean override, short repl, long blockSize) { public FSCreate(InputStream is, String path, short perm, boolean override,
short repl, long blockSize) {
this.is = is; this.is = is;
this.path = new Path(path); this.path = new Path(path);
this.permission = perm; this.permission = perm;
@ -293,7 +275,7 @@ public class FSOperations {
if (blockSize == -1) { if (blockSize == -1) {
blockSize = fs.getDefaultBlockSize(path); blockSize = fs.getDefaultBlockSize(path);
} }
FsPermission fsPermission = getPermission(permission); FsPermission fsPermission = new FsPermission(permission);
int bufferSize = fs.getConf().getInt("httpfs.buffer.size", 4096); int bufferSize = fs.getConf().getInt("httpfs.buffer.size", 4096);
OutputStream os = fs.create(path, fsPermission, override, bufferSize, replication, blockSize, null); OutputStream os = fs.create(path, fsPermission, override, bufferSize, replication, blockSize, null);
IOUtils.copyBytes(is, os, bufferSize, true); IOUtils.copyBytes(is, os, bufferSize, true);
@ -477,7 +459,7 @@ public class FSOperations {
public static class FSMkdirs implements FileSystemAccess.FileSystemExecutor<JSONObject> { public static class FSMkdirs implements FileSystemAccess.FileSystemExecutor<JSONObject> {
private Path path; private Path path;
private String permission; private short permission;
/** /**
* Creates a mkdirs executor. * Creates a mkdirs executor.
@ -485,7 +467,7 @@ public class FSOperations {
* @param path directory path to create. * @param path directory path to create.
* @param permission permission to use. * @param permission permission to use.
*/ */
public FSMkdirs(String path, String permission) { public FSMkdirs(String path, short permission) {
this.path = new Path(path); this.path = new Path(path);
this.permission = permission; this.permission = permission;
} }
@ -502,7 +484,7 @@ public class FSOperations {
*/ */
@Override @Override
public JSONObject execute(FileSystem fs) throws IOException { public JSONObject execute(FileSystem fs) throws IOException {
FsPermission fsPermission = getPermission(permission); FsPermission fsPermission = new FsPermission(permission);
boolean mkdirs = fs.mkdirs(path, fsPermission); boolean mkdirs = fs.mkdirs(path, fsPermission);
return toJSON(HttpFSFileSystem.MKDIRS_JSON, mkdirs); return toJSON(HttpFSFileSystem.MKDIRS_JSON, mkdirs);
} }
@ -621,7 +603,7 @@ public class FSOperations {
public static class FSSetPermission implements FileSystemAccess.FileSystemExecutor<Void> { public static class FSSetPermission implements FileSystemAccess.FileSystemExecutor<Void> {
private Path path; private Path path;
private String permission; private short permission;
/** /**
* Creates a set-permission executor. * Creates a set-permission executor.
@ -629,7 +611,7 @@ public class FSOperations {
* @param path path to set the permission. * @param path path to set the permission.
* @param permission permission to set. * @param permission permission to set.
*/ */
public FSSetPermission(String path, String permission) { public FSSetPermission(String path, short permission) {
this.path = new Path(path); this.path = new Path(path);
this.permission = permission; this.permission = permission;
} }
@ -645,7 +627,7 @@ public class FSOperations {
*/ */
@Override @Override
public Void execute(FileSystem fs) throws IOException { public Void execute(FileSystem fs) throws IOException {
FsPermission fsPermission = getPermission(permission); FsPermission fsPermission = new FsPermission(permission);
fs.setPermission(path, fsPermission); fs.setPermission(path, fsPermission);
return null; return null;
} }

View File

@ -337,25 +337,19 @@ public class HttpFSParametersProvider extends ParametersProvider {
/** /**
* Class for permission parameter. * Class for permission parameter.
*/ */
public static class PermissionParam extends StringParam { public static class PermissionParam extends ShortParam {
/** /**
* Parameter name. * Parameter name.
*/ */
public static final String NAME = HttpFSFileSystem.PERMISSION_PARAM; public static final String NAME = HttpFSFileSystem.PERMISSION_PARAM;
/**
* Symbolic Unix permissions regular expression pattern.
*/
private static final Pattern PERMISSION_PATTERN =
Pattern.compile(HttpFSFileSystem.DEFAULT_PERMISSION +
"|[0-1]?[0-7][0-7][0-7]");
/** /**
* Constructor. * Constructor.
*/ */
public PermissionParam() { public PermissionParam() {
super(NAME, HttpFSFileSystem.DEFAULT_PERMISSION, PERMISSION_PATTERN); super(NAME, HttpFSFileSystem.DEFAULT_PERMISSION, 8);
} }
} }

View File

@ -484,7 +484,7 @@ public class HttpFSServer {
createUploadRedirectionURL(uriInfo, createUploadRedirectionURL(uriInfo,
HttpFSFileSystem.Operation.CREATE)).build(); HttpFSFileSystem.Operation.CREATE)).build();
} else { } else {
String permission = params.get(PermissionParam.NAME, Short permission = params.get(PermissionParam.NAME,
PermissionParam.class); PermissionParam.class);
boolean override = params.get(OverwriteParam.NAME, boolean override = params.get(OverwriteParam.NAME,
OverwriteParam.class); OverwriteParam.class);
@ -504,7 +504,7 @@ public class HttpFSServer {
break; break;
} }
case MKDIRS: { case MKDIRS: {
String permission = params.get(PermissionParam.NAME, Short permission = params.get(PermissionParam.NAME,
PermissionParam.class); PermissionParam.class);
FSOperations.FSMkdirs command = FSOperations.FSMkdirs command =
new FSOperations.FSMkdirs(path, permission); new FSOperations.FSMkdirs(path, permission);
@ -533,7 +533,7 @@ public class HttpFSServer {
break; break;
} }
case SETPERMISSION: { case SETPERMISSION: {
String permission = params.get(PermissionParam.NAME, Short permission = params.get(PermissionParam.NAME,
PermissionParam.class); PermissionParam.class);
FSOperations.FSSetPermission command = FSOperations.FSSetPermission command =
new FSOperations.FSSetPermission(path, permission); new FSOperations.FSSetPermission(path, permission);

View File

@ -20,12 +20,19 @@ package org.apache.hadoop.lib.wsrs;
public abstract class ShortParam extends Param<Short> { public abstract class ShortParam extends Param<Short> {
public ShortParam(String name, Short defaultValue) { private int radix;
public ShortParam(String name, Short defaultValue, int radix) {
super(name, defaultValue); super(name, defaultValue);
this.radix = radix;
}
public ShortParam(String name, Short defaultValue) {
this(name, defaultValue, 10);
} }
protected Short parse(String str) throws Exception { protected Short parse(String str) throws Exception {
return Short.parseShort(str); return Short.parseShort(str, radix);
} }
@Override @Override

View File

@ -77,6 +77,11 @@ public class TestParam {
}; };
test(param, "S", "a short", (short) 1, (short) 2, "x", test(param, "S", "a short", (short) 1, (short) 2, "x",
"" + ((int)Short.MAX_VALUE + 1)); "" + ((int)Short.MAX_VALUE + 1));
param = new ShortParam("S", (short) 1, 8) {
};
Assert.assertEquals(new Short((short)01777), param.parse("01777"));
} }
@Test @Test

View File

@ -399,6 +399,8 @@ Branch-2 ( Unreleased changes )
HDFS-3551. WebHDFS CREATE should use client location for HTTP redirection. HDFS-3551. WebHDFS CREATE should use client location for HTTP redirection.
(szetszwo) (szetszwo)
HDFS-3491. HttpFs does not set permissions correctly (tucu)
Release 2.0.0-alpha - 05-23-2012 Release 2.0.0-alpha - 05-23-2012
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES