@@ -31,18 +31,21 @@ def exclude_paths(root, patterns, dockerfile=None):
31
31
if dockerfile is None :
32
32
dockerfile = 'Dockerfile'
33
33
34
+ def split_path (p ):
35
+ return [pt for pt in re .split (_SEP , p ) if pt and pt != '.' ]
36
+
34
37
def normalize (p ):
35
38
# Leading and trailing slashes are not relevant. Yes,
36
39
# "foo.py/" must exclude the "foo.py" regular file. "."
37
40
# components are not relevant either, even if the whole
38
41
# pattern is only ".", as the Docker reference states: "For
39
42
# historical reasons, the pattern . is ignored."
40
- split = [pt for pt in re .split (_SEP , p ) if pt and pt != '.' ]
41
43
# ".." component must be cleared with the potential previous
42
44
# component, regardless of whether it exists: "A preprocessing
43
45
# step [...] eliminates . and .. elements using Go's
44
46
# filepath.".
45
47
i = 0
48
+ split = split_path (p )
46
49
while i < len (split ):
47
50
if split [i ] == '..' :
48
51
del split [i ]
@@ -62,7 +65,7 @@ def normalize(p):
62
65
# Exclude empty patterns such as "." or the empty string.
63
66
filter (lambda p : p [1 ], patterns ),
64
67
# Always include the Dockerfile and .dockerignore
65
- [(True , dockerfile . split ( '/' )), (True , ['.dockerignore' ])]))))
68
+ [(True , split_path ( dockerfile )), (True , ['.dockerignore' ])]))))
66
69
return set (walk (root , patterns ))
67
70
68
71
0 commit comments