Pino Toscano
2015-Sep-30 08:38 UTC
[Libguestfs] [PATCH v2] copy-in: error out early if the localpath does not exist
---
src/copy-in-out.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/copy-in-out.c b/src/copy-in-out.c
index d5e7fb0..89344d8 100644
--- a/src/copy-in-out.c
+++ b/src/copy-in-out.c
@@ -46,6 +46,12 @@ guestfs_impl_copy_in (guestfs_h *g,
size_t buf_len = strlen (localpath) + 1;
char buf[buf_len];
const char *dirname, *basename;
+ struct stat statbuf;
+
+ if (stat (localpath, &statbuf) == -1) {
+ error (g, _("source '%s' does not exist (or cannot be
read)"), localpath);
+ return -1;
+ }
int remote_is_dir = guestfs_is_dir (g, remotedir);
if (remote_is_dir == -1)
--
2.1.0
Richard W.M. Jones
2015-Sep-30 08:54 UTC
Re: [Libguestfs] [PATCH v2] copy-in: error out early if the localpath does not exist
On Wed, Sep 30, 2015 at 10:38:57AM +0200, Pino Toscano wrote:> --- > src/copy-in-out.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/src/copy-in-out.c b/src/copy-in-out.c > index d5e7fb0..89344d8 100644 > --- a/src/copy-in-out.c > +++ b/src/copy-in-out.c > @@ -46,6 +46,12 @@ guestfs_impl_copy_in (guestfs_h *g, > size_t buf_len = strlen (localpath) + 1; > char buf[buf_len]; > const char *dirname, *basename; > + struct stat statbuf; > + > + if (stat (localpath, &statbuf) == -1) { > + error (g, _("source '%s' does not exist (or cannot be read)"), localpath); > + return -1; > + } > > int remote_is_dir = guestfs_is_dir (g, remotedir); > if (remote_is_dir == -1) > -- > 2.1.0ACK, probably. The current message isn't too bad: $ ./run guestfish -N fs -m /dev/sda1 copy-in /tmp/foobar / libguestfs: error: tar subprocess failed: tar: foobar: Cannot stat: No such file or directory tar: Exiting with failure status due to previous errors Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
Seemingly Similar Threads
- Re: [PATCH 2/2] copy-in: error out early if the localpath does not exist (RHBZ#1267032)
- [PATCH 1/2] copy-in: print tar stderr when it fails
- [PATCH 2/2] copy-in: error out early if the localpath does not exist (RHBZ#1267032)
- Re: [PATCH 2/2] copy-in: error out early if the localpath does not exist (RHBZ#1267032)
- Re: [PATCH 5/6] New APIs: copy-in and copy-out