summaryrefslogtreecommitdiff
path: root/meta/lib/oe
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:50:54 +0000
commit15376e5ff35367c1b40941d10e7b19302058a53e (patch)
tree44afaa4cdb66d06c77cf3b1033de15bf3bf98c31 /meta/lib/oe
parentf70603887f823c14030bb738c4951d7aa3f022db (diff)
downloadopenembedded-core-15376e5ff35367c1b40941d10e7b19302058a53e.tar.gz
openembedded-core-15376e5ff35367c1b40941d10e7b19302058a53e.tar.bz2
openembedded-core-15376e5ff35367c1b40941d10e7b19302058a53e.zip
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. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oe')
-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):
os.remove(path)
os.symlink(base, path)
+def replace_absolute_symlinks(basedir, d):
+ """
+ Walk basedir looking for absolute symlinks and replacing them with relative ones.
+ The absolute links are assumed to be relative to basedir
+ (compared to make_relative_symlink above which tries to compute common ancestors
+ using pattern matching instead)
+ """
+ for walkroot, dirs, files in os.walk(basedir):
+ for file in files + dirs:
+ path = os.path.join(walkroot, file)
+ if not os.path.islink(path):
+ continue
+ link = os.readlink(path)
+ if not os.path.isabs(link):
+ continue
+ walkdir = os.path.dirname(path.rpartition(basedir)[2])
+ base = os.path.relpath(link, walkdir)
+ bb.debug(2, "Replacing absolute path %s with relative path %s" % (link, base))
+ os.remove(path)
+ os.symlink(base, path)
+
def format_display(path, metadata):
""" Prepare a path for display to the user. """
rel = relative(metadata.getVar("TOPDIR"), path)