Commit 24bca4e7 authored by Daniel Cheng's avatar Daniel Cheng Committed by Commit Bot

owners.py: Use os.path.split to handle file separators correctly

The script gets confused on Windows, because the path delimieter is \,
not /.

Bug: 899724
Change-Id: Id907aceb4f7bb6fcc0460245890b9e4716054ff9
Reviewed-on: https://chromium-review.googlesource.com/c/1308897Reviewed-by: 's avatarDirk Pranke <dpranke@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
parent a870c969
......@@ -149,6 +149,12 @@ class Database(object):
# File with global status lines for owners.
self._status_file = None
def _file_affects_ownership(self, path):
"""Returns true if the path refers to a file that could affect ownership."""
filename = self.os_path.split(path)[-1]
return filename == 'OWNERS' or filename.endswith('_OWNERS')
def reviewers_for(self, files, author):
"""Returns a suggested set of reviewers that will cover the files.
......@@ -395,7 +401,7 @@ class Database(object):
# Paths included via "file:" must end in OWNERS or _OWNERS. Files that can
# affect ownership have a different set of ownership rules, so that users
# cannot self-approve changes adding themselves to an OWNERS file.
if not (owners_path.endswith('/OWNERS') or owners_path.endswith('_OWNERS')):
if not self._file_affects_ownership(owners_path):
raise SyntaxErrorInOwnersFile(start, lineno, 'file: include must specify '
'a file named OWNERS or ending in _OWNERS')
......
......@@ -30,9 +30,6 @@ class MockFileSystem(object):
def sep(self):
return self._sep
def _split(self, path):
return path.rsplit(self.sep, 1)
def abspath(self, path):
if path.endswith(self.sep):
return path[:-1]
......@@ -41,12 +38,12 @@ class MockFileSystem(object):
def basename(self, path):
if self.sep not in path:
return ''
return self._split(path)[-1] or self.sep
return self.split(path)[-1] or self.sep
def dirname(self, path):
if self.sep not in path:
return ''
return self._split(path)[0] or self.sep
return self.split(path)[0] or self.sep
def exists(self, path):
return self.isfile(path) or self.isdir(path)
......@@ -92,3 +89,6 @@ class MockFileSystem(object):
base += self.sep
assert path.startswith(base)
return path[len(base):]
def split(self, path):
return path.rsplit(self.sep, 1)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment