1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-08-07 09:11:11 +02:00

(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.
This commit is contained in:
Jim Meyering
2000-09-22 15:40:43 +00:00
parent e34407ac09
commit c2c680ad95
+17 -12
View File
@@ -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.