Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-15711: Fix GCSRepository to follow createDirectory API contract (#373)

Houston Putman401da355157e
diff --git a/solr/contrib/gcs-repository/src/java/org/apache/solr/gcs/GCSBackupRepository.java b/solr/contrib/gcs-repository/src/java/org/apache/solr/gcs/GCSBackupRepository.java
index 29fc30c4f07..5fba08777bd 100644
--- a/solr/contrib/gcs-repository/src/java/org/apache/solr/gcs/GCSBackupRepository.java
+++ b/solr/contrib/gcs-repository/src/java/org/apache/solr/gcs/GCSBackupRepository.java
@@ -175,19 +175,22 @@ public class GCSBackupRepository implements BackupRepository {
@Override
public boolean exists(URI path) throws IOException {
- if (path.toString().equals(getConfigProperty(CoreAdminParams.BACKUP_LOCATION))) {
+ return exists(path.toString());
+ }
+
+ public boolean exists(String path) throws IOException {
+ if (path.equals(getConfigProperty(CoreAdminParams.BACKUP_LOCATION))) {
return true;
}
- if (path.toString().endsWith("/")) {
- return storage.get(bucketName, path.toString(), Storage.BlobGetOption.fields()) != null;
+ if (path.endsWith("/")) {
+ return storage.get(bucketName, path, Storage.BlobGetOption.fields()) != null;
} else {
- final String filePath = path.toString();
- final String directoryPath = path.toString() + "/";
+ final String filePath = path;
+ final String directoryPath = path + "/";
return storage.get(bucketName, filePath, Storage.BlobGetOption.fields()) != null ||
- storage.get(bucketName, directoryPath, Storage.BlobGetOption.fields()) != null;
+ storage.get(bucketName, directoryPath, Storage.BlobGetOption.fields()) != null;
}
-
}
@Override
@@ -293,7 +296,9 @@ public class GCSBackupRepository implements BackupRepository {
@Override
public void createDirectory(URI path) throws IOException {
final String name = appendTrailingSeparatorIfNecessary(path.toString());
- storage.create(BlobInfo.newBuilder(bucketName, name).build()) ;
+ if (!exists(name)) {
+ storage.create(BlobInfo.newBuilder(bucketName, name).build());
+ }
}
@Override