Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,28 +157,7 @@ public boolean delete() throws IOException, InterruptedException {
LOGGER.log(Level.FINE, "Ignoring blob deletion: {0}", blobPath);
return false;
}
return delete(provider, getContext().getBlobStore(), blobPath);
}

/**
* Delete all blobs starting with prefix
*/
public static boolean delete(BlobStoreProvider provider, BlobStore blobStore, String prefix) throws IOException, InterruptedException {
try {
Iterator<StorageMetadata> it = new JCloudsVirtualFile.PageSetIterable(blobStore, provider.getContainer(), ListContainerOptions.Builder.prefix(prefix).recursive());
boolean found = false;
while (it.hasNext()) {
StorageMetadata sm = it.next();
String path = sm.getName();
assert path.startsWith(prefix);
LOGGER.fine("deleting " + path);
blobStore.removeBlob(provider.getContainer(), path);
found = true;
}
return found;
} catch (RuntimeException x) {
throw new IOException(x);
}
return JCloudsVirtualFile.delete(provider, getContext().getBlobStore(), blobPath);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@
import java.net.URI;
import java.net.URL;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Deque;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Spliterator;
Expand Down Expand Up @@ -402,4 +404,30 @@ private Deque<CacheFrame> cacheFrames() {
return cacheFrames().stream().filter(frame -> key.startsWith(frame.root)).findFirst().orElse(null);
}

/**
* Delete all blobs starting with a given prefix.
*/
public static boolean delete(BlobStoreProvider provider, BlobStore blobStore, String prefix) throws IOException, InterruptedException {
try {
Iterator<StorageMetadata> it = new PageSetIterable(blobStore, provider.getContainer(), ListContainerOptions.Builder.prefix(prefix).recursive());
List<String> paths = new ArrayList<>();
while (it.hasNext()) {
StorageMetadata sm = it.next();
String path = sm.getName();
assert path.startsWith(prefix);
paths.add(path);
}
if (paths.isEmpty()) {
LOGGER.log(Level.FINE, "nothing to delete under {0}", prefix);
return false;
} else {
LOGGER.log(Level.FINE, "deleting {0} blobs under {1}", new Object[] {paths.size(), prefix});
blobStore.removeBlobs(provider.getContainer(), paths);
return true;
}
} catch (RuntimeException x) {
throw new IOException(x);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import io.jenkins.plugins.artifact_manager_jclouds.BlobStoreProvider;
import io.jenkins.plugins.artifact_manager_jclouds.JCloudsVirtualFile;
import io.jenkins.plugins.artifact_manager_jclouds.JCloudsArtifactManager;
import com.amazonaws.SdkClientException;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;

Expand Down Expand Up @@ -123,7 +122,7 @@ public void tearDown() throws Exception {

@After
public void deleteBlobs() throws Exception {
JCloudsArtifactManager.delete(provider, blobStore, prefix);
JCloudsVirtualFile.delete(provider, blobStore, prefix);
}

}