Skip to content

Commit dd8120b

Browse files
idodeclareVladimir Kotal
authored andcommitted
Fix #2148 : mkdirs() in doLink() in case no other related content
When a leaf directory consists solely of symlinks to other local directories -- i.e. with no other content or child content to xref, then the xref/ directory would not have been created to contain the duplicated symlinks.
1 parent 493447d commit dd8120b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/org/opensolaris/opengrok/index/PendingFileCompleter.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,20 @@ private void doLink(PendingSymlinkageExec lnk) throws IOException {
350350
}
351351
Path sourcePath = Paths.get(lnk.source);
352352
deleteFileOrDirectory(sourcePath);
353-
Files.createSymbolicLink(sourcePath, Paths.get(lnk.targetRel));
353+
354+
File sourceParentFile = sourcePath.getParent().toFile();
355+
/**
356+
* The double check-exists in the following conditional is necessary
357+
* because during a race when two threads are simultaneously linking
358+
* for a not-yet-existent `sourceParentFile`, the first check-exists
359+
* will be false for both threads, but then only one will see true
360+
* from mkdirs -- so the other needs a fallback again to
361+
* check-exists.
362+
*/
363+
if (sourceParentFile.exists() || sourceParentFile.mkdirs() ||
364+
sourceParentFile.exists()) {
365+
Files.createSymbolicLink(sourcePath, Paths.get(lnk.targetRel));
366+
}
354367
} catch (IOException e) {
355368
LOGGER.log(Level.WARNING, "Failed to link: {0} -> {1}",
356369
new Object[]{lnk.source, lnk.targetRel});

0 commit comments

Comments
 (0)