all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Michalis V." <mvar.40k@gmail.com>
To: Okam <okamsn@protonmail.com>
Cc: 46913@debbugs.gnu.org
Subject: bug#46913: dired-do-compress doesn't work on files in inserted subdirectories
Date: Tue, 21 Sep 2021 11:35:57 +0300	[thread overview]
Message-ID: <87h7eeqqaa.fsf@cnu407c2zx.nsn-intra.net> (raw)
In-Reply-To: <d2275396-b556-8bf4-5f7a-c22670139870@protonmail.com> (Okam's message of "Thu, 04 Mar 2021 01:53:08 +0000")

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

Okam <okamsn@protonmail.com> writes:

> Hello,
>
> If I insert a sub-directory into the current Dired buffer using
> `dired-maybe-insert-subdir`, I am able to mark files in this
> sub-directory and the current directory.
>
> If I try to compress these marked files using `dired-do-compress`, such
> as into a Zip file, only the files in the current directory, and not any
> in the sub-directory, will be entered into the archive.
>
> Thank you.

hi,

i'm assuming you meant "dired-do-compress-to" since "dired-do-compress"
will just compress the files themselves (i.e. it won't compress them into a
single archive)
the root cause seems to be in dired-do-compress-to map function:

when (zerop
      (dired-shell-command
       (format-spec (cdr rule)
                    `((?o . ,(shell-quote-argument out-file))
                      (?i . ,(mapconcat
                              (lambda (in-file)
                                (shell-quote-argument
                                 (file-name-nondirectory in-file)))
                              in-files " "))))))


in-files is a list with all marked files including their full path,
e.g. ("/home/mvar/m/a" "/home/mvar/m/b" "/home/mvar/m/n/c")

file-name-nondirectory will strip the whole path and leave just the
filenames and the final command for dired-shell-command will be
something like this:

tar -cf - a b c | gzip -c9 > /home/varagoul/m/a.tar.gz

and since dired-shell-command is executed from within the parent
dired-directory (/home/mvar/m in this case), file c won't be found so it
won't be included in the resulting archive. A workaround for this is to
include the whole path, i.e.

(lambda (in-file)
  (shell-quote-argument
    (expand-file-name in-file)))


but if you untar the file later, the files will be extracted with the
full path (in our example under home/mvar/m)
and i don't think we want the full path in there. So another solution
which is a bit more hackish is the following (and also attached as a
patch)


(shell-quote-argument
  (replace-regexp-in-string
    (expand-file-name dired-directory) "" in-file)))

which removes the base dired-directory from the filename and leaves only
the relative path for any marked files inside subdirectories of the
dired-directory
expand-file-name is also applied because dired-directory might be
something like "~/" which does not seem to work very well with
shell-quote-argument


cheers,
Michalis


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dired-aux.patch --]
[-- Type: text/x-patch, Size: 817 bytes --]

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index f2cb745ad4..1b73f098e3 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -1246,7 +1246,9 @@ dired-do-compress-to
                                   (?i . ,(mapconcat
                                           (lambda (in-file)
                                             (shell-quote-argument
-                                             (file-name-nondirectory in-file)))
+                                             (replace-regexp-in-string
+                                              (expand-file-name dired-directory) ""
+                                              in-file)))
                                           in-files " "))))))
              (message (ngettext "Compressed %d file to %s"
 			        "Compressed %d files to %s"

  reply	other threads:[~2021-09-21  8:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-04  1:53 bug#46913: dired-do-compress doesn't work on files in inserted subdirectories Okam via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-21  8:35 ` Michalis V. [this message]
2021-09-21  9:22   ` Eli Zaretskii
2021-09-21  9:36     ` Michalis V.
2021-09-21 17:13       ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h7eeqqaa.fsf@cnu407c2zx.nsn-intra.net \
    --to=mvar.40k@gmail.com \
    --cc=46913@debbugs.gnu.org \
    --cc=okamsn@protonmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.