]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix compression of directories in Dired
authorEli Zaretskii <eliz@gnu.org>
Wed, 8 Jan 2020 16:21:53 +0000 (18:21 +0200)
committerEli Zaretskii <eliz@gnu.org>
Wed, 8 Jan 2020 16:21:53 +0000 (18:21 +0200)
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

index 59d389dc630b5d175da0baf3e01d224cac324ad7..0069c1744dcc562f608f74d6693d4b5b8e7acad6 100644 (file)
@@ -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)))