* bug#38707: dired-do-rename doesn't check for "/" !
@ 2019-12-22 16:37 積丹尼 Dan Jacobson
2019-12-24 4:28 ` Nick Helm
0 siblings, 1 reply; 3+ messages in thread
From: 積丹尼 Dan Jacobson @ 2019-12-22 16:37 UTC (permalink / raw)
To: 38707
R runs the command dired-do-rename (found in dired-mode-map), which is
an interactive autoloaded compiled Lisp function in ‘dired-aux.el’.
But it has a big bug.
Let's say you tell it to rename qqq to "xxx/yyy/zzz/".
And it works.
You get xxx/yyy/zzz/qqq
But if there is no directory zzz,
then one day you will discover you got
xxx/yyy/qqq .
Real "mv" doesn't have this bug.
$ mv k /tmp/p/
mv: cannot create regular file '/tmp/p/': Not a directory
dired-do-rename perhaps under the hood does the "mv" action, but instead
of reporting the failure, tries again with the final slash removed!
emacs-version "26.3"
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#38707: dired-do-rename doesn't check for "/" !
2019-12-22 16:37 bug#38707: dired-do-rename doesn't check for "/" ! 積丹尼 Dan Jacobson
@ 2019-12-24 4:28 ` Nick Helm
2020-08-06 10:13 ` Lars Ingebrigtsen
0 siblings, 1 reply; 3+ messages in thread
From: Nick Helm @ 2019-12-24 4:28 UTC (permalink / raw)
To: 38707
Dan Jacobson <jidanni@jidanni.org> writes:
> Let's say you tell it to rename qqq to "xxx/yyy/zzz/".
>
> And it works.
>
> You get xxx/yyy/zzz/qqq
>
> But if there is no directory zzz,
> then one day you will discover you got
>
> xxx/yyy/qqq .
I'm not sure this is actually a bug, but it looks like the behaviour
happens because of these lines in dired-do-create-files.
;; rename-file bombs when moving directories unless we do this:
(or into-dir (setq target (directory-file-name target)))
Dired could check for and issue an error in the case where the source is
a file and the target appears to be a non-existent directory. Something
like this perhaps?
--- a/lisp/dired-aux.el 2019-12-23 15:12:26.000000000 +1300
+++ b/lisp/dired-aux.el 2019-12-23 15:18:17.000000000 +1300
@@ -1878,6 +1878,10 @@
(apply (car into-dir) operation rfn-list fn-list target (cdr into-dir))
(if (not (or dired-one-file into-dir))
(error "Marked %s: target must be a directory: %s" operation target))
+ (if (and (not (file-directory-p (car fn-list)))
+ (not (file-directory-p target))
+ (directory-name-p target))
+ (error "%s: Target directory does not exist: %s" operation target))
;; rename-file bombs when moving directories unless we do this:
(or into-dir (setq target (directory-file-name target)))
(dired-create-files
Nick
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#38707: dired-do-rename doesn't check for "/" !
2019-12-24 4:28 ` Nick Helm
@ 2020-08-06 10:13 ` Lars Ingebrigtsen
0 siblings, 0 replies; 3+ messages in thread
From: Lars Ingebrigtsen @ 2020-08-06 10:13 UTC (permalink / raw)
To: Nick Helm; +Cc: 38707
Nick Helm <nick@tenpoint.co.nz> writes:
> Dired could check for and issue an error in the case where the source is
> a file and the target appears to be a non-existent directory. Something
> like this perhaps?
[...]
> + (if (and (not (file-directory-p (car fn-list)))
> + (not (file-directory-p target))
> + (directory-name-p target))
> + (error "%s: Target directory does not exist: %s" operation target))
I think this makes sense, so I've applied it to Emacs 28.1. However, it
is a slight behavioural change -- previously you could enter, say
"/tmp/bar/" (when moving one file), and it would move the file to the
file "/tmp/bar".
I think the new behaviour is better (i.e., bugging out), but if people
complain for some reason, then it should perhaps be reverted.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-08-06 10:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-22 16:37 bug#38707: dired-do-rename doesn't check for "/" ! 積丹尼 Dan Jacobson
2019-12-24 4:28 ` Nick Helm
2020-08-06 10: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).