4 ms·
It's treated special cause most shells handle undefined variables as empty strings so `rm -rf "${base_path}/${sub_dir}"` can turn into `rm -rf '/'` and users co
by ender341341 1y ago
It's treated special cause most shells handle undefined variables as empty strings so `rm -rf "${base_path}/${sub_dir}"` can turn into `rm -rf '/'` and users commonly don't expect that.
While that case may be simple to catch the writers of gnu rm also recognize that scripts tend to not be well tested and decided "better than it currently is" is better than "we didn't do any mitigations to a common problem cause the solution wasn't perfect".
- serbuvlad 1y agoAh, the beauties of the POSIX shell.
- riffraff 1y agoI think a valid interpretation of GPs point could be that top-level folders should have special properties so that they're not at risk of a bad rm, e.g. xattr "unchangeable" flags. The fact that you can accidentally nuke the system seems a remnant from the olden days which we should have corrected a long time ago. (I think GNU did a valid mitigation with preserve-root, just musing philosophically.)
- delamon 1y ago"immutable" top-level folders won't cut it. In order to recursively delete a folder, rm has to delete leaves first. So, you will endup with empty top-level folders, which is no better.
- charcircuit 1y ago>rm has to delete leaves first There is nothing fundamental with rm for it to work like that.
- lmz 1y agoIt does if you ever want rmdir to succeed.
- ender341341 1y agoI think they mean that rm could check the folder you're trying to delete and see if it has whatever attribute and if so don't delete it's contents. so "rm -rf /" would see that '/' has it and be a no-op, but '~/home/foo' doesn't so it would recurse and start deleting. It could go further do that check for each sub directory recursively, so say '~/home/foo/bar/baz' that 'bar' does have the flag so `rm -rf ~/home/foo/` would delete everything else from the foo folder but leave bar and it's descendants alone.
- ender341341 1y agoThat's reasonable, I was mainly responding to this part > Being special to just / doesn't make sense to me. and explaining why being special to / can make sense. I too often feel like people see comments like that and decide to let perfect get in the way of better in their own work.
- grahamjperrin 1y ago> … GPs point … I'm slightly disoriented, who's the other GP? (I'm a GP.)