Compare commits

..

10 Commits

18 changed files with 249 additions and 184 deletions

View File

@ -22,7 +22,7 @@
// clang-format on // clang-format on
#define LM_VERSION "24.04" #define LM_VERSION "24.09"
#include "ctx.h" #include "ctx.h"
#include "error.h" #include "error.h"

View File

@ -93,8 +93,8 @@ bool lm_ctx_install(lm_ctx_t *ctx, lm_pkg_t *pkg, bool run_install, lm_ctx_insta
void *data); // installs/updates a single package void *data); // installs/updates a single package
bool lm_ctx_check( bool lm_ctx_check(
lm_ctx_t *ctx, lm_entry_t *entry, lm_ctx_check_callback_t callback, void *data); // checks a single package lm_ctx_t *ctx, lm_entry_t *entry, lm_ctx_check_callback_t callback, void *data); // checks a single package
size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback, void *data); // syncs all the pools ssize_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback, void *data); // syncs all the pools
void lm_ctx_ping(lm_ctx_t *ctx, lm_ctx_ping_callback_t callback, void *data); // pings all the pools 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, __sighandler_t handler, lm_ctx_serve_callback_t callback, bool lm_ctx_serve(lm_ctx_t *ctx, char *addr, uint8_t threads, __sighandler_t handler, lm_ctx_serve_callback_t callback,
void *data); // serves all the pools void *data); // serves all the pools

View File

@ -140,7 +140,7 @@ typedef enum lm_error {
LM_ERR_InstallSaveFail = 138, LM_ERR_InstallSaveFail = 138,
LM_ERR_FailMkdir = 139, LM_ERR_FailMkdir = 139,
LM_ERR_NotDir = 140, LM_ERR_NotDir = 140,
LM_ERR_NoWrite = 141, LM_ERR_NoRead = 141,
LM_ERR_PoolListBadDir = 142, LM_ERR_PoolListBadDir = 142,
LM_ERR_FileNotExist = 143, LM_ERR_FileNotExist = 143,
LM_ERR_FileNotLink = 144, LM_ERR_FileNotLink = 144,
@ -154,6 +154,10 @@ typedef enum lm_error {
LM_ERR_PoolInfoUnknown = 152, LM_ERR_PoolInfoUnknown = 152,
LM_ERR_MPTPBadPath = 153, LM_ERR_MPTPBadPath = 153,
LM_ERR_UnknownThread = 154, LM_ERR_UnknownThread = 154,
LM_ERR_PkgBadVersion = 155,
LM_ERR_PkgDataMissing = 156,
LM_ERR_PoolListDataFail = 157,
LM_ERR_PoolListAddFail = 158,
} lm_error_t; } lm_error_t;
typedef struct lm_error_desc { typedef struct lm_error_desc {

View File

@ -33,8 +33,9 @@ bool rmrf(char *p);
int digits(int n); int digits(int n);
bool package_parse(char *package, char *name, char *version); bool package_parse(char *package, char *name, char *version);
bool package_version_valid(char *name); bool __package_field_valid(char *field);
bool package_name_valid(char *name); #define package_version_valid(x) __package_field_valid(x)
#define package_name_valid(x) __package_field_valid(x)
void pdebug(const char *func, const char *fmt, ...); void pdebug(const char *func, const char *fmt, ...);
void pdebug_binary(char *data, size_t len); void pdebug_binary(char *data, size_t len);
@ -42,7 +43,7 @@ void pdebug_binary(char *data, size_t len);
bool parse_host(char *addr, char *host, uint16_t *port); bool parse_host(char *addr, char *host, uint16_t *port);
bool copy_blocks(struct archive *w, struct archive *r); bool copy_blocks(struct archive *w, struct archive *r);
bool extract_archive(char *dst, char *src); bool extract_archive(char *dst, char *src);
bool mkdir_ifnot(char *path); bool mkdir_ifnot(char *path, int mode);
int join_multiple(char *res, const char *base, const char *pth, const char *pth2); int join_multiple(char *res, const char *base, const char *pth, const char *pth2);
int join(char *res, const char *base, const char *pth); int join(char *res, const char *base, const char *pth);

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-16 03:06+0300\n" "POT-Creation-Date: 2024-08-25 14:07+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -203,461 +203,481 @@ msgid "failed to open extracted pool list directory"
msgstr "" msgstr ""
#: src/error.c:76 #: src/error.c:76
msgid "failed to read access the pool list file" #, c-format
msgid "failed to load \"%s\" data: %s"
msgstr "" msgstr ""
#: src/error.c:77 #: src/error.c:77
msgid "failed to read access the pool info file" #, c-format
msgid "failed add \"%s\" to the pool list: %s"
msgstr "" msgstr ""
#: src/error.c:78 #: src/error.c:78
msgid "failed to parse package data" msgid "failed to read access the pool list file"
msgstr "" msgstr ""
#: src/error.c:79 #: src/error.c:79
msgid "failed to read access the pool info file"
msgstr ""
#: src/error.c:80
msgid "failed to parse package data"
msgstr ""
#: src/error.c:81
#, fuzzy #, fuzzy
msgid "package name is invalid" msgid "package name is invalid"
msgstr "URL hostname is too large" msgstr "URL hostname is too large"
#: src/error.c:80 #: src/error.c:82
#, fuzzy
msgid "package version is invalid"
msgstr "URL hostname is too large"
#: src/error.c:83
#, c-format
msgid "package data has missing field: %s"
msgstr ""
#: src/error.c:84
msgid "data path is not set with in the ctx" msgid "data path is not set with in the ctx"
msgstr "" msgstr ""
#: src/error.c:81 #: src/error.c:85
msgid "temp path is not set with in the ctx" msgid "temp path is not set with in the ctx"
msgstr "" msgstr ""
#: src/error.c:82 #: src/error.c:86
msgid "root path is not set with in the ctx" msgid "root path is not set with in the ctx"
msgstr "" msgstr ""
#: src/error.c:83 #: src/error.c:87
#, c-format #, c-format
msgid "failed to set the ctx temp director to %s: %s" msgid "failed to set the ctx temp director to %s: %s"
msgstr "" msgstr ""
#: src/error.c:84 #: src/error.c:88
#, c-format #, c-format
msgid "failed to set the ctx root directory to %s: %s" msgid "failed to set the ctx root directory to %s: %s"
msgstr "" msgstr ""
#: src/error.c:85 #: src/error.c:89
#, c-format #, c-format
msgid "failed to set the ctx data directory to %s: %s" msgid "failed to set the ctx data directory to %s: %s"
msgstr "" msgstr ""
#: src/error.c:86 #: src/error.c:90
msgid "pool did not respond ping with pong" msgid "pool did not respond ping with pong"
msgstr "" msgstr ""
#: src/error.c:87 #: src/error.c:91
msgid "package file and directory paths are empty" msgid "package file and directory paths are empty"
msgstr "" msgstr ""
#: src/error.c:88 #: src/error.c:92
msgid "failed to to open target file for sending" msgid "failed to to open target file for sending"
msgstr "" msgstr ""
#: src/error.c:89 #: src/error.c:93
msgid "failed to to delete target file for receiving" msgid "failed to to delete target file for receiving"
msgstr "" msgstr ""
#: src/error.c:90 #: src/error.c:94
msgid "failed to to open target file for receiving" msgid "failed to to open target file for receiving"
msgstr "" msgstr ""
#: src/error.c:91 #: src/error.c:95
msgid "got a bad response code for receiving the target file" msgid "got a bad response code for receiving the target file"
msgstr "" msgstr ""
#: src/error.c:92 #: src/error.c:96
msgid "failed to write to the target file for receiving" msgid "failed to write to the target file for receiving"
msgstr "" msgstr ""
#: src/error.c:93 #: src/error.c:97
#, fuzzy #, fuzzy
msgid "package not found" msgid "package not found"
msgstr "URL hostname is too large" msgstr "URL hostname is too large"
#: src/error.c:94 #: src/error.c:98
msgid "failed to access to the database file/directory" msgid "failed to access to the database file/directory"
msgstr "" msgstr ""
#: src/error.c:95 #: src/error.c:99
msgid "failed to open SQLite database" msgid "failed to open SQLite database"
msgstr "" msgstr ""
#: src/error.c:96 #: src/error.c:100
msgid "failed to create table in SQLite database" msgid "failed to create table in SQLite database"
msgstr "" msgstr ""
#: src/error.c:97 #: src/error.c:101
msgid "failed to prepare statement for SQLite database" msgid "failed to prepare statement for SQLite database"
msgstr "" msgstr ""
#: src/error.c:98 #: src/error.c:102
msgid "failed to insert to the table in SQLite database" msgid "failed to insert to the table in SQLite database"
msgstr "" msgstr ""
#: src/error.c:99 #: src/error.c:103
msgid "failed to select from the table in SQLite database" msgid "failed to select from the table in SQLite database"
msgstr "" msgstr ""
#: src/error.c:100 #: src/error.c:104
msgid "failed to delete from the table in SQLite database" msgid "failed to delete from the table in SQLite database"
msgstr "" msgstr ""
#: src/error.c:101 #: src/error.c:105
msgid "failed to find entry in SQLite database" msgid "failed to find entry in SQLite database"
msgstr "" msgstr ""
#: src/error.c:102 #: src/error.c:106
msgid "failed to init GPG for package verification" msgid "failed to init GPG for package verification"
msgstr "" msgstr ""
#: src/error.c:103 #: src/error.c:107
msgid "failed to import signature to GPG for package verification" msgid "failed to import signature to GPG for package verification"
msgstr "" msgstr ""
#: src/error.c:104 #: src/error.c:108
msgid "failed to import archive to GPG for package verification" msgid "failed to import archive to GPG for package verification"
msgstr "" msgstr ""
#: src/error.c:105 #: src/error.c:109
msgid "package signature verification failed with zero matches" msgid "package signature verification failed with zero matches"
msgstr "" msgstr ""
#: src/error.c:106 #: src/error.c:110
msgid "package signature verification failed with zero results" msgid "package signature verification failed with zero results"
msgstr "" msgstr ""
#: src/error.c:107 #: src/error.c:111
msgid "pool file and directory paths are empty" msgid "pool file and directory paths are empty"
msgstr "" msgstr ""
#: src/error.c:108 #: src/error.c:112
msgid "pool is not avaliable for connection" msgid "pool is not avaliable for connection"
msgstr "" msgstr ""
#: src/error.c:109 #: src/error.c:113
msgid "pool URL is empty or invalid" msgid "pool URL is empty or invalid"
msgstr "" msgstr ""
#: src/error.c:110 #: src/error.c:114
msgid "pool directory path is not accessible" msgid "pool directory path is not accessible"
msgstr "" msgstr ""
#: src/error.c:111 #: src/error.c:115
msgid "pool directory sub-paths are not accessible" msgid "pool directory sub-paths are not accessible"
msgstr "" msgstr ""
#: src/error.c:112 #: src/error.c:116
msgid "file list not found for the package" msgid "file list not found for the package"
msgstr "" msgstr ""
#: src/error.c:113 #: src/error.c:117
#, c-format #, c-format
msgid "failed to rename the file list for the package: %s" msgid "failed to rename the file list for the package: %s"
msgstr "" msgstr ""
#: src/error.c:114 #: src/error.c:118
#, c-format #, c-format
msgid "failed to open the package file list: %s" msgid "failed to open the package file list: %s"
msgstr "" msgstr ""
#: src/error.c:115 #: src/error.c:119
#, c-format #, c-format
msgid "failed to open the database directory: %s" msgid "failed to open the database directory: %s"
msgstr "" msgstr ""
#: src/error.c:116 #: src/error.c:120
#, c-format #, c-format
msgid "failed to remove package file list: %s" msgid "failed to remove package file list: %s"
msgstr "" msgstr ""
#: src/error.c:117 #: src/error.c:121
msgid "package keep list not found in the database" msgid "package keep list not found in the database"
msgstr "" msgstr ""
#: src/error.c:118 #: src/error.c:122
msgid "failed to open package keep list in the database" msgid "failed to open package keep list in the database"
msgstr "" msgstr ""
#: src/error.c:119 #: src/error.c:123
msgid "failed to access package keep list database directory" msgid "failed to access package keep list database directory"
msgstr "" msgstr ""
#: src/error.c:120 #: src/error.c:124
msgid "failed to remove package keep list from the database" msgid "failed to remove package keep list from the database"
msgstr "" msgstr ""
#: src/error.c:121 #: src/error.c:125
#, c-format #, c-format
msgid "failed to find %s (dependency of %s)" msgid "failed to find %s (dependency of %s)"
msgstr "" msgstr ""
#: src/error.c:122 #: src/error.c:126
#, c-format #, c-format
msgid "failed to download %s for installation: %s" msgid "failed to download %s for installation: %s"
msgstr "" msgstr ""
#: src/error.c:123 #: src/error.c:127
#, fuzzy #, fuzzy
msgid "package is not downloaded" msgid "package is not downloaded"
msgstr "URL hostname is too large" msgstr "URL hostname is too large"
#: src/error.c:124 src/error.c:125 #: src/error.c:128 src/error.c:129
msgid "failed to remove downloaded package" msgid "failed to remove downloaded package"
msgstr "" msgstr ""
#: src/error.c:126 #: src/error.c:130
msgid "failed to open the destination file" msgid "failed to open the destination file"
msgstr "" msgstr ""
#: src/error.c:127 #: src/error.c:131
msgid "failed to open the source file" msgid "failed to open the source file"
msgstr "" msgstr ""
#: src/error.c:128 src/error.c:129 #: src/error.c:132 src/error.c:133
msgid "failed to write to the destination file" msgid "failed to write to the destination file"
msgstr "" msgstr ""
#: src/error.c:130 #: src/error.c:134
msgid "package does not have associated pool" msgid "package does not have associated pool"
msgstr "" msgstr ""
#: src/error.c:131 #: src/error.c:135
msgid "failed to create specified temp directory" msgid "failed to create specified temp directory"
msgstr "" msgstr ""
#: src/error.c:132 #: src/error.c:136
msgid "package archive does not contain required files" msgid "package archive does not contain required files"
msgstr "" msgstr ""
#: src/error.c:133 #: src/error.c:137
msgid "package data does not match with target package" msgid "package data does not match with target package"
msgstr "" msgstr ""
#: src/error.c:134 #: src/error.c:138
#, c-format #, c-format
msgid "failed to update changes file for package: %s" msgid "failed to update changes file for package: %s"
msgstr "" msgstr ""
#: src/error.c:135 #: src/error.c:139
msgid "failed to access package hashes file" msgid "failed to access package hashes file"
msgstr "" msgstr ""
#: src/error.c:136 #: src/error.c:140
msgid "failed to remove package changes file from the database" msgid "failed to remove package changes file from the database"
msgstr "" msgstr ""
#: src/error.c:137 #: src/error.c:141
msgid "failed to stat target file for sending" msgid "failed to stat target file for sending"
msgstr "" msgstr ""
#: src/error.c:138 #: src/error.c:142
msgid "failed to format target file size for sending" msgid "failed to format target file size for sending"
msgstr "" msgstr ""
#: src/error.c:139 #: src/error.c:143
msgid "failed to read target file size for sending" msgid "failed to read target file size for sending"
msgstr "" msgstr ""
#: src/error.c:140 #: src/error.c:144
msgid "failed to parse target file size for receiving" msgid "failed to parse target file size for receiving"
msgstr "" msgstr ""
#: src/error.c:141 #: src/error.c:145
msgid "target file is not fully received" msgid "target file is not fully received"
msgstr "" msgstr ""
#: src/error.c:142 #: src/error.c:146
msgid "failed to stat for target extract archive" msgid "failed to stat for target extract archive"
msgstr "" msgstr ""
#: src/error.c:143 #: src/error.c:147
#, c-format #, c-format
msgid "failed to add package file (%s) to the database: %s" msgid "failed to add package file (%s) to the database: %s"
msgstr "" msgstr ""
#: src/error.c:144 #: src/error.c:148
#, c-format #, c-format
msgid "failed to extract package files: %s" msgid "failed to extract package files: %s"
msgstr "" msgstr ""
#: src/error.c:145 #: src/error.c:149
#, c-format #, c-format
msgid "failed to add package to the database: %s" msgid "failed to add package to the database: %s"
msgstr "" msgstr ""
#: src/error.c:146 #: src/error.c:150
#, fuzzy #, fuzzy
msgid "package is already installed" msgid "package is already installed"
msgstr "URL hostname is too large" msgstr "URL hostname is too large"
#: src/error.c:147 #: src/error.c:151
#, fuzzy #, fuzzy
msgid "package is not installed" msgid "package is not installed"
msgstr "URL hostname is too large" msgstr "URL hostname is too large"
#: src/error.c:148 #: src/error.c:152
#, c-format #, c-format
msgid "failed to remove package file (%s): %s" msgid "failed to remove package file (%s): %s"
msgstr "" msgstr ""
#: src/error.c:149 #: src/error.c:153
#, c-format #, c-format
msgid "failed to remove package from the database: %s" msgid "failed to remove package from the database: %s"
msgstr "" msgstr ""
#: src/error.c:150 #: src/error.c:154
#, c-format #, c-format
msgid "failed to remove package files from the database: %s" msgid "failed to remove package files from the database: %s"
msgstr "" msgstr ""
#: src/error.c:151 #: src/error.c:155
#, c-format #, c-format
msgid "failed to remove changes file for package: %s" msgid "failed to remove changes file for package: %s"
msgstr "" msgstr ""
#: src/error.c:152 #: src/error.c:156
msgid "failed to get current directory for running install" msgid "failed to get current directory for running install"
msgstr "" msgstr ""
#: src/error.c:153 #: src/error.c:157
msgid "failed change directory to root for running install" msgid "failed change directory to root for running install"
msgstr "" msgstr ""
#: src/error.c:154 #: src/error.c:158
msgid "failed run install spawn command" msgid "failed run install spawn command"
msgstr "" msgstr ""
#: src/error.c:156 #: src/error.c:160
msgid "failed to change directory to old directory after running install" msgid "failed to change directory to old directory after running install"
msgstr "" msgstr ""
#: src/error.c:157 #: src/error.c:161
msgid "install script returned a bad status code" msgid "install script returned a bad status code"
msgstr "" msgstr ""
#: src/error.c:158 #: src/error.c:162
#, c-format #, c-format
msgid "failed to run the package install script: %s" msgid "failed to run the package install script: %s"
msgstr "" msgstr ""
#: src/error.c:159 #: src/error.c:163
#, c-format #, c-format
msgid "failed to save the package install script: %s" msgid "failed to save the package install script: %s"
msgstr "" msgstr ""
#: src/error.c:160 #: src/error.c:164
#, c-format #, c-format
msgid "removing package breaks %s" msgid "removing package breaks %s"
msgstr "" msgstr ""
#: src/error.c:161 #: src/error.c:165
#, fuzzy #, fuzzy
msgid "package is already up-to-date" msgid "package is already up-to-date"
msgstr "URL hostname is too large" msgstr "URL hostname is too large"
#: src/error.c:162 #: src/error.c:166
msgid "failed to open file for hashing" msgid "failed to open file for hashing"
msgstr "" msgstr ""
#: src/error.c:163 #: src/error.c:167
msgid "failed create digest for hashing" msgid "failed create digest for hashing"
msgstr "" msgstr ""
#: src/error.c:164 #: src/error.c:168
#, c-format #, c-format
msgid "failed to get hash of %s: %s" msgid "failed to get hash of %s: %s"
msgstr "" msgstr ""
#: src/error.c:165 #: src/error.c:169
#, c-format #, c-format
msgid "file hash does not match for %s" msgid "file hash does not match for %s"
msgstr "" msgstr ""
#: src/error.c:166 #: src/error.c:170
#, fuzzy #, fuzzy
msgid "pool info is not loaded" msgid "pool info is not loaded"
msgstr "URL hostname is too large" msgstr "URL hostname is too large"
#: src/error.c:167 #: src/error.c:171
msgid "pool list is empty" msgid "pool list is empty"
msgstr "" msgstr ""
#: src/error.c:168 #: src/error.c:172
msgid "package changes file not found in the database" msgid "package changes file not found in the database"
msgstr "" msgstr ""
#: src/error.c:169 #: src/error.c:173
msgid "failed to change mod of the changes file" msgid "failed to change mod of the changes file"
msgstr "" msgstr ""
#: src/error.c:170 #: src/error.c:174
msgid "failed to create install script save directory" msgid "failed to create install script save directory"
msgstr "" msgstr ""
#: src/error.c:171 #: src/error.c:175
msgid "directory does not have write permissions" msgid "directory does not have read permissions"
msgstr "" msgstr ""
#: src/error.c:172 #: src/error.c:176
msgid "specified path is not a directory" msgid "specified path is not a directory"
msgstr "" msgstr ""
#: src/error.c:173 #: src/error.c:177
msgid "failed to create the specified directory" msgid "failed to create the specified directory"
msgstr "" msgstr ""
#: src/error.c:174 #: src/error.c:178
msgid "specified list extraction directory is not accessible" msgid "specified list extraction directory is not accessible"
msgstr "" msgstr ""
#: src/error.c:175 #: src/error.c:179
#, c-format #, c-format
msgid "file does not exist: %s" msgid "file does not exist: %s"
msgstr "" msgstr ""
#: src/error.c:176 #: src/error.c:180
#, c-format #, c-format
msgid "file is a symbolic link: %s" msgid "file is a symbolic link: %s"
msgstr "" msgstr ""
#: src/error.c:177
msgid "failed to set the package archive"
msgstr ""
#: src/error.c:178
#, c-format
msgid "failed change directory: %s"
msgstr ""
#: src/error.c:179
msgid "failed to change directory to root during extraction"
msgstr ""
#: src/error.c:180
msgid "failed to change directory back from root during extraction"
msgstr ""
#: src/error.c:181 #: src/error.c:181
#, c-format msgid "failed to set the package archive"
msgid "failed to accept the MPTP connection: %s"
msgstr "" msgstr ""
#: src/error.c:182 #: src/error.c:182
#, c-format #, c-format
msgid "failed to listen the MPTP socket: %s" msgid "failed change directory: %s"
msgstr "" msgstr ""
#: src/error.c:183 #: src/error.c:183
msgid "failed to change directory to root during extraction"
msgstr ""
#: src/error.c:184
msgid "failed to change directory back from root during extraction"
msgstr ""
#: src/error.c:185
#, c-format
msgid "failed to accept the MPTP connection: %s"
msgstr ""
#: src/error.c:186
#, c-format
msgid "failed to listen the MPTP socket: %s"
msgstr ""
#: src/error.c:187
#, c-format #, c-format
msgid "pool name (%s) doesn't match with: %s" msgid "pool name (%s) doesn't match with: %s"
msgstr "" msgstr ""
#: src/error.c:184 #: src/error.c:188
#, c-format #, c-format
msgid "unknown key in the configuration: %s" msgid "unknown key in the configuration: %s"
msgstr "" msgstr ""

View File

@ -3,15 +3,16 @@
#include "../../include/ctx.h" #include "../../include/ctx.h"
#include <linux/limits.h> #include <linux/limits.h>
#include <strings.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <locale.h> #include <locale.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <strings.h> #include <errno.h>
bool __lm_ctx_init_checkdir(char *path){ bool __lm_ctx_init_checkdir(char *path){
if(!mkdir_ifnot(path)){ if(!mkdir_ifnot(path, 0755)){
lm_error_set(LM_ERR_FailMkdir); lm_error_set(LM_ERR_FailMkdir);
return false; return false;
} }
@ -21,8 +22,8 @@ bool __lm_ctx_init_checkdir(char *path){
return false; return false;
} }
if(!can_write(path)){ if(!can_read(path)){
lm_error_set(LM_ERR_NoWrite); lm_error_set(LM_ERR_NoRead);
return false; return false;
} }
@ -63,6 +64,12 @@ bool lm_ctx_new(lm_ctx_t *ctx, char *root_dir, char *temp_dir, char *data_dir) {
goto end; goto end;
} }
if(root_dir != NULL && !can_write(root_dir)){
pdebug(__func__, "check failed for specified root directory: %s", lm_strerror());
lm_error_set(LM_ERR_CtxRootFail, root_dir, "directory is not writeable");
goto end;
}
if(root_dir != NULL) if(root_dir != NULL)
ctx->root = realpath(root_dir, NULL); ctx->root = realpath(root_dir, NULL);
@ -94,6 +101,8 @@ end:
void lm_ctx_free(lm_ctx_t *ctx) { void lm_ctx_free(lm_ctx_t *ctx) {
lm_ctx_pool_clear(ctx); lm_ctx_pool_clear(ctx);
lm_ctx_temp_clear(ctx);
free(ctx->data); free(ctx->data);
free(ctx->root); free(ctx->root);
free(ctx->temp); free(ctx->temp);

View File

@ -29,7 +29,7 @@ bool __lm_ctx_save_install(lm_ctx_t *ctx, lm_pkg_t *pkg, char *install_path){
sprintf(script_name, "install_%s", pkg->data.name); sprintf(script_name, "install_%s", pkg->data.name);
join(script_dir, ctx->data, "scripts"); join(script_dir, ctx->data, "scripts");
if(!mkdir_ifnot(script_dir)){ if(!mkdir_ifnot(script_dir, 0755)){
lm_error_set(LM_ERR_InstallDirFail); lm_error_set(LM_ERR_InstallDirFail);
return false; return false;
} }
@ -229,10 +229,8 @@ bool lm_ctx_install(lm_ctx_t *ctx, lm_pkg_t *pkg, bool run_install, lm_ctx_insta
return false; return false;
} }
if(!mkdir_ifnot(ctx->temp)){ if(!lm_ctx_temp_clear(ctx))
lm_error_set(LM_ERR_CtxTempFailMkdir); return false; // error set by function
return false;
}
if(!lm_ctx_database_init(ctx)) if(!lm_ctx_database_init(ctx))
return false; // error set by function return false; // error set by function
@ -386,7 +384,10 @@ end:
lm_database_files_del(ctx->db, &pkg->data); lm_database_files_del(ctx->db, &pkg->data);
} }
unlink(pkg->archive); if (pkg->pool != NULL){
unlink(pkg->signature); unlink(pkg->archive);
unlink(pkg->signature);
}
return ret; return ret;
} }

View File

@ -41,9 +41,14 @@ lm_pkg_t *lm_ctx_list_next(lm_ctx_list_t *list){
return list->pkg; return list->pkg;
} }
if((list->pkg = list->pkg->next) && NULL == list->pkg){ if((list->pkg = list->pkg->next) == NULL){
if((list->pool = list->pool->next) != NULL) next_pool:
list->pkg = list->pool->pkg; if((list->pool = list->pool->next) == NULL)
return list->pkg;
if((list->pkg = list->pool->pkg) == NULL)
goto next_pool;
return list->pkg; return list->pkg;
} }

View File

@ -20,18 +20,23 @@ bool __lm_ctx_resolve_contains(lm_pkg_t *pkg, lm_ctx_resolve_list_t *list){
} }
bool __lm_ctx_resolve(lm_ctx_t *ctx, lm_ctx_resolve_list_t *list, lm_pkg_t *pkg, bool resolve_depends){ bool __lm_ctx_resolve(lm_ctx_t *ctx, lm_ctx_resolve_list_t *list, lm_pkg_t *pkg, bool resolve_depends){
if(__lm_ctx_resolve_contains(pkg, list)) if(__lm_ctx_resolve_contains(pkg, list)){
pdebug(__func__, "%s is already in the list, skipping", pkg->data.name);
return true; return true;
}
if(NULL == list->packages) if(NULL == list->packages)
list->packages = malloc(sizeof(lm_pkg_t *)*(++list->count)); list->packages = malloc(sizeof(lm_pkg_t *)*(++list->count));
else else
list->packages = realloc(list->packages, sizeof(lm_pkg_t *)*(++list->count)); list->packages = realloc(list->packages, sizeof(lm_pkg_t *)*(++list->count));
pdebug(__func__, "adding %s to the list", pkg->data.name);
list->packages[list->count-1] = pkg; list->packages[list->count-1] = pkg;
if(!resolve_depends || NULL == pkg->data.depends) if(!resolve_depends || NULL == pkg->data.depends){
pdebug(__func__, "skipping depend resolve for %s", pkg->data.name);
return true; return true;
}
lm_pkg_t *depend = NULL; lm_pkg_t *depend = NULL;

View File

@ -25,7 +25,7 @@ bool __lm_ctx_sync_callback(char *path, size_t current, size_t total, void *data
return cbdata->callback(cbdata->ctx, cbdata->pool, cbdata->state, current, total, data); return cbdata->callback(cbdata->ctx, cbdata->pool, cbdata->state, current, total, data);
} }
size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback, void *data){ ssize_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback, void *data){
if(NULL == ctx) { if(NULL == ctx) {
lm_error_set(LM_ERR_ArgNULL); lm_error_set(LM_ERR_ArgNULL);
return -1; return -1;

View File

@ -19,7 +19,7 @@ char *lm_ctx_temp_dir(lm_ctx_t *ctx, char *dir){
char td[strlen(ctx->temp)+strlen(dir)+10]; char td[strlen(ctx->temp)+strlen(dir)+10];
join(td, ctx->temp, dir); join(td, ctx->temp, dir);
if(!mkdir_ifnot(td)){ if(!mkdir_ifnot(td, 0755)){
lm_error_set(LM_ERR_CtxTempFailMkdir); lm_error_set(LM_ERR_CtxTempFailMkdir);
return NULL; return NULL;
} }
@ -35,11 +35,10 @@ bool lm_ctx_temp_clear(lm_ctx_t *ctx) {
rmrf(ctx->temp); rmrf(ctx->temp);
if(!mkdir_ifnot(ctx->temp)){ if(!mkdir_ifnot(ctx->temp, 0755)){
lm_error_set(LM_ERR_CtxTempFailMkdir); lm_error_set(LM_ERR_CtxTempFailMkdir);
return false; return false;
} }
return true; return true;
} }

View File

@ -38,12 +38,12 @@ lm_database_t *lm_database_new(char *path){
char *err = NULL; char *err = NULL;
bzero(db, sizeof(lm_database_t)); bzero(db, sizeof(lm_database_t));
if(exists(path, NULL) && (is_file(path) || !can_read(path) || !can_write(path))){ if(exists(path, NULL) && (is_file(path) || !can_read(path))){
lm_error_set(LM_ERR_DbCantAccess); lm_error_set(LM_ERR_DbCantAccess);
return NULL; return NULL;
} }
if(!exists(path, NULL) && !mkdir_ifnot(path)){ if(!exists(path, NULL) && !mkdir_ifnot(path, 0755)){
lm_error_set(LM_ERR_DbCantAccess); lm_error_set(LM_ERR_DbCantAccess);
return NULL; return NULL;
} }
@ -58,7 +58,7 @@ lm_database_t *lm_database_new(char *path){
return NULL; return NULL;
} }
if(sqlite3_exec(db->sql, queries[QUERY_CREATE_TABLE], NULL, 0, &err) != SQLITE_OK){ if(can_write(path) && sqlite3_exec(db->sql, queries[QUERY_CREATE_TABLE], NULL, 0, &err) != SQLITE_OK){
pdebug(__func__, "(%s) failed to create packages table: %s", packagesdb, err); pdebug(__func__, "(%s) failed to create packages table: %s", packagesdb, err);
lm_error_set(LM_ERR_DbSqlCreateFail); lm_error_set(LM_ERR_DbSqlCreateFail);
sqlite3_free(err); sqlite3_free(err);

View File

@ -73,10 +73,14 @@ void lm_error_set(lm_error_t code, ...) {
{.code = LM_ERR_ArcNextHeaderFail, .desc = _("failed to read the next header of the archive") }, {.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_GetCwdFail, .desc = _("failed to obtain current working directory") },
{.code = LM_ERR_PoolListDirFail, .desc = _("failed to open extracted pool list directory") }, {.code = LM_ERR_PoolListDirFail, .desc = _("failed to open extracted pool list directory") },
{.code = LM_ERR_PoolListDataFail, .desc = _("failed to load \"%s\" data: %s") },
{.code = LM_ERR_PoolListAddFail, .desc = _("failed add \"%s\" to the pool list: %s") },
{.code = LM_ERR_PoolListCantRead, .desc = _("failed to read access the pool list file") }, {.code = LM_ERR_PoolListCantRead, .desc = _("failed to read access the pool list file") },
{.code = LM_ERR_PoolInfoCantRead, .desc = _("failed to read access the pool info file") }, {.code = LM_ERR_PoolInfoCantRead, .desc = _("failed to read access the pool info file") },
{.code = LM_ERR_PkgDataBad, .desc = _("failed to parse package data") }, {.code = LM_ERR_PkgDataBad, .desc = _("failed to parse package data") },
{.code = LM_ERR_PkgBadName, .desc = _("package name is invalid") }, {.code = LM_ERR_PkgBadName, .desc = _("package name is invalid") },
{.code = LM_ERR_PkgBadVersion, .desc = _("package version is invalid") },
{.code = LM_ERR_PkgDataMissing, .desc = _("package data has missing field: %s") },
{.code = LM_ERR_CtxDataNULL, .desc = _("data path is not set with in the ctx") }, {.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_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_CtxRootNULL, .desc = _("root path is not set with in the ctx") },
@ -168,7 +172,7 @@ void lm_error_set(lm_error_t code, ...) {
{.code = LM_ERR_DbChangesNotExists, .desc = _("package changes file not found in the database") }, {.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_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_InstallDirFail, .desc = _("failed to create install script save directory") },
{.code = LM_ERR_NoWrite, .desc = _("directory does not have write permissions") }, {.code = LM_ERR_NoRead, .desc = _("directory does not have read permissions") },
{.code = LM_ERR_NotDir, .desc = _("specified path is not a directory") }, {.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_FailMkdir, .desc = _("failed to create the specified directory") },
{.code = LM_ERR_PoolListBadDir, .desc = _("specified list extraction directory is not accessible") }, {.code = LM_ERR_PoolListBadDir, .desc = _("specified list extraction directory is not accessible") },

View File

@ -12,8 +12,10 @@ int lm_package_data_handler(void *_data, const char *_section, const char *_key,
lm_pkg_data_t *data = _data; lm_pkg_data_t *data = _data;
if(NULL == data->name){ if(NULL == data->name){
if(!package_name_valid(section)) if(!package_name_valid(section)){
lm_error_set(LM_ERR_PkgBadName);
return 0; return 0;
}
data->name = strdup(section); data->name = strdup(section);
} }
@ -24,8 +26,10 @@ int lm_package_data_handler(void *_data, const char *_section, const char *_key,
data->desc = strdup(value); data->desc = strdup(value);
else if(eq(key, PKG_DATA_VERSION)){ else if(eq(key, PKG_DATA_VERSION)){
if(!package_version_valid(value)) if(!package_version_valid(value)){
lm_error_set(LM_ERR_PkgBadVersion);
return 0; return 0;
}
data->version = strdup(value); data->version = strdup(value);
} }
@ -47,13 +51,26 @@ int lm_package_data_handler(void *_data, const char *_section, const char *_key,
bool lm_package_data_load(lm_pkg_data_t *data, char *file){ bool lm_package_data_load(lm_pkg_data_t *data, char *file){
lm_package_data_free(data); lm_package_data_free(data);
lm_error_clear();
if (ini_parse(file, lm_package_data_handler, data) < 0) { if (ini_parse(file, lm_package_data_handler, data) < 0) {
lm_error_set(LM_ERR_PkgDataBad); lm_error_set(LM_ERR_PkgDataBad);
return false; return false;
} }
return true; if(LM_ERR_NoError != lm_error())
return false;
if(NULL == data->name)
lm_error_set(LM_ERR_PkgDataMissing, "name");
else if(NULL == data->desc)
lm_error_set(LM_ERR_PkgDataMissing, "desc");
else if(NULL == data->version)
lm_error_set(LM_ERR_PkgDataMissing, "version");
else if(0 == data->size)
lm_error_set(LM_ERR_PkgDataMissing, "size");
return LM_ERR_NoError == lm_error();
} }
void lm_package_data_free(lm_pkg_data_t *data){ void lm_package_data_free(lm_pkg_data_t *data){
@ -62,5 +79,5 @@ void lm_package_data_free(lm_pkg_data_t *data){
free(data->version); free(data->version);
lm_package_data_depend_free(data); lm_package_data_depend_free(data);
lm_package_data_keep_free(data); lm_package_data_keep_free(data);
bzero(&data, sizeof(lm_pkg_data_t)); bzero(data, sizeof(lm_pkg_data_t));
} }

View File

@ -89,7 +89,7 @@ bool lm_pool_info_download(lm_pool_t *pool, lm_mptp_transfer_callback_t callback
return false; return false;
} }
if(!mkdir_ifnot(pool->dir)){ if(!mkdir_ifnot(pool->dir, 0755)){
lm_error_set(LM_ERR_PoolBadDir); lm_error_set(LM_ERR_PoolBadDir);
return false; return false;
} }

View File

@ -30,12 +30,12 @@ bool lm_pool_list_load(lm_pool_t *pool, char *dir){
pdebug(__func__, "(%s) extracting pool to %s", pool->name, dir); pdebug(__func__, "(%s) extracting pool to %s", pool->name, dir);
if(!mkdir_ifnot(pool->dir)){ if(!mkdir_ifnot(pool->dir, 0755)){
lm_error_set(LM_ERR_PoolBadDir); lm_error_set(LM_ERR_PoolBadDir);
return false; return false;
} }
if(!mkdir_ifnot(dir)){ if(!mkdir_ifnot(dir, 0755)){
lm_error_set(LM_ERR_PoolListBadDir); lm_error_set(LM_ERR_PoolListBadDir);
return false; return false;
} }
@ -64,15 +64,23 @@ bool lm_pool_list_load(lm_pool_t *pool, char *dir){
lm_pkg_t *pkg = lm_package_new(); lm_pkg_t *pkg = lm_package_new();
if(!lm_package_data_load(&pkg->data, datap)){ if(!lm_package_data_load(&pkg->data, datap)){
pdebug(__func__, "(%s) failed to load new package from %s", pool->name, datap); pdebug(__func__, "(%s) failed to load new package from %s: %s", pool->name, datap, lm_strerror());
if(NULL != pkg->data.name){
char *suberr = lm_strerror_dup();
lm_error_set(LM_ERR_PoolListDataFail, pkg->data.name, suberr);
free(suberr);
}
lm_package_free(pkg); lm_package_free(pkg);
continue; goto end;
} }
if(!lm_pool_package_add(pool, pkg)){ if(!lm_pool_package_add(pool, pkg)){
pdebug(__func__, "(%s) failed to add new package: %s", pool->name, pkg->data.name); pdebug(__func__, "(%s) failed to add package %s: %s", pool->name, pkg->data.name, lm_strerror());
char *suberr = lm_strerror_dup();
lm_error_set(LM_ERR_PoolListAddFail, pkg->data.name, suberr);
free(suberr);
lm_package_free(pkg); lm_package_free(pkg);
continue; goto end;
} }
pdebug(__func__, "(%s) added new package: %s", pool->name, pkg->data.name); pdebug(__func__, "(%s) added new package: %s", pool->name, pkg->data.name);
@ -102,7 +110,7 @@ bool lm_pool_list_download(lm_pool_t *pool, char *dir, lm_mptp_transfer_callback
return false; return false;
} }
if(!mkdir_ifnot(pool->dir)){ if(!mkdir_ifnot(pool->dir, 0755)){
lm_error_set(LM_ERR_PoolBadDir); lm_error_set(LM_ERR_PoolBadDir);
return false; return false;
} }

View File

@ -17,7 +17,7 @@ bool lm_pool_path_set_dir(lm_pool_t *pool, char *dir){
if(NULL == dir) if(NULL == dir)
return true; return true;
if(exists(dir, NULL) && (is_file(dir) || !can_read(dir) || !can_write(dir))){ if(exists(dir, NULL) && (is_file(dir) || !can_read(dir))){
lm_error_set(LM_ERR_PoolBadDir); lm_error_set(LM_ERR_PoolBadDir);
return false; return false;
} }
@ -26,12 +26,12 @@ bool lm_pool_path_set_dir(lm_pool_t *pool, char *dir){
pool->info_file = join_alloc(dir, "INFO"); pool->info_file = join_alloc(dir, "INFO");
pool->list_file = join_alloc(dir, "LIST"); pool->list_file = join_alloc(dir, "LIST");
if(exists(pool->info_file, NULL) && (!is_file(pool->info_file) || !can_read(pool->info_file) || !can_write(pool->info_file))){ if(exists(pool->info_file, NULL) && (!is_file(pool->info_file) || !can_read(pool->info_file))){
lm_error_set(LM_ERR_PoolBadPaths); lm_error_set(LM_ERR_PoolBadPaths);
return false; return false;
} }
if(exists(pool->list_file, NULL) && (!is_file(pool->list_file) || !can_read(pool->list_file) || !can_write(pool->list_file))){ if(exists(pool->list_file, NULL) && (!is_file(pool->list_file) || !can_read(pool->list_file))){
lm_error_set(LM_ERR_PoolBadPaths); lm_error_set(LM_ERR_PoolBadPaths);
return false; return false;
} }

View File

@ -278,20 +278,12 @@ bool can_write(char *path) {
return access(path, W_OK) == 0; return access(path, W_OK) == 0;
} }
bool mkdir_ifnot(char *path) { bool mkdir_ifnot(char *path, int mode) {
return !(mkdir(path, 0700) < 0 && errno != EEXIST); return !(mkdir(path, mode) < 0 && errno != EEXIST);
} }
bool package_name_valid(char *name) { bool __package_field_valid(char *field) {
for (char *c = name; *c != 0; c++) { for (char *c = field; *c != 0; c++) {
if (!is_digit(*c) && !is_letter(*c) && *c != '-' && *c != '.')
return false;
}
return true;
}
bool package_version_valid(char *version) {
for (char *c = version; *c != 0; c++) {
if (!is_digit(*c) && !is_letter(*c) && *c != '-' && *c != '+' && *c != '.') if (!is_digit(*c) && !is_letter(*c) && *c != '-' && *c != '+' && *c != '.')
return false; return false;
} }