On 17 January 2016, Bram Moolenaar <[email protected]> wrote:
>
> Lcd wrote:
>
> > On 16 January 2016, Bram Moolenaar <[email protected]> wrote:
> > >
> > > Patch 7.4.1107
> > > Problem: Vim can create a directory but not delete it.
> > > Solution: Add an argument to delete() to make it possible to delete a
> > > directory, also recursively.
> > > Files: src/fileio.c, src/eval.c, src/proto/fileio.pro,
> > > src/testdir/test_delete.vim, src/testdir/test_alot.vim,
> > > runtime/doc/eval.txt
> > [...]
> > > *** ../vim-7.4.1106/runtime/doc/eval.txt 2016-01-15 20:48:09.862003231
> > > +0100
> > > --- runtime/doc/eval.txt 2016-01-16 20:34:22.280259614 +0100
> > > ! delete({fname} [, {flags}])
> > > *delete()*
> > > ! Without {flags} or with {flags} empty: Deletes the file
> > > by the
> > > ! name {fname}.
> > > !
> > > ! When {flags} is "d": Deletes the directory by the name
> > > ! {fname}. This fails when {fname} is not empty.
> > > !
> > > ! When {flags} is "rf": Deletes the directory by the name
> > > ! {fname} and everything in it, recursively. Be careful!
> > [...]
> >
> > There seems to be a serious problem with delete("dir", "rf"):
> > if "dir" has a symlink descendant then (1) the symlink is followed
> > (that is, the content of the directory symlink points to is deleted
> > recursively), (2) the symlink is not deleted, and (3) the operation
> > returns -1, signifying failure. I believe neither of this is
> > expected, or useful.
>
> I believe you mean that a symbolic link to a directory does not work
> as expected.
Yes, the problem is following symlinks when they point to
directories. Here's a quick demo:
- in shell:
$ mkdir -p a/b/c 1/2/3
$ ln -s ../../1/2 a/b/sym
- in Vim:
:echo delete('a', 'rf')
-1
- in shell again:
$ ls 1/2
$ ls a/b
sym@
Directory 3 is gone, because sym was pointing to 1/2.
Now imagine sym pointing to $HOME...
> The "rm" manual page actually does not mention symbolic links and what
> it does with them.
It never makes sense for "rm -rf" to follow (directory) symlinks.
It would be a security problem otherwise: just create a symlink in
/tmp pointing to /sbin or to /etc, and wait for the next reboot: the
startup scripts that clean /tmp, running as root, would dutifully remove
everything in /sbin or /etc.
> Currently delete("link") deletes the link, not the file it points to.
> I think that is good. So we should do the same for when the symbolic
> link points to a directory.
Yes: that's backwards compatible with older Vim's, and is compatible
to both rm(1) and unlink(2).
> Hmm, would that require: delete("dirlink", 'd') ? Or can it be done
> with delete("dirlink") ? It appears "rm dirlink" works, so we best
> follow that.
For the purpose of delete(), symlinks should be identical to normal
files regardless of where they point to. There is too much potential
for trouble any other way.
/lcd
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.