Bug 1150867 - 'copy-file-to-file /src /dest' create file /dest even if command 'copy-file-to-file /src /dest' failed
Summary: 'copy-file-to-file /src /dest' create file /dest even if command 'copy-file-t...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libguestfs
Version: 7.1
Hardware: Unspecified
OS: Unspecified
low
low
Target Milestone: rc
: ---
Assignee: Richard W.M. Jones
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-10-09 05:36 UTC by Lingfei Kong
Modified: 2015-03-05 13:45 UTC (History)
5 users (show)

Fixed In Version: libguestfs-1.27.61-1.1.el7
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-03-05 13:45:59 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2015:0303 0 normal SHIPPED_LIVE libguestfs bug fix and enhancement update 2015-03-05 17:34:44 UTC

Description Lingfei Kong 2014-10-09 05:36:22 UTC
Description of problem:
'copy-file-to-file  /src /dest' create file /dest even if command 'copy-file-to-file  /src /dest' failed.
Maybe copy-file-to-file just call touch command to create /dest first then check /src is a directory or ordinary file, if it is a directory, then it will give an error messages. If there is no risk to modify related code, the best way is not create /dest when 'copy-file-to-file  /src /dest' failed


Version-Release number of selected component (if applicable):
libguestfs-1.27.58-1.1.el7


How reproducible:
100%


Steps to Reproduce:
#guestfish -N fs
><fs> list-filesystems
/dev/sda1: ext2
><fs> mount /dev/sda1 /
><fs> mkdir /src
><fs> copy-file-to-file  /src /dest
libguestfs: error: copy_file_to_file: read: /src: Is a directory
><fs> ls /
dest
lost+found
src


Actual results:
Command 'copy-file-to-file  /src /dest' failed but file /dest still be created


Expected results:
File /dest should not be created


Additional info:

Comment 1 Richard W.M. Jones 2014-10-09 08:10:41 UTC
Yes, it should remove the output file along error paths.

Comment 2 Richard W.M. Jones 2014-10-09 08:38:51 UTC
One line reproducer:

$ guestfish -N fs -m /dev/sda1 -- mkdir /src : -copy-file-to-file /src /dest : ll /

If the bug exists, then /dest is shown in the output:

libguestfs: error: copy_file_to_file: read: /src: Is a directory
total 18
drwxr-xr-x  4 root root  1024 Oct  9 08:36 .
drwxr-xr-x 19 root root  4096 Oct  9 08:36 ..
-rw-r--r--  1 root root     0 Oct  9 08:36 dest        <--- NOTE
drwx------  2 root root 12288 Oct  9 08:36 lost+found
drwxr-xr-x  2 root root  1024 Oct  9 08:36 src

If the bug is fixed, then /dest is not shown because it has been
deleted:

libguestfs: error: copy_file_to_file: read: /src: Is a directory
total 18
drwxr-xr-x  4 root root  1024 Oct  9 08:37 .
drwxr-xr-x 19 root root  4096 Oct  9 08:37 ..
drwx------  2 root root 12288 Oct  9 08:37 lost+found
drwxr-xr-x  2 root root  1024 Oct  9 08:37 src

Normal file copies still work:

$ guestfish -N fs -m /dev/sda1 -- fill-pattern "12345" 10000 /src : copy-file-to-file /src /dest : ll /
total 37
drwxr-xr-x  3 root root  1024 Oct  9 08:38 .
drwxr-xr-x 19 root root  4096 Oct  9 08:38 ..
-rw-r--r--  1 root root 10000 Oct  9 08:38 dest
drwx------  2 root root 12288 Oct  9 08:38 lost+found
-rw-r--r--  1 root root 10000 Oct  9 08:38 src

Comment 5 jiyu 2014-10-13 06:29:58 UTC
Verified with libguestfs-1.27.62-1.1.el7

Steps to verify:
1. #guestfish -N fs -m /dev/sda1 -- mkdir /src : -copy-file-to-file /src /dest : ll /
libguestfs: error: copy_file_to_file: read: /src: Is a directory
total 18
drwxr-xr-x  4 root root  1024 Oct 13 06:25 .
drwxr-xr-x 19 root root  4096 Oct 13 06:25 ..
drwx------  2 root root 12288 Oct 13 06:25 lost+found
drwxr-xr-x  2 root root  1024 Oct 13 06:25 src

dest was not created if src is a directory.

2. guestfish -N fs -m /dev/sda1 -- fill-pattern "12345" 10000 /src : copy-file-to-file /src /dest : ll /
total 37
drwxr-xr-x  3 root root  1024 Oct 13 06:26 .
drwxr-xr-x 19 root root  4096 Oct 13 06:26 ..
-rw-r--r--  1 root root 10000 Oct 13 06:26 dest
drwx------  2 root root 12288 Oct 13 06:26 lost+found
-rw-r--r--  1 root root 10000 Oct 13 06:26 src

dest was created if src is a file.

So bug is fixed

Comment 7 errata-xmlrpc 2015-03-05 13:45:59 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2015-0303.html


Note You need to log in before you can comment on or make changes to this bug.