28
28
import java .util .Arrays ;
29
29
import java .util .Enumeration ;
30
30
import java .util .Hashtable ;
31
+ import java .util .Vector ;
31
32
32
33
import org .apache .hadoop .conf .Configuration ;
33
34
import org .apache .hadoop .fs .BlockLocation ;
@@ -57,7 +58,7 @@ public class GlusterVolume extends RawLocalFileSystem{
57
58
58
59
protected Hashtable <String ,String > volumes =new Hashtable <String ,String >();
59
60
protected String default_volume = null ;
60
-
61
+ protected boolean sortDirectoryListing = false ;
61
62
62
63
protected static GlusterFSXattr attr = null ;
63
64
@@ -107,7 +108,14 @@ public void setConf(Configuration conf){
107
108
if (conf !=null ){
108
109
109
110
try {
110
- String [] v =conf .get ("fs.glusterfs.volumes" , "" ).split ("," );
111
+ String r =conf .get ("fs.glusterfs.volumes" , "" );
112
+
113
+ if ("" .equals (r )){
114
+ log .error ("fs.glusterfs.volumes not defined." );
115
+ throw new RuntimeException ("Error loading gluster configuration.. fs.glusterfs.volumes not defined." );
116
+ }
117
+ String [] v =r .split ("," );
118
+
111
119
default_volume = v [0 ];
112
120
for (int i =0 ;i <v .length ;i ++){
113
121
String vol = conf .get ("fs.glusterfs.volume.fuse." + v [i ] , null );
@@ -170,6 +178,10 @@ public void setConf(Configuration conf){
170
178
}
171
179
log .info ("Default block size : " +conf .getInt ("fs.local.block.size" ,-1 )) ;
172
180
181
+ sortDirectoryListing =conf .getBoolean ("fs.glusterfs.sort.directory.listing" ,false );
182
+
183
+ log .info ("Directory list order : " + (sortDirectoryListing ?"sorted" :"fs ordering" )) ;
184
+
173
185
}
174
186
catch (Exception e ){
175
187
throw new RuntimeException (e );
@@ -269,10 +281,11 @@ public boolean mkdirs(Path f) throws IOException {
269
281
return super .mkdirs (f );
270
282
}
271
283
272
- public FileStatus [] listStatus (Path f ) throws IOException {
284
+ public FileStatus [] listStatus (Path f ) throws IOException {
273
285
File localf = pathToFile (f );
274
- FileStatus [] results ;
275
-
286
+ Vector <FileStatus > results = new Vector <FileStatus >();
287
+
288
+
276
289
if (!localf .exists ()) {
277
290
throw new FileNotFoundException ("File " + f + " does not exist" );
278
291
}
@@ -285,21 +298,34 @@ public FileStatus[] listStatus(Path f) throws IOException {
285
298
if (names == null ) {
286
299
return null ;
287
300
}
288
- results = new FileStatus [names .length ];
289
- int j = 0 ;
301
+
290
302
for (int i = 0 ; i < names .length ; i ++) {
291
303
try {
292
- results [j ] = getFileStatus (fileToPath (names [i ]));
293
- j ++;
304
+ FileStatus listing = getFileStatus (fileToPath (names [i ]));
305
+ if (sortDirectoryListing ){
306
+ int j ;
307
+ for (j =0 ;j <results .size ();j ++){
308
+
309
+ if (results .get (j ).compareTo (listing )>0 ){
310
+ results .insertElementAt (listing ,j );
311
+ break ;
312
+ }
313
+
314
+ }
315
+ if (results .size ()==j )
316
+ results .add (listing );
317
+ }else {
318
+ results .add (listing );
319
+ }
320
+
294
321
} catch (FileNotFoundException e ) {
295
322
// ignore the files not found since the dir list may have have changed
296
323
// since the names[] list was generated.
297
324
}
298
325
}
299
- if (j == names .length ) {
300
- return results ;
301
- }
302
- return Arrays .copyOf (results , j );
326
+
327
+ return results .toArray (new FileStatus [results .size ()]);
328
+
303
329
}
304
330
305
331
public FileStatus getFileStatus (Path f ) throws IOException {
0 commit comments