Skip to content

Commit

Permalink
Changes to validator for private MacOS paths (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Mar 11, 2022
1 parent 173a769 commit 14b0bd4
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions tools/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,12 @@ def _CheckGlobstarInPathSegment(

return True

def _CheckMacOSPaths(self, filename, artifact_definition, source, paths):
def _CheckMacOSPaths(self, filename, artifact_definition, paths):
"""Checks if the paths are valid MacOS paths.
Args:
filename (str): name of the artifacts definition file.
artifact_definition (ArtifactDefinition): artifact definition.
source (SourceType): source definition.
paths (list[str]): paths to validate.
Returns:
Expand All @@ -105,7 +104,7 @@ def _CheckMacOSPaths(self, filename, artifact_definition, source, paths):

for path in paths:
path_lower = path.lower()
path_segments = path_lower.split(source.separator)
path_segments = path_lower.split('/')
if not path_segments:
logging.warning((
'Empty path defined by artifact definition: {0:s} in file: '
Expand Down Expand Up @@ -145,7 +144,7 @@ def _CheckMacOSPaths(self, filename, artifact_definition, source, paths):
filename, artifact_definition, path, path_segment):
result = False

if has_globstar and path.endswith(source.separator):
if has_globstar and path.endswith('/'):
logging.warning((
'Unsupported path: {0:s} with globstar and trailing path '
'separator defined by artifact definition: {1:s} in file: '
Expand Down Expand Up @@ -469,6 +468,8 @@ def CheckFile(self, filename):
definitions.SUPPORTED_OS_WINDOWS in (
artifact_definition.supported_os))

macos_paths = []

for source in artifact_definition.sources:
if source.type_indicator == definitions.TYPE_INDICATOR_DIRECTORY:
logging.warning((
Expand All @@ -483,9 +484,13 @@ def CheckFile(self, filename):
if (definitions.SUPPORTED_OS_DARWIN in source.supported_os or (
artifact_definition_supports_macos and
not source.supported_os)):
if not self._CheckMacOSPaths(
filename, artifact_definition, source, source.paths):
result = False
if source.separator != '/':
logging.warning((
'Use of unsupported path segment seperator in artifact '
'definition: {0:s} in file: {1:s}').format(
artifact_definition.name, filename))

macos_paths.extend(source.paths)

elif (artifact_definition_supports_windows or
definitions.SUPPORTED_OS_WINDOWS in source.supported_os):
Expand Down Expand Up @@ -523,6 +528,11 @@ def CheckFile(self, filename):
filename, artifact_definition, key_value_pair['key']):
result = False

if macos_paths:
if not self._CheckMacOSPaths(
filename, artifact_definition, macos_paths):
result = False

except errors.FormatError as exception:
logging.warning(
'Unable to validate file: {0:s} with error: {1!s}'.format(
Expand Down

0 comments on commit 14b0bd4

Please sign in to comment.