diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2006-10-06 20:44:31 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2006-10-06 20:44:31 +0000 |
commit | 4767fc607e5fd38b2a9c8db2d876125aaa10e578 (patch) | |
tree | b4468e643bfee985d4a797ce142567f17dbfe7a5 /src/install.c | |
parent | 0fc6edb71490b03c79dd03c903a4b72ce2a23d81 (diff) | |
download | coreutils-4767fc607e5fd38b2a9c8db2d876125aaa10e578.tar.xz |
Fix bug reported today by Mike Frysinger: mkdir -pv is logging the
wrong file name in some cases.
* src/install.c (struct install_options): New type.
(install_file_in_file_parents, main):
Use it instead of struct cp_options.
(process_dir): Remember the full name.
(announce_mkdir, make_ancestor): Use the full name in announcements.
* src/mkdir.c (struct mkdir_options): Add full_name member.
(make_ancestor): Use the full name in announcements.
(process_dir): Remember the full name.
* tests/mkdir/Makefile.am (TESTS): Add p-v.
* tests/mkdir/p-v: New file, to test this bug.
Diffstat (limited to 'src/install.c')
-rw-r--r-- | src/install.c | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/src/install.c b/src/install.c index 9c5150fbc..aabbafaf0 100644 --- a/src/install.c +++ b/src/install.c @@ -66,12 +66,22 @@ /* Number of bytes of a file to copy at a time. */ #define READ_SIZE (32 * 1024) +/* Options passed to subsidiary functions. */ +struct install_options +{ + /* Full name of file being installed. */ + char const *full_name; + + /* Options for cp-related code. */ + struct cp_options cp; +}; + static bool change_timestamps (struct stat const *from_sb, char const *to); static bool change_attributes (char const *name); static bool copy_file (const char *from, const char *to, const struct cp_options *x); static bool install_file_in_file_parents (char const *from, char *to, - struct cp_options *x); + struct install_options *x); static bool install_file_in_dir (const char *from, const char *to_dir, const struct cp_options *x); static bool install_file_in_file (const char *from, const char *to, @@ -198,6 +208,8 @@ target_directory_operand (char const *file) static int process_dir (char *dir, struct savewd *wd, void *options) { + struct install_options *o = options; + o->full_name = dir; return (make_dir_parents (dir, wd, make_ancestor, options, dir_mode, announce_mkdir, @@ -216,7 +228,7 @@ main (int argc, char **argv) char *backup_suffix_string; char *version_control_string = NULL; bool mkdir_and_install = false; - struct cp_options x; + struct install_options x; char const *target_directory = NULL; bool no_target_directory = false; int n_files; @@ -230,7 +242,7 @@ main (int argc, char **argv) atexit (close_stdout); - cp_option_init (&x); + cp_option_init (&x.cp); owner_name = NULL; group_name = NULL; @@ -268,7 +280,7 @@ main (int argc, char **argv) mkdir_and_install = true; break; case 'v': - x.verbose = true; + x.cp.verbose = true; break; case 'g': group_name = optarg; @@ -280,7 +292,7 @@ main (int argc, char **argv) owner_name = optarg; break; case 'p': - x.preserve_timestamps = true; + x.cp.preserve_timestamps = true; break; case 'S': make_backups = true; @@ -322,10 +334,10 @@ main (int argc, char **argv) if (backup_suffix_string) simple_backup_suffix = xstrdup (backup_suffix_string); - x.backup_type = (make_backups - ? xget_version (_("backup type"), - version_control_string) - : no_backups); + x.cp.backup_type = (make_backups + ? xget_version (_("backup type"), + version_control_string) + : no_backups); n_files = argc - optind; file = argv + optind; @@ -385,15 +397,15 @@ main (int argc, char **argv) { if (! (mkdir_and_install ? install_file_in_file_parents (file[0], file[1], &x) - : install_file_in_file (file[0], file[1], &x))) + : install_file_in_file (file[0], file[1], &x.cp))) exit_status = EXIT_FAILURE; } else { int i; - dest_info_init (&x); + dest_info_init (&x.cp); for (i = 0; i < n_files; i++) - if (! install_file_in_dir (file[i], target_directory, &x)) + if (! install_file_in_dir (file[i], target_directory, &x.cp)) exit_status = EXIT_FAILURE; } } @@ -406,7 +418,7 @@ main (int argc, char **argv) static bool install_file_in_file_parents (char const *from, char *to, - struct cp_options *x) + struct install_options *x) { bool save_working_directory = ! (IS_ABSOLUTE_FILE_NAME (from) && IS_ABSOLUTE_FILE_NAME (to)); @@ -437,7 +449,7 @@ install_file_in_file_parents (char const *from, char *to, } } - return (status == EXIT_SUCCESS && install_file_in_file (from, to, x)); + return (status == EXIT_SUCCESS && install_file_in_file (from, to, &x->cp)); } /* Copy file FROM onto file TO and give TO the appropriate @@ -624,8 +636,8 @@ get_ids (void) static void announce_mkdir (char const *dir, void *options) { - struct cp_options const *x = options; - if (x->verbose) + struct install_options const *x = options; + if (x->cp.verbose) error (0, 0, _("creating directory %s"), quote (dir)); } @@ -633,9 +645,10 @@ announce_mkdir (char const *dir, void *options) static int make_ancestor (char const *dir, void *options) { + struct install_options const *x = options; int r = mkdir (dir, DEFAULT_MODE); if (r == 0) - announce_mkdir (dir, options); + announce_mkdir (x->full_name, options); return r; } |