Commit 6cd9ccb0 authored by Eli Zaretskii's avatar Eli Zaretskii

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.
parent 42329e6d
Pipeline #4515 passed with stage
in 54 minutes and 44 seconds
......@@ -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)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment