fix: list archive extraction and package creation errors
This commit is contained in:
parent
3b19e2840b
commit
ed52710355
@ -1,8 +1,8 @@
|
||||
CC = gcc
|
||||
|
||||
all: ../dist/example_pool ../dist/example_server
|
||||
all: ../dist/example_client ../dist/example_server
|
||||
|
||||
../dist/example_pool: pool/*.c ../dist/libmp.so
|
||||
../dist/example_client: client/*.c ../dist/libmp.so
|
||||
mkdir -pv ../dist
|
||||
$(CC) -L../dist $< -lmp -o $@
|
||||
|
||||
|
@ -20,11 +20,16 @@ int main(int argc, char *argv[]) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!lm_pool_info_load(pool, "./examples/tests/pool/INFO")) {
|
||||
if (!lm_pool_info_load(pool, "./examples/tests/INFO")) {
|
||||
printf("failed to load pool info: %s (%d)\n", lm_strerror(), lm_error());
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!lm_pool_list_load(pool, "./examples/tests/LIST")) {
|
||||
printf("failed to load pool list: %s (%d)\n", lm_strerror(), lm_error());
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!lm_ctx_pools_serve(&ctx, argv[1], 10)) {
|
||||
printf("failed to serve the pools: %s (%d)\n", lm_strerror(), lm_error());
|
||||
goto end;
|
||||
|
1
examples/tests/.gitignore
vendored
Normal file
1
examples/tests/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
LIST_extracted
|
@ -1,4 +1,4 @@
|
||||
[base]
|
||||
size = 314073
|
||||
size = 314121
|
||||
maintainer = ngn
|
||||
pubkey = F9E70878C2FB389AEC2BA34CA3654DF5AD9F641D
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -39,23 +39,25 @@ typedef enum lm_error {
|
||||
LM_ERR_ArcOpenFail = 35,
|
||||
LM_ERR_ArcWHeaderFail = 36,
|
||||
LM_ERR_ArcWEntryFail = 37,
|
||||
LM_ERR_GetCwdFail = 38,
|
||||
LM_ERR_PoolListDirFail = 39,
|
||||
LM_ERR_PoolListCantRead = 40,
|
||||
LM_ERR_PoolInfoCantRead = 41,
|
||||
LM_ERR_PkgBadName = 42,
|
||||
LM_ERR_PkgDataBad = 43,
|
||||
LM_ERR_CtxDataNULL = 44,
|
||||
LM_ERR_CtxTempFail = 45,
|
||||
LM_ERR_CtxTempNotDir = 46,
|
||||
LM_ERR_CtxTempNoWrite = 47,
|
||||
LM_ERR_CtxRootFail = 48,
|
||||
LM_ERR_CtxRootNotDir = 49,
|
||||
LM_ERR_CtxRootNoWrite = 50,
|
||||
LM_ERR_CtxDataNotDir = 51,
|
||||
LM_ERR_CtxDataNoWrite = 52,
|
||||
LM_ERR_CtxDataFailMkdir = 53,
|
||||
|
||||
LM_ERR_ArcNewFail = 38,
|
||||
LM_ERR_ArcNextHeaderFail = 39,
|
||||
LM_ERR_GetCwdFail = 39,
|
||||
LM_ERR_PoolListDirFail = 40,
|
||||
LM_ERR_PoolListCantRead = 41,
|
||||
LM_ERR_PoolInfoCantRead = 42,
|
||||
LM_ERR_PkgBadName = 43,
|
||||
LM_ERR_PkgDataBad = 44,
|
||||
LM_ERR_CtxDataNULL = 45,
|
||||
LM_ERR_CtxTempFail = 46,
|
||||
LM_ERR_CtxTempNotDir = 47,
|
||||
LM_ERR_CtxTempNoWrite = 48,
|
||||
LM_ERR_CtxRootFail = 49,
|
||||
LM_ERR_CtxRootNotDir = 50,
|
||||
LM_ERR_CtxRootNoWrite = 51,
|
||||
LM_ERR_CtxDataNotDir = 52,
|
||||
LM_ERR_CtxDataNoWrite = 53,
|
||||
LM_ERR_CtxDataFailMkdir = 54,
|
||||
LM_ERR_ArcRealpathFail = 55,
|
||||
} lm_error_t;
|
||||
|
||||
typedef struct lm_error_desc {
|
||||
|
@ -4,12 +4,12 @@
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct lm_pkg {
|
||||
size_t size;
|
||||
struct lm_pkg *next;
|
||||
char *name;
|
||||
char *desc;
|
||||
char **depends;
|
||||
char *version;
|
||||
size_t size;
|
||||
} lm_pkg_t;
|
||||
|
||||
typedef struct lm_pool_info {
|
||||
|
@ -8,7 +8,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2024-06-28 20:24+0300\n"
|
||||
"POT-Creation-Date: 2024-06-28 21:45+0300\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@ -176,66 +176,78 @@ msgid "failed to finish writing the archive entry"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:51
|
||||
msgid "failed to obtain current working directory"
|
||||
msgid "failed to create new archive reader/writer"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:52
|
||||
msgid "failed to open extracted pool list directory"
|
||||
msgid "failed to resolve full path for archive file"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:53
|
||||
msgid "failed to read access the pool list file"
|
||||
msgid "failed to read the next header of the archive"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:54
|
||||
msgid "failed to read access the pool info file"
|
||||
msgid "failed to obtain current working directory"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:55
|
||||
msgid "failed to parse package data"
|
||||
msgid "failed to open extracted pool list directory"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:56
|
||||
msgid "failed to read access the pool list file"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:57
|
||||
msgid "failed to read access the pool info file"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:58
|
||||
msgid "failed to parse package data"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:59
|
||||
#, fuzzy
|
||||
msgid "package name is invalid"
|
||||
msgstr "URL hostname is too large"
|
||||
|
||||
#: src/error.c:57
|
||||
#: src/error.c:60
|
||||
msgid "data path is not set with in the ctx"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:58
|
||||
#: src/error.c:61
|
||||
msgid "specified temp path does not exist"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:59
|
||||
#: src/error.c:62
|
||||
msgid "specified temp path is not a directory"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:60
|
||||
#: src/error.c:63
|
||||
msgid "specified temp directory does not have write access"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:61
|
||||
#: src/error.c:64
|
||||
msgid "specified root path does not exist"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:62
|
||||
#: src/error.c:65
|
||||
msgid "specified root path is not a directory"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:63
|
||||
#: src/error.c:66
|
||||
msgid "specified root directory does not have write access"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:64
|
||||
#: src/error.c:67
|
||||
msgid "specified data path does not exist"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:65
|
||||
#: src/error.c:68
|
||||
msgid "specified data path is not a directory"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:66
|
||||
#: src/error.c:69
|
||||
msgid "failed to create specified data directory"
|
||||
msgstr ""
|
||||
|
@ -48,6 +48,9 @@ char *lm_strerror() {
|
||||
{.code = LM_ERR_ArcOpenFail, .desc = _("failed to open archive") },
|
||||
{.code = LM_ERR_ArcWHeaderFail, .desc = _("failed to write archive header") },
|
||||
{.code = LM_ERR_ArcWEntryFail, .desc = _("failed to finish writing the archive entry") },
|
||||
{.code = LM_ERR_ArcNewFail, .desc = _("failed to create new archive reader/writer") },
|
||||
{.code = LM_ERR_ArcRealpathFail, .desc = _("failed to resolve full path for archive file") },
|
||||
{.code = LM_ERR_ArcNextHeaderFail, .desc = _("failed to read the next header of the archive") },
|
||||
{.code = LM_ERR_GetCwdFail, .desc = _("failed to obtain current working directory") },
|
||||
{.code = LM_ERR_PoolListDirFail, .desc = _("failed to open extracted pool list directory") },
|
||||
{.code = LM_ERR_PoolListCantRead, .desc = _("failed to read access the pool list file") },
|
||||
|
@ -25,7 +25,7 @@ bool lm_pkg_data_depend_add(lm_pkg_t *pkg, char *depend){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(is_pkg_name_valid(depend)){
|
||||
if(!is_pkg_name_valid(depend)){
|
||||
lm_error_set(LM_ERR_PkgBadName);
|
||||
return false;
|
||||
}
|
||||
@ -89,6 +89,9 @@ void lm_pkg_data_free(lm_pkg_t *pkg){
|
||||
free(pkg->desc);
|
||||
free(pkg->name);
|
||||
free(pkg->version);
|
||||
|
||||
if(NULL != pkg->depends){
|
||||
for(int i = 0; pkg->depends[i] != NULL; i++)
|
||||
free(pkg->depends[i]);
|
||||
}
|
||||
}
|
||||
|
@ -29,11 +29,13 @@ bool lm_pool_list_load(lm_pool_t *pool, char *file){
|
||||
memcpy(file_copy2, file, file_len+1);
|
||||
|
||||
list_dir = dirname(file_copy);
|
||||
list_name = dirname(file_copy2);
|
||||
list_name = basename(file_copy2);
|
||||
|
||||
char extract_dir[file_len+15];
|
||||
snprintf(extract_dir, sizeof(extract_dir), "%s/%s_extracted", list_dir, list_name);
|
||||
|
||||
pdebug(__func__, "extracting pool to %s", extract_dir);
|
||||
|
||||
if(!mkdir_ifnot(extract_dir)){
|
||||
lm_error_set(LM_ERR_PoolListDirFail);
|
||||
return false;
|
||||
@ -53,24 +55,32 @@ bool lm_pool_list_load(lm_pool_t *pool, char *file){
|
||||
}
|
||||
|
||||
while((ent = readdir(dirfd)) != NULL){
|
||||
ent_len = strlen(ent->d_name);
|
||||
if(eq(ent->d_name, "..") || eq(ent->d_name, "."))
|
||||
continue;
|
||||
|
||||
ent_len = strlen(ent->d_name);
|
||||
char datap[ent_len+sizeof(extract_dir)+10];
|
||||
snprintf(datap, sizeof(datap), "%s/%s/DATA", extract_dir, ent->d_name);
|
||||
|
||||
lm_pkg_t *pkg = lm_pkg_new();
|
||||
|
||||
if(!lm_pkg_data_load(pkg, datap)){
|
||||
pdebug(__func__, "(%s) failed to load new package from %s", pool->name, datap);
|
||||
lm_pkg_free(pkg);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!lm_pool_add(pool, pkg)){
|
||||
pdebug(__func__, "(%s) failed to add new package: %s", pool->name, pkg->name);
|
||||
lm_pkg_free(pkg);
|
||||
continue;
|
||||
}
|
||||
|
||||
pdebug(__func__, "(%s) added new package: %s", pool->name, pkg->name);
|
||||
}
|
||||
|
||||
ret = true;
|
||||
|
||||
end:
|
||||
if(NULL != dirfd)
|
||||
closedir(dirfd);
|
||||
|
24
src/util.c
24
src/util.c
@ -131,6 +131,12 @@ bool extract_archive(char *dst, char *src) {
|
||||
int flags = 0, rc = 0;
|
||||
char *oldpwd = NULL;
|
||||
bool ret = false;
|
||||
char srcfull[PATH_MAX + 1];
|
||||
|
||||
if (NULL == realpath(src, srcfull)) {
|
||||
lm_error_set(LM_ERR_ArcRealpathFail);
|
||||
goto end;
|
||||
}
|
||||
|
||||
oldpwd = getcwd(NULL, 0);
|
||||
if (NULL == oldpwd) {
|
||||
@ -144,7 +150,12 @@ bool extract_archive(char *dst, char *src) {
|
||||
flags |= ARCHIVE_EXTRACT_UNLINK;
|
||||
|
||||
reader = archive_read_new();
|
||||
writer = archive_write_new();
|
||||
writer = archive_write_disk_new();
|
||||
|
||||
if (NULL == reader || NULL == writer) {
|
||||
lm_error_set(LM_ERR_ArcNewFail);
|
||||
goto end;
|
||||
}
|
||||
|
||||
archive_write_disk_set_options(writer, flags);
|
||||
archive_write_disk_set_standard_lookup(writer);
|
||||
@ -152,7 +163,7 @@ bool extract_archive(char *dst, char *src) {
|
||||
archive_read_support_format_tar(reader);
|
||||
archive_read_support_filter_gzip(reader);
|
||||
|
||||
if (archive_read_open_filename(reader, src, 1024 * 10) != ARCHIVE_OK) {
|
||||
if (archive_read_open_filename(reader, srcfull, 1024 * 10) != ARCHIVE_OK) {
|
||||
lm_error_set(LM_ERR_ArcOpenFail);
|
||||
goto end;
|
||||
}
|
||||
@ -174,6 +185,11 @@ bool extract_archive(char *dst, char *src) {
|
||||
}
|
||||
}
|
||||
|
||||
if (rc != ARCHIVE_EOF) {
|
||||
lm_error_set(LM_ERR_ArcNextHeaderFail);
|
||||
goto end;
|
||||
}
|
||||
|
||||
ret = true;
|
||||
|
||||
end:
|
||||
@ -183,8 +199,8 @@ end:
|
||||
}
|
||||
|
||||
if (NULL != writer) {
|
||||
archive_write_close(reader);
|
||||
archive_write_free(reader);
|
||||
archive_write_close(writer);
|
||||
archive_write_free(writer);
|
||||
}
|
||||
|
||||
if (NULL != oldpwd) {
|
||||
|
Loading…
Reference in New Issue
Block a user