summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-09-22 15:40:43 +0000
committerJim Meyering <jim@meyering.net>2000-09-22 15:40:43 +0000
commitc2c680ad95f304dae28b2607cb741fa7cac69486 (patch)
tree46379a741855fe2cb5a1f5c68542d8c72140c520 /src
parente34407ac096cc1785423043c2858b2d906858204 (diff)
downloadcoreutils-c2c680ad95f304dae28b2607cb741fa7cac69486.tar.xz
(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.
Diffstat (limited to 'src')
-rw-r--r--src/mv.c29
1 files changed, 17 insertions, 12 deletions
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.