- if (r != -2)
- reply_with_error ("tar subcommand failed on directory: %s", dir);
- return -1;
- }
-
- return 0;
-}
-
-/* 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 (r != -2) {
+ char *errstr = read_error_file ();
+ reply_with_error ("tar subcommand failed on directory: %s: %s",
+ dir, errstr);
+ free (errstr);