unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#56603: [PATCH] Ensure that directories exist when copying files from archive
@ 2022-07-16 15:20 Visuwesh
  2022-07-17  9:23 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 3+ messages in thread
From: Visuwesh @ 2022-07-16 15:20 UTC (permalink / raw)
  To: 56603

[-- Attachment #1: Type: text/plain, Size: 1077 bytes --]

Tags: patch

If a zip file is of the following contents,

    a/some-text.txt
    a/b/some-other.txt

and you mark all files and extract them to the directory /tmp/test/, the current copy
command bugs out since `write-to-region' complains about /tmp/test/a/ and
/tmp/test/a/b/ not existing.

If you tried to extract a single file a/some-text.txt after answer /tmp/
to the prompt, the C command fails due to the above reason.

This patch creates the relevant directories if they don't exist.  But
perhaps the patch should be more robust?  I.e., if /tmp/test/a was a
file, then it should error?

In GNU Emacs 29.0.50 (build 21, x86_64-pc-linux-gnu, X toolkit, Xaw scroll bars)
 of 2022-07-16 built on astatine
Repository revision: 9a5b52dace4cb0fe6b99205911d9b2f2487a4a83
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101003
System Description: Debian GNU/Linux bookworm/sid

Configured using:
 'configure --with-sound=alsa --with-x-toolkit=lucid --with-json
 --without-xaw3d --without-gconf --without-libsystemd --without-cairo'


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Ensure-that-directories-exist-when-copying-files-fro.patch --]
[-- Type: text/patch, Size: 1548 bytes --]

From 0166179e60644475abb878ecec86c8847871eab6 Mon Sep 17 00:00:00 2001
From: Visuwesh <visuweshm@gmail.com>
Date: Sat, 16 Jul 2022 20:44:50 +0530
Subject: [PATCH] Ensure that directories exist when copying files from archive

* lisp/arc-mode.el (archive-copy-file): If the directory the file is
being extracted to does not exist, then create it.
---
 lisp/arc-mode.el | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el
index c52f2a4432..e5aadccc87 100644
--- a/lisp/arc-mode.el
+++ b/lisp/arc-mode.el
@@ -1073,13 +1073,16 @@ archive-copy-file
     (user-error "Can't copy a list of files to a single file"))
   (save-excursion
     (dolist (file files)
-      (let ((write-to (if (file-directory-p new-name)
-                          (expand-file-name file new-name)
-                        new-name)))
+      (let* ((write-to (if (file-directory-p new-name)
+                           (expand-file-name file new-name)
+                         new-name))
+             (write-to-dir (file-name-directory write-to)))
         (when (and (file-exists-p write-to)
                    (not (yes-or-no-p (format "%s already exists; overwrite? "
                                              write-to))))
           (user-error "Not overwriting %s" write-to))
+        (unless (file-directory-p write-to-dir)
+          (make-directory write-to-dir t))
         (archive-goto-file file)
         (let* ((descr (archive-get-descr))
                (archive (buffer-file-name))
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#56603: [PATCH] Ensure that directories exist when copying files from archive
  2022-07-16 15:20 bug#56603: [PATCH] Ensure that directories exist when copying files from archive Visuwesh
@ 2022-07-17  9:23 ` Lars Ingebrigtsen
  2022-07-17  9:58   ` Visuwesh
  0 siblings, 1 reply; 3+ messages in thread
From: Lars Ingebrigtsen @ 2022-07-17  9:23 UTC (permalink / raw)
  To: Visuwesh; +Cc: 56603

Visuwesh <visuweshm@gmail.com> writes:

> This patch creates the relevant directories if they don't exist.  But
> perhaps the patch should be more robust?  I.e., if /tmp/test/a was a
> file, then it should error?

We'll get an error from that make-directory call, and I think that's
sufficient, so I've pushed your patch to Emacs 29.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#56603: [PATCH] Ensure that directories exist when copying files from archive
  2022-07-17  9:23 ` Lars Ingebrigtsen
@ 2022-07-17  9:58   ` Visuwesh
  0 siblings, 0 replies; 3+ messages in thread
From: Visuwesh @ 2022-07-17  9:58 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 56603

[ஞாயிறு ஜூலை 17, 2022] Lars Ingebrigtsen wrote:

> Visuwesh <visuweshm@gmail.com> writes:
>
>> This patch creates the relevant directories if they don't exist.  But
>> perhaps the patch should be more robust?  I.e., if /tmp/test/a was a
>> file, then it should error?
>
> We'll get an error from that make-directory call, and I think that's
> sufficient, so I've pushed your patch to Emacs 29.

Thanks





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-17  9:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-16 15:20 bug#56603: [PATCH] Ensure that directories exist when copying files from archive Visuwesh
2022-07-17  9:23 ` Lars Ingebrigtsen
2022-07-17  9:58   ` Visuwesh

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).