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:
Yes, it should remove the output file along error paths.
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
Upstream fix: https://github.com/libguestfs/libguestfs/commit/4d4cada65a09dd40940aa021ba7a52b5fbf266be
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
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