diff options
author | Pádraig Brady <P@draigBrady.com> | 2016-01-02 18:38:37 +0000 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2016-01-03 12:58:39 +0000 |
commit | 6c65ce4c643b038c61bd332aab5ea87a75117273 (patch) | |
tree | 76190ad69cfe2f11a9c8b8c5e6a4ac2347887467 /src | |
parent | 50a950ba69c2ba8f2300c9e77f67978979537ad5 (diff) | |
download | coreutils-6c65ce4c643b038c61bd332aab5ea87a75117273.tar.xz |
install: fix relative copies to absolute directory with -D
* src/install.c (mkancesdirs_safe_wd): Unconditionally
restore the current working directory when possibly called
multiple times (from install_file_in_dir()).
* tests/install/create-leading.sh: Add a test case.
* NEWS: Mention the fix.
Fixes http://bugs.gnu.org/21497
Diffstat (limited to 'src')
-rw-r--r-- | src/install.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/install.c b/src/install.c index 1bdb757a1..6efb29e66 100644 --- a/src/install.c +++ b/src/install.c @@ -704,14 +704,17 @@ install_file_in_file (const char *from, const char *to, return change_attributes (to); } -/* Copy file FROM onto file TO, creating any missing parent directories of TO. +/* Create any missing parent directories of TO, + while maintaining the current Working Directory. Return true if successful. */ static bool -mkancesdirs_safe_wd (char const *from, char *to, struct cp_options *x) +mkancesdirs_safe_wd (char const *from, char *to, struct cp_options *x, + bool save_always) { bool save_working_directory = - ! (IS_ABSOLUTE_FILE_NAME (from) && IS_ABSOLUTE_FILE_NAME (to)); + save_always + || ! (IS_ABSOLUTE_FILE_NAME (from) && IS_ABSOLUTE_FILE_NAME (to)); int status = EXIT_SUCCESS; struct savewd wd; @@ -749,7 +752,7 @@ static bool install_file_in_file_parents (char const *from, char *to, const struct cp_options *x) { - return (mkancesdirs_safe_wd (from, to, (struct cp_options *)x) + return (mkancesdirs_safe_wd (from, to, (struct cp_options *)x, false) && install_file_in_file (from, to, x)); } @@ -766,7 +769,7 @@ install_file_in_dir (const char *from, const char *to_dir, bool ret = true; if (mkdir_and_install) - ret = mkancesdirs_safe_wd (from, to, (struct cp_options *)x); + ret = mkancesdirs_safe_wd (from, to, (struct cp_options *)x, true); ret = ret && install_file_in_file (from, to, x); free (to); |