Skip to content

Commit 207c21a

Browse files
Update archive.c
1 parent bffd012 commit 207c21a

File tree

1 file changed

+10
-39
lines changed

1 file changed

+10
-39
lines changed

code/logic/archive.c

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -329,49 +329,20 @@ fossil_io_archive_t* fossil_io_archive_create(const char *path, fossil_io_archiv
329329
// ======================================================
330330

331331
bool fossil_io_archive_get_stats(fossil_io_archive_t *archive, fossil_io_archive_stats_t *stats) {
332-
if (!archive || !stats)
333-
return false;
334-
335-
if (!archive->entries || archive->entry_count == 0) {
336-
// Handle empty archive safely
337-
stats->total_entries = 0;
338-
stats->total_size = 0;
339-
stats->compressed_size = 0;
340-
stats->compression_ratio = 0.0;
341-
return true;
342-
}
343-
344-
stats->total_entries = 0;
332+
if (!archive || !stats) return false;
333+
334+
stats->total_entries = archive->entry_count;
345335
stats->total_size = 0;
346336
stats->compressed_size = 0;
347-
348-
// Optional: track seen entry names or IDs to avoid duplicates
349-
// (requires unique identifier or path)
337+
350338
for (size_t i = 0; i < archive->entry_count; i++) {
351-
fossil_io_archive_entry_t *entry = &archive->entries[i];
352-
353-
if (!entry || !entry->name)
354-
continue; // skip invalid entries safely
355-
356-
// Skip duplicates by comparing with previous entries
357-
bool duplicate = false;
358-
for (size_t j = 0; j < i; j++) {
359-
if (archive->entries[j].name && strcmp(entry->name, archive->entries[j].name) == 0) {
360-
duplicate = true;
361-
break;
362-
}
363-
}
364-
if (duplicate)
365-
continue;
366-
367-
stats->total_entries++;
368-
stats->total_size += entry->size;
369-
stats->compressed_size += entry->compressed_size;
339+
stats->total_size += archive->entries[i].size;
340+
stats->compressed_size += archive->entries[i].compressed_size;
370341
}
371-
372-
stats->compression_ratio = stats->total_size > 0 ?
373-
(double)stats->compressed_size / (double)stats->total_size : 0.0;
374-
342+
343+
stats->compression_ratio = stats->total_size > 0 ?
344+
(double)stats->compressed_size / stats->total_size : 0.0;
345+
375346
return true;
376347
}
377348

0 commit comments

Comments
 (0)