فهرست منبع

Bug 2086: Restore previous behaviour with MVS systems

https://winscp.net/tracker/2086
(cherry picked from commit 7996f5831a28317622d0ff255758e1b916d033bd)

Source commit: 342921fc1a29b58feb43b8052f25e1e39969e27e
Martin Prikryl 3 سال پیش
والد
کامیت
7045b9f259
2فایلهای تغییر یافته به همراه30 افزوده شده و 70 حذف شده
  1. 30 67
      source/core/FtpFileSystem.cpp
  2. 0 3
      source/core/FtpFileSystem.h

+ 30 - 67
source/core/FtpFileSystem.cpp

@@ -847,21 +847,6 @@ void __fastcall TFTPFileSystem::Discard()
   }
 }
 //---------------------------------------------------------------------------
-UnicodeString TFTPFileSystem::MakeUnixAbsolutePath(const UnicodeString & Path)
-{
-  UnicodeString Result = Path;
-  if ((Result.Length() > 0) && !UnixIsAbsolutePath(Result))
-  {
-    Result = L"/" + Result;
-  }
-  return Result;
-}
-//---------------------------------------------------------------------------
-bool TFTPFileSystem::IsMVSAbsolutePath(const UnicodeString & Path)
-{
-  return (Path.Length() >= 3) && StartsStr(L"'", Path) && EndsStr(L"'", Path);
-}
-//---------------------------------------------------------------------------
 UnicodeString __fastcall TFTPFileSystem::AbsolutePath(UnicodeString Path, bool /*Local*/)
 {
   // TODO: improve (handle .. etc.)
@@ -869,10 +854,6 @@ UnicodeString __fastcall TFTPFileSystem::AbsolutePath(UnicodeString Path, bool /
   {
     return Path;
   }
-  else if (FMVS && IsMVSAbsolutePath(Path))
-  {
-    return MakeUnixAbsolutePath(Path);
-  }
   else
   {
     return ::AbsolutePath(FCurrentDirectory, Path);
@@ -881,16 +862,9 @@ UnicodeString __fastcall TFTPFileSystem::AbsolutePath(UnicodeString Path, bool /
 //---------------------------------------------------------------------------
 UnicodeString __fastcall TFTPFileSystem::ActualCurrentDirectory()
 {
-  UnicodeString Result;
-  Result.SetLength(1024);
-  FFileZillaIntf->GetCurrentPath(Result.c_str(), Result.Length());
-  PackStr(Result);
-  if (FMVS)
-  {
-    Result = MakeUnixAbsolutePath(Result);
-  }
-  Result = UnixExcludeTrailingBackslash(Result);
-  return Result;
+  wchar_t CurrentPath[1024];
+  FFileZillaIntf->GetCurrentPath(CurrentPath, LENOF(CurrentPath));
+  return UnixExcludeTrailingBackslash(CurrentPath);
 }
 //---------------------------------------------------------------------------
 void __fastcall TFTPFileSystem::EnsureLocation(const UnicodeString & Directory, bool Log)
@@ -1625,10 +1599,10 @@ void __fastcall TFTPFileSystem::CopyToLocal(TStrings * FilesToCopy,
 UnicodeString TFTPFileSystem::RemoteExtractFilePath(const UnicodeString & Path)
 {
   UnicodeString Result;
-  // If the path ends with a slash, FZAPI CServerPath contructor does not identify the path as VMS nor MVS.
+  // If the path ends with a slash, FZAPI CServerPath contructor does not identify the path as VMS.
   // It is probably ok to use UnixExtractFileDir for all paths passed to FZAPI,
-  // but for now, we limit the impact of the change to VMS/MVS.
-  if (FVMS || FMVS)
+  // but for now, we limit the impact of the change to VMS.
+  if (FVMS)
   {
     Result = UnixExtractFileDir(Path);
   }
@@ -1905,29 +1879,7 @@ void __fastcall TFTPFileSystem::DoStartup()
   }
 
   // retrieve initialize working directory to save it as home directory
-  UnicodeString RawPwd = DoReadCurrentDirectory();
-
-  // Full name is "MVS is the operating system of this server. FTP Server is running on ..."
-  // (the ... can be "z/OS")
-  // https://www.ibm.com/docs/en/zos/latest?topic=2rc-215-mvs-is-operating-system-this-server-ftp-server-is-running-name
-  // FZPI has a different incompatible detection.
-  // MVS FTP servers have two separate MVS and Unix file systems cooexisting in the same session.
-  // Use the "MVS mode" only if we are starting in the MVS file system.
-  // WinSCP cannot handle switching between these two file system in one session.
-  FMVS = (FSystem.SubString(1, 3) == L"MVS") && !UnixIsAbsolutePath(RawPwd);
-  if (FMVS)
-  {
-    FTerminal->LogEvent(L"MVS system detected.");
-  }
-
-  // Other systems are detected in HandleReplyStatus
-
-  if ((FWorkFromCwd == asAuto) && (FVMS || FMVS))
-  {
-    FTerminal->LogEvent(L"Server is known to require use of relative paths");
-    FWorkFromCwd = asOn;
-  }
-
+  ReadCurrentDirectory();
   FHomeDirectory = FCurrentDirectory;
 }
 //---------------------------------------------------------------------------
@@ -2010,12 +1962,6 @@ void __fastcall TFTPFileSystem::LookupUsersGroups()
 //---------------------------------------------------------------------------
 void __fastcall TFTPFileSystem::ReadCurrentDirectory()
 {
-  DoReadCurrentDirectory();
-}
-//---------------------------------------------------------------------------
-UnicodeString TFTPFileSystem::DoReadCurrentDirectory()
-{
-  UnicodeString Path;
   // ask the server for current directory on startup only
   // and immediately after call to CWD,
   // later our current directory may be not synchronized with FZAPI current
@@ -2038,7 +1984,7 @@ UnicodeString TFTPFileSystem::DoReadCurrentDirectory()
       if (((Code == 257) || FTerminal->SessionData->FtpAnyCodeForPwd) &&
           (Response->Count == 1))
       {
-        Path = Response->Text;
+        UnicodeString Path = Response->Text;
 
         int P = Path.Pos(L"\"");
         if (P == 0)
@@ -2064,7 +2010,11 @@ UnicodeString TFTPFileSystem::DoReadCurrentDirectory()
 
         if (Result)
         {
-          FCurrentDirectory = UnixExcludeTrailingBackslash(MakeUnixAbsolutePath(Path));
+          if ((Path.Length() > 0) && !UnixIsAbsolutePath(Path))
+          {
+            Path = L"/" + Path;
+          }
+          FCurrentDirectory = UnixExcludeTrailingBackslash(Path);
           FReadCurrentDirectory = false;
         }
       }
@@ -2083,7 +2033,6 @@ UnicodeString TFTPFileSystem::DoReadCurrentDirectory()
       delete Response;
     }
   }
-  return Path;
 }
 //---------------------------------------------------------------------------
 void __fastcall TFTPFileSystem::DoReadDirectory(TRemoteFileList * FileList)
@@ -2469,7 +2418,7 @@ void __fastcall TFTPFileSystem::ReadFile(const UnicodeString FileName,
       int P;
       bool MVSPath =
         FMVS && Path.IsEmpty() &&
-        IsMVSAbsolutePath(FileName) &&
+        (FileName.SubString(1, 1) == L"'") && (FileName.SubString(FileName.Length(), 1) == L"'") &&
         ((P = FileName.Pos(L".")) > 0);
       if (!MVSPath)
       {
@@ -3555,6 +3504,17 @@ void __fastcall TFTPFileSystem::HandleReplyStatus(UnicodeString Response)
         FSystem = FLastResponse->Text.TrimRight();
         // FZAPI has own detection of MVS/VMS
 
+        // Full name is "MVS is the operating system of this server. FTP Server is running on ..."
+        // (the ... can be "z/OS")
+        // https://www.ibm.com/docs/en/zos/latest?topic=2rc-215-mvs-is-operating-system-this-server-ftp-server-is-running-name
+        // FZPI has a different incompatible detection.
+        // MVS FTP servers have two separate MVS and Unix file systems cooexisting in the same session.
+        FMVS = (FSystem.SubString(1, 3) == L"MVS");
+        if (FMVS)
+        {
+          FTerminal->LogEvent(L"MVS system detected.");
+        }
+
         // The FWelcomeMessage usually contains "Microsoft FTP Service" but can be empty
         if (ContainsText(FSystem, L"Windows_NT"))
         {
@@ -3576,6 +3536,11 @@ void __fastcall TFTPFileSystem::HandleReplyStatus(UnicodeString Response)
           FTerminal->LogEvent(L"Server is known not to support LIST -a");
           FListAll = asOff;
         }
+        if ((FWorkFromCwd == asAuto) && FVMS)
+        {
+          FTerminal->LogEvent(L"Server is known to require use of relative paths");
+          FWorkFromCwd = asOn;
+        }
         // 220-FileZilla Server 1.0.1
         // 220 Please visit https://filezilla-project.org/
         // SYST
@@ -3586,8 +3551,6 @@ void __fastcall TFTPFileSystem::HandleReplyStatus(UnicodeString Response)
           FTerminal->LogEvent(L"FileZilla server detected.");
           FFileZilla = true;
         }
-
-        // MVS is detected in DoStartup
       }
       else
       {

+ 0 - 3
source/core/FtpFileSystem.h

@@ -158,8 +158,6 @@ protected:
   void __fastcall Discard();
   void __fastcall DoChangeDirectory(const UnicodeString & Directory);
   void SendCwd(const UnicodeString & Directory);
-  UnicodeString MakeUnixAbsolutePath(const UnicodeString & Path);
-  bool IsMVSAbsolutePath(const UnicodeString & Path);
 
   void __fastcall Sink(const UnicodeString FileName,
     const TRemoteFile * File, const UnicodeString TargetDir,
@@ -217,7 +215,6 @@ protected:
   bool __fastcall CanTransferSkipList(int Params, unsigned int Flags, const TCopyParamType * CopyParam);
   void __fastcall Disconnect();
   UnicodeString RemoteExtractFilePath(const UnicodeString & Path);
-  UnicodeString DoReadCurrentDirectory();
 
   static bool __fastcall Unquote(UnicodeString & Str);