summaryrefslogtreecommitdiff
path: root/docker/utils/utils.py
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2017-01-06 16:37:15 -0800
committerJoffrey F <joffrey@docker.com>2017-01-06 16:37:15 -0800
commit9450442c8c3e69d6ec82dc9610fe7f8ee31181f2 (patch)
tree6496b11a84af1e0a0ee2da7f1870555ef12f12bd /docker/utils/utils.py
parent6d871990d207027bc73ab16eae539af280151016 (diff)
downloaddocker-py-compose-4302-dockerignore-windows.tar.gz
Accept / as a path separator in dockerignore patterns on all platformscompose-4302-dockerignore-windows
Signed-off-by: Joffrey F <joffrey@docker.com>
Diffstat (limited to 'docker/utils/utils.py')
-rw-r--r--docker/utils/utils.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py
index 4e5f454..e12fcf0 100644
--- a/docker/utils/utils.py
+++ b/docker/utils/utils.py
@@ -175,11 +175,17 @@ def should_check_directory(directory_path, exclude_patterns, include_patterns):
# docker logic (2016-10-27):
# https://github.com/docker/docker/blob/bc52939b0455116ab8e0da67869ec81c1a1c3e2c/pkg/archive/archive.go#L640-L671
- path_with_slash = directory_path + os.sep
- possible_child_patterns = [pattern for pattern in include_patterns if
- (pattern + os.sep).startswith(path_with_slash)]
- directory_included = should_include(directory_path, exclude_patterns,
- include_patterns)
+ def normalize_path(path):
+ return path.replace(os.path.sep, '/')
+
+ path_with_slash = normalize_path(directory_path) + '/'
+ possible_child_patterns = [
+ pattern for pattern in map(normalize_path, include_patterns)
+ if (pattern + '/').startswith(path_with_slash)
+ ]
+ directory_included = should_include(
+ directory_path, exclude_patterns, include_patterns
+ )
return directory_included or len(possible_child_patterns) > 0
@@ -195,9 +201,11 @@ def get_paths(root, exclude_patterns, include_patterns, has_exceptions=False):
# by mutating the dirs we're iterating over.
# This looks strange, but is considered the correct way to skip
# traversal. See https://docs.python.org/2/library/os.html#os.walk
- dirs[:] = [d for d in dirs if
- should_check_directory(os.path.join(parent, d),
- exclude_patterns, include_patterns)]
+ dirs[:] = [
+ d for d in dirs if should_check_directory(
+ os.path.join(parent, d), exclude_patterns, include_patterns
+ )
+ ]
for path in dirs:
if should_include(os.path.join(parent, path),
@@ -213,7 +221,7 @@ def get_paths(root, exclude_patterns, include_patterns, has_exceptions=False):
def match_path(path, pattern):
- pattern = pattern.rstrip('/')
+ pattern = pattern.rstrip('/' + os.path.sep)
if pattern:
pattern = os.path.relpath(pattern)