emacs-diffs
[Top][All Lists]
Advanced

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

emacs-27 6cd9ccb: Fix compression of directories in Dired


From: Eli Zaretskii
Subject: emacs-27 6cd9ccb: Fix compression of directories in Dired
Date: Wed, 8 Jan 2020 11:23:22 -0500 (EST)

branch: emacs-27
commit 6cd9ccb0a28ec03ffe180b7429e0378511b7d459
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Fix compression of directories in Dired
    
    This fixes comporession and uncompression of directories on
    MS-Windows, but also on other systems.  The original code used
    ":" as the REGEXP of the directory entry in
    dired-compress-file-suffixes, which on Windows always matched any
    absolute file name, and can also match unusual file names on Posix
    hosts.  This false match would cause dired-compress-file to act as
    if we are decompressing a directory, but use a command suitable
    for compression, which would fail in interesting ways.
    We now use a REGEXP that can never match any valid file name.
    
    * lisp/dired-aux.el (dired-compress-file-suffixes): Make the
    "compress directory" entry's REGEXP really fail to match any valid
    file name.
    (dired-compress-file): Adapt to the change in
    dired-compress-file-suffixes.  (Bug#39024)
    (dired-compress): If the current file is a directory, or if the
    uncompressed file is a directory, don't remove the original from
    the listing, since it is left in the filesystem.
---
 lisp/dired-aux.el | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 59d389d..0069c17 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -992,7 +992,14 @@ command with a prefix argument (the value does not 
matter)."
          (ignore-errors (dired-remove-entry new-file))
          (goto-char start)
          ;; Now replace the current line with an entry for NEW-FILE.
-         (dired-update-file-line new-file) nil)
+         ;; But don't remove the current line if either FROM-FILE or
+         ;; NEW-FILE is a directory, because compressing/uncompressing
+          ;; directories doesn't remove the original.
+          (if (or (file-directory-p from-file)
+                  (file-directory-p new-file))
+              (dired-add-entry new-file nil t)
+            (dired-update-file-line new-file))
+          nil)
       (dired-log (concat "Failed to (un)compress " from-file))
       from-file)))
 
@@ -1020,8 +1027,9 @@ command with a prefix argument (the value does not 
matter)."
     ("\\.7z\\'" "" "7z x -aoa -o%o %i")
     ;; This item controls naming for compression.
     ("\\.tar\\'" ".tgz" nil)
-    ;; This item controls the compression of directories
-    (":" ".tar.gz" "tar -cf - %i | gzip -c9 > %o"))
+    ;; This item controls the compression of directories.  Its REGEXP
+    ;; element should never match any valid file name.
+    ("\000" ".tar.gz" "tar -cf - %i | gzip -c9 > %o"))
   "Control changes in file name suffixes for compression and uncompression.
 Each element specifies one transformation rule, and has the form:
   (REGEXP NEW-SUFFIX PROGRAM)
@@ -1145,7 +1153,7 @@ Return nil if no change in files."
            (condition-case nil
                (if (file-directory-p file)
                    (progn
-                     (setq suffix (cdr (assoc ":" 
dired-compress-file-suffixes)))
+                     (setq suffix (cdr (assoc "\000" 
dired-compress-file-suffixes)))
                      (when suffix
                        (let ((out-name (concat file (car suffix)))
                              (default-directory (file-name-directory file)))



reply via email to

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