Bug 13574 - Package installation fails if target directory is a symlink
Summary: Package installation fails if target directory is a symlink
Status: RESOLVED FIXED
Alias: None
Product: opkg
Classification: Yocto Project Subprojects
Component: opkg (show other bugs)
Version: 0.4.1
Hardware: All Multiple
: Undecided normal
Target Milestone: 0.4.2
Assignee: Alejandro del Castillo
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2019-10-04 19:39 UTC by Melanie
Modified: 2019-12-06 15:58 UTC (History)
0 users

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: No (bug/feature does not impact docs)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Melanie 2019-10-04 19:39:03 UTC
Some packages fail to install with the following message:

Collected errors:
 * check_data_file_clashes: Package <name> wants to install directory /lib/
   But that path is currently a file

On my system, /lib is a symlink that points to /usr/lib.
It seems that opkg is not able to handle this situation.
Comment 1 Alejandro del Castillo 2019-10-11 18:22:58 UTC
I don't think package managers are suppose to follow directory symlinks
when installing files...it's my understanding that dpkg will fail in
that situation too:

(bb) adelcast@delcastillo2 ~/dpkg $ tree a_1.0
a_1.0
├── DEBIAN
│   └── control
├── myfile
└── tmp
    ├── lib
    └── lib64 -> lib/

4 directories, 2 files
(bb) adelcast@delcastillo2 ~/dpkg $ tree b_1.0
b_1.0
├── DEBIAN
│   └── control
├── myfile2
└── tmp
    └── lib64
        └── otherfile

(bb) adelcast@delcastillo2 ~/dpkg $ sudo dpkg -i a_1.0.deb
Selecting previously unselected package a.
(Reading database ... 620831 files and directories currently installed.)
Preparing to unpack a_1.0.deb ...
Unpacking a (1.0) ...
Setting up a (1.0) ...
(bb) adelcast@delcastillo2 ~/dpkg $ sudo dpkg -i b_1.0.deb
Selecting previously unselected package b.
(Reading database ... 620834 files and directories currently installed.)
Preparing to unpack b_1.0.deb ...
Unpacking b (1.0) ...
dpkg: error processing archive b_1.0.deb (--install):
 trying to overwrite '/tmp/lib64', which is also in package a 1.0
Errors were encountered while processing:
 b_1.0.deb

The package needs to be authored in a way that doesn't assume symlinks are going to be followed. Closing as not a bug.
Comment 2 Melanie 2019-10-15 16:58:40 UTC
I am reopening this issue because I believe that the error message in your example is not caused by the symlink itself but by the conflict between different packages.

The debian policy manual [1] describes the details of unpack phase of installation or upgrade and states the following:
"A directory will never be replaced by a symbolic link to a directory or vice versa; instead, the existing state (symlink or not) will be left alone and dpkg will follow the symlink if there is one."

In addition there is a comment in the dpkg source code [2] with further details.

Based on all these informations I still believe that opkg should be able to handle such situations (follow symlinks) when installing debian packages.

[1] https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html
[2] https://git.dpkg.org/cgit/dpkg/dpkg.git/tree/src/unpack.c#n1340
Comment 3 Alejandro del Castillo 2019-10-28 21:44:42 UTC
What is not clear to me is why my example using dpkg failed? You say that the problem is not due to symlinks but to a conflict between packages...could you expand on which conflict pakcage A and B  have, on your view?
Comment 4 Melanie 2019-11-02 10:48:41 UTC
I must admit that it is not clear to me either.

The dpkg error message in your example states that Package B tries to overwrite '/tmp/lib64' (the symlink from Package A), but the debian policy manual clearly describes how to handle such situations (follow the symlink, do NOT overwrite it).

Did you use a dpkg version from dpkg.org or from elsewhere (i.e. BusyBox)?

Maybe it would make sense to ask the dpkg folks [1] for a statement on that topic ...



[1] https://wiki.debian.org/Teams/Dpkg
Comment 5 Alejandro del Castillo 2019-11-21 00:13:35 UTC
Posted on debian mailing list: https://lists.debian.org/debian-dpkg/2019/11/msg00001.html
Comment 6 Alejandro del Castillo 2019-11-22 19:37:59 UTC
The error on my example was not due to a dpkg policy, but by the symlink being followed living on tmpfs. The setting on /proc/sys/fs/protected_symlinks (1) toggles the symlink behavior on tmpfs.

Opkg then should follow symlinks at install time, and this bug is valid.
Comment 7 Alejandro del Castillo 2019-12-06 15:58:20 UTC
Fixed on commit 445fe1b3345ae64b20807ff4c362af273cb247ed