@@ -175,11 +175,17 @@ def should_check_directory(directory_path, exclude_patterns, include_patterns):
175
175
# docker logic (2016-10-27):
176
176
# https://github.com/docker/docker/blob/bc52939b0455116ab8e0da67869ec81c1a1c3e2c/pkg/archive/archive.go#L640-L671
177
177
178
- path_with_slash = directory_path + os .sep
179
- possible_child_patterns = [pattern for pattern in include_patterns if
180
- (pattern + os .sep ).startswith (path_with_slash )]
181
- directory_included = should_include (directory_path , exclude_patterns ,
182
- include_patterns )
178
+ def normalize_path (path ):
179
+ return path .replace (os .path .sep , '/' )
180
+
181
+ path_with_slash = normalize_path (directory_path ) + '/'
182
+ possible_child_patterns = [
183
+ pattern for pattern in map (normalize_path , include_patterns )
184
+ if (pattern + '/' ).startswith (path_with_slash )
185
+ ]
186
+ directory_included = should_include (
187
+ directory_path , exclude_patterns , include_patterns
188
+ )
183
189
return directory_included or len (possible_child_patterns ) > 0
184
190
185
191
@@ -195,9 +201,11 @@ def get_paths(root, exclude_patterns, include_patterns, has_exceptions=False):
195
201
# by mutating the dirs we're iterating over.
196
202
# This looks strange, but is considered the correct way to skip
197
203
# traversal. See https://docs.python.org/2/library/os.html#os.walk
198
- dirs [:] = [d for d in dirs if
199
- should_check_directory (os .path .join (parent , d ),
200
- exclude_patterns , include_patterns )]
204
+ dirs [:] = [
205
+ d for d in dirs if should_check_directory (
206
+ os .path .join (parent , d ), exclude_patterns , include_patterns
207
+ )
208
+ ]
201
209
202
210
for path in dirs :
203
211
if should_include (os .path .join (parent , path ),
@@ -213,7 +221,7 @@ def get_paths(root, exclude_patterns, include_patterns, has_exceptions=False):
213
221
214
222
215
223
def match_path (path , pattern ):
216
- pattern = pattern .rstrip ('/' )
224
+ pattern = pattern .rstrip ('/' + os . path . sep )
217
225
if pattern :
218
226
pattern = os .path .relpath (pattern )
219
227
0 commit comments