提交 b4af8a5a 编写于 作者: M mindless

Fix createSymlink so it overwrites existing link properly if the existing

link points to a non-existent file/dir (in this case File.exists() returns
false, so it was not removed before creating new symlink).
This change also avoids exec of "rm -rf" when simple File.delete() succeeds.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@23972 71c3de6d-444a-0410-be80-ed276b4c234a
上级 b86b2d72
......@@ -318,7 +318,7 @@ public class Util {
fileInCanonicalParent = new File( parentDir.getCanonicalPath(), name );
}
return !fileInCanonicalParent.getCanonicalFile().equals( fileInCanonicalParent.getAbsoluteFile() );
}
}
/**
* Creates a new temporary directory.
......@@ -960,8 +960,10 @@ public class Util {
if(!isWindows() && !NO_SYMLINK) {
try {
// if a file or a directory exists here, delete it first.
// try simple delete first (whether exists() or not, as it may be symlink pointing
// to non-existent target), but fallback to "rm -rf" to delete non-empty dir.
File symlinkFile = new File(baseDir, symlinkPath);
if (symlinkFile.exists())
if (!symlinkFile.delete() && symlinkFile.exists())
// ignore a failure.
new LocalProc(new String[]{"rm","-rf", symlinkPath},new String[0],listener.getLogger(), baseDir).join();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册