only commit on successful upload

This commit is contained in:
Dave Pedu 2016-07-23 21:49:12 -07:00
parent d2ac206a70
commit 9b16728f2b
2 changed files with 6 additions and 6 deletions

View File

@ -12,7 +12,6 @@ from b2mirror.common import Result, results_ok
# import logging
# logging.basicConfig(level=logging.INFO)
"""
How it works:
@ -79,7 +78,7 @@ class B2SyncManager(object):
tables = {
"files": """
CREATE TABLE `files` (
`path` varchar(1024) PRIMARY KEY,
`path` varchar(4096) PRIMARY KEY,
`mtime` INTEGER,
`size` INTEGER,
`seen` BOOLEAN
@ -141,6 +140,7 @@ class B2SyncManager(object):
Future-called function that handles a single file. The file's modification time is checked against the database
to see if the file has new content that should be uploaded or is untouched since the last sync
"""
result = Result.failed
c = self.db.cursor()
@ -149,9 +149,6 @@ class B2SyncManager(object):
if self.should_transfer(row, f):
# The file was uploaded, commit it to the db
c.execute("REPLACE INTO 'files' VALUES(?, ?, ?, ?);", (f.rel_path, f.mtime, f.size, 1))
print("Uploading:", f.rel_path)
try:
result = self.dest.put_file(f, purge_historics=row is not None)
@ -160,6 +157,9 @@ class B2SyncManager(object):
print("Unexpected error:", sys.exc_info()[0])
raise
# The file was uploaded, commit it to the db
c.execute("REPLACE INTO 'files' VALUES(?, ?, ?, ?);", (f.rel_path, f.mtime, f.size, 1))
else:
c.execute("UPDATE 'files' SET seen=1 WHERE `path` = ?;", (f.rel_path,)).fetchone()
#print("Skipping:", f.rel_path)

View File

@ -22,7 +22,7 @@ def main():
args = parser.parse_args()
ignore_res = [re.compile(i) for i in args.exclude]
ignore_res = [re.compile(i) for i in args.exclude] if args.exclude else []
mirror.sync(
args.source,