Skip to content

Commit

Permalink
[JENKINS-18459] reporting where it's failing to write to assist diagn…
Browse files Browse the repository at this point in the history
…ostics
  • Loading branch information
kohsuke committed Jul 26, 2013
1 parent d0334ba commit 8c85a77
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/main/java/hudson/remoting/FileSystemJarCache.java
Expand Up @@ -57,28 +57,32 @@ protected URL retrieve(Channel channel, long sum1, long sum2) throws IOException
File target = map(sum1, sum2);
File parent = target.getParentFile();
parent.mkdirs();
File tmp = File.createTempFile(target.getName(),"tmp", parent);
try {
RemoteOutputStream o = new RemoteOutputStream(new FileOutputStream(tmp));
File tmp = File.createTempFile(target.getName(),"tmp", parent);
try {
LOGGER.log(Level.FINE, String.format("Retrieving jar file %16X%16X",sum1,sum2));
getJarLoader(channel).writeJarTo(sum1, sum2, o);
} finally {
o.close();
}
RemoteOutputStream o = new RemoteOutputStream(new FileOutputStream(tmp));
try {
LOGGER.log(Level.FINE, String.format("Retrieving jar file %16X%16X",sum1,sum2));
getJarLoader(channel).writeJarTo(sum1, sum2, o);
} finally {
o.close();
}

tmp.renameTo(target);
tmp.renameTo(target);

if (target.exists()) {
// even if we fail to rename, we are OK as long as the target actually exists at this point
// this can happen if two FileSystejarCache instances share the same cache dir
return target.toURI().toURL();
}
if (target.exists()) {
// even if we fail to rename, we are OK as long as the target actually exists at this point
// this can happen if two FileSystejarCache instances share the same cache dir
return target.toURI().toURL();
}

// for example if the file system went read only in the mean time
throw new IOException("Unable to create "+target+" from "+tmp);
} finally {
tmp.delete();
// for example if the file system went read only in the mean time
throw new IOException("Unable to create "+target+" from "+tmp);
} finally {
tmp.delete();
}
} catch (IOException e) {
throw (IOException)new IOException("Failed to write to "+target).initCause(e);
}
}

Expand Down

0 comments on commit 8c85a77

Please sign in to comment.