need to be on a stack instead of being a single variable since
directories are processed depth-first. Otherwise dne randomly
depends on the previously processed entry.
This fixes both chmod of non-created directories (they used to be
chmod'd even when not created if their last child element did not
exist in the target subtree) and a "foo exists" bug exposed by my
last commit which removed directory sorting.
all regression tests passed
before directories since files (usually) are in the same cylinder
group and subdirectories aren't. However, this mostly changed with
the new ffs dirpref algorithm in 2001.
No sorting has two effects:
1) copy appears to be somewhat faster (e.g. on my laptop cp'ing build
objdir to tmpfs is 7% faster after the change)
2) source file parameters no longer get randomly shuffled due to
fts doing an unstable sort of them. this means that
"cp 1 2 3 4 dest/" will copy the files in that order instead
of e.g. 3 4 1 2.
output behave itself. PR bin/37018 from Dieter Roelants.
(I used a slightly different patch to make sure "any file failed"
didn't get lost in the shuffle, and renamed the variables in the name
of greater clarity.)
"-R" claims:
-R [...] Created directories have the same mode as the corre-
sponding source directory, unmodified
by the process' umask.
Make this actually true.
In addition, make '-P' (no symbolic links are followed) apply even if
'-R' is not specified. This allows users to overwrite symbolic links
with files and/or to copy symbolic links over a file without indirecting
through the link (ie a copy of a link turns the target into a link, not
a copy of the file pointed to by the source).
If stdout is a tty, use vis(3) to print any filenames to prevent garbage
from being printed if the filename contains control- or other non-printable
characters.
While here, sprinkle some EXIT_FAILURE and NOTREACHED where appropriate.
to what the manpage and POSIX say) copied as symlinks, even without -R.
Return ENOENT instead. Closes PR 6975 by Johan Danielsson <joda@pdc.kth.se>.
From FreeBSD: return correct error message if source directory is
unreadable; remove unnecessarily included headers.
It's suppsed to remove the file and then copy, which it wasn't doing.
But no wait, it turns out that the described behaviour in the manual doesn't
agree with POSIX. So we change the above fix and the manual to "try copy, and
if fail, try remove, then copy".
Fix bug where "cp -R" didn't work on read-only directories:
It would make the directory, set the mode, and not be able to write files into it.
Don't bother mmap()ing files of zero length. Was a workaround for a bug in Rhapsody
mmap(), which didn't get along with such files, but makes sense anyway.
Fix race condition where "cp -p" would set the mod time of a file before close()ing
the file, which would update the mod time and therefore screw up the "-p" idea,
except, of course, while running in gdb, which sucked.
Add -f option to usage message in binary and man page. Already documented in man page.