Skip to content
Permalink
Browse files
[JENKINS-20534] Avoid usage of temporary file to write symlink.
Creating a symlink is an atomic operation, and additionally
usage of tmp file + rename performs very badly on NTFS file
system because of the way the rename is tracked in the $MFT.

In case symbolic links are not supported, we still fallback to
a regular file.
  • Loading branch information
Vlatombe committed Dec 13, 2013
1 parent 0c2b722 commit c0742b8bff9fe407e568da7ed860f30d9ea8aedc
Showing with 11 additions and 19 deletions.
  1. +11 −19 core/src/main/java/jenkins/model/PeepholePermalink.java
@@ -167,25 +167,17 @@ static String readSymlink(File cache) throws IOException, InterruptedException {
static void writeSymlink(File cache, String target) throws IOException, InterruptedException {
StringWriter w = new StringWriter();
StreamTaskListener listener = new StreamTaskListener(w);
File tmp = new File(cache.getPath()+".tmp");
try {
Util.createSymlink(tmp.getParentFile(),target,tmp.getName(),listener);
// Avoid calling resolveSymlink on a nonexistent file as it will probably throw an IOException:
if (!exists(tmp) || Util.resolveSymlink(tmp)==null) {
// symlink not supported. use a regular file
AtomicFileWriter cw = new AtomicFileWriter(cache);
try {
cw.write(target);
cw.commit();
} finally {
cw.abort();
}
} else {
cache.delete();
tmp.renameTo(cache);
}
} finally {
tmp.delete();
Util.createSymlink(cache.getParentFile(),target,cache.getName(),listener);
// Avoid calling resolveSymlink on a nonexistent file as it will probably throw an IOException:
if (!exists(cache) || Util.resolveSymlink(cache)==null) {
// symlink not supported. use a regular file
AtomicFileWriter cw = new AtomicFileWriter(cache);
try {
cw.write(target);
cw.commit();
} finally {
cw.abort();
}
}
}

0 comments on commit c0742b8

Please sign in to comment.