summaryrefslogtreecommitdiff
path: root/src/cp.c
AgeCommit message (Collapse)Author
2007-06-15Correct cp's handling of destination symlinks in some cases.Paul Eggert
* NEWS: "cp" no longer considers a destination symlink to be the same as the referenced file when copying links or making backups. * src/copy.c (copy_reg): When following a symlink, use the followed name in later chown etc. requests, so that the created file is affected, rather than the symlink. Use O_NOFOLLOW on source when not dereferencing symlinks; this avoids a race. Preserve errno correctly when doing multiple open attempts on the destination. (copy_internal): Follow destination symlinks only when copying a regular file and only when we don't intend to remove or rename the destination first, regardless of whether following source symlinks; this is because since POSIX and tradition (e.g., FreeBSD) say we should ordinarily follow destination symlinks if the system calls would ordinarily do so. * src/copy.h (struct cp_options): Add comment that 'dereference' is only for source files. * src/cp.c (usage): Note that --derereference etc. are only for source files. (make_dir_parents_private): Follow symlinks, regardless of whether --dereference is specified, because these are destination symlinks. * tests/cp/same-file: Adjust tests to match revised behavior. Filter out perror output since it might vary from host to host. Use sed alone instead of also using echo. * doc/coreutils.texi (cp invocation): Document the behavior better when the destination is a symlink. Clarify source versus destination symlinks. Describe the new behavior for destination symlinks. 2007-06-15 Jim Meyering <jim@meyering.net> * src/copy.c: Include "canonicalize.h". (copy_reg): Use canonicalize_filename_mode to follow the symlink, so that we can always open with O_EXCL and avoid a race.
2007-06-13Don't include "quotearg.h" when it is not used.Jim Meyering
* Makefile.maint (sc_prohibit_quotearg_without_use): New rule. * src/cp.c: Don't include "quotearg.h". It wasn't used.
2007-03-29* tests/cp/cp-a-selinux: New file. Test for the bug reported inJim Meyering
* tests/cp/Makefile.am (TESTS): Add cp-a-selinux. * tests/selinux: New file. * tests/Makefile.am (EXTRA_DIST): Add selinux. * tests/misc/selinux: Source the new script, rather than open coding it. Change how "cp -a" and "cp --preserve=context" work with SELinux. Now, cp -a attempts to preserve context, but failure to do so does not change cp's exit status. However "cp --preserve=context" is similar, but failure *does* cause cp to exit with nonzero status. * src/copy.h (struct cp_options) [require_preserve_context]: New member. * src/copy.c (copy_reg, copy_internal): Implement the above. * src/mv.c (cp_option_init): Initialize the new member. * src/install.c (cp_option_init): Likewise. * src/cp.c (cp_option_init): Likewise. (decode_preserve_arg): Set it or reset it. FIXME: add an on-writable-NFS-only test
2007-03-29cp, mv, install: add SELinux support, but unlike with the Red HatJim Meyering
patch, mv and cp do not provide the "-Z context" option. * src/copy.c: Include <selinux/selinux.h>. (restore_default_fscreatecon): New function. (copy_reg): Make cp --preserve=context work for existing destination. (copy_internal): Likewise for new destinations. * src/copy.h (cp_options) [preserve_security_context]: New member. * src/cp.c: Include <selinux/selinux.h>. (selinux_enabled): New global. (usage): Mention new --preserve=context option. (PRESERVE_CONTEXT): Define/use. (decode_preserve_arg): Handle PRESERVE_CONTEXT. (main): Remove an obsolete comment. If --preserve=context is specified on a system without SELinux enabled, give a diagnostic and fail. * src/mv.c: Include <selinux/selinux.h>. Set x->preserve_security_context if SELinux is enabled. * src/install.c: Accept new "-Z, --context=C" option. Accept --preserve-context option (but not -P option). Accept alternate spelling: --preserve_context, for now. Include <selinux/selinux.h> and "quotearg.h". (selinux_enabled, use_default_selinux_context): New globals. (PRESERVE_CONTEXT_OPTION): Define. (cp_option_init): Default: do not preserve security context. (setdefaultfilecon): New function. (main): Honor new options. * src/Makefile.am (mv_LDADD, cp_LDADD, ginstall_LDADD): Add $(LIB_SELINUX).
2007-03-28Help translators include translation team's web or email address.Jim Meyering
* src/system.h (emit_bug_reporting_address): New function. * src/base64.c: Use it rather than a literal printf. * src/basename.c, src/cat.c, src/chgrp.c, src/chmod.c: * src/chown.c, src/chroot.c, src/cksum.c, src/comm.c, src/cp.c: * src/csplit.c, src/cut.c, src/date.c, src/dd.c, src/df.c: * src/dircolors.c, src/dirname.c, src/du.c, src/echo.c, src/env.c: * src/expand.c, src/expr.c, src/factor.c, src/fmt.c, src/fold.c: * src/head.c, src/hostid.c, src/hostname.c, src/id.c, src/install.c: * src/join.c, src/kill.c, src/link.c, src/ln.c, src/logname.c: * src/ls.c, src/md5sum.c, src/mkdir.c, src/mkfifo.c, src/mknod.c: * src/mv.c, src/nice.c, src/nl.c, src/nohup.c, src/od.c: * src/paste.c, src/pathchk.c, src/pinky.c, src/pr.c, src/printenv.c: * src/printf.c, src/ptx.c, src/pwd.c, src/readlink.c, src/rm.c: * src/rmdir.c, src/seq.c, src/setuidgid.c, src/shred.c, src/shuf.c: * src/sleep.c, src/sort.c, src/split.c, src/stat.c, src/stty.c: * src/su.c, src/sum.c, src/sync.c, src/system.h, src/tac.c: * src/tail.c, src/tee.c, src/test.c, src/touch.c, src/tr.c: * src/true.c, src/tsort.c, src/tty.c, src/uname.c, src/unexpand.c: * src/uniq.c, src/unlink.c, src/uptime.c, src/users.c, src/wc.c: * src/who.c, src/whoami.c, src/yes.c: Likewise.
2007-02-03* NEWS: Document fix for cp --preserve=mode.Paul Eggert
* src/copy.c (copy_internal): Omit the group- or other-writeable permissions when creating a directory, to avoid a race condition if the special mode bits aren't right just after the directory is created. * src/cp.c (make_dir_parents_private): Likewise. * tests/cp/parent-perm-race: Test for the "cp --preserve=mode" race fix in copy.c.
2007-02-03* NEWS: Document fix for cp --parents.Paul Eggert
* src/cp.c (make_dir_parents_private): Report the error sooner with "cp --parents DIR/FILE DEST" when DIR is a non-directory, thus not creating the directory, DEST/DIR. * tests/cp/cp-parents: Test for the non-race-condition bug fixed by the above change.
2006-12-06* NEWS: Document the cp --preserve=ownership fix.Paul Eggert
* m4/jm-macros.m4 (coreutils_MACROS): Check for fchmod. * src/copy.c (fchmod_or_lchmod): New function. (copy_reg): New arg OMITTED_PERMISSIONS. All uses changed. Omit confusing and unused ", dst_mode" arg to 'open' without O_CREAT. When creating a file, use O_EXCL, so we're more likely to detect funny business by other processes. At the end, if permissions were omitted, chmod them back in. (copy_internal): If the ownership might change, omit some permissions at first, then restore them after chowning the file. * src/cp.c (make_dir_parents_private): Likewise. * src/copy.c (cached_umask): New function. * src/copy.h (cached_umask): New decl.
2006-10-18* src/copy.c (copy_internal): Don't pass mkdir a mode greater thanPaul Eggert
7777. This matches historical 'cp' behavior and avoids some (though not all) implementation-defined behavior of mkdir. * src/cp.c (make_dir_parents_private): Likewise. * src/copy.c (copy_internal): Don't pass 'open' a mode greater than 777. This is required by POSIX. It doesn't make any difference in actual behavior on any host that I know of.
2006-09-08mv and "cp -r" no longer fail when invoked with two argumentsJim Meyering
where the first one names a directory and the second name ends in a slash and doesn't exist. E.g., "mv dir B/", for nonexistent B, now succeeds, once more. This reverts part of the 2004-06-27 change for 5.3.0. * NEWS: Say the above. * src/mv.c (target_directory_operand): Don't require (here) that the target operand "look like" a directory. This change pushes the test down to the rename syscall level, where a "mv dir existing-non-dir/" will mistakenly succeed on older systems that ignore trailing slashes in the rename destination argument. * src/cp.c (target_directory_operand): Likewise, but for cp. * tests/mv/trailing-slash: Exercise the above fixes. * tests/cp/trailing-slash: New file. * tests/cp/Makefile.am (EXTRA_DIST): Add trailing-slash.
2006-09-03Don't include dirname.h, since system.h does it now.Paul Eggert
2006-08-28* src/copy.c (copy_internal): Don't test whether macros likePaul Eggert
S_ISLNK are defined, since they're always defined now. * src/cp.c (main): Likewise. * src/ln.c (main): Likewise. * src/ls.c (get_link_name, make_link_name): Likewise. * src/mkfifo.c (usage): Likewise. * src/who.c (S_IWGRP): Likewise.
2006-05-15(usage): Correct description of -a: s/-dpR/-dpPR/. From Tomas Pospisek.Jim Meyering
2006-03-26(target_directory_operand): Use new last_component.Jim Meyering
(ASSIGN_BASENAME_STRDUPA): Likewise. Reduce time spent traversing the string.
2006-02-06(usage): Use two spaces (not one) to separate theJim Meyering
option string from its description, so help2man formats the derived man page properly. Patch from Nicolas François in http://bugs.debian.org/351601.
2006-01-02Include lchmod.h.Paul Eggert
(re_protect, make_dir_parents_private): Use lchmod rather than chmod.
2005-12-28Don't include <assert.h>; it wasn't used.Jim Meyering
2005-12-17(umask_kill): With default acls, the umask is not to be applied.Jim Meyering
Remove umask_kill, don't change the process umask, and let the kernel apply the umask where appropriate. (make_dir_parents_private): Fix logic for POSIX ACLs.
2005-09-16Include stat-time.h, and use its functions instead of the obsoletePaul Eggert
TIMESPEC_NS macro.
2005-07-03(main): Using --reply now evokes a warning.Jim Meyering
(usage): Remove description of --reply.
2005-06-30Add uses of ARGMATCH_VERIFY to ensure thatJim Meyering
corresponding option string and value arrays are consistent. Remove a harmless trailing `, 0' from a value list.
2005-06-16Finally remove support for --version-control=S (-V).Jim Meyering
It was deprecated nearly 6 years ago and has been warning users to switch to --backup=S since fileutils-4.0j.
2005-06-02Don't use "path" or "filename".Paul Eggert
(parents_option): Renamed from flag_path. All uses changed. (make_dir_parents_private): Renamed from make_path_private. All uses changed. (usage): Don't use "path" to describe a file name.
2005-05-31(re_protect): Remove unnecessary call to geteuid.Paul Eggert
Use chown_failure_ok rather than our own code. (cp_options_init): Use chown_privileges rather than getuid.
2005-05-30(geteuid) [!defined _POSIX_VERSION]: Remove decl.Paul Eggert
2005-05-14Update FSF postal mail address.Jim Meyering
2005-05-14Update FSF postal mail address.Jim Meyering
2005-03-28(sparse_type_string, reply_args, decode_preserve_arg): Use NULL, not `0'.Jim Meyering
2005-01-25(usage): Add comma after "-P" to fix typo in previous patch.Paul Eggert
2005-01-24(usage): Merge the descriptions of --no-dereference and -P.Jim Meyering
2004-09-21Remove unused "case 0".Paul Eggert
2004-09-13Adjust to backup enum rename.Paul Eggert
2004-07-30(struct dir_attr, flag_path, remove_trailing_slashes,Paul Eggert
re_protect, make_path_private, target_directory_operand, do_copy, cp_option_init, decode_preserve_arg, main): Use bool when appropriate. (target_directory_operand): Do not clear *NEW_DST if stat succeeds. It's not necessary in that case, as *NEW_DST is always false already. (do_copy): Rewrite slightly to avoid need for "unreachable" comment. (main): Use EXIT_SUCCESS, EXIT_FAILURE instead of 0, 1.
2004-07-27(do_copy): find_backup_file_name no longer returns NULL, so don'tPaul Eggert
bother to check for this.
2004-07-04(do_copy): Assume path_concat returns non-NULL.Jim Meyering
(make_path_private): 2nd arg is now size_t, not int, to avoid problem when path_concat dir name is longer than 2 GiB (!).
2004-07-02Add short names -t and -T for --target-directoryJim Meyering
and --no-target-directory options, respectively. (NO_TARGET_DIRECTORY_OPTION, TARGET_DIRECTORY_OPTION): Remove. All uses changed to 'T' and 't', respectively. (long_opts, usage, do_copy, main): Add -t and -T as aliases for --target-directory and --no-target-directory, respectively.
2004-06-30Add support for --no-target-directory option.Jim Meyering
(NO_TARGET_DIRECTORY_OPTION): New constant. (long_opts, usage, do_copy, main): Add support for
2004-06-28 Use more-consistent rules among cp, ln, and mv when dealing withJim Meyering
last operands that are (or look like) directories. * src/cp.c (target_directory_operand): New, nearly-common function, It reports an error if the destination appears to be a directory (e.g., because it has a trailing slash) but is not. * src/cp.c (do_copy): Use it. * src/cp.c (do_copy): Don't assume argc is positive. Don't bother to lstat dest, since copy() will do that for us. Use "const" to avoid the need for cast. * src/cp.c (do_copy): Don't output a usage message because of file problems (e.g., an operand is not a directory). Use it only for syntax. Standardize on "target %s is not a directory" for the diagnostic. * src/cp.c (do_copy): Remove test for trailing slash, since target_directory_operand now does this. * src/cp.c (main): Reject multiple target directories. Check whether a specified target is a directory when parsing the options, using stat. This gives more-accurate diagnostics.
2004-06-28(usage): Fix copy+paste error in description ofJim Meyering
--target-directory: s/move/copy/. From Paul Jarc.
2004-06-21Standardize on the diagnostics given when someone givesJim Meyering
too few operands ("missing operand after `xxx'") or too many operands ("extra operand `xxx'"). Include "quote.h" and/or "error.h" if it wasn't already being included. (do_copy): Likewise.
2004-03-13(do_copy): Tweak wording in a diagnostic.Jim Meyering
Suggestion from Karl Berry. Include "quoatearg.h". (do_copy): Use quotearg_colon (not quote) for diagnostics that begin with `"%s:'.
2004-02-07(re_protect): Use `XSTAT (x, ...)' in place of `*(x->xstat) (...)'.Jim Meyering
(do_copy): Declare/use local xstat rather than x->xstat. (main): Remove code that set x.xstat.
2004-01-21(usage): Use EXIT_SUCCESS, not 0, for clarity.Jim Meyering
(exit_status): Remove static var.... (main): Making it local here instead. Use =, not |=, to set it.
2004-01-04(re_protect): Use ASSIGN_STRDUPA rather than alloca and strcpy.Jim Meyering
(make_path_private): Likewise.
2003-11-02(make_path_private): Use `sizeof *var' rather than `sizeof EXPLICIT_TYPE'.Jim Meyering
The former is more maintainable and usually shorter.
2003-10-18Most .c files (AUTHORS): Revert the WRITTEN_BY/AUTHORS changeJim Meyering
of 2003-09-19. Now, AUTHORS is a comma-separated list of strings. Update the call to parse_long_options so that `AUTHORS, NULL' are the last parameters. * src/true.c (main): Append NULL to version_etc argument list. * src/sys2.h (case_GETOPT_VERSION_CHAR): Likewise.
2003-09-28Remove unnecessary casts of alloca, since now it's guaranteed to be (void *).Jim Meyering
2003-09-18(WRITTEN_BY): Rename from AUTHORS.Jim Meyering
Begin each WRITTEN_BY string with `Written by ' and end it with `.'. Mark each WRITTEN_BY string as translatable.
2003-09-18revert previous changeJim Meyering
2003-09-18Update AUTHORS definition to be a comma-separated list of strings and/or updateJim Meyering
the call to parse_long_options so that `AUTHORS, NULL' are the last parameters.