new: custom pool dirs and remove ctx path functions

This commit is contained in:
ngn 2024-08-03 22:23:32 +03:00
parent 960596ae3a
commit 7c3d0dc1f8
35 changed files with 346 additions and 356 deletions

View File

@ -47,13 +47,14 @@ locale/libmp.pot: $(SRCS)
xgettext -k_ -c $^ -o $@
install:
install -m755 dist/libmp.so $(DESTDIR)/$(PREFIX)/lib/libmp.so
mkdir -pv $(DESTDIR)/$(PREFIX)/include/libmp
cp $(HDRS) $(DESTDIR)/usr/include/libmp
install -m755 dist/libmp.so $(DESTDIR)/$(PREFIX)/lib/libmp.so
install -dm755 $(DESTDIR)/$(PREFIX)/include/libmp
install -m644 $(HDRS) $(DESTDIR)/usr/include/libmp
rm $(DESTDIR)/usr/include/libmp/util.h
@for po in $(PO_DIRS) ; do \
echo "installing locale: $$po/libmp.mo" ; \
mkdir -pv $(DESTDIR)/$(PREFIX)/share/$$po ; \
cp $$po/libmp.mo $(DESTDIR)/$(PREFIX)/share/$$po ; \
install -dm755 $(DESTDIR)/$(PREFIX)/share/$$po ; \
install -m644 $$po/libmp.mo $(DESTDIR)/$(PREFIX)/share/$$po ; \
done
uninstall:

View File

@ -2,23 +2,23 @@ CC = gcc
all: ../dist/client_install ../dist/client_remove ../dist/client_update ../dist/client_check ../dist/client_list ../dist/server
../dist/client_install: client/install.c client/*.h ../dist/libmp.so
../dist/client_install: client/install.c ../dist/libmp.so
mkdir -pv ../dist
$(CC) -L../dist $< -lmp -o $@
../dist/client_remove: client/remove.c client/*.h ../dist/libmp.so
../dist/client_remove: client/remove.c ../dist/libmp.so
mkdir -pv ../dist
$(CC) -L../dist $< -lmp -o $@
../dist/client_update: client/update.c client/*.h ../dist/libmp.so
../dist/client_update: client/update.c ../dist/libmp.so
mkdir -pv ../dist
$(CC) -L../dist $< -lmp -o $@
../dist/client_check: client/check.c client/*.h ../dist/libmp.so
../dist/client_check: client/check.c ../dist/libmp.so
mkdir -pv ../dist
$(CC) -L../dist $< -lmp -o $@
../dist/client_list: client/list.c client/*.h ../dist/libmp.so
../dist/client_list: client/list.c ../dist/libmp.so
mkdir -pv ../dist
$(CC) -L../dist $< -lmp -o $@

View File

@ -1,5 +1,5 @@
#include "../../include/all.h"
#include "./common.h"
#include "../common.h"
#include <stdio.h>
#include <stdlib.h>
@ -10,27 +10,15 @@ int main(int argc, char *argv[]) {
lm_entry_t entry;
lm_ctx_t ctx;
lm_entry_init(&entry);
if (argc != 2) {
printf("usage: %s <package name>\n", argv[0]);
return ret;
}
if (!mkdir_ifnot(ROOT_DIR)) {
printf("failed to create root dir: %s\n", ROOT_DIR);
return ret;
}
lm_entry_init(&entry);
lm_ctx_init(&ctx);
if (!lm_ctx_set_data(&ctx, DATA_DIR)) {
printf("failed to set data dir: %s (%d)\n", lm_strerror(), lm_error());
goto end;
}
if (!lm_ctx_set_root(&ctx, ROOT_DIR)) {
printf("failed to set root dir: %s (%d)\n", lm_strerror(), lm_error());
if (!lm_ctx_init(&ctx, ROOT_DIR, NULL, DATA_DIR)) {
printf("failed to init the ctx: %s (%d)\n", lm_strerror(), lm_error());
goto end;
}

View File

@ -1,5 +1,5 @@
#include "../../include/all.h"
#include "./common.h"
#include "../common.h"
#include <stdio.h>
#include <stdlib.h>
@ -11,34 +11,20 @@ int main(int argc, char *argv[]) {
lm_ctx_t ctx;
int ret = EXIT_FAILURE;
char pooldir[strlen(TEMP_DIR) + 10];
sprintf(pooldir, "%s/%s", TEMP_DIR, "pool");
if (argc != 4) {
printf("usage: %s <package name> <pool name> <pool url>\n", argv[0]);
return ret;
}
if (!mkdir_ifnot(ROOT_DIR)) {
printf("failed to create root dir: %s\n", ROOT_DIR);
return ret;
}
lm_ctx_init(&ctx);
if (!lm_ctx_set_data(&ctx, DATA_DIR)) {
printf("failed to set data dir: %s (%d)\n", lm_strerror(), lm_error());
if (!lm_ctx_init(&ctx, ROOT_DIR, TEMP_DIR, DATA_DIR)) {
printf("failed to init the ctx: %s (%d)\n", lm_strerror(), lm_error());
goto end;
}
if (!lm_ctx_set_temp(&ctx, TEMP_DIR)) {
printf("failed to set temp dir: %s (%d)\n", lm_strerror(), lm_error());
goto end;
}
if (!lm_ctx_set_root(&ctx, ROOT_DIR)) {
printf("failed to set root dir: %s (%d)\n", lm_strerror(), lm_error());
goto end;
}
if (lm_ctx_pool_add(&ctx, argv[2], argv[3]) == NULL) {
if (lm_ctx_pool_add(&ctx, argv[2], argv[3], pooldir) == NULL) {
printf("failed to add pool: %s (%d)\n", lm_strerror(), lm_error());
goto end;
}

View File

@ -1,5 +1,5 @@
#include "../../include/all.h"
#include "./common.h"
#include "../common.h"
#include <stdio.h>
#include <stdlib.h>
@ -11,9 +11,8 @@ int main(int argc, char *argv[]) {
int ret = EXIT_FAILURE;
lm_entry_init(&entry);
lm_ctx_init(&ctx);
if (!lm_ctx_set_data(&ctx, DATA_DIR)) {
if (!lm_ctx_init(&ctx, NULL, NULL, DATA_DIR)) {
printf("failed to set data dir: %s (%d)\n", lm_strerror(), lm_error());
goto end;
}

View File

@ -1,5 +1,5 @@
#include "../../include/all.h"
#include "./common.h"
#include "../common.h"
#include <stdio.h>
#include <stdlib.h>
@ -17,25 +17,8 @@ int main(int argc, char *argv[]) {
return ret;
}
if (!mkdir_ifnot(ROOT_DIR)) {
printf("failed to create root dir: %s\n", ROOT_DIR);
return ret;
}
lm_ctx_init(&ctx);
if (!lm_ctx_set_data(&ctx, DATA_DIR)) {
printf("failed to set data dir: %s (%d)\n", lm_strerror(), lm_error());
goto end;
}
if (!lm_ctx_set_temp(&ctx, TEMP_DIR)) {
printf("failed to set temp dir: %s (%d)\n", lm_strerror(), lm_error());
goto end;
}
if (!lm_ctx_set_root(&ctx, ROOT_DIR)) {
printf("failed to set root dir: %s (%d)\n", lm_strerror(), lm_error());
if (!lm_ctx_init(&ctx, ROOT_DIR, TEMP_DIR, DATA_DIR)) {
printf("failed to init the ctx: %s (%d)\n", lm_strerror(), lm_error());
goto end;
}

View File

@ -1,5 +1,5 @@
#include "../../include/all.h"
#include "./common.h"
#include "../common.h"
#include <stdio.h>
#include <stdlib.h>
@ -17,30 +17,8 @@ int main(int argc, char *argv[]) {
return ret;
}
if (!mkdir_ifnot(ROOT_DIR)) {
printf("failed to create root dir: %s\n", ROOT_DIR);
return ret;
}
lm_ctx_init(&ctx);
if (!lm_ctx_set_data(&ctx, DATA_DIR)) {
printf("failed to set data dir: %s (%d)\n", lm_strerror(), lm_error());
goto end;
}
if (!lm_ctx_set_temp(&ctx, TEMP_DIR)) {
printf("failed to set temp dir: %s (%d)\n", lm_strerror(), lm_error());
goto end;
}
if (!lm_ctx_set_root(&ctx, ROOT_DIR)) {
printf("failed to set root dir: %s (%d)\n", lm_strerror(), lm_error());
goto end;
}
if (lm_ctx_pool_add(&ctx, argv[1], argv[2]) == NULL) {
printf("failed to add pool: %s (%d)\n", lm_strerror(), lm_error());
if (!lm_ctx_init(&ctx, ROOT_DIR, TEMP_DIR, DATA_DIR)) {
printf("failed to init the ctx: %s (%d)\n", lm_strerror(), lm_error());
goto end;
}

View File

@ -1 +0,0 @@
*/LIST_extracted

View File

@ -1,10 +1,10 @@
#include "../../include/all.h"
#include "../common.h"
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#define DATA_DIR "./examples"
int main(int argc, char *argv[]) {
int ret = EXIT_FAILURE;
lm_ctx_t ctx;
@ -14,14 +14,12 @@ int main(int argc, char *argv[]) {
return ret;
}
lm_ctx_init(&ctx);
if (!lm_ctx_set_data(&ctx, DATA_DIR)) {
printf("failed to set data dir: %s (%d)\n", lm_strerror(), lm_error());
if (!lm_ctx_init(&ctx, NULL, TEMP_DIR, NULL)) {
printf("failed to init the ctx: %s (%d)\n", lm_strerror(), lm_error());
goto end;
}
if (lm_ctx_pool_add(&ctx, "test", "mptp://127.0.0.1:5858") == NULL) {
if (lm_ctx_pool_add(&ctx, "test", "mptp://127.0.0.1:5858", "./examples/test") == NULL) {
printf("failed to add pool: %s (%d)\n", lm_strerror(), lm_error());
goto end;
}

View File

@ -27,4 +27,3 @@
#include "ctx.h"
#include "error.h"
#include "pool.h"
#include "util.h"

View File

@ -54,10 +54,7 @@ typedef lm_ctx_remove_callback_t lm_ctx_check_callback_t;
/* ###############
## ctx stuff ##
############### */
void lm_ctx_init(lm_ctx_t *ctx);
bool lm_ctx_set_data(lm_ctx_t *ctx, char *dir);
bool lm_ctx_set_root(lm_ctx_t *ctx, char *dir);
bool lm_ctx_set_temp(lm_ctx_t *ctx, char *dir);
bool lm_ctx_init(lm_ctx_t *ctx, char *root_dir, char *temp_dir, char *data_dir);
void lm_ctx_free(lm_ctx_t *ctx);
/* ####################
@ -87,16 +84,22 @@ size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callbac
void lm_ctx_ping(lm_ctx_t *ctx, lm_ctx_ping_callback_t callback, void *data); // pings all the pools
bool lm_ctx_serve(
lm_ctx_t *ctx, char *addr, uint8_t threads, lm_ctx_serve_callback_t callback, void *data); // serves all the pools
//
/* ##############################
## temp directory fucntions ##
############################## */
char *lm_ctx_temp_dir(lm_ctx_t *ctx, char *dir);
void lm_ctx_temp_clear(lm_ctx_t *ctx);
/* ####################
## pool fucntions ##
#################### */
lm_pkg_t *lm_ctx_pool_find(lm_ctx_t *ctx, char *name, char *version); // find a package in ctx pool list
lm_pool_t *lm_ctx_pool_add(lm_ctx_t *ctx, char *name, char *url); // add a pool to the ctx pool list
bool lm_ctx_pool_del(lm_ctx_t *ctx, char *name); // remove a pool from the ctx pool list
void lm_ctx_pool_clear(lm_ctx_t *ctx); // clear all the pools in the ctx pool list
lm_pool_t *lm_ctx_pool_by_name(lm_ctx_t *ctx, char *name); // find pool by name
lm_pool_t *lm_ctx_pool_by_url(lm_ctx_t *ctx, char *host, char *path); // find pool by URL
lm_pkg_t *lm_ctx_pool_find(lm_ctx_t *ctx, char *name, char *version); // find a package in ctx pool list
lm_pool_t *lm_ctx_pool_add(lm_ctx_t *ctx, char *name, char *url, char *dir); // add a pool to the ctx pool list
bool lm_ctx_pool_del(lm_ctx_t *ctx, char *name); // remove a pool from the ctx pool list
void lm_ctx_pool_clear(lm_ctx_t *ctx); // clear all the pools in the ctx pool list
lm_pool_t *lm_ctx_pool_by_name(lm_ctx_t *ctx, char *name); // find pool by name
lm_pool_t *lm_ctx_pool_by_url(lm_ctx_t *ctx, char *host, char *path); // find pool by URL
/* ########################
## database fucntions ##

View File

@ -1,6 +1,6 @@
#pragma once
#define lm_strerror_dup() {strdup(lm_strerror())}
#define lm_strerror_dup() strdup(lm_strerror())
typedef enum lm_error {
LM_ERR_NoError = 0,
@ -51,14 +51,8 @@ typedef enum lm_error {
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_CtxDataFail = 54,
LM_ERR_ArcRealpathFail = 55,
LM_ERR_PoolTestNotPong = 56,
LM_ERR_PkgPathsEmpty = 57,
@ -144,6 +138,10 @@ typedef enum lm_error {
LM_ERR_DbChangesChmodFail = 136,
LM_ERR_InstallDirFail = 137,
LM_ERR_InstallSaveFail = 138,
LM_ERR_FailMkdir = 139,
LM_ERR_NotDir = 140,
LM_ERR_NoWrite = 141,
LM_ERR_PoolListBadDir = 142,
} lm_error_t;
typedef struct lm_error_desc {

View File

@ -20,7 +20,6 @@ typedef struct lm_pool {
char *name;
char *info_file;
char *list_file;
char *list_dir;
char *dir;
bool available, loaded;
} lm_pool_t;
@ -43,6 +42,6 @@ bool lm_pool_info_download(lm_pool_t *pool, lm_mptp_transfer_callback_t callback
bool lm_pool_info_load(lm_pool_t *pool);
void lm_pool_info_free(lm_pool_t *pool);
bool lm_pool_list_download(lm_pool_t *pool, lm_mptp_transfer_callback_t callback, void *data);
bool lm_pool_list_load(lm_pool_t *pool);
bool lm_pool_list_download(lm_pool_t *pool, char *dir, lm_mptp_transfer_callback_t callback, void *data);
bool lm_pool_list_load(lm_pool_t *pool, char *dir);
void lm_pool_list_free(lm_pool_t *pool);

View File

@ -25,6 +25,8 @@ bool is_file(char *path);
bool is_dir(char *path);
bool exists(char *path);
bool is_empty(char *p);
bool is_dir_empty(char *p);
bool rmrf(char *p);
bool package_parse(char *package, char *name, char *version);
bool package_version_valid(char *name);

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-31 23:52+0300\n"
"POT-Creation-Date: 2024-08-03 22:16+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"
@ -225,386 +225,381 @@ msgid "root path is not set with in the ctx"
msgstr ""
#: src/error.c:70
msgid "specified temp path does not exist"
#, c-format
msgid "failed to set the ctx temp director to %s: %s"
msgstr ""
#: src/error.c:71
msgid "specified temp path is not a directory"
#, c-format
msgid "failed to set the ctx root directory to %s: %s"
msgstr ""
#: src/error.c:72
msgid "specified temp directory does not have write access"
#, c-format
msgid "failed to set the ctx data directory to %s: %s"
msgstr ""
#: src/error.c:73
msgid "specified root path does not exist"
msgstr ""
#: src/error.c:74
msgid "specified root path is not a directory"
msgstr ""
#: src/error.c:75
msgid "specified root directory does not have write access"
msgstr ""
#: src/error.c:76
msgid "specified data path is not a directory"
msgstr ""
#: src/error.c:77
msgid "specified data directory does not have write access"
msgstr ""
#: src/error.c:78
msgid "failed to create specified data directory"
msgstr ""
#: src/error.c:79
msgid "pool did not respond ping with pong"
msgstr ""
#: src/error.c:80
#: src/error.c:74
msgid "package file and directory paths are empty"
msgstr ""
#: src/error.c:81
#: src/error.c:75
msgid "failed to to open target file for sending"
msgstr ""
#: src/error.c:82
#: src/error.c:76
msgid "failed to to delete target file for receiving"
msgstr ""
#: src/error.c:83
#: src/error.c:77
msgid "failed to to open target file for receiving"
msgstr ""
#: src/error.c:84
#: src/error.c:78
msgid "got a bad response code for receiving the target file"
msgstr ""
#: src/error.c:85
#: src/error.c:79
msgid "failed to write to the target file for receiving"
msgstr ""
#: src/error.c:86
#: src/error.c:80
#, fuzzy
msgid "package not found"
msgstr "URL hostname is too large"
#: src/error.c:87
#: src/error.c:81
msgid "failed to access to the database file/directory"
msgstr ""
#: src/error.c:88
#: src/error.c:82
msgid "failed to open SQLite database"
msgstr ""
#: src/error.c:89
#: src/error.c:83
msgid "failed to create table in SQLite database"
msgstr ""
#: src/error.c:90
#: src/error.c:84
msgid "failed to prepare statement for SQLite database"
msgstr ""
#: src/error.c:91
#: src/error.c:85
msgid "failed to insert to the table in SQLite database"
msgstr ""
#: src/error.c:92
#: src/error.c:86
msgid "failed to select from the table in SQLite database"
msgstr ""
#: src/error.c:93
#: src/error.c:87
msgid "failed to delete from the table in SQLite database"
msgstr ""
#: src/error.c:94
#: src/error.c:88
msgid "failed to find entry in SQLite database"
msgstr ""
#: src/error.c:95
#: src/error.c:89
msgid "failed to init GPG for package verification"
msgstr ""
#: src/error.c:96
#: src/error.c:90
msgid "failed to import signature to GPG for package verification"
msgstr ""
#: src/error.c:97
#: src/error.c:91
msgid "failed to import archive to GPG for package verification"
msgstr ""
#: src/error.c:98
#: src/error.c:92
msgid "package signature verification failed with zero matches"
msgstr ""
#: src/error.c:99
#: src/error.c:93
msgid "package signature verification failed with zero results"
msgstr ""
#: src/error.c:100
#: src/error.c:94
msgid "pool file and directory paths are empty"
msgstr ""
#: src/error.c:101
#: src/error.c:95
msgid "pool is not avaliable for connection"
msgstr ""
#: src/error.c:102
#: src/error.c:96
msgid "pool URL is empty or invalid"
msgstr ""
#: src/error.c:103
#: src/error.c:97
msgid "pool directory path is not accessible"
msgstr ""
#: src/error.c:104
#: src/error.c:98
msgid "pool directory sub-paths are not accessible"
msgstr ""
#: src/error.c:105
#: src/error.c:99
msgid "package file list not found in the database"
msgstr ""
#: src/error.c:106
#: src/error.c:100
msgid "failed to open package file list in the database"
msgstr ""
#: src/error.c:107
#: src/error.c:101
msgid "failed to access package file list database directory"
msgstr ""
#: src/error.c:108
#: src/error.c:102
msgid "failed to remove package file list from the database"
msgstr ""
#: src/error.c:109
#: src/error.c:103
msgid "failed to write to the file list in the database"
msgstr ""
#: src/error.c:110
#: src/error.c:104
msgid "package keep list not found in the database"
msgstr ""
#: src/error.c:111
#: src/error.c:105
msgid "failed to open package keep list in the database"
msgstr ""
#: src/error.c:112
#: src/error.c:106
msgid "failed to access package keep list database directory"
msgstr ""
#: src/error.c:113
#: src/error.c:107
msgid "failed to remove package keep list from the database"
msgstr ""
#: src/error.c:114
#: src/error.c:108
#, c-format
msgid "failed to find %s (dependency of %s)"
msgstr ""
#: src/error.c:115
#: src/error.c:109
#, c-format
msgid "failed to download %s for installation: %s"
msgstr ""
#: src/error.c:116
#: src/error.c:110
#, fuzzy
msgid "package is not downloaded"
msgstr "URL hostname is too large"
#: src/error.c:117 src/error.c:118
#: src/error.c:111 src/error.c:112
msgid "failed to remove downloaded package"
msgstr ""
#: src/error.c:119
#: src/error.c:113
msgid "failed to open the destination file"
msgstr ""
#: src/error.c:120
#: src/error.c:114
msgid "failed to open the source file"
msgstr ""
#: src/error.c:121 src/error.c:122
#: src/error.c:115 src/error.c:116
msgid "failed to write to the destination file"
msgstr ""
#: src/error.c:123
#: src/error.c:117
msgid "package does not have associated pool"
msgstr ""
#: src/error.c:124
#: src/error.c:118
msgid "failed to create specified temp directory"
msgstr ""
#: src/error.c:125
#: src/error.c:119
msgid "package archive does not contain required files"
msgstr ""
#: src/error.c:126
#: src/error.c:120
msgid "package data does not match with target package"
msgstr ""
#: src/error.c:127
#: src/error.c:121
#, c-format
msgid "failed to update changes file for package: %s"
msgstr ""
#: src/error.c:128
#: src/error.c:122
msgid "failed to access package hashes file"
msgstr ""
#: src/error.c:129
#: src/error.c:123
msgid "failed to remove package changes file from the database"
msgstr ""
#: src/error.c:130
#: src/error.c:124
msgid "failed to stat target file for sending"
msgstr ""
#: src/error.c:131
#: src/error.c:125
msgid "failed to format target file size for sending"
msgstr ""
#: src/error.c:132
#: src/error.c:126
msgid "failed to read target file size for sending"
msgstr ""
#: src/error.c:133
#: src/error.c:127
msgid "failed to parse target file size for receiving"
msgstr ""
#: src/error.c:134
#: src/error.c:128
msgid "target file is not fully received"
msgstr ""
#: src/error.c:135
#: src/error.c:129
msgid "failed to stat for target extract archive"
msgstr ""
#: src/error.c:136
#: src/error.c:130
#, c-format
msgid "failed to add package file (%s) to the database: %s"
msgstr ""
#: src/error.c:137
#: src/error.c:131
#, c-format
msgid "failed to extract package files: %s"
msgstr ""
#: src/error.c:138
#: src/error.c:132
#, c-format
msgid "failed to add package to the database: %s"
msgstr ""
#: src/error.c:139
#: src/error.c:133
#, fuzzy
msgid "package is already installed"
msgstr "URL hostname is too large"
#: src/error.c:140
#: src/error.c:134
#, fuzzy
msgid "package is not installed"
msgstr "URL hostname is too large"
#: src/error.c:141
#: src/error.c:135
#, c-format
msgid "failed to remove package file (%s): %s"
msgstr ""
#: src/error.c:142
#: src/error.c:136
#, c-format
msgid "failed to remove package from the database: %s"
msgstr ""
#: src/error.c:143
#: src/error.c:137
#, c-format
msgid "failed to remove package files from the database: %s"
msgstr ""
#: src/error.c:144
#: src/error.c:138
#, c-format
msgid "failed to remove changes file for package: %s"
msgstr ""
#: src/error.c:145
#: src/error.c:139
msgid "failed to get current directory for running install"
msgstr ""
#: src/error.c:146
#: src/error.c:140
msgid "failed change directory to root for running install"
msgstr ""
#: src/error.c:147
#: src/error.c:141
msgid "failed run install spawn command"
msgstr ""
#: src/error.c:149
#: src/error.c:143
msgid "failed to change directory to old directory after running install"
msgstr ""
#: src/error.c:150
#: src/error.c:144
msgid "install script returned a bad status code"
msgstr ""
#: src/error.c:151
#: src/error.c:145
#, c-format
msgid "failed to run the package install script: %s"
msgstr ""
#: src/error.c:152
#: src/error.c:146
#, c-format
msgid "failed to save the package install script: %s"
msgstr ""
#: src/error.c:153
#: src/error.c:147
#, c-format
msgid "removing package breaks %s"
msgstr ""
#: src/error.c:154
#: src/error.c:148
#, fuzzy
msgid "package is already up-to-date"
msgstr "URL hostname is too large"
#: src/error.c:155
#: src/error.c:149
msgid "failed to open file for hashing"
msgstr ""
#: src/error.c:156
#: src/error.c:150
msgid "failed create digest for hashing"
msgstr ""
#: src/error.c:157
#: src/error.c:151
#, c-format
msgid "failed to get hash of %s: %s"
msgstr ""
#: src/error.c:158
#: src/error.c:152
#, c-format
msgid "file hash does not match for %s"
msgstr ""
#: src/error.c:159
#: src/error.c:153
#, fuzzy
msgid "pool info is not loaded"
msgstr "URL hostname is too large"
#: src/error.c:160
#: src/error.c:154
msgid "pool list is empty"
msgstr ""
#: src/error.c:161
#: src/error.c:155
msgid "package changes file not found in the database"
msgstr ""
#: src/error.c:162
#: src/error.c:156
msgid "failed to change mod of the changes file"
msgstr ""
#: src/error.c:163
#: src/error.c:157
msgid "failed to create install script save directory"
msgstr ""
#: src/error.c:158
msgid "directory does not have write permissions"
msgstr ""
#: src/error.c:159
msgid "specified path is not a directory"
msgstr ""
#: src/error.c:160
msgid "failed to create the specified directory"
msgstr ""
#: src/error.c:161
msgid "specified list extraction directory is not accessible"
msgstr ""

View File

@ -9,83 +9,70 @@
#include <string.h>
#include <stdio.h>
void lm_ctx_init(lm_ctx_t *ctx) {
bool __lm_ctx_init_checkdir(char *path){
if(!mkdir_ifnot(path)){
lm_error_set(LM_ERR_FailMkdir);
return false;
}
if(!is_dir(path)){
lm_error_set(LM_ERR_NotDir);
return false;
}
if(!can_write(path)){
lm_error_set(LM_ERR_NoWrite);
return false;
}
return true;
}
bool lm_ctx_init(lm_ctx_t *ctx, char *root_dir, char *temp_dir, char *data_dir) {
setlocale(LC_ALL, "");
textdomain("libmp");
char *suberr = NULL;
bool ret = false;
bzero(ctx, sizeof(lm_ctx_t));
ctx->version = LM_VERSION;
lm_error_clear();
}
bool lm_ctx_set_temp(lm_ctx_t *ctx, char *dir){
if(!mkdir_ifnot(dir)){
lm_error_set(LM_ERR_CtxTempFailMkdir);
return false;
if(root_dir != NULL && !__lm_ctx_init_checkdir(root_dir)){
suberr = lm_strerror_dup();
pdebug(__func__, "check failed for specified root directory: %s", lm_strerror());
lm_error_set(LM_ERR_CtxRootFail, root_dir, suberr);
goto end;
}
if(!is_dir(dir)){
lm_error_set(LM_ERR_CtxTempNotDir);
return false;
if(root_dir != NULL)
ctx->root = realpath(root_dir, NULL);
if(temp_dir != NULL && !__lm_ctx_init_checkdir(temp_dir)){
suberr = lm_strerror_dup();
pdebug(__func__, "check failed for specified temp directory: %s", lm_strerror());
lm_error_set(LM_ERR_CtxTempFail, temp_dir, suberr);
goto end;
}
if(!can_write(dir)){
lm_error_set(LM_ERR_CtxTempNoWrite);
return false;
if(temp_dir != NULL)
ctx->temp = realpath(temp_dir, NULL);
if(data_dir != NULL && !__lm_ctx_init_checkdir(data_dir)){
suberr = lm_strerror_dup();
pdebug(__func__, "check failed for specified data directory: %s", lm_strerror());
lm_error_set(LM_ERR_CtxDataFail, data_dir, suberr);
goto end;
}
char fullpath[PATH_MAX + 1];
realpath(dir, fullpath);
if(data_dir != NULL)
ctx->data = realpath(data_dir, NULL);
ctx->temp = strdup(fullpath);
return true;
}
bool lm_ctx_set_root(lm_ctx_t *ctx, char *dir){
if(!exists(dir)){
lm_error_set(LM_ERR_CtxRootFail);
return false;
}
if(!is_dir(dir)){
lm_error_set(LM_ERR_CtxRootNotDir);
return false;
}
if(!can_write(dir)){
lm_error_set(LM_ERR_CtxRootNoWrite);
return false;
}
char fullpath[PATH_MAX + 1];
realpath(dir, fullpath);
ctx->root = strdup(fullpath);
return true;
}
bool lm_ctx_set_data(lm_ctx_t *ctx, char *dir){
if(!mkdir_ifnot(dir)){
lm_error_set(LM_ERR_CtxDataFailMkdir);
return false;
}
if(!is_dir(dir)){
lm_error_set(LM_ERR_CtxDataNotDir);
return false;
}
if(!can_write(dir)){
lm_error_set(LM_ERR_CtxDataNoWrite);
return false;
}
char fullpath[PATH_MAX + 1];
realpath(dir, fullpath);
ctx->data = strdup(fullpath);
return true;
ret = true;
end:
free(suberr);
return ret;
}
void lm_ctx_free(lm_ctx_t *ctx) {

View File

@ -28,8 +28,8 @@ lm_pkg_t *lm_ctx_pool_find(lm_ctx_t *ctx, char *name, char *version){
return found;
}
lm_pool_t *lm_ctx_pool_add(lm_ctx_t *ctx, char *name, char *url) {
if(NULL == name){
lm_pool_t *lm_ctx_pool_add(lm_ctx_t *ctx, char *name, char *url, char *dir) {
if(NULL == name || NULL == dir){
lm_error_set(LM_ERR_ArgNULL);
return NULL;
}
@ -38,26 +38,15 @@ lm_pool_t *lm_ctx_pool_add(lm_ctx_t *ctx, char *name, char *url) {
if (NULL == pool)
return NULL;
pdebug(__func__, "adding new pool: %s (%s://%s:%d%s)", pool->name, pool->url.protocol, pool->url.host, pool->url.port, pool->url.path);
if(NULL == url)
pdebug(__func__, "adding new pool: %s", pool->name);
else
pdebug(__func__, "adding new pool: %s (%s://%s:%d%s)", pool->name, pool->url.protocol, pool->url.host, pool->url.port, pool->url.path);
if(NULL != ctx->data){
char pools_dir[strlen(ctx->data)+strlen(pool->name)+10];
join(pools_dir, ctx->data, "pools");
if(!mkdir_ifnot(pools_dir)){
lm_error_set(LM_ERR_CtxDataFailMkdir);
lm_pool_free(pool);
return NULL;
}
bzero(pools_dir, sizeof(pools_dir));
join_multiple(pools_dir, ctx->data, "pools", pool->name);
if(!lm_pool_path_set_dir(pool, pools_dir)){
// error is set by set_dir
lm_pool_free(pool);
return NULL;
}
if(!lm_pool_path_set_dir(pool, dir)){
// error is set by set_dir
lm_pool_free(pool);
return NULL;
}
// add to the start

View File

@ -43,6 +43,7 @@ size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callbac
};
lm_pool_t *cur = ctx->pools;
size_t loaded_count = 0;
char *tempdir = NULL;
bool status = false;
while(NULL != cur){
@ -98,12 +99,14 @@ size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callbac
goto next_list;
}
if(!do_update && !lm_pool_list_load(cur)){
tempdir = lm_ctx_temp_dir(ctx, "list_extracted");
if(!do_update && !lm_pool_list_load(cur, tempdir)){
pdebug(__func__, "(%s) failed to load list: %s", cur->name, lm_strerror());
goto next_list;
}
else if(do_update && !lm_pool_list_download(cur, __lm_ctx_sync_callback, &cbdata)) {
else if(do_update && !lm_pool_list_download(cur, tempdir, __lm_ctx_sync_callback, &cbdata)) {
pdebug(__func__, "(%s) failed to update list: %s", cur->name, lm_strerror());
goto next_list;
}
@ -112,6 +115,9 @@ size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callbac
status = true;
next_list:
free(tempdir);
tempdir = NULL;
if(NULL != callback && status)
callback(ctx, cur, SYNC_LIST_SUCCESS, 0, 0, data);
else if(NULL != callback && !status)

38
src/ctx/temp.c Normal file
View File

@ -0,0 +1,38 @@
#include "../../include/error.h"
#include "../../include/util.h"
#include "../../include/ctx.h"
#include <stdbool.h>
#include <string.h>
char *lm_ctx_temp_dir(lm_ctx_t *ctx, char *dir){
if(NULL == dir){
lm_error_set(LM_ERR_ArgNULL);
return false;
}
if(NULL == ctx->temp){
lm_error_set(LM_ERR_CtxTempNULL);
return false;
}
char td[strlen(ctx->temp)+strlen(dir)+10];
join(td, ctx->temp, dir);
if(!mkdir_ifnot(td)){
lm_error_set(LM_ERR_CtxTempFailMkdir);
return NULL;
}
return strdup(td);
}
void lm_ctx_temp_clear(lm_ctx_t *ctx) {
if(NULL == ctx->temp){
lm_error_set(LM_ERR_CtxTempNULL);
return;
}
rmrf(ctx->temp);
}

View File

@ -67,15 +67,9 @@ void lm_error_set(lm_error_t code, ...) {
{.code = LM_ERR_CtxDataNULL, .desc = _("data path is not set with in the ctx") },
{.code = LM_ERR_CtxTempNULL, .desc = _("temp path is not set with in the ctx") },
{.code = LM_ERR_CtxRootNULL, .desc = _("root path is not set with in the ctx") },
{.code = LM_ERR_CtxTempFail, .desc = _("specified temp path does not exist") },
{.code = LM_ERR_CtxTempNotDir, .desc = _("specified temp path is not a directory") },
{.code = LM_ERR_CtxTempNoWrite, .desc = _("specified temp directory does not have write access") },
{.code = LM_ERR_CtxRootFail, .desc = _("specified root path does not exist") },
{.code = LM_ERR_CtxRootNotDir, .desc = _("specified root path is not a directory") },
{.code = LM_ERR_CtxRootNoWrite, .desc = _("specified root directory does not have write access") },
{.code = LM_ERR_CtxDataNotDir, .desc = _("specified data path is not a directory") },
{.code = LM_ERR_CtxDataNoWrite, .desc = _("specified data directory does not have write access") },
{.code = LM_ERR_CtxDataFailMkdir, .desc = _("failed to create specified data directory") },
{.code = LM_ERR_CtxTempFail, .desc = _("failed to set the ctx temp director to %s: %s") },
{.code = LM_ERR_CtxRootFail, .desc = _("failed to set the ctx root directory to %s: %s") },
{.code = LM_ERR_CtxDataFail, .desc = _("failed to set the ctx data directory to %s: %s") },
{.code = LM_ERR_PoolTestNotPong, .desc = _("pool did not respond ping with pong") },
{.code = LM_ERR_PkgPathsEmpty, .desc = _("package file and directory paths are empty") },
{.code = LM_ERR_SendOpenFail, .desc = _("failed to to open target file for sending") },
@ -161,6 +155,10 @@ void lm_error_set(lm_error_t code, ...) {
{.code = LM_ERR_DbChangesNotExists, .desc = _("package changes file not found in the database") },
{.code = LM_ERR_DbChangesChmodFail, .desc = _("failed to change mod of the changes file") },
{.code = LM_ERR_InstallDirFail, .desc = _("failed to create install script save directory") },
{.code = LM_ERR_NoWrite, .desc = _("directory does not have write permissions") },
{.code = LM_ERR_NotDir, .desc = _("specified path is not a directory") },
{.code = LM_ERR_FailMkdir, .desc = _("failed to create the specified directory") },
{.code = LM_ERR_PoolListBadDir, .desc = _("specified list extraction directory is not accessible") },
};
char *fmt = NULL;

View File

@ -9,8 +9,8 @@
#include <libgen.h>
#include <string.h>
bool lm_pool_list_load(lm_pool_t *pool){
if(NULL == pool){
bool lm_pool_list_load(lm_pool_t *pool, char *dir){
if(NULL == pool || NULL == dir){
lm_error_set(LM_ERR_ArgNULL);
return false;
}
@ -27,27 +27,27 @@ bool lm_pool_list_load(lm_pool_t *pool){
return false;
}
pdebug(__func__, "(%s) extracting pool to %s", pool->name, pool->list_dir);
pdebug(__func__, "(%s) extracting pool to %s", pool->name, dir);
if(!mkdir_ifnot(pool->dir)){
lm_error_set(LM_ERR_PoolBadDir);
return false;
}
if(!mkdir_ifnot(pool->list_dir)){
lm_error_set(LM_ERR_PoolBadPaths);
if(!mkdir_ifnot(dir)){
lm_error_set(LM_ERR_PoolListBadDir);
return false;
}
size_t ent_len = 0, list_dir_len = strlen(pool->list_dir);
size_t ent_len = 0, list_dir_len = strlen(dir);
struct dirent *ent = NULL;
DIR *dirfd = NULL;
bool ret = false;
if(!extract_archive(pool->list_dir, pool->list_file))
if(!extract_archive(dir, pool->list_file))
goto end;
if((dirfd = opendir(pool->list_dir)) == NULL){
if((dirfd = opendir(dir)) == NULL){
lm_error_set(LM_ERR_PoolListDirFail);
goto end;
}
@ -58,7 +58,7 @@ bool lm_pool_list_load(lm_pool_t *pool){
ent_len = strlen(ent->d_name);
char datap[ent_len+list_dir_len+10];
join_multiple(datap, pool->list_dir, ent->d_name, "DATA");
join_multiple(datap, dir, ent->d_name, "DATA");
lm_pkg_t *pkg = lm_package_new();
@ -85,8 +85,8 @@ end:
return ret;
}
bool lm_pool_list_download(lm_pool_t *pool, lm_mptp_transfer_callback_t callback, void *data) {
if(NULL == pool){
bool lm_pool_list_download(lm_pool_t *pool, char *dir, lm_mptp_transfer_callback_t callback, void *data) {
if(NULL == pool || NULL == dir){
lm_error_set(LM_ERR_ArgNULL);
return false;
}
@ -106,11 +106,6 @@ bool lm_pool_list_download(lm_pool_t *pool, lm_mptp_transfer_callback_t callback
return false;
}
if(!mkdir_ifnot(pool->list_dir)){
lm_error_set(LM_ERR_PoolBadPaths);
return false;
}
if(NULL == pool->url.path || NULL == pool->url.host){
lm_error_set(LM_ERR_PoolUrlEmpty);
return false;
@ -137,7 +132,7 @@ bool lm_pool_list_download(lm_pool_t *pool, lm_mptp_transfer_callback_t callback
end:
lm_mptp_close(sock);
if(ret)
ret = lm_pool_list_load(pool);
ret = lm_pool_list_load(pool, dir);
return ret;
}

View File

@ -7,12 +7,10 @@
bool lm_pool_path_set_dir(lm_pool_t *pool, char *dir){
free(pool->dir);
free(pool->list_dir);
free(pool->info_file);
free(pool->list_file);
pool->dir = NULL;
pool->list_dir = NULL;
pool->info_file = NULL;
pool->list_file = NULL;
@ -27,7 +25,6 @@ bool lm_pool_path_set_dir(lm_pool_t *pool, char *dir){
pool->dir = strdup(dir);
pool->info_file = join_alloc(dir, "INFO");
pool->list_file = join_alloc(dir, "LIST");
pool->list_dir = join_alloc(dir, "LIST_extracted");
if(exists(pool->info_file) && (!is_file(pool->info_file) || !can_read(pool->info_file) || !can_write(pool->info_file))){
lm_error_set(LM_ERR_PoolBadPaths);
@ -39,17 +36,11 @@ bool lm_pool_path_set_dir(lm_pool_t *pool, char *dir){
return false;
}
if(exists(pool->list_dir) && (is_file(pool->list_dir) || !can_read(pool->list_dir) || !can_write(pool->list_dir))){
lm_error_set(LM_ERR_PoolBadPaths);
return false;
}
return true;
}
bool lm_pool_path_is_empty(lm_pool_t *pool){
return NULL == pool->info_file ||
NULL == pool->list_file ||
NULL == pool->list_dir ||
NULL == pool->dir;
}

View File

@ -66,11 +66,12 @@ end:
void lm_pool_free(lm_pool_t *pool) {
free(pool->dir);
free(pool->list_dir);
free(pool->info_file);
free(pool->list_file);
lm_url_free(&pool->url);
lm_pool_info_free(pool);
lm_pool_list_free(pool);
free(pool);
}

View File

@ -3,6 +3,7 @@
#include <archive.h>
#include <arpa/inet.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/limits.h>
@ -498,3 +499,59 @@ end:
close(fd);
return ret;
}
bool rmrf(char *p) {
DIR *fd = opendir(p);
struct dirent *ent = NULL;
size_t pl = strlen(p), dl = 0;
bool ret = false;
if (NULL == fd)
return false;
while ((ent = readdir(fd)) != NULL) {
if (eq(ent->d_name, ".") || eq(ent->d_name, ".."))
continue;
dl = strlen(ent->d_name);
char fp[pl + dl + 10];
join(fp, p, ent->d_name);
switch (ent->d_type) {
case DT_DIR:
if (!rmrf(fp))
goto end;
break;
default:
if (unlink(fp) < 0)
goto end;
break;
}
}
ret = true;
end:
closedir(fd);
rmdir(p);
return ret;
}
bool is_dir_empty(char *p) {
DIR *fd = opendir(p);
struct dirent *ent = NULL;
bool empty = true;
if (NULL == fd)
return false;
while ((ent = readdir(fd)) != NULL) {
if (eq(ent->d_name, ".") || eq(ent->d_name, ".."))
continue;
empty = false;
break;
}
closedir(fd);
return empty;
}