[PATCH] (against 1.4.2) prevent cp of dir into itself (reprise)

Denys Vlasenko vda.linux at googlemail.com
Sat Aug 25 21:03:57 UTC 2007


On Thursday 23 August 2007 22:16, S H wrote:
> cp -R sub sub results in a nasty subdirectory tree (see
> http://bugs.busybox.net/view.php?id=1412). coreutils cp stops it before it
> goes out of control. FreeBSD ignores it. I prefer the coreutils behavior.
>
> This patch approximates the coreutils behavior to the best of my knowledge,
> without some of the issues found in r8517.  It works by recording the
> source directories which are visited; because no parent of dest can occur
> in source. This will only happen with directories; and since there can't be
> hardlinks to directories, this should never cause problems with the other
> code that uses the ino_dev_hashtable.
>
>
> The patch is against 1.4.2; if anyone is seriously interested in this, I'm
> happy to port it up to svn HEAD. I'm primarily seeking comments that this
> is on a better path than the original solution, and whether or not
> developers are genuinely interested in emulating the coreutils behavior in
> this case.

I would rather no use inode_hashtable. Who knows how deep that tree is,
and inode hashtable actually remembers *each pathname*!!

Please download svn version (yes, it has changed since 1.7.0 in that area),
apply attached patch and try your testcases. Does that work?

The solution is a hack (need to avoid using static), but the basic idea is
to remember a dev and inode of top-level created directory,
and refuse to copy it if it turns up as a source later.
--
vda
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 5.patch
Type: text/x-diff
Size: 928 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20070825/c3c44b7c/attachment-0002.bin 


More information about the busybox mailing list