Update FilePath.delete* to use Util.delete*

This reduces duplication of file deletion strategy code and potentially fixes a regression noted in JENKINS-55448.

Signed-off-by: Matt Sicker <boards@gmail.com>
This commit is contained in:
Matt Sicker committed 2019-01-10 11:00:54 -06:00
1 parent 4c6160d710
commit c05d00ad69
1 file changed
+2 -25
+2 -25
View File
@@ -1271,7 +1271,7 @@ public final class FilePath implements Serializable {
private static final long serialVersionUID = 1L;
@Override
public Void invoke(File f, VirtualChannel channel) throws IOException {
deleteRecursive(deleting(f));
Util.deleteRecursive(deleting(f));
return null;
}
}
@@ -1286,34 +1286,11 @@ public final class FilePath implements Serializable {
private static final long serialVersionUID = 1L;
@Override
public Void invoke(File f, VirtualChannel channel) throws IOException {
deleteContentsRecursive(f);
Util.deleteContentsRecursive(deleting(f));
return null;
}
}
private void deleteRecursive(File dir) throws IOException {
if(!isSymlink(dir))
deleteContentsRecursive(dir);
try {
deleteFile(deleting(dir));
} catch (IOException e) {
// if some of the child directories are big, it might take long enough to delete that
// it allows others to create new files, causing problems like JENKINS-10113
// so give it one more attempt before we give up.
if(!isSymlink(dir))
deleteContentsRecursive(dir);
deleteFile(deleting(dir));
}
}
private void deleteContentsRecursive(File file) throws IOException {
File[] files = file.listFiles();
if(files==null)
return; // the directory didn't exist in the first place
for (File child : files)
deleteRecursive(child);
}
/**
* Gets the file name portion except the extension.
*