Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Clean up FilePath. Extract one method out and ensure closing of input stream after copy #462

Merged
merged 1 commit into from almost 2 years ago

2 participants

Jerome Lacoste Nicolas De loof
Jerome Lacoste
Collaborator

No description provided.

Nicolas De loof ndeloof merged commit d621c00 into from May 01, 2012
Nicolas De loof ndeloof closed this May 01, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

May 01, 2012
Jerome Lacoste Clean up FilePath. Extract one method out, and ensure closing of inpu…
…t stream after copy
4aab81f
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 12 additions and 8 deletions. Show diff stats Hide diff stats

  1. 20  core/src/main/java/hudson/FilePath.java
20  core/src/main/java/hudson/FilePath.java
@@ -213,17 +213,18 @@ public FilePath(File localPath) {
213 213
      */
214 214
     public FilePath(FilePath base, String rel) {
215 215
         this.channel = base.channel;
216  
-        if(isAbsolute(rel)) {
217  
-            // absolute
218  
-            this.remote = normalize(rel);
219  
-        } else 
  216
+        this.remote = normalize(resolvePathIfRelative(base, rel));
  217
+    }
  218
+
  219
+    private String resolvePathIfRelative(FilePath base, String rel) {
  220
+        if(isAbsolute(rel)) return rel;
220 221
         if(base.isUnix()) {
221 222
             // shouldn't need this replace, but better safe than sorry
222  
-            this.remote = normalize(base.remote+'/'+rel.replace('\\','/'));
  223
+            return base.remote+'/'+rel.replace('\\','/');
223 224
         } else {
224 225
             // need this replace, see Slave.getWorkspaceFor and AbstractItem.getFullName, nested jobs on Windows
225 226
             // slaves will always have a rel containing at least one '/' character. JENKINS-13649
226  
-            this.remote = normalize(base.remote+'\\'+rel.replace('/','\\'));
  227
+            return base.remote+'\\'+rel.replace('/','\\');
227 228
         }
228 229
     }
229 230
 
@@ -781,8 +782,11 @@ public void copyFrom(FileItem file) throws IOException, InterruptedException {
781 782
             try {
782 783
                 IOUtils.copy(i,o);
783 784
             } finally {
784  
-                o.close();
785  
-                i.close();
  785
+                try {
  786
+                    o.close();
  787
+                } finally {
  788
+                    i.close();
  789
+                }
786 790
             }
787 791
         }
788 792
     }
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.