summaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-11-08 11:36:35 +0000
committerRichard W.M. Jones <rjones@redhat.com>2012-11-09 13:11:53 +0000
commit1efed122c07792f4c66a4083159cfacfb1893212 (patch)
treec751f26ec9d3c152905fdf34d48a2b79a0af5216 /generator
parente8d937bd739a70394ec72482a8cb1df3b0601dcc (diff)
downloadlibguestfs-1efed122c07792f4c66a4083159cfacfb1893212.tar.gz
libguestfs-1efed122c07792f4c66a4083159cfacfb1893212.tar.xz
libguestfs-1efed122c07792f4c66a4083159cfacfb1893212.zip
lib: Rework temporary and cache directory code.
New APIs: set-tmpdir, get-tmpdir, set-cachedir, get-cachedir. The current code has evolved over time and has a number of problems: (a) A single environment variable ($TMPDIR) controls the location of several directories. (b) It's hard for the library user to predict which directory libguestfs will use, unless the user simulates the same internal steps that libguestfs performs. This commit fixes these issues. (a) Now three environment variables control the location of all small temporary files, and the appliance cache: For temporary files: $LIBGUESTFS_TMPDIR or $TMPDIR or /tmp. For the appliance cache: $LIBGUESTFS_CACHEDIR or $TMPDIR or /var/tmp. The user can also set these directories explicitly through API calls (guestfs_set_tmpdir and guestfs_set_cachedir). (b) The user can also retrieve the actual directories that libguestfs will use, by calling guestfs_get_tmpdir and guestfs_get_cachedir. These functions are also used internally. This commit also: - reworks the internal tmpdir code - removes the internal (undocumented) guestfs_tmpdir call (replacing it with calls to the documented guestfs_get_tmpdir API instead) - changes the ./run script to set LIBGUESTFS_TMPDIR and LIBGUESTFS_CACHEDIR - adds a test - fixes a few places like libguestfs-make-fixed-appliance which depended on $TMPDIR
Diffstat (limited to 'generator')
-rw-r--r--generator/actions.ml47
-rw-r--r--generator/c.ml2
2 files changed, 47 insertions, 2 deletions
diff --git a/generator/actions.ml b/generator/actions.ml
index 65d27852..e4f8dd41 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -2677,6 +2677,53 @@ This is the same as C<guestfs_parse_environment> except that
it parses an explicit list of strings instead of the program's
environment." };
+ { defaults with
+ name = "set_tmpdir";
+ style = RErr, [OptString "tmpdir"], [];
+ fish_alias = ["tmpdir"]; config_only = true;
+ blocking = false;
+ shortdesc = "set the temporary directory";
+ longdesc = "\
+Set the directory used by the handle to store temporary files.
+
+The environment variables C<LIBGUESTFS_TMPDIR> and C<TMPDIR>
+control the default value: If C<LIBGUESTFS_TMPDIR> is set, then
+that is the default. Else if C<TMPDIR> is set, then that is
+the default. Else C</tmp> is the default." };
+
+ { defaults with
+ name = "get_tmpdir";
+ style = RString "tmpdir", [], [];
+ blocking = false;
+ shortdesc = "get the temporary directory";
+ longdesc = "\
+Get the directory used by the handle to store temporary files." };
+
+ { defaults with
+ name = "set_cachedir";
+ style = RErr, [OptString "cachedir"], [];
+ fish_alias = ["cachedir"]; config_only = true;
+ blocking = false;
+ shortdesc = "set the appliance cache directory";
+ longdesc = "\
+Set the directory used by the handle to store the appliance
+cache, when using a supermin appliance. The appliance is
+cached and shared between all handles which have the same
+effective user ID.
+
+The environment variables C<LIBGUESTFS_CACHEDIR> and C<TMPDIR>
+control the default value: If C<LIBGUESTFS_CACHEDIR> is set, then
+that is the default. Else if C<TMPDIR> is set, then that is
+the default. Else C</var/tmp> is the default." };
+
+ { defaults with
+ name = "get_cachedir";
+ style = RString "cachedir", [], [];
+ blocking = false;
+ shortdesc = "get the appliance cache directory";
+ longdesc = "\
+Get the directory used by the handle to store the appliance cache." };
+
]
(* daemon_functions are any functions which cause some action
diff --git a/generator/c.ml b/generator/c.ml
index 76c74226..923758e4 100644
--- a/generator/c.ml
+++ b/generator/c.ml
@@ -674,7 +674,6 @@ extern GUESTFS_DLL_PUBLIC void *guestfs_safe_malloc (guestfs_h *g, size_t nbytes
extern GUESTFS_DLL_PUBLIC void *guestfs_safe_calloc (guestfs_h *g, size_t n, size_t s);
extern GUESTFS_DLL_PUBLIC char *guestfs_safe_strdup (guestfs_h *g, const char *str);
extern GUESTFS_DLL_PUBLIC void *guestfs_safe_memdup (guestfs_h *g, const void *ptr, size_t size);
-extern GUESTFS_DLL_PUBLIC const char *guestfs_tmpdir (void);
#ifdef GUESTFS_PRIVATE_FOR_EACH_DISK
extern GUESTFS_DLL_PUBLIC int guestfs___for_each_disk (guestfs_h *g, virDomainPtr dom, int (*)(guestfs_h *g, const char *filename, const char *format, int readonly, void *data), void *data);
#endif
@@ -1584,7 +1583,6 @@ and generate_linker_script () =
"guestfs_safe_malloc";
"guestfs_safe_strdup";
"guestfs_safe_memdup";
- "guestfs_tmpdir";
"guestfs___for_each_disk";
] in
let functions =