Rewriting hash_worker() to export file_hashes.txt

This commit is contained in:
2026-03-07 11:54:13 +01:00
parent 417dbad374
commit b5667e0463
3 changed files with 50 additions and 3 deletions

View File

@@ -408,19 +408,64 @@ static void xxh3_hash_file_stream(const char *path, char *out_hex) {
}
// ------------------------- Hash worker --------------------------------
// Functions without writing to disk
// static DWORD WINAPI hash_worker(LPVOID arg) {
// MPMCQueue *q = (MPMCQueue *)arg;
//
// for (;;) {
//
// FileEntry *fe = mpmc_pop(q);
//
// if (!fe)
// break; // poison pill
//
// char hash[HASH_STRLEN];
// xxh3_hash_file_stream(fe->path, hash);
//
// atomic_fetch_add(&g_files_hashed, 1);
//
// free(fe->path);
// free(fe);
// }
//
// return 0;
// }
static DWORD WINAPI hash_worker(LPVOID arg) {
MPMCQueue *q = (MPMCQueue *)arg;
static CRITICAL_SECTION append_cs;
static LONG init = 0;
if (InterlockedCompareExchange(&init, 1, 0) == 0) {
InitializeCriticalSection(&append_cs);
}
for (;;) {
FileEntry *fe = mpmc_pop(q);
if (!fe)
break; // poison pill
break;
char hash[HASH_STRLEN];
xxh3_hash_file_stream(fe->path, hash);
char created[32], modified[32];
format_time(fe->created_time, created, sizeof(created));
format_time(fe->modified_time, modified, sizeof(modified));
double size_kib = (double)fe->size_bytes / 1024.0;
EnterCriticalSection(&append_cs);
FILE *hf = fopen(FILE_HASHES_TXT, "a");
if (hf) {
fprintf(hf, "%s\t%s\t%.2f\t%s\t%s\t%s\n", hash, fe->path, size_kib,
created, modified, fe->owner);
fclose(hf);
}
LeaveCriticalSection(&append_cs);
atomic_fetch_add(&g_files_hashed, 1);
free(fe->path);