summaryrefslogtreecommitdiff
path: root/src/local.mk
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2017-02-11 23:12:31 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2017-02-11 23:14:02 -0800
commit376967889ed7ed561e46ff6d88a66779db62737a (patch)
tree7ca32f07b738fc2f9902c1643bb01dedb7d1066b /src/local.mk
parent2f69dba5df8caaf9eda658c1808b1379e9949f22 (diff)
downloadcoreutils-376967889ed7ed561e46ff6d88a66779db62737a.tar.xz
ln: replace destination links more atomically
If the file B already exists, commands like 'ln -f A B' and 'cp -fl A B' no longer remove B before creating the new link. Instead, they arrange for the new link to replace B atomically. This should fix a race condition reported by Mike Crowe (Bug#25680). * NEWS, doc/coreutils.texi (cp invocation, ln invocation): Document this. * bootstrap.conf (gnulib_modules): Add symlinkat. * src/copy.c, src/ln.c: Include force-link.h. * src/copy.c (same_file_ok): It's also OK to remove a destination symlink when creating symbolic links, or when the source and destination are on the same file system and when creating hard links. * src/copy.c (create_hard_link, copy_internal): * src/ln.c (do_link): Rewrite using force_linkat and force_symlinkat, to close a window where the destination temporarily does not exist. * src/cp.c (main): Do not set x.unlink_dest_before_opening merely because we are in link-creation mode. * src/force-link.c, src/force-link.h: New files. * src/local.mk (copy_sources, src_ln_SOURCES): Add them. * tests/cp/same-file.sh: Adjust test case to match fixed behavior.
Diffstat (limited to 'src/local.mk')
-rw-r--r--src/local.mk8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/local.mk b/src/local.mk
index 5b25fcb87..84df09916 100644
--- a/src/local.mk
+++ b/src/local.mk
@@ -328,7 +328,9 @@ copy_sources = \
src/copy.c \
src/cp-hash.c \
src/extent-scan.c \
- src/extent-scan.h
+ src/extent-scan.h \
+ src/force-link.c \
+ src/force-link.h
# Use 'ginstall' in the definition of PROGRAMS and in dependencies to avoid
# confusion with the 'install' target. The install rule transforms 'ginstall'
@@ -357,7 +359,9 @@ src_vdir_SOURCES = src/ls.c src/ls-vdir.c
src_id_SOURCES = src/id.c src/group-list.c
src_groups_SOURCES = src/groups.c src/group-list.c
src_ls_SOURCES = src/ls.c src/ls-ls.c
-src_ln_SOURCES = src/ln.c src/relpath.c src/relpath.h
+src_ln_SOURCES = src/ln.c \
+ src/force-link.c src/force-link.h \
+ src/relpath.c src/relpath.h
src_chown_SOURCES = src/chown.c src/chown-core.c
src_chgrp_SOURCES = src/chgrp.c src/chown-core.c
src_kill_SOURCES = src/kill.c src/operand2sig.c