X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/aa94204c3e88f5386d14cb90e3e13a5e9caaf251..ebb2559b3a09636ff687316bbe512e0e8a86b168:/sdk/python/arvados/commands/put.py diff --git a/sdk/python/arvados/commands/put.py b/sdk/python/arvados/commands/put.py index 479c72a5ed..714281cc95 100644 --- a/sdk/python/arvados/commands/put.py +++ b/sdk/python/arvados/commands/put.py @@ -423,6 +423,12 @@ class ArvPutUploadJob(object): # there aren't any file to upload. if self.dry_run: raise ArvPutUploadNotPending() + # Remove local_collection's files that don't exist locally anymore, so the + # bytes_written count is correct. + for f in self.collection_file_paths(self._local_collection, + path_prefix=""): + if f != 'stdin' and f != self.filename and not f in self._file_paths: + self._local_collection.remove(f) # Update bytes_written from current local collection and # report initial progress. self._update() @@ -659,6 +665,17 @@ class ArvPutUploadJob(object): # Load the previous manifest so we can check if files were modified remotely. self._local_collection = arvados.collection.Collection(self._state['manifest'], replication_desired=self.replication_desired) + def collection_file_paths(self, col, path_prefix='.'): + """Return a list of file paths by recursively go through the entire collection `col`""" + file_paths = [] + for name, item in col.items(): + if isinstance(item, arvados.arvfile.ArvadosFile): + file_paths.append(os.path.join(path_prefix, name)) + elif isinstance(item, arvados.collection.Subcollection): + new_prefix = os.path.join(path_prefix, name) + file_paths += self.collection_file_paths(item, path_prefix=new_prefix) + return file_paths + def _lock_file(self, fileobj): try: fcntl.flock(fileobj, fcntl.LOCK_EX | fcntl.LOCK_NB) @@ -794,6 +811,9 @@ def main(arguments=None, stdout=sys.stdout, stderr=sys.stderr): if args.stream or args.raw: logger.error("Cannot use --name with --stream or --raw") sys.exit(1) + elif args.update_collection: + logger.error("Cannot use --name with --update-collection") + sys.exit(1) collection_name = args.name else: collection_name = "Saved at {} by {}@{}".format(