فهرست منبع

When moving or duplicating a folder by drag&drop to a path that already contains a subfolder with the same name, the existing folder is overwritten

For drag&drop operations, this undoes Bug 2120 and Bug 2233.

Source commit: 2700156d41d70311f6b4d4ee53072677d8dd8fc6
Martin Prikryl 1 سال پیش
والد
کامیت
b3698f0078
4فایلهای تغییر یافته به همراه32 افزوده شده و 12 حذف شده
  1. 4 1
      source/forms/CustomScpExplorer.cpp
  2. 20 7
      source/forms/RemoteTransfer.cpp
  3. 6 3
      source/forms/RemoteTransfer.h
  4. 2 1
      source/windows/WinInterface.h

+ 4 - 1
source/forms/CustomScpExplorer.cpp

@@ -4509,16 +4509,19 @@ bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *&
     Session = Terminal;
   }
 
+  bool TargetConfirmed = false;
   if (Session == Terminal)
   {
     if (RemoteDriveView->DropTarget != NULL)
     {
       Target = RemoteDriveView->NodePathName(RemoteDriveView->DropTarget);
+      TargetConfirmed = true;
     }
     else if (RemoteDirView->DropTarget != NULL)
     {
       DebugAssert(RemoteDirView->ItemIsDirectory(RemoteDirView->DropTarget));
       Target = RemoteDirView->ItemFullFileName(RemoteDirView->DropTarget);
+      TargetConfirmed = true;
     }
     else
     {
@@ -4594,7 +4597,7 @@ bool __fastcall TCustomScpExplorerForm::RemoteTransferDialog(TManagedTerminal *&
       void * ASession = Session;
       Result = DoRemoteCopyDialog(
         Sessions.get(), Directories.get(), AllowDirectCopy, Multi, ASession, Target, FileMask, DirectCopy, Terminal,
-        DoDirectoryExists);
+        DoDirectoryExists, TargetConfirmed);
       Session = static_cast<TManagedTerminal *>(ASession);
     }
   }

+ 20 - 7
source/forms/RemoteTransfer.cpp

@@ -19,13 +19,13 @@
 bool __fastcall DoRemoteCopyDialog(
   TStrings * Sessions, TStrings * Directories,
   TDirectRemoteCopy AllowDirectCopy, bool Multi, void *& Session, UnicodeString & Target, UnicodeString & FileMask,
-  bool & DirectCopy, void * CurrentSession, TDirectoryExistsEvent OnDirectoryExists)
+  bool & DirectCopy, void * CurrentSession, TDirectoryExistsEvent OnDirectoryExists, bool TargetConfirmed)
 {
   bool Result;
   TRemoteTransferDialog * Dialog = SafeFormCreate<TRemoteTransferDialog>();
   try
   {
-    Dialog->Init(Multi, Sessions, Directories, AllowDirectCopy, CurrentSession, OnDirectoryExists);
+    Dialog->Init(Multi, Sessions, Directories, AllowDirectCopy, CurrentSession, OnDirectoryExists, TargetConfirmed);
     Result = Dialog->Execute(Session, Target, FileMask, DirectCopy);
   }
   __finally
@@ -44,8 +44,8 @@ __fastcall TRemoteTransferDialog::TRemoteTransferDialog(TComponent * Owner)
 }
 //---------------------------------------------------------------------------
 void __fastcall TRemoteTransferDialog::Init(
-  bool Multi, TStrings * Sessions, TStrings * Directories, TDirectRemoteCopy AllowDirectCopy, void * CurrentSession,
-  TDirectoryExistsEvent OnDirectoryExists)
+  bool Multi, TStrings * Sessions, TStrings * Directories, TDirectRemoteCopy AllowDirectCopy,
+  void * CurrentSession, TDirectoryExistsEvent OnDirectoryExists, bool TargetConfirmed)
 {
   FMulti = Multi;
   SessionCombo->Items = Sessions;
@@ -55,6 +55,7 @@ void __fastcall TRemoteTransferDialog::Init(
   FAllowDirectCopy = AllowDirectCopy;
   FCurrentSession = CurrentSession;
   FOnDirectoryExists = OnDirectoryExists;
+  FTargetConfirmed = TargetConfirmed;
   LoadDialogImage(Image, L"Duplicate L to R");
 }
 //---------------------------------------------------------------------------
@@ -72,20 +73,26 @@ bool __fastcall TRemoteTransferDialog::Execute(void *& Session, UnicodeString &
   DirectoryEdit->Items = CustomWinConfiguration->History[L"RemoteTarget"];
   DirectoryEdit->Text = UnixIncludeTrailingBackslash(Target) + FileMask;
   FDirectCopy = DirectCopy;
+  FOriginalTarget = Target;
   UpdateNotDirectCopyCheck();
   bool Result = (ShowModal() == DefaultResult(this));
   if (Result)
   {
     Session = GetSelectedSession();
     CustomWinConfiguration->History[L"RemoteTarget"] = DirectoryEdit->Items;
-    Target = UnixExtractFilePath(DirectoryEdit->Text);
+    Target = GetTarget();
     FileMask = GetFileMask();
     DirectCopy = !NotDirectCopyCheck->Checked;
   }
   return Result;
 }
 //---------------------------------------------------------------------------
-UnicodeString __fastcall TRemoteTransferDialog::GetFileMask()
+UnicodeString TRemoteTransferDialog::GetTarget()
+{
+  return UnixExtractFilePath(DirectoryEdit->Text);
+}
+//---------------------------------------------------------------------------
+UnicodeString TRemoteTransferDialog::GetFileMask()
 {
   return UnixExtractFileName(DirectoryEdit->Text);
 }
@@ -142,7 +149,13 @@ void __fastcall TRemoteTransferDialog::FormCloseQuery(TObject * /*Sender*/,
 {
   if (ModalResult == DefaultResult(this))
   {
-    if (FOnDirectoryExists(GetSelectedSession(), DirectoryEdit->Text))
+    bool TargetConfirmed =
+      FTargetConfirmed &&
+      UnixSamePath(GetTarget(), FOriginalTarget);
+
+    if (!TargetConfirmed &&
+        !IsFileNameMask(GetFileMask()) &&
+        FOnDirectoryExists(GetSelectedSession(), DirectoryEdit->Text))
     {
       DirectoryEdit->Text = UnixCombinePaths(DirectoryEdit->Text, AnyMask);
     }

+ 6 - 3
source/forms/RemoteTransfer.h

@@ -34,14 +34,15 @@ public:
   __fastcall TRemoteTransferDialog(TComponent * Owner);
 
   void __fastcall Init(
-    bool Multi, TStrings * Sessions, TStrings * Directories, TDirectRemoteCopy AllowDirectCopy, void * CurrentSession,
-    TDirectoryExistsEvent OnDirectoryExists);
+    bool Multi, TStrings * Sessions, TStrings * Directories, TDirectRemoteCopy AllowDirectCopy,
+    void * CurrentSession, TDirectoryExistsEvent OnDirectoryExists, bool TargetConfirmed);
   bool __fastcall Execute(void *& Session, UnicodeString & Target,
     UnicodeString & FileMask, bool & DirectCopy);
 
 protected:
   void __fastcall UpdateControls();
-  UnicodeString __fastcall GetFileMask();
+  UnicodeString GetTarget();
+  UnicodeString GetFileMask();
   bool __fastcall IsCurrentSessionSelected();
   void * GetSelectedSession();
   void __fastcall UpdateNotDirectCopyCheck();
@@ -53,6 +54,8 @@ private:
   bool FMulti;
   TDirectRemoteCopy FAllowDirectCopy;
   TDirectoryExistsEvent FOnDirectoryExists;
+  bool FTargetConfirmed;
+  UnicodeString FOriginalTarget;
 
   INTERFACE_HOOK;
 };

+ 2 - 1
source/windows/WinInterface.h

@@ -335,7 +335,8 @@ enum TDirectRemoteCopy { drcDisallow, drcAllow, drcConfirmCommandSession, drcCon
 bool __fastcall DoRemoteCopyDialog(
   TStrings * Sessions, TStrings * Directories,
   TDirectRemoteCopy AllowDirectCopy, bool Multi, void *& Session, UnicodeString & Target, UnicodeString & FileMask,
-  bool & DirectCopy, void * CurrentSession, TDirectoryExistsEvent OnDirectoryExists);
+  bool & DirectCopy, void * CurrentSession, TDirectoryExistsEvent OnDirectoryExists,
+  bool TargetConfirmed);
 
 // forms\SelectMask.cpp
 bool __fastcall DoSelectMaskDialog(TControl * Parent, bool Select, TFileFilter & Filter);