aboutsummaryrefslogtreecommitdiff
path: root/src/file_processor.c
diff options
context:
space:
mode:
authorThorsten Töpper <atsutane@freethoughts.de>2026-02-18 22:59:41 +0100
committerThorsten Töpper <atsutane@freethoughts.de>2026-02-18 22:59:41 +0100
commit6dbce994b660c3bcf587b0b8b45680b1e6b7ba69 (patch)
treeaf068aaef1520d667cb1134d85329907e77fdcd0 /src/file_processor.c
parent0ecbd06d797d805092c80253c299e963c391ccbf (diff)
downloadduplicate_finder-6dbce994b660c3bcf587b0b8b45680b1e6b7ba69.tar.gz
duplicate_finder-6dbce994b660c3bcf587b0b8b45680b1e6b7ba69.tar.bz2
file_processor: fix and additional debug output
Diffstat (limited to 'src/file_processor.c')
-rw-r--r--src/file_processor.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/file_processor.c b/src/file_processor.c
index f4f9d05..d3f2196 100644
--- a/src/file_processor.c
+++ b/src/file_processor.c
@@ -59,7 +59,7 @@ const EVP_MD *glbl_md_sha512 = NULL;
/*=========== FUNCTIONS ===========*/
struct df_md_components *init_md_components();
void destroy_md_components(struct df_md_components *pkg);
-
+void print_fileinfo(struct df_fileinfo *info);
/**
* Prepare a df_md_components struct for active usage.
@@ -299,7 +299,7 @@ int process_file(struct df_fileinfo *info) {
struct df_fileinfo *prepare_fileinfo(char *key) {
char *tmp;
char *fname = NULL;
- size_t plen=0;
+ size_t plen=0, flen=0;
struct df_fileinfo *info = NULL;
if (key == NULL || key[0] == '\0') {
@@ -313,6 +313,7 @@ struct df_fileinfo *prepare_fileinfo(char *key) {
/* At this point the address of fname will always be equal or larger than keys */
plen = (size_t) (fname - key);
fname++; /* drop the / */
+ flen = strlen(fname);
if ((info=calloc(1, sizeof(struct df_fileinfo))) == NULL) {
return NULL;
@@ -325,14 +326,17 @@ struct df_fileinfo *prepare_fileinfo(char *key) {
memcpy(tmp, key, plen);
info->path = tmp;
- if ((tmp = calloc(strlen(fname)+1, sizeof(char))) == NULL) {
+ if ((tmp = calloc(flen+1, sizeof(char))) == NULL) {
free(info->path);
free(info);
return NULL;
}
- memcpy(tmp, fname, plen);
+ memcpy(tmp, fname, flen);
info->name = tmp;
+ DBGTRC("DEBUG: key '%s' | fname '%s' | info->path '%s' | info->name '%s'\n",
+ key, fname, info->path, info->name);
+
return info;
}
@@ -350,8 +354,12 @@ int process_gdbm_content() {
key = kv_first_key();
while (key != NULL) {
+ DBGTRC("DEBUG: key '%s' | value '%c%c'\n", key, kv_get_type(key),
+ (kv_get_bool(key)) ? 'T' : 'F'); /* would require DEBUG block for raw data */
+
/* file? already processed? */
if (kv_get_type(key) == 'D' || kv_get_bool(key)) {
+ DBGTRC("DEBUG: Skip\n");
tmpkey = key;
key = kv_next_key(tmpkey);
free(tmpkey);
@@ -364,18 +372,24 @@ int process_gdbm_content() {
return -1;
}
if (process_file(info) < 0) {
+ LOGERR("ERROR: Failed to process file %s\n", key);
free(info->path);
free(info->name);
free(info);
+ free(key);
return -1;
}
+#ifdef DEBUGBUILD
+ print_fileinfo(info);
+#endif
dbrc = dbi_insert_fileinfo(info);
free(info->path);
free(info->name);
free(info);
if (dbrc < 0) {
LOGERR("ERROR: Aborting after database error.\n");
+ free(key);
return -1;
}
@@ -390,3 +404,12 @@ int process_gdbm_content() {
return 0;
}
+inline void print_fileinfo(struct df_fileinfo *info) {
+ fprintf(stderr, "info->path = \"%s\"\n", info->path);
+ fprintf(stderr, "info->name = \"%s\"\n", info->name);
+ fprintf(stderr, "info->hashes.blake2 = \"%s\"\n", info->hashes.blake2);
+ fprintf(stderr, "info->hashes.sha256 = \"%s\"\n", info->hashes.sha256);
+ fprintf(stderr, "info->hashes.sha512 = \"%s\"\n", info->hashes.sha512);
+ fprintf(stderr, "info->statbuf.st_size = \"%ld\"\n", info->statbuf.st_size);
+}
+