Skip to content

Commit

Permalink
Merge pull request #194 from perfectsense/feature/remote-backend-delete
Browse files Browse the repository at this point in the history
Remote file backend to delete file only if exists.
  • Loading branch information
Jeremy Collins authored Jul 24, 2020
2 parents 0cf7b2e + 2e95b56 commit 1572d8b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/java/gyro/google/GoogleStorageFileBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
import java.io.OutputStream;
import java.util.stream.Stream;

import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.ByteArrayContent;
import com.google.api.services.storage.Storage;
import com.google.api.services.storage.model.StorageObject;

import com.psddev.dari.util.ObjectUtils;

import gyro.core.FileBackend;
import gyro.core.GyroException;
import gyro.core.Type;
Expand Down Expand Up @@ -94,7 +93,14 @@ public void close() {

@Override
public void delete(String file) throws Exception {
client().objects().delete(getBucket(), prefixed(file)).execute();
// Delete if exists.
try {
client().objects().delete(getBucket(), prefixed(file)).execute();
} catch (GoogleJsonResponseException e) {
if (e.getStatusCode() != 404) {
throw e;
}
}
}

private Storage client() {
Expand Down

0 comments on commit 1572d8b

Please sign in to comment.