Skip to content

Commit c95676b

Browse files
committed
Merge pull request #92 from rootfs/master
BZ 1065438: apply umask in setPermission
2 parents 813230e + d3ffa66 commit c95676b

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

src/main/java/org/apache/hadoop/fs/glusterfs/GlusterFileSystem.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.hadoop.fs.FileSystem;
3737
import org.apache.hadoop.fs.FileUtil;
3838
import org.apache.hadoop.fs.FilterFileSystem;
39+
import org.apache.hadoop.fs.permission.FsPermission;
3940
import org.apache.hadoop.fs.Path;
4041
import org.slf4j.Logger;
4142
import org.slf4j.LoggerFactory;
@@ -92,6 +93,11 @@ public void copyToLocalFile(boolean delSrc,Path src,Path dst) throws IOException
9293
FileUtil.copy(srcFs, src, dstFs, dst, delSrc, getConf());
9394
}
9495

96+
@Override
97+
public boolean mkdirs(Path f) throws IOException {
98+
return mkdirs(f, FsPermission.getDirDefault().applyUMask(FsPermission.getUMask(getConf())));
99+
}
100+
95101
public String toString(){
96102
return "Gluster File System, no CRC.";
97103
}

src/test/java/org/apache/hadoop/fs/test/unit/HcfsFileSystemTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,5 +338,4 @@ public void testPermissionsChanging() throws Exception{
338338
fs.delete(new Path("mnt"),true);
339339

340340
}
341-
342341
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
*
3+
* Copyright (c) 2014 Gluster, Inc. <http://www.gluster.com>
4+
* This file is part of GlusterFS.
5+
*
6+
* Licensed under the Apache License, Version 2.0
7+
* (the "License"); you may not use this file except in compliance with
8+
* the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15+
* implied. See the License for the specific language governing
16+
* permissions and limitations under the License.
17+
*
18+
*/
19+
20+
package org.apache.hadoop.fs.test.unit;
21+
22+
import static org.apache.hadoop.fs.FileSystemTestHelper.getTestRootPath;
23+
import static org.junit.Assert.assertEquals;
24+
import static org.junit.Assert.assertFalse;
25+
import static org.junit.Assert.assertTrue;
26+
27+
import java.io.IOException;
28+
29+
import org.apache.hadoop.fs.FSDataInputStream;
30+
import org.apache.hadoop.fs.FSDataOutputStream;
31+
import org.apache.hadoop.fs.FileStatus;
32+
import org.apache.hadoop.fs.FileSystem;
33+
import org.apache.hadoop.fs.Path;
34+
import org.apache.hadoop.conf.Configuration;
35+
import org.apache.hadoop.fs.permission.FsAction;
36+
import org.apache.hadoop.fs.permission.FsPermission;
37+
import org.apache.hadoop.fs.test.connector.HcfsTestConnectorFactory;
38+
import org.apache.hadoop.fs.test.connector.HcfsTestConnectorInterface;
39+
import org.junit.After;
40+
import org.junit.AfterClass;
41+
import org.junit.Assert;
42+
import org.junit.BeforeClass;
43+
import org.junit.Test;
44+
45+
/**
46+
* Unit test for HCFS classes.
47+
*
48+
*/
49+
public class HcfsUmaskTest{
50+
51+
static FileSystem fs ;
52+
53+
@BeforeClass
54+
public static void setup() throws Exception {
55+
HcfsTestConnectorInterface connector = HcfsTestConnectorFactory.getHcfsTestConnector();
56+
fs= connector.create();
57+
}
58+
59+
@AfterClass
60+
public static void after() throws IOException{
61+
fs.close();
62+
}
63+
64+
@After
65+
public void tearDown() throws Exception {
66+
fs.delete(getTestRootPath(fs, "test"),true);
67+
}
68+
69+
@org.junit.Test
70+
public void testMkdirsWithUmask() throws Exception {
71+
Configuration conf = fs.getConf();
72+
String oldUmask = conf.get("fs.permissions.umask-mode");
73+
Path dir = new Path("dirUmask022");
74+
conf.set("fs.permissions.umask-mode", "022");
75+
assertTrue(fs.mkdirs(dir));
76+
conf.set("fs.permissions.umask-mode", oldUmask);
77+
FileStatus status = fs.getFileStatus(dir);
78+
assertTrue(status.isDirectory());
79+
assertEquals((short)0755, status.getPermission().toShort());
80+
81+
}
82+
}

0 commit comments

Comments
 (0)