From c2c680ad95f304dae28b2607cb741fa7cac69486 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Fri, 22 Sep 2000 15:40:43 +0000 Subject: (do_move): Moving a directory specified with a trailing slash from one partition to another, and giving it a different name at the destination would cause mv to get a failed assertion. Reported by Michael Stone. (strip_trailing_slashes_2): Move function definition to precede new first use. --- src/mv.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/mv.c b/src/mv.c index 0806d5356..9a9c5fc0e 100644 --- a/src/mv.c +++ b/src/mv.c @@ -145,6 +145,18 @@ is_real_dir (const char *path) return lstat (path, &stats) == 0 && S_ISDIR (stats.st_mode); } +static int +strip_trailing_slashes_2 (char *path) +{ + char *end_p = path + strlen (path) - 1; + char *slash = end_p; + + while (slash > path && *slash == '/') + *slash-- = '\0'; + + return slash < end_p; +} + /* Move SOURCE onto DEST. Handles cross-filesystem moves. If SOURCE is a directory, DEST must not exist. Return 0 if successful, non-zero if an error occurred. */ @@ -233,6 +245,11 @@ do_move (const char *source, const char *dest, const struct cp_options *x) remove_init (); fspec_init_file (&fs, dir_to_remove); + + /* Remove any trailing slashes. This is necessary if we + took the else branch of movefile. */ + strip_trailing_slashes_2 (fs.filename); + status = rm (&fs, 1, &rm_options); assert (VALID_STATUS (status)); if (status == RM_ERROR) @@ -251,18 +268,6 @@ do_move (const char *source, const char *dest, const struct cp_options *x) return fail; } -static int -strip_trailing_slashes_2 (char *path) -{ - char *end_p = path + strlen (path) - 1; - char *slash = end_p; - - while (slash > path && *slash == '/') - *slash-- = '\0'; - - return slash < end_p; -} - /* Move file SOURCE onto DEST. Handles the case when DEST is a directory. DEST_IS_DIR must be nonzero when DEST is a directory or a symlink to a directory and zero otherwise. -- cgit v1.2.3-54-g00ecf