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 fa28ba31c27..9191129e110 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 class HttpFSFileSystem extends FileSystem { * @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 9e51ce8a775..b6ab69f2378 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 @@ import java.util.Map; */ 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 class FSOperations { 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 class FSOperations { * @param repl the replication factor 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.path = new Path(path); this.permission = perm; @@ -293,7 +275,7 @@ public class FSOperations { if (blockSize == -1) { blockSize = fs.getDefaultBlockSize(path); } - FsPermission fsPermission = getPermission(permission); + FsPermission fsPermission = new FsPermission(permission); int bufferSize = fs.getConf().getInt("httpfs.buffer.size", 4096); OutputStream os = fs.create(path, fsPermission, override, bufferSize, replication, blockSize, null); IOUtils.copyBytes(is, os, bufferSize, true); @@ -477,7 +459,7 @@ public class FSOperations { public static class FSMkdirs implements FileSystemAccess.FileSystemExecutor { private Path path; - private String permission; + private short permission; /** * Creates a mkdirs executor. @@ -485,7 +467,7 @@ public class FSOperations { * @param path directory path to create. * @param permission permission to use. */ - public FSMkdirs(String path, String permission) { + public FSMkdirs(String path, short permission) { this.path = new Path(path); this.permission = permission; } @@ -502,7 +484,7 @@ public class FSOperations { */ @Override public JSONObject execute(FileSystem fs) throws IOException { - FsPermission fsPermission = getPermission(permission); + FsPermission fsPermission = new FsPermission(permission); boolean mkdirs = fs.mkdirs(path, fsPermission); return toJSON(HttpFSFileSystem.MKDIRS_JSON, mkdirs); } @@ -621,7 +603,7 @@ public class FSOperations { public static class FSSetPermission implements FileSystemAccess.FileSystemExecutor { private Path path; - private String permission; + private short permission; /** * Creates a set-permission executor. @@ -629,7 +611,7 @@ public class FSOperations { * @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 class FSOperations { */ @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 0ab10179c88..e696f331243 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 class HttpFSParametersProvider extends ParametersProvider { /** * 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 22a173ac8a1..70994b3e4fb 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 class HttpFSServer { 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 class HttpFSServer { 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 class HttpFSServer { 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 cc75a860621..85591deb8fb 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 @@ package org.apache.hadoop.lib.wsrs; 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 ed79c86e7de..e2376879d7d 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 class TestParam { }; 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 22fc118da45..5d792be212e 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