mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-08 09:36:04 +00:00
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
This commit is contained in:
1 parent
b86b2d7226
commit
b4af8a5a2a
1 file changed
+4
-2
@@ -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();
|
||||
|
||||
|
||||
Reference in new issue
Block a user