elif os.path.isdir(path):
# Use absolute paths on cache index so CWD doesn't interfere
# with the caching logic.
- prefixdir = path = os.path.abspath(path)
- if prefixdir != '/':
- prefixdir += '/'
+ orig_path = path
+ path = os.path.abspath(path)
+ if orig_path[-1:] == os.sep:
+ # When passing a directory reference with a trailing slash,
+ # its contents should be uploaded directly to the collection's root.
+ prefixdir = path
+ else:
+ # When passing a directory reference with no trailing slash,
+ # upload the directory to the collection's root.
+ prefixdir = os.path.dirname(path)
+ prefixdir += os.sep
for root, dirs, files in os.walk(path, followlinks=self.follow_links):
+ root_relpath = os.path.relpath(root, path)
+ # Exclude files/dirs by full path matching pattern
+ if self.exclude_paths:
+ dirs[:] = filter(
+ lambda d: not any([pathname_match(os.path.join(root_relpath, d),
+ pat)
+ for pat in self.exclude_paths]),
+ dirs)
+ files = filter(
+ lambda f: not any([pathname_match(os.path.join(root_relpath, f),
+ pat)
+ for pat in self.exclude_paths]),
+ files)
+ # Exclude files/dirs by name matching pattern
+ if self.exclude_names is not None:
+ dirs[:] = filter(lambda d: not self.exclude_names.match(d), dirs)
+ files = filter(lambda f: not self.exclude_names.match(f), files)
# Make os.walk()'s dir traversing order deterministic
dirs.sort()
files.sort()