lib: Fix guestfs_int_download_to_tmp.

Since commit 65cfecb0f5,
‘guestfs_int_download_to_tmp’ was buggy because it did not deal with
the case where a guest had multiple roots.  It cached the downloaded
file under a single name which was not distinguished by which root we
were looking at.  As a result, if you inspected (eg.) the icon on such
a guest, then in some circumstances the same icon could be returned
for all roots (incorrectly).

This changes the function in a few ways:

 - Don't cache downloaded files.  It wasn't a useful feature of the
   function in most scenarios.  Instead a new name is generated for
   every call.

 - Use guestfs_int_make_temp_path.

 - Allow an extension to be specified.
This commit is contained in:
Richard W.M. Jones
2017-09-19 11:59:35 +01:00
parent 0ec0af27c5
commit 0734afd41f
3 changed files with 21 additions and 29 deletions

View File

@@ -370,14 +370,12 @@ list_applications_rpm (guestfs_h *g, const char *root)
struct guestfs_application2_list *apps = NULL;
struct read_package_data data;
Name = guestfs_int_download_to_tmp (g,
"/var/lib/rpm/Name", "rpm_Name",
Name = guestfs_int_download_to_tmp (g, "/var/lib/rpm/Name", NULL,
MAX_PKG_DB_SIZE);
if (Name == NULL)
goto error;
Packages = guestfs_int_download_to_tmp (g,
"/var/lib/rpm/Packages", "rpm_Packages",
Packages = guestfs_int_download_to_tmp (g, "/var/lib/rpm/Packages", NULL,
MAX_PKG_DB_SIZE);
if (Packages == NULL)
goto error;
@@ -429,7 +427,7 @@ list_applications_deb (guestfs_h *g, const char *root)
char **continuation_field = NULL;
size_t continuation_field_len = 0;
status = guestfs_int_download_to_tmp (g, "/var/lib/dpkg/status", "status",
status = guestfs_int_download_to_tmp (g, "/var/lib/dpkg/status", NULL,
MAX_PKG_DB_SIZE);
if (status == NULL)
return NULL;
@@ -605,7 +603,7 @@ list_applications_pacman (guestfs_h *g, const char *root)
fname = safe_malloc (g, strlen (curr->name) + path_len + 1);
sprintf (fname, "/var/lib/pacman/local/%s/desc", curr->name);
free (desc_file);
desc_file = guestfs_int_download_to_tmp (g, fname, curr->name, 8192);
desc_file = guestfs_int_download_to_tmp (g, fname, NULL, 8192);
/* The desc files are small (4K). If the desc file does not exist or is
* larger than the 8K limit we've used, the database is probably corrupted,
@@ -714,7 +712,7 @@ list_applications_apk (guestfs_h *g, const char *root)
*url = NULL, *description = NULL;
installed = guestfs_int_download_to_tmp (g, "/lib/apk/db/installed",
"installed", MAX_PKG_DB_SIZE);
NULL, MAX_PKG_DB_SIZE);
if (installed == NULL)
return NULL;