[v4,1/1] dpkg-base: resolve DL_DIR in do_adjust_git

Message ID 20220209081244.814-2-Cedric_Hombourger@mentor.com
State Accepted, archived
Headers show
Series dpkg-base: resolve DL_DIR in do_adjust_git | expand

Commit Message

Cedric Hombourger Feb. 8, 2022, 10:12 p.m. UTC
From: Cedric Hombourger <cedric.hombourger@siemens.com>

git_link is resolved using os.path.realpath() but git_dl is not.
If DL_DIR points to a symbolic link, the comparison will always
fail and do_adjust_git() will attempt to re-create the symbolic
link. Resolve DL_DIR for a comparison between resolved paths.
In the event where paths do differ, the symbolic link needs to
be deleted first.

Disposition: Submit upstream
Signed-off-by: Cedric Hombourger <cedric.hombourger@siemens.com>
---
 meta/classes/dpkg-base.bbclass | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Patch

diff --git a/meta/classes/dpkg-base.bbclass b/meta/classes/dpkg-base.bbclass
index 2add0b2..4d496fc 100644
--- a/meta/classes/dpkg-base.bbclass
+++ b/meta/classes/dpkg-base.bbclass
@@ -20,9 +20,13 @@  python do_adjust_git() {
     rootdir = d.getVar('WORKDIR', True)
 
     git_link = os.path.join(d.getVar('GIT_DL_LINK_DIR'), '.git-downloads')
-    git_dl = os.path.join(d.getVar("DL_DIR"), "git")
+    dl_dir = d.getVar("DL_DIR")
+    git_dl = os.path.join(dl_dir, "git")
 
-    if not os.path.exists(git_link) or os.path.realpath(git_link) != git_dl:
+    if os.path.exists(git_link) and os.path.realpath(git_link) != os.path.realpath(git_dl):
+        os.unlink(git_link)
+
+    if not os.path.exists(git_link):
         os.symlink(git_dl, git_link)
 
     for src_uri in (d.getVar("SRC_URI", True) or "").split():
@@ -34,7 +38,7 @@  python do_adjust_git() {
 
             if os.path.islink(ud.localpath):
                 realpath = os.path.realpath(ud.localpath)
-                filter_out = os.path.join(d.getVar("DL_DIR"), "git") + "/"
+                filter_out = git_dl + "/"
                 if realpath.startswith(filter_out):
                     # make the link relative
                     link = realpath.replace(filter_out, '', 1)