You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ho...@apache.org on 2021/11/10 16:12:44 UTC

[solr] branch main updated: SOLR-15711: Fix GCSRepository to follow createDirectory API contract (#373)

This is an automated email from the ASF dual-hosted git repository.

houston pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new 401da35  SOLR-15711: Fix GCSRepository to follow createDirectory API contract (#373)
401da35 is described below

commit 401da355157ef969a80e3fd0be1bd673a7acc51a
Author: Houston Putman <ho...@apache.org>
AuthorDate: Wed Nov 10 11:12:40 2021 -0500

    SOLR-15711: Fix GCSRepository to follow createDirectory API contract (#373)
---
 .../org/apache/solr/gcs/GCSBackupRepository.java    | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

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 29fc30c..5fba087 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