]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix uncompressing a .tar.gz archive whose files have no leading dir
authorEli Zaretskii <eliz@gnu.org>
Thu, 23 May 2024 09:51:19 +0000 (12:51 +0300)
committerEshel Yaron <me@eshelyaron.com>
Thu, 23 May 2024 20:36:22 +0000 (22:36 +0200)
* 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

index 82b85d83498ea8b70eb1ed0c2c4fd374dec444dd..3741895021daaf376c3a90bca567d86a48d28718 100644 (file)
@@ -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)))