From 34605c9594770b204b28a809d8dbc0dae11ff0d1 Mon Sep 17 00:00:00 2001 From: Alejandro Abdelnur Date: Fri, 29 Jun 2012 20:59:11 +0000 Subject: [PATCH] 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 --- .../fs/http/client/HttpFSFileSystem.java | 4 +- .../hadoop/fs/http/server/FSOperations.java | 38 +++++-------------- .../http/server/HttpFSParametersProvider.java | 10 +---- .../hadoop/fs/http/server/HttpFSServer.java | 8 ++-- .../apache/hadoop/lib/wsrs/ShortParam.java | 11 +++++- .../org/apache/hadoop/lib/wsrs/TestParam.java | 5 +++ hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 2 + 7 files changed, 34 insertions(+), 44 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSFileSystem.java index fa28ba31c2..9191129e11 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSFileSystem.java @@ -86,7 +86,7 @@ public class HttpFSFileSystem extends FileSystem { public static final String ACCESS_TIME_PARAM = "accesstime"; 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"; @@ -438,7 +438,7 @@ public void close() throws IOException { * @return the Unix string symbolic reprentation. */ 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); } /* diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/FSOperations.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/FSOperations.java index 9e51ce8a77..b6ab69f237 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/FSOperations.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/FSOperations.java @@ -42,25 +42,6 @@ */ 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 FsPermission.getDefault(). - */ - 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"}) private static Map fileStatusToJSONRaw(FileStatus status, boolean emptyPathSuffix) { Map json = new LinkedHashMap(); @@ -252,7 +233,7 @@ public Map execute(FileSystem fs) throws IOException { public static class FSCreate implements FileSystemAccess.FileSystemExecutor { private InputStream is; private Path path; - private String permission; + private short permission; private boolean override; private short replication; private long blockSize; @@ -267,7 +248,8 @@ public static class FSCreate implements FileSystemAccess.FileSystemExecutor { private Path path; - private String permission; + private short permission; /** * Creates a mkdirs executor. @@ -485,7 +467,7 @@ public static class FSMkdirs implements FileSystemAccess.FileSystemExecutor { private Path path; - private String permission; + private short permission; /** * Creates a set-permission executor. @@ -629,7 +611,7 @@ public static class FSSetPermission implements FileSystemAccess.FileSystemExecut * @param path path to set the permission. * @param permission permission to set. */ - public FSSetPermission(String path, String permission) { + public FSSetPermission(String path, short permission) { this.path = new Path(path); this.permission = permission; } @@ -645,7 +627,7 @@ public FSSetPermission(String path, String permission) { */ @Override public Void execute(FileSystem fs) throws IOException { - FsPermission fsPermission = getPermission(permission); + FsPermission fsPermission = new FsPermission(permission); fs.setPermission(path, fsPermission); return null; } diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSParametersProvider.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSParametersProvider.java index 0ab10179c8..e696f33124 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSParametersProvider.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSParametersProvider.java @@ -337,25 +337,19 @@ public OwnerParam() { /** * Class for permission parameter. */ - public static class PermissionParam extends StringParam { + public static class PermissionParam extends ShortParam { /** * Parameter name. */ 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. */ public PermissionParam() { - super(NAME, HttpFSFileSystem.DEFAULT_PERMISSION, PERMISSION_PATTERN); + super(NAME, HttpFSFileSystem.DEFAULT_PERMISSION, 8); } } diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java index 22a173ac8a..70994b3e4f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java @@ -484,7 +484,7 @@ public Response put(InputStream is, createUploadRedirectionURL(uriInfo, HttpFSFileSystem.Operation.CREATE)).build(); } else { - String permission = params.get(PermissionParam.NAME, + Short permission = params.get(PermissionParam.NAME, PermissionParam.class); boolean override = params.get(OverwriteParam.NAME, OverwriteParam.class); @@ -504,7 +504,7 @@ public Response put(InputStream is, break; } case MKDIRS: { - String permission = params.get(PermissionParam.NAME, + Short permission = params.get(PermissionParam.NAME, PermissionParam.class); FSOperations.FSMkdirs command = new FSOperations.FSMkdirs(path, permission); @@ -533,8 +533,8 @@ public Response put(InputStream is, break; } case SETPERMISSION: { - String permission = params.get(PermissionParam.NAME, - PermissionParam.class); + Short permission = params.get(PermissionParam.NAME, + PermissionParam.class); FSOperations.FSSetPermission command = new FSOperations.FSSetPermission(path, permission); fsExecute(user, doAs, command); diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/ShortParam.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/ShortParam.java index cc75a86062..85591deb8f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/ShortParam.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/ShortParam.java @@ -20,12 +20,19 @@ public abstract class ShortParam extends Param { - public ShortParam(String name, Short defaultValue) { + private int radix; + + public ShortParam(String name, Short defaultValue, int radix) { super(name, defaultValue); + this.radix = radix; + } + + public ShortParam(String name, Short defaultValue) { + this(name, defaultValue, 10); } protected Short parse(String str) throws Exception { - return Short.parseShort(str); + return Short.parseShort(str, radix); } @Override diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/lib/wsrs/TestParam.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/lib/wsrs/TestParam.java index ed79c86e7d..e2376879d7 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/lib/wsrs/TestParam.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/lib/wsrs/TestParam.java @@ -77,6 +77,11 @@ public void testShort() throws Exception { }; test(param, "S", "a short", (short) 1, (short) 2, "x", "" + ((int)Short.MAX_VALUE + 1)); + + param = new ShortParam("S", (short) 1, 8) { + }; + + Assert.assertEquals(new Short((short)01777), param.parse("01777")); } @Test diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 22fc118da4..5d792be212 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -399,6 +399,8 @@ Branch-2 ( Unreleased changes ) HDFS-3551. WebHDFS CREATE should use client location for HTTP redirection. (szetszwo) + HDFS-3491. HttpFs does not set permissions correctly (tucu) + Release 2.0.0-alpha - 05-23-2012 INCOMPATIBLE CHANGES