Skip to content

Commit 6cd9ccb

Browse files
committed
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.
1 parent 42329e6 commit 6cd9ccb

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lisp/dired-aux.el

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,14 @@ command with a prefix argument (the value does not matter)."
992992
(ignore-errors (dired-remove-entry new-file))
993993
(goto-char start)
994994
;; Now replace the current line with an entry for NEW-FILE.
995-
(dired-update-file-line new-file) nil)
995+
;; But don't remove the current line if either FROM-FILE or
996+
;; NEW-FILE is a directory, because compressing/uncompressing
997+
;; directories doesn't remove the original.
998+
(if (or (file-directory-p from-file)
999+
(file-directory-p new-file))
1000+
(dired-add-entry new-file nil t)
1001+
(dired-update-file-line new-file))
1002+
nil)
9961003
(dired-log (concat "Failed to (un)compress " from-file))
9971004
from-file)))
9981005

@@ -1020,8 +1027,9 @@ command with a prefix argument (the value does not matter)."
10201027
("\\.7z\\'" "" "7z x -aoa -o%o %i")
10211028
;; This item controls naming for compression.
10221029
("\\.tar\\'" ".tgz" nil)
1023-
;; This item controls the compression of directories
1024-
(":" ".tar.gz" "tar -cf - %i | gzip -c9 > %o"))
1030+
;; This item controls the compression of directories. Its REGEXP
1031+
;; element should never match any valid file name.
1032+
("\000" ".tar.gz" "tar -cf - %i | gzip -c9 > %o"))
10251033
"Control changes in file name suffixes for compression and uncompression.
10261034
Each element specifies one transformation rule, and has the form:
10271035
(REGEXP NEW-SUFFIX PROGRAM)
@@ -1145,7 +1153,7 @@ Return nil if no change in files."
11451153
(condition-case nil
11461154
(if (file-directory-p file)
11471155
(progn
1148-
(setq suffix (cdr (assoc ":" dired-compress-file-suffixes)))
1156+
(setq suffix (cdr (assoc "\000" dired-compress-file-suffixes)))
11491157
(when suffix
11501158
(let ((out-name (concat file (car suffix)))
11511159
(default-directory (file-name-directory file)))

0 commit comments

Comments
 (0)