4 ms·
That was already fixed with -print0 | xargs -0, but then this solution is dismissed with "The problem is that this is not a portable construct;...". The -delete
by nuxi 15y ago
That was already fixed with -print0 | xargs -0, but then this solution is dismissed with "The problem is that this is not a portable construct;...".
The -delete isn't either, so this is a straw man argument, although it probably is the most efficient and secure of all.
- ars 15y agoRead it again. -print-0 | xargs -0 does not fix the race condition. The problem is someone can swap in a symlink after the find, and before the xargs.
- nuxi 15y agoI'll have to run some more tests, but I can't see how -delete would help in that case .
- ars 15y agoBecause find changes to the directory first (carefully not following symlinks), and then deletes the file from there. It does not delete the file using the entire path (which may contain a sudden symlink). It's not possible to do this safely using xargs. Take a look also at -execdir which does the same thing - changes to the directory first, and runs things from there. -exec is not safe and should not be used. xargs is not safe if you are running against a directory not your own. You should use find and -execdir instead. Yes, the original authors of posix made a mistake here. > Also, rant rant, I really don't understand why find was extended with -delete in the first place. I'm hoping you understand it now.
- nuxi 15y agoYes, thanks for the extensive info.