diff --git a/src/chat/chat_attachment.c b/src/chat/chat_attachment.c index 9ff2251e..c12502d7 100644 --- a/src/chat/chat_attachment.c +++ b/src/chat/chat_attachment.c @@ -574,6 +574,12 @@ static void ak_recover_preparations(struct UTUN_INSTANCE* inst) { } sqlite3_free_table(paths); if (rows && !failed) { + const char* slash = strrchr(CC(inst)->db_path, '/'); + unsigned prefix = slash ? (unsigned)(slash - CC(inst)->db_path) : 1; + char cleanup[768]; + snprintf(cleanup, sizeof(cleanup), "DELETE FROM media_files WHERE chat_id='%s' AND location IN" + "(SELECT substr(a.cipher_path,%u) FROM attachment_keys a WHERE %s)", channel, prefix + 2, condition); + if (ak_exec(inst, cleanup)) continue; snprintf(sql, sizeof(sql), "DELETE FROM attachment_keys AS a WHERE %s", condition); if (!ak_exec(inst, sql)) DEBUG_INFO(DEBUG_CATEGORY_MEDIA, "attachment keys: discarded unpublished preparations channel=%s count=%d", channel, rows); } diff --git a/src/dm/dm_crypto.c b/src/dm/dm_crypto.c index f6d5e102..74f0e092 100644 --- a/src/dm/dm_crypto.c +++ b/src/dm/dm_crypto.c @@ -77,4 +77,3 @@ void dm_build_nonce(uint64_t conv_id, uint64_t author, uint64_t seq, uint8_t non SHA256_Final(hash, &ctx); memcpy(nonce, hash, DM_NONCE_SIZE); } -