mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-04 07:35:53 +00:00
[FIXED JENKINS-12514]
Fixed the file overwrite problem on Windows.
This commit is contained in:
1 parent
63529f0f3e
commit
132f8b769d
2 files changed
+20
-6
No files matched your search
@@ -414,12 +414,9 @@ public abstract class PluginManager extends AbstractModelObject {
|
||||
File file = new File(rootDir, fileName);
|
||||
File pinFile = new File(rootDir, fileName+".pinned");
|
||||
|
||||
{// normalization first
|
||||
File legacyFile = new File(rootDir,legacyName);
|
||||
if (legacyFile.exists()) legacyFile.renameTo(file);
|
||||
File legacyPinFile = new File(rootDir,legacyName+".pinned");
|
||||
if (legacyPinFile.exists()) legacyPinFile.renameTo(pinFile);
|
||||
}
|
||||
// normalization first, if the old file exists.
|
||||
rename(new File(rootDir,legacyName),file);
|
||||
rename(new File(rootDir,legacyName+".pinned"),pinFile);
|
||||
|
||||
// update file if:
|
||||
// - no file exists today
|
||||
@@ -434,6 +431,20 @@ public abstract class PluginManager extends AbstractModelObject {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename a legacy file to a new name, with care to Windows where {@link File#renameTo(File)}
|
||||
* doesn't work if the destination already exists.
|
||||
*/
|
||||
private void rename(File legacyFile, File newFile) throws IOException {
|
||||
if (!legacyFile.exists()) return;
|
||||
if (newFile.exists()) {
|
||||
Util.deleteFile(newFile);
|
||||
}
|
||||
if (!legacyFile.renameTo(newFile)) {
|
||||
LOGGER.warning("Failed to rename " + legacyFile + " to " + newFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a hudson.PluginStrategy, looking at the corresponding system property.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user