Skip to content

Commit b4b3361

Browse files
author
Vladimir Kotal
committed
swallow FileAlreadyExistsException in doLink()
fixes #2464
1 parent 244aa65 commit b4b3361

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/index/PendingFileCompleter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.io.File;
2727
import java.io.IOException;
2828
import java.nio.file.DirectoryStream;
29+
import java.nio.file.FileAlreadyExistsException;
2930
import java.nio.file.FileVisitResult;
3031
import java.nio.file.Files;
3132
import java.nio.file.Path;
@@ -360,7 +361,7 @@ private void doLink(PendingSymlinkageExec lnk) throws IOException {
360361
deleteFileOrDirectory(sourcePath);
361362

362363
File sourceParentFile = sourcePath.getParent().toFile();
363-
/**
364+
/*
364365
* The double check-exists in the following conditional is necessary
365366
* because during a race when two threads are simultaneously linking
366367
* for a not-yet-existent `sourceParentFile`, the first check-exists
@@ -372,11 +373,16 @@ private void doLink(PendingSymlinkageExec lnk) throws IOException {
372373
sourceParentFile.exists()) {
373374
Files.createSymbolicLink(sourcePath, Paths.get(lnk.targetRel));
374375
}
376+
} catch (FileAlreadyExistsException e) {
377+
// Another case of racing threads. Given that each of them works with the same path,
378+
// there is no need to worry.
379+
return;
375380
} catch (IOException e) {
376381
LOGGER.log(Level.WARNING, "Failed to link: {0} -> {1}",
377382
new Object[]{lnk.source, lnk.targetRel});
378383
throw e;
379384
}
385+
380386
if (LOGGER.isLoggable(Level.FINEST)) {
381387
LOGGER.log(Level.FINEST, "Linked pending: {0} -> {1}",
382388
new Object[]{lnk.source, lnk.targetRel});

0 commit comments

Comments
 (0)