From 9da70731a8d166d5ccf341771bd1bbf379ea07ed Mon Sep 17 00:00:00 2001 From: Maxim Sobolev Date: Wed, 5 Dec 2001 08:13:40 +0000 Subject: Make the tool working even if there is a symlink in a given path to a port's file. For example I'm usually keeping all working directories in /tmp using WRKDIRPREFIX, while for the quick access to a port's files creating a symlink to this directory in skeleton's dir (i.e. ports/foo/bar/src --> /tmp/usr/ports/foo/bar/work/bar-0.0) and with this patch the tool correctly works when I'm specifying `src/foo.c' as an argument. --- Tools/scripts/patchtool.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'Tools/scripts/patchtool.py') diff --git a/Tools/scripts/patchtool.py b/Tools/scripts/patchtool.py index 3e28abd39335..ec786d332534 100755 --- a/Tools/scripts/patchtool.py +++ b/Tools/scripts/patchtool.py @@ -108,7 +108,7 @@ def locateportdir(path, wrkdirprefix= '', strict = False): # # Get value of a make(1) variable called varname. Optionally maintain a cache # for resolved varname:makepath pairs to speed-up operation if the same variable -# from the exactly same file is requiested repeatedly (invocation of make(1) is +# from the exactly same file is requested repeatedly (invocation of make(1) is # very expensive operation...) # def querymakevar(varname, path = 'Makefile', strict = False, cache = {}): @@ -456,6 +456,31 @@ class PatchesCollection: return self.patches.values() +# +# Resolve all symbolic links in the given path to a file +# +def truepath(path): + if not os.path.isfile(path): + raise IOError(errno.ENOENT, path) + + result = '' + while len(path) > 0: + path, lastcomp = os.path.split(path) + if len(lastcomp) == 0: + lastcomp = path + path = '' + result = os.path.join(lastcomp, result) + if len(path) == 0: + break + if os.path.islink(path): + linkto = os.path.normpath(os.readlink(path)) + if linkto[0] != '/': + path = os.path.join(path, linkto) + else: + path = linkto + return result[:-1] + + def main(): try: opts, args = getopt.getopt(sys.argv[1:], 'afui') @@ -508,6 +533,8 @@ def generate(args, automatic, force, ignoremtime): raise IOError(errno.ENOENT, filepath) # Not reached # + filepath = truepath(filepath) + wrkdirprefix = querymakevar('WRKDIRPREFIX', Vars.ETC_MAKE_CONF, False) portdir = locateportdir(os.path.dirname(filepath), wrkdirprefix, True) wrksrc = querymakevar('WRKSRC', portdir, True) -- cgit v1.2.3