From 386ea85fea1fc20adaca2677a3213c076a48f4b1 Mon Sep 17 00:00:00 2001 From: evgeny Date: Thu, 22 Oct 2026 10:27:42 +0200 Subject: [PATCH] Log precise copy and media indexing failure operations --- src/media_async/media_async.c | 22 +++++++++++++++++----- src/media_delivery/media_index.c | 20 ++++++++++++++------ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/media_async/media_async.c b/src/media_async/media_async.c index f8b9e8ff..b9f5a792 100644 --- a/src/media_async/media_async.c +++ b/src/media_async/media_async.c @@ -41,6 +41,7 @@ static void ma_finish(struct ma_thread_ctx* job, int error) { while (*p && *p != job) p = &(*p)->next; if (*p) *p = job->next; pthread_join(job->thread, NULL); + DEBUG_DEBUG(DEBUG_CATEGORY_MEDIA, "media task completed job=%p error=%d remaining=%d", (void*)job, error, job->owner->jobs != NULL); job->done(job->arg, error); u_free(job); } @@ -110,6 +111,7 @@ void media_async_submit(struct media_async* ma, struct UASYNC* ua, u_free(job->completion); u_free(job); done(arg, -1); return; } job->next = ma->jobs; ma->jobs = job; + DEBUG_DEBUG(DEBUG_CATEGORY_MEDIA, "media task accepted job=%p pending=%u", (void*)job, active + 1); } /* Синхронный SHA256; результат не публикуется при ошибке чтения/close. */ @@ -165,14 +167,24 @@ int ma_copy_file(const char* source, const char* destination) { if (status == 0 && file_io_temp_open(&output, destination)) status = -1; if (status == 0) { uint8_t buffer[65536]; size_t count; - phase = "read/write"; - while ((count = fread(buffer, 1, sizeof(buffer), input)) > 0) { - if (fwrite(buffer, 1, count, output.file) != count) { status = -1; break; } + while (1) { + phase = "read source"; count = fread(buffer, 1, sizeof(buffer), input); + if (ferror(input)) { + DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "copy read failed path=%s errno=%d", source, errno); status = -1; break; + } + if (!count) break; + phase = "write temporary"; + if (fwrite(buffer, 1, count, output.file) != count) { + DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "copy write failed path=%s requested=%zu errno=%d", output.temporary, count, errno); + status = -1; break; + } total += count; } - if (ferror(input)) status = -1; } - if (fclose(input)) { phase = "close source"; status = -1; } + if (fclose(input)) { + DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "copy source close failed path=%s errno=%d", source, errno); + phase = "close source"; status = -1; + } if (status == 0) phase = "flush/close temporary"; if (status == 0 && file_io_temp_finish(&output)) status = -1; if (status == 0) phase = "publish"; diff --git a/src/media_delivery/media_index.c b/src/media_delivery/media_index.c index 3658d6a3..8ef15a13 100644 --- a/src/media_delivery/media_index.c +++ b/src/media_delivery/media_index.c @@ -279,12 +279,20 @@ static void mi_reg_work(void* data) { if (!buffer) goto done; phase = "seek"; ctx->err = -70; #ifdef _WIN32 - if (_fseeki64(file, offset, SEEK_SET)) goto done; + int seek_error = _fseeki64(file, offset, SEEK_SET); #else - if ((int64_t)(off_t)offset != offset || fseeko(file, (off_t)offset, SEEK_SET)) goto done; + int seek_error = (int64_t)(off_t)offset != offset || fseeko(file, (off_t)offset, SEEK_SET); #endif + if (seek_error) { + DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "media_index seek failed path=%s offset=%lld errno=%d", + ctx->dest_path, (long long)offset, errno); goto done; + } phase = "read"; - if (fread(buffer, 1, length, file) != length) goto done; + size_t received = fread(buffer, 1, length, file); + if (received != length) { + DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "media_index read failed path=%s offset=%lld wanted=%zu received=%zu error=%d", + ctx->dest_path, (long long)offset, length, received, ferror(file)); goto done; + } phase = "block UUID"; ctx->err = -81; if (ma_uuid(ctx->result.block_ids + (size_t)n * 16)) goto done; phase = "block signature"; ctx->err = -80; @@ -293,13 +301,13 @@ static void mi_reg_work(void* data) { } phase = "close"; ctx->err = -71; int close_error = fclose(file); file = NULL; - if (close_error) goto done; + if (close_error) { DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "media_index close failed path=%s errno=%d", ctx->dest_path, errno); goto done; } ctx->err = 0; DEBUG_DEBUG(DEBUG_CATEGORY_MEDIA, "media_index prepared path=%s bytes=%lld blocks=%d", ctx->dest_path, (long long)size, ctx->result.num_blocks); done: - if (ctx->err) DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "media_index preparation failed phase=%s path=%s error=%d errno=%d", - phase, ctx->dest_path, ctx->err, errno); + if (ctx->err) DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "media_index preparation failed phase=%s path=%s error=%d", + phase, ctx->dest_path, ctx->err); u_free(buffer); if (file && fclose(file)) DEBUG_WARN(DEBUG_CATEGORY_MEDIA, "media_index cleanup close failed path=%s errno=%d", ctx->dest_path, errno); }