mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
Allow /dev/null to be added multiple times.
Change the test for duplicate drives so that you're allowed to
add /dev/null multiple times. This corresponds to traditional
usage.
This amends commit be47b66c30.
This commit is contained in:
@@ -297,6 +297,7 @@ guestfs__add_drive_opts (guestfs_h *g, const char *filename,
|
||||
char *name;
|
||||
char *abs_path = NULL;
|
||||
int use_cache_off;
|
||||
int check_duplicate;
|
||||
|
||||
if (check_path(g, filename) == -1)
|
||||
return -1;
|
||||
@@ -336,10 +337,16 @@ guestfs__add_drive_opts (guestfs_h *g, const char *filename,
|
||||
}
|
||||
}
|
||||
|
||||
/* Make the path canonical, so we can check if the user is trying to
|
||||
* add the same path twice. Allow /dev/null to be added multiple
|
||||
* times, in accordance with traditional usage.
|
||||
*/
|
||||
abs_path = realpath (filename, NULL);
|
||||
check_duplicate = STRNEQ (abs_path, "/dev/null");
|
||||
|
||||
struct drive **i = &(g->drives);
|
||||
while (*i != NULL) {
|
||||
if (STREQ((*i)->path, abs_path)) {
|
||||
if (check_duplicate && STREQ((*i)->path, abs_path)) {
|
||||
error (g, _("drive %s can't be added twice"), abs_path);
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
@@ -30,28 +30,6 @@ main (int argc, char *argv[])
|
||||
{
|
||||
guestfs_h *g;
|
||||
int r;
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen ("test1.img", "w");
|
||||
if (fp == NULL) {
|
||||
perror ("test1.img");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
fclose (fp);
|
||||
|
||||
fp = fopen ("test2.img", "w");
|
||||
if (fp == NULL) {
|
||||
perror ("test2.img");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
fclose (fp);
|
||||
|
||||
fp = fopen ("test3.img", "w");
|
||||
if (fp == NULL) {
|
||||
perror ("test3.img");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
fclose (fp);
|
||||
|
||||
g = guestfs_create ();
|
||||
if (g == NULL) {
|
||||
@@ -59,15 +37,15 @@ main (int argc, char *argv[])
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
r = guestfs_add_drive_opts (g, "test1.img", -1);
|
||||
r = guestfs_add_drive_opts (g, "/dev/null", -1);
|
||||
if (r == -1)
|
||||
exit (EXIT_FAILURE);
|
||||
r = guestfs_add_drive_opts (g, "test2.img",
|
||||
r = guestfs_add_drive_opts (g, "/dev/null",
|
||||
GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
|
||||
-1);
|
||||
if (r == -1)
|
||||
exit (EXIT_FAILURE);
|
||||
r = guestfs_add_drive_opts (g, "test3.img",
|
||||
r = guestfs_add_drive_opts (g, "/dev/null",
|
||||
GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
|
||||
GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
|
||||
-1);
|
||||
@@ -76,9 +54,5 @@ main (int argc, char *argv[])
|
||||
|
||||
guestfs_close (g);
|
||||
|
||||
unlink ("test1.img");
|
||||
unlink ("test2.img");
|
||||
unlink ("test3.img");
|
||||
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user