unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#46913: dired-do-compress doesn't work on files in inserted subdirectories
@ 2021-03-04  1:53 Okam via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2021-09-21  8:35 ` Michalis V.
  0 siblings, 1 reply; 5+ messages in thread
From: Okam via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-03-04  1:53 UTC (permalink / raw)
  To: 46913

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.






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

* bug#46913: dired-do-compress doesn't work on files in inserted subdirectories
  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.
  2021-09-21  9:22   ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Michalis V. @ 2021-09-21  8:35 UTC (permalink / raw)
  To: Okam; +Cc: 46913

[-- 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"

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

* bug#46913: dired-do-compress doesn't work on files in inserted subdirectories
  2021-09-21  8:35 ` Michalis V.
@ 2021-09-21  9:22   ` Eli Zaretskii
  2021-09-21  9:36     ` Michalis V.
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2021-09-21  9:22 UTC (permalink / raw)
  To: Michalis V.; +Cc: okamsn, 46913

> From: "Michalis V." <mvar.40k@gmail.com>
> Date: Tue, 21 Sep 2021 11:35:57 +0300
> Cc: 46913@debbugs.gnu.org
> 
> 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.

Yes, absolute file names in archives should be avoided at all costs.

> So another solution which is a bit more hackish is the following
> (and also attached as a patch)

Why not use file-relative-name instead?

Btw, please don't use "path" for anything that is not PATH-style
directory lists: the GNU Coding Standards frown on such uses.  We use
"file name" or "absolute file name" or "leading directories" instead,
as appropriate for the context.

Thanks.





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

* bug#46913: dired-do-compress doesn't work on files in inserted subdirectories
  2021-09-21  9:22   ` Eli Zaretskii
@ 2021-09-21  9:36     ` Michalis V.
  2021-09-21 17:13       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Michalis V. @ 2021-09-21  9:36 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Michalis V., okamsn, 46913

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


hi Eli,

Eli Zaretskii <eliz@gnu.org> writes:
>> So another solution which is a bit more hackish is the following
>> (and also attached as a patch)
>
> Why not use file-relative-name instead?

i was totally, 100% oblivious that this existed. It simplifies the
solution even more.

> Btw, please don't use "path" for anything that is not PATH-style
> directory lists: the GNU Coding Standards frown on such uses.  We use
> "file name" or "absolute file name" or "leading directories" instead,
> as appropriate for the context.
>
> Thanks.

i'll do so, thank you!

Michalis


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

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index f2cb745ad4..023531038f 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -1246,7 +1246,7 @@ dired-do-compress-to
                                   (?i . ,(mapconcat
                                           (lambda (in-file)
                                             (shell-quote-argument
-                                             (file-name-nondirectory in-file)))
+                                             (file-relative-name in-file)))
                                           in-files " "))))))
              (message (ngettext "Compressed %d file to %s"
 			        "Compressed %d files to %s"

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

* bug#46913: dired-do-compress doesn't work on files in inserted subdirectories
  2021-09-21  9:36     ` Michalis V.
@ 2021-09-21 17:13       ` Lars Ingebrigtsen
  0 siblings, 0 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2021-09-21 17:13 UTC (permalink / raw)
  To: Michalis V.; +Cc: okamsn, 46913

"Michalis V." <mvar.40k@gmail.com> writes:

> i was totally, 100% oblivious that this existed. It simplifies the
> solution even more.

Makes sense to me; pushed to Emacs 28 now.

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





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

end of thread, other threads:[~2021-09-21 17:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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.
2021-09-21  9:22   ` Eli Zaretskii
2021-09-21  9:36     ` Michalis V.
2021-09-21 17:13       ` Lars Ingebrigtsen

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).