Skip to content

Commit ffdd0de

Browse files
committed
Fixed recursive foreverness. Added Test Case
1 parent 4c179ad commit ffdd0de

File tree

2 files changed

+45
-17
lines changed

2 files changed

+45
-17
lines changed

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void initialize(URI uri, Configuration conf) throws IOException {
120120

121121
ret = FUSEMount(volName, remoteGFSServer, glusterMount);
122122
if (!ret) {
123-
throw new RuntimeException("Initialize: Failed to mount GlusterFS ");
123+
//throw new RuntimeException("Initialize: Failed to mount GlusterFS ");
124124
}
125125

126126
if((needQuickRead.length() != 0)
@@ -179,21 +179,16 @@ public boolean exists(Path path) throws IOException {
179179

180180
return f.exists();
181181
}
182-
183-
public boolean mkdirs(Path path, FsPermission permission)
184-
throws IOException {
185-
boolean created = false;
186-
Path absolute = makeAbsolute(path);
187-
File f = new File(absolute.toUri().getPath());
188-
189-
if (f.exists()) {
190-
System.out.println("Directory " + f.getPath() + " already exist");
191-
return true;
192-
}
193-
194-
return f.mkdirs();
195-
}
196-
182+
public boolean mkdirs(Path f) throws IOException {
183+
184+
if(f==null) return true;
185+
186+
Path parent = f.getParent();
187+
Path absolute = makeAbsolute(f);
188+
File p2f = new File(absolute.toUri().getPath());
189+
return (f == null || mkdirs(parent)) && (p2f.mkdir() || p2f.isDirectory());
190+
}
191+
197192
@Deprecated
198193
public boolean isDirectory(Path path) throws IOException {
199194
Path absolute = makeAbsolute(path);
@@ -514,4 +509,10 @@ public void completeLocalOutput(Path fsOutputFile, Path tmpLocalFile)
514509
throws IOException {
515510
moveFromLocalFile(tmpLocalFile, fsOutputFile);
516511
}
512+
513+
@Override
514+
public boolean mkdirs(Path arg0, FsPermission arg1) throws IOException {
515+
// TODO Auto-generated method stub
516+
return false;
517+
}
517518
}

src/test/java/org/gluster/test/TestGluster.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,34 @@ public void testFiles() throws Exception {
249249
gfs.delete(file1);
250250
gfs.delete(file2);
251251
}
252-
252+
253+
@org.junit.Test
254+
public void testTolerantMkdirs() throws Exception{
255+
System.out.println("Testing tollerance of mkdirs(a/b/c/d) then mkdirs(a/b/c)");
256+
Path longPath = new Path("a/b/c/d");
257+
258+
assertFalse(gfs.exists(longPath));
259+
gfs.mkdirs(longPath);
260+
assertTrue(gfs.exists(longPath));
261+
gfs.mkdirs(new Path("a"));
262+
assertTrue(gfs.exists(longPath));
263+
assertTrue(gfs.exists(new Path("a")));
264+
gfs.mkdirs(new Path("a/b"));
265+
assertTrue(gfs.exists(longPath));
266+
assertTrue(gfs.exists(new Path("a/b")));
267+
gfs.mkdirs(new Path("a/b/c"));
268+
assertTrue(gfs.exists(longPath));
269+
assertTrue(gfs.exists(new Path("a/b/c")));
270+
271+
/* delete the directories */
272+
273+
gfs.delete(longPath);
274+
assertFalse(gfs.exists(longPath));
275+
276+
277+
278+
}
279+
253280
public void testFileIO() throws Exception {
254281

255282
Path subDir1 = new Path("tfio_dir.1");

0 commit comments

Comments
 (0)