diff options
author | 2015-11-08 01:57:42 -0500 | |
---|---|---|
committer | 2015-11-08 03:03:52 -0500 | |
commit | 1dc8c1d403afb8a3b0fdc48e5a598105283c2f29 (patch) | |
tree | f48a2b0c958fe94084d62d7e4274c65afe7b70d5 | |
parent | test: add workarounds to support both legacy and new repo/dist/pkg dirs (diff) | |
download | pkgcore-1dc8c1d403afb8a3b0fdc48e5a598105283c2f29.tar.gz pkgcore-1dc8c1d403afb8a3b0fdc48e5a598105283c2f29.tar.bz2 pkgcore-1dc8c1d403afb8a3b0fdc48e5a598105283c2f29.zip |
repository: use realpath instead of abspath to determine file repo status
Previously using abspath would cause a mismatch in certain cases for
files located in a symlinked repo since abspath actually resolves
symlinks in cases due to os.getcwd() also resolving symlinks when within
a path containing them.
Now when doing path comparisons to determine if a file is in a repo or
not we use both the file and the repo's real paths so all symlinks
should be resolved.
-rw-r--r-- | pkgcore/ebuild/repository.py | 8 | ||||
-rw-r--r-- | pkgcore/repository/prototype.py | 10 |
2 files changed, 12 insertions, 6 deletions
diff --git a/pkgcore/ebuild/repository.py b/pkgcore/ebuild/repository.py index a2d5c2fa..19b7fa06 100644 --- a/pkgcore/ebuild/repository.py +++ b/pkgcore/ebuild/repository.py @@ -305,16 +305,16 @@ class _UnconfiguredTree(prototype.tree): :param path: full or partial path to an ebuild :return: a package restriction matching the given path if possible """ - abspath = os.path.abspath(path) + realpath = os.path.realpath(path) - if not self.contains(abspath): + if not self.contains(realpath): raise ValueError("'%s' repo doesn't contain: '%s'" % (self.repo_id, path)) - relpath = abspath[len(self.location):].strip('/') + relpath = realpath[len(os.path.realpath(self.location)):].strip('/') repo_path = relpath.split(os.path.sep) if relpath else [] restrictions = [] - if os.path.isfile(abspath): + if os.path.isfile(realpath): if not path.endswith('.ebuild'): raise ValueError("file is not an ebuild: '%s'" % (path,)) elif len(repo_path) != 3: diff --git a/pkgcore/repository/prototype.py b/pkgcore/repository/prototype.py index dbb760eb..a6daace9 100644 --- a/pkgcore/repository/prototype.py +++ b/pkgcore/repository/prototype.py @@ -193,8 +193,14 @@ class tree(object): :param path: path in the filesystem :return: True if path is in repo, otherwise False """ - path = os.path.abspath(path) - if os.path.exists(path) and path.startswith(getattr(self, 'location', ())): + path = os.path.realpath(path) + + try: + repo_path = os.path.realpath(getattr(self, 'location')) + except AttributeError: + return False + + if os.path.exists(path) and path.startswith(repo_path): return True return False |