Jelajahi Sumber

ADD: Ignore skipped files (issue #365)

Alexander Koblov 3 tahun lalu
induk
melakukan
038b4d5c67
1 mengubah file dengan 45 tambahan dan 3 penghapusan
  1. 45 3
      src/filesources/filesystem/ufilesystemutil.pas

+ 45 - 3
src/filesources/filesystem/ufilesystemutil.pas

@@ -126,6 +126,7 @@ type
                         var AbsoluteTargetFileName: String;
                         AllowAppend: Boolean): TFileSourceOperationOptionFileExists;
 
+    procedure SkipStatistics(aNode: TFileTreeNode);
     procedure CountStatistics(aNode: TFileTreeNode);
 
   public
@@ -1061,7 +1062,7 @@ begin
         else
             begin
               Result := False;
-              CountStatistics(CurrentSubNode);
+              SkipStatistics(CurrentSubNode);
               AppProcessMessages;
               CheckOperationState;
               Continue;
@@ -1086,7 +1087,7 @@ begin
           begin
             Result := False;
             FMaxPathOption := fsourSkip;
-            CountStatistics(CurrentSubNode);
+            SkipStatistics(CurrentSubNode);
             AppProcessMessages;
             CheckOperationState;
             Continue;
@@ -1136,7 +1137,7 @@ begin
     fsoterSkip:
       begin
         Result := False;
-        CountStatistics(aNode);
+        SkipStatistics(aNode);
       end;
 
     fsoterDeleted, fsoterNotExists:
@@ -1788,6 +1789,47 @@ begin
   end;
 end;
 
+procedure TFileSystemOperationHelper.SkipStatistics(aNode: TFileTreeNode);
+
+  procedure SkipNodeStatistics(aNode: TFileTreeNode);
+  var
+    aFileAttrs: TFileAttributesProperty;
+    i: Integer;
+  begin
+    aFileAttrs := aNode.TheFile.AttributesProperty;
+
+    with FStatistics do
+    begin
+      if aFileAttrs.IsDirectory then
+      begin
+        // No statistics for directory.
+        // Go through subdirectories.
+        for i := 0 to aNode.SubNodesCount - 1 do
+          SkipNodeStatistics(aNode.SubNodes[i]);
+      end
+      else if aFileAttrs.IsLink then
+      begin
+        // Count only not-followed links.
+        if aNode.SubNodesCount = 0 then
+          TotalFiles := TotalFiles - 1
+        else
+          // Count target of link.
+          SkipNodeStatistics(aNode.SubNodes[0]);
+      end
+      else
+      begin
+        // Count files.
+        TotalFiles := TotalFiles - 1;
+        TotalBytes := TotalBytes - aNode.TheFile.Size;
+      end;
+    end;
+  end;
+
+begin
+  SkipNodeStatistics(aNode);
+  UpdateStatistics(FStatistics);
+end;
+
 procedure TFileSystemOperationHelper.ShowError(sMessage: String);
 begin
   if gSkipFileOpError then