print >>sys.stderr, "arv-put: Resuming previous upload. Bypass with the --no-resume option."
self.report_progress(self.bytes_written, self.bytes_expected)
- def checkpoint_state(self):
- if self.cache is None:
- return
+ def cache_state(self):
state = self.dump_state()
# Transform attributes for serialization.
for attr, value in state.items():
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))
-
- # Copy file data to Keep.
- for path in args.paths:
- if os.path.isdir(path):
- writer.write_directory_tree(
- path, max_manifest_depth=args.max_manifest_depth)
- else:
- writer.start_new_stream()
- writer.write_file(path, args.filename or os.path.basename(path))
+ try:
+ writer = ArvPutCollectionWriter.from_cache(
+ resume_cache, reporter, expected_bytes_for(args.paths))
+
+ # Copy file data to Keep.
+ for path in args.paths:
+ if os.path.isdir(path):
+ writer.write_directory_tree(
+ path, max_manifest_depth=args.max_manifest_depth)
+ else:
+ writer.start_new_stream()
+ writer.write_file(path, args.filename or os.path.basename(path))
+ except (Exception, KeyboardInterrupt):
+ writer.cache_state()
+ raise
if args.stream:
print writer.manifest_text(),
def test_writer_caches(self):
cwriter = arv_put.ArvPutCollectionWriter(self.cache)
cwriter.write_file('/dev/null')
+ cwriter.cache_state()
self.assertTrue(self.cache.load())
self.assertEquals(". 0:0:null\n", cwriter.manifest_text())
cwriter = arv_put.ArvPutCollectionWriter(self.cache)
with self.make_test_file() as testfile:
cwriter.write_file(testfile.name, 'test')
+ cwriter.cache_state()
new_writer = arv_put.ArvPutCollectionWriter.from_cache(
self.cache)
self.assertEquals(
# These bytes are intentionally not valid UTF-8.
with self.make_test_file('\x00\x07\xe2') as testfile:
cwriter.write_file(testfile.name, 'test')
+ cwriter.cache_state()
new_writer = arv_put.ArvPutCollectionWriter.from_cache(
self.cache)
self.assertEquals(cwriter.manifest_text(), new_writer.manifest_text())
# Set up a writer with some flushed bytes.
cwriter.write_file(testfile.name, 'test')
cwriter.finish_current_stream()
- cwriter.checkpoint_state()
+ cwriter.cache_state()
# Restore a writer from that state and check its progress report.
# We're also checking that progress is reported immediately after
# resuming.