bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#46913: dired-do-compress doesn't work on files in inserted subdirect


From: Michalis V.
Subject: bug#46913: dired-do-compress doesn't work on files in inserted subdirectories
Date: Tue, 21 Sep 2021 11:35:57 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

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

Attachment: dired-aux.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]