only commit on successful upload
This commit is contained in:
parent
d2ac206a70
commit
9b16728f2b
|
@ -12,7 +12,6 @@ from b2mirror.common import Result, results_ok
|
||||||
# import logging
|
# import logging
|
||||||
# logging.basicConfig(level=logging.INFO)
|
# logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
How it works:
|
How it works:
|
||||||
|
|
||||||
|
@ -79,7 +78,7 @@ class B2SyncManager(object):
|
||||||
tables = {
|
tables = {
|
||||||
"files": """
|
"files": """
|
||||||
CREATE TABLE `files` (
|
CREATE TABLE `files` (
|
||||||
`path` varchar(1024) PRIMARY KEY,
|
`path` varchar(4096) PRIMARY KEY,
|
||||||
`mtime` INTEGER,
|
`mtime` INTEGER,
|
||||||
`size` INTEGER,
|
`size` INTEGER,
|
||||||
`seen` BOOLEAN
|
`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
|
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
|
to see if the file has new content that should be uploaded or is untouched since the last sync
|
||||||
"""
|
"""
|
||||||
|
|
||||||
result = Result.failed
|
result = Result.failed
|
||||||
|
|
||||||
c = self.db.cursor()
|
c = self.db.cursor()
|
||||||
|
@ -149,9 +149,6 @@ class B2SyncManager(object):
|
||||||
|
|
||||||
if self.should_transfer(row, f):
|
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)
|
print("Uploading:", f.rel_path)
|
||||||
try:
|
try:
|
||||||
result = self.dest.put_file(f, purge_historics=row is not None)
|
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])
|
print("Unexpected error:", sys.exc_info()[0])
|
||||||
raise
|
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:
|
else:
|
||||||
c.execute("UPDATE 'files' SET seen=1 WHERE `path` = ?;", (f.rel_path,)).fetchone()
|
c.execute("UPDATE 'files' SET seen=1 WHERE `path` = ?;", (f.rel_path,)).fetchone()
|
||||||
#print("Skipping:", f.rel_path)
|
#print("Skipping:", f.rel_path)
|
||||||
|
|
|
@ -22,7 +22,7 @@ def main():
|
||||||
|
|
||||||
args = parser.parse_args()
|
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(
|
mirror.sync(
|
||||||
args.source,
|
args.source,
|
||||||
|
|
Loading…
Reference in New Issue