download_file: Catch exceptions raised from shutil.copyfile

shutil.copyfile can raise shutil.Error and IOError.  Catch these and
exit with error status after logging the error to the console.

Change-Id: I63b8caa371cc7034bbb3f19d0bd3fdd0446af2bf
This commit is contained in:
David Pursehouse
2013-08-08 10:44:23 +09:00
parent 8ea0650c8c
commit e277fc3f74

View File

@@ -169,7 +169,11 @@ if args.exclude_java_sources:
safe_mkdirs(path.dirname(args.o))
if exclude:
shutil.copyfile(cache_ent, args.o)
try:
shutil.copyfile(cache_ent, args.o)
except (shutil.Error, IOError) as err:
print("error copying to %s: %s" % (args.o, err), file=stderr)
exit(1)
try:
check_call(['zip', '-d', args.o] + exclude)
except CalledProcessError as err:
@@ -179,4 +183,8 @@ else:
try:
link(cache_ent, args.o)
except OSError as err:
shutil.copyfile(cache_ent, args.o)
try:
shutil.copyfile(cache_ent, args.o)
except (shutil.Error, IOError) as err:
print("error copying to %s: %s" % (args.o, err), file=stderr)
exit(1)