Browse Source

Bug fix: Path argument in lcd command in generated script has to end with backslash, if it points to a root folder

Source commit: e4ce718547362fac3d4f944415741ef4e19387b2
Martin Prikryl 7 years ago
parent
commit
f6171cd883
1 changed files with 12 additions and 2 deletions
  1. 12 2
      source/forms/GenerateUrl.cpp

+ 12 - 2
source/forms/GenerateUrl.cpp

@@ -21,6 +21,16 @@
 const UnicodeString AllFilesMask(L"*");
 const UnicodeString NoOpOperationMask(L"*");
 //---------------------------------------------------------------------------
+static UnicodeString ExcludeTrailingBackslashUnlessRoot(const UnicodeString & Path)
+{
+  UnicodeString Result = ExcludeTrailingBackslash(Path);
+  if (SameText(Result, ExtractFileDrive(Result)))
+  {
+    Result = IncludeTrailingBackslash(Path);
+  }
+  return Result;
+}
+//---------------------------------------------------------------------------
 void __fastcall DoGenerateUrlDialog(TSessionData * Data, TStrings * Paths)
 {
   std::unique_ptr<TGenerateUrlDialog> Dialog(
@@ -133,7 +143,7 @@ __fastcall TGenerateUrlDialog::TGenerateUrlDialog(
     if (FToRemote)
     {
       UnicodeString FirstPath = Paths->Strings[0];
-      FSourcePath = FToRemote ? ExcludeTrailingBackslash(ExtractFilePath(FirstPath)) : UnixExtractFilePath(FirstPath);
+      FSourcePath = FToRemote ? ExcludeTrailingBackslashUnlessRoot(ExtractFilePath(FirstPath)) : UnixExtractFilePath(FirstPath);
       for (int Index = 0; Index < FPaths->Count; Index++)
       {
         FPaths->Strings[Index] = ExtractFileName(FPaths->Strings[Index]);
@@ -306,7 +316,7 @@ UnicodeString __fastcall TGenerateUrlDialog::GenerateScript(UnicodeString & Scri
     else
     {
       Commands.push_back(RtfScriptCommand(L"cd") + L" " + RtfText(QuoteStringParam(FSourcePath)));
-      Commands.push_back(RtfScriptCommand(L"lcd") + L" " + RtfText(QuoteStringParam(ExcludeTrailingBackslash(FPath))));
+      Commands.push_back(RtfScriptCommand(L"lcd") + L" " + RtfText(QuoteStringParam(ExcludeTrailingBackslashUnlessRoot(FPath))));
       TransferCommand = L"get";
     }