Răsfoiți Sursa

Bug 1850: Support clearing GID/UID flag on directories with new versions of GNU coreutils

https://winscp.net/tracker/1850
(cherry picked from commit e31f0b66c788618b2697f80824ba87d8f4607116)

Source commit: cd1683ffc98036433af968f26191c562d3db7062
Martin Prikryl 5 ani în urmă
părinte
comite
98527fe824
3 a modificat fișierele cu 16 adăugiri și 8 ștergeri
  1. 10 3
      source/core/RemoteFiles.cpp
  2. 2 2
      source/core/RemoteFiles.h
  3. 4 3
      source/core/ScpFileSystem.cpp

+ 10 - 3
source/core/RemoteFiles.cpp

@@ -2431,16 +2431,23 @@ bool  __fastcall TRights::GetReadOnly()
   return Right[rrUserWrite] && Right[rrGroupWrite] && Right[rrOtherWrite];
 }
 //---------------------------------------------------------------------------
-UnicodeString __fastcall TRights::GetSimplestStr() const
+UnicodeString __fastcall TRights::GetChmodStr(int Directory) const
 {
+  UnicodeString Result;
   if (IsUndef)
   {
-    return ModeStr;
+    Result = ModeStr;
   }
   else
   {
-    return Octal;
+    Result = Octal;
+    if (Directory != 0) // unknown or folder
+    {
+      // New versions of coreutils need leading 5th zero to unset UID/GID for directories
+      Result = UnicodeString(L"0") + Result;
+    }
   }
+  return Result;
 }
 //---------------------------------------------------------------------------
 UnicodeString __fastcall TRights::GetModeStr() const

+ 2 - 2
source/core/RemoteFiles.h

@@ -368,10 +368,11 @@ public:
   __fastcall operator unsigned short() const;
   __fastcall operator unsigned long() const;
 
+  UnicodeString __fastcall GetChmodStr(int Directory) const;
+
   __property bool AllowUndef = { read = FAllowUndef, write = SetAllowUndef };
   __property bool IsUndef = { read = GetIsUndef };
   __property UnicodeString ModeStr = { read = GetModeStr };
-  __property UnicodeString SimplestStr = { read = GetSimplestStr };
   __property UnicodeString Octal = { read = GetOctal, write = SetOctal };
   __property unsigned short Number = { read = GetNumber, write = SetNumber };
   __property unsigned short NumberSet = { read = FSet };
@@ -392,7 +393,6 @@ private:
 
   bool __fastcall GetIsUndef() const;
   UnicodeString __fastcall GetModeStr() const;
-  UnicodeString __fastcall GetSimplestStr() const;
   void __fastcall SetNumber(unsigned short value);
   UnicodeString __fastcall GetText() const;
   void __fastcall SetText(const UnicodeString & value);

+ 4 - 3
source/core/ScpFileSystem.cpp

@@ -1237,7 +1237,8 @@ void __fastcall TSCPFileSystem::ChangeFileProperties(const UnicodeString FileNam
   TChmodSessionAction & Action)
 {
   DebugAssert(Properties);
-  bool IsDirectory = File && File->IsDirectory;
+  int Directory = ((File == NULL) ? -1 : (File->IsDirectory ? 1 : 0));
+  bool IsDirectory = (Directory > 0);
   bool Recursive = Properties->Recursive && IsDirectory;
   UnicodeString RecursiveStr = Recursive ? L"-R" : L"";
 
@@ -1269,7 +1270,7 @@ void __fastcall TSCPFileSystem::ChangeFileProperties(const UnicodeString FileNam
     if ((Rights.NumberSet | Rights.NumberUnset) != TRights::rfNo)
     {
       ExecCommand(fsChangeMode,
-        ARRAYOFCONST((RecursiveStr, Rights.SimplestStr, DelimitedName)));
+        ARRAYOFCONST((RecursiveStr, Rights.GetChmodStr(Directory), DelimitedName)));
     }
 
     // if file is directory and we do recursive mode settings with
@@ -1278,7 +1279,7 @@ void __fastcall TSCPFileSystem::ChangeFileProperties(const UnicodeString FileNam
     {
       Rights.AddExecute();
       ExecCommand(fsChangeMode,
-        ARRAYOFCONST((L"", Rights.SimplestStr, DelimitedName)));
+        ARRAYOFCONST((L"", Rights.GetChmodStr(Directory), DelimitedName)));
     }
   }
   else