mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-10 02:26:18 +00:00
JENKINS-41805 Cleanup workspace suffixes (#4824)
This commit is contained in:
1 parent
55d1b9e387
commit
e9dc2694db
4 files changed
+58
-6
No files matched your search
@@ -48,6 +48,7 @@ import hudson.remoting.RemoteOutputStream;
|
||||
import hudson.remoting.VirtualChannel;
|
||||
import hudson.remoting.Which;
|
||||
import hudson.security.AccessControlled;
|
||||
import hudson.slaves.WorkspaceList;
|
||||
import hudson.util.DaemonThreadFactory;
|
||||
import hudson.util.DirScanner;
|
||||
import hudson.util.ExceptionCatchingThreadFactory;
|
||||
@@ -1257,6 +1258,44 @@ public final class FilePath implements SerializableOnlyOverRemoting {
|
||||
return mkdirs(f) || f.exists();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all suffixes recursively.
|
||||
* @throws IOException if it exists but could not be successfully deleted
|
||||
* @since TODO
|
||||
*/
|
||||
public void deleteSuffixesRecursive() throws IOException, InterruptedException {
|
||||
act(new DeleteSuffixesRecursive());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all suffixed directories that are separated by {@link WorkspaceList#COMBINATOR}, including all its contents recursively.
|
||||
*/
|
||||
private class DeleteSuffixesRecursive extends SecureFileCallable<Void> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public Void invoke(File f, VirtualChannel channel) throws IOException {
|
||||
for (File file : listParentFiles(f)) {
|
||||
if (file.getName().startsWith(f.getName() + WorkspaceList.COMBINATOR)) {
|
||||
Util.deleteRecursive(file.toPath(), path -> deleting(path.toFile()));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static File[] listParentFiles(File f) {
|
||||
File parentFile = f.getParentFile();
|
||||
if (parentFile != null) {
|
||||
File[] files = parentFile.listFiles();
|
||||
if (files != null) {
|
||||
return files;
|
||||
}
|
||||
}
|
||||
return new File[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes this directory, including all its contents recursively.
|
||||
|
||||
Reference in new issue
Block a user