Skip to content

Commit 088094c

Browse files
committed
On Windows, convert paths to use forward slashes before fnmatch call
Signed-off-by: Joffrey F <[email protected]>
1 parent 5017de4 commit 088094c

File tree

3 files changed

+511
-490
lines changed

3 files changed

+511
-490
lines changed

docker/utils/build.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import io
22
import os
33
import re
4-
import six
54
import tarfile
65
import tempfile
76

8-
from ..constants import IS_WINDOWS_PLATFORM
7+
import six
8+
99
from .fnmatch import fnmatch
10+
from ..constants import IS_WINDOWS_PLATFORM
1011

1112

1213
_SEP = re.compile('/|\\\\') if IS_WINDOWS_PLATFORM else re.compile('/')
@@ -139,6 +140,12 @@ def split_path(p):
139140
return [pt for pt in re.split(_SEP, p) if pt and pt != '.']
140141

141142

143+
def normalize_slashes(p):
144+
if IS_WINDOWS_PLATFORM:
145+
return '/'.join(split_path(p))
146+
return p
147+
148+
142149
# Heavily based on
143150
# https://github.com/moby/moby/blob/master/pkg/fileutils/fileutils.go
144151
class PatternMatcher(object):
@@ -184,7 +191,7 @@ def rec_walk(current_dir):
184191
continue
185192

186193
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
188195
# then we should first check to see if there's an
189196
# excludes pattern (e.g. !dir/file) that starts with this
190197
# dir. If so then we can't skip this dir.
@@ -193,7 +200,8 @@ def rec_walk(current_dir):
193200
for pat in self.patterns:
194201
if not pat.exclusion:
195202
continue
196-
if pat.cleaned_pattern.startswith(fpath):
203+
if pat.cleaned_pattern.startswith(
204+
normalize_slashes(fpath)):
197205
skip = False
198206
break
199207
if skip:
@@ -239,4 +247,4 @@ def normalize(cls, p):
239247
return split
240248

241249
def match(self, filepath):
242-
return fnmatch(filepath, self.cleaned_pattern)
250+
return fnmatch(normalize_slashes(filepath), self.cleaned_pattern)

0 commit comments

Comments
 (0)