[Libguestfs] [PATCH v12 07/11] lib: inspect: Remove ‘fs’ parameter from ‘guestfs_int_download_to_tmp’.

Richard W.M. Jones rjones at redhat.com
Wed Aug 9 17:23:42 UTC 2017


After we move inspection code to the daemon, the library will no
longer have access to ‘struct inspect_fs’, and so we won't be able to
prefix downloads with the "root filesystem number".

Just remove this prefix (it's internal only).  However it does mean
that this function can no longer cache downloaded files.
---
 lib/guestfs-internal.h |  2 +-
 lib/inspect-apps.c     | 10 +++++-----
 lib/inspect-icon.c     | 10 +++++-----
 lib/inspect.c          | 11 ++---------
 4 files changed, 13 insertions(+), 20 deletions(-)

diff --git a/lib/guestfs-internal.h b/lib/guestfs-internal.h
index 6dbaba9bd..585dac706 100644
--- a/lib/guestfs-internal.h
+++ b/lib/guestfs-internal.h
@@ -855,7 +855,7 @@ extern int guestfs_int_set_backend (guestfs_h *g, const char *method);
 
 /* inspect.c */
 extern void guestfs_int_free_inspect_info (guestfs_h *g);
-extern char *guestfs_int_download_to_tmp (guestfs_h *g, struct inspect_fs *fs, const char *filename, const char *basename, uint64_t max_size);
+extern char *guestfs_int_download_to_tmp (guestfs_h *g, const char *filename, const char *basename, uint64_t max_size);
 extern int guestfs_int_parse_unsigned_int (guestfs_h *g, const char *str);
 extern int guestfs_int_parse_unsigned_int_ignore_trailing (guestfs_h *g, const char *str);
 extern struct inspect_fs *guestfs_int_search_for_root (guestfs_h *g, const char *root);
diff --git a/lib/inspect-apps.c b/lib/inspect-apps.c
index 0ea962a73..86cf82333 100644
--- a/lib/inspect-apps.c
+++ b/lib/inspect-apps.c
@@ -393,13 +393,13 @@ list_applications_rpm (guestfs_h *g, struct inspect_fs *fs)
   struct guestfs_application2_list *apps = NULL;
   struct read_package_data data;
 
-  Name = guestfs_int_download_to_tmp (g, fs,
+  Name = guestfs_int_download_to_tmp (g,
 				      "/var/lib/rpm/Name", "rpm_Name",
 				      MAX_PKG_DB_SIZE);
   if (Name == NULL)
     goto error;
 
-  Packages = guestfs_int_download_to_tmp (g, fs,
+  Packages = guestfs_int_download_to_tmp (g,
 					  "/var/lib/rpm/Packages", "rpm_Packages",
 					  MAX_PKG_DB_SIZE);
   if (Packages == NULL)
@@ -452,7 +452,7 @@ list_applications_deb (guestfs_h *g, struct inspect_fs *fs)
   char **continuation_field = NULL;
   size_t continuation_field_len = 0;
 
-  status = guestfs_int_download_to_tmp (g, fs, "/var/lib/dpkg/status", "status",
+  status = guestfs_int_download_to_tmp (g, "/var/lib/dpkg/status", "status",
 					MAX_PKG_DB_SIZE);
   if (status == NULL)
     return NULL;
@@ -628,7 +628,7 @@ list_applications_pacman (guestfs_h *g, struct inspect_fs *fs)
     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, fs, fname, curr->name, 8192);
+    desc_file = guestfs_int_download_to_tmp (g, fname, curr->name, 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,
@@ -736,7 +736,7 @@ list_applications_apk (guestfs_h *g, struct inspect_fs *fs)
   CLEANUP_FREE char *name = NULL, *version = NULL, *release = NULL, *arch = NULL,
     *url = NULL, *description = NULL;
 
-  installed = guestfs_int_download_to_tmp (g, fs, "/lib/apk/db/installed",
+  installed = guestfs_int_download_to_tmp (g, "/lib/apk/db/installed",
                                            "installed", MAX_PKG_DB_SIZE);
   if (installed == NULL)
     return NULL;
diff --git a/lib/inspect-icon.c b/lib/inspect-icon.c
index 89c232f5b..89f5da082 100644
--- a/lib/inspect-icon.c
+++ b/lib/inspect-icon.c
@@ -270,7 +270,7 @@ get_png (guestfs_h *g, struct inspect_fs *fs, const char *filename,
   if (max_size == 0)
     max_size = 4 * w * h;
 
-  local = guestfs_int_download_to_tmp (g, fs, real, "icon", max_size);
+  local = guestfs_int_download_to_tmp (g, real, "icon", max_size);
   if (!local)
     return NOT_FOUND;
 
@@ -421,7 +421,7 @@ icon_cirros (guestfs_h *g, struct inspect_fs *fs, size_t *size_r)
   if (!STRPREFIX (type, "ASCII text"))
     return NOT_FOUND;
 
-  local = guestfs_int_download_to_tmp (g, fs, CIRROS_LOGO, "icon", 1024);
+  local = guestfs_int_download_to_tmp (g, CIRROS_LOGO, "icon", 1024);
   if (!local)
     return NOT_FOUND;
 
@@ -505,7 +505,7 @@ icon_windows_xp (guestfs_h *g, struct inspect_fs *fs, size_t *size_r)
   if (r == 0)
     return NOT_FOUND;
 
-  filename_downloaded = guestfs_int_download_to_tmp (g, fs, filename_case,
+  filename_downloaded = guestfs_int_download_to_tmp (g, filename_case,
 						     "explorer.exe",
 						     MAX_WINDOWS_EXPLORER_SIZE);
   if (filename_downloaded == NULL)
@@ -575,7 +575,7 @@ icon_windows_7 (guestfs_h *g, struct inspect_fs *fs, size_t *size_r)
   if (win7_explorer[i] == NULL)
     return NOT_FOUND;
 
-  filename_downloaded = guestfs_int_download_to_tmp (g, fs, filename_case,
+  filename_downloaded = guestfs_int_download_to_tmp (g, filename_case,
 						     "explorer.exe",
 						     MAX_WINDOWS_EXPLORER_SIZE);
   if (filename_downloaded == NULL)
@@ -629,7 +629,7 @@ icon_windows_8 (guestfs_h *g, struct inspect_fs *fs, size_t *size_r)
   if (r == 0)
     return NOT_FOUND;
 
-  filename_downloaded = guestfs_int_download_to_tmp (g, fs, filename_case,
+  filename_downloaded = guestfs_int_download_to_tmp (g, filename_case,
 						     "wlive48x48.png", 8192);
   if (filename_downloaded == NULL)
     return NOT_FOUND;
diff --git a/lib/inspect.c b/lib/inspect.c
index 37d175873..f4ad192a9 100644
--- a/lib/inspect.c
+++ b/lib/inspect.c
@@ -741,7 +741,7 @@ guestfs_int_free_inspect_info (guestfs_h *g)
  * handle the case of multiple roots.
  */
 char *
-guestfs_int_download_to_tmp (guestfs_h *g, struct inspect_fs *fs,
+guestfs_int_download_to_tmp (guestfs_h *g,
 			     const char *filename,
 			     const char *basename, uint64_t max_size)
 {
@@ -750,18 +750,11 @@ guestfs_int_download_to_tmp (guestfs_h *g, struct inspect_fs *fs,
   char devfd[32];
   int64_t size;
 
-  /* Make the basename unique by prefixing it with the fs number.
-   * This also ensures there is one cache per filesystem.
-   */
-  if (asprintf (&r, "%s/%td-%s", g->tmpdir, fs - g->fses, basename) == -1) {
+  if (asprintf (&r, "%s/%s", g->tmpdir, basename) == -1) {
     perrorf (g, "asprintf");
     return NULL;
   }
 
-  /* If the file has already been downloaded, return. */
-  if (access (r, R_OK) == 0)
-    return r;
-
   /* Check size of remote file. */
   size = guestfs_filesize (g, filename);
   if (size == -1)
-- 
2.13.2




More information about the Libguestfs mailing list