[Toybox] cp --parents
Rob Landley
rob at landley.net
Fri Apr 6 22:19:52 PDT 2018
I have a todo item to add cp --parents (somebody asked for it) and I was giving
it a go, and as is completely standard for gnu/dammit features it's TERRIBLY
SPECIFIED.
$ cd ~/toybox
$ mkdir -p dest/dest2/dest3
$ cd dest/dest2
$ cp --parents ../../toys/posix/cp.c dest3
That creates dest/toys/posix/cp.c. The ability to escape the destination
directory with relative paths seems kinda unsafe.
Anybody got suggestions for what it _should_ be doing?
I was also wondering how cp -s and --parents should combine (my version can
handle relative paths by prepending the appropriate number of .. entries, which
varies based on -r level...) but for the moment I'm thinking of just forbidding
the combination until somebody asks for it.
Rob
P.S. A piece of infrastructure on my todo list forever is basically "readlink
-f" on both source and dest and failing if dest isn't under source. All sorts of
stuff from tar -x to httpd should use that, and I _could_ do that here, but it's
silly expensive. I'm more likely to use lib/lib.c xabspath() and then barf if
the result starts with "../", but of course you can follow symlinks which means
the normal cp -r could follow a symlink out of the destination directory, can't
it? (Honestly a month to just focus on the darn test suite would be nice...) But
a dishonest source is more likely/alarming than a dishonest destination...
More information about the Toybox
mailing list