Hi, I forked off my own copy of rm to play with and have added the following functionality.
1. If the --warnings (-w) option is given, read the file ~/.rmfd/warn.list if it exists. The format is one absolute path per line. Before any files are removed, see if any file in the list would be removed by the invocation, and if so, warn and prompt the user for each file found whether it is OK to continue. Note that this overrides --force. If the user declines, exit with status EXIT_FAILURE. If the user allows it, continue with the usual semantics. Note that rm also checks as it is removing files, so if it finds a file that is in the list that wasn't warned about during the initial check, it will still prompt, but the "abort the entire operation" semantics can't be carried out. 2. If a symlink is found in warn.list, also add the target file (if it exists) to the list. Symlinks that aren't in the list explicitly are generally OK to remove without warning except in the case we are given --recursive and the symlink points to a directory that's in the list. 3. Upon start up, check the parent directory of each program argument. If the parent directory is in warn.list we open the directory and check if every non-dot file in the directory is in the argument list. In that case we warn and prompt that "*" is being removed in a directory in warn.list. Of course, this isn't a guaranteed accurate test, it's a best-effort attempt. 4. Add color to the warning prompt when stderr is a tty. I realize the initial code I posted was very basic, so I wanted to take the time to post a more complete implementation. The code is hosted at <http://github.com/d5h/rmfd> (the repo can be cloned via <[email protected]:d5h/rmfd.git>). The master branch only contains infrastructure changes dealing with forking Coreutils. The rmfd branch contains the code implementing the above-noted functionality (with tests). I made it easy to check the patches without downloading the code by uploading the master..rmfd patches to <http://linux.ucla.edu/~dsh/rmfd-patches/>. I also noted the "code" patches (not dealing with distribution, etc.) with "IMPORTANT" so you can quickly skip the others without loss of understanding. I would appreciate feedback on the concept or the code. I am still interested in hearing if this could be considered as an extension to GNU rm on the grounds that the extra code is not substantial (Coreutils' rm stripped is 47K on my system and rmfd's rm is 50K) and the performance hit and POSIX noncompliance is entirely opt-in. Thanks for your time. Dan Hipschman
