Fix broken links after moving the bin and sbin directories

This commit is contained in:
Martin Gracik 2009-10-21 12:56:05 +02:00
parent 551647a017
commit 69c69d0e13
2 changed files with 20 additions and 22 deletions

View File

@ -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)

View File

@ -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()