libmpm

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

commit 461e61639e797ab9981b6041435d454b31d5d982
parent 05ac6a8399dd68299019e553cc43e7c992a06552
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Sun, 28 May 2017 14:47:04 +0200

Add(Packer): Add rights (mode_t) in the file archive

Diffstat:
Minc/packer_file.h | 1+
Msrc/packer.c | 1+
Msrc/packer_file.c | 15+++++++++++++--
Mtests/packer/ncurses/package.json | 1-
Mtests/test_compile.c | 2+-
5 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/inc/packer_file.h b/inc/packer_file.h @@ -27,6 +27,7 @@ typedef struct packer_file_s { char *fn; /*!< Filename, with relative path (Ex: srcs/main.c ) */ off_t file_size; /*!< File size, in bytes */ off_t compressed_size; /*!< Compression size, in bytes */ + mode_t mode; /*!< Mode / Rights on the file (st_mode) */ char sum[crypto_hash_sha256_BYTES]; /*!< Sha256sum of the file */ char *content; /*!< Actual content of the file */ } packer_file_t; diff --git a/src/packer.c b/src/packer.c @@ -561,6 +561,7 @@ MPX_STATIC bool write_packer_sources(FILE *fd, packer_t *ctx, const char *dir_na list_for_each(files_list, tmp2, file) { fprintf(fd, "%s%c", file->fn, 0); + fwrite(&file->mode, sizeof(file->mode), 1, fd); fwrite(&file->compressed_size, sizeof(file->compressed_size), 1, fd); fwrite(&file->file_size, sizeof(file->file_size), 1, fd); if (file->file_size != 0) diff --git a/src/packer_file.c b/src/packer_file.c @@ -112,11 +112,15 @@ error: bool get_file_information(packer_file_t *file) { z_stream stream; + struct stat f_stat; char *file_content = NULL; char *chunk = NULL; off_t file_size; - file_size = mpm_get_file_size_from_fn(file->fn); + if (stat(file->fn, &f_stat) == -1) + return false; + + file_size = f_stat.st_size; file_content = mpm_read_file_from_fn(file->fn); if (file_content == NULL) { @@ -161,6 +165,7 @@ bool get_file_information(packer_file_t *file) { memcpy(file->content, chunk, file->compressed_size); file->file_size = file_size; + file->mode = f_stat.st_mode; free(file_content); free(chunk); @@ -208,6 +213,10 @@ bool packer_file_from_binary_to_disk(const char *content, off_t *ctr) { *ctr += strlen(file.fn) + 1; + /* File mode */ + memcpy(&file.mode, content + *ctr, sizeof(file.mode)); + *ctr += sizeof(file.mode); + /* File content size */ memcpy(&file.compressed_size, content + *ctr, sizeof(file.compressed_size)); *ctr += sizeof(file.compressed_size); @@ -246,7 +255,9 @@ bool packer_file_from_binary_to_disk(const char *content, off_t *ctr) { inflateEnd(&stream); } - status = true; + /* Set the rights */ + if (fchmod(fd->_fileno, file.mode) != -1) + status = true; cleanup: fclose(fd); diff --git a/tests/packer/ncurses/package.json b/tests/packer/ncurses/package.json @@ -15,7 +15,6 @@ ], "make": "", "test": "", - "install": "all", "env": [ {"CPPFLAGS": "-P"} ] diff --git a/tests/test_compile.c b/tests/test_compile.c @@ -27,7 +27,7 @@ TEST(configure_package) { TEST_ASSERT(patch_package(ptr) == true, "An error happened"); TEST_ASSERT(configure_package(ptr) == true, "An error happened"); TEST_ASSERT(make_package(ptr) == true, "An error happened"); - /*TEST_ASSERT(install_package(ptr) == true, "An error happened");*/ + TEST_ASSERT(install_package(ptr) == true, "An error happened"); TEST_ASSERT(after_package(ptr) == true, "An error happened"); TEST_ASSERT(package_install_cleanup(ptr) == true, "An error happened");