-/* Has one FileOut parameter. */
-int
-do_tar_out (const char *dir)
-{
- int r;
- FILE *fp;
- char *cmd;
- char buf[GUESTFS_MAX_CHUNK_SIZE];
-
- /* "tar -C /sysroot%s -cf - ." but we have to quote the dir. */
- if (asprintf_nowarn (&cmd, "tar -C %R -cf - .", dir) == -1) {
- reply_with_perror ("asprintf");
- return -1;
- }
-
- if (verbose)
- fprintf (stderr, "%s\n", cmd);
-
- fp = popen (cmd, "r");
- if (fp == NULL) {
- reply_with_perror ("%s", cmd);
- free (cmd);
- return -1;
- }
- free (cmd);
-
- /* Now we must send the reply message, before the file contents. After
- * this there is no opportunity in the protocol to send any error
- * message back. Instead we can only cancel the transfer.
- */
- reply (NULL, NULL);
-
- while ((r = fread (buf, 1, sizeof buf, fp)) > 0) {
- if (send_file_write (buf, r) < 0) {
- pclose (fp);
- return -1;
- }
- }
-
- if (ferror (fp)) {
- perror (dir);
- send_file_end (1); /* Cancel. */
- pclose (fp);
- return -1;
- }
-
- if (pclose (fp) != 0) {
- perror (dir);
- send_file_end (1); /* Cancel. */
- return -1;
- }
-
- if (send_file_end (0)) /* Normal end of file. */
- return -1;
-
- return 0;
-}
-