emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/dired-duplicates 4318c0c420 06/57: Sort files by name a


From: ELPA Syncer
Subject: [elpa] externals/dired-duplicates 4318c0c420 06/57: Sort files by name and grouped results by file size
Date: Sat, 4 Nov 2023 06:58:26 -0400 (EDT)

branch: externals/dired-duplicates
commit 4318c0c420ae10892f15918b458bf466edad0b79
Author: Harald Judt <h.judt@gmx.at>
Commit: Harald Judt <h.judt@gmx.at>

    Sort files by name and grouped results by file size
    
    Sort files by name (ascending) and grouped results by file size 
(descending). A
    future commit will allow to choose sorting by file size in ascending or
    descending order.
---
 find-dupes-dired.el | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/find-dupes-dired.el b/find-dupes-dired.el
index 9c7b15ec5f..79ea044260 100644
--- a/find-dupes-dired.el
+++ b/find-dupes-dired.el
@@ -39,7 +39,8 @@
 (defun find-dupes--duplicate-files (directories)
   "Given one or more root directories, search inside below the
 directories for duplicate files. Returns a hash-table with the
-generated checksums as keys and files as values."
+checksums as keys and a list of size and duplicate files as
+values."
   (cl-loop with files = (mapcan #'(lambda (d) (directory-files-recursively d 
".*"))
                                 (ensure-list directories))
            and same-size-table = (make-hash-table)
@@ -55,18 +56,29 @@ generated checksums as keys and files as values."
                              for checksum = (find-dupes-checksum-file f)
                              do (setf (gethash checksum checksum-table)
                                       (append (gethash checksum 
checksum-table) (list f)))))
-           (cl-loop for checksum being the hash-key in checksum-table using 
(hash-value same-files)
-                    when (< (length same-files) 2) do
-                    (remhash checksum checksum-table))
+           (cl-loop with size
+                    for same-files being the hash-value in checksum-table 
using (hash-key checksum)
+                    do
+                    (if (> (length same-files) 1)
+                        (setf (gethash checksum checksum-table)
+                              (cons (file-attribute-size (file-attributes 
(first same-files)))
+                                    (sort same-files #'string<)))
+                      (remhash checksum checksum-table)))
            (cl-return checksum-table)))
 
 (defun find-dupes--generate-dired-list (&optional directories)
   "Generate a list of grouped duplicate files, separated by a
 separator file specified by `find-dupes-separator-file'."
   (cl-loop with dupes-table = (find-dupes--duplicate-files (or directories
-                                                           
find-dupes-directories))
-           for files being the hash-values in dupes-table
-           appending (append files (list find-dupes-separator-file))))
+                                                               
find-dupes-directories))
+           with sorted-sums = (cl-sort
+                               (cl-loop for k being the hash-key in 
dupes-table using (hash-value v)
+                                        collect (list k (first v)))
+                               #'>
+                               :key #'second)
+           for (checksum) in sorted-sums
+           append (rest (gethash checksum dupes-table))
+           append (list find-dupes-separator-file)))
 
 (defun find-dupes-revert-function (&optional arg noconfirm)
   "Revert function used instead of `dired-revert' for dired buffers generated 
by find-dupes."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]