sys.exit(-sigcode)
def main(arguments=None):
- ResumeCache.setup_user_cache()
args = parse_arguments(arguments)
if args.progress:
reporter = progress_writer(machine_progress)
else:
reporter = None
+ bytes_expected = expected_bytes_for(args.paths)
try:
+ ResumeCache.setup_user_cache()
resume_cache = ResumeCache(ResumeCache.make_path(args))
- if not args.resume:
- resume_cache.restart()
+ except (IOError, OSError):
+ # Couldn't open cache directory/file. Continue without it.
+ resume_cache = None
+ writer = ArvPutCollectionWriter(resume_cache, reporter, bytes_expected)
except ResumeCacheConflict:
print "arv-put: Another process is already uploading this data."
sys.exit(1)
-
- writer = ArvPutCollectionWriter.from_cache(
- resume_cache, reporter, expected_bytes_for(args.paths))
+ else:
+ if not args.resume:
+ resume_cache.restart()
+ writer = ArvPutCollectionWriter.from_cache(
+ resume_cache, reporter, bytes_expected)
# Install our signal handler for each code in CAUGHT_SIGNALS, and save
# the originals.
for sigcode, orig_handler in orig_signal_handlers.items():
signal.signal(sigcode, orig_handler)
- resume_cache.destroy()
+ if resume_cache is not None:
+ resume_cache.destroy()
if __name__ == '__main__':
main()
class ArvadosPutTest(ArvadosKeepLocalStoreTestCase):
- def test_simple_file_put(self):
+ def call_main_on_test_file(self):
with self.make_test_file() as testfile:
path = testfile.name
arv_put.main(['--stream', '--no-progress', path])
'098f6bcd4621d373cade4e832627b4f6')),
"did not find file stream in Keep store")
+ def test_simple_file_put(self):
+ self.call_main_on_test_file()
+
+ def test_put_with_unwriteable_cache_dir(self):
+ orig_cachedir = arv_put.ResumeCache.CACHE_DIR
+ cachedir = self.make_tmpdir()
+ os.chmod(cachedir, 0o0)
+ arv_put.ResumeCache.CACHE_DIR = cachedir
+ try:
+ self.call_main_on_test_file()
+ finally:
+ arv_put.ResumeCache.CACHE_DIR = orig_cachedir
+ os.chmod(cachedir, 0o700)
+
+ def test_put_with_unwritable_cache_subdir(self):
+ orig_cachedir = arv_put.ResumeCache.CACHE_DIR
+ cachedir = self.make_tmpdir()
+ os.chmod(cachedir, 0o0)
+ arv_put.ResumeCache.CACHE_DIR = os.path.join(cachedir, 'cachedir')
+ try:
+ self.call_main_on_test_file()
+ finally:
+ arv_put.ResumeCache.CACHE_DIR = orig_cachedir
+ os.chmod(cachedir, 0o700)
+
def test_short_put_from_stdin(self):
# Have to run this separately since arv-put can't read from the
# tests' stdin.