29
29
import java .util .Arrays ;
30
30
import java .util .Enumeration ;
31
31
import java .util .Hashtable ;
32
+ import java .util .Vector ;
32
33
33
34
import org .apache .hadoop .conf .Configuration ;
34
35
import org .apache .hadoop .fs .BlockLocation ;
@@ -58,7 +59,7 @@ public class GlusterVolume extends RawLocalFileSystem{
58
59
59
60
protected Hashtable <String ,String > volumes =new Hashtable <String ,String >();
60
61
protected String default_volume = null ;
61
-
62
+ protected boolean sortDirectoryListing = false ;
62
63
63
64
protected static GlusterFSXattr attr = null ;
64
65
@@ -115,7 +116,14 @@ public void setConf(Configuration conf){
115
116
if (conf !=null ){
116
117
117
118
try {
118
- String [] v =conf .get ("fs.glusterfs.volumes" , "" ).split ("," );
119
+ String r =conf .get ("fs.glusterfs.volumes" , "" );
120
+
121
+ if ("" .equals (r )){
122
+ log .error ("fs.glusterfs.volumes not defined." );
123
+ throw new RuntimeException ("Error loading gluster configuration.. fs.glusterfs.volumes not defined." );
124
+ }
125
+ String [] v =r .split ("," );
126
+
119
127
default_volume = v [0 ];
120
128
for (int i =0 ;i <v .length ;i ++){
121
129
String vol = conf .get ("fs.glusterfs.volume.fuse." + v [i ] , null );
@@ -183,6 +191,10 @@ public void setConf(Configuration conf){
183
191
}
184
192
log .info ("Default block size : " +conf .getInt ("fs.local.block.size" ,-1 )) ;
185
193
194
+ sortDirectoryListing =conf .getBoolean ("fs.glusterfs.sort.directory.listing" ,false );
195
+
196
+ log .info ("Directory list order : " + (sortDirectoryListing ?"sorted" :"fs ordering" )) ;
197
+
186
198
}
187
199
catch (Exception e ){
188
200
throw new RuntimeException (e );
@@ -290,10 +302,11 @@ public boolean mkdirs(Path f) throws IOException {
290
302
return super .mkdirs (f );
291
303
}
292
304
293
- public FileStatus [] listStatus (Path f ) throws IOException {
305
+ public FileStatus [] listStatus (Path f ) throws IOException {
294
306
File localf = pathToFile (f );
295
- FileStatus [] results ;
296
-
307
+ Vector <FileStatus > results = new Vector <FileStatus >();
308
+
309
+
297
310
if (!localf .exists ()) {
298
311
throw new FileNotFoundException ("File " + f + " does not exist" );
299
312
}
@@ -310,20 +323,33 @@ public FileStatus[] listStatus(Path f) throws IOException {
310
323
if (names == null ) {
311
324
return null ;
312
325
}
313
- results = new FileStatus [names .length ];
314
- int j = 0 ;
326
+
315
327
for (int i = 0 ; i < names .length ; i ++) {
316
328
try {
317
- results [j ] = getFileStatus (fileToPath (names [i ]));
318
- j ++;
329
+ FileStatus listing = getFileStatus (fileToPath (names [i ]));
330
+ if (sortDirectoryListing ){
331
+ int j ;
332
+ for (j =0 ;j <results .size ();j ++){
333
+
334
+ if (results .get (j ).compareTo (listing )>0 ){
335
+ results .insertElementAt (listing ,j );
336
+ break ;
337
+ }
338
+
339
+ }
340
+ if (results .size ()==j )
341
+ results .add (listing );
342
+ }else {
343
+ results .add (listing );
344
+ }
345
+
319
346
} catch (FileNotFoundException e ) {
320
347
log .info ("ignoring invisible path : " + names [i ]);
321
348
}
322
349
}
323
- if (j == names .length ) {
324
- return results ;
325
- }
326
- return Arrays .copyOf (results , j );
350
+
351
+ return results .toArray (new FileStatus [results .size ()]);
352
+
327
353
}
328
354
329
355
public FileStatus getFileStatus (Path f ) throws IOException {
0 commit comments