From 0c901258b676c0cdf1af86f26b3ace08e8f828d3 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 23 May 2024 12:51:19 +0300 Subject: [PATCH] Fix uncompressing a .tar.gz archive whose files have no leading dir * lisp/dired-aux.el (dired-compress): Handle the case when NEW-FILE is not produced in the current directory by uncompressing a compressed file. (Bug#47058) (cherry picked from commit f75fec5cacce47c9714f10592d75c8fb9c63999d) --- lisp/dired-aux.el | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 82b85d83498..3741895021d 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -1511,14 +1511,23 @@ A FMT of \"\" will suppress the messaging." ;; Remove any preexisting entry for the name NEW-FILE. (ignore-errors (dired-remove-entry new-file)) (goto-char start) - ;; Now replace the current line with an entry for NEW-FILE. - ;; 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)) + ;; Now replace the current line with an entry for NEW-FILE, + ;; if it exists. 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 NEW-FILE doesn't exist, assume that we are + ;; out of sync with the current directory, and revert it. + ;; This can happen, for example, when unpacking a .tar.gz + ;; archive which adds files to the current directory (as + ;; opposed to adding them to a directory whose name is + ;; NEW-FILE). + (if (file-exists-p new-file) + (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)) + (dired-fun-in-all-buffers (dired-current-directory) + nil #'revert-buffer)) nil) (dired-log (concat "Failed to (un)compress " from-file)) from-file))) -- 2.39.5