@@ -218,43 +218,29 @@ public boolean isFilePathCaseSensitive() {
218
218
219
219
@ Override
220
220
public boolean createDirectory (Path path ) throws IOException {
221
+ File file = getIoFile (path );
222
+ if (file .mkdir ()) {
223
+ return true ;
224
+ }
221
225
222
- // We always synchronize on the current path before doing it on the parent path and file system
223
- // path structure ensures that this locking order will never be reversed.
224
- // When refactoring, check that subclasses still work as expected and there can be no
225
- // deadlocks.
226
- synchronized (path ) {
227
- File file = getIoFile (path );
228
- if (file .mkdir ()) {
229
- return true ;
230
- }
231
-
232
- // We will be checking the state of the parent path as well. Synchronize on it before
233
- // attempting anything.
234
- Path parentDirectory = path .getParentDirectory ();
235
- synchronized (parentDirectory ) {
236
- if (fileIsSymbolicLink (file )) {
237
- throw new IOException (path + ERR_FILE_EXISTS );
238
- }
239
- if (file .isDirectory ()) {
240
- return false ; // directory already existed
241
- } else if (file .exists ()) {
242
- throw new IOException (path + ERR_FILE_EXISTS );
243
- } else if (!file .getParentFile ().exists ()) {
244
- throw new FileNotFoundException (path .getParentDirectory () + ERR_NO_SUCH_FILE_OR_DIR );
245
- }
246
- // Parent directory apparently exists - try to create our directory again - protecting
247
- // against the case where parent directory would be created right before us obtaining
248
- // synchronization lock.
249
- if (file .mkdir ()) {
250
- return true ; // Everything is fine finally.
251
- } else if (!file .getParentFile ().canWrite ()) {
252
- throw new FileAccessException (path + ERR_PERMISSION_DENIED );
253
- } else {
254
- // Parent exists, is writable, yet we can't create our directory.
255
- throw new FileNotFoundException (path .getParentDirectory () + ERR_NOT_A_DIRECTORY );
256
- }
257
- }
226
+ if (fileIsSymbolicLink (file )) {
227
+ throw new IOException (path + ERR_FILE_EXISTS );
228
+ }
229
+ if (file .isDirectory ()) {
230
+ return false ; // directory already existed
231
+ } else if (file .exists ()) {
232
+ throw new IOException (path + ERR_FILE_EXISTS );
233
+ } else if (!file .getParentFile ().exists ()) {
234
+ throw new FileNotFoundException (path .getParentDirectory () + ERR_NO_SUCH_FILE_OR_DIR );
235
+ }
236
+ // Parent directory apparently exists - try to create our directory again.
237
+ if (file .mkdir ()) {
238
+ return true ; // Everything is fine finally.
239
+ } else if (!file .getParentFile ().canWrite ()) {
240
+ throw new FileAccessException (path + ERR_PERMISSION_DENIED );
241
+ } else {
242
+ // Parent exists, is writable, yet we can't create our directory.
243
+ throw new FileNotFoundException (path .getParentDirectory () + ERR_NOT_A_DIRECTORY );
258
244
}
259
245
}
260
246
@@ -323,26 +309,24 @@ protected PathFragment readSymbolicLink(Path path) throws IOException {
323
309
324
310
@ Override
325
311
public void renameTo (Path sourcePath , Path targetPath ) throws IOException {
326
- synchronized (sourcePath ) {
327
- File sourceFile = getIoFile (sourcePath );
328
- File targetFile = getIoFile (targetPath );
329
- if (!sourceFile .renameTo (targetFile )) {
330
- if (!sourceFile .exists ()) {
331
- throw new FileNotFoundException (sourcePath + ERR_NO_SUCH_FILE_OR_DIR );
332
- }
333
- if (targetFile .exists ()) {
334
- if (targetFile .isDirectory () && targetFile .list ().length > 0 ) {
335
- throw new IOException (targetPath + ERR_DIRECTORY_NOT_EMPTY );
336
- } else if (sourceFile .isDirectory () && targetFile .isFile ()) {
337
- throw new IOException (sourcePath + " -> " + targetPath + ERR_NOT_A_DIRECTORY );
338
- } else if (sourceFile .isFile () && targetFile .isDirectory ()) {
339
- throw new IOException (sourcePath + " -> " + targetPath + ERR_IS_DIRECTORY );
340
- } else {
341
- throw new IOException (sourcePath + " -> " + targetPath + ERR_PERMISSION_DENIED );
342
- }
312
+ File sourceFile = getIoFile (sourcePath );
313
+ File targetFile = getIoFile (targetPath );
314
+ if (!sourceFile .renameTo (targetFile )) {
315
+ if (!sourceFile .exists ()) {
316
+ throw new FileNotFoundException (sourcePath + ERR_NO_SUCH_FILE_OR_DIR );
317
+ }
318
+ if (targetFile .exists ()) {
319
+ if (targetFile .isDirectory () && targetFile .list ().length > 0 ) {
320
+ throw new IOException (targetPath + ERR_DIRECTORY_NOT_EMPTY );
321
+ } else if (sourceFile .isDirectory () && targetFile .isFile ()) {
322
+ throw new IOException (sourcePath + " -> " + targetPath + ERR_NOT_A_DIRECTORY );
323
+ } else if (sourceFile .isFile () && targetFile .isDirectory ()) {
324
+ throw new IOException (sourcePath + " -> " + targetPath + ERR_IS_DIRECTORY );
343
325
} else {
344
- throw new FileAccessException (sourcePath + " -> " + targetPath + ERR_PERMISSION_DENIED );
326
+ throw new IOException (sourcePath + " -> " + targetPath + ERR_PERMISSION_DENIED );
345
327
}
328
+ } else {
329
+ throw new FileAccessException (sourcePath + " -> " + targetPath + ERR_PERMISSION_DENIED );
346
330
}
347
331
}
348
332
}
@@ -361,22 +345,20 @@ protected long getFileSize(Path path, boolean followSymlinks) throws IOException
361
345
public boolean delete (Path path ) throws IOException {
362
346
File file = getIoFile (path );
363
347
long startTime = Profiler .nanoTimeMaybe ();
364
- synchronized (path ) {
365
- try {
366
- if (file .delete ()) {
367
- return true ;
368
- }
369
- if (file .exists ()) {
370
- if (file .isDirectory () && file .list ().length > 0 ) {
371
- throw new IOException (path + ERR_DIRECTORY_NOT_EMPTY );
372
- } else {
373
- throw new IOException (path + ERR_PERMISSION_DENIED );
374
- }
348
+ try {
349
+ if (file .delete ()) {
350
+ return true ;
351
+ }
352
+ if (file .exists ()) {
353
+ if (file .isDirectory () && file .list ().length > 0 ) {
354
+ throw new IOException (path + ERR_DIRECTORY_NOT_EMPTY );
355
+ } else {
356
+ throw new IOException (path + ERR_PERMISSION_DENIED );
375
357
}
376
- return false ;
377
- } finally {
378
- profiler .logSimpleTask (startTime , ProfilerTask .VFS_DELETE , file .getPath ());
379
358
}
359
+ return false ;
360
+ } finally {
361
+ profiler .logSimpleTask (startTime , ProfilerTask .VFS_DELETE , file .getPath ());
380
362
}
381
363
}
382
364
0 commit comments