core: Add files to blob list on scan

Signed-off-by: Chloe M. <chloe@mirocom.org>
This commit is contained in:
2026-04-30 21:12:13 -04:00
parent d991988fd8
commit 1d4bb8769a
5 changed files with 82 additions and 3 deletions
+31 -3
View File
@@ -12,6 +12,7 @@
#include <dirent.h>
#include "blobchain/common.h"
#include "blobchain/stream.h"
#include "blobchain/blob.h"
/* Input directory path */
static char *input_dir = NULL;
@@ -32,11 +33,13 @@ version(void)
}
static void
pack_foreach(const char *input_dir)
pack_foreach(struct blob_list *blobs, const char *input_dir)
{
struct data_stream stream;
char pathbuf[512];
struct dirent *dirent;
DIR *dir;
int error;
if (input_dir == NULL) {
return;
@@ -55,12 +58,27 @@ pack_foreach(const char *input_dir)
switch (dirent->d_type) {
case DT_DIR:
snprintf(pathbuf, sizeof(pathbuf), "%s/%s", input_dir, dirent->d_name);
pack_foreach(pathbuf);
pack_foreach(blobs, pathbuf);
printf("[d] %s\n", pathbuf);
break;
case DT_REG:
snprintf(pathbuf, sizeof(pathbuf), "%s/%s", input_dir, dirent->d_name);
printf("[r] %s\n", pathbuf);
error = stream_from_file(&stream, pathbuf);
if (error < 0) {
printf("fatal: could not create stream from '%s'\n", pathbuf);
return;
}
error = blob_list_append(blobs, blob_allocate(&stream));
if (error < 0) {
printf("fatal: failed to append blob '%s'\n", pathbuf);
stream_destroy(&stream);
continue;
}
stream_destroy(&stream);
break;
}
}
@@ -70,6 +88,7 @@ static void
pack_dir(void)
{
struct stat sb;
struct blob_list blobs;
if (stat(input_dir, &sb) < 0) {
perror("stat");
@@ -82,7 +101,16 @@ pack_dir(void)
return;
}
pack_foreach(input_dir);
if (blob_list_init(&blobs) < 0) {
printf("fatal: failed to initialize blob list...\n");
return;
}
pack_foreach(&blobs, input_dir);
#if BLOBCHAIN_DEBUG
blob_list_dump(&blobs);
#endif /* BLOBCHAIN_DEBUG */
blob_list_destroy(&blobs);
}
int