1
1
import io
2
2
import os
3
3
import re
4
- import six
5
4
import tarfile
6
5
import tempfile
7
6
8
- from ..constants import IS_WINDOWS_PLATFORM
7
+ import six
8
+
9
9
from .fnmatch import fnmatch
10
+ from ..constants import IS_WINDOWS_PLATFORM
10
11
11
12
12
13
_SEP = re .compile ('/|\\ \\ ' ) if IS_WINDOWS_PLATFORM else re .compile ('/' )
@@ -139,6 +140,12 @@ def split_path(p):
139
140
return [pt for pt in re .split (_SEP , p ) if pt and pt != '.' ]
140
141
141
142
143
+ def normalize_slashes (p ):
144
+ if IS_WINDOWS_PLATFORM :
145
+ return '/' .join (split_path (p ))
146
+ return p
147
+
148
+
142
149
# Heavily based on
143
150
# https://github.com/moby/moby/blob/master/pkg/fileutils/fileutils.go
144
151
class PatternMatcher (object ):
@@ -184,7 +191,7 @@ def rec_walk(current_dir):
184
191
continue
185
192
186
193
if match :
187
- # If we want to skip this file and its a directory
194
+ # If we want to skip this file and it's a directory
188
195
# then we should first check to see if there's an
189
196
# excludes pattern (e.g. !dir/file) that starts with this
190
197
# dir. If so then we can't skip this dir.
@@ -193,7 +200,8 @@ def rec_walk(current_dir):
193
200
for pat in self .patterns :
194
201
if not pat .exclusion :
195
202
continue
196
- if pat .cleaned_pattern .startswith (fpath ):
203
+ if pat .cleaned_pattern .startswith (
204
+ normalize_slashes (fpath )):
197
205
skip = False
198
206
break
199
207
if skip :
@@ -239,4 +247,4 @@ def normalize(cls, p):
239
247
return split
240
248
241
249
def match (self , filepath ):
242
- return fnmatch (filepath , self .cleaned_pattern )
250
+ return fnmatch (normalize_slashes ( filepath ) , self .cleaned_pattern )
0 commit comments