Procházet zdrojové kódy

Prevent recursive directory tree updates when changes happen too frequently

Attempt to fix Bug 2024
https://winscp.net/tracker/2024

(cherry picked from commit fc8df43a35e42915fef405e8d5d7ee96051fdf77)

Source commit: 4e4858579f1761909bc88145dc46f361abd7a235
Martin Prikryl před 4 roky
rodič
revize
6aaf724d66
1 změnil soubory, kde provedl 17 přidání a 9 odebrání
  1. 17 9
      source/packages/filemng/DriveView.pas

+ 17 - 9
source/packages/filemng/DriveView.pas

@@ -2039,16 +2039,24 @@ begin
     begin
       if DriveStatusPair.Value.ChangeTimer = Sender then
       begin
-        with DriveStatusPair.Value.ChangeTimer do
-        begin
-          Interval := 0;
-          Enabled := False;
-        end;
+        // Messages are processed during ValidateDirectory, so we may detect another change while
+        // updating the directory. Prevent the recursion.
+        // But retry the update afterwards (by reenabling the timer in ChangeDetected)
+        SuspendChangeTimer;
+        try
+          with DriveStatusPair.Value.ChangeTimer do
+          begin
+            Interval := 0;
+            Enabled := False;
+          end;
 
-        if Assigned(DriveStatusPair.Value.RootNode) then
-        begin
-          {Check also collapsed (invisible) subdirectories:}
-          ValidateDirectory(DriveStatusPair.Value.RootNode);
+          if Assigned(DriveStatusPair.Value.RootNode) then
+          begin
+            {Check also collapsed (invisible) subdirectories:}
+            ValidateDirectory(DriveStatusPair.Value.RootNode);
+          end;
+        finally
+          ResumeChangeTimer;
         end;
       end;
     end;