Use canonical media base throughout attachment recovery

This commit is contained in:
evgeny committed 2026-10-24 14:51:32 +02:00
1 parent 6bf6d99b9c
commit be0bd224fa
2 files changed
+7 -3

No files matched your search

+3 -2
View File
@@ -595,6 +595,8 @@ static void ak_recover_temps(struct UTUN_INSTANCE* inst) {
* Вызывается до запуска workers либо после их полного завершения. */
static void ak_recover_preparations(struct UTUN_INSTANCE* inst) {
ak_recover_temps(inst);
char base[MEDIA_BASE_MAX];
if (media_index_get_base(CC(inst)->db, base)) return;
char** channels = NULL; int count = 0, columns = 0;
if (sqlite3_get_table(CC(inst)->db, "SELECT channel_id FROM channels", &channels, &count, &columns, NULL) != SQLITE_OK) {
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "attachment keys: recovery channel scan failed: %s", sqlite3_errmsg(CC(inst)->db)); return;
@@ -621,8 +623,7 @@ 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;
unsigned prefix = (unsigned)strlen(base);
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);
+4 -1
View File
@@ -122,7 +122,7 @@ int main(void) {
snprintf(cancelled_cipher, sizeof(cancelled_cipher), "%s", sqlite3_column_text(paths, 0));
snprintf(cancelled_plain, sizeof(cancelled_plain), "%s", sqlite3_column_text(paths, 1)); sqlite3_finalize(paths);
#ifdef __linux__
pthread_barrier_wait(&prepared_barrier); REQUIRE(!pthread_barrier_destroy(&prepared_barrier));
pthread_barrier_wait(&prepared_barrier);
REQUIRE(ma_file_size(cancelled_cipher) > 0 && ma_file_size(cancelled_plain) == 1);
#endif
req = u_calloc(1, sizeof(*req)); REQUIRE(req);
@@ -131,6 +131,9 @@ int main(void) {
req->pcm = test.pcm; req->pcm_count = 48000; req->pcm_owner = &test; req->pcm_release = release_pcm;
attachment_send_trampoline(req);
chat_service_stop(inst);
#ifdef __linux__
REQUIRE(!pthread_barrier_destroy(&prepared_barrier));
#endif
REQUIRE(test.released == 2 && test.failed == 1 && count(inst) == 1);
sqlite3_stmt* cancelled_key = NULL;
REQUIRE(!sqlite3_prepare_v2(inst->topo_sqlite_db, "SELECT count(*) FROM attachment_keys", -1, &cancelled_key, NULL));