Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1150867

Summary: 'copy-file-to-file /src /dest' create file /dest even if command 'copy-file-to-file /src /dest' failed
Product: Red Hat Enterprise Linux 7 Reporter: Lingfei Kong <lkong>
Component: libguestfsAssignee: Richard W.M. Jones <rjones>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: low Docs Contact:
Priority: low    
Version: 7.1CC: leiwang, mbooth, ptoscano, wshi, yuliu
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libguestfs-1.27.61-1.1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-03-05 13:45:59 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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