Browse Source

Bug fix: Trying to enter an invalid link in local panel fails silently

Source commit: 07b147ef2fb10b257763ab06ba45f22d70f18162
Martin Prikryl 3 months ago
parent
commit
6e9bfb7dbd

+ 2 - 9
source/packages/filemng/DirView.pas

@@ -2804,19 +2804,12 @@ begin
     if PFileRec(Item.Data)^.IsDirectory then
     begin
       FileName := ItemFullFileName(Item);
-      if not DirectoryExistsFix(FileName) then
-      begin
-        Reload2;
-        if Assigned(FDriveView) and Assigned(FDriveView.Selected) then
-          with FDriveView do
-            ValidateDirectory(Selected);
-        Exit;
-      end;
     end
       else
     FileName := ResolveFileShortCut(ItemFullFileName(Item), True);
 
-    if DirectoryExistsFix(FileName) then
+    // Don't check link target existence, if is does not exist, let it fail later, so that an error message is shown
+    if DirectoryExistsFix(FileName, False) then
     begin
       Path := FileName;
       Exit;

+ 2 - 0
source/packages/filemng/DriveView.pas

@@ -1362,6 +1362,7 @@ begin
         FChangeFlag := True;
         FLastDir := NewDir;
 
+        // Most of this is done already in CanChange and possibly redundant here
         OldSerial := DriveInfo.Get(Drive).DriveSerial;
         DriveInfo.ReadDriveStatus(Drive, dsSize or dsImageIndex);
         with DriveInfo.Get(Drive) do
@@ -1373,6 +1374,7 @@ begin
           begin
             if not DirectoryExists(ApiPath(NewDir)) then
             begin
+              // Unlikely to ever happen, as CanChange already tests the directory
               ValidateDirectory(GetDriveStatus(Drive).RootNode);
               Exit;
             end;

+ 3 - 3
source/packages/my/PasTools.pas

@@ -72,7 +72,7 @@ procedure ForceColorChange(Control: TWinControl);
 
 function IsUncPath(Path: string): Boolean;
 function FileExistsFix(Path: string): Boolean;
-function DirectoryExistsFix(Path: string): Boolean;
+function DirectoryExistsFix(Path: string; FollowLink: Boolean = True): Boolean;
 
 const
   FIND_FIRST_EX_LARGE_FETCH_PAS = 2; // VCLCOPY (actually should be part of Winapi)
@@ -1049,11 +1049,11 @@ begin
   Result := DoExists(FileExists(ApiPath(Path)), Path);
 end;
 
-function DirectoryExistsFix(Path: string): Boolean;
+function DirectoryExistsFix(Path: string; FollowLink: Boolean): Boolean;
 begin
   // WORKAROUND
   SetLastError(ERROR_SUCCESS);
-  Result := DoExists(DirectoryExists(ApiPath(Path)), Path);
+  Result := DoExists(DirectoryExists(ApiPath(Path), FollowLink), Path);
 end;
 
 // VCLCOPY