[patch] rm can have undesired side-effects

Mike Meyer mwm-keyword-freebsdhackers2.e313df at mired.org
Mon Oct 30 01:33:55 UTC 2006


In <00f201c6fbb6$0c6bd150$b3db87d4 at multiplay.co.uk>, Steven Hartland <killing at multiplay.co.uk> typed:
>  
> ----- Original Message ----- 
> From: "Joerg Pernfuss" <elessar at bsdforen.de>
> >> I guess that it can be fixed (in case it is not desired) by:
> >>  - Ignoring the -P option when the link count is greater then one, or
> > Silently ignoring user specified options is seldom a good way to go.
> > The user explicitly stated he wants to wipe the file contents.
> That maybe the case but does rm -f <file> remove all copies?
> Nope so its behaviour is safe even with multiple hardlinks.

Of course it doesn't remove all copies - because there *aren't*
multiple copies. There is only *one* copy, with multiple hardlinks.
You told it to remove one hardlink, and it did that, without caring if
that's the last link or not, and erroring out because you could lose
data if it's the last link.

> From the description I've seen thats not the case for -P
> here and as such I dont think its quite a simple as that.

I think it is. There's a flag that basically says "make sure no one
can read this data ever again". It does that. That said data is still
available via some other link is immaterial.

> My personal preference would be for it to warn or perhaps
> error if the link count is not zero. Possibly use -f to
> override this but even that I'd say is dangerous.

My personal preference is that the system do what I tell it to. If I
wanted a system that second guessed me and didn't do things that I
told it to because it thought it knew better than I did what I wanted,
I wouldn't be using Unix.

Adding code so that this is mentioned if you asked to be coddled with
-i or -I is probably worthwhile, at least if you can make it not ask
if you're actually removing all the links if you do -RP.

	<mike
-- 
Mike Meyer <mwm at mired.org>		http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.


More information about the freebsd-hackers mailing list