summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan van Berkom <tristan@codethink.co.uk>2020-11-11 20:17:15 +0900
committerTristan van Berkom <tristan@codethink.co.uk>2020-11-19 15:41:28 +0900
commit8aadb611f38162c8345d480e944ee48b736cc0f4 (patch)
treed93bfd90b5a564772d0ecb0308c60da5d4e313f1
parent2991a5dd265751c309cbc2b2bbc4c44c3cc3a9d6 (diff)
downloadbuildstream-8aadb611f38162c8345d480e944ee48b736cc0f4.tar.gz
_stream.py: Use consistent glob handling with utils.glob()
We should not have a different globbing behavior than split rules for the command line. This should also make artifact globbing slightly more performant, as the regular expression under the hood need not be recompiled for each file being checked. This commit also updates tests/frontend/artifact_list_contents.py to use a double star `**` (globstar syntax) in order to match path separators as well as all other characters in the list contents command.
-rw-r--r--src/buildstream/_assetcache.py9
-rw-r--r--tests/frontend/artifact_list_contents.py2
2 files changed, 8 insertions, 3 deletions
diff --git a/src/buildstream/_assetcache.py b/src/buildstream/_assetcache.py
index 68f7fd732..a0b502f2b 100644
--- a/src/buildstream/_assetcache.py
+++ b/src/buildstream/_assetcache.py
@@ -17,7 +17,7 @@
# Raoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk>
#
import os
-from fnmatch import fnmatch
+import re
from itertools import chain
from typing import TYPE_CHECKING
import grpc
@@ -630,11 +630,16 @@ class AssetCache:
# append the glob to optimise the os.walk()
path = os.path.join(base_path, globdir)
+ regexer = None
+ if glob_expr:
+ expression = utils._glob2re(glob_expr)
+ regexer = re.compile(expression)
+
for root, _, files in os.walk(path):
for filename in files:
ref_path = os.path.join(root, filename)
relative_path = os.path.relpath(ref_path, base_path) # Relative to refs head
- if not glob_expr or fnmatch(relative_path, glob_expr):
+ if regexer is None or regexer.match(relative_path):
# Obtain the mtime (the time a file was last modified)
yield (os.path.getmtime(ref_path), relative_path)
diff --git a/tests/frontend/artifact_list_contents.py b/tests/frontend/artifact_list_contents.py
index 8bd7bdeff..ee129cc9f 100644
--- a/tests/frontend/artifact_list_contents.py
+++ b/tests/frontend/artifact_list_contents.py
@@ -71,7 +71,7 @@ def test_artifact_list_exact_contents_glob(cli, datafiles):
assert result.exit_code == 0
# List the contents via glob
- result = cli.run(project=project, args=["artifact", "list-contents", "test/*"])
+ result = cli.run(project=project, args=["artifact", "list-contents", "test/**"])
assert result.exit_code == 0
# get the cahe keys for each element in the glob