Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 708360 - [Future EAPI] dosym -r to create relative symlinks
Summary: [Future EAPI] dosym -r to create relative symlinks
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: PMS/EAPI (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Package Manager Specification
URL:
Whiteboard: in-eapi-8
Keywords:
Depends on:
Blocks: future-eapi
  Show dependency tree
 
Reported: 2020-02-05 16:41 UTC by Ulrich Müller
Modified: 2023-10-21 07:58 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ulrich Müller gentoo-dev 2020-02-05 16:41:47 UTC
Like "ln -s -r" from GNU coreutils.

Shouldn't be too difficult to emulate this in bash for non-coreutils implementations of ln. For example, eselect is already doing this:
https://gitweb.gentoo.org/proj/eselect.git/tree/libs/path-manipulation.bash.in#n69
Comment 1 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2020-02-05 16:53:46 UTC
It should probably come with a big fat note that it won't figure out symlinks if they get in the way.
Comment 2 Ulrich Müller gentoo-dev 2020-02-05 17:31:51 UTC
(In reply to Michał Górny from comment #1)
> It should probably come with a big fat note that it won't figure out
> symlinks if they get in the way.

Relative symlinks should work, I think, because the paths are canonicalised. If the image in ${D} contains absolute links then you lose of course.
Comment 3 Ulrich Müller gentoo-dev 2020-02-05 17:38:58 UTC
In #gentoo-qa we came up with this:
- dosym without option accepts only a relative path as first argument
- dosym -r expands the first arg relative to the link location
- dosym -l (or -a for "absolute"?) treats the first arg as a literal string
Comment 4 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2020-02-05 17:43:47 UTC
(In reply to Ulrich Müller from comment #2)
> (In reply to Michał Górny from comment #1)
> > It should probably come with a big fat note that it won't figure out
> > symlinks if they get in the way.
> 
> Relative symlinks should work, I think, because the paths are canonicalised.
> If the image in ${D} contains absolute links then you lose of course.

I meant directory symlinks along the way.

E.g.:

ROOT has /a/b -> ../c
D has plain /a/b directory
you 'dosym -r /a/d /a/b/c'
you get ../d as target

I think we should just make it clear that '-d' doesn't work if there are directory symlinks along the way, whether they are reproduced in D or not.
Comment 5 Ulrich Müller gentoo-dev 2020-02-06 11:12:25 UTC
I think the spec would define that both target and directory will be canonicalised by the same algorithm as used in "readlink -f". Portage already has a canonicalize() shell replacement in misc-functions.sh, so we don't have to worry about systems where readlink doesn't support the -f option.

Alternatively, we could canonicalise using "realpath -m -s" from >=coreutils-8.15, which would purely act on the string, without looking at the filesystem. But IMHO that would be inferior to the above method.
Comment 6 Larry the Git Cow gentoo-dev 2021-05-24 06:08:53 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/portage.git/commit/?id=dfa50503f76f3e70bac50f959a9c7248e6ea880d

commit dfa50503f76f3e70bac50f959a9c7248e6ea880d
Author:     Ulrich Müller <ulm@gentoo.org>
AuthorDate: 2020-11-23 09:06:49 +0000
Commit:     Zac Medico <zmedico@gentoo.org>
CommitDate: 2021-05-24 05:55:41 +0000

    dosym: Implement -r option for EAPI 8.
    
    "dosym -r <target> <link>" will expand the (apparent) path of <target>
    relative to the (apparent) path of the directory containing <link>.
    The main aim of this is to allow for an absolute path to be specified
    as the link target, and the function will count path components and
    convert it into a relative path.
    
    Since we're inside ED at this point but the image will finally be
    installed in EROOT, we don't try to resolve any pre-existing symlinks
    in <target> or <link>. In other words, path expansion only looks at
    the specified apparent paths, without touching any actual files in ED
    or EROOT.
    
    Bug: https://bugs.gentoo.org/708360
    Signed-off-by: Ulrich Müller <ulm@gentoo.org>
    Signed-off-by: Michał Górny <mgorny@gentoo.org>
    Signed-off-by: Zac Medico <zmedico@gentoo.org>

 bin/eapi.sh              |  4 +++
 bin/ebuild-helpers/dosym | 67 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 70 insertions(+), 1 deletion(-)
Comment 7 Larry the Git Cow gentoo-dev 2021-06-13 19:19:01 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/pms.git/commit/?id=42fdc187b717120717e55d9b1bee06a764e55b5d

commit 42fdc187b717120717e55d9b1bee06a764e55b5d
Author:     Ulrich Müller <ulm@gentoo.org>
AuthorDate: 2021-05-16 18:22:15 +0000
Commit:     Ulrich Müller <ulm@gentoo.org>
CommitDate: 2021-06-05 08:55:40 +0000

    EAPI 8 has dosym -r
    
    Bug: https://bugs.gentoo.org/708360
    Signed-off-by: Ulrich Müller <ulm@gentoo.org>

 eapi-differences.tex |  4 ++++
 pkg-mgr-commands.tex | 39 ++++++++++++++++++++++++++++++++++++---
 2 files changed, 40 insertions(+), 3 deletions(-)