mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-06 16:45:58 +00:00
[JENKINS-16215] Avoiding unnecessary downloads in FilePath.installIfNecessaryFrom.
The updated version uses the locally cached timestamp, '.timestamp', to set the 'If-Modified-Since' header. 304 Not Modified responses are dealt with by aborting the installation.
This commit is contained in:
1 parent
d43b978f92
commit
35f7653b7b
2 files changed
+86
-1
No files matched your search
@@ -77,6 +77,7 @@ import java.io.Serializable;
|
||||
import java.io.Writer;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
@@ -682,9 +683,13 @@ public final class FilePath implements Serializable {
|
||||
*/
|
||||
public boolean installIfNecessaryFrom(URL archive, TaskListener listener, String message) throws IOException, InterruptedException {
|
||||
try {
|
||||
FilePath timestamp = this.child(".timestamp");
|
||||
URLConnection con;
|
||||
try {
|
||||
con = ProxyConfiguration.open(archive);
|
||||
if (timestamp.exists()) {
|
||||
con.setIfModifiedSince(timestamp.lastModified());
|
||||
}
|
||||
con.connect();
|
||||
} catch (IOException x) {
|
||||
if (this.exists()) {
|
||||
@@ -697,8 +702,13 @@ public final class FilePath implements Serializable {
|
||||
throw x;
|
||||
}
|
||||
}
|
||||
|
||||
if (con instanceof HttpURLConnection
|
||||
&& ((HttpURLConnection)con).getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
long sourceTimestamp = con.getLastModified();
|
||||
FilePath timestamp = this.child(".timestamp");
|
||||
|
||||
if(this.exists()) {
|
||||
if(timestamp.exists() && sourceTimestamp ==timestamp.lastModified())
|
||||
|
||||
Reference in new issue
Block a user