Share atomic media commits between downloads and backfill
This commit is contained in:
1 parent
90fab54a4a
commit
34959a9657
3 files changed
+4
-4
No files matched your search
+1
-1
@@ -1198,7 +1198,7 @@ void chat_media_backfill(struct UTUN_INSTANCE* inst) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int registered = media_index_register_downloaded_file(cc->db, &result, cc->my_node_id, ch_id, path, media_base);
|
||||
int registered = media_index_commit(cc->db, &result, cc->my_node_id, NULL, ch_id, path, media_base);
|
||||
if (!registered) total += result.num_blocks;
|
||||
else DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "media backfill registration failed ch=%s file=%s", ch_id, path);
|
||||
|
||||
|
||||
@@ -650,7 +650,7 @@ static int md_dl_register_servable(struct media_download* dl) {
|
||||
struct media_index_result result = { .file_size = dl->file_size, .block_size = dl->block_size,
|
||||
.num_blocks = dl->num_blocks, .block_ids = ids };
|
||||
memcpy(result.media_id, dl->media_id, 16); memcpy(result.content_hash, dl->content_hash, 32);
|
||||
int rc = media_index_register_downloaded_file(db, &result, inst->node_id, chat_id, dl->dest_path, dl->media_base);
|
||||
int rc = media_index_commit(db, &result, inst->node_id, NULL, chat_id, dl->dest_path, dl->media_base);
|
||||
u_free(ids); return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ static void transactions(void) {
|
||||
sql(db, "CREATE TRIGGER fail_second BEFORE INSERT ON media_files WHEN NEW.chunk=1 BEGIN SELECT RAISE(ABORT,'second'); END");
|
||||
assert(commit(db, "1", path) == -1 && scalar(db, "SELECT count(*) FROM media_files") == 0);
|
||||
assert(!sqlite3_get_autocommit(db) && scalar(db, "SELECT n FROM marker") == 42);
|
||||
assert(media_index_register_downloaded_file(db, &result, 1, "1", path, root) == -1);
|
||||
assert(media_index_commit(db, &result, 1, NULL, "1", path, root) == -1);
|
||||
assert(!scalar(db, "SELECT count(*) FROM media_files"));
|
||||
sql(db, "DROP TRIGGER fail_second");
|
||||
assert(!commit(db, "1", path) && scalar(db, "SELECT count(*) FROM media_files") == 2);
|
||||
@@ -116,7 +116,7 @@ static void transactions(void) {
|
||||
assert(commit(db, "1", path) == -1 && sqlite3_get_autocommit(db));
|
||||
sql(db, "DROP TRIGGER rollback_all");
|
||||
assert(!commit(db, "1", path) && !commit(db, "1", path));
|
||||
assert(!media_index_register_downloaded_file(db, &result, 1, "1", path, root));
|
||||
assert(!media_index_commit(db, &result, 1, NULL, "1", path, root));
|
||||
assert(scalar(db, "SELECT count(*) FROM media_files WHERE node_sign!=zeroblob(64)") == 2);
|
||||
assert(media_index_register_downloaded(db, result.media_id, ids, result.content_hash, "conflict", "wrong", 1, 14, 7, 0, 0) == -1);
|
||||
assert(scalar(db, "SELECT count(*) FROM media_files WHERE chat_id='1'") == 2);
|
||||
|
||||
Reference in new issue
Block a user