diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2007-06-15 22:47:16 +0200 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2007-06-15 22:47:16 +0200 |
commit | cdec7e6e93db547a80525c24167345a090a00273 (patch) | |
tree | ca98ab8f400d602f30f1642fb1ff8b57c9713b25 /doc | |
parent | cad884a24545464cb42296834a8b5c02ee116379 (diff) | |
download | coreutils-cdec7e6e93db547a80525c24167345a090a00273.tar.xz |
Correct cp's handling of destination symlinks in some cases.
* 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.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/coreutils.texi | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 4fdee3ecb..7290ab27f 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -6910,13 +6910,22 @@ By default, @command{cp} does not copy directories. However, the copy recursively by descending into source directories and copying files to corresponding destination directories. -By default, @command{cp} follows symbolic links only when not copying +When copying from a symbolic link, @command{cp} normally follows the +link only when not copying recursively. This default can be overridden with the @option{--archive} (@option{-a}), @option{-d}, @option{--dereference} (@option{-L}), @option{--no-dereference} (@option{-P}), and @option{-H} options. If more than one of these options is specified, the last one silently overrides the others. +When copying to a symbolic link, @command{cp} normally follows the +link when creating or copying to a regular file, even if the link is +dangling. However, @command{cp} does not follow these links when +creating directories or special files. Also, when an option like +@option{--backup} or @option{--link} acts to rename or remove the +destination before copying, @command{cp} renames or removes the +symbolic link rather than the file it points to. + By default, @command{cp} copies the contents of special files only when not copying recursively. This default can be overridden with the @option{--copy-contents} option. @@ -6996,10 +7005,10 @@ Equivalent to @option{--no-dereference --preserve=links}. @opindex --force When copying without this option and an existing destination file cannot be opened for writing, the copy fails. However, with @option{--force}), -when a destination file cannot be opened, @command{cp} then unlinks it and +when a destination file cannot be opened, @command{cp} then removes it and tries to open it again. Contrast this behavior with that enabled by @option{--link} and @option{--symbolic-link}, whereby the destination file -is never opened but rather is unlinked unconditionally. Also see the +is never opened but rather is removed unconditionally. Also see the description of @option{--remove-destination}. This option is independent of the @option{--interactive} or @@ -7029,7 +7038,7 @@ Make hard links instead of copies of non-directories. @itemx --dereference @opindex -L @opindex --dereference -Always follow symbolic links. +Follow symbolic links when copying from them. @item -P @itemx --no-dereference @@ -7037,7 +7046,8 @@ Always follow symbolic links. @opindex --no-dereference @cindex symbolic links, copying Copy symbolic links as symbolic links rather than copying the files that -they point to. +they point to. This option affects only symbolic links in the source; +symbolic links in the destination are always followed if possible. @item -p @itemx @w{@kbd{--preserve}[=@var{attribute_list}]} @@ -7127,8 +7137,8 @@ about each existing destination file. @cindex copying directories recursively @cindex recursively copying directories @cindex non-directories, copying as special files -Copy directories recursively. Symbolic links are not followed by -default; see the @option{--archive} (@option{-a}), @option{-d}, +Copy directories recursively. By default, do not follow symbolic +links in the source; see the @option{--archive} (@option{-a}), @option{-d}, @option{--dereference} (@option{-L}), @option{--no-dereference} (@option{-P}), and @option{-H} options. Special files are copied by creating a destination file of the same type as the source; see the |