diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-02-09 14:16:12 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-02-09 14:16:12 +0100 |
commit | 03e12282df9aa1e1fb05a8b90f1cfc2e08764cec (patch) | |
tree | 52599cd0ab782b1768e23ad176f7618f98333cb6 /Tools/Scripts/webkitpy/common/system/filesystem_mock.py | |
parent | cd44dc59cdfc39534aef4d417e9f3c412e3be139 (diff) | |
download | qtwebkit-03e12282df9aa1e1fb05a8b90f1cfc2e08764cec.tar.gz |
Imported WebKit commit e09a82039aa4273ab318b71122e92d8e5f233525 (http://svn.webkit.org/repository/webkit/trunk@107223)
Diffstat (limited to 'Tools/Scripts/webkitpy/common/system/filesystem_mock.py')
-rw-r--r-- | Tools/Scripts/webkitpy/common/system/filesystem_mock.py | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/Tools/Scripts/webkitpy/common/system/filesystem_mock.py b/Tools/Scripts/webkitpy/common/system/filesystem_mock.py index e91d6682a..6e106dd83 100644 --- a/Tools/Scripts/webkitpy/common/system/filesystem_mock.py +++ b/Tools/Scripts/webkitpy/common/system/filesystem_mock.py @@ -33,7 +33,6 @@ import os import re from webkitpy.common.system import path -from webkitpy.common.system import ospath class MockFileSystem(object): @@ -180,7 +179,7 @@ class MockFileSystem(object): # to a different thread and potentially modifying the dict in # mid-iteration. files = self.files.keys()[:] - result = any(f.startswith(path) for f in files) + result = any(f.startswith(path) and len(self.split(f)[0]) >= len(path) for f in files) if result: self.dirs.add(path) return result @@ -303,7 +302,33 @@ class MockFileSystem(object): return hashlib.sha1(contents).hexdigest() def relpath(self, path, start='.'): - return ospath.relpath(path, start, self.abspath, self.sep) + # Since os.path.relpath() calls os.path.normpath() + # (see http://docs.python.org/library/os.path.html#os.path.abspath ) + # it also removes trailing slashes and converts forward and backward + # slashes to the preferred slash os.sep. + start = self.abspath(start) + path = self.abspath(path) + + if not path.lower().startswith(start.lower()): + # Then path is outside the directory given by start. + return None # FIXME: os.relpath still returns a path here. + + rel_path = path[len(start):] + + if not rel_path: + # Then the paths are the same. + pass + elif rel_path[0] == self.sep: + # It is probably sufficient to remove just the first character + # since os.path.normpath() collapses separators, but we use + # lstrip() just to be sure. + rel_path = rel_path.lstrip(self.sep) + else: + # We are in the case typified by the following example: + # path = "/tmp/foobar", start = "/tmp/foo" -> rel_path = "bar" + return None + + return rel_path def remove(self, path): if self.files[path] is None: |