From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Visuwesh Newsgroups: gmane.emacs.bugs Subject: bug#56603: [PATCH] Ensure that directories exist when copying files from archive Date: Sat, 16 Jul 2022 20:50:38 +0530 Message-ID: <87k08d13uh.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36878"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) To: 56603@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 16 17:21:14 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oCjbW-0009MC-EL for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 16 Jul 2022 17:21:14 +0200 Original-Received: from localhost ([::1]:47592 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oCjbV-0007pD-En for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 16 Jul 2022 11:21:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33412) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oCjbK-0007ok-Ug for bug-gnu-emacs@gnu.org; Sat, 16 Jul 2022 11:21:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48009) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oCjbK-00057H-Ls for bug-gnu-emacs@gnu.org; Sat, 16 Jul 2022 11:21:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oCjbK-0002Lo-G7 for bug-gnu-emacs@gnu.org; Sat, 16 Jul 2022 11:21:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Visuwesh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 16 Jul 2022 15:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 56603 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16579848528997 (code B ref -1); Sat, 16 Jul 2022 15:21:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 16 Jul 2022 15:20:52 +0000 Original-Received: from localhost ([127.0.0.1]:45768 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oCjbA-0002L2-4l for submit@debbugs.gnu.org; Sat, 16 Jul 2022 11:20:52 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:34884) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oCjb6-0002Ks-AC for submit@debbugs.gnu.org; Sat, 16 Jul 2022 11:20:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33402) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oCjb6-0007nc-5r for bug-gnu-emacs@gnu.org; Sat, 16 Jul 2022 11:20:48 -0400 Original-Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:33345) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oCjb4-00056W-Hq for bug-gnu-emacs@gnu.org; Sat, 16 Jul 2022 11:20:47 -0400 Original-Received: by mail-pf1-x443.google.com with SMTP id v7so7097186pfb.0 for ; Sat, 16 Jul 2022 08:20:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:user-agent:mime-version; bh=dWTKmyY7vTITpBI+lQvbxLNwuN3eFBlgNlEL7Lashm8=; b=NuP2NrjrTs8a0cUhEV+vPU/snnLOn2zv3saBcC3m28+WAlzh/n0ycP7ntvdAj2bobw PfOtTLPmyeASuaDei2/20ZGHA6zhI8JhqVYGB3gW7J71dIKlaEKIxcpc+RLIxwBOj2KD D8a9hphRn7sqkk3pgTr3k/VIxuIywQmOwnVy99wMkrjiI+xjGa4gbfXM3fopCsZTJibS 7tGDyFH2x9yb+inT3grps2QtauYaAUm9mNmbzcTKpW+XA4opKOGw73tYcMEQZgZOPzyP MeddfDbwiyGmOn22J1WUkiUm2jBaYHM43p7Ma/7tW3vMJAUOBIuH6fqWptgPluTaI9eO +vqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:user-agent :mime-version; bh=dWTKmyY7vTITpBI+lQvbxLNwuN3eFBlgNlEL7Lashm8=; b=Kik8vP9yQGiN+Hz7B/EodbJlRKEsOMij9d2SCIglXfHGUzhsNeXtZ3lbvldlEeaK6m 6U4jHgSDC8EuFDzNC/2jCvWwjqBg4Eu+MJA1pEkSDh0sYB/nq1lflFwK6xEavrVKZUjh DCyUK3FtDZytp2y9BOUsBJJQrPlW+qKAS/NfDuXYUTGKdJZ7vHUcGd3un09+FMSS3Cy3 hVzMpt7ERkVOKV0Ek5yrmkYE1UyvjIUgVbRlle0LpLyBKk7HrnMJlzevidd1dNGItDXp HV1FJSnU2edx2q4ix/Mulh74S5H1qJpQCuEl2BqPdCkJ1F3gIYmxT89PDpX7FOD/cHJf +ovQ== X-Gm-Message-State: AJIora9rjgoatTm2cnm9+K+DGYdWeYZ56ahuH7YnMNvvG5PiwMW8KTT9 R/P0aJtOXonYTJWJGrcjcjprIQfRk/o= X-Google-Smtp-Source: AGRyM1sJMv9MnEO8b05jAbP5ruFLJFgre8/aU7+e5pqjUat4PHMRBXqAo1hyUcuW5WQ9qVaUPLanMA== X-Received: by 2002:a63:91c3:0:b0:419:b004:a99b with SMTP id l186-20020a6391c3000000b00419b004a99bmr12879796pge.331.1657984844392; Sat, 16 Jul 2022 08:20:44 -0700 (PDT) Original-Received: from localhost ([49.205.85.181]) by smtp.gmail.com with ESMTPSA id w188-20020a6282c5000000b0052aee60e058sm5947262pfd.102.2022.07.16.08.20.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jul 2022 08:20:41 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::443; envelope-from=visuweshm@gmail.com; helo=mail-pf1-x443.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:237199 Archived-At: --=-=-= Content-Type: text/plain 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' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Ensure-that-directories-exist-when-copying-files-fro.patch >From 0166179e60644475abb878ecec86c8847871eab6 Mon Sep 17 00:00:00 2001 From: Visuwesh 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 --=-=-=--