From 69c69d0e13f5db514e3418bfc46db19ab074661a Mon Sep 17 00:00:00 2001 From: Martin Gracik Date: Wed, 21 Oct 2009 12:56:05 +0200 Subject: [PATCH] Fix broken links after moving the bin and sbin directories --- src/pylorax/_rewrite/scrubs.py | 22 ---------------------- src/pylorax/insttree.py | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/pylorax/_rewrite/scrubs.py b/src/pylorax/_rewrite/scrubs.py index a85bdfa9..1ec6279a 100644 --- a/src/pylorax/_rewrite/scrubs.py +++ b/src/pylorax/_rewrite/scrubs.py @@ -161,25 +161,3 @@ class Install(object): # remove dirs from etc/rc.d dirs = ('rc?.d', 'rc', 'rc.local', 'rc.sysinit') map(lambda dir: rm(os.path.join(self.conf.treedir, 'etc', 'rc.d', dir)), dirs) - - def fix_links(self): - print("Fixing broken links") - for dir in ('bin', 'sbin'): - dir = os.path.join(self.conf.treedir, 'usr', dir) - - brokenlinks = [] - for root, dnames, fnames in os.walk(dir): - for fname in fnames: - fname = os.path.join(root, fname) - if os.path.islink(fname): - target = os.readlink(fname) - if not os.path.exists(fname): - brokenlinks.append(fname) - - for link in brokenlinks: - target = os.readlink(link) - for dir in ('bin', 'sbin'): - newtarget = re.sub(r'^\.\./\.\./%s/(.*)' % dir, '../%s/\g<1>' % dir, target) - if newtarget != target: - os.unlink(link) - os.symlink(newtarget, link) diff --git a/src/pylorax/insttree.py b/src/pylorax/insttree.py index be106bb6..44118cdc 100644 --- a/src/pylorax/insttree.py +++ b/src/pylorax/insttree.py @@ -24,6 +24,7 @@ import os import glob import fnmatch import shutil +import re from utils.fileutils import copy, move, remove, replace, touch @@ -485,6 +486,25 @@ class InstallTree(object): dst_path=os.path.join("usr", "sbin")) remove(os.path.join(self.conf.treedir, "sbin")) + # fix broken links + brokenlinks = [] + for dir in ("bin", "sbin"): + dir = os.path.join(self.conf.treedir, "usr", dir) + for root, dnames, fnames in os.walk(dir): + for fname in fnames: + fname = os.path.join(root, fname) + if os.path.islink(fname) and not os.path.exists(fname): + brokenlinks.append(fname) + + for link in brokenlinks: + target = os.readlink(link) + newtarget = re.sub(r"^\.\./\.\./(bin|sbin)/(.*)$", "../\g<1>/\g<2>", + target) + + if newtarget != target: + os.unlink(link) + os.symlink(newtarget, link) + def scrub(self): self.copy_stubs() self.create_dogtail_conf()