Red Hat Bugzilla – Bug 1293271
virt-sysprep --delete fails to delete a symbolic link to a dir
Last modified: 2017-11-13 09:02:14 EST
Created attachment 1108267 [details]
log for virt-sysprep --delete
Description of problem:
I was trying to use virt-sysprep --delete to delete a symbolic link to a dir:'/home/testdir_link' in guestos, but it failed without any prompt.
Then I tried it in RHEL7.2(libguestfs-1.28.1-55.el7.x86_64), it's ok.
I looked into the two detailed log and found that in RHEL7.2 it used 'rm_rf "/home/testdir_link"',but in RHEL6.8 it used 'rm_rf "/home/testdir_link/"' , which caused the failure.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. Prepare a image: RHEL-Server-6.7-32-hvm.raw
$ guestfish -a RHEL-Server-6.7-32-hvm.raw -i mkdir /home/testdir
$ guestfish -a RHEL-Server-6.7-32-hvm.raw -i ln-s /home/testdir /home/testdir_link
$ virt-sysprep -a RHEL-Server-6.7-32-hvm.raw --delete /home/testdir_link -v -x 2>&1 | tee tmplog
$ guestfish -a RHEL-Server-6.7-32-hvm.raw -i glob-expand '/home/testdir_link'
3. Then I tried in guestfish and found that you can only use "rm-rf /home/testdir_link" to delete it (it's same as the host):
$ guestfish -a RHEL-Server-6.7-32-hvm.raw -i
><fs> rm-rf /home/testdir_link/
><fs> ls /home/
><fs> rm-rf /home/testdir_link
><fs> ls /home/
After step 2, the "/home/testdir_link/" is still there.
It should be deleted successfully.
RHEL7.2(libguestfs-1.28.1-55.el7.x86_64) is ok.
*** This bug has been marked as a duplicate of bug 1216296 ***
I'm unduplicating this, because it doesn't really have
anything to do with the rm-rf API.
What happens is that we call glob_expand first, and that API
returns the path with trailing "/":
libguestfs: trace: glob_expand "/home/testdir_link"
libguestfs: trace: glob_expand = ["/home/testdir_link/"]
libguestfs: trace: rm_rf "/home/testdir_link/"
What's interesting is:
(1) This does not happen upstream. Upstream, the virt-sysprep
--delete option does not support globbing at all, which I think
may be an accidental regression.
(2) This does not happen in upstream 1.20 either.
It only happens in RHEL 6 because we backported the following
(The second commit is just a doc change).
(In reply to Richard W.M. Jones from comment #2)
> I'm unduplicating this, because it doesn't really have
> anything to do with the rm-rf API.
> What happens is that we call glob_expand first, and that API
> returns the path with trailing "/":
> libguestfs: trace: glob_expand "/home/testdir_link"
> libguestfs: trace: glob_expand = ["/home/testdir_link/"]
> libguestfs: trace: rm_rf "/home/testdir_link/"
> What's interesting is:
> (1) This does not happen upstream. Upstream, the virt-sysprep
> --delete option does not support globbing at all, which I think
> may be an accidental regression.
> (2) This does not happen in upstream 1.20 either.
> It only happens in RHEL 6 because we backported the following
> (The second commit is just a doc change).
Yes, I agree with you, it has nothing to do with rm-rf API, but I looked into the steps of the bug 1216296, it's actually the same.
So I duplicate it because they are the same problem, may be the subject of bug 1216296 is not proper. I'll close the bug 1216296 as duplicate if it confused you.
The situation described in this bug is actually a bit more convoluted than it seems:
(1) --delete in RHEL 7 and upstream does not support globbing; this has been introduced during the creation of virt-customize, when virt-sysprep has been changed to use the customize operations, losing the globbing feature of --delete
(2) when globbing is used, glob_expand returns paths with trailing slash, and `rm -rf dir-symlink/` does not work; this happens because in the glob_expand implementation we pass GLOB_MARK to glob()
(3) `rm -rf dir-symlink/` does not remove that symlink to a directory (whereas without the slash it works); this is also bug #1216296
- regarding (1): implementing globbing for --delete is trivial, but then it would introduce (2) upstream as well
- removing GLOB_MARK from the flags of glob() fixes (2), although that may break users of the glob_expand API (i.e. those relying on directories ending with slash, and not appending it by themselves)
*** Bug 1216296 has been marked as a duplicate of this bug. ***
I'm closing this as WONTFIX for a couple of reasons:
(1) RHEL 6 is in production phase 3.
(2) This wasn't reported by a customer.
Note that this does not mean this is not a bug, just that we are not
going to fix it in RHEL 6.