Skip to content

Commit

Permalink
Fixes to delete a file only if it exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Sung committed Jul 10, 2020
1 parent 0cf7b2e commit 2e95b56
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 2e95b56

Please sign in to comment.