提交 0efdf8fb 编写于 作者: H hplatou 提交者: Oleg Nenashev

[JENKINS-13153] - Use directory from env:BASE when writing jenkins.copies (#2992)

[JENKINS-13153] - Use directory from env:BASE when writing jenkins.copies
上级 8189c2cd
......@@ -60,20 +60,20 @@ public class WindowsServiceLifecycle extends Lifecycle {
*/
private void updateJenkinsExeIfNeeded() {
try {
File rootDir = Jenkins.getInstance().getRootDir();
File baseDir = getBaseDir();
URL exe = getClass().getResource("/windows-service/jenkins.exe");
String ourCopy = Util.getDigestOf(exe.openStream());
for (String name : new String[]{"hudson.exe","jenkins.exe"}) {
try {
File currentCopy = new File(rootDir,name);
File currentCopy = new File(baseDir,name);
if(!currentCopy.exists()) continue;
String curCopy = new FilePath(currentCopy).digest();
if(ourCopy.equals(curCopy)) continue; // identical
File stage = new File(rootDir,name+".new");
File stage = new File(baseDir,name+".new");
FileUtils.copyURLToFile(exe,stage);
Kernel32.INSTANCE.MoveFileExA(stage.getAbsolutePath(),currentCopy.getAbsolutePath(),MOVEFILE_DELAY_UNTIL_REBOOT|MOVEFILE_REPLACE_EXISTING);
LOGGER.info("Scheduled a replacement of "+name);
......@@ -107,8 +107,8 @@ public class WindowsServiceLifecycle extends Lifecycle {
String baseName = dest.getName();
baseName = baseName.substring(0,baseName.indexOf('.'));
File rootDir = Jenkins.getInstance().getRootDir();
File copyFiles = new File(rootDir,baseName+".copies");
File baseDir = getBaseDir();
File copyFiles = new File(baseDir,baseName+".copies");
try (FileWriter w = new FileWriter(copyFiles, true)) {
w.write(by.getAbsolutePath() + '>' + getHudsonWar().getAbsolutePath() + '\n');
......@@ -144,6 +144,19 @@ public class WindowsServiceLifecycle extends Lifecycle {
if(r!=0)
throw new IOException(baos.toString());
}
private static final File getBaseDir() {
File baseDir;
String baseEnv = System.getenv("BASE");
if (baseEnv != null) {
baseDir = new File(baseEnv);
} else {
LOGGER.log(Level.WARNING, "Could not find environment variable 'BASE' for Jenkins base directory. Falling back to JENKINS_HOME");
baseDir = Jenkins.getInstance().getRootDir();
}
return baseDir;
}
private static final Logger LOGGER = Logger.getLogger(WindowsServiceLifecycle.class.getName());
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册