summaryrefslogtreecommitdiff
path: root/Tools/Scripts/webkitpy/common/system/filesystem_mock.py
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/Scripts/webkitpy/common/system/filesystem_mock.py')
-rw-r--r--Tools/Scripts/webkitpy/common/system/filesystem_mock.py31
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: