Browse Source

Bug 2042: Compatibility with Google Cloud S3 API when deleting implicitly existing directories

https://winscp.net/tracker/2042

Source commit: 53f16330ad215a521520eb9ca7dbaef7b667fe99
Martin Prikryl 4 years ago
parent
commit
c441ee1998
1 changed files with 18 additions and 2 deletions
  1. 18 2
      source/core/S3FileSystem.cpp

+ 18 - 2
source/core/S3FileSystem.cpp

@@ -1190,13 +1190,29 @@ void __fastcall TS3FileSystem::DeleteFile(const UnicodeString AFileName,
       BucketContext.protocol, BucketContext.uriStyle, BucketContext.accessKeyId, BucketContext.secretAccessKey,
       BucketContext.securityToken, BucketContext.hostName, BucketContext.bucketName, BucketContext.authRegion,
       FRequestContext, FTimeout, &ResponseHandler, &Data);
+    CheckLibS3Error(Data);
   }
   else
   {
     S3_delete_object(&BucketContext, StrToS3(Key), FRequestContext, FTimeout, &ResponseHandler, &Data);
+    try
+    {
+      CheckLibS3Error(Data);
+    }
+    catch (...)
+    {
+      if (FTerminal->Active && Dir && !FTerminal->FileExists(AFileName))
+      {
+        // Amazon silently ignores attampts to delete non existing folders,
+        // But Google Cloud fails that.
+        FTerminal->LogEvent(L"Folder does not exist anymore, it was probably only virtual");
+      }
+      else
+      {
+        throw;
+      }
+    }
   }
-
-  CheckLibS3Error(Data);
 }
 //---------------------------------------------------------------------------
 void __fastcall TS3FileSystem::RenameFile(const UnicodeString FileName, const TRemoteFile * File,