mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
daemon: move make_exclude_from_file as common helper
It will be useful also for APIs different than tar-out, so move it to guestfsd.c, and add it a parameter to specify the function name that invoked it. This is mostly code motion.
This commit is contained in:
58
daemon/tar.c
58
daemon/tar.c
@@ -268,62 +268,6 @@ do_txz_in (const char *dir)
|
||||
return do_tar_in (dir, "xz", 0, 0, 0);
|
||||
}
|
||||
|
||||
/* Turn list 'excludes' into a temporary file, and return a string
|
||||
* containing the temporary file name. Caller must unlink the file
|
||||
* and free the string.
|
||||
*/
|
||||
static char *
|
||||
make_exclude_from_file (char *const *excludes)
|
||||
{
|
||||
size_t i;
|
||||
int fd;
|
||||
char template[] = "/tmp/excludesXXXXXX";
|
||||
char *ret;
|
||||
|
||||
fd = mkstemp (template);
|
||||
if (fd == -1) {
|
||||
reply_with_perror ("mkstemp");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; excludes[i] != NULL; ++i) {
|
||||
if (strchr (excludes[i], '\n')) {
|
||||
reply_with_error ("tar-out: excludes file patterns cannot contain \\n character");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (xwrite (fd, excludes[i], strlen (excludes[i])) == -1 ||
|
||||
xwrite (fd, "\n", 1) == -1) {
|
||||
reply_with_perror ("write");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (verbose)
|
||||
fprintf (stderr, "tar-out: adding excludes pattern '%s'\n", excludes[i]);
|
||||
}
|
||||
|
||||
if (close (fd) == -1) {
|
||||
reply_with_perror ("close");
|
||||
fd = -1;
|
||||
goto error;
|
||||
}
|
||||
fd = -1;
|
||||
|
||||
ret = strdup (template);
|
||||
if (ret == NULL) {
|
||||
reply_with_perror ("strdup");
|
||||
goto error;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
error:
|
||||
if (fd >= 0)
|
||||
close (fd);
|
||||
unlink (template);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Has one FileOut parameter. */
|
||||
/* Takes optional arguments, consult optargs_bitmask. */
|
||||
int
|
||||
@@ -367,7 +311,7 @@ do_tar_out (const char *dir, const char *compress, int numericowner,
|
||||
numericowner = 0;
|
||||
|
||||
if ((optargs_bitmask & GUESTFS_TAR_OUT_EXCLUDES_BITMASK)) {
|
||||
exclude_from_file = make_exclude_from_file (excludes);
|
||||
exclude_from_file = make_exclude_from_file ("tar-out", excludes);
|
||||
if (!exclude_from_file)
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user