فهرست منبع

Logging decisions on not doing resumable transfer when overwriting an existing SFTP file

Source commit: c46da9c6cc69009d1aa07d39715dc0af6405e952
Martin Prikryl 9 سال پیش
والد
کامیت
c714cdb8be
3فایلهای تغییر یافته به همراه30 افزوده شده و 12 حذف شده
  1. 19 8
      source/core/SftpFileSystem.cpp
  2. 10 4
      source/core/Terminal.cpp
  3. 1 0
      source/core/Terminal.h

+ 19 - 8
source/core/SftpFileSystem.cpp

@@ -4652,28 +4652,39 @@ void __fastcall TSFTPFileSystem::SFTPSource(const UnicodeString FileName,
 
 
           if (DestFileExists)
           if (DestFileExists)
           {
           {
+            FTerminal->LogEvent(FORMAT(L"File exists: %s", (FTerminal->GetRemoteFileInfo(File))));
             OpenParams.DestFileSize = File->Size;
             OpenParams.DestFileSize = File->Size;
             FileParams.DestSize = OpenParams.DestFileSize;
             FileParams.DestSize = OpenParams.DestFileSize;
             FileParams.DestTimestamp = File->Modification;
             FileParams.DestTimestamp = File->Modification;
             DestRights = *File->Rights;
             DestRights = *File->Rights;
-            // - If destination file is symlink, never do resumable transfer,
+            // If destination file is symlink, never do resumable transfer,
             // as it would delete the symlink.
             // as it would delete the symlink.
-            // - Also bit of heuristics to detect symlink on SFTP-3 and older
+            if (File->IsSymLink)
+            {
+              ResumeAllowed = false;
+              FTerminal->LogEvent(L"Existing file is symbolic link, not doing resumable transfer.");
+            }
+            // Also bit of heuristics to detect symlink on SFTP-3 and older
             // (which does not indicate symlink in SSH_FXP_ATTRS).
             // (which does not indicate symlink in SSH_FXP_ATTRS).
             // if file has all permissions and is small, then it is likely symlink.
             // if file has all permissions and is small, then it is likely symlink.
             // also it is not likely that such a small file (if it is not symlink)
             // also it is not likely that such a small file (if it is not symlink)
             // gets overwritten by large file (that would trigger resumable transfer).
             // gets overwritten by large file (that would trigger resumable transfer).
-            // - Also never do resumable transfer for file owned by other user
+            else if ((FVersion < 4) &&
+                     ((*File->Rights & TRights::rfAll) == TRights::rfAll) &&
+                     (File->Size < 100))
+            {
+              ResumeAllowed = false;
+              FTerminal->LogEvent(L"Existing file looks like a symbolic link, not doing resumable transfer.");
+            }
+            // Also never do resumable transfer for file owned by other user
             // as deleting and recreating the file would change ownership.
             // as deleting and recreating the file would change ownership.
             // This won't for work for SFTP-3 (OpenSSH) as it does not provide
             // This won't for work for SFTP-3 (OpenSSH) as it does not provide
             // owner name (only UID) and we know only logged in user name (not UID)
             // owner name (only UID) and we know only logged in user name (not UID)
-            if (File->IsSymLink ||
-                ((FVersion < 4) &&
-                 ((*File->Rights & TRights::rfAll) == TRights::rfAll) &&
-                 (File->Size < 100)) ||
-                (!File->Owner.Name.IsEmpty() && !SameUserName(File->Owner.Name, FTerminal->UserName)))
+            else if (!File->Owner.Name.IsEmpty() && !SameUserName(File->Owner.Name, FTerminal->UserName))
             {
             {
               ResumeAllowed = false;
               ResumeAllowed = false;
+              FTerminal->LogEvent(
+                FORMAT(L"Existing file is owned by another user [%s], not doing resumable transfer.", (File->Owner.Name)));
             }
             }
 
 
             delete File;
             delete File;

+ 10 - 4
source/core/Terminal.cpp

@@ -2732,15 +2732,21 @@ void __fastcall TTerminal::ReadDirectory(bool ReloadOnly, bool ForceCache)
   }
   }
 }
 }
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
+UnicodeString __fastcall TTerminal::GetRemoteFileInfo(TRemoteFile * File)
+{
+  return
+    FORMAT(L"%s;%s;%d;%s;%d;%s;%s;%s;%d",
+      (File->FileName, File->Type, File->Size, StandardTimestamp(File->Modification), int(File->ModificationFmt),
+       File->Owner.LogText, File->Group.LogText, File->Rights->Text,
+       File->Attr));
+}
+//---------------------------------------------------------------------------
 void __fastcall TTerminal::LogRemoteFile(TRemoteFile * File)
 void __fastcall TTerminal::LogRemoteFile(TRemoteFile * File)
 {
 {
   // optimization
   // optimization
   if (Log->Logging)
   if (Log->Logging)
   {
   {
-    LogEvent(FORMAT(L"%s;%s;%d;%s;%d;%s;%s;%s;%d",
-      (File->FileName, File->Type, File->Size, StandardTimestamp(File->Modification), int(File->ModificationFmt),
-       File->Owner.LogText, File->Group.LogText, File->Rights->Text,
-       File->Attr)));
+    LogEvent(GetRemoteFileInfo(File));
   }
   }
 }
 }
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------

+ 1 - 0
source/core/Terminal.h

@@ -372,6 +372,7 @@ protected:
   TRemoteFileList * __fastcall DoReadDirectoryListing(UnicodeString Directory, bool UseCache);
   TRemoteFileList * __fastcall DoReadDirectoryListing(UnicodeString Directory, bool UseCache);
   RawByteString __fastcall EncryptPassword(const UnicodeString & Password);
   RawByteString __fastcall EncryptPassword(const UnicodeString & Password);
   UnicodeString __fastcall DecryptPassword(const RawByteString & Password);
   UnicodeString __fastcall DecryptPassword(const RawByteString & Password);
+  UnicodeString __fastcall GetRemoteFileInfo(TRemoteFile * File);
   void __fastcall LogRemoteFile(TRemoteFile * File);
   void __fastcall LogRemoteFile(TRemoteFile * File);
   UnicodeString __fastcall FormatFileDetailsForLog(const UnicodeString & FileName, TDateTime Modification, __int64 Size);
   UnicodeString __fastcall FormatFileDetailsForLog(const UnicodeString & FileName, TDateTime Modification, __int64 Size);
   void __fastcall LogFileDetails(const UnicodeString & FileName, TDateTime Modification, __int64 Size);
   void __fastcall LogFileDetails(const UnicodeString & FileName, TDateTime Modification, __int64 Size);