46
46
* This package provides interface for hadoop jobs (incl. Map/Reduce)
47
47
* to access files in GlusterFS backed file system via FUSE mount
48
48
*/
49
+
50
+
51
+ /*
52
+ *
53
+ * TODO: Evaluate LocalFileSystem and RawLocalFileSystem as possible delegate file systems to remove & refactor this code.
54
+ *
55
+ */
49
56
public class GlusterFileSystem extends FileSystem {
50
57
51
58
private FileSystem glusterFs = null ;
@@ -180,19 +187,21 @@ public boolean exists(Path path) throws IOException {
180
187
return f .exists ();
181
188
}
182
189
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
- }
190
+ /*
191
+ * Code copied from:
192
+ * @see org.apache.hadoop.fs.RawLocalFileSystem#mkdirs(org.apache.hadoop.fs.Path)
193
+ * as incremental fix towards a re-write. of this class to remove duplicity.
194
+ *
195
+ */
196
+ public boolean mkdirs (Path f , FsPermission permission ) throws IOException {
197
+
198
+ if (f ==null ) return true ;
199
+
200
+ Path parent = f .getParent ();
201
+ Path absolute = makeAbsolute (f );
202
+ File p2f = new File (absolute .toUri ().getPath ());
203
+ return (f == null || mkdirs (parent )) && (p2f .mkdir () || p2f .isDirectory ());
204
+ }
196
205
197
206
@ Deprecated
198
207
public boolean isDirectory (Path path ) throws IOException {
@@ -293,9 +302,10 @@ public String getOwner() {
293
302
* is an instance of OutputStream class.
294
303
*/
295
304
public FSDataOutputStream create (Path path , FsPermission permission ,
296
- boolean overwrite , int bufferSize , short replication ,
305
+ boolean overwrite , int bufferSize , short replication ,
297
306
long blockSize , Progressable progress ) throws IOException {
298
- Path absolute = makeAbsolute (path );
307
+
308
+ Path absolute = makeAbsolute (path );
299
309
Path parent = null ;
300
310
File f = null ;
301
311
File fParent = null ;
@@ -311,32 +321,9 @@ public FSDataOutputStream create(Path path, FsPermission permission,
311
321
}
312
322
313
323
parent = path .getParent ();
314
- fParent = new File ((makeAbsolute (parent )).toUri ().getPath ());
315
- if ((parent != null ) && (fParent != null ) && (!fParent .exists ())) {
316
- if (!fParent .mkdirs ()) {
317
- //
318
- // File.mkdirs() is not multi-process safe. It is possible for
319
- // a peer who is running mkdirs() to cause us to fail. In such
320
- // a case, a rudimentary test is to try our exists() test for a
321
- // second time. The isDirectory() protects us from exists()
322
- // passing when a file is put in place of the directory we were
323
- // trying to create. We can be fooled by a directory, or set of
324
- // directories in the path, being owned by another user or with
325
- // incompatible permissions.
326
- //
327
- // This could be slightly improved to retry the mkdirs(), which
328
- // would cover races deep within the fParent's path. Each
329
- // iteration will address one race.
330
- //
331
- if (!fParent .exists () || !fParent .isDirectory ()) {
332
- throw new IOException ("cannot create parent directory: "
333
- + fParent .getPath ());
334
- }
335
- }
336
- }
324
+ mkdirs (parent );
337
325
338
- glusterFileStream = new FSDataOutputStream (new GlusterFUSEOutputStream (
339
- f .getPath (), false ));
326
+ glusterFileStream = new FSDataOutputStream (new GlusterFUSEOutputStream (f .getPath (), false ));
340
327
341
328
return glusterFileStream ;
342
329
}
0 commit comments