@@ -175,11 +175,17 @@ def should_check_directory(directory_path, exclude_patterns, include_patterns):
175175 # docker logic (2016-10-27):
176176 # https://github.com/docker/docker/blob/bc52939b0455116ab8e0da67869ec81c1a1c3e2c/pkg/archive/archive.go#L640-L671
177177
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+ )
183189 return directory_included or len (possible_child_patterns ) > 0
184190
185191
@@ -195,9 +201,11 @@ def get_paths(root, exclude_patterns, include_patterns, has_exceptions=False):
195201 # by mutating the dirs we're iterating over.
196202 # This looks strange, but is considered the correct way to skip
197203 # 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+ ]
201209
202210 for path in dirs :
203211 if should_include (os .path .join (parent , path ),
@@ -213,7 +221,7 @@ def get_paths(root, exclude_patterns, include_patterns, has_exceptions=False):
213221
214222
215223def match_path (path , pattern ):
216- pattern = pattern .rstrip ('/' )
224+ pattern = pattern .rstrip ('/' + os . path . sep )
217225 if pattern :
218226 pattern = os .path .relpath (pattern )
219227
0 commit comments