summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2017-02-08 15:08:54 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-02-09 10:52:03 +0000
commiteac8f9b986b565ff8ce6ffeb93bcadffc9c34330 (patch)
tree382d2ac03fcc61bf505d32f8a5e9fc47b8215358
parent48527d4ff3a41c16eafebd87620469f341ff981a (diff)
downloadpoky-eac8f9b986b565ff8ce6ffeb93bcadffc9c34330.tar.gz
lib/oe/path: Add replace_absolute_symlinks function
We need a function to walk a directory and replace absolute symlinks with relative ones. Add such a function to the path module of lib/oe. It does this relative to the directory being walked for files. (From OE-Core rev: 15376e5ff35367c1b40941d10e7b19302058a53e) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oe/path.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/meta/lib/oe/path.py b/meta/lib/oe/path.py
index d4685403c5..a2a50c5b39 100644
--- a/meta/lib/oe/path.py
+++ b/meta/lib/oe/path.py
@@ -50,6 +50,27 @@ def make_relative_symlink(path):
50 os.remove(path) 50 os.remove(path)
51 os.symlink(base, path) 51 os.symlink(base, path)
52 52
53def replace_absolute_symlinks(basedir, d):
54 """
55 Walk basedir looking for absolute symlinks and replacing them with relative ones.
56 The absolute links are assumed to be relative to basedir
57 (compared to make_relative_symlink above which tries to compute common ancestors
58 using pattern matching instead)
59 """
60 for walkroot, dirs, files in os.walk(basedir):
61 for file in files + dirs:
62 path = os.path.join(walkroot, file)
63 if not os.path.islink(path):
64 continue
65 link = os.readlink(path)
66 if not os.path.isabs(link):
67 continue
68 walkdir = os.path.dirname(path.rpartition(basedir)[2])
69 base = os.path.relpath(link, walkdir)
70 bb.debug(2, "Replacing absolute path %s with relative path %s" % (link, base))
71 os.remove(path)
72 os.symlink(base, path)
73
53def format_display(path, metadata): 74def format_display(path, metadata):
54 """ Prepare a path for display to the user. """ 75 """ Prepare a path for display to the user. """
55 rel = relative(metadata.getVar("TOPDIR"), path) 76 rel = relative(metadata.getVar("TOPDIR"), path)