X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Ftar.c;h=74d7b056697847e8e9cba3d6e6d555fa0106fe04;hp=072a56693ec33f40ae9c221508ea77176abb18de;hb=f3341222b37f91d7f7fcdafe30b107ea9da9ad02;hpb=9ff99418361cd1b56b00e4ffef52444021e60c72 diff --git a/daemon/tar.c b/daemon/tar.c index 072a566..74d7b05 100644 --- a/daemon/tar.c +++ b/daemon/tar.c @@ -1,5 +1,5 @@ /* libguestfs - the guestfsd daemon - * Copyright (C) 2009 Red Hat Inc. + * Copyright (C) 2009-2010 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,8 +33,7 @@ int optgroup_xz_available (void) { - int r = access ("/usr/bin/xz", X_OK); - return r == 0; + return prog_exists ("xz"); } /* Redirect errors from the tar command to the error file, then @@ -86,7 +85,7 @@ do_tXz_in (const char *dir, const char *filter) err = errno; r = cancel_receive (); errno = err; - if (r != -2) reply_with_perror ("asprintf"); + reply_with_perror ("asprintf"); return -1; } @@ -98,7 +97,7 @@ do_tXz_in (const char *dir, const char *filter) err = errno; r = cancel_receive (); errno = err; - if (r != -2) reply_with_perror ("%s", cmd); + reply_with_perror ("%s", cmd); free (cmd); return -1; } @@ -111,29 +110,27 @@ do_tXz_in (const char *dir, const char *filter) r = receive_file (write_cb, &fd); if (r == -1) { /* write error */ - if (cancel_receive () != -2) { - char *errstr = read_error_file (); - reply_with_error ("write error on directory: %s: %s", dir, errstr); - free (errstr); - } + cancel_receive (); + char *errstr = read_error_file (); + reply_with_error ("write error on directory: %s: %s", dir, errstr); + free (errstr); pclose (fp); return -1; } if (r == -2) { /* cancellation from library */ + /* This error is ignored by the library since it initiated the + * cancel. Nevertheless we must send an error reply here. + */ + reply_with_error ("file upload cancelled"); pclose (fp); - /* Do NOT send any error. */ return -1; } if (pclose (fp) != 0) { - if (r == -1) /* if r == 0, file transfer ended already */ - r = cancel_receive (); - if (r != -2) { - char *errstr = read_error_file (); - reply_with_error ("tar subcommand failed on directory: %s: %s", - dir, errstr); - free (errstr); - } + char *errstr = read_error_file (); + reply_with_error ("tar subcommand failed on directory: %s: %s", + dir, errstr); + free (errstr); return -1; }