]> git.ipfire.org Git - thirdparty/coreutils.git/commit
mv: fewer syscalls for ‘mv a b’
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 10 Jan 2018 08:48:51 +0000 (00:48 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 10 Jan 2018 08:51:54 +0000 (00:51 -0800)
commitbedd9bb6520a663cdaa0171879abc60bfc9c4f0a
treef6bf5174c4fbd21666853600970d4fa1e35e9c35
parent29baf25aa02d95c832a1258a71cbd2b8d25f5d09
mv: fewer syscalls for ‘mv a b’

This builds on a previous patch for mv atomicity (Bug#29961).
It merely improves performance; it does not fix bugs.
* src/copy.h (struct cp_options): New members last_file, rename_errno.
* src/copy.c (copy_internal): Support new rename_errno member
for the copy options.  Avoid calling stat when new members
suggest it’s not needed.
(cp_options_default): Initialize new members.
* src/mv.c: Include renameat2.h.
(main): With two arguments, first call ‘renamat2 (AT_FDCWD, "a",
AT_FDCWD, "b", RENAME_NOREPLACE)’.  Use its results to skip
remaining processing if possible; for example, if it succeeds
there is no need to stat either "a" or "b".  Also, set
x.last_file when it is the last file to rename.
src/copy.c
src/copy.h
src/mv.c