Skip to content

Commit

Permalink
[JENKINS-20534] Avoid usage of temporary file to write symlink.
Browse files Browse the repository at this point in the history
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.

(cherry picked from commit c0742b8)
  • Loading branch information
Vlatombe authored and olivergondza committed Feb 26, 2014
1 parent ab54f13 commit f768fb7
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions core/src/main/java/jenkins/model/PeepholePermalink.java
Expand Up @@ -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();
}
}
}

Expand Down

0 comments on commit f768fb7

Please sign in to comment.