Bug #3736
opencp -r shouldn't allow infinite loops
60%
Description
If you do
> mkdir foo > cp -r . foo
cp will loop ever deeper, until you run out of file descriptors (which may indicate it's leaking them, I haven't checked if that's to be expected or not).
It should stop short, as GNU cp does (but BSD cp doesn't, that one runs out to PATH_MAX instead).
Files
Updated by Garrick Peterson about 10 years ago
I've started taking a look at this. Don't have permissions to assign bug to myself, but will update with progress.
[edit 2013-05-10]
The initial bug is fixed and working. If ( source == target )
it skips to the next item. The remainder of the current directory is still recursively-copied to foo/ as expected. Also a warning is printed to stdout.
However this still fails. Not yet sure how to fix this.
$ mkdir -p foo/bar
$ cp -r . foo/bar/
Also trying to refactor the relevant function and clean up the code a bit. Doing that in a separate git branch for now.
Updated by Alexander Eremin about 10 years ago
Possible fix is attached
Updated by Garrick Peterson about 10 years ago
- Status changed from New to In Progress
- % Done changed from 0 to 60
Going to publish webrev shortly for initial review. Will need a strategy/tool for thorough testing.
Took a different approach from Alexander. Now that mine is working, I'm comparing them more closely. Also did some refactoring in the same function, where it made sense.