Bug 1153412

Summary: copy-in and copy-out copy symbolic link file problems, it only copy the link property not the real file
Product: Red Hat Enterprise Linux 6 Reporter: Lingfei Kong <lkong>
Component: libguestfsAssignee: Richard W.M. Jones <rjones>
Status: CLOSED NOTABUG QA Contact: Virtualization Bugs <virt-bugs>
Severity: low Docs Contact:
Priority: medium    
Version: 6.6CC: leiwang, mbooth, ptoscano, rjones, virt-bugs, wshi, yuliu
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 1153411 Environment:
Last Closed: 2014-11-04 12:41:49 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:
Bug Depends On: 1153411    
Bug Blocks:    

Description Lingfei Kong 2014-10-16 02:46:13 UTC
+++ This bug was initially created as a clone of Bug #1153411 +++

Description of problem:
when copy-in/copy-out a symbolic link, the two APIs only copy the link property not the real file, some times it may have no problem but some times it will have a unexpected result.

When we copy ordinary symbolic links what we want is to copy the real file, in other words the TARGET files. 
When we copy directories, in most cases we want to keep the symbolic link in a directory. One reason is we want to keep the structure in the directory the other reason is the directory may contain links refer to a large file and we don't want to copy it or other reasons. 

The best way is to add an option to copy-in and copy-out to let the users to select if they want to follow the symbolic links like rsync. If copy-in and copy-out will not add such option, then at least it should add some text in help messages to describe this problem.  The same problem exist in virt-copy-in and virt-copy-out. 


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


How reproducible:
100%


Steps to Reproduce:
copy-in:
1. #echo "in host" > /etc/hosts.deny
2. #ln -s /etc/hosts.deny /etc/deny_link
3. #guestfish -i -a rhel.img
><fs> copy-in /etc/deny_link /etc/
><fs> ll /etc/deny_link
lrwxrwxrwx 1 root root 15 Oct 14 14:12 /sysroot/etc/deny_link -> /etc/hosts.deny

><fs> cat /etc/hosts.deny
#
# hosts.deny    This file contains access rules which are used to
#               deny connections to network services that either use
#               the tcp_wrappers library or that have been
#               started through a tcp_wrappers-enabled xinetd.
#
#               The rules in this file can also be set up in
#               /etc/hosts.allow with a 'deny' option instead.
#
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
#               for information on rule syntax.
#               See 'man tcpd' for information on tcp_wrappers
#

copy-out:
4. #guestfish -i -a rhel.img
><fs> vi /etc/hosts.deny
><fs> cat /etc/hosts.deny
in guest

><fs> ln-s /etc/hosts.deny /etc/host_deny_link
><fs> copy-out  /etc/ .
><fs> quit
5. #ll etc/host_deny_link
lrwxrwxrwx. 1 root root 15 Oct 14 22:15 etc/host_deny_link -> /etc/hosts.deny
6. #cat etc/host_deny_link
in host


Actual results:
copy-in and copy-out only copy the link property not copy the real file.


Expected results:
At step 3, ><fs> cat /etc/hosts.deny should output "in host"
At step 6, #cat etc/host_deny_link should output "in guest"
copy-in and copy-out should copy the real file.


Additional info:

Comment 1 Lingfei Kong 2014-10-16 03:35:55 UTC
><fs> trace 1
><fs> copy-in soft_hosts /boot/
libguestfs: trace: is_dir "/boot/"
libguestfs: trace: is_dir = 1
libguestfs: trace: tar_in "/dev/fd/10" "/boot/"
libguestfs: trace: tar_in = 0
><fs> ll /boot/soft_hosts
libguestfs: trace: ll "/boot/soft_hosts"
libguestfs: trace: ll = "lrwxrwxrwx 1 root root 5 Oct 16 03:11 /sysroot/boot/soft_hosts -> hosts\n"
lrwxrwxrwx 1 root root 5 Oct 16 03:11 /sysroot/boot/soft_hosts -> hosts

><fs> help copy-in
NAME
    copy-in - copy local files or directories into an image

DESCRIPTION
     copy-in local [local ...] /remotedir

    "copy-in" copies local files or directories recursively into the disk
    image, placing them in the directory called "/remotedir" (which must
    exist). This guestfish meta-command turns into a sequence of "tar-in"
    and other commands as necessary.
    ......

It use tar_in to copy the symbolic links, i found the following line in 'help copy-in':
This guestfish meta-command turns into a sequence of "tar-in" and other commands as necessary.
When it copy ordinary files maybe upload is best for it.

Comment 2 Pino Toscano 2014-11-04 12:41:49 UTC
Closing as NOTABUG, per comments in bug 1153411.