From 57c812cc3e17ecf5df887029221fe3f2d0cd7ea0 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 29 Jan 2022 11:40:17 -0800 Subject: mv: when installing to dir use dir-relative names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the destination for mv is a directory, use functions like openat to access the destination files, when such functions are available. This should be more efficient and should avoid some race conditions. Likewise for 'install'. * src/cp.c (must_be_working_directory, target_directory_operand) (target_dirfd_valid): Move from here ... * src/system.h: ... to here, so that install and mv can use them. Make them inline so GCC doesn’t complain. * src/install.c (lchown) [HAVE_LCHOWN]: Remove; no longer needed. (need_copy, copy_file, change_attributes, change_timestamps) (install_file_in_file, install_file_in_dir): New args for directory-relative names. All uses changed. Continue to pass full names as needed, for diagnostics and for lower-level functions that do not support directory-relative names. (install_file_in_dir): Update *TARGET_DIRFD as needed. (main): Handle target-directory in the new, cp-like way. * src/mv.c (remove_trailing_slashes): Remove static var; now local. (do_move): New args for directory-relative names. All uses changed. Continue to pass full names as needed, for diagnostics and for lower-level functions that do not support directory-relative names. (movefile): Remove; no longer needed. (main): Handle target-directory in the new, cp-like way. * tests/install/basic-1.sh: * tests/mv/diag.sh: Adjust to match new diagnostic wording. --- tests/install/basic-1.sh | 2 +- tests/mv/diag.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/install/basic-1.sh b/tests/install/basic-1.sh index 83bec639b..690d591e5 100755 --- a/tests/install/basic-1.sh +++ b/tests/install/basic-1.sh @@ -131,7 +131,7 @@ EOF touch sub4/file_exists || framework_failure_ ginstall -t sub4/file_exists -Dv file >out 2>&1 && fail=1 compare - out <<\EOF || fail=1 -ginstall: target 'sub4/file_exists' is not a directory +ginstall: failed to access 'sub4/file_exists': Not a directory EOF # Ensure that -D with an already existing directory for -t's option argument diff --git a/tests/mv/diag.sh b/tests/mv/diag.sh index 92410699f..c0a558548 100755 --- a/tests/mv/diag.sh +++ b/tests/mv/diag.sh @@ -39,8 +39,8 @@ mv: missing file operand Try 'mv --help' for more information. mv: missing destination file operand after 'no-file' Try 'mv --help' for more information. -mv: target 'f1' is not a directory -mv: target 'f2' is not a directory +mv: target 'f1': Not a directory +mv: target directory 'f2': Not a directory EOF compare exp out || fail=1 -- cgit v1.2.3