Move the last remaining function ‘guestfs_int_download_to_tmp’ to
lib/inspect-icon.c (the main, but not only user of this function).
Then remove lib/inspect.c entirely.
This is not quite code motion because I updated the comment for the
function to reflect what it does in reality.
---
docs/C_SOURCE_FILES | 1 -
lib/Makefile.am | 1 -
lib/inspect-icon.c | 74 +++++++++++++++++++++++++++++++++++-
lib/inspect.c | 106 ----------------------------------------------------
po/POTFILES | 1 -
5 files changed, 73 insertions(+), 110 deletions(-)
diff --git a/docs/C_SOURCE_FILES b/docs/C_SOURCE_FILES
index 386df6d9a..2b947a81c 100644
--- a/docs/C_SOURCE_FILES
+++ b/docs/C_SOURCE_FILES
@@ -313,7 +313,6 @@ lib/handle.c
lib/info.c
lib/inspect-apps.c
lib/inspect-icon.c
-lib/inspect.c
lib/journal.c
lib/launch-direct.c
lib/launch-libvirt.c
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 677180636..a1d8ee70e 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -93,7 +93,6 @@ libguestfs_la_SOURCES = \
guid.c \
handle.c \
info.c \
- inspect.c \
inspect-apps.c \
inspect-icon.c \
journal.c \
diff --git a/lib/inspect-icon.c b/lib/inspect-icon.c
index f4f5f0660..c45761041 100644
--- a/lib/inspect-icon.c
+++ b/lib/inspect-icon.c
@@ -20,8 +20,11 @@
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
+#include <inttypes.h>
#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <libintl.h>
#include <sys/wait.h>
#include "guestfs.h"
@@ -644,3 +647,72 @@ case_sensitive_path_silently (guestfs_h *g, const char *path)
return ret;
}
+
+/**
+ * Download a guest file to a local temporary file. The file is
+ * cached in the temporary directory using C<basename>, and is not
+ * downloaded again.
+ *
+ * The name of the temporary (downloaded) file is returned. The
+ * caller must free the pointer, but does I<not> need to delete the
+ * temporary file. It will be deleted when the handle is closed.
+ *
+ * Refuse to download the guest file if it is larger than C<max_size>.
+ * On this and other errors, C<NULL> is returned.
+ *
+ * XXX Prior to commit 65cfecb0f5344ec92d3f0d3c2ec0538b6b2726e2 this
+ * function used different basenames for each inspection root. After
+ * this commit icons probably won't work properly. Needs fixing.
+ */
+char *
+guestfs_int_download_to_tmp (guestfs_h *g,
+ const char *filename,
+ const char *basename, uint64_t max_size)
+{
+ char *r;
+ int fd;
+ char devfd[32];
+ int64_t size;
+
+ if (asprintf (&r, "%s/%s", g->tmpdir, basename) == -1) {
+ perrorf (g, "asprintf");
+ return NULL;
+ }
+
+ /* Check size of remote file. */
+ size = guestfs_filesize (g, filename);
+ if (size == -1)
+ /* guestfs_filesize failed and has already set error in handle */
+ goto error;
+ if ((uint64_t) size > max_size) {
+ error (g, _("size of %s is unreasonably large (%" PRIi64 "
bytes)"),
+ filename, size);
+ goto error;
+ }
+
+ fd = open (r, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY|O_CLOEXEC, 0600);
+ if (fd == -1) {
+ perrorf (g, "open: %s", r);
+ goto error;
+ }
+
+ snprintf (devfd, sizeof devfd, "/dev/fd/%d", fd);
+
+ if (guestfs_download (g, filename, devfd) == -1) {
+ unlink (r);
+ close (fd);
+ goto error;
+ }
+
+ if (close (fd) == -1) {
+ perrorf (g, "close: %s", r);
+ unlink (r);
+ goto error;
+ }
+
+ return r;
+
+ error:
+ free (r);
+ return NULL;
+}
diff --git a/lib/inspect.c b/lib/inspect.c
deleted file mode 100644
index eb53edf32..000000000
--- a/lib/inspect.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/* libguestfs
- * Copyright (C) 2010-2012 Red Hat Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <config.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <inttypes.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <libintl.h>
-#include <assert.h>
-
-#ifdef HAVE_ENDIAN_H
-#include <endian.h>
-#endif
-
-#include "ignore-value.h"
-
-#include "guestfs.h"
-#include "guestfs-internal.h"
-#include "guestfs-internal-actions.h"
-
-/**
- * Download a guest file to a local temporary file. The file is
- * cached in the temporary directory, and is not downloaded again.
- *
- * The name of the temporary (downloaded) file is returned. The
- * caller must free the pointer, but does I<not> need to delete the
- * temporary file. It will be deleted when the handle is closed.
- *
- * Refuse to download the guest file if it is larger than C<max_size>.
- * On this and other errors, C<NULL> is returned.
- *
- * There is actually one cache per C<struct inspect_fs *> in order to
- * handle the case of multiple roots.
- */
-char *
-guestfs_int_download_to_tmp (guestfs_h *g,
- const char *filename,
- const char *basename, uint64_t max_size)
-{
- char *r;
- int fd;
- char devfd[32];
- int64_t size;
-
- if (asprintf (&r, "%s/%s", g->tmpdir, basename) == -1) {
- perrorf (g, "asprintf");
- return NULL;
- }
-
- /* Check size of remote file. */
- size = guestfs_filesize (g, filename);
- if (size == -1)
- /* guestfs_filesize failed and has already set error in handle */
- goto error;
- if ((uint64_t) size > max_size) {
- error (g, _("size of %s is unreasonably large (%" PRIi64 "
bytes)"),
- filename, size);
- goto error;
- }
-
- fd = open (r, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY|O_CLOEXEC, 0600);
- if (fd == -1) {
- perrorf (g, "open: %s", r);
- goto error;
- }
-
- snprintf (devfd, sizeof devfd, "/dev/fd/%d", fd);
-
- if (guestfs_download (g, filename, devfd) == -1) {
- unlink (r);
- close (fd);
- goto error;
- }
-
- if (close (fd) == -1) {
- perrorf (g, "close: %s", r);
- unlink (r);
- goto error;
- }
-
- return r;
-
- error:
- free (r);
- return NULL;
-}
diff --git a/po/POTFILES b/po/POTFILES
index 182c80bbd..7d58151b3 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -376,7 +376,6 @@ lib/handle.c
lib/info.c
lib/inspect-apps.c
lib/inspect-icon.c
-lib/inspect.c
lib/journal.c
lib/launch-direct.c
lib/launch-libvirt.c
--
2.13.2