Skip to content

Commit fe1dfdf

Browse files
committed
Merge pull request #36 from gluster/BZ__createNonRecursive
Bz create non recursive
2 parents ce3531a + 3a589ba commit fe1dfdf

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ public void setOwner(Path p, String username, String groupname) throws IOExcepti
569569

570570
if (username == null) {
571571
execCommand(f, Shell.SET_GROUP_COMMAND, groupname);
572-
}
572+
}
573573
else {
574574
//OWNER[:[GROUP]]
575575
String s = username + (groupname == null? "": ":" + groupname);
@@ -592,4 +592,17 @@ public Path startLocalOutput(Path fsOutputFile,Path tmpLocalFile) throws IOExcep
592592
public void completeLocalOutput(Path fsOutputFile,Path tmpLocalFile) throws IOException{
593593
moveFromLocalFile(tmpLocalFile, fsOutputFile);
594594
}
595+
596+
/**
597+
* Taken from https://github.com/quantcast/qfs/pull/21/files, a non
598+
* recursive create implementation to support HBASE.
599+
*/
600+
public FSDataOutputStream createNonRecursive(Path file,FsPermission permission,boolean overwrite,int bufferSize,short replication,long blockSize,Progressable progress) throws IOException{
601+
Path parent=file.getParent();
602+
if(parent==null||exists(parent)){
603+
return create(file, permission, overwrite, bufferSize, replication, blockSize, progress);
604+
}else{
605+
throw new IOException("Parent "+parent+" does not exist");
606+
}
607+
}
595608
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public void testPermissions() throws Exception{
249249
gfs.delete(new Path("aa"),true);
250250
assertFalse(gfs.exists(directory));
251251
}
252-
252+
253253
@org.junit.Test
254254
public void testZDirs() throws Exception{
255255
final Path subDir1=new Path("td_dir.1");
@@ -435,4 +435,16 @@ public void test0aPermissions() throws Exception{
435435
gfs.delete(new Path("mnt"),true);
436436

437437
}
438+
439+
440+
@Test
441+
public void testCreateNR() throws Exception{
442+
Path nonrec = new Path("nonrec");
443+
this.gfs.createNonRecursive(
444+
new Path("nonrec"),
445+
FsPermission.valueOf("-rwxrwxrwx"),
446+
true, 100, (short)0, 0L, null);
447+
Assert.assertTrue(this.gfs.exists(new Path("nonrec")));
448+
this.gfs.delete(nonrec);
449+
}
438450
}

0 commit comments

Comments
 (0)