Skip to content

Commit cfc01fa

Browse files
committed
Fixes #1190 - Set properly PARTIAL exit code for object_get when needed
1 parent d79246c commit cfc01fa

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

s3cmd

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -607,24 +607,32 @@ def cmd_object_get(args):
607607
dst_stream.close()
608608
raise ParameterError(u"File %s already exists. Use either of --force / --continue / --skip-existing or give it a new name." % destination)
609609
except IOError as e:
610-
error(u"Skipping %s: %s" % (destination, e.strerror))
610+
error(u"Creation of file '%s' failed (Reason: %s)"
611+
% (destination, e.strerror))
612+
if cfg.stop_on_error:
613+
error(u"Exiting now because of --stop-on-error")
614+
raise
615+
ret = EX_PARTIAL
611616
continue
617+
612618
try:
613619
try:
614620
response = s3.object_get(uri, dst_stream, destination, start_position = start_position, extra_label = seq_label)
615621
finally:
616622
dst_stream.close()
617623
except S3DownloadError as e:
618-
error(u"%s: Skipping that file. This is usually a transient error, please try again later." % e)
619-
if not file_exists: # Delete, only if file didn't exist before!
624+
error(u"Download of '%s' failed (Reason: %s)" % (destination, e))
625+
# Delete, only if file didn't exist before!
626+
if not file_exists:
620627
debug(u"object_get failed for '%s', deleting..." % (destination,))
621628
os.unlink(deunicodise(destination))
622-
ret = EX_PARTIAL
623-
if cfg.stop_on_error:
624-
ret = EX_DATAERR
625-
break
629+
if cfg.stop_on_error:
630+
error(u"Exiting now because of --stop-on-error")
631+
raise
632+
ret = EX_PARTIAL
626633
continue
627634
except S3Error as e:
635+
error(u"Download of '%s' failed (Reason: %s)" % (destination, e))
628636
if not file_exists: # Delete, only if file didn't exist before!
629637
debug(u"object_get failed for '%s', deleting..." % (destination,))
630638
os.unlink(deunicodise(destination))
@@ -644,7 +652,7 @@ def cmd_object_get(args):
644652
if Config().delete_after_fetch:
645653
s3.object_delete(uri)
646654
output(u"File '%s' removed after fetch" % (uri))
647-
return EX_OK
655+
return ret
648656

649657
def cmd_object_del(args):
650658
cfg = Config()
@@ -1742,11 +1750,11 @@ def cmd_sync_local2remote(args):
17421750
continue
17431751
except InvalidFileError as exc:
17441752
error(u"Upload of '%s' is not possible (Reason: %s)" % (item['full_name'], exc))
1745-
ret = EX_PARTIAL
17461753
if cfg.stop_on_error:
17471754
ret = EX_OSFILE
17481755
error(u"Exiting now because of --stop-on-error")
17491756
raise
1757+
ret = EX_PARTIAL
17501758
continue
17511759
speed_fmt = formatSize(response["speed"], human_readable = True, floating_point = True)
17521760
if not cfg.progress_meter:

0 commit comments

Comments
 (0)