Selaa lähdekoodia

FIX: Delete to trash with file paths containing spaces. Fix reading error from gvfs-trash.

cobines 15 vuotta sitten
vanhempi
commit
69c492d34e
3 muutettua tiedostoa jossa 29 lisäystä ja 10 poistoa
  1. 11 6
      src/platform/uOSUtils.pas
  2. 3 3
      src/uacts.pas
  3. 15 1
      src/udcutils.pas

+ 11 - 6
src/platform/uOSUtils.pas

@@ -1525,11 +1525,16 @@ end;
 var f: textfile;
     s: string;
 begin
-  popen(f, _PATH_GVFS_TRASH + #32 + FileName, 'r');     // try to delete.
-  readln(f,s);
-  If (Pos('Error trashing',s) = 1) then Result := false // 17.05.2009 - return result from gvfs-trash;
-  else Result := true;
-  pclose(f);
+  // Open pipe to gvfs-trash to read the output in case of error.
+  // The errors are written to stderr hence "2>&1" is needed because popen only catches stdout.
+  if popen(f, _PATH_GVFS_TRASH + #32 + QuoteStr(FileName) + ' 2>&1', 'r') = 0 then
+  begin
+    readln(f,s);
+    Result := not StrBegins(s, 'Error trashing');
+    pclose(f);
+  end
+  else
+   Result := False;
 end;
 {$ENDIF}
 // --------------------------------------------------------------------------------
@@ -2005,4 +2010,4 @@ finalization
 
 {$ENDIF}
 
-end.
+end.

+ 3 - 3
src/uacts.pas

@@ -1401,9 +1401,9 @@ begin
     end;
 
     if (((gUseTrash = True) and ((param = '') or (param = 'recyclesetting'))) or
-       ((gUseTrash = False) and (param = 'recyclesettingrev')) or
-       (param = 'recycle') and
-       FileSource.IsClass(TFileSystemFileSource)) and
+        ((gUseTrash = False) and (param = 'recyclesettingrev')) or
+        (param = 'recycle')) and
+       FileSource.IsClass(TFileSystemFileSource) and
        mbCheckTrash(CurrentPath) then
     begin
       bRecycle := True;

+ 15 - 1
src/udcutils.pas

@@ -260,6 +260,14 @@ procedure StrDisposeW(var pStr : PWideChar);
 function StrLCopyW(Dest, Source: PWideChar; MaxLen: SizeInt): PWideChar;
 function StrPCopyW(Dest: PWideChar; const Source: WideString): PWideChar;
 function StrPLCopyW(Dest: PWideChar; const Source: WideString; MaxLen: Cardinal): PWideChar;
+
+{en
+   Checks if a string begins with another string.
+   @returns(@true if StringToCheck begins with StringToMatch.
+            StringToCheck may be longer than StringToMatch.)
+}
+function StrBegins(const StringToCheck, StringToMatch: String): Boolean;
+
 {en
    Convert a number specified as an octal number to it's decimal value.
    @param(Value Octal number as string)
@@ -960,6 +968,12 @@ begin
   Result := StrLCopyW(Dest, PWideChar(Source), MaxLen);
 end;
 
+function StrBegins(const StringToCheck, StringToMatch: String): Boolean;
+begin
+  Result := (Length(StringToCheck) >= Length(StringToMatch)) and
+            (CompareChar(StringToCheck[1], StringToMatch[1], Length(StringToMatch)) = 0);
+end;
+
 function OctToDec(Value: String): LongInt;
 var
   I: Integer;
@@ -1011,4 +1025,4 @@ begin
 end;
 
 end.
-
+