Skip to content

Commit

Permalink
Fixes #886 - Don't force to have a / on last parameter for "modify" c…
Browse files Browse the repository at this point in the history
…ommand.
  • Loading branch information
fviard committed Jun 28, 2017
1 parent ca4a19a commit 377dc7a
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions s3cmd
Original file line number Diff line number Diff line change
Expand Up @@ -793,41 +793,45 @@ def cmd_object_restore(args):


def subcmd_cp_mv(args, process_fce, action_str, message):
if action_str != 'modify' and len(args) < 2:
raise ParameterError("Expecting two or more S3 URIs for " + action_str)
if action_str == 'modify' and len(args) < 1:
raise ParameterError("Expecting one or more S3 URIs for " + action_str)
if action_str != 'modify':
dst_base_uri = S3Uri(args.pop())
if action_str == 'modify':
if len(args) < 1:
raise ParameterError("Expecting one or more S3 URIs for " + action_str)
destination_base = None
else:
dst_base_uri = S3Uri(args[-1])
if len(args) < 2:
raise ParameterError("Expecting two or more S3 URIs for " + action_str)
dst_base_uri = S3Uri(args.pop())
if dst_base_uri.type != "s3":
raise ParameterError("Destination must be S3 URI. To download a file use 'get' or 'sync'.")
destination_base = dst_base_uri.uri()

scoreboard = ExitScoreboard()
if dst_base_uri.type != "s3":
raise ParameterError("Destination must be S3 URI. To download a file use 'get' or 'sync'.")
destination_base = dst_base_uri.uri()

remote_list, exclude_list, remote_total_size = fetch_remote_list(args, require_attribs = False)

remote_count = len(remote_list)

info(u"Summary: %d remote files to %s" % (remote_count, action_str))

if not destination_base.endswith('/'):
if destination_base:
# Trying to mv dir1/ to dir2 will not pass a test in S3.FileLists,
# so we don't need to test for it here.
if len(remote_list) > 1 or cfg.recursive:
raise ParameterError("Destination must be a directory and end with '/' when acting on a folder content or on multiple sources.")
if not destination_base.endswith('/') \
and (len(remote_list) > 1 or cfg.recursive):
raise ParameterError("Destination must be a directory and end with '/' when acting on a folder content or on multiple sources.")

if cfg.recursive:
for key in remote_list:
remote_list[key]['dest_name'] = destination_base + key
if cfg.recursive:
for key in remote_list:
remote_list[key]['dest_name'] = destination_base + key
else:
for key in remote_list:
if destination_base.endswith("/"):
remote_list[key]['dest_name'] = destination_base + key
else:
remote_list[key]['dest_name'] = destination_base
else:
for key in remote_list:
if destination_base.endswith("/"):
remote_list[key]['dest_name'] = destination_base + key
else:
remote_list[key]['dest_name'] = destination_base
remote_list[key]['dest_name'] = remote_list[key]['object_uri_str']

if cfg.dry_run:
for key in exclude_list:
Expand Down

0 comments on commit 377dc7a

Please sign in to comment.