Bug 13806

Summary: cannot change the ownership of symbolic link
Product: [Build System, Metadata & Runtime] BitBake Reporter: daisuke.yamane
Component: bitbakeAssignee: daisuke.yamane
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: Medium+ CC: poky.bs.watcher, poky.watcher, randy.macleod, richard.purdie
Version: unspecified   
Target Milestone: 3.1 M4   
Hardware: x86   
OS: Multiple   
Whiteboard: backport
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: Don't know

Description daisuke.yamane 2020-02-21 08:29:12 UTC
I try to change owership of symbolic link in do_install, but it doesn't work.

I use the recipes like below.
===
do_install_append () {
        touch ${D}${bindir}/chown-test
        ln -fs ${bindir}/chown-test ${D}${bindir}/link-to-chown-test
        chown -R -h user:user ${D}${bindir}/link-to-chown-test
        chown -R -h user:user ${D}${bindir}/chown-test
}
===

It seems that only ownership of symbolic-link was modified to root when copied to package-split.
> $ echo '.dump' |sqlite3 <WORKDIR>/pseudo/files.db |grep chown
> INSERT INTO files VALUES(120,'<WORKDIR>/image/usr/bin/chown-test',2066,26881543,1000,1000,33188,0,0);
> INSERT INTO files VALUES(121,'<WORKDIR>/image/usr/bin/link-to-chown-test',2066,26881556,1000,1000,41471,0,0);
> INSERT INTO files VALUES(17091,'<WORKDIR>/package/usr/bin/chown-test',2066,28453918,1000,1000,33188,0,0);
> INSERT INTO files VALUES(17106,'<WORKDIR>/package/usr/bin/link-to-chown-test',2066,28453919,1000,1000,41471,0,0);
> INSERT INTO files VALUES(18732,'<WORKDIR>/packages-split/rsyslog/usr/bin/chown-test',2066,28453918,1000,1000,33188,0,0);
> INSERT INTO files VALUES(18733,'<WORKDIR>/packages-split/rsyslog/usr/bin/link-to-chown-test',2066,28454108,0,0,41471,0,0);
Note: Paths omitted for clarity

The following is the copy process that causes this problem.
When os.lchown() is uncommented, it works fine for me.
- lib/bb/utils.py
> def copyfile(src, dest, newmtime = None, sstat = None):
...(snip)...
>     if stat.S_ISLNK(sstat[stat.ST_MODE]):
>         try:
>             target = os.readlink(src)
>             if destexists and not stat.S_ISDIR(dstat[stat.ST_MODE]):
>                 os.unlink(dest)
>             os.symlink(target, dest)
>             #os.lchown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID])
>             return os.lstat(dest)

I think this is a bug. Right?
Comment 1 Richard Purdie 2020-02-21 12:18:12 UTC
It does sound like a bug. Could you send a patch please? 

Bonus marks if you extend our automated test coverage
http://git.yoctoproject.org/cgit.cgi/poky/tree/meta/lib/oeqa/selftest/cases/package.py
Run as oe-sefltest -e package.PackageTeststest_preserve_sparse_hardlinks

(could just add a chown'd symlink to that test)
Comment 2 daisuke.yamane 2020-02-22 06:26:29 UTC
Hi Richard,
thank you for reply.

> It does sound like a bug. Could you send a patch please? 
I just sent a patch. https://bugzilla.yoctoproject.org/show_bug.cgi?id=13806

> Bonus marks if you extend our automated test coverage
> http://git.yoctoproject.org/cgit.cgi/poky/tree/meta/lib/oeqa/selftest/cases/package.py
> Run as oe-sefltest -e package.PackageTeststest_preserve_sparse_hardlinks
I'm making a test now, however it may take some time because I am not used to it.
Comment 3 Richard Purdie 2020-02-23 11:17:35 UTC
(In reply to comment #2)
> Hi Richard,
> thank you for reply.
> 
> > It does sound like a bug. Could you send a patch please? 
> I just sent a patch. https://bugzilla.yoctoproject.org/show_bug.cgi?id=13806

Thanks, I saw it, put through testing and then merged it!

I did a little digging of the history and that code line has been commented out since it was added in 2005! (no idea why)

> > Bonus marks if you extend our automated test coverage
> > http://git.yoctoproject.org/cgit.cgi/poky/tree/meta/lib/oeqa/selftest/cases/package.py
> > Run as oe-sefltest -e package.PackageTeststest_preserve_sparse_hardlinks
> I'm making a test now, however it may take some time because I am not used
> to it.

Thanks, the tests are how we managed to keep the project stable so this does help and is appreciated!
Comment 5 Randy MacLeod 2020-02-27 15:41:23 UTC
Bug fixed. Added backport requests. Tests coming in M4 hopefully. Thanks Daisuke.
Comment 6 daisuke.yamane 2020-03-14 13:22:31 UTC
> > Bonus marks if you extend our automated test coverage
> > http://git.yoctoproject.org/cgit.cgi/poky/tree/meta/lib/oeqa/selftest/cases/package.py
> > Run as oe-sefltest -e package.PackageTeststest_preserve_sparse_hardlinks
> I'm making a test now, however it may take some time because I am not used to it.

I send a patch to add test. Please review it!
https://patchwork.openembedded.org/patch/171025/
Comment 7 Richard Purdie 2020-04-20 05:46:49 UTC
Thanks for the test, it was close to release to add new tests but this will be queued for the next cycle./