libmpm

morphux C package management library
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/libmpm

commit 050af83d2edb5157e0120a5d58d2dececc79d681
parent 3b23c38718bae2726922bf5cd85dfd2e2b4a2807
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue, 18 Apr 2017 23:47:41 +0200

WIP(Packer): Read files content, replace chdir with getcwd

Diffstat:
Msrc/packer.c | 33+++++++++++++++++++++++++--------
Mtests/packer/right/srcs/Makefile | 2++
Mtests/packer/right/srcs/directory/something | 1+
Mtests/packer/right/srcs/main.c | 6++++++
4 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/src/packer.c b/src/packer.c @@ -526,6 +526,8 @@ static bool read_files_from_dir(const char *dir_name, mlist_t **files, mlist_t * } else { + file->file_size = mpm_get_file_size_from_fn(file->fn); + file->content = mpm_read_file_from_fn(file->fn); list_add((*files), file, sizeof(*file)); } free(file); @@ -543,26 +545,41 @@ static bool write_package_sources(FILE *fd, packer_t *ctx) { mlist_t *files_list = NULL; mlist_t *dirs = NULL; mlist_t *tmp = NULL; + char old_pwd[PATH_MAX]; + char *dir = NULL; assert(fd != NULL && ctx != NULL); + getcwd(old_pwd, sizeof(old_pwd)); + + /* If we can't get the current working directory, it's a fatal error */ + assert(old_pwd != NULL); + chdir(ctx->str); list_add(dirs, PACKER_SRC_DIR, sizeof(PACKER_SRC_DIR)); - char *dir = NULL; - list_for_each(dirs, tmp, dir) { - read_files_from_dir(dir, &files_list, &dirs); - printf("%s\n", dir); + if (read_files_from_dir(dir, &files_list, &dirs) == false) + goto error; } - list_free(files_list, packer_file_free); + list_free(dirs, NULL); - chdir("../../"); + packer_file_t *file; + list_for_each(files_list, tmp, file) { + printf("File: %s:\n'%s'\n", file->fn, file->content); + } + list_free(files_list, packer_file_free); + + chdir(old_pwd); return true; -/*error:*/ - /*return false;*/ +error: + list_free(files_list, packer_file_free); + list_free(dirs, NULL); + chdir(old_pwd); + + return false; } bool packer_create_archive(packer_t *ctx, const char *archive_path) { diff --git a/tests/packer/right/srcs/Makefile b/tests/packer/right/srcs/Makefile @@ -0,0 +1,2 @@ +all: + gcc main.c -o main diff --git a/tests/packer/right/srcs/directory/something b/tests/packer/right/srcs/directory/something @@ -0,0 +1 @@ +Somewhat diff --git a/tests/packer/right/srcs/main.c b/tests/packer/right/srcs/main.c @@ -0,0 +1,6 @@ +#include <stdio.h> + +int main(void) { + printf("Hello World !\n"); + return 0; +}