11789: Merge branch 'master' into 11789-arvput-exclude-flag
authorLucas Di Pentima <lucas@curoverse.com>
Tue, 20 Jun 2017 20:41:36 +0000 (17:41 -0300)
committerLucas Di Pentima <lucas@curoverse.com>
Tue, 20 Jun 2017 20:41:36 +0000 (17:41 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@curoverse.com>

1  2 
sdk/python/arvados/commands/put.py

index 4aab5d56c6541bdfb8eef6843248ca54a7dda7a6,e5916560bfb8b1670e0dc995fed11d06807d44e6..ba7ff2bbd9f62af754bb59762d17342eb1484441
@@@ -451,27 -440,18 +453,35 @@@ class ArvPutUploadJob(object)
                  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()