浏览代码

Bug 1462: Failure when moving "Download and Delete" operation to background

https://winscp.net/tracker/1462

Source commit: 42d3c5fdb7da6d49bb4f49a3188663a75ed2b5b4
Martin Prikryl 9 年之前
父节点
当前提交
5a0adb82f9
共有 3 个文件被更改,包括 27 次插入1 次删除
  1. 11 0
      source/core/RemoteFiles.cpp
  2. 3 0
      source/core/RemoteFiles.h
  3. 13 1
      source/forms/CustomScpExplorer.cpp

+ 11 - 0
source/core/RemoteFiles.cpp

@@ -1479,6 +1479,17 @@ void __fastcall TRemoteFileList::AddFile(TRemoteFile * File)
   File->Directory = this;
 }
 //---------------------------------------------------------------------------
+TStrings * __fastcall TRemoteFileList::CloneStrings(TStrings * List)
+{
+  std::unique_ptr<TStringList> Result(new TStringList());
+  for (int Index = 0; Index < List->Count; Index++)
+  {
+    TRemoteFile * File = static_cast<TRemoteFile *>(List->Objects[Index]);
+    Result->AddObject(List->Strings[Index], File);
+  }
+  return Result.release();
+}
+//---------------------------------------------------------------------------
 void __fastcall TRemoteFileList::DuplicateTo(TRemoteFileList * Copy)
 {
   Copy->Reset();

+ 3 - 0
source/core/RemoteFiles.h

@@ -217,6 +217,9 @@ public:
   TRemoteFile * __fastcall FindFile(const UnicodeString &FileName);
   virtual void __fastcall DuplicateTo(TRemoteFileList * Copy);
   virtual void __fastcall AddFile(TRemoteFile * File);
+
+  static TStrings * __fastcall CloneStrings(TStrings * List);
+
   __property UnicodeString Directory = { read = FDirectory, write = SetDirectory };
   __property TRemoteFile * Files[Integer Index] = { read = GetFiles };
   __property UnicodeString FullDirectory  = { read=GetFullDirectory };

+ 13 - 1
source/forms/CustomScpExplorer.cpp

@@ -2295,10 +2295,15 @@ bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Oper
 
         try
         {
+          TStrings * PermanentFileList;
+          std::unique_ptr<TStrings> PermanentFileListOwner;
+
           try
           {
             if (Side == osLocal)
             {
+              PermanentFileList = FileList;
+
               Params |= FLAGMASK(Temp, cpTemporary);
               Terminal->CopyToRemote(FileList, TargetDirectory, &CopyParam, Params);
               if (Operation == foMove)
@@ -2313,6 +2318,13 @@ bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Oper
             }
             else
             {
+              // Clone the file list as it may refer to current directory files,
+              // which get destroyed, when the source directory is reloaded after foMove operation.
+              // We should actually clone the file list for whole ExecuteFileOperation to protect against reloads.
+              // But for a hotfix, we are not going to do such a big change.
+              PermanentFileListOwner.reset(TRemoteFileList::CloneStrings(FileList));
+              PermanentFileList = PermanentFileListOwner.get();
+
               try
               {
                 Terminal->CopyToLocal(FileList, TargetDirectory, &CopyParam,
@@ -2355,7 +2367,7 @@ bool __fastcall TCustomScpExplorerForm::ExecuteFileOperation(TFileOperation Oper
 
               Configuration->Usage->Inc("MovesToBackground");
 
-              AddQueueItem(Queue, Direction, FileList, TargetDirectory, CopyParam, Params);
+              AddQueueItem(Queue, Direction, PermanentFileList, TargetDirectory, CopyParam, Params);
               ClearTransferSourceSelection(Direction);
             }