Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-12514]
Fixed the file overwrite problem on Windows.
  • Loading branch information
kohsuke committed Mar 10, 2012
1 parent 63529f0 commit 132f8b7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -55,6 +55,9 @@
<!-- 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>
Expand Down
23 changes: 17 additions & 6 deletions core/src/main/java/hudson/PluginManager.java
Expand Up @@ -414,12 +414,9 @@ protected void copyBundledPlugin(URL src, String fileName) throws IOException {
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
Expand All @@ -434,6 +431,20 @@ protected void copyBundledPlugin(URL src, String fileName) throws IOException {
}
}

/**
* 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.
*/
Expand Down

0 comments on commit 132f8b7

Please sign in to comment.