summaryrefslogtreecommitdiff
path: root/src/copy.c
AgeCommit message (Collapse)Author
2009-09-05maint: remove some tab indentation from copy.cPádraig Brady
* src/copy.c (copy_internal): Remove tabs erroneously added in commit 3346c0af.
2009-09-04mv, cp: tweak LINK_FOLLOWS_SYMLINKS logicEric Blake
* gnulib: Update to latest gnulib. * src/copy.c (copy_internal): Adjust comment in light of POSIX 2008, and deal with macro now being tri-state.
2009-09-03cp: don't leak resources for each xattr preservation failureOndřej Vašík
* src/copy.c (copy_reg): Don't return from the function after an unsuccessful and required preservation of extended attributes. This resulted in leaking the copy buffer and file descriptors. * NEWS (Bug fixes): Mention the fix. The bug was introduced in coreutils-7.1 via commit 0889381c, 2009-01-23, "cp/mv: add xattr support".
2009-08-29cp --reflink: preserve attributes on cloned files if askedPádraig Brady
* src/copy.c (copy_reg): When cloning only skip the data copying * tests/cp/reflink-perm: New test to check times and modes copied * tests/Makefile.am: Reference the new test * NEWS: Mention the fix
2009-08-29cp --reflink: add an "auto" parameter to fall back to a normal copyPádraig Brady
* doc/coreutils.texi (cp invocation): Document the new "auto" and "always" options to --reflink. * src/copy.c (copy_reg): Fall back to a standard copy when reflink() is not supported and --reflink=auto specified. * src/copy.h [struct cp_options] (reflink): Change type s/bool/enum/. * src/cp.c (usage): Describe the --reflink={always,auto} options and expand a little on what --reflink does. (main): parse the new parameters to --reflink and allow all --sparse options with --reflink=auto. * src/install.c (cp_option_init): Init the enum instead of bool. * src/mv.c (cp_option_init): Likewise. * tests/cp/reflink-auto: A new test for falling back to normal copy. * tests/Makefile.am: Reference the new test. * NEWS: Mention the new feature.
2009-08-28build: avoid unused variable warnings on cygwinEric Blake
* src/copy.c (clone_file, copy_attr_by_fd, copy_attr_by_name): Mark up unused variables. * src/remove.c (dirent_inode_sort_may_be_useful): Likewise.
2009-08-25global: convert indentation-TABs to spacesJim Meyering
Transformed via this shell code: t=$'\t' git ls-files \ | grep -vE '(^|/)((GNU)?[Mm]akefile|ChangeLog)|\.(am|mk)$' \ | grep -vE 'tests/pr/|help2man' \ | xargs grep -lE "^ *$t" \ | xargs perl -MText::Tabs -ni -le \ '$m=/^( *\t[ \t]*)(.*)/; print $m ? expand($1) . $2 : $_'
2009-08-24cp: ignore obscure failure to preserve symlink time stamps,Jim Meyering
...when run on a kernel older than what was implied by headers and libraries tested at configure time. * src/copy.c (utimens_symlink): Ignore failure when errno == ENOSYS. * NEWS (Bug fixes): Mention it. Reported by Todd Zullinger and Kamil Dudka. Details in this thread: http://thread.gmane.org/gmane.linux.redhat.fedora.devel/119834
2009-08-14cp,mv: fix issues with preserving timestamps of copied symlinksPádraig Brady
* src/copy.c (copy_internal): On systems without utimensat don't use utimens on a symlink, as that would dereference the symlink. * tests/cp/abuse: To work around possible attribute preservation failures breaking the test, use cp -dR rather than cp -a.
2009-08-07cp: accept the --reflink optionGiuseppe Scrivano
* NEWS: Mention it. * doc/coreutils.texi (cp invocation): Describe it. * src/copy.h (struct cp_options) [reflink]: New member. * src/copy.c (usage): Describe it. (copy_reg): If reflink is true try to clone the file. (main): Check for --reflink. (cp_option_init): Initialize the new member. * src/install.c (cp_option_init): Initialize the new member. * src/mv.c (cp_option_init): Likewise. * tests/cp/sparse: Add a new test case.
2009-08-04cp -pP (and e.g., -a): preserve time stamps on symlinks, tooJim Meyering
* src/copy.c (utimensat_if_possible): New function. (copy_internal): Remove variable, "preserve_metadata". Replace with "dest_is_symlink". That covers all cases but one: the one in which cp --link has created hard links to non-directories. In that case, there is no need to update attributes of the links. Use utimensat_if_possible, to preserve timestamps of symlinks. * NEWS (New features): Mention this. * tests/Makefile.am (TESTS): Add cp/preserve-slink-time. * tests/cp/preserve-slink-time: New file. * m4/jm-macros.m4 (coreutils_MACROS): Test for utimensat. Reported in http://bugzilla.redhat.com/230866
2009-07-29cp: support btrfs' copy-on-write file clone operationGiuseppe Scrivano
* src/copy.c [HAVE_SYS_IOCTL_H]: Include <sys/ioctl.h>. (BTRFS_IOCTL_MAGIC, BTRFS_IOC_CLONE): Define. (clone_file): New function. (copy_reg): Use the btrfs clone operation if possible.
2009-07-08copy.c: remove a duplicate expressionOndřej Vašík
* src/copy.c (copy_attr_error): remove a redundant expression added in commit e0cf592f, 2009-04-27, "factor out test for errno ...".
2009-04-27copy.c: factor out test for errno value indicating "unsupported"Jim Meyering
* src/copy.c (errno_unsupported): New function. (copy_attr_error, copy_internal): Use it.
2009-04-27cp -a: diagnose failure when preserving xattr/context requiredOndřej Vašík
* src/copy.c (copy_attr_by_fs): Always print diagnostics when preserving xattrs is required. (copy_attr_by_name): Likewise. (copy_reg): Always print diagnostics when preserving SELinux context is required. (copy_internal): Likewise. Also, do not ignore ENOTSUP and ENODATA errors when preserving SELinux context is required. * NEWS (Bug fixes): Mention it.
2009-04-27mv: ignore xattr-preservation failure when not supported by filesystemOndřej Vašík
*src/copy.c: Do not warn about xattr-preservation failure when xattrs are not supported and preservation of xattrs is not explicitly required. Reported by Eric Sandeen in http://bugzilla.redhat.com/496142
2009-04-22cp: work around linux kernel bug: short-read != EOF on /procJim Meyering
Remove the optimization that avoided up to 50% of cp's read syscalls. Do not assume that a short read on a regular file indicates EOF. When reading from a file in /proc on linux [at least 2.6.9 - 2.6.29] into a 4k-byte buffer or larger, a short read does not always indicate EOF. For example, "cp /proc/slabinfo /tmp" copies only 4068 of the total 7493 bytes. This optimization (25719a33154f0c62ea9881f0c79ae312dd4cec7a, Improve performance a bit by optimizing away; 2005-11-24) appears to have been worth less than a 2% speed-up (and usually much less), so the impact of removing it is negligible. * src/copy.c (copy_reg): Don't exit the loop early. * tests/cp/proc-short-read: New test, lightly based on a suggestion from Mike Frysinger, to exercise this fix. * tests/Makefile.am (TESTS): Add cp/proc-short-read. * NEWS (Improve robustness): Mention this change.
2009-03-11cp: make -a option preserve xattrs, but with reduced diagnosticsOndřej Vašík
* copy.c (copy_attr_by_fd): Reduce xattr diagnostics for 'cp -a'. (copy_attr_by_name): Likewise. * cp.c (main): Preserve xattrs with -a option, when possible. * doc/coreutils.texi: Document that xattrs are preserved with cp -a, with no added diagnostics. * NEWS: Mention the change. * tests/misc/xattr: Add tests for 'cp --preserve=all' and 'cp -a'.
2009-03-11cat,cp,mv,install,split: Set the minimum IO block size used to 32KiBPádraig Brady
This is following on from this change: [02c3dc9d 2008-03-06 cat: use larger buffer sizes ...] which increased the IO block size used by cat by 8 times, but also capped it at 32KiB. * NEWS: Mention the change in behavior. * src/system.h: Add a new io_blksize() function that returns the max of ST_BLKSIZE or 32KiB, as this was seen as a good value for a minimum block size to use to get good performance while minimizing system call overhead. * src/cat.c: Use it. * src/copy.c: ditto * src/split.c: ditto
2009-02-27cp: diagnose invalid "cp -rl dir dir" right away, once againJim Meyering
Running "mkdir dir; cp -rl dir dir" would create dir/dir/dir/... rather than diagnosing the "copy-into-self" failure. The easy fix would have been to revert this part of the change [3ece0355 2008-11-09 cp: use far less memory in some cases] that introduced the bug: - remember_copied (dst_name, dst_sb.st_ino, dst_sb.st_dev); + if (!x->hard_link) + remember_copied (dst_name, dst_sb.st_ino, dst_sb.st_dev); However, that would have induced the failure of the new cp/link-heap test, due to the added memory pressure of recording 10k dev/ino pairs. And besides, I liked that improvement and wanted to keep it. Now that it's obvious recording the just-created-directory dev/ino needn't depend on the setting of hard_link, I realized it is necessary to record the pair only for the first directory created for each source command-line argument. I made that change, then noticed the new test, cp -rl a d d, would pass when run once, yet output the into-self diagnostic twice. Also note the side effect: it creates d/a and d/d. However, running that same command a second time, now with the modified directory, would fail. That turned out to be due to the fact that although the first into-self failure was detected in copy_dir, that function would continue copying other entries regardless -- and that would make it fail (eventually) with the unwanted recursion. * src/copy.c (copy_internal): This function needed an indicator of whether, for a give command line argument, it had already created its first directory. If so, no more need to record dev/ino pairs. If this is the first, then do record its pair. Hence, the new parameter. (copy_dir, copy): Update callers. (copy_dir): Upon any into-self failure, break out of the loop. * tests/cp/into-self: Test for the above. Reported by Mikael Magnusson.
2009-02-18cp: -a now preserves SELinux context, with reduced diagnosticsOndřej Vašík
* copy.c (copy_reg): Reduce SELinux context diagnostics for 'cp -a'. (copy_internal): Likewise * copy.h (cp_options): Add boolean reduce_diagnostics. * cp.c (usage): Say that --archive (-a) behaves like -dR --preserve=all. (cp_option_init): Initialize added reduce_diagnostics. (main): Add reduce_diagnostics for the -a option, and preserve SELinux context, if possible. * mv.c (cp_options_init): Initialize new cp_options booleans. * install.c (cp_option_init): Likewise. * NEWS: Mention those behaviour changes. * doc/coreutils.texi: Document --preserve=context, document that diagnostics are not shown for failures of non-mandatory attributes (just SELinux at the moment). * tests/cp/cp-a-selinux: Check not only failures, but succesful use of preserving SELinux context in cp.
2009-02-05avoid spurious parentheses/arith-op-related warnings from newer gccJim Meyering
* src/copy.c (set_owner): Use && rather than &. * src/stty.c (main): Likewise. * src/wc.c (wc): Likewise.
2009-01-29cp/mv: add xattr supportKamil Dudka
This patch was originally written by Andreas Grünbacher, nowadays available at http://www.suse.de/~agruen/coreutils/5.91/coreutils-xattr.diff * bootstrap.conf: Add gnulib module verror. * po/POTFILES.in: Add lib/verror.c. * m4/xattr.m4: Check for libattr availability, new configure option --disable-xattr. * m4/prereq.m4: Require gl_FUNC_XATTR. * src/Makefile.am: Link cp, mv and ginstall with libattr. * src/copy.h: Add preserve_xattr and require_preserve_xattr to cp_options. * src/copy.c (copy_attr_error): New function to handle errors during xattr copying. (copy_attr_quote): New function to quote file name in error messages printed by libattr. (copy_attr_free): Empty function requested by libattr to free quoted string. (copy_attr_by_fd): New fd-oriented function to copy xattr. (copy_attr_by_name): New name-oriented function to copy xattr. (copy_reg, copy_internal): Call copy_extended_attributes function. * src/cp.c (usage): Mention new --preserve=xattr option. (decode_preserve_arg): Handle new --preserve=xattr option. * src/mv.c: Always attempt to preserve xattr. * src/install.c: Never attempt to preserve xattr. * tests/misc/xattr: New test for xattr support in cp, mv and install. * tests/Makefile.am: Add the new test to list. * doc/coreutils.texi: Mention xattr support, new --preserve=xattr option. * NEWS: Mention the change.
2008-11-20cp: use far less memory in some casesJim Meyering
cp --link was "remembering" many name,dev,inode triples unnecessarily. cp was doing the same, even without --link, for every directory in the source hierarchy, while it can do its job with entries merely for the command-line arguments. Prompted by a report from Patrick Shoenfeld. Details <http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/15081>. * src/copy.c (copy_internal): Refrain from remembering name,dev,inode for most files, when invoked via cp --link. Record an infloop-avoidance triple for each directory specified on the command line, not for each directory in the source tree. Don't record a dir-triple when x->hard_link is set. * NEWS (Buf fixes): Mention it. * tests/cp/link-heap: New file. Test for cp's lowered memory usage. * tests/Makefile.am (TESTS): Add link-heap.
2008-10-19accommodate gnulib header removalsJim Meyering
* src/copy.c: Don't include "euidaccess.h" or "lchmod.h". * src/cp.c: Don't include "lchmod.h". * src/ls.c: Don't include "dirfd.h". * src/mkdir.c: Don't include "lchmod.h". * src/pwd.c: Don't include "dirfd.h". * src/remove.c: Don't include "dirfd.h" or "euidaccess.h". * src/test.c: Don't include "euidaccess.h". * gl/modules/getloadavg.diff: Adjust diff for changed context. * src/uptime.c (uptime): Remove declaration.
2008-10-17maint: avoid warnings due to attribute warn_unused_resultJim Meyering
Now that a (void) cast no longer suffices to ignore warnings from gcc about uses of functions marked with the warn_unused_result attribute, we need an alternative. For the record, here's one of the ignorable warnings: "copy.c:233: warning: ignoring return value of 'fchown', declared with attribute warn_unused_result" * bootstrap.conf (gnulib_modules): Import ignore-value. * src/copy.c: Include "ignore-value.h". (set_owner): Use ignore_value in place of "(void)" casts, to ignore lchown and fchown failures. * src/cp.c (re_protect): Likewise, to ignore lchown failure. * src/remove.c (preprocess_dir): Remove unnecessary "(void)" cast.
2008-06-03use gnulib's progname moduleJim Meyering
* bootstrap.conf (gnulib_modules): Add progname. * src/*.c (program_name): Remove declaration. * (main): Call set_program_name rather than setting program_name. * src/nice.c (main): Cast program_name to "(char *)". * src/prog-fprintf.c: Include "system.h" * src/system.h: Include "progname.h". * maint.mk (sc_program_name): Adjust rule. Suggestion from Eric Blake.
2008-06-02fix cpp indentation policy violationsJim Meyering
* src/copy.c (mkfifo): Indent nested "# define". * src/timeout.c (ECANCELED): Likewise.
2008-04-02"touch E; mkfifo F; cp -fR F E" no longer fails due to existing EJim Meyering
* src/copy.c (copy_internal): Revert change of 2005-03-01, 4303f0454592421eea48be87777d32a49e1d5e5b Prompted by Michael Stone, who pointed me to an old bug report from Ian Jackson: http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/7504 * tests/cp/special-f: New file. Test for the above. * tests/cp/Makefile.am (TESTS): Add special-f. * NEWS: mention this bug fix.
2008-04-02copy.c: remove an in-function #ifdefJim Meyering
* src/copy.c (rpl_mkfifo) [! HAVE_MKFIFO]: New function. (mkfifo) [! HAVE_MKFIFO]: Define to rpl_mkfifo. (copy_internal): Remove #ifdef. Signed-off-by: Jim Meyering <meyering@redhat.com>
2008-03-19mv: never unlink a destination file before calling renameJim Meyering
While cp --preserve=links must unlink certain destination files, mv must never do that. * src/copy.c (copy_internal): Pull the '! x->move_mode' test "up", so it affects the entire condition, and not just DEREF_NEVER mode. Reported by James Ralston in <http://bugzilla.redhat.com/438076>. * tests/mv/atomic2: New file. Test for the above fix. * tests/mv/Makefile.am (TESTS): Add atomic2. * NEWS: Mention the bug-fix. [Bug introduced in 367719ba5f1dbd5e2f7fa2466c441f23f66a7c9e]
2008-02-28Make copyright comments consistent.Jim Meyering
* src/mktemp.c: Update copyright to use newer form. Make first copyright lines consistent. Some did not end in ", Inc.". Due to that missing ", Inc" at end of line, emacs' copyright-updating code missed some opportunities. This corrects most of those, and adds some mistakenly omitted years. * src/chown-core.c: Adjust. * src/chown-core.h: Likewise. * src/copy.c: Likewise. * src/copy.h: Likewise. * src/cp-hash.c: Likewise. * src/cp.c: Likewise. * src/group-list.h: Likewise. * src/mktemp.c: Likewise. * src/stat.c: Likewise. * tests/chmod/equal-x: Likewise. * tests/dd/skip-seek: Likewise. * tests/envvar-check: Likewise. * tests/mv/into-self-2: Likewise.
2007-12-04Reflect change in gnulib: don't include getpagesize.h,Jim Meyering
now that it's provided by unistd.h. * src/cat.c: Don't include getpagesize.h. * src/copy.c: Likewise. * src/dd.c: Likewise. * src/shred.c: Likewise. * src/split.c: Likewise.
2007-12-01Add "extern" keyword to declaration of cp_options_default.Jim Meyering
* src/copy.c (cp_options_default): Mark as "extern", so the "sc_tight_scope" part of "make distcheck" passes.
2007-12-01Fix a security race with "cp -p A B" when B already exists.Paul Eggert
* src/copy.h (struct cp_options): New member owner_privileges. * src/copy.c (USE_ACL): Define to 0 if not defined, for convenience. (owner_failure_ok): New function. (set_owner): Avoid a security-related race by doing an extra chmod first if it looks like there might be trouble right after a chown. Accept a source struct stat rather than a uid and gid, and accept a boolean NEW_DST and destination struct stat. All callers changed. * src/copy.h (cp_options_default): New function, replacing the old chown_privileges. * src/copy.c (cp_options_default): Likewise. * src/cp.c (cp_option_init): Use it. * src/install.c (cp_option_init): Likewise. * src/mv.c (cp_option_init): Likewise.
2007-11-29Close a file descriptor leak when cp --preserve=context fails.Paul Eggert
* src/copy.c (copy_reg): Close dest_desc too, if getfscreatecon or fsetfilecon fail.
2007-11-24"cp -p" tries to preserve GID even if preserving the UID fails.Lasse Collin
* NEWS: Mention this new feature. * src/copy.c (set_owner): Try to preserve just the GID, when initial fchown/lchown fails. * src/cp.c (re_protect): Likewise.
2007-11-22Quiet warnings about unused parameters.Jim Meyering
* src/copy.c (set_author) [!HAVE_STRUCT_STAT_ST_AUTHOR]: "Use" each of the parameters.
2007-11-22cp: by default, refuse to copy through a dangling destination symlinkJim Meyering
* NEWS: Mention this change. * doc/coreutils.texi (cp invocation): Describe the new behavior. * src/copy.c: No longer include "canonicalize.h". (copy_reg): Upon failure to open a dangling destination symlink, don't canonicalize the name, but rather fail (default) or, with POSIXLY_CORRECT, repeat the open call without O_EXCL (potentially dangerous). * src/copy.h (struct cp_options) [open_dangling_dest_symlink]: New member. Reorder the others, grouping "bool" and "enum" members together. * tests/cp/thru-dangling: Test for changed and new behavior. * src/cp.c (cp_option_init): Initialize new member. * src/install.c (cp_option_init): Likewise. * src/mv.c (cp_option_init): Likewise. Signed-off-by: Jim Meyering <meyering@redhat.com>
2007-11-15Avoid misbehavior of a cross-device "mv" or "install".Jim Meyering
Those programs must not dereference a destination symlink. * src/copy.c (copy_reg): Don't treat a dangling destination symlink differently in move mode. In move mode, the only way the added O_EXCL can cause failure is when some other process has recreated the file this code unlinked a few instructions before.
2007-10-07Avoid a used-uninitialized error.Jim Meyering
* src/copy.c (copy_internal): Don't overload "use_stat".
2007-10-02Never copy through a symlink that cp has just created.Jim Meyering
* src/copy.c (copy_internal): When same-file detection requires 'stat'ing the destination file, also 'lstat' it and ensure that it wasn't the destination of a preceding copy operation. This bug was introduced on 2007-06-18. * tests/cp/abuse: New test for the above. * tests/cp/Makefile.am (TESTS): Add abuse.
2007-09-24copy.c: Remove definitions of factored-out functions.Jim Meyering
* src/copy.c: Include "file-set.h". (seen_file, record_file): Remove functions that I factored out on 2007-08-23.
2007-08-28Reflect renaming: mreadlink-with-size -> areadlink-with-size.Jim Meyering
* bootstrap.conf: Update module name. * src/copy.c (copy_internal): Update header and function names. * src/ls.c (get_link_name): Likewise. * src/readlink.c (main): Likewise. * src/stat.c (print_stat): Likewise.
2007-08-23Move functions from copy.c into new modules, since ln needs them, too.Jim Meyering
* bootstrap.conf (gnulib_modules): Add file-set. * gl/lib/file-set.c (record_file, seen_file): Functions from copy.c. * gl/lib/file-set.h: Add prototypes. * gl/lib/hash-triple.c (triple_hash, triple_hash_no_name): (triple_compare, triple_free): Functions from copy.c. * gl/lib/hash-triple.h (struct F_triple): Define. From copy.c. Add prototypes. * gl/modules/file-set: New module. * gl/modules/hash-triple: New module. * src/Makefile.am (copy_sources): New variable. (ginstall_SOURCES, cp_SOURCES, mv_SOURCES): Use it. * src/copy.c: Include hash-triple.h. No longer include hash-pjw.h. (copy_internal): Don't pass a NULL third argument to record_file, since that function no longer accepts that. (record_file): Move this function to file-set.c. Along the way, remove the code to allow a NULL stat-buffer pointer. Adjust sole caller. (seen_file): Move this function to file-set.c. (struct F_triple): Move declaration to hash-triple.h. (triple_compare, triple_free, triple_hash, triple_hash_no_name): Move these functions to hash-triple.c. Signed-off-by: Jim Meyering <jim@meyering.net>
2007-08-22* src/copy.c (DEST_INFO_INITIAL_CAPACITY): Correct a comment.Jim Meyering
2007-07-29Adjust indentation to reflect today's change.Jim Meyering
2007-07-29Attempt to copy a regular file, even if stat says it is empty.Jim Meyering
* NEWS: Document this bug fix. * src/copy.c (copy_reg): Read from a regular file, even if it appears (stat.st_size == 0) to be empty. This reverts an optimization introduced on 2005-11-23 for coreutils-6.0. Otherwise, "cp /proc/cpuinfo /tmp" creates an empty file, on e.g., linux-2.6.20. * tests/cp/proc-zero-len: New file. Test for the above. * tests/cp/Makefile.am (TESTS): Add proc-zero-len. Reported by Dan Berrangé.
2007-07-23Update all copyright notices to use the newer form.Jim Meyering
2007-07-19"cp -i --update older newer" no longer prompts; same for mvJim Meyering
* src/copy.c (copy_internal): Perform "update" check before the possible interactive prompt. Reported by zeno_AT_biyg_DOT_org in <http://bugzilla.redhat.com/248591> * tests/mv/update: Add tests for the above. * NEWS: Mention the bug fix.