Skip to content

Commit ae6ad7a

Browse files
author
Sanjay Radia
committed
HDFS-4659 Support setting execution bit for regular files (Brandon Li via sanjay)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1477994 13f79535-47bb-0310-9956-ffa450edef68
1 parent d035755 commit ae6ad7a

File tree

9 files changed

+179
-190
lines changed

9 files changed

+179
-190
lines changed

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileContextPermissionBase.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ void doFilePermissionCheck(FsPermission expectedPerm, FsPermission actualPerm) {
202202

203203

204204
/*
205-
* Some filesystem like HDFS ignore the "x" bit if the permission.
206-
* Others like localFs does not.
207205
* Override the method below if the file system being tested masks our
208206
* certain bits for file masks.
209207
*/

hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Trunk (Unreleased)
2222
Azure environments. (See breakdown of tasks below for subtasks and
2323
contributors)
2424

25+
HDFS-4659 Support setting execution bit for regular files (Brandon Li via sanjay)
26+
2527
IMPROVEMENTS
2628

2729
HDFS-4665. Move TestNetworkTopologyWithNodeGroup to common.

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFile.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ public static INodeFile valueOf(INode inode, String path
4444
return (INodeFile)inode;
4545
}
4646

47-
static final FsPermission UMASK = FsPermission.createImmutable((short)0111);
48-
49-
5047
/** Format: [16 bits for replication][48 bits for PreferredBlockSize] */
5148
private static class HeaderFormat {
5249
/** Number of bits for Block size */
@@ -101,16 +98,6 @@ public final boolean isFile() {
10198
return true;
10299
}
103100

104-
/**
105-
* Set the {@link FsPermission} of this {@link INodeFile}.
106-
* Since this is a file,
107-
* the {@link FsAction#EXECUTE} action, if any, is ignored.
108-
*/
109-
@Override
110-
void setPermission(FsPermission permission) {
111-
super.setPermission(permission.applyUMask(UMASK));
112-
}
113-
114101
/** @return the replication factor of the file. */
115102
@Override
116103
public short getBlockReplication() {

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/INodeFileUnderConstruction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public static INodeFileUnderConstruction valueOf(INode inode, String path
5757
String clientName,
5858
String clientMachine,
5959
DatanodeDescriptor clientNode) {
60-
super(id, permissions.applyUMask(UMASK), BlockInfo.EMPTY_ARRAY,
61-
replication, modTime, modTime, preferredBlockSize);
60+
super(id, permissions, BlockInfo.EMPTY_ARRAY, replication, modTime,
61+
modTime, preferredBlockSize);
6262
this.clientName = clientName;
6363
this.clientMachine = clientMachine;
6464
this.clientNode = clientNode;

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestFcHdfsPermission.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,4 @@ public void setUp() throws Exception {
6767
public void tearDown() throws Exception {
6868
super.tearDown();
6969
}
70-
71-
/*
72-
* HDFS ignore the "x" bit if the permission.
73-
*
74-
*/
75-
static final FsPermission FILE_MASK_IGNORE_X_BIT =
76-
new FsPermission((short) ~0666);
77-
@Override
78-
FsPermission getFileMask() {
79-
return FILE_MASK_IGNORE_X_BIT;
80-
}
8170
}

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/permission/TestStickyBit.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,7 @@ private void confirmSettingAndGetting(FileSystem hdfs, Path baseDir)
141141
hdfs.setPermission(p1, new FsPermission(withSB));
142142
assertTrue(hdfs.getFileStatus(p1).getPermission().getStickyBit());
143143

144-
// However, while you can set the sticky bit on files, it has no effect,
145-
// following the linux/unix model:
146-
//
147-
// [user@host test]$ ls -alh
148-
// -rw-r--r-- 1 user users 0 Dec 31 01:46 aFile
149-
// [user@host test]$ chmod +t aFile
150-
// [user@host test]$ ls -alh
151-
// -rw-r--r-- 1 user users 0 Dec 31 01:46 aFile
152-
153-
// Write a file to the fs, try to set its sticky bit, expect to be ignored
144+
// Write a file to the fs, try to set its sticky bit
154145
Path f = new Path(baseDir, "somefile");
155146
writeFile(hdfs, f);
156147
assertFalse(hdfs.getFileStatus(f).getPermission().getStickyBit());
@@ -159,7 +150,7 @@ private void confirmSettingAndGetting(FileSystem hdfs, Path baseDir)
159150

160151
hdfs.setPermission(f, new FsPermission(withSB));
161152

162-
assertFalse(hdfs.getFileStatus(f).getPermission().getStickyBit());
153+
assertTrue(hdfs.getFileStatus(f).getPermission().getStickyBit());
163154
}
164155

165156
@Test

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSPermission.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public class TestDFSPermission {
6363

6464
final private static short MAX_PERMISSION = 511;
6565
final private static short DEFAULT_UMASK = 022;
66-
final private static short FILE_MASK = 0666;
6766
final private static FsPermission DEFAULT_PERMISSION =
6867
FsPermission.createImmutable((short) 0777);
6968
final static private int NUM_TEST_PERMISSIONS =
@@ -171,7 +170,7 @@ private void testPermissionSetting(OpType op) throws Exception {
171170
uMask = (short) 0111;
172171
initFileSystem(uMask);
173172
fs.setPermission(FILE_DIR_PATH, new FsPermission(uMask));
174-
short expectedPermission = (short) ((op == OpType.CREATE) ? 0 : 0111);
173+
short expectedPermission = (short) 0111;
175174
checkPermission(FILE_DIR_PATH, expectedPermission, true);
176175
closeFileSystem();
177176

@@ -234,7 +233,7 @@ private void createAndCheckPermission(OpType op, Path name, short umask,
234233

235234
// get the expected permission
236235
short expectedPermission = (op == OpType.CREATE) ? (short) (~umask
237-
& permissionNum & FILE_MASK) : (short) (~umask & permissionNum);
236+
& permissionNum) : (short) (~umask & permissionNum);
238237

239238
// check if permission is correctly set
240239
checkPermission(name, expectedPermission, delete);

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/security/TestPermission.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,28 @@ public void testFilePermission() throws Exception {
190190
catch(java.io.FileNotFoundException e) {
191191
LOG.info("GOOD: got " + e);
192192
}
193+
194+
// make sure nn can take user specified permission (with default fs
195+
// permission umask applied)
196+
FSDataOutputStream out = nnfs.create(CHILD_FILE1, new FsPermission(
197+
(short) 0777), true, 1024, (short) 1, 1024, null);
198+
FileStatus status = nnfs.getFileStatus(CHILD_FILE1);
199+
// FS_PERMISSIONS_UMASK_DEFAULT is 0022
200+
assertTrue(status.getPermission().toString().equals("rwxr-xr-x"));
201+
nnfs.delete(CHILD_FILE1, false);
202+
193203
// following dir/file creations are legal
194204
nnfs.mkdirs(CHILD_DIR1);
195-
FSDataOutputStream out = nnfs.create(CHILD_FILE1);
205+
out = nnfs.create(CHILD_FILE1);
206+
status = nnfs.getFileStatus(CHILD_FILE1);
207+
assertTrue(status.getPermission().toString().equals("rw-r--r--"));
196208
byte data[] = new byte[FILE_LEN];
197209
RAN.nextBytes(data);
198210
out.write(data);
199211
out.close();
200212
nnfs.setPermission(CHILD_FILE1, new FsPermission("700"));
213+
status = nnfs.getFileStatus(CHILD_FILE1);
214+
assertTrue(status.getPermission().toString().equals("rwx------"));
201215

202216
// following read is legal
203217
byte dataIn[] = new byte[FILE_LEN];
@@ -208,6 +222,15 @@ public void testFilePermission() throws Exception {
208222
assertEquals(data[i], dataIn[i]);
209223
}
210224

225+
// test execution bit support for files
226+
nnfs.setPermission(CHILD_FILE1, new FsPermission("755"));
227+
status = nnfs.getFileStatus(CHILD_FILE1);
228+
assertTrue(status.getPermission().toString().equals("rwxr-xr-x"));
229+
nnfs.setPermission(CHILD_FILE1, new FsPermission("744"));
230+
status = nnfs.getFileStatus(CHILD_FILE1);
231+
assertTrue(status.getPermission().toString().equals("rwxr--r--"));
232+
nnfs.setPermission(CHILD_FILE1, new FsPermission("700"));
233+
211234
////////////////////////////////////////////////////////////////
212235
// test illegal file/dir creation
213236
UserGroupInformation userGroupInfo =

0 commit comments

Comments
 (0)