Bug 13806 - cannot change the ownership of symbolic link
Summary: cannot change the ownership of symbolic link
Status: RESOLVED FIXED
Alias: None
Product: BitBake
Classification: Build System, Metadata & Runtime
Component: bitbake (show other bugs)
Version: unspecified
Hardware: x86 Multiple
: Medium+ normal
Target Milestone: 3.1 M4
Assignee: daisuke.yamane
QA Contact:
URL:
Whiteboard: backport
Depends on:
Blocks:
 
Reported: 2020-02-21 08:29 UTC by daisuke.yamane
Modified: 2020-04-30 08:10 UTC (History)
4 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: Don't know


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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./