提交 132f8b76 编写于 作者: K Kohsuke Kawaguchi

[FIXED JENKINS-12514]

Fixed the file overwrite problem on Windows.
上级 63529f0f
......@@ -55,6 +55,9 @@ Upcoming changes</a>
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=bug>
Fixed a bug in the auto-overwrite of bundled plugins on Windows.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-12514">issue 12514</a>)
<li class=bug>
Fixed a temporary memory spike when dealing with rapidly growing large console output and interactive monitoring.
<li class=bug>
......
......@@ -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.
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册