@@ -203,15 +203,24 @@ public boolean exists(Path path) throws IOException{
203
203
* org.apache.hadoop.fs.RawLocalFileSystem#mkdirs(org.apache.hadoop.fs.Path)
204
204
* as incremental fix towards a re-write. of this class to remove duplicity.
205
205
*/
206
- public boolean mkdirs (Path f ,FsPermission permission ) throws IOException {
207
-
208
- if (f ==null )
209
- return true ;
210
-
211
- Path parent =f .getParent ();
212
- Path absolute =makeAbsolute (f );
213
- File p2f =new File (absolute .toUri ().getPath ());
214
- return (f ==null ||mkdirs (parent ))&&(p2f .mkdir ()||p2f .isDirectory ());
206
+ public boolean mkdirs (Path path ,FsPermission permission ) throws IOException {
207
+
208
+ String split []=path .toString ().split (Path .SEPARATOR );
209
+ String current ="" ;
210
+ boolean success =true ;
211
+ for (int i =0 ;i <split .length &&success ;i ++){
212
+ current +=split [i ]+Path .SEPARATOR ;
213
+ Path absolute =makeAbsolute (new Path (current ));
214
+ File p2f =new File (absolute .toUri ().getPath ());
215
+ if (!p2f .exists ()){
216
+ p2f .mkdirs ();
217
+ setPermission (new Path (current ), permission );
218
+ }
219
+ success =p2f .exists ();
220
+ }
221
+
222
+ return success ;
223
+
215
224
}
216
225
217
226
@ Deprecated
@@ -298,14 +307,18 @@ public FUSEFileStatus(File f, boolean isdir, int block_replication, long blocksi
298
307
*/
299
308
@ Override
300
309
public String getOwner (){
301
- try {
302
- return FileInfoUtil .getLSinfo (theFile .getAbsolutePath ()).get ("owner" );
303
- }catch (Exception e ){
304
- throw new RuntimeException (e );
305
- }
310
+ loadPermissionInfo ();
311
+ return super .getOwner ();
306
312
}
313
+
314
+
315
+ @ Override
316
+ public String getGroup () {
317
+ loadPermissionInfo ();
318
+ return super .getGroup ();
319
+ }
307
320
308
- public FsPermission getPermission (){
321
+ public FsPermission getPermission (){
309
322
// should be amortized, see method.
310
323
loadPermissionInfo ();
311
324
return super .getPermission ();
@@ -322,7 +335,6 @@ private void loadPermissionInfo(){
322
335
try {
323
336
String output ;
324
337
StringTokenizer t =new StringTokenizer (output =execCommand (theFile , Shell .getGET_PERMISSION_COMMAND ()));
325
-
326
338
// log.info("Output of PERMISSION command = " + output
327
339
// + " for " + this.getPath());
328
340
// expected format
@@ -371,6 +383,9 @@ public static String execCommand(File f,String...cmd) throws IOException{
371
383
*/
372
384
@ Override
373
385
public void setPermission (Path p ,FsPermission permission ){
386
+
387
+ if (permission ==null ) return ;
388
+
374
389
try {
375
390
Path absolute =makeAbsolute (p );
376
391
final File f =new File (absolute .toUri ().getPath ());
@@ -409,7 +424,7 @@ public FSDataOutputStream create(Path path,FsPermission permission,boolean overw
409
424
Path absolute =makeAbsolute (path );
410
425
Path parent =null ;
411
426
File f =null ;
412
- File fParent = null ;
427
+
413
428
FSDataOutputStream glusterFileStream =null ;
414
429
415
430
f =new File (absolute .toUri ().getPath ());
@@ -422,7 +437,10 @@ public FSDataOutputStream create(Path path,FsPermission permission,boolean overw
422
437
}
423
438
424
439
parent =path .getParent ();
425
- mkdirs (parent );
440
+ mkdirs (parent , permission );
441
+
442
+ f .createNewFile ();
443
+ setPermission (path , permission );
426
444
427
445
glusterFileStream =new FSDataOutputStream (new GlusterFUSEOutputStream (f .getPath (), false , writeBufferSize ));
428
446
@@ -494,7 +512,7 @@ public boolean delete(Path path,boolean recursive) throws IOException{
494
512
if (dirEntries !=null )
495
513
for (int i =0 ;i <dirEntries .length ;i ++)
496
514
delete (new Path (absolute , dirEntries [i ].getPath ()), recursive );
497
-
515
+
498
516
return f .delete ();
499
517
}
500
518
@@ -562,8 +580,31 @@ public BlockLocation[] getFileBlockLocations(FileStatus file,long start,long len
562
580
return result ;
563
581
}
564
582
583
+ /**
584
+ * Adopted from {@link org.apache.hadoop.RawLocalFileSystem}, so that group privileges are
585
+ * set properly when hadoop fs chwon is called in {@link org.apache.hadoop.fs.FSShellPermissions}.
586
+ */
587
+ @ Override
588
+ public void setOwner (Path p , String username , String groupname ) throws IOException {
589
+ Path absolute =makeAbsolute (p );
590
+ File f =new File (absolute .toUri ().getPath ());
591
+
592
+ if (username == null && groupname == null ) {
593
+ throw new IOException ("username == null && groupname == null" );
594
+ }
595
+
596
+ if (username == null ) {
597
+ execCommand (f , Shell .SET_GROUP_COMMAND , groupname );
598
+ }
599
+ else {
600
+ //OWNER[:[GROUP]]
601
+ String s = username + (groupname == null ? "" : ":" + groupname );
602
+ execCommand (f , Shell .SET_OWNER_COMMAND , s );
603
+ }
604
+ }
605
+
565
606
public void copyFromLocalFile (boolean delSrc ,Path src ,Path dst ) throws IOException {
566
- FileUtil .copy (glusterFs , src , this , dst , delSrc , getConf ());
607
+ FileUtil .copy (glusterFs , src , this , dst , delSrc , getConf ());
567
608
}
568
609
569
610
public void copyToLocalFile (boolean delSrc ,Path src ,Path dst ) throws IOException {
0 commit comments