update: refactoring and small fixes
This commit is contained in:
parent
3f794e1a90
commit
9cd4eb9905
@ -6,11 +6,11 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
int ret = EXIT_FAILURE;
|
int ret = EXIT_FAILURE;
|
||||||
lm_pkg_t pkg;
|
lm_entry_t entry;
|
||||||
lm_ctx_t ctx;
|
lm_ctx_t ctx;
|
||||||
|
|
||||||
lm_package_init(&pkg);
|
lm_entry_init(&entry);
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
printf("usage: %s <package name>\n", argv[0]);
|
printf("usage: %s <package name>\n", argv[0]);
|
||||||
@ -34,14 +34,14 @@ int main(int argc, char *argv[]) {
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lm_ctx_database_find(&ctx, &pkg, argv[1], NULL)) {
|
if (!lm_ctx_database_find(&ctx, &entry, argv[1], NULL)) {
|
||||||
printf("failed to find package: %s (%d)\n", lm_strerror(), lm_error());
|
printf("failed to find package: %s (%d)\n", lm_strerror(), lm_error());
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("checking %s (%s)...\n", pkg.name, pkg.version);
|
printf("checking %s (%s)...\n", entry.name, entry.version);
|
||||||
|
|
||||||
if (!lm_ctx_check(&ctx, &pkg, NULL, NULL)) {
|
if (!lm_ctx_check(&ctx, &entry, NULL, NULL)) {
|
||||||
printf("failed to verify the package: %s (%d)\n", lm_strerror(), lm_error());
|
printf("failed to verify the package: %s (%d)\n", lm_strerror(), lm_error());
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ int main(int argc, char *argv[]) {
|
|||||||
ret = EXIT_SUCCESS;
|
ret = EXIT_SUCCESS;
|
||||||
|
|
||||||
end:
|
end:
|
||||||
lm_package_free(&pkg);
|
lm_entry_free(&entry);
|
||||||
lm_ctx_free(&ctx);
|
lm_ctx_free(&ctx);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ int main(int argc, char *argv[]) {
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("resolving package: %s (%s)...\n", pkg->name, pkg->version);
|
printf("resolving package: %s (%s)...\n", pkg->data.name, pkg->data.version);
|
||||||
|
|
||||||
if ((list = lm_ctx_resolve(&ctx, pkg, NULL)) == NULL) {
|
if ((list = lm_ctx_resolve(&ctx, pkg, NULL)) == NULL) {
|
||||||
printf("failed to resolve package: %s (%d)\n", lm_strerror(), lm_error());
|
printf("failed to resolve package: %s (%d)\n", lm_strerror(), lm_error());
|
||||||
@ -59,7 +59,7 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while ((cur = lm_ctx_resolve_next(list)) != NULL) {
|
while ((cur = lm_ctx_resolve_next(list)) != NULL) {
|
||||||
printf("downloading package: %s (%s)...\n", cur->name, cur->version);
|
printf("downloading package: %s (%s)...\n", cur->data.name, cur->data.version);
|
||||||
if (!lm_ctx_download(&ctx, cur, NULL, NULL)) {
|
if (!lm_ctx_download(&ctx, cur, NULL, NULL)) {
|
||||||
printf("failed to download package: %s (%d)\n", lm_strerror(), lm_error());
|
printf("failed to download package: %s (%d)\n", lm_strerror(), lm_error());
|
||||||
goto end;
|
goto end;
|
||||||
@ -67,8 +67,8 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while ((cur = lm_ctx_resolve_next(list)) != NULL) {
|
while ((cur = lm_ctx_resolve_next(list)) != NULL) {
|
||||||
printf("installing package: %s (%s)...\n", cur->name, cur->version);
|
printf("installing package: %s (%s)...\n", cur->data.name, cur->data.version);
|
||||||
if (!lm_ctx_install(&ctx, cur, NULL, NULL)) {
|
if (!lm_ctx_install(&ctx, cur, false, NULL, NULL)) {
|
||||||
printf("failed to install the package: %s (%d)\n", lm_strerror(), lm_error());
|
printf("failed to install the package: %s (%d)\n", lm_strerror(), lm_error());
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,11 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
lm_ctx_t ctx;
|
lm_ctx_t ctx;
|
||||||
lm_pkg_t pkg;
|
lm_entry_t entry;
|
||||||
int ret = EXIT_FAILURE;
|
int ret = EXIT_FAILURE;
|
||||||
|
|
||||||
|
lm_entry_init(&entry);
|
||||||
lm_ctx_init(&ctx);
|
lm_ctx_init(&ctx);
|
||||||
|
|
||||||
if (!lm_ctx_set_data(&ctx, DATA_DIR)) {
|
if (!lm_ctx_set_data(&ctx, DATA_DIR)) {
|
||||||
@ -19,10 +20,10 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
printf("listing installed packages:\n");
|
printf("listing installed packages:\n");
|
||||||
|
|
||||||
while (lm_ctx_database_next(&ctx, &pkg))
|
while (lm_ctx_database_next(&ctx, &entry))
|
||||||
printf("%s (%s)\n", pkg.name, pkg.version);
|
printf("%s (%s)\n", entry.name, entry.version);
|
||||||
|
|
||||||
end:
|
end:
|
||||||
lm_ctx_database_next_free(&ctx, &pkg);
|
lm_ctx_database_next_free(&ctx, &entry);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,11 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
int ret = EXIT_FAILURE;
|
int ret = EXIT_FAILURE;
|
||||||
lm_pkg_t pkg;
|
lm_entry_t entry;
|
||||||
lm_ctx_t ctx;
|
lm_ctx_t ctx;
|
||||||
|
|
||||||
lm_package_init(&pkg);
|
lm_entry_init(&entry);
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
printf("usage: %s <package name>\n", argv[0]);
|
printf("usage: %s <package name>\n", argv[0]);
|
||||||
@ -39,19 +39,19 @@ int main(int argc, char *argv[]) {
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lm_ctx_database_find(&ctx, &pkg, argv[1], NULL)) {
|
if (!lm_ctx_database_find(&ctx, &entry, argv[1], NULL)) {
|
||||||
printf("failed to find package: %s (%d)\n", lm_strerror(), lm_error());
|
printf("failed to find package: %s (%d)\n", lm_strerror(), lm_error());
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lm_ctx_removeable(&ctx, &pkg)) {
|
if (!lm_ctx_removeable(&ctx, &entry)) {
|
||||||
printf("cannot remove package: %s (%d)", lm_strerror(), lm_error());
|
printf("cannot remove package: %s (%d)\n", lm_strerror(), lm_error());
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("removing package: %s (%s)...\n", pkg.name, pkg.version);
|
printf("removing package: %s (%s)...\n", entry.name, entry.version);
|
||||||
|
|
||||||
if (!lm_ctx_remove(&ctx, &pkg, NULL, NULL)) {
|
if (!lm_ctx_remove(&ctx, &entry, NULL, NULL)) {
|
||||||
printf("failed to remove package: %s (%d)\n", lm_strerror(), lm_error());
|
printf("failed to remove package: %s (%d)\n", lm_strerror(), lm_error());
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ int main(int argc, char *argv[]) {
|
|||||||
ret = EXIT_SUCCESS;
|
ret = EXIT_SUCCESS;
|
||||||
|
|
||||||
end:
|
end:
|
||||||
lm_package_free(&pkg);
|
lm_entry_free(&entry);
|
||||||
lm_ctx_free(&ctx);
|
lm_ctx_free(&ctx);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,9 @@
|
|||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
lm_ctx_update_list_t *list = NULL;
|
lm_ctx_update_list_t *list = NULL;
|
||||||
int ret = EXIT_FAILURE;
|
int ret = EXIT_FAILURE;
|
||||||
lm_pkg_t pkg, *old = NULL, *new = NULL;
|
lm_pkg_t *new = NULL;
|
||||||
lm_ctx_t ctx;
|
lm_entry_t *old = NULL;
|
||||||
|
lm_ctx_t ctx;
|
||||||
|
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
printf("usage: %s <pool name> <pool url>\n", argv[0]);
|
printf("usage: %s <pool name> <pool url>\n", argv[0]);
|
||||||
@ -74,7 +75,7 @@ int main(int argc, char *argv[]) {
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lm_ctx_install(&ctx, new, NULL, NULL)) {
|
if (!lm_ctx_install(&ctx, new, false, NULL, NULL)) {
|
||||||
printf("failed to install new package: %s", lm_strerror());
|
printf("failed to install new package: %s", lm_strerror());
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
@ -27,5 +27,4 @@
|
|||||||
#include "ctx.h"
|
#include "ctx.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "pool.h"
|
#include "pool.h"
|
||||||
#include "types.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
#include "mptp.h"
|
#include "mptp.h"
|
||||||
#include "types.h"
|
#include "pool.h"
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
@ -18,13 +18,12 @@ typedef struct lm_ctx_resolve_list {
|
|||||||
lm_pkg_t *resolving;
|
lm_pkg_t *resolving;
|
||||||
lm_pkg_t *packages;
|
lm_pkg_t *packages;
|
||||||
lm_pkg_t *cur;
|
lm_pkg_t *cur;
|
||||||
size_t count;
|
ssize_t count;
|
||||||
} lm_ctx_resolve_list_t;
|
} lm_ctx_resolve_list_t;
|
||||||
|
|
||||||
typedef struct lm_ctx_update_list {
|
typedef struct lm_ctx_update_list {
|
||||||
lm_pkg_t *packages;
|
lm_entry_t **entries;
|
||||||
lm_pkg_t *cur;
|
ssize_t index, count;
|
||||||
size_t count;
|
|
||||||
} lm_ctx_update_list_t;
|
} lm_ctx_update_list_t;
|
||||||
|
|
||||||
typedef enum lm_ctx_sync_state {
|
typedef enum lm_ctx_sync_state {
|
||||||
@ -48,8 +47,9 @@ typedef bool (*lm_ctx_sync_callback_t)(
|
|||||||
lm_ctx_t *ctx, lm_pool_t *pool, lm_ctx_sync_state_t state, size_t current, size_t total, void *data);
|
lm_ctx_t *ctx, lm_pool_t *pool, lm_ctx_sync_state_t state, size_t current, size_t total, void *data);
|
||||||
typedef bool (*lm_ctx_serve_callback_t)(lm_pool_t *pool, lm_mptp_t *packet, struct sockaddr *addr, void *data);
|
typedef bool (*lm_ctx_serve_callback_t)(lm_pool_t *pool, lm_mptp_t *packet, struct sockaddr *addr, void *data);
|
||||||
typedef bool (*lm_ctx_ping_callback_t)(lm_ctx_t *ctx, lm_pool_t *pool, bool status, void *data);
|
typedef bool (*lm_ctx_ping_callback_t)(lm_ctx_t *ctx, lm_pool_t *pool, bool status, void *data);
|
||||||
typedef lm_ctx_install_callback_t lm_ctx_remove_callback_t;
|
typedef bool (*lm_ctx_remove_callback_t)(
|
||||||
typedef lm_ctx_install_callback_t lm_ctx_check_callback_t;
|
lm_ctx_t *ctx, lm_entry_t *pkg, char *file, size_t current, size_t total, void *data);
|
||||||
|
typedef lm_ctx_remove_callback_t lm_ctx_check_callback_t;
|
||||||
|
|
||||||
/* ###############
|
/* ###############
|
||||||
## ctx stuff ##
|
## ctx stuff ##
|
||||||
@ -68,21 +68,21 @@ lm_ctx_resolve_list_t *lm_ctx_resolve(
|
|||||||
lm_pkg_t *lm_ctx_resolve_next(lm_ctx_resolve_list_t *list); // returns the next package in the list
|
lm_pkg_t *lm_ctx_resolve_next(lm_ctx_resolve_list_t *list); // returns the next package in the list
|
||||||
void lm_ctx_resolve_free(lm_ctx_resolve_list_t *list); // frees the resolved list returned by lm_ctx_resolve
|
void lm_ctx_resolve_free(lm_ctx_resolve_list_t *list); // frees the resolved list returned by lm_ctx_resolve
|
||||||
|
|
||||||
lm_ctx_update_list_t *lm_ctx_update_list(lm_ctx_t *ctx); // get a list of packages to update
|
lm_ctx_update_list_t *lm_ctx_update_list(lm_ctx_t *ctx); // get a list of entries to update
|
||||||
lm_pkg_t *lm_ctx_update_list_next(lm_ctx_update_list_t *list); // get the next package in the update list
|
lm_entry_t *lm_ctx_update_list_next(lm_ctx_update_list_t *list); // get the next entry in the update list
|
||||||
void lm_ctx_update_list_free(lm_ctx_update_list_t *list); // free the update list
|
void lm_ctx_update_list_free(lm_ctx_update_list_t *list); // free the update list
|
||||||
lm_pkg_t *lm_ctx_update(lm_ctx_t *ctx, lm_pkg_t *pkg); // returns the updated version of a package
|
lm_pkg_t *lm_ctx_update(lm_ctx_t *ctx, lm_entry_t *pkg); // returns the updated version of a entry
|
||||||
|
|
||||||
bool lm_ctx_removeable(lm_ctx_t *ctx, lm_pkg_t *pkg); // checks if a package is available for removal
|
bool lm_ctx_removeable(lm_ctx_t *ctx, lm_entry_t *entry); // checks if a package is available for removal
|
||||||
bool lm_ctx_remove(
|
bool lm_ctx_remove(
|
||||||
lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_remove_callback_t callback, void *data); // removes a single package
|
lm_ctx_t *ctx, lm_entry_t *entry, lm_ctx_remove_callback_t callback, void *data); // removes a single package
|
||||||
|
|
||||||
bool lm_ctx_download(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_download_callback_t callback,
|
bool lm_ctx_download(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_download_callback_t callback,
|
||||||
void *data); // downloads a single package
|
void *data); // downloads a single package
|
||||||
bool lm_ctx_install(
|
bool lm_ctx_install(lm_ctx_t *ctx, lm_pkg_t *pkg, bool run_install, lm_ctx_install_callback_t callback,
|
||||||
lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_install_callback_t callback, 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_pkg_t *pkg, 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
|
size_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(
|
bool lm_ctx_serve(
|
||||||
@ -102,9 +102,9 @@ lm_pool_t *lm_ctx_pool_by_url(lm_ctx_t *ctx, char *host, char *path); // find p
|
|||||||
## database fucntions ##
|
## database fucntions ##
|
||||||
######################## */
|
######################## */
|
||||||
bool lm_ctx_database_init(lm_ctx_t *ctx); // init ctx database (if not already present)
|
bool lm_ctx_database_init(lm_ctx_t *ctx); // init ctx database (if not already present)
|
||||||
bool lm_ctx_database_is_installed(lm_ctx_t *ctx, lm_pkg_t *pkg, bool check_version); // check if a package is installed
|
bool lm_ctx_database_is_installed(lm_ctx_t *ctx, char *name, char *version); // check if a package is installed
|
||||||
bool lm_ctx_database_find(lm_ctx_t *ctx, lm_pkg_t *pkg, char *name, char *version); // find a package by name
|
bool lm_ctx_database_find(lm_ctx_t *ctx, lm_entry_t *entry, char *name, char *version); // find a package by name
|
||||||
bool lm_ctx_database_next(lm_ctx_t *ctx, lm_pkg_t *pkg); // load the next package into pkg pointer
|
bool lm_ctx_database_next(lm_ctx_t *ctx, lm_entry_t *entry); // load the next package into pkg pointer
|
||||||
bool lm_ctx_database_next_free(lm_ctx_t *ctx, lm_pkg_t *pkg); // free the used next pointers
|
bool lm_ctx_database_next_free(lm_ctx_t *ctx, lm_entry_t *entry); // free the used next pointers
|
||||||
char *lm_ctx_database_changes(
|
char *lm_ctx_database_changes(
|
||||||
lm_ctx_t *ctx, lm_pkg_t *pkg); // get changes file path for a package, FREE THE RETURNED POINTER
|
lm_ctx_t *ctx, lm_entry_t *entry); // get changes file path for a package, FREE THE RETURNED POINTER
|
||||||
|
@ -1,78 +1,86 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "database.h"
|
||||||
#include "package.h"
|
#include "package.h"
|
||||||
|
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
#define HASH_LEN 32
|
#define HASH_LEN 32
|
||||||
|
|
||||||
enum lm_query_index {
|
enum lm_query_index {
|
||||||
QUERY_CREATE_PACKAGE_TABLE = 0,
|
QUERY_CREATE_ENTRY_TABLE = 0,
|
||||||
QUERY_INSERT_PACKAGE_SINGLE = 1,
|
QUERY_INSERT_ENTRY_SINGLE = 1,
|
||||||
QUERY_SELECT_PACKAGE_SINGLE_1 = 2,
|
QUERY_SELECT_ENTRY_SINGLE_1 = 2,
|
||||||
QUERY_SELECT_PACKAGE_SINGLE_2 = 3,
|
QUERY_SELECT_ENTRY_SINGLE_2 = 3,
|
||||||
QUERY_DELETE_PACKAGE_SINGLE = 4,
|
QUERY_DELETE_ENTRY_SINGLE = 4,
|
||||||
QUERY_SELECT_PACKAGE_ALL = 5,
|
QUERY_SELECT_ENTRY_ALL = 5,
|
||||||
QUERY_CREATE_FILE_TABLE = 6,
|
QUERY_CREATE_FILE_TABLE = 6,
|
||||||
QUERY_INSERT_FILE_SINGLE = 7,
|
QUERY_INSERT_FILE_SINGLE = 7,
|
||||||
QUERY_DELETE_FILE_ALL = 8,
|
QUERY_DELETE_FILE_ALL = 8,
|
||||||
QUERY_SELECT_FILE_SINGLE = 9,
|
QUERY_SELECT_FILE_SINGLE = 9,
|
||||||
QUERY_SELECT_FILE_ALL = 10,
|
QUERY_SELECT_FILE_ALL = 10,
|
||||||
QUERY_UPDATE_FILE_1 = 11,
|
QUERY_UPDATE_FILE_1 = 11,
|
||||||
QUERY_UPDATE_FILE_2 = 12,
|
QUERY_UPDATE_FILE_2 = 12,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum lm_columns {
|
enum lm_columns {
|
||||||
FILES_COLUMN_PATH = 1,
|
FILES_COLUMN_PATH = 1,
|
||||||
FILES_COLUMN_HASH = 2,
|
FILES_COLUMN_HASH = 2,
|
||||||
FILES_COLUMN_KEEP = 3,
|
FILES_COLUMN_KEEP = 3,
|
||||||
FILES_COLUMN_PACKAGE = 4,
|
FILES_COLUMN_ENTRY = 4,
|
||||||
|
|
||||||
PACKAGES_COLUMN_NAME = 1,
|
ENTRIES_COLUMN_NAME = 1,
|
||||||
PACKAGES_COLUMN_VERSION = 2,
|
ENTRIES_COLUMN_VERSION = 2,
|
||||||
PACKAGES_COLUMN_DESC = 3,
|
ENTRIES_COLUMN_DESC = 3,
|
||||||
PACKAGES_COLUMN_SIZE = 4,
|
ENTRIES_COLUMN_SIZE = 4,
|
||||||
PACKAGES_COLUMN_DEPENDS = 5,
|
ENTRIES_COLUMN_DEPENDS = 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
extern char *queries[];
|
extern char *queries[];
|
||||||
|
|
||||||
|
typedef lm_pkg_data_t lm_entry_t;
|
||||||
|
|
||||||
typedef struct lm_database {
|
typedef struct lm_database {
|
||||||
sqlite3 *packages_db;
|
sqlite3 *entries_db;
|
||||||
sqlite3_stmt *packages_st;
|
sqlite3_stmt *entries_st;
|
||||||
|
|
||||||
sqlite3 *files_db;
|
sqlite3 *files_db;
|
||||||
sqlite3_stmt *files_st;
|
sqlite3_stmt *files_st;
|
||||||
|
|
||||||
lm_pkg_t *pkg;
|
char *dir;
|
||||||
char *dir;
|
|
||||||
} lm_database_t;
|
} lm_database_t;
|
||||||
|
|
||||||
|
void lm_entry_init(lm_entry_t *entry);
|
||||||
|
void lm_entry_free(lm_entry_t *entry);
|
||||||
|
|
||||||
lm_database_t *lm_database_new(char *path);
|
lm_database_t *lm_database_new(char *path);
|
||||||
void lm_database_free(lm_database_t *db);
|
void lm_database_free(lm_database_t *db);
|
||||||
bool lm_database_step_all(sqlite3_stmt *st);
|
bool lm_database_step_all(sqlite3_stmt *st);
|
||||||
|
|
||||||
bool lm_database_package_find(
|
bool lm_database_entry_find(
|
||||||
lm_database_t *db, lm_pkg_t *pkg, char *name, char *version); // finds a package by its name, package stored in *pkg
|
lm_database_t *db, lm_entry_t *out, char *name, char *version); // finds a entry by its name, entry stored in *pkg
|
||||||
bool lm_database_package_next(lm_database_t *db, lm_pkg_t *pkg); // gets the next package in the database
|
bool lm_database_entry_next(lm_database_t *db, lm_entry_t *entry); // gets the next entry in the database
|
||||||
bool lm_database_package_add(lm_database_t *db, lm_pkg_t *pkg); // adds a package to the database
|
bool lm_database_entry_add(lm_database_t *db, lm_entry_t *entry); // adds a entry to the database
|
||||||
bool lm_database_package_del(lm_database_t *db, lm_pkg_t *pkg); // delete a package from the database
|
bool lm_database_entry_del(lm_database_t *db, lm_entry_t *entry); // delete a entry from the database
|
||||||
void lm_database_package_next_free(
|
void lm_database_entry_next_free(
|
||||||
lm_database_t *db, lm_pkg_t *pkg); // frees resources used for lm_database_package_next
|
lm_database_t *db, lm_entry_t *entry); // frees resources used for lm_database_entry_next
|
||||||
|
|
||||||
size_t lm_database_files_count(
|
ssize_t lm_database_files_count(
|
||||||
lm_database_t *db, lm_pkg_t *pkg); // returns the count of files associated with a package
|
lm_database_t *db, lm_entry_t *entry); // returns the count of files associated with a entry
|
||||||
bool lm_database_files_contains(
|
bool lm_database_files_contains(
|
||||||
lm_database_t *db, lm_pkg_t *pkg, char *path); // check if a package contains the given file
|
lm_database_t *db, lm_entry_t *entry, char *path); // check if a entry contains the given file
|
||||||
bool lm_database_files_matches(
|
bool lm_database_files_matches(
|
||||||
lm_database_t *db, char *path, char *hash); // checks if the given file matches with the given hash
|
lm_database_t *db, char *path, char *hash); // checks if the given file matches with the given hash
|
||||||
bool lm_database_files_iskeep(lm_database_t *db, char *path); // checks if the given file is marked as keep
|
bool lm_database_files_iskeep(lm_database_t *db, char *path); // checks if the given file is marked as keep
|
||||||
bool lm_database_files_next(
|
bool lm_database_files_next(
|
||||||
lm_database_t *db, lm_pkg_t *pkg, char **path, char **hash, bool *keep); // gets the next file of the package
|
lm_database_t *db, lm_entry_t *entry, char **path, char **hash, bool *keep); // gets the next file of the entry
|
||||||
bool lm_database_files_add(
|
bool lm_database_files_add(
|
||||||
lm_database_t *db, lm_pkg_t *pkg, char *path, char *hash); // adds a file to the files database
|
lm_database_t *db, lm_entry_t *entry, char *path, char *hash); // adds a file to the files database
|
||||||
bool lm_database_files_del(lm_database_t *db, lm_pkg_t *pkg); // dels all files of belonging to a package
|
bool lm_database_files_del(lm_database_t *db, lm_entry_t *entry); // dels all files of belonging to a entry
|
||||||
void lm_database_files_next_free(lm_database_t *db, lm_pkg_t *pkg, char **path, char **hash,
|
void lm_database_files_next_free(lm_database_t *db, lm_entry_t *entry, char **path, char **hash,
|
||||||
bool *keep); // frees resources used for lm_database_files_next
|
bool *keep); // frees resources used for lm_database_files_next
|
||||||
|
|
||||||
bool lm_database_changes_update(lm_database_t *db, lm_pkg_t *pkg, char *file);
|
bool lm_database_changes_update(lm_database_t *db, lm_entry_t *entry, char *file);
|
||||||
char *lm_database_changes_get(lm_database_t *db, lm_pkg_t *pkg);
|
char *lm_database_changes_get(lm_database_t *db, lm_entry_t *entry);
|
||||||
bool lm_database_changes_del(lm_database_t *db, lm_pkg_t *pkg);
|
bool lm_database_changes_del(lm_database_t *db, lm_entry_t *entry);
|
||||||
|
@ -131,7 +131,7 @@ typedef enum lm_error {
|
|||||||
LM_ERR_InstallSpawnFail = 123,
|
LM_ERR_InstallSpawnFail = 123,
|
||||||
LM_ERR_InstallBackChdirFail = 124,
|
LM_ERR_InstallBackChdirFail = 124,
|
||||||
LM_ERR_InstallStatusFail = 125,
|
LM_ERR_InstallStatusFail = 125,
|
||||||
LM_ERR_InstallScriptFail = 126,
|
LM_ERR_InstallRunFail = 126,
|
||||||
LM_ERR_PkgBreaks = 127,
|
LM_ERR_PkgBreaks = 127,
|
||||||
LM_ERR_PkgUpToDate = 128,
|
LM_ERR_PkgUpToDate = 128,
|
||||||
LM_ERR_HashOpenFail = 129,
|
LM_ERR_HashOpenFail = 129,
|
||||||
@ -142,6 +142,8 @@ typedef enum lm_error {
|
|||||||
LM_ERR_NoPools = 134,
|
LM_ERR_NoPools = 134,
|
||||||
LM_ERR_DbChangesNotExists = 135,
|
LM_ERR_DbChangesNotExists = 135,
|
||||||
LM_ERR_DbChangesChmodFail = 136,
|
LM_ERR_DbChangesChmodFail = 136,
|
||||||
|
LM_ERR_InstallDirFail = 137,
|
||||||
|
LM_ERR_InstallSaveFail = 138,
|
||||||
} lm_error_t;
|
} lm_error_t;
|
||||||
|
|
||||||
typedef struct lm_error_desc {
|
typedef struct lm_error_desc {
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "types.h"
|
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "types.h"
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
#define PKG_DATA_SIZE "size"
|
#define PKG_DATA_SIZE "size"
|
||||||
#define PKG_DATA_DESC "desc"
|
#define PKG_DATA_DESC "desc"
|
||||||
@ -8,32 +8,46 @@
|
|||||||
#define PKG_DATA_DEPENDS "depends"
|
#define PKG_DATA_DEPENDS "depends"
|
||||||
#define PKG_DATA_KEEPS "keeps"
|
#define PKG_DATA_KEEPS "keeps"
|
||||||
|
|
||||||
|
typedef struct lm_pkg_data {
|
||||||
|
char *name;
|
||||||
|
char *desc;
|
||||||
|
char **depends;
|
||||||
|
char **keeps;
|
||||||
|
char *version;
|
||||||
|
ssize_t size;
|
||||||
|
} lm_pkg_data_t;
|
||||||
|
|
||||||
|
typedef struct lm_pkg {
|
||||||
|
struct lm_pkg_data data;
|
||||||
|
struct lm_pool *pool;
|
||||||
|
struct lm_pkg *next;
|
||||||
|
char *signature;
|
||||||
|
char *archive;
|
||||||
|
} lm_pkg_t;
|
||||||
|
|
||||||
lm_pkg_t *lm_package_new();
|
lm_pkg_t *lm_package_new();
|
||||||
void lm_package_free(lm_pkg_t *pkg);
|
void lm_package_free(lm_pkg_t *pkg);
|
||||||
bool lm_package_verify(lm_pkg_t *pkg);
|
bool lm_package_verify(lm_pkg_t *pkg);
|
||||||
void lm_package_init(lm_pkg_t *pkg);
|
void lm_package_init(lm_pkg_t *pkg);
|
||||||
bool lm_package_copy(lm_pkg_t *dst, lm_pkg_t *src);
|
bool lm_package_downloaded(lm_pkg_t *pkg);
|
||||||
|
bool lm_package_is_same(lm_pkg_t *one, lm_pkg_t *two);
|
||||||
|
|
||||||
bool lm_package_data_load(lm_pkg_t *pkg, char *file);
|
bool lm_package_data_load(lm_pkg_data_t *data, char *file);
|
||||||
void lm_package_data_free(lm_pkg_t *pkg);
|
void lm_package_data_free(lm_pkg_data_t *data);
|
||||||
|
|
||||||
bool lm_package_downloaded(lm_pkg_t *pkg);
|
bool lm_package_data_depend_add(lm_pkg_data_t *data, char *depend);
|
||||||
bool lm_package_depend_add(lm_pkg_t *pkg, char *depend);
|
ssize_t lm_package_data_depend_count(lm_pkg_data_t *data);
|
||||||
size_t lm_package_depend_count(lm_pkg_t *pkg);
|
ssize_t lm_package_data_depend_strlen(lm_pkg_data_t *data);
|
||||||
size_t lm_package_depend_strlen(lm_pkg_t *pkg);
|
char *lm_package_data_depend_tostr(lm_pkg_data_t *data, char *buffer);
|
||||||
char *lm_package_depend_tostr(lm_pkg_t *pkg, char *buffer);
|
bool lm_package_data_depend_fromstr(lm_pkg_data_t *data, char *buffer);
|
||||||
bool lm_package_depend_fromstr(lm_pkg_t *pkg, char *buffer);
|
void lm_package_data_depend_free(lm_pkg_data_t *data);
|
||||||
void lm_package_depend_free(lm_pkg_t *pkg);
|
bool lm_package_data_depends(lm_pkg_data_t *data, char *dep);
|
||||||
bool lm_package_depends(lm_pkg_t *pkg, char *dep);
|
|
||||||
|
|
||||||
size_t lm_package_keep_count(lm_pkg_t *pkg);
|
size_t lm_package_data_keep_count(lm_pkg_data_t *data);
|
||||||
bool lm_package_keep_add(lm_pkg_t *pkg, char *path);
|
bool lm_package_data_keep_add(lm_pkg_data_t *data, char *path);
|
||||||
bool lm_package_keep_contains(lm_pkg_t *pkg, char *path);
|
bool lm_package_data_keep_contains(lm_pkg_data_t *data, char *path);
|
||||||
void lm_package_keep_free(lm_pkg_t *pkg);
|
void lm_package_data_keep_free(lm_pkg_data_t *data);
|
||||||
|
|
||||||
bool lm_package_path_set_signature(lm_pkg_t *pkg, char *signature_path);
|
bool lm_package_path_set_signature(lm_pkg_t *pkg, char *signature_path);
|
||||||
bool lm_package_path_set_archive(lm_pkg_t *pkg, char *archive_path);
|
bool lm_package_path_set_archive(lm_pkg_t *pkg, char *archive_path);
|
||||||
bool lm_package_path_is_empty(lm_pkg_t *pkg);
|
bool lm_package_path_is_empty(lm_pkg_t *pkg);
|
||||||
void lm_package_path_free(lm_pkg_t *pkg);
|
|
||||||
bool lm_package_path_copy(lm_pkg_t *dst, lm_pkg_t *src);
|
|
||||||
bool lm_package_is_same(lm_pkg_t *one, lm_pkg_t *two);
|
|
||||||
|
@ -1,10 +1,30 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "mptp.h"
|
#include "mptp.h"
|
||||||
#include "types.h"
|
#include "package.h"
|
||||||
|
#include "url.h"
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
typedef struct lm_pool_info {
|
||||||
|
char *maintainer;
|
||||||
|
char *pubkey;
|
||||||
|
ssize_t size;
|
||||||
|
} lm_pool_info_t;
|
||||||
|
|
||||||
|
typedef struct lm_pool {
|
||||||
|
struct lm_pool *next;
|
||||||
|
lm_pool_info_t info;
|
||||||
|
lm_url_t url;
|
||||||
|
lm_pkg_t *pkg;
|
||||||
|
char *name;
|
||||||
|
char *info_file;
|
||||||
|
char *list_file;
|
||||||
|
char *list_dir;
|
||||||
|
char *dir;
|
||||||
|
bool available, loaded;
|
||||||
|
} lm_pool_t;
|
||||||
|
|
||||||
#define POOL_INFO_SIZE "size"
|
#define POOL_INFO_SIZE "size"
|
||||||
#define POOL_INFO_PUBKEY "pubkey"
|
#define POOL_INFO_PUBKEY "pubkey"
|
||||||
#define POOL_INFO_MAINTAINER "maintainer"
|
#define POOL_INFO_MAINTAINER "maintainer"
|
||||||
@ -18,7 +38,6 @@ bool lm_pool_package_add(lm_pool_t *pool, lm_pkg_t *pkg);
|
|||||||
|
|
||||||
bool lm_pool_path_set_dir(lm_pool_t *pool, char *dir);
|
bool lm_pool_path_set_dir(lm_pool_t *pool, char *dir);
|
||||||
bool lm_pool_path_is_empty(lm_pool_t *pool);
|
bool lm_pool_path_is_empty(lm_pool_t *pool);
|
||||||
void lm_pool_path_free(lm_pool_t *pool);
|
|
||||||
|
|
||||||
bool lm_pool_info_download(lm_pool_t *pool, lm_mptp_transfer_callback_t callback, void *data);
|
bool lm_pool_info_download(lm_pool_t *pool, lm_mptp_transfer_callback_t callback, void *data);
|
||||||
bool lm_pool_info_load(lm_pool_t *pool);
|
bool lm_pool_info_load(lm_pool_t *pool);
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "url.h"
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
typedef struct lm_pkg_file {
|
|
||||||
char *path;
|
|
||||||
char *hash;
|
|
||||||
} lm_pkg_file_t;
|
|
||||||
|
|
||||||
typedef struct lm_pkg_path {
|
|
||||||
char *archive;
|
|
||||||
char *signature;
|
|
||||||
} lm_pkg_path_t;
|
|
||||||
|
|
||||||
typedef struct lm_pkg {
|
|
||||||
struct lm_pool *pool;
|
|
||||||
struct lm_pkg *next;
|
|
||||||
lm_pkg_path_t paths;
|
|
||||||
char *name;
|
|
||||||
char *desc;
|
|
||||||
char **depends;
|
|
||||||
char **keeps;
|
|
||||||
char *version;
|
|
||||||
size_t size;
|
|
||||||
} lm_pkg_t;
|
|
||||||
|
|
||||||
typedef struct lm_pool_info {
|
|
||||||
char *maintainer;
|
|
||||||
char *pubkey;
|
|
||||||
ssize_t size;
|
|
||||||
} lm_pool_info_t;
|
|
||||||
|
|
||||||
typedef struct lm_pool_path {
|
|
||||||
char *info_file;
|
|
||||||
char *list_file;
|
|
||||||
char *list_dir;
|
|
||||||
char *dir;
|
|
||||||
} lm_pool_path_t;
|
|
||||||
|
|
||||||
typedef struct lm_pool {
|
|
||||||
struct lm_pool *next;
|
|
||||||
lm_pool_info_t info;
|
|
||||||
lm_pool_path_t paths;
|
|
||||||
lm_url_t url;
|
|
||||||
lm_pkg_t *pkg;
|
|
||||||
char *name;
|
|
||||||
bool available, loaded;
|
|
||||||
} lm_pool_t;
|
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "types.h"
|
#include "pool.h"
|
||||||
|
|
||||||
#include <archive.h>
|
#include <archive.h>
|
||||||
#include <libintl.h>
|
#include <libintl.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
@ -23,6 +24,7 @@ bool can_read(char *path);
|
|||||||
bool is_file(char *path);
|
bool is_file(char *path);
|
||||||
bool is_dir(char *path);
|
bool is_dir(char *path);
|
||||||
bool exists(char *path);
|
bool exists(char *path);
|
||||||
|
bool is_empty(char *p);
|
||||||
|
|
||||||
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_version_valid(char *name);
|
||||||
|
@ -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-07-19 19:22+0300\n"
|
"POT-Creation-Date: 2024-07-31 21:14+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"
|
||||||
@ -249,11 +249,11 @@ msgid "specified root directory does not have write access"
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/error.c:76
|
#: src/error.c:76
|
||||||
msgid "specified data path does not exist"
|
msgid "specified data path is not a directory"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/error.c:77
|
#: src/error.c:77
|
||||||
msgid "specified data path is not a directory"
|
msgid "specified data directory does not have write access"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/error.c:78
|
#: src/error.c:78
|
||||||
@ -557,45 +557,54 @@ msgstr ""
|
|||||||
|
|
||||||
#: src/error.c:152
|
#: src/error.c:152
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "removing package breaks %s"
|
msgid "failed to save the package install script: %s"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/error.c:153
|
#: src/error.c:153
|
||||||
|
#, c-format
|
||||||
|
msgid "removing package breaks %s"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/error.c:154
|
||||||
#, 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:154
|
#: src/error.c:155
|
||||||
msgid "failed to open file for hashing"
|
msgid "failed to open file for hashing"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/error.c:155
|
|
||||||
msgid "failed create digest for hashing"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: src/error.c:156
|
#: src/error.c:156
|
||||||
#, c-format
|
msgid "failed create digest for hashing"
|
||||||
msgid "failed to get hash of %s: %s"
|
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/error.c:157
|
#: src/error.c:157
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "file hash does not match for %s"
|
msgid "failed to get hash of %s: %s"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/error.c:158
|
#: src/error.c:158
|
||||||
|
#, c-format
|
||||||
|
msgid "file hash does not match for %s"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/error.c:159
|
||||||
#, 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:159
|
#: src/error.c:160
|
||||||
msgid "pool list is empty"
|
msgid "pool list is empty"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/error.c:160
|
#: src/error.c:161
|
||||||
msgid "package changes file not found in the database"
|
msgid "package changes file not found in the database"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/error.c:161
|
#: src/error.c:162
|
||||||
msgid "failed to change mod of the changes file"
|
msgid "failed to change mod of the changes file"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/error.c:163
|
||||||
|
msgid "failed to create install script save directory"
|
||||||
|
msgstr ""
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
bool lm_ctx_check(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_check_callback_t callback, void *data){
|
bool lm_ctx_check(lm_ctx_t *ctx, lm_entry_t *entry, lm_ctx_check_callback_t callback, void *data){
|
||||||
if(NULL == ctx || NULL == pkg){
|
if(NULL == ctx || NULL == entry){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -24,9 +24,9 @@ bool lm_ctx_check(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_check_callback_t callback
|
|||||||
char *path = NULL, *hash = NULL, *fhash = NULL;
|
char *path = NULL, *hash = NULL, *fhash = NULL;
|
||||||
bool keep = false, ret = false;
|
bool keep = false, ret = false;
|
||||||
|
|
||||||
total = lm_database_files_count(ctx->db, pkg);
|
total = lm_database_files_count(ctx->db, entry);
|
||||||
|
|
||||||
while(lm_database_files_next(ctx->db, pkg, &path, &hash, &keep)){
|
while(lm_database_files_next(ctx->db, entry, &path, &hash, &keep)){
|
||||||
char fp[rootlen+strlen(path)+10];
|
char fp[rootlen+strlen(path)+10];
|
||||||
join(fp, ctx->root, path);
|
join(fp, ctx->root, path);
|
||||||
current++;
|
current++;
|
||||||
@ -34,7 +34,7 @@ bool lm_ctx_check(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_check_callback_t callback
|
|||||||
pdebug(__func__, "(%d/%d) checking %s", current, total, fp);
|
pdebug(__func__, "(%d/%d) checking %s", current, total, fp);
|
||||||
|
|
||||||
if(NULL != callback)
|
if(NULL != callback)
|
||||||
if(!callback(ctx, pkg, fp, current, total, data))
|
if(!callback(ctx, entry, fp, current, total, data))
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
if(!exists(fp)){
|
if(!exists(fp)){
|
||||||
@ -61,7 +61,7 @@ bool lm_ctx_check(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_check_callback_t callback
|
|||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
end:
|
end:
|
||||||
lm_database_files_next_free(ctx->db, pkg, &path, &hash, &keep);
|
lm_database_files_next_free(ctx->db, entry, &path, &hash, &keep);
|
||||||
free(fhash);
|
free(fhash);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -21,17 +21,17 @@ bool lm_ctx_database_init(lm_ctx_t *ctx){
|
|||||||
return ctx->db != NULL; // error set by function
|
return ctx->db != NULL; // error set by function
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_ctx_database_is_installed(lm_ctx_t *ctx, lm_pkg_t *pkg, bool check_version){
|
bool lm_ctx_database_is_installed(lm_ctx_t *ctx, char *name, char *version){
|
||||||
if(!lm_ctx_database_init(ctx))
|
if(!lm_ctx_database_init(ctx))
|
||||||
return false; // error set by function
|
return false; // error set by function
|
||||||
|
|
||||||
if(NULL == ctx->db)
|
if(NULL == ctx->db)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return lm_database_package_find(ctx->db, NULL, pkg->name, check_version ? pkg->version : NULL);
|
return lm_database_entry_find(ctx->db, NULL, name, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_ctx_database_find(lm_ctx_t *ctx, lm_pkg_t *pkg, char *name, char *version){
|
bool lm_ctx_database_find(lm_ctx_t *ctx, lm_entry_t *entry, char *name, char *version){
|
||||||
if(NULL == ctx || NULL == name){
|
if(NULL == ctx || NULL == name){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return false;
|
return false;
|
||||||
@ -41,11 +41,11 @@ bool lm_ctx_database_find(lm_ctx_t *ctx, lm_pkg_t *pkg, char *name, char *versio
|
|||||||
return false; // error set by function
|
return false; // error set by function
|
||||||
|
|
||||||
lm_error_clear();
|
lm_error_clear();
|
||||||
return lm_database_package_find(ctx->db, pkg, name, version);
|
return lm_database_entry_find(ctx->db, entry, name, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_ctx_database_next(lm_ctx_t *ctx, lm_pkg_t *pkg){
|
bool lm_ctx_database_next(lm_ctx_t *ctx, lm_entry_t *entry){
|
||||||
if(NULL == ctx || NULL == pkg){
|
if(NULL == ctx || NULL == entry){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -53,11 +53,11 @@ bool lm_ctx_database_next(lm_ctx_t *ctx, lm_pkg_t *pkg){
|
|||||||
if(!lm_ctx_database_init(ctx))
|
if(!lm_ctx_database_init(ctx))
|
||||||
return false; // error set by function
|
return false; // error set by function
|
||||||
|
|
||||||
return lm_database_package_next(ctx->db, pkg);
|
return lm_database_entry_next(ctx->db, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_ctx_database_next_free(lm_ctx_t *ctx, lm_pkg_t *pkg){
|
bool lm_ctx_database_next_free(lm_ctx_t *ctx, lm_entry_t *entry){
|
||||||
if(NULL == ctx || NULL == pkg){
|
if(NULL == ctx || NULL == entry){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -65,12 +65,12 @@ bool lm_ctx_database_next_free(lm_ctx_t *ctx, lm_pkg_t *pkg){
|
|||||||
if(!lm_ctx_database_init(ctx))
|
if(!lm_ctx_database_init(ctx))
|
||||||
return false; // error set by function
|
return false; // error set by function
|
||||||
|
|
||||||
lm_database_package_next_free(ctx->db, pkg);
|
lm_database_entry_next_free(ctx->db, entry);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *lm_ctx_database_changes(lm_ctx_t *ctx, lm_pkg_t *pkg){
|
char *lm_ctx_database_changes(lm_ctx_t *ctx, lm_entry_t *entry){
|
||||||
if(NULL == ctx || NULL == pkg){
|
if(NULL == ctx || NULL == entry){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -78,5 +78,5 @@ char *lm_ctx_database_changes(lm_ctx_t *ctx, lm_pkg_t *pkg){
|
|||||||
if(!lm_ctx_database_init(ctx))
|
if(!lm_ctx_database_init(ctx))
|
||||||
return NULL; // error set by function
|
return NULL; // error set by function
|
||||||
|
|
||||||
return lm_database_changes_get(ctx->db, pkg);
|
return lm_database_changes_get(ctx->db, entry);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ bool __lm_ctx_download_callback(char *path, size_t current, size_t total, void *
|
|||||||
if(NULL == cbdata->callback)
|
if(NULL == cbdata->callback)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if(eq(cbdata->pkg->paths.archive, path))
|
if(eq(cbdata->pkg->archive, path))
|
||||||
return cbdata->callback(cbdata->ctx, cbdata->pkg, true, current, total, cbdata->data);
|
return cbdata->callback(cbdata->ctx, cbdata->pkg, true, current, total, cbdata->data);
|
||||||
else
|
else
|
||||||
return cbdata->callback(cbdata->ctx, cbdata->pkg, false, current, total, cbdata->data);
|
return cbdata->callback(cbdata->ctx, cbdata->pkg, false, current, total, cbdata->data);
|
||||||
@ -45,8 +45,8 @@ bool lm_ctx_download(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_download_callback_t ca
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char path[strlen(pool->url.path)+strlen(pkg->name)+strlen(pkg->version)+20];
|
char path[strlen(pool->url.path)+strlen(pkg->data.name)+strlen(pkg->data.version)+20];
|
||||||
char name[strlen(pkg->name)+strlen(pkg->version)+10];
|
char name[strlen(pkg->data.name)+strlen(pkg->data.version)+10];
|
||||||
struct __lm_ctx_download_cb_data cbdata = {
|
struct __lm_ctx_download_cb_data cbdata = {
|
||||||
.ctx = ctx,
|
.ctx = ctx,
|
||||||
.pkg = pkg,
|
.pkg = pkg,
|
||||||
@ -57,7 +57,7 @@ bool lm_ctx_download(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_download_callback_t ca
|
|||||||
bool ret = false;
|
bool ret = false;
|
||||||
int sock = -1;
|
int sock = -1;
|
||||||
|
|
||||||
snprintf(name, sizeof(name), "%s_%s", pkg->name, pkg->version);
|
snprintf(name, sizeof(name), "%s_%s", pkg->data.name, pkg->data.version);
|
||||||
join(path, pool->url.path, name);
|
join(path, pool->url.path, name);
|
||||||
|
|
||||||
pdebug(__func__, "connecting to %s:%d for download", pool->url.host, pool->url.port);
|
pdebug(__func__, "connecting to %s:%d for download", pool->url.host, pool->url.port);
|
||||||
@ -72,10 +72,10 @@ bool lm_ctx_download(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_download_callback_t ca
|
|||||||
if(!lm_mptp_client_send(sock, &packet))
|
if(!lm_mptp_client_send(sock, &packet))
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
if(!lm_mptp_recvfile(sock, pkg->paths.archive, __lm_ctx_download_callback, &cbdata))
|
if(!lm_mptp_recvfile(sock, pkg->archive, __lm_ctx_download_callback, &cbdata))
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
if(!lm_mptp_recvfile(sock, pkg->paths.signature, __lm_ctx_download_callback, &cbdata))
|
if(!lm_mptp_recvfile(sock, pkg->signature, __lm_ctx_download_callback, &cbdata))
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
if(!lm_package_verify(pkg))
|
if(!lm_package_verify(pkg))
|
||||||
|
@ -14,13 +14,36 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
bool __lm_ctx_run_install(char *root, char *install_path) {
|
bool __lm_ctx_save_install(lm_ctx_t *ctx, lm_pkg_t *pkg, char *install_path){
|
||||||
struct stat st;
|
if(NULL == ctx->data){
|
||||||
bzero(&st, sizeof(st));
|
lm_error_set(LM_ERR_CtxDataNULL);
|
||||||
stat(install_path, &st);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// no need to save empty install script :)
|
||||||
|
if(is_empty(install_path))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
char script_name[strlen(pkg->data.name)+15];
|
||||||
|
char script_dir[strlen(ctx->data)+15];
|
||||||
|
|
||||||
|
sprintf(script_name, "install_%s", pkg->data.name);
|
||||||
|
join(script_dir, ctx->data, "scripts");
|
||||||
|
|
||||||
|
if(!mkdir_ifnot(script_dir)){
|
||||||
|
lm_error_set(LM_ERR_InstallDirFail);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
char dst[sizeof(script_name)+sizeof(script_dir)+10];
|
||||||
|
join(dst, script_dir, script_name);
|
||||||
|
|
||||||
|
return copy_file(dst, install_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool __lm_ctx_run_install(char *root, char *install_path) {
|
||||||
// no need to run empty install script :)
|
// no need to run empty install script :)
|
||||||
if(st.st_size <= 0)
|
if(is_empty(install_path))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
char *args[] = {"/bin/bash", install_path, NULL}, *oldpwd = NULL;
|
char *args[] = {"/bin/bash", install_path, NULL}, *oldpwd = NULL;
|
||||||
@ -113,8 +136,8 @@ bool __lm_ctx_extract_files(lm_ctx_t *ctx, lm_pkg_t *pkg, char *files, lm_ctx_in
|
|||||||
current += archive_entry_size(entry);
|
current += archive_entry_size(entry);
|
||||||
type = archive_entry_filetype(entry);
|
type = archive_entry_filetype(entry);
|
||||||
|
|
||||||
if(type == AE_IFREG && !lm_database_files_contains(ctx->db, pkg, entry_path)){
|
if(type == AE_IFREG && !lm_database_files_contains(ctx->db, &pkg->data, entry_path)){
|
||||||
pdebug(__func__, "archive file not included in the database: %s (%s)", entry_path, pkg->name);
|
pdebug(__func__, "archive file not included in the database: %s (%s)", entry_path, pkg->data.name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +187,7 @@ end:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_ctx_install(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_install_callback_t callback, void *data) {
|
bool lm_ctx_install(lm_ctx_t *ctx, lm_pkg_t *pkg, bool run_install, lm_ctx_install_callback_t callback, void *data) {
|
||||||
if(NULL == ctx->temp || NULL == pkg){
|
if(NULL == ctx->temp || NULL == pkg){
|
||||||
lm_error_set(LM_ERR_CtxTempNULL);
|
lm_error_set(LM_ERR_CtxTempNULL);
|
||||||
return false;
|
return false;
|
||||||
@ -183,7 +206,7 @@ bool lm_ctx_install(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_install_callback_t call
|
|||||||
if(!lm_ctx_database_init(ctx))
|
if(!lm_ctx_database_init(ctx))
|
||||||
return false; // error set by function
|
return false; // error set by function
|
||||||
|
|
||||||
if(lm_ctx_database_is_installed(ctx, pkg, false)){
|
if(lm_ctx_database_is_installed(ctx, pkg->data.name, NULL)){
|
||||||
lm_error_set(LM_ERR_PkgAlreadyInstalled);
|
lm_error_set(LM_ERR_PkgAlreadyInstalled);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -193,7 +216,7 @@ bool lm_ctx_install(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_install_callback_t call
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!extract_archive(ctx->temp, pkg->paths.archive))
|
if(!extract_archive(ctx->temp, pkg->archive))
|
||||||
return false; // error set by function
|
return false; // error set by function
|
||||||
|
|
||||||
size_t bufsize = strlen(ctx->temp) + 25;
|
size_t bufsize = strlen(ctx->temp) + 25;
|
||||||
@ -218,18 +241,18 @@ bool lm_ctx_install(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_install_callback_t call
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!lm_package_data_load(&temp, data_file))
|
if(!lm_package_data_load(&temp.data, data_file))
|
||||||
return false; // error set by function
|
return false; // error set by function
|
||||||
|
|
||||||
if(!lm_package_is_same(&temp, pkg)){
|
if(!lm_package_is_same(&temp, pkg)){
|
||||||
pdebug(__func__, "DATA file does not match with stored %s data", pkg->name);
|
pdebug(__func__, "DATA file does not match with stored %s data", pkg->data.name);
|
||||||
lm_error_set(LM_ERR_PkgDataNotMatch);
|
lm_error_set(LM_ERR_PkgDataNotMatch);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!lm_database_changes_update(ctx->db, pkg, changes_file)){
|
if(!lm_database_changes_update(ctx->db, &pkg->data, changes_file)){
|
||||||
char *suberr = lm_strerror_dup();
|
char *suberr = lm_strerror_dup();
|
||||||
pdebug(__func__, "failed to update changes file for %s: %s", pkg->name, suberr);
|
pdebug(__func__, "failed to update changes file for %s: %s", pkg->data.name, suberr);
|
||||||
lm_error_set(LM_ERR_PkgChangesUpdateFail, suberr);
|
lm_error_set(LM_ERR_PkgChangesUpdateFail, suberr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -240,7 +263,7 @@ bool lm_ctx_install(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_install_callback_t call
|
|||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
if((hashes = fopen(hashes_file, "r")) == NULL){
|
if((hashes = fopen(hashes_file, "r")) == NULL){
|
||||||
pdebug(__func__, "failed to open hash file for %s", pkg->name);
|
pdebug(__func__, "failed to open hash file for %s", pkg->data.name);
|
||||||
lm_error_set(LM_ERR_PkgHashesOpenFail);
|
lm_error_set(LM_ERR_PkgHashesOpenFail);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -267,9 +290,9 @@ bool lm_ctx_install(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_install_callback_t call
|
|||||||
|
|
||||||
pdebug(__func__, "(%lu) %s => %s", line_len, file, hash);
|
pdebug(__func__, "(%lu) %s => %s", line_len, file, hash);
|
||||||
|
|
||||||
if(!lm_database_files_add(ctx->db, pkg, file, hash)){
|
if(!lm_database_files_add(ctx->db, &pkg->data, file, hash)){
|
||||||
char *suberr = lm_strerror_dup();
|
char *suberr = lm_strerror_dup();
|
||||||
pdebug(__func__, "failed to add file to the database for %s: %s", pkg->name, suberr);
|
pdebug(__func__, "failed to add file to the database for %s: %s", pkg->data.name, suberr);
|
||||||
lm_error_set(LM_ERR_PkgFilesAddFail, file, suberr);
|
lm_error_set(LM_ERR_PkgFilesAddFail, file, suberr);
|
||||||
free(suberr);
|
free(suberr);
|
||||||
goto end;
|
goto end;
|
||||||
@ -283,24 +306,32 @@ bool lm_ctx_install(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_install_callback_t call
|
|||||||
|
|
||||||
if(!__lm_ctx_extract_files(ctx, pkg, files_archive, callback, data)){
|
if(!__lm_ctx_extract_files(ctx, pkg, files_archive, callback, data)){
|
||||||
char *suberr = lm_strerror_dup();
|
char *suberr = lm_strerror_dup();
|
||||||
pdebug(__func__, "failed to extract the files archive for %s: %s", pkg->name, suberr);
|
pdebug(__func__, "failed to extract the files archive for %s: %s", pkg->data.name, suberr);
|
||||||
lm_error_set(LM_ERR_PkgExtractFilesFail, suberr);
|
lm_error_set(LM_ERR_PkgExtractFilesFail, suberr);
|
||||||
free(suberr);
|
free(suberr);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!lm_database_package_add(ctx->db, pkg)){
|
if(!lm_database_entry_add(ctx->db, &pkg->data)){
|
||||||
char *suberr = lm_strerror_dup();
|
char *suberr = lm_strerror_dup();
|
||||||
pdebug(__func__, "failed to add %s to the database: %s", pkg->name, lm_strerror());
|
pdebug(__func__, "failed to add %s to the database: %s", pkg->data.name, lm_strerror());
|
||||||
lm_error_set(LM_ERR_PkgDatabaseAddFail, suberr);
|
lm_error_set(LM_ERR_PkgDatabaseAddFail, suberr);
|
||||||
free(suberr);
|
free(suberr);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!__lm_ctx_run_install(ctx->root, install_file)){
|
if(run_install && !__lm_ctx_run_install(ctx->root, install_file)){
|
||||||
char *suberr = lm_strerror_dup();
|
char *suberr = lm_strerror_dup();
|
||||||
pdebug(__func__, "failed to run install script: %s", lm_strerror());
|
pdebug(__func__, "failed to run install script: %s", lm_strerror());
|
||||||
lm_error_set(LM_ERR_InstallScriptFail, suberr);
|
lm_error_set(LM_ERR_InstallRunFail, suberr);
|
||||||
|
free(suberr);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!run_install && !__lm_ctx_save_install(ctx, pkg, install_file)){
|
||||||
|
char *suberr = lm_strerror_dup();
|
||||||
|
pdebug(__func__, "failed to save install script: %s", lm_strerror());
|
||||||
|
lm_error_set(LM_ERR_InstallSaveFail, suberr);
|
||||||
free(suberr);
|
free(suberr);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@ -313,12 +344,12 @@ end:
|
|||||||
fclose(hashes);
|
fclose(hashes);
|
||||||
|
|
||||||
if(!ret){
|
if(!ret){
|
||||||
lm_database_package_del(ctx->db, pkg);
|
lm_database_entry_del(ctx->db, &pkg->data);
|
||||||
lm_database_changes_del(ctx->db, pkg);
|
lm_database_changes_del(ctx->db, &pkg->data);
|
||||||
lm_database_files_del(ctx->db, pkg);
|
lm_database_files_del(ctx->db, &pkg->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink(pkg->paths.archive);
|
unlink(pkg->archive);
|
||||||
unlink(pkg->paths.signature);
|
unlink(pkg->signature);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,13 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
bool lm_ctx_removeable(lm_ctx_t *ctx, lm_pkg_t *pkg){
|
bool lm_ctx_removeable(lm_ctx_t *ctx, lm_entry_t *entry){
|
||||||
if(NULL == ctx && NULL == pkg){
|
if(NULL == ctx && NULL == entry){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!lm_ctx_database_is_installed(ctx, pkg, true)){
|
if(!lm_ctx_database_is_installed(ctx, entry->name, entry->version)){
|
||||||
lm_error_set(LM_ERR_PkgNotInstalled);
|
lm_error_set(LM_ERR_PkgNotInstalled);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -22,22 +22,22 @@ bool lm_ctx_removeable(lm_ctx_t *ctx, lm_pkg_t *pkg){
|
|||||||
if(!lm_ctx_database_init(ctx))
|
if(!lm_ctx_database_init(ctx))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
lm_pkg_t cur;
|
lm_entry_t cur;
|
||||||
|
|
||||||
while (lm_database_package_next(ctx->db, &cur)) {
|
while (lm_database_entry_next(ctx->db, &cur)) {
|
||||||
if(lm_package_depends(&cur, pkg->name)){
|
if(lm_package_data_depends(&cur, entry->name)){
|
||||||
lm_error_set(LM_ERR_PkgBreaks, cur.name);
|
lm_error_set(LM_ERR_PkgBreaks, cur.name);
|
||||||
lm_database_package_next_free(ctx->db, &cur);
|
lm_database_entry_next_free(ctx->db, &cur);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lm_database_package_next_free(ctx->db, &cur);
|
lm_database_entry_next_free(ctx->db, &cur);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_ctx_remove(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_remove_callback_t callback, void *data){
|
bool lm_ctx_remove(lm_ctx_t *ctx, lm_entry_t *entry, lm_ctx_remove_callback_t callback, void *data){
|
||||||
if(NULL == ctx && NULL == pkg){
|
if(NULL == ctx && NULL == entry){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -54,14 +54,14 @@ bool lm_ctx_remove(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_remove_callback_t callba
|
|||||||
bool in_keep = false, ret = false;
|
bool in_keep = false, ret = false;
|
||||||
size_t total = 0, current = 0;
|
size_t total = 0, current = 0;
|
||||||
|
|
||||||
total = lm_database_files_count(ctx->db, pkg);
|
total = lm_database_files_count(ctx->db, entry);
|
||||||
|
|
||||||
while(lm_database_files_next(ctx->db, pkg, &path, &hash, &in_keep)){
|
while(lm_database_files_next(ctx->db, entry, &path, &hash, &in_keep)){
|
||||||
if(in_keep)
|
if(in_keep)
|
||||||
goto next;
|
goto next;
|
||||||
|
|
||||||
fpath = join_alloc(ctx->root, path);
|
fpath = join_alloc(ctx->root, path);
|
||||||
pdebug(__func__, "removing file %s (%s)", fpath, pkg->name);
|
pdebug(__func__, "removing file %s (%s)", fpath, entry->name);
|
||||||
|
|
||||||
if(!exists(fpath)){
|
if(!exists(fpath)){
|
||||||
pdebug(__func__, "found file in database, but its not on the file system: %s", fpath);
|
pdebug(__func__, "found file in database, but its not on the file system: %s", fpath);
|
||||||
@ -69,7 +69,7 @@ bool lm_ctx_remove(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_remove_callback_t callba
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(unlink(fpath) < 0){
|
if(unlink(fpath) < 0){
|
||||||
pdebug(__func__, "failed to delete file for removing %s: %s", pkg->name, strerror(errno));
|
pdebug(__func__, "failed to delete file for removing %s: %s", entry->name, strerror(errno));
|
||||||
lm_error_set(LM_ERR_PkgFileUnlinkFail, path, strerror(errno));
|
lm_error_set(LM_ERR_PkgFileUnlinkFail, path, strerror(errno));
|
||||||
goto next;
|
goto next;
|
||||||
}
|
}
|
||||||
@ -78,36 +78,36 @@ bool lm_ctx_remove(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_remove_callback_t callba
|
|||||||
free(fpath);
|
free(fpath);
|
||||||
fpath = NULL;
|
fpath = NULL;
|
||||||
|
|
||||||
if(NULL != callback && !callback(ctx, pkg, fpath, ++current, total, data))
|
if(NULL != callback && !callback(ctx, entry, fpath, ++current, total, data))
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!lm_database_package_del(ctx->db, pkg)){
|
if(!lm_database_entry_del(ctx->db, entry)){
|
||||||
char *suberr = lm_strerror_dup();
|
char *suberr = lm_strerror_dup();
|
||||||
pdebug(__func__, "failed to delete %s from the database: %s", pkg->name, lm_strerror());
|
pdebug(__func__, "failed to delete %s from the database: %s", entry->name, lm_strerror());
|
||||||
lm_error_set(LM_ERR_PkgDatabaseDelFail, suberr);
|
lm_error_set(LM_ERR_PkgDatabaseDelFail, suberr);
|
||||||
free(suberr);
|
free(suberr);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!lm_database_files_del(ctx->db, pkg)){
|
if(!lm_database_files_del(ctx->db, entry)){
|
||||||
char *suberr = lm_strerror_dup();
|
char *suberr = lm_strerror_dup();
|
||||||
pdebug(__func__, "failed to delete files of %s from the database: %s", pkg->name, suberr);
|
pdebug(__func__, "failed to delete files of %s from the database: %s", entry->name, suberr);
|
||||||
lm_error_set(LM_ERR_PkgFilesDelFail, suberr);
|
lm_error_set(LM_ERR_PkgFilesDelFail, suberr);
|
||||||
free(suberr);
|
free(suberr);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!lm_database_changes_del(ctx->db, pkg)){
|
if(!lm_database_changes_del(ctx->db, entry)){
|
||||||
char *suberr = lm_strerror_dup();
|
char *suberr = lm_strerror_dup();
|
||||||
pdebug(__func__, "failed to delete changes file for %s: %s", pkg->name, suberr);
|
pdebug(__func__, "failed to delete changes file for %s: %s", entry->name, suberr);
|
||||||
lm_error_set(LM_ERR_PkgChangesDelFail, suberr);
|
lm_error_set(LM_ERR_PkgChangesDelFail, suberr);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
end:
|
end:
|
||||||
lm_database_files_next_free(ctx->db, pkg, &path, &hash, &in_keep);
|
lm_database_files_next_free(ctx->db, entry, &path, &hash, &in_keep);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,26 +11,26 @@ bool __lm_ctx_resolve(lm_ctx_t *ctx, lm_ctx_resolve_list_t *list, lm_pkg_t *pkg)
|
|||||||
if(pkglist_contains(list->packages, pkg))
|
if(pkglist_contains(list->packages, pkg))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if(NULL == pkg->depends)
|
if(NULL == pkg->data.depends)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
list->resolving = pkglist_add_top(list->resolving, pkg);
|
list->resolving = pkglist_add_top(list->resolving, pkg);
|
||||||
lm_pkg_t *depend = NULL;
|
lm_pkg_t *depend = NULL;
|
||||||
|
|
||||||
for(int i = 0; pkg->depends[i] != NULL; i++){
|
for(int i = 0; pkg->data.depends[i] != NULL; i++){
|
||||||
// if found then its already installed
|
// if found then its already installed
|
||||||
if(lm_ctx_database_find(ctx, NULL, pkg->depends[i], NULL))
|
if(lm_ctx_database_find(ctx, NULL, pkg->data.depends[i], NULL))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
depend = lm_ctx_pool_find(ctx, pkg->depends[i], NULL);
|
depend = lm_ctx_pool_find(ctx, pkg->data.depends[i], NULL);
|
||||||
|
|
||||||
if(NULL == depend){
|
if(NULL == depend){
|
||||||
lm_error_set(LM_ERR_DependNotFound, pkg->depends[i], pkg->name);
|
lm_error_set(LM_ERR_DependNotFound, pkg->data.depends[i], pkg->data.name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pkglist_contains(list->resolving, depend)){
|
if(pkglist_contains(list->resolving, depend)){
|
||||||
lm_error_set(LM_ERR_DependNotFound, pkg->depends[i], pkg->name);
|
lm_error_set(LM_ERR_DependNotFound, pkg->data.depends[i], pkg->data.name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,13 +33,13 @@ void __lm_ctx_serve(lm_pool_t *pool, lm_mptp_t *packet, int sock, struct sockadd
|
|||||||
// when INFO file is requested, send the file
|
// when INFO file is requested, send the file
|
||||||
case MPTP_C2S_INFO:
|
case MPTP_C2S_INFO:
|
||||||
pdebug(__func__, "(%s) INFO: attempting to send info", pool->name);
|
pdebug(__func__, "(%s) INFO: attempting to send info", pool->name);
|
||||||
lm_mptp_sendfile(sock, addr, pool->paths.info_file, NULL, NULL);
|
lm_mptp_sendfile(sock, addr, pool->info_file, NULL, NULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// when LIST file is requested, send the file
|
// when LIST file is requested, send the file
|
||||||
case MPTP_C2S_LIST:
|
case MPTP_C2S_LIST:
|
||||||
pdebug(__func__, "(%s) LIST: attempting to send list", pool->name);
|
pdebug(__func__, "(%s) LIST: attempting to send list", pool->name);
|
||||||
lm_mptp_sendfile(sock, addr, pool->paths.list_file, NULL, NULL);
|
lm_mptp_sendfile(sock, addr, pool->list_file, NULL, NULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// when the request code is PULL, send the requested package archive and
|
// when the request code is PULL, send the requested package archive and
|
||||||
@ -88,8 +88,8 @@ void __lm_ctx_serve(lm_pool_t *pool, lm_mptp_t *packet, int sock, struct sockadd
|
|||||||
}
|
}
|
||||||
|
|
||||||
// send package archive and the signature file
|
// send package archive and the signature file
|
||||||
lm_mptp_sendfile(sock, addr, pkg->paths.archive, NULL, NULL);
|
lm_mptp_sendfile(sock, addr, pkg->archive, NULL, NULL);
|
||||||
lm_mptp_sendfile(sock, addr, pkg->paths.signature, NULL, NULL);
|
lm_mptp_sendfile(sock, addr, pkg->signature, NULL, NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,53 +15,45 @@ lm_ctx_update_list_t *lm_ctx_update_list(lm_ctx_t *ctx){
|
|||||||
}
|
}
|
||||||
|
|
||||||
lm_ctx_update_list_t *list = malloc(sizeof(lm_ctx_update_list_t));
|
lm_ctx_update_list_t *list = malloc(sizeof(lm_ctx_update_list_t));
|
||||||
lm_pkg_t cur, *new = NULL;
|
lm_entry_t *cur = malloc(sizeof(lm_entry_t));
|
||||||
|
lm_pkg_t *new = NULL;
|
||||||
|
|
||||||
bzero(list, sizeof(lm_ctx_update_list_t));
|
bzero(list, sizeof(lm_ctx_update_list_t));
|
||||||
lm_package_init(&cur);
|
lm_entry_init(cur);
|
||||||
|
|
||||||
while(lm_ctx_database_next(ctx, &cur)){
|
while(lm_ctx_database_next(ctx, cur)){
|
||||||
if((new = lm_ctx_pool_find(ctx, cur.name, NULL)) == NULL)
|
if((new = lm_ctx_pool_find(ctx, cur->name, NULL)) == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(eq(new->version, cur.version))
|
if(eq(new->data.version, cur->version))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(NULL == list->packages)
|
if(NULL == list->entries)
|
||||||
list->packages = malloc(sizeof(lm_pkg_t));
|
list->entries = malloc(sizeof(lm_entry_t*)*(++list->count));
|
||||||
else
|
else
|
||||||
list->packages = realloc(list->packages, (list->count+1)*sizeof(lm_pkg_t));
|
list->entries = realloc(list->entries, sizeof(lm_entry_t*)*(++list->count));
|
||||||
|
list->entries[list->count-1] = cur;
|
||||||
lm_package_copy(&list->packages[list->count++], &cur);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lm_ctx_database_next_free(ctx, &cur);
|
lm_ctx_database_next_free(ctx, NULL);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
lm_pkg_t *lm_ctx_update_list_next(lm_ctx_update_list_t *list){
|
lm_entry_t *lm_ctx_update_list_next(lm_ctx_update_list_t *list){
|
||||||
if(NULL == list){
|
if(NULL == list){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NULL == list->packages)
|
if(NULL == list->entries)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if(NULL == list->cur){
|
if(list->index >= list->count){
|
||||||
list->cur = &list->packages[0];
|
list->index = 0;
|
||||||
return list->cur;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < list->count-1; i++){
|
return list->entries[list->index++];
|
||||||
if(list->cur != &list->packages[i])
|
|
||||||
continue;
|
|
||||||
list->cur = &list->packages[i+1];
|
|
||||||
return list->cur;
|
|
||||||
}
|
|
||||||
|
|
||||||
list->cur = NULL;
|
|
||||||
return list->cur;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lm_ctx_update_list_free(lm_ctx_update_list_t *list){
|
void lm_ctx_update_list_free(lm_ctx_update_list_t *list){
|
||||||
@ -70,29 +62,29 @@ void lm_ctx_update_list_free(lm_ctx_update_list_t *list){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NULL != list->packages){
|
if(NULL != list->entries){
|
||||||
for(int i = 0; i < list->count; i++)
|
for(int i = 0; i < list->count; i++)
|
||||||
lm_package_free(&list->packages[i]);
|
lm_entry_free(list->entries[i]);
|
||||||
free(list->packages);
|
free(list->entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(list);
|
free(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
lm_pkg_t *lm_ctx_update(lm_ctx_t *ctx, lm_pkg_t *pkg){
|
lm_pkg_t *lm_ctx_update(lm_ctx_t *ctx, lm_entry_t *entry){
|
||||||
if(NULL == ctx || NULL == pkg){
|
if(NULL == ctx || NULL == entry){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
lm_pkg_t *new = NULL;
|
lm_pkg_t *new = NULL;
|
||||||
|
|
||||||
if((new = lm_ctx_pool_find(ctx, pkg->name, NULL)) == NULL){
|
if((new = lm_ctx_pool_find(ctx, entry->name, NULL)) == NULL){
|
||||||
lm_error_set(LM_ERR_PkgNotFound);
|
lm_error_set(LM_ERR_PkgNotFound);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(eq(new->version, pkg->version)){
|
if(eq(new->data.version, entry->version)){
|
||||||
lm_error_set(LM_ERR_PkgUpToDate);
|
lm_error_set(LM_ERR_PkgUpToDate);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,14 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
bool lm_database_changes_update(lm_database_t *db, lm_pkg_t *pkg, char *file){
|
bool lm_database_changes_update(lm_database_t *db, lm_entry_t *entry, char *file){
|
||||||
if(NULL == db || NULL == pkg || NULL == file){
|
if(NULL == db || NULL == entry || NULL == file){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char changes_file[strlen(pkg->name)+20];
|
char changes_file[strlen(entry->name)+20];
|
||||||
sprintf(changes_file, "%s_changes", pkg->name);
|
sprintf(changes_file, "%s_changes", entry->name);
|
||||||
|
|
||||||
char changes_path[strlen(db->dir)+sizeof(changes_file)];
|
char changes_path[strlen(db->dir)+sizeof(changes_file)];
|
||||||
join(changes_path, db->dir, changes_file);
|
join(changes_path, db->dir, changes_file);
|
||||||
@ -31,14 +31,14 @@ bool lm_database_changes_update(lm_database_t *db, lm_pkg_t *pkg, char *file){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_database_changes_del(lm_database_t *db, lm_pkg_t *pkg){
|
bool lm_database_changes_del(lm_database_t *db, lm_entry_t *entry){
|
||||||
if(NULL == db || NULL == pkg){
|
if(NULL == db || NULL == entry){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char changes_file[strlen(pkg->name)+20];
|
char changes_file[strlen(entry->name)+20];
|
||||||
sprintf(changes_file, "%s_changes", pkg->name);
|
sprintf(changes_file, "%s_changes", entry->name);
|
||||||
|
|
||||||
char changes_path[strlen(db->dir)+sizeof(changes_file)];
|
char changes_path[strlen(db->dir)+sizeof(changes_file)];
|
||||||
join(changes_path, db->dir, changes_file);
|
join(changes_path, db->dir, changes_file);
|
||||||
@ -51,9 +51,9 @@ bool lm_database_changes_del(lm_database_t *db, lm_pkg_t *pkg){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *lm_database_changes_get(lm_database_t *db, lm_pkg_t *pkg){
|
char *lm_database_changes_get(lm_database_t *db, lm_entry_t *entry){
|
||||||
char changes_file[strlen(pkg->name)+20];
|
char changes_file[strlen(entry->name)+20];
|
||||||
sprintf(changes_file, "%s_changes", pkg->name);
|
sprintf(changes_file, "%s_changes", entry->name);
|
||||||
|
|
||||||
char *changes_path = malloc(strlen(db->dir)+sizeof(changes_file));
|
char *changes_path = malloc(strlen(db->dir)+sizeof(changes_file));
|
||||||
join(changes_path, db->dir, changes_file);
|
join(changes_path, db->dir, changes_file);
|
||||||
|
@ -79,8 +79,8 @@ lm_database_t *lm_database_new(char *path){
|
|||||||
join(packagesdb, path, "packages.db");
|
join(packagesdb, path, "packages.db");
|
||||||
join(filesdb, path, "files.db");
|
join(filesdb, path, "files.db");
|
||||||
|
|
||||||
if(sqlite3_open(packagesdb, &db->packages_db)){
|
if(sqlite3_open(packagesdb, &db->entries_db)){
|
||||||
pdebug(__func__, "(%s) failed to open databse: %s", packagesdb, sqlite3_errmsg(db->packages_db));
|
pdebug(__func__, "(%s) failed to open databse: %s", packagesdb, sqlite3_errmsg(db->entries_db));
|
||||||
lm_error_set(LM_ERR_DbSqlOpenFail);
|
lm_error_set(LM_ERR_DbSqlOpenFail);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -91,11 +91,11 @@ lm_database_t *lm_database_new(char *path){
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sqlite3_exec(db->packages_db, queries[QUERY_CREATE_PACKAGE_TABLE], NULL, 0, &err) != SQLITE_OK){
|
if(sqlite3_exec(db->entries_db, queries[QUERY_CREATE_ENTRY_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);
|
||||||
db->packages_db = NULL;
|
db->entries_db = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sqlite3_exec(db->files_db, queries[QUERY_CREATE_FILE_TABLE], NULL, 0, &err) != SQLITE_OK){
|
if(sqlite3_exec(db->files_db, queries[QUERY_CREATE_FILE_TABLE], NULL, 0, &err) != SQLITE_OK){
|
||||||
@ -110,23 +110,16 @@ lm_database_t *lm_database_new(char *path){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void lm_database_free(lm_database_t *db){
|
void lm_database_free(lm_database_t *db){
|
||||||
if(NULL != db->packages_st)
|
if(NULL != db->entries_st)
|
||||||
sqlite3_finalize(db->packages_st);
|
sqlite3_finalize(db->entries_st);
|
||||||
|
|
||||||
if(NULL != db->files_st)
|
if(NULL != db->files_st)
|
||||||
sqlite3_finalize(db->files_st);
|
sqlite3_finalize(db->files_st);
|
||||||
|
|
||||||
sqlite3_close(db->packages_db);
|
sqlite3_close(db->entries_db);
|
||||||
sqlite3_close(db->files_db);
|
sqlite3_close(db->files_db);
|
||||||
|
|
||||||
free(db->dir);
|
free(db->dir);
|
||||||
|
|
||||||
lm_pkg_t *cur = db->pkg, *prev = NULL;
|
|
||||||
while(NULL != cur){
|
|
||||||
prev = cur;
|
|
||||||
cur = cur->next;
|
|
||||||
lm_package_free(prev);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(db);
|
free(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
208
src/database/entry.c
Normal file
208
src/database/entry.c
Normal file
@ -0,0 +1,208 @@
|
|||||||
|
#include "../../include/database.h"
|
||||||
|
#include "../../include/package.h"
|
||||||
|
#include "../../include/error.h"
|
||||||
|
#include "../../include/util.h"
|
||||||
|
|
||||||
|
#include <sqlite3.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <strings.h>
|
||||||
|
|
||||||
|
void lm_entry_init(lm_entry_t *entry){
|
||||||
|
bzero(entry, sizeof(lm_entry_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
void lm_entry_free(lm_entry_t *entry){
|
||||||
|
if(NULL == entry)
|
||||||
|
return;
|
||||||
|
lm_package_data_free(entry);
|
||||||
|
lm_entry_init(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool lm_database_entry_add(lm_database_t *db, lm_entry_t *entry){
|
||||||
|
if(NULL == db || NULL == entry){
|
||||||
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
char depends[lm_package_data_depend_strlen(entry)];
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
if(sqlite3_prepare(db->entries_db, queries[QUERY_INSERT_ENTRY_SINGLE], strlen(queries[QUERY_INSERT_ENTRY_SINGLE]), &db->entries_st, NULL) != SQLITE_OK){
|
||||||
|
pdebug(__func__, "failed to prepare statement for inserting %s: %s", entry->name, sqlite3_errmsg(db->entries_db));
|
||||||
|
lm_error_set(LM_ERR_DbSqlPrepareFail);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3_bind_text(db->entries_st, ENTRIES_COLUMN_NAME, entry->name, strlen(entry->name), SQLITE_STATIC);
|
||||||
|
sqlite3_bind_text(db->entries_st, ENTRIES_COLUMN_DESC, entry->desc, strlen(entry->desc), SQLITE_STATIC);
|
||||||
|
sqlite3_bind_text(db->entries_st, ENTRIES_COLUMN_VERSION, entry->version, strlen(entry->version), SQLITE_STATIC);
|
||||||
|
sqlite3_bind_int64(db->entries_st, ENTRIES_COLUMN_SIZE, entry->size);
|
||||||
|
|
||||||
|
if(!lm_package_data_depend_tostr(entry, depends)){
|
||||||
|
pdebug(__func__, "failed to convert depends to string for inserting %s: %s", entry->name, lm_strerror());
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
pdebug(__func__, "depend list for %s: %s", entry->name, depends);
|
||||||
|
sqlite3_bind_text(db->entries_st, ENTRIES_COLUMN_DEPENDS, depends, strlen(depends), SQLITE_STATIC);
|
||||||
|
|
||||||
|
if(!lm_database_step_all(db->entries_st)){
|
||||||
|
pdebug(__func__, "failed to execute insert statement for inserting %s: %s", entry->name, sqlite3_errmsg(db->entries_db));
|
||||||
|
lm_error_set(LM_ERR_DbSqlInsertFail);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = true;
|
||||||
|
end:
|
||||||
|
if(NULL != db->entries_st){
|
||||||
|
sqlite3_finalize(db->entries_st);
|
||||||
|
db->entries_st = NULL;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool lm_database_entry_find(lm_database_t *db, lm_entry_t *entry, char *name, char *version){
|
||||||
|
if(NULL == db || NULL == name){
|
||||||
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ret = false;
|
||||||
|
char *query = NULL;
|
||||||
|
|
||||||
|
if(NULL == version)
|
||||||
|
query = queries[QUERY_SELECT_ENTRY_SINGLE_1];
|
||||||
|
else
|
||||||
|
query = queries[QUERY_SELECT_ENTRY_SINGLE_2];
|
||||||
|
|
||||||
|
// package pointer should already be free'd
|
||||||
|
// we are initing it just in case the caller didn't
|
||||||
|
if(NULL != entry)
|
||||||
|
lm_entry_free(entry);
|
||||||
|
|
||||||
|
if(sqlite3_prepare(db->entries_db, query, strlen(query), &db->entries_st, NULL) != SQLITE_OK){
|
||||||
|
pdebug(__func__, "failed to prepare statement for finding %s: %s", name, sqlite3_errmsg(db->entries_db));
|
||||||
|
lm_error_set(LM_ERR_DbSqlPrepareFail);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3_bind_text(db->entries_st, ENTRIES_COLUMN_NAME, name, strlen(name), SQLITE_STATIC);
|
||||||
|
if(NULL != version)
|
||||||
|
sqlite3_bind_text(db->entries_st, ENTRIES_COLUMN_VERSION, version, strlen(version), SQLITE_STATIC);
|
||||||
|
|
||||||
|
if(sqlite3_step(db->entries_st) != SQLITE_ROW){
|
||||||
|
pdebug(__func__, "got no rows for %s", name);
|
||||||
|
lm_error_set(LM_ERR_DbSqlNotFound);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(NULL == entry){
|
||||||
|
ret = true;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry->name = strdup((char*)sqlite3_column_text(db->entries_st, ENTRIES_COLUMN_NAME-1));
|
||||||
|
entry->desc = strdup((char*)sqlite3_column_text(db->entries_st, ENTRIES_COLUMN_DESC-1));
|
||||||
|
entry->version = strdup((char*)sqlite3_column_text(db->entries_st, ENTRIES_COLUMN_VERSION-1));
|
||||||
|
entry->size = sqlite3_column_int64(db->entries_st, ENTRIES_COLUMN_SIZE-1);
|
||||||
|
|
||||||
|
char *depends = (char*)sqlite3_column_text(db->entries_st, ENTRIES_COLUMN_DEPENDS-1);
|
||||||
|
if(!lm_package_data_depend_fromstr(entry, depends)){
|
||||||
|
pdebug(__func__, "failed to load depends for finding %s: %s", entry->name, lm_strerror());
|
||||||
|
// error is set by the function
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = true;
|
||||||
|
end:
|
||||||
|
if(NULL != db->entries_st){
|
||||||
|
sqlite3_finalize(db->entries_st);
|
||||||
|
db->entries_st = NULL;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool lm_database_entry_del(lm_database_t *db, lm_entry_t *entry){
|
||||||
|
if(NULL == db || NULL == entry){
|
||||||
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
if(sqlite3_prepare(db->entries_db, queries[QUERY_DELETE_ENTRY_SINGLE], strlen(queries[QUERY_DELETE_ENTRY_SINGLE]), &db->entries_st, NULL) != SQLITE_OK){
|
||||||
|
pdebug(__func__, "failed to prepare statement for deleting %s: %s", entry->name, sqlite3_errmsg(db->entries_db));
|
||||||
|
lm_error_set(LM_ERR_DbSqlPrepareFail);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3_bind_text(db->entries_st, ENTRIES_COLUMN_NAME, entry->name, strlen(entry->name), SQLITE_STATIC);
|
||||||
|
|
||||||
|
if(sqlite3_step(db->entries_st) != SQLITE_DONE){
|
||||||
|
pdebug(__func__, "failed to execute delete statement for deleting %s: %s", entry->name, sqlite3_errmsg(db->entries_db));
|
||||||
|
lm_error_set(LM_ERR_DbSqlDeleteFail);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = true;
|
||||||
|
end:
|
||||||
|
if(NULL != db->entries_st){
|
||||||
|
sqlite3_finalize(db->entries_st);
|
||||||
|
db->entries_st = NULL;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool lm_database_entry_next(lm_database_t *db, lm_entry_t *entry){
|
||||||
|
if(NULL == db || NULL == entry){
|
||||||
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(NULL != db->entries_st)
|
||||||
|
lm_entry_free(entry);
|
||||||
|
|
||||||
|
else if(NULL == db->entries_st &&
|
||||||
|
sqlite3_prepare(db->entries_db, queries[QUERY_SELECT_ENTRY_ALL], strlen(queries[QUERY_SELECT_ENTRY_ALL]), &db->entries_st, NULL) != SQLITE_OK){
|
||||||
|
pdebug(__func__, "failed to prepare statement for selecting all: %s", sqlite3_errmsg(db->entries_db));
|
||||||
|
lm_error_set(LM_ERR_DbSqlPrepareFail);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
lm_entry_init(entry);
|
||||||
|
|
||||||
|
if(sqlite3_step(db->entries_st) != SQLITE_ROW){
|
||||||
|
sqlite3_finalize(db->entries_st);
|
||||||
|
db->entries_st = NULL;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry->name = strdup((char*)sqlite3_column_text(db->entries_st, ENTRIES_COLUMN_NAME-1));
|
||||||
|
entry->desc = strdup((char*)sqlite3_column_text(db->entries_st, ENTRIES_COLUMN_DESC-1));
|
||||||
|
entry->version = strdup((char*)sqlite3_column_text(db->entries_st, ENTRIES_COLUMN_VERSION-1));
|
||||||
|
entry->size = sqlite3_column_int64(db->entries_st, ENTRIES_COLUMN_SIZE-1);
|
||||||
|
|
||||||
|
char *depends = (char*)sqlite3_column_text(db->entries_st, ENTRIES_COLUMN_DEPENDS-1);
|
||||||
|
if(!lm_package_data_depend_fromstr(entry, depends)){
|
||||||
|
pdebug(__func__, "failed to load depends for finding %s: %s", entry->name, lm_strerror());
|
||||||
|
sqlite3_finalize(db->entries_st);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void lm_database_entry_next_free(lm_database_t *db, lm_entry_t *entry){
|
||||||
|
if(NULL == db || NULL == entry){
|
||||||
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(NULL != db->entries_st){
|
||||||
|
sqlite3_finalize(db->entries_st);
|
||||||
|
db->entries_st = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(NULL != entry)
|
||||||
|
lm_entry_free(entry);
|
||||||
|
}
|
@ -11,10 +11,10 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
size_t lm_database_files_count(lm_database_t *db, lm_pkg_t *pkg){
|
ssize_t lm_database_files_count(lm_database_t *db, lm_entry_t *entry){
|
||||||
size_t count = 0;
|
ssize_t count = 0;
|
||||||
|
|
||||||
if(NULL == db || NULL == pkg){
|
if(NULL == db || NULL == entry){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@ -25,7 +25,7 @@ size_t lm_database_files_count(lm_database_t *db, lm_pkg_t *pkg){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_bind_text(db->files_st, 1, pkg->name, strlen(pkg->name), SQLITE_STATIC);
|
sqlite3_bind_text(db->files_st, 1, entry->name, strlen(entry->name), SQLITE_STATIC);
|
||||||
|
|
||||||
while(sqlite3_step(db->files_st) == SQLITE_ROW)
|
while(sqlite3_step(db->files_st) == SQLITE_ROW)
|
||||||
count++;
|
count++;
|
||||||
@ -37,7 +37,7 @@ end:
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_database_files_contains(lm_database_t *db, lm_pkg_t *pkg, char *path){
|
bool lm_database_files_contains(lm_database_t *db, lm_entry_t *entry, char *path){
|
||||||
char *package = NULL;
|
char *package = NULL;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
@ -60,8 +60,8 @@ bool lm_database_files_contains(lm_database_t *db, lm_pkg_t *pkg, char *path){
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
package = (char*)sqlite3_column_text(db->files_st, FILES_COLUMN_PACKAGE-1);
|
package = (char*)sqlite3_column_text(db->files_st, FILES_COLUMN_ENTRY-1);
|
||||||
ret = eq(package, pkg->name);
|
ret = eq(package, entry->name);
|
||||||
end:
|
end:
|
||||||
if(NULL != db->files_st){
|
if(NULL != db->files_st){
|
||||||
sqlite3_finalize(db->files_st);
|
sqlite3_finalize(db->files_st);
|
||||||
@ -139,10 +139,10 @@ end:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_database_files_add(lm_database_t *db, lm_pkg_t *pkg, char *path, char *hash){
|
bool lm_database_files_add(lm_database_t *db, lm_entry_t *entry, char *path, char *hash){
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
if(NULL == db || NULL == pkg || NULL == path || NULL == hash){
|
if(NULL == db || NULL == entry || NULL == path || NULL == hash){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@ -155,14 +155,14 @@ bool lm_database_files_add(lm_database_t *db, lm_pkg_t *pkg, char *path, char *h
|
|||||||
|
|
||||||
sqlite3_bind_text(db->files_st, FILES_COLUMN_PATH, path, strlen(path), SQLITE_STATIC);
|
sqlite3_bind_text(db->files_st, FILES_COLUMN_PATH, path, strlen(path), SQLITE_STATIC);
|
||||||
sqlite3_bind_text(db->files_st, FILES_COLUMN_HASH, hash, strlen(hash), SQLITE_STATIC);
|
sqlite3_bind_text(db->files_st, FILES_COLUMN_HASH, hash, strlen(hash), SQLITE_STATIC);
|
||||||
if(lm_package_keep_contains(pkg, path))
|
if(lm_package_data_keep_contains(entry, path))
|
||||||
sqlite3_bind_int(db->files_st, FILES_COLUMN_KEEP, 1);
|
sqlite3_bind_int(db->files_st, FILES_COLUMN_KEEP, 1);
|
||||||
else
|
else
|
||||||
sqlite3_bind_int(db->files_st, FILES_COLUMN_KEEP, 0);
|
sqlite3_bind_int(db->files_st, FILES_COLUMN_KEEP, 0);
|
||||||
sqlite3_bind_text(db->files_st, FILES_COLUMN_PACKAGE, pkg->name, strlen(pkg->name), SQLITE_STATIC);
|
sqlite3_bind_text(db->files_st, FILES_COLUMN_ENTRY, entry->name, strlen(entry->name), SQLITE_STATIC);
|
||||||
|
|
||||||
if(!lm_database_step_all(db->files_st)){
|
if(!lm_database_step_all(db->files_st)){
|
||||||
pdebug(__func__, "failed to execute insert statement for inserting %s: %s", pkg->name, sqlite3_errmsg(db->files_db));
|
pdebug(__func__, "failed to execute insert statement for inserting %s: %s", entry->name, sqlite3_errmsg(db->files_db));
|
||||||
lm_error_set(LM_ERR_DbSqlInsertFail);
|
lm_error_set(LM_ERR_DbSqlInsertFail);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@ -176,8 +176,8 @@ end:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_database_files_del(lm_database_t *db, lm_pkg_t *pkg){
|
bool lm_database_files_del(lm_database_t *db, lm_entry_t *entry){
|
||||||
if(NULL == db || NULL == pkg){
|
if(NULL == db || NULL == entry){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -185,15 +185,15 @@ bool lm_database_files_del(lm_database_t *db, lm_pkg_t *pkg){
|
|||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
if(sqlite3_prepare(db->files_db, queries[QUERY_DELETE_FILE_ALL], strlen(queries[QUERY_DELETE_FILE_ALL]), &db->files_st, NULL) != SQLITE_OK){
|
if(sqlite3_prepare(db->files_db, queries[QUERY_DELETE_FILE_ALL], strlen(queries[QUERY_DELETE_FILE_ALL]), &db->files_st, NULL) != SQLITE_OK){
|
||||||
pdebug(__func__, "failed to prepare statement for deleting %s: %s", pkg->name, sqlite3_errmsg(db->files_db));
|
pdebug(__func__, "failed to prepare statement for deleting %s: %s", entry->name, sqlite3_errmsg(db->files_db));
|
||||||
lm_error_set(LM_ERR_DbSqlPrepareFail);
|
lm_error_set(LM_ERR_DbSqlPrepareFail);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_bind_text(db->files_st, 1, pkg->name, strlen(pkg->name), SQLITE_STATIC);
|
sqlite3_bind_text(db->files_st, 1, entry->name, strlen(entry->name), SQLITE_STATIC);
|
||||||
|
|
||||||
if(!lm_database_step_all(db->files_st)){
|
if(!lm_database_step_all(db->files_st)){
|
||||||
pdebug(__func__, "failed to execute delete statement for deleting %s: %s", pkg->name, sqlite3_errmsg(db->files_db));
|
pdebug(__func__, "failed to execute delete statement for deleting %s: %s", entry->name, sqlite3_errmsg(db->files_db));
|
||||||
lm_error_set(LM_ERR_DbSqlDeleteFail);
|
lm_error_set(LM_ERR_DbSqlDeleteFail);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@ -207,8 +207,8 @@ end:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_database_files_next(lm_database_t *db, lm_pkg_t *pkg, char **path, char **hash, bool *keep){
|
bool lm_database_files_next(lm_database_t *db, lm_entry_t *entry, char **path, char **hash, bool *keep){
|
||||||
if(NULL == db || NULL == pkg || NULL == path || NULL == hash || NULL == keep){
|
if(NULL == db || NULL == entry || NULL == path || NULL == hash || NULL == keep){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -219,7 +219,7 @@ bool lm_database_files_next(lm_database_t *db, lm_pkg_t *pkg, char **path, char
|
|||||||
lm_error_set(LM_ERR_DbSqlPrepareFail);
|
lm_error_set(LM_ERR_DbSqlPrepareFail);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
sqlite3_bind_text(db->files_st, 1, pkg->name, strlen(pkg->name), SQLITE_STATIC);
|
sqlite3_bind_text(db->files_st, 1, entry->name, strlen(entry->name), SQLITE_STATIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(NULL != db->files_st){
|
else if(NULL != db->files_st){
|
||||||
@ -242,8 +242,8 @@ bool lm_database_files_next(lm_database_t *db, lm_pkg_t *pkg, char **path, char
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lm_database_files_next_free(lm_database_t *db, lm_pkg_t *pkg, char **path, char **hash, bool *keep){
|
void lm_database_files_next_free(lm_database_t *db, lm_entry_t *entry, char **path, char **hash, bool *keep){
|
||||||
if(NULL == db || NULL == pkg || NULL == path || NULL == hash || NULL == keep){
|
if(NULL == db || NULL == entry || NULL == path || NULL == hash || NULL == keep){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,197 +0,0 @@
|
|||||||
#include "../../include/database.h"
|
|
||||||
#include "../../include/package.h"
|
|
||||||
#include "../../include/error.h"
|
|
||||||
#include "../../include/util.h"
|
|
||||||
|
|
||||||
#include <sqlite3.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <strings.h>
|
|
||||||
|
|
||||||
bool lm_database_package_add(lm_database_t *db, lm_pkg_t *pkg){
|
|
||||||
if(NULL == db || NULL == pkg){
|
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
char depends[lm_package_depend_strlen(pkg)];
|
|
||||||
bool ret = false;
|
|
||||||
|
|
||||||
if(sqlite3_prepare(db->packages_db, queries[QUERY_INSERT_PACKAGE_SINGLE], strlen(queries[QUERY_INSERT_PACKAGE_SINGLE]), &db->packages_st, NULL) != SQLITE_OK){
|
|
||||||
pdebug(__func__, "failed to prepare statement for inserting %s: %s", pkg->name, sqlite3_errmsg(db->packages_db));
|
|
||||||
lm_error_set(LM_ERR_DbSqlPrepareFail);
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
sqlite3_bind_text(db->packages_st, PACKAGES_COLUMN_NAME, pkg->name, strlen(pkg->name), SQLITE_STATIC);
|
|
||||||
sqlite3_bind_text(db->packages_st, PACKAGES_COLUMN_DESC, pkg->desc, strlen(pkg->desc), SQLITE_STATIC);
|
|
||||||
sqlite3_bind_text(db->packages_st, PACKAGES_COLUMN_VERSION, pkg->version, strlen(pkg->version), SQLITE_STATIC);
|
|
||||||
sqlite3_bind_int64(db->packages_st, PACKAGES_COLUMN_SIZE, pkg->size);
|
|
||||||
|
|
||||||
if(!lm_package_depend_tostr(pkg, depends)){
|
|
||||||
pdebug(__func__, "failed to convert depends to string for inserting %s: %s", pkg->name, lm_strerror());
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
pdebug(__func__, "depend list for %s: %s", pkg->name, depends);
|
|
||||||
sqlite3_bind_text(db->packages_st, PACKAGES_COLUMN_DEPENDS, depends, strlen(depends), SQLITE_STATIC);
|
|
||||||
|
|
||||||
if(!lm_database_step_all(db->packages_st)){
|
|
||||||
pdebug(__func__, "failed to execute insert statement for inserting %s: %s", pkg->name, sqlite3_errmsg(db->packages_db));
|
|
||||||
lm_error_set(LM_ERR_DbSqlInsertFail);
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = true;
|
|
||||||
end:
|
|
||||||
if(NULL != db->packages_st){
|
|
||||||
sqlite3_finalize(db->packages_st);
|
|
||||||
db->packages_st = NULL;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool lm_database_package_find(lm_database_t *db, lm_pkg_t *pkg, char *name, char *version){
|
|
||||||
if(NULL == db || NULL == name){
|
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ret = false;
|
|
||||||
char *query = NULL;
|
|
||||||
|
|
||||||
if(NULL == version)
|
|
||||||
query = queries[QUERY_SELECT_PACKAGE_SINGLE_1];
|
|
||||||
else
|
|
||||||
query = queries[QUERY_SELECT_PACKAGE_SINGLE_2];
|
|
||||||
|
|
||||||
// package pointer should already be free'd
|
|
||||||
// we are initing it just in case the caller didn't
|
|
||||||
if(NULL != pkg)
|
|
||||||
lm_package_init(pkg);
|
|
||||||
|
|
||||||
if(sqlite3_prepare(db->packages_db, query, strlen(query), &db->packages_st, NULL) != SQLITE_OK){
|
|
||||||
pdebug(__func__, "failed to prepare statement for finding %s: %s", name, sqlite3_errmsg(db->packages_db));
|
|
||||||
lm_error_set(LM_ERR_DbSqlPrepareFail);
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
sqlite3_bind_text(db->packages_st, PACKAGES_COLUMN_NAME, name, strlen(name), SQLITE_STATIC);
|
|
||||||
if(NULL != version)
|
|
||||||
sqlite3_bind_text(db->packages_st, PACKAGES_COLUMN_VERSION, version, strlen(version), SQLITE_STATIC);
|
|
||||||
|
|
||||||
if(sqlite3_step(db->packages_st) != SQLITE_ROW){
|
|
||||||
pdebug(__func__, "got no rows for %s", name);
|
|
||||||
lm_error_set(LM_ERR_DbSqlNotFound);
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(NULL == pkg){
|
|
||||||
ret = true;
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
pkg->name = strdup((char*)sqlite3_column_text(db->packages_st, PACKAGES_COLUMN_NAME-1));
|
|
||||||
pkg->desc = strdup((char*)sqlite3_column_text(db->packages_st, PACKAGES_COLUMN_DESC-1));
|
|
||||||
pkg->version = strdup((char*)sqlite3_column_text(db->packages_st, PACKAGES_COLUMN_VERSION-1));
|
|
||||||
pkg->size = sqlite3_column_int64(db->packages_st, PACKAGES_COLUMN_SIZE-1);
|
|
||||||
|
|
||||||
char *depends = (char*)sqlite3_column_text(db->packages_st, PACKAGES_COLUMN_DEPENDS-1);
|
|
||||||
if(!lm_package_depend_fromstr(pkg, depends)){
|
|
||||||
pdebug(__func__, "failed to load depends for finding %s: %s", pkg->name, lm_strerror());
|
|
||||||
// error is set by the function
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = true;
|
|
||||||
end:
|
|
||||||
if(NULL != db->packages_st){
|
|
||||||
sqlite3_finalize(db->packages_st);
|
|
||||||
db->packages_st = NULL;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool lm_database_package_del(lm_database_t *db, lm_pkg_t *pkg){
|
|
||||||
if(NULL == db || NULL == pkg){
|
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ret = false;
|
|
||||||
|
|
||||||
if(sqlite3_prepare(db->packages_db, queries[QUERY_DELETE_PACKAGE_SINGLE], strlen(queries[QUERY_DELETE_PACKAGE_SINGLE]), &db->packages_st, NULL) != SQLITE_OK){
|
|
||||||
pdebug(__func__, "failed to prepare statement for deleting %s: %s", pkg->name, sqlite3_errmsg(db->packages_db));
|
|
||||||
lm_error_set(LM_ERR_DbSqlPrepareFail);
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
sqlite3_bind_text(db->packages_st, PACKAGES_COLUMN_NAME, pkg->name, strlen(pkg->name), SQLITE_STATIC);
|
|
||||||
|
|
||||||
if(sqlite3_step(db->packages_st) != SQLITE_DONE){
|
|
||||||
pdebug(__func__, "failed to execute delete statement for deleting %s: %s", pkg->name, sqlite3_errmsg(db->packages_db));
|
|
||||||
lm_error_set(LM_ERR_DbSqlDeleteFail);
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = true;
|
|
||||||
end:
|
|
||||||
if(NULL != db->packages_st){
|
|
||||||
sqlite3_finalize(db->packages_st);
|
|
||||||
db->packages_st = NULL;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool lm_database_package_next(lm_database_t *db, lm_pkg_t *pkg){
|
|
||||||
if(NULL == db || NULL == pkg){
|
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(NULL != db->packages_st)
|
|
||||||
lm_package_free(pkg);
|
|
||||||
|
|
||||||
else if(NULL == db->packages_st &&
|
|
||||||
sqlite3_prepare(db->packages_db, queries[QUERY_SELECT_PACKAGE_ALL], strlen(queries[QUERY_SELECT_PACKAGE_ALL]), &db->packages_st, NULL) != SQLITE_OK){
|
|
||||||
pdebug(__func__, "failed to prepare statement for selecting all: %s", sqlite3_errmsg(db->packages_db));
|
|
||||||
lm_error_set(LM_ERR_DbSqlPrepareFail);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
lm_package_init(pkg);
|
|
||||||
|
|
||||||
if(sqlite3_step(db->packages_st) != SQLITE_ROW){
|
|
||||||
sqlite3_finalize(db->packages_st);
|
|
||||||
db->packages_st = NULL;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
pkg->name = strdup((char*)sqlite3_column_text(db->packages_st, PACKAGES_COLUMN_NAME-1));
|
|
||||||
pkg->desc = strdup((char*)sqlite3_column_text(db->packages_st, PACKAGES_COLUMN_DESC-1));
|
|
||||||
pkg->version = strdup((char*)sqlite3_column_text(db->packages_st, PACKAGES_COLUMN_VERSION-1));
|
|
||||||
pkg->size = sqlite3_column_int64(db->packages_st, PACKAGES_COLUMN_SIZE-1);
|
|
||||||
|
|
||||||
char *depends = (char*)sqlite3_column_text(db->packages_st, PACKAGES_COLUMN_DEPENDS-1);
|
|
||||||
if(!lm_package_depend_fromstr(pkg, depends)){
|
|
||||||
pdebug(__func__, "failed to load depends for finding %s: %s", pkg->name, lm_strerror());
|
|
||||||
sqlite3_finalize(db->packages_st);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void lm_database_package_next_free(lm_database_t *db, lm_pkg_t *pkg){
|
|
||||||
if(NULL == db || NULL == pkg){
|
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(NULL != db->packages_st){
|
|
||||||
sqlite3_finalize(db->packages_st);
|
|
||||||
db->packages_st = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(NULL != pkg)
|
|
||||||
lm_package_free(pkg);
|
|
||||||
}
|
|
@ -73,8 +73,8 @@ void lm_error_set(lm_error_t code, ...) {
|
|||||||
{.code = LM_ERR_CtxRootFail, .desc = _("specified root path does not exist") },
|
{.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_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_CtxRootNoWrite, .desc = _("specified root directory does not have write access") },
|
||||||
{.code = LM_ERR_CtxDataNotDir, .desc = _("specified data path does not exist") },
|
{.code = LM_ERR_CtxDataNotDir, .desc = _("specified data path is not a directory") },
|
||||||
{.code = LM_ERR_CtxDataNoWrite, .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_CtxDataFailMkdir, .desc = _("failed to create specified data directory") },
|
||||||
{.code = LM_ERR_PoolTestNotPong, .desc = _("pool did not respond ping with pong") },
|
{.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_PkgPathsEmpty, .desc = _("package file and directory paths are empty") },
|
||||||
@ -148,7 +148,8 @@ void lm_error_set(lm_error_t code, ...) {
|
|||||||
{.code = LM_ERR_InstallBackChdirFail,
|
{.code = LM_ERR_InstallBackChdirFail,
|
||||||
.desc = _("failed to change directory to old directory after running install") },
|
.desc = _("failed to change directory to old directory after running install") },
|
||||||
{.code = LM_ERR_InstallStatusFail, .desc = _("install script returned a bad status code") },
|
{.code = LM_ERR_InstallStatusFail, .desc = _("install script returned a bad status code") },
|
||||||
{.code = LM_ERR_InstallScriptFail, .desc = _("failed to run the package install script: %s") },
|
{.code = LM_ERR_InstallRunFail, .desc = _("failed to run the package install script: %s") },
|
||||||
|
{.code = LM_ERR_InstallSaveFail, .desc = _("failed to save the package install script: %s") },
|
||||||
{.code = LM_ERR_PkgBreaks, .desc = _("removing package breaks %s") },
|
{.code = LM_ERR_PkgBreaks, .desc = _("removing package breaks %s") },
|
||||||
{.code = LM_ERR_PkgUpToDate, .desc = _("package is already up-to-date") },
|
{.code = LM_ERR_PkgUpToDate, .desc = _("package is already up-to-date") },
|
||||||
{.code = LM_ERR_HashOpenFail, .desc = _("failed to open file for hashing") },
|
{.code = LM_ERR_HashOpenFail, .desc = _("failed to open file for hashing") },
|
||||||
@ -159,6 +160,7 @@ void lm_error_set(lm_error_t code, ...) {
|
|||||||
{.code = LM_ERR_NoPools, .desc = _("pool list is empty") },
|
{.code = LM_ERR_NoPools, .desc = _("pool list is empty") },
|
||||||
{.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") },
|
||||||
};
|
};
|
||||||
|
|
||||||
char *fmt = NULL;
|
char *fmt = NULL;
|
||||||
|
@ -7,48 +7,48 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ini.h>
|
#include <ini.h>
|
||||||
|
|
||||||
int lm_package_data_handler(void *data, const char *_section, const char *_key, const char *_value) {
|
int lm_package_data_handler(void *_data, const char *_section, const char *_key, const char *_value) {
|
||||||
char *section = (char *)_section, *value = (char *)_value, *key = (char *)_key;
|
char *section = (char *)_section, *value = (char *)_value, *key = (char *)_key;
|
||||||
lm_pkg_t *pkg = data;
|
lm_pkg_data_t *data = _data;
|
||||||
|
|
||||||
if(NULL == pkg->name){
|
if(NULL == data->name){
|
||||||
if(!package_name_valid(section))
|
if(!package_name_valid(section))
|
||||||
return 0;
|
return 0;
|
||||||
pkg->name = strdup(section);
|
data->name = strdup(section);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(!eq(pkg->name, section))
|
else if(!eq(data->name, section))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(eq(key, PKG_DATA_DESC))
|
if(eq(key, PKG_DATA_DESC))
|
||||||
pkg->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))
|
||||||
return 0;
|
return 0;
|
||||||
pkg->version = strdup(value);
|
data->version = strdup(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(eq(key, PKG_DATA_SIZE))
|
else if(eq(key, PKG_DATA_SIZE))
|
||||||
pkg->size = atol(value);
|
data->size = atol(value);
|
||||||
|
|
||||||
else if(eq(key, PKG_DATA_DEPENDS)){
|
else if(eq(key, PKG_DATA_DEPENDS)){
|
||||||
if(!lm_package_depend_add(pkg, value))
|
if(!lm_package_data_depend_add(data, value))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(eq(key, PKG_DATA_KEEPS)){
|
else if(eq(key, PKG_DATA_KEEPS)){
|
||||||
if(!lm_package_keep_add(pkg, value))
|
if(!lm_package_data_keep_add(data, value))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_package_data_load(lm_pkg_t *pkg, char *file){
|
bool lm_package_data_load(lm_pkg_data_t *data, char *file){
|
||||||
lm_package_data_free(pkg);
|
lm_package_data_free(data);
|
||||||
|
|
||||||
if (ini_parse(file, lm_package_data_handler, pkg) < 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;
|
||||||
}
|
}
|
||||||
@ -56,11 +56,11 @@ bool lm_package_data_load(lm_pkg_t *pkg, char *file){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lm_package_data_free(lm_pkg_t *pkg){
|
void lm_package_data_free(lm_pkg_data_t *data){
|
||||||
free(pkg->desc);
|
free(data->name);
|
||||||
free(pkg->name);
|
free(data->desc);
|
||||||
free(pkg->version);
|
free(data->version);
|
||||||
|
lm_package_data_depend_free(data);
|
||||||
lm_package_depend_free(pkg);
|
lm_package_data_keep_free(data);
|
||||||
lm_package_keep_free(pkg);
|
bzero(&data, sizeof(lm_pkg_data_t));
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,23 @@
|
|||||||
#include "../../include/package.h"
|
#include "../../include/package.h"
|
||||||
#include "../../include/error.h"
|
#include "../../include/error.h"
|
||||||
#include "../../include/types.h"
|
|
||||||
#include "../../include/util.h"
|
#include "../../include/util.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
size_t lm_package_depend_count(lm_pkg_t *pkg){
|
ssize_t lm_package_data_depend_count(lm_pkg_data_t *data){
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
|
|
||||||
if(NULL == pkg->depends)
|
if(NULL == data->depends)
|
||||||
return index;
|
return index;
|
||||||
|
|
||||||
while(pkg->depends[index] != NULL)
|
while(data->depends[index] != NULL)
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_package_depend_add(lm_pkg_t *pkg, char *depend){
|
bool lm_package_data_depend_add(lm_pkg_data_t *data, char *depend){
|
||||||
if(NULL == depend){
|
if(NULL == depend){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return false;
|
return false;
|
||||||
@ -29,76 +28,76 @@ bool lm_package_depend_add(lm_pkg_t *pkg, char *depend){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NULL == pkg->depends){
|
if(NULL == data->depends){
|
||||||
pkg->depends = malloc(sizeof(char*)*2);
|
data->depends = malloc(sizeof(char*)*2);
|
||||||
pkg->depends[0] = strdup(depend);
|
data->depends[0] = strdup(depend);
|
||||||
pkg->depends[1] = NULL;
|
data->depends[1] = NULL;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t count = lm_package_depend_count(pkg);
|
size_t count = lm_package_data_depend_count(data);
|
||||||
pkg->depends = realloc(pkg->depends, sizeof(char*)*(count+2));
|
data->depends = realloc(data->depends, sizeof(char*)*(count+2));
|
||||||
pkg->depends[count++] = strdup(depend);
|
data->depends[count++] = strdup(depend);
|
||||||
pkg->depends[count] = NULL;
|
data->depends[count] = NULL;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lm_package_depend_free(lm_pkg_t *pkg){
|
void lm_package_data_depend_free(lm_pkg_data_t *data){
|
||||||
if(NULL == pkg)
|
if(NULL == data)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(NULL == pkg->depends)
|
if(NULL == data->depends)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(int i = 0; pkg->depends[i] != NULL; i++)
|
for(int i = 0; data->depends[i] != NULL; i++)
|
||||||
free(pkg->depends[i]);
|
free(data->depends[i]);
|
||||||
free(pkg->depends);
|
free(data->depends);
|
||||||
|
|
||||||
pkg->depends = NULL;
|
data->depends = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t lm_package_depend_strlen(lm_pkg_t *pkg){
|
ssize_t lm_package_data_depend_strlen(lm_pkg_data_t *data){
|
||||||
size_t len = 1;
|
size_t len = 1;
|
||||||
|
|
||||||
if(NULL == pkg->depends)
|
if(NULL == data->depends)
|
||||||
return len;
|
return len;
|
||||||
|
|
||||||
for(int i = 0; NULL != pkg->depends[i]; i++)
|
for(int i = 0; NULL != data->depends[i]; i++)
|
||||||
len += strlen(pkg->depends[i])+1;
|
len += strlen(data->depends[i])+1;
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *lm_package_depend_tostr(lm_pkg_t *pkg, char *buffer){
|
char *lm_package_data_depend_tostr(lm_pkg_data_t *data, char *buffer){
|
||||||
if(NULL == pkg){
|
if(NULL == data){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NULL == buffer){
|
if(NULL == buffer){
|
||||||
size_t buflen = lm_package_depend_strlen(pkg)+1;
|
size_t buflen = lm_package_data_depend_strlen(data)+1;
|
||||||
buffer = malloc(buflen);
|
buffer = malloc(buflen);
|
||||||
bzero(buffer, buflen);
|
bzero(buffer, buflen);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NULL == pkg->depends){
|
if(NULL == data->depends){
|
||||||
buffer[0] = 0;
|
buffer[0] = 0;
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bufsz = 0, depsz = 0;
|
size_t bufsz = 0, depsz = 0;
|
||||||
|
|
||||||
for(int i = 0; NULL != pkg->depends[i]; i++){
|
for(int i = 0; NULL != data->depends[i]; i++){
|
||||||
depsz = strlen(pkg->depends[i]);
|
depsz = strlen(data->depends[i]);
|
||||||
|
|
||||||
if(i == 0){
|
if(i == 0){
|
||||||
memcpy(buffer, pkg->depends[i], depsz);
|
memcpy(buffer, data->depends[i], depsz);
|
||||||
bufsz += depsz;
|
bufsz += depsz;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer[bufsz++] = ',';
|
buffer[bufsz++] = ',';
|
||||||
memcpy(buffer+bufsz, pkg->depends[i], depsz);
|
memcpy(buffer+bufsz, data->depends[i], depsz);
|
||||||
bufsz += depsz;
|
bufsz += depsz;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,13 +105,13 @@ char *lm_package_depend_tostr(lm_pkg_t *pkg, char *buffer){
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_package_depend_fromstr(lm_pkg_t *pkg, char *buffer){
|
bool lm_package_data_depend_fromstr(lm_pkg_data_t *data, char *buffer){
|
||||||
if(NULL == pkg){
|
if(NULL == data){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
lm_package_depend_free(pkg);
|
lm_package_data_depend_free(data);
|
||||||
|
|
||||||
if(NULL == buffer)
|
if(NULL == buffer)
|
||||||
return true;
|
return true;
|
||||||
@ -124,24 +123,24 @@ bool lm_package_depend_fromstr(lm_pkg_t *pkg, char *buffer){
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if(!lm_package_depend_add(pkg, dep))
|
if(!lm_package_data_depend_add(data, dep))
|
||||||
return false;
|
return false;
|
||||||
}while((dep = strtok_r(NULL, ",", &save)) != NULL);
|
}while((dep = strtok_r(NULL, ",", &save)) != NULL);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_package_depends(lm_pkg_t *pkg, char *dep){
|
bool lm_package_data_depends(lm_pkg_data_t *data, char *dep){
|
||||||
if(NULL == pkg || NULL == dep){
|
if(NULL == data || NULL == dep){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NULL == pkg->depends)
|
if(NULL == data->depends)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for(int i = 0; pkg->depends[i] != NULL; i++)
|
for(int i = 0; data->depends[i] != NULL; i++)
|
||||||
if(eq(pkg->depends[i], dep))
|
if(eq(data->depends[i], dep))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,69 +1,68 @@
|
|||||||
#include "../../include/package.h"
|
#include "../../include/package.h"
|
||||||
#include "../../include/types.h"
|
|
||||||
#include "../../include/error.h"
|
#include "../../include/error.h"
|
||||||
#include "../../include/util.h"
|
#include "../../include/util.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
size_t lm_package_keep_count(lm_pkg_t *pkg){
|
size_t lm_package_data_keep_count(lm_pkg_data_t *data){
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
|
|
||||||
if(NULL == pkg->keeps)
|
if(NULL == data->keeps)
|
||||||
return index;
|
return index;
|
||||||
|
|
||||||
while(pkg->keeps[index] != NULL)
|
while(data->keeps[index] != NULL)
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_package_keep_add(lm_pkg_t *pkg, char *path){
|
bool lm_package_data_keep_add(lm_pkg_data_t *data, char *path){
|
||||||
if(NULL == path){
|
if(NULL == path){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NULL == pkg->keeps){
|
if(NULL == data->keeps){
|
||||||
pkg->keeps = malloc(sizeof(char*)*2);
|
data->keeps = malloc(sizeof(char*)*2);
|
||||||
pkg->keeps[0] = strdup(path);
|
data->keeps[0] = strdup(path);
|
||||||
pkg->keeps[1] = NULL;
|
data->keeps[1] = NULL;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t count = lm_package_depend_count(pkg);
|
size_t count = lm_package_data_depend_count(data);
|
||||||
pkg->keeps = realloc(pkg->depends, sizeof(char*)*(count+2));
|
data->keeps = realloc(data->depends, sizeof(char*)*(count+2));
|
||||||
pkg->keeps[count++] = strdup(path);
|
data->keeps[count++] = strdup(path);
|
||||||
pkg->keeps[count] = NULL;
|
data->keeps[count] = NULL;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_package_keep_contains(lm_pkg_t *pkg, char *path){
|
bool lm_package_data_keep_contains(lm_pkg_data_t *data, char *path){
|
||||||
if(NULL == pkg || NULL == path){
|
if(NULL == data || NULL == path){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NULL == pkg->keeps)
|
if(NULL == data->keeps)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for(int i = 0; NULL != pkg->keeps[i]; i++)
|
for(int i = 0; NULL != data->keeps[i]; i++)
|
||||||
if(eq(pkg->keeps[i], path))
|
if(eq(data->keeps[i], path))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lm_package_keep_free(lm_pkg_t *pkg){
|
void lm_package_data_keep_free(lm_pkg_data_t *data){
|
||||||
if(NULL == pkg)
|
if(NULL == data)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(NULL == pkg->keeps)
|
if(NULL == data->keeps)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(int i = 0; pkg->keeps[i] != NULL; i++)
|
for(int i = 0; data->keeps[i] != NULL; i++)
|
||||||
free(pkg->keeps[i]);
|
free(data->keeps[i]);
|
||||||
free(pkg->keeps);
|
free(data->keeps);
|
||||||
|
|
||||||
pkg->keeps = NULL;
|
data->keeps = NULL;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include "../../include/package.h"
|
#include "../../include/package.h"
|
||||||
#include "../../include/error.h"
|
#include "../../include/error.h"
|
||||||
#include "../../include/types.h"
|
|
||||||
#include "../../include/mptp.h"
|
#include "../../include/mptp.h"
|
||||||
#include "../../include/util.h"
|
#include "../../include/util.h"
|
||||||
|
|
||||||
@ -26,7 +25,7 @@ bool lm_package_downloaded(lm_pkg_t *pkg){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!exists(pkg->paths.archive) || !exists(pkg->paths.signature)){
|
if(!exists(pkg->archive) || !exists(pkg->signature)){
|
||||||
lm_error_set(LM_ERR_PkgNotDownloaded);
|
lm_error_set(LM_ERR_PkgNotDownloaded);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -35,12 +34,12 @@ bool lm_package_downloaded(lm_pkg_t *pkg){
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool lm_package_remove_download(lm_pkg_t *pkg){
|
bool lm_package_remove_download(lm_pkg_t *pkg){
|
||||||
if(unlink(pkg->paths.archive) < 0 && errno != ENOENT){
|
if(unlink(pkg->archive) < 0 && errno != ENOENT){
|
||||||
lm_error_set(LM_ERR_PkgRemoveDownloadFail);
|
lm_error_set(LM_ERR_PkgRemoveDownloadFail);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(unlink(pkg->paths.signature) < 0 && errno != ENOENT){
|
if(unlink(pkg->signature) < 0 && errno != ENOENT){
|
||||||
lm_error_set(LM_ERR_PkgRemoveDownloadFail);
|
lm_error_set(LM_ERR_PkgRemoveDownloadFail);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -54,41 +53,15 @@ bool lm_package_is_same(lm_pkg_t *one, lm_pkg_t *two){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return eq(one->version, two->version) &&
|
return eq(one->data.version, two->data.version) &&
|
||||||
eq(one->name, two->name) &&
|
eq(one->data.name, two->data.name) &&
|
||||||
eq(one->desc, two->desc) &&
|
eq(one->data.desc, two->data.desc) &&
|
||||||
one->size == two->size;
|
one->data.size == two->data.size;
|
||||||
}
|
|
||||||
|
|
||||||
bool lm_package_copy(lm_pkg_t *dst, lm_pkg_t *src){
|
|
||||||
lm_package_init(dst);
|
|
||||||
|
|
||||||
if(NULL != src->name)
|
|
||||||
dst->name = strdup(src->name);
|
|
||||||
|
|
||||||
if(NULL != src->version)
|
|
||||||
dst->version = strdup(src->version);
|
|
||||||
|
|
||||||
if(NULL != src->desc)
|
|
||||||
dst->desc = strdup(src->desc);
|
|
||||||
|
|
||||||
dst->size = src->size;
|
|
||||||
dst->pool = src->pool;
|
|
||||||
|
|
||||||
if(NULL != src->keeps){
|
|
||||||
for(int i = 0; src->keeps[i] != NULL; i++)
|
|
||||||
lm_package_keep_add(dst, src->keeps[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(NULL != src->depends){
|
|
||||||
for(int i = 0; src->depends[i] != NULL; i++)
|
|
||||||
lm_package_depend_add(dst, src->depends[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return lm_package_path_copy(dst, src);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lm_package_free(lm_pkg_t *pkg){
|
void lm_package_free(lm_pkg_t *pkg){
|
||||||
lm_package_data_free(pkg);
|
free(pkg->archive);
|
||||||
|
free(pkg->signature);
|
||||||
|
lm_package_data_free(&pkg->data);
|
||||||
bzero(pkg, sizeof(lm_pkg_t));
|
bzero(pkg, sizeof(lm_pkg_t));
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
#include "../../include/package.h"
|
#include "../../include/package.h"
|
||||||
#include "../../include/error.h"
|
#include "../../include/error.h"
|
||||||
#include "../../include/types.h"
|
|
||||||
#include "../../include/util.h"
|
#include "../../include/util.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
bool lm_package_path_set_archive(lm_pkg_t *pkg, char *archive_path){
|
bool lm_package_path_set_archive(lm_pkg_t *pkg, char *archive_path){
|
||||||
free(pkg->paths.archive);
|
free(pkg->archive);
|
||||||
pkg->paths.archive = NULL;
|
pkg->archive = NULL;
|
||||||
|
|
||||||
if(NULL == archive_path)
|
if(NULL == archive_path)
|
||||||
return true;
|
return true;
|
||||||
@ -16,13 +15,13 @@ bool lm_package_path_set_archive(lm_pkg_t *pkg, char *archive_path){
|
|||||||
if(is_dir(archive_path))
|
if(is_dir(archive_path))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
pkg->paths.archive = strdup(archive_path);
|
pkg->archive = strdup(archive_path);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_package_path_set_signature(lm_pkg_t *pkg, char *signature_path){
|
bool lm_package_path_set_signature(lm_pkg_t *pkg, char *signature_path){
|
||||||
free(pkg->paths.signature);
|
free(pkg->signature);
|
||||||
pkg->paths.signature = NULL;
|
pkg->signature = NULL;
|
||||||
|
|
||||||
if(NULL == signature_path)
|
if(NULL == signature_path)
|
||||||
return true;
|
return true;
|
||||||
@ -30,13 +29,13 @@ bool lm_package_path_set_signature(lm_pkg_t *pkg, char *signature_path){
|
|||||||
if(is_dir(signature_path))
|
if(is_dir(signature_path))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
pkg->paths.signature = strdup(signature_path);
|
pkg->signature = strdup(signature_path);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_package_path_is_empty(lm_pkg_t *pkg){
|
bool lm_package_path_is_empty(lm_pkg_t *pkg){
|
||||||
return NULL == pkg->paths.signature ||
|
return NULL == pkg->signature ||
|
||||||
NULL == pkg->paths.archive;
|
NULL == pkg->archive;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lm_package_path_copy(lm_pkg_t *dst, lm_pkg_t *src){
|
bool lm_package_path_copy(lm_pkg_t *dst, lm_pkg_t *src){
|
||||||
@ -45,16 +44,11 @@ bool lm_package_path_copy(lm_pkg_t *dst, lm_pkg_t *src){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(NULL != src->paths.archive)
|
if(NULL != src->archive)
|
||||||
dst->paths.archive = strdup(src->paths.archive);
|
dst->archive = strdup(src->archive);
|
||||||
|
|
||||||
if(NULL != src->paths.signature)
|
if(NULL != src->signature)
|
||||||
dst->paths.signature = strdup(src->paths.signature);
|
dst->signature = strdup(src->signature);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lm_package_path_free(lm_pkg_t *pkg){
|
|
||||||
free(pkg->paths.signature);
|
|
||||||
free(pkg->paths.archive);
|
|
||||||
}
|
|
||||||
|
@ -26,27 +26,27 @@ bool lm_package_verify(lm_pkg_t *pkg){
|
|||||||
err = gpgme_new(&ctx);
|
err = gpgme_new(&ctx);
|
||||||
|
|
||||||
if (err != GPG_ERR_NO_ERROR) {
|
if (err != GPG_ERR_NO_ERROR) {
|
||||||
pdebug(__func__, "(%s) failed to create gpgme: %s", pkg->name, gpgme_strerror(err));
|
pdebug(__func__, "(%s) failed to create gpgme: %s", pkg->data.name, gpgme_strerror(err));
|
||||||
lm_error_set(LM_ERR_PkgGPGFail);
|
lm_error_set(LM_ERR_PkgGPGFail);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
gpgme_op_import(ctx, NULL);
|
gpgme_op_import(ctx, NULL);
|
||||||
|
|
||||||
if((err = gpgme_data_new_from_file(&sig, pkg->paths.signature, 1)) != GPG_ERR_NO_ERROR){
|
if((err = gpgme_data_new_from_file(&sig, pkg->signature, 1)) != GPG_ERR_NO_ERROR){
|
||||||
pdebug(__func__, "(%s) failed to import package signature %s", pkg->name, gpgme_strerror(err));
|
pdebug(__func__, "(%s) failed to import package signature %s", pkg->data.name, gpgme_strerror(err));
|
||||||
lm_error_set(LM_ERR_PkgGPGSigFail);
|
lm_error_set(LM_ERR_PkgGPGSigFail);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = gpgme_data_new_from_file(&text, pkg->paths.archive, 1)) != GPG_ERR_NO_ERROR) {
|
if ((err = gpgme_data_new_from_file(&text, pkg->archive, 1)) != GPG_ERR_NO_ERROR) {
|
||||||
pdebug(__func__, "(%s) failed to import package archive %s", pkg->name, gpgme_strerror(err));
|
pdebug(__func__, "(%s) failed to import package archive %s", pkg->data.name, gpgme_strerror(err));
|
||||||
lm_error_set(LM_ERR_PkgGPGArchiveFail);
|
lm_error_set(LM_ERR_PkgGPGArchiveFail);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = gpgme_op_verify(ctx, sig, text, NULL)) != GPG_ERR_NO_ERROR) {
|
if ((err = gpgme_op_verify(ctx, sig, text, NULL)) != GPG_ERR_NO_ERROR) {
|
||||||
pdebug(__func__, "(%s) failed to verify package archive %s", pkg->name, gpgme_strerror(err));
|
pdebug(__func__, "(%s) failed to verify package archive %s", pkg->data.name, gpgme_strerror(err));
|
||||||
lm_error_set(LM_ERR_PkgSigNoResult);
|
lm_error_set(LM_ERR_PkgSigNoResult);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
@ -40,12 +40,12 @@ bool lm_pool_info_load(lm_pool_t *pool) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!exists(pool->paths.info_file) || !can_read(pool->paths.info_file)){
|
if(!exists(pool->info_file) || !can_read(pool->info_file)){
|
||||||
lm_error_set(LM_ERR_PoolInfoCantRead);
|
lm_error_set(LM_ERR_PoolInfoCantRead);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ini_parse(pool->paths.info_file, lm_pool_info_handler, pool) < 0) {
|
if (ini_parse(pool->info_file, lm_pool_info_handler, pool) < 0) {
|
||||||
lm_error_set(LM_ERR_PoolInfoBad);
|
lm_error_set(LM_ERR_PoolInfoBad);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ bool lm_pool_info_download(lm_pool_t *pool, lm_mptp_transfer_callback_t callback
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!mkdir_ifnot(pool->paths.dir)){
|
if(!mkdir_ifnot(pool->dir)){
|
||||||
lm_error_set(LM_ERR_PoolBadDir);
|
lm_error_set(LM_ERR_PoolBadDir);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ bool lm_pool_info_download(lm_pool_t *pool, lm_mptp_transfer_callback_t callback
|
|||||||
if(!lm_mptp_client_send(sock, &packet))
|
if(!lm_mptp_client_send(sock, &packet))
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
if(!lm_mptp_recvfile(sock, pool->paths.info_file, callback, data))
|
if(!lm_mptp_recvfile(sock, pool->info_file, callback, data))
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
|
@ -22,32 +22,32 @@ bool lm_pool_list_load(lm_pool_t *pool){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!exists(pool->paths.list_file) || !can_read(pool->paths.list_file)){
|
if(!exists(pool->list_file) || !can_read(pool->list_file)){
|
||||||
lm_error_set(LM_ERR_PoolListCantRead);
|
lm_error_set(LM_ERR_PoolListCantRead);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdebug(__func__, "(%s) extracting pool to %s", pool->name, pool->paths.list_dir);
|
pdebug(__func__, "(%s) extracting pool to %s", pool->name, pool->list_dir);
|
||||||
|
|
||||||
if(!mkdir_ifnot(pool->paths.dir)){
|
if(!mkdir_ifnot(pool->dir)){
|
||||||
lm_error_set(LM_ERR_PoolBadDir);
|
lm_error_set(LM_ERR_PoolBadDir);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!mkdir_ifnot(pool->paths.list_dir)){
|
if(!mkdir_ifnot(pool->list_dir)){
|
||||||
lm_error_set(LM_ERR_PoolBadPaths);
|
lm_error_set(LM_ERR_PoolBadPaths);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ent_len = 0, list_dir_len = strlen(pool->paths.list_dir);
|
size_t ent_len = 0, list_dir_len = strlen(pool->list_dir);
|
||||||
struct dirent *ent = NULL;
|
struct dirent *ent = NULL;
|
||||||
DIR *dirfd = NULL;
|
DIR *dirfd = NULL;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
if(!extract_archive(pool->paths.list_dir, pool->paths.list_file))
|
if(!extract_archive(pool->list_dir, pool->list_file))
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
if((dirfd = opendir(pool->paths.list_dir)) == NULL){
|
if((dirfd = opendir(pool->list_dir)) == NULL){
|
||||||
lm_error_set(LM_ERR_PoolListDirFail);
|
lm_error_set(LM_ERR_PoolListDirFail);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@ -58,23 +58,23 @@ bool lm_pool_list_load(lm_pool_t *pool){
|
|||||||
|
|
||||||
ent_len = strlen(ent->d_name);
|
ent_len = strlen(ent->d_name);
|
||||||
char datap[ent_len+list_dir_len+10];
|
char datap[ent_len+list_dir_len+10];
|
||||||
join_multiple(datap, pool->paths.list_dir, ent->d_name, "DATA");
|
join_multiple(datap, pool->list_dir, ent->d_name, "DATA");
|
||||||
|
|
||||||
lm_pkg_t *pkg = lm_package_new();
|
lm_pkg_t *pkg = lm_package_new();
|
||||||
|
|
||||||
if(!lm_package_data_load(pkg, 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", pool->name, datap);
|
||||||
lm_package_free(pkg);
|
lm_package_free(pkg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
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->name);
|
pdebug(__func__, "(%s) failed to add new package: %s", pool->name, pkg->data.name);
|
||||||
lm_package_free(pkg);
|
lm_package_free(pkg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdebug(__func__, "(%s) added new package: %s", pool->name, pkg->name);
|
pdebug(__func__, "(%s) added new package: %s", pool->name, pkg->data.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
@ -101,12 +101,12 @@ bool lm_pool_list_download(lm_pool_t *pool, lm_mptp_transfer_callback_t callback
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!mkdir_ifnot(pool->paths.dir)){
|
if(!mkdir_ifnot(pool->dir)){
|
||||||
lm_error_set(LM_ERR_PoolBadDir);
|
lm_error_set(LM_ERR_PoolBadDir);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!mkdir_ifnot(pool->paths.list_dir)){
|
if(!mkdir_ifnot(pool->list_dir)){
|
||||||
lm_error_set(LM_ERR_PoolBadPaths);
|
lm_error_set(LM_ERR_PoolBadPaths);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ bool lm_pool_list_download(lm_pool_t *pool, lm_mptp_transfer_callback_t callback
|
|||||||
if(!lm_mptp_client_send(sock, &packet))
|
if(!lm_mptp_client_send(sock, &packet))
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
if(!lm_mptp_recvfile(sock, pool->paths.list_file, callback, data))
|
if(!lm_mptp_recvfile(sock, pool->list_file, callback, data))
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
|
@ -14,13 +14,13 @@ lm_pkg_t *lm_pool_package_find(lm_pool_t *pool, char *name, char *version){
|
|||||||
|
|
||||||
lm_pkg_t *cur = pool->pkg;
|
lm_pkg_t *cur = pool->pkg;
|
||||||
while(NULL != cur){
|
while(NULL != cur){
|
||||||
if(NULL == version && eq(cur->name, name))
|
if(NULL == version && eq(cur->data.name, name))
|
||||||
return cur;
|
return cur;
|
||||||
|
|
||||||
else if(NULL == name && eq(cur->version, version))
|
else if(NULL == name && eq(cur->data.version, version))
|
||||||
return cur;
|
return cur;
|
||||||
|
|
||||||
else if(eq(cur->name, name) && eq(cur->version, version))
|
else if(eq(cur->data.name, name) && eq(cur->data.version, version))
|
||||||
return cur;
|
return cur;
|
||||||
|
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
@ -38,17 +38,17 @@ bool lm_pool_package_add(lm_pool_t *pool, lm_pkg_t *pkg){
|
|||||||
pkg->pool = pool;
|
pkg->pool = pool;
|
||||||
|
|
||||||
if(!lm_pool_path_is_empty(pool)){
|
if(!lm_pool_path_is_empty(pool)){
|
||||||
size_t path_size = strlen(pool->paths.dir)+strlen(pkg->name)+strlen(pkg->version);
|
size_t path_size = strlen(pool->dir)+strlen(pkg->data.name)+strlen(pkg->data.version);
|
||||||
size_t name_size = path_size - strlen(pool->paths.dir);
|
size_t name_size = path_size - strlen(pool->dir);
|
||||||
|
|
||||||
char archive_path[path_size+10], sig_path[path_size+20];
|
char archive_path[path_size+10], sig_path[path_size+20];
|
||||||
char archive_name[name_size+10], sig_name[name_size+20];
|
char archive_name[name_size+10], sig_name[name_size+20];
|
||||||
|
|
||||||
sprintf(archive_name, "%s_%s.mpf", pkg->name, pkg->version);
|
sprintf(archive_name, "%s_%s.mpf", pkg->data.name, pkg->data.version);
|
||||||
sprintf(sig_name, "%s_%s.mpf.sig", pkg->name, pkg->version);
|
sprintf(sig_name, "%s_%s.mpf.sig", pkg->data.name, pkg->data.version);
|
||||||
|
|
||||||
join(archive_path, pool->paths.dir, archive_name);
|
join(archive_path, pool->dir, archive_name);
|
||||||
join(sig_path, pool->paths.dir, sig_name);
|
join(sig_path, pool->dir, sig_name);
|
||||||
|
|
||||||
lm_package_path_set_archive(pkg, archive_path);
|
lm_package_path_set_archive(pkg, archive_path);
|
||||||
lm_package_path_set_signature(pkg, sig_path);
|
lm_package_path_set_signature(pkg, sig_path);
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#include "../../include/types.h"
|
|
||||||
#include "../../include/error.h"
|
#include "../../include/error.h"
|
||||||
#include "../../include/pool.h"
|
#include "../../include/pool.h"
|
||||||
#include "../../include/util.h"
|
#include "../../include/util.h"
|
||||||
@ -7,8 +6,15 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
bool lm_pool_path_set_dir(lm_pool_t *pool, char *dir){
|
bool lm_pool_path_set_dir(lm_pool_t *pool, char *dir){
|
||||||
free(pool->paths.dir);
|
free(pool->dir);
|
||||||
pool->paths.dir = NULL;
|
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;
|
||||||
|
|
||||||
if(NULL == dir)
|
if(NULL == dir)
|
||||||
return true;
|
return true;
|
||||||
@ -18,25 +24,22 @@ bool lm_pool_path_set_dir(lm_pool_t *pool, char *dir){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pool->paths.dir = strdup(dir);
|
pool->dir = strdup(dir);
|
||||||
pool->paths.info_file = join_alloc(dir, "INFO");
|
pool->info_file = join_alloc(dir, "INFO");
|
||||||
pool->paths.list_file = join_alloc(dir, "LIST");
|
pool->list_file = join_alloc(dir, "LIST");
|
||||||
pool->paths.list_dir = join_alloc(dir, "LIST_extracted");
|
pool->list_dir = join_alloc(dir, "LIST_extracted");
|
||||||
|
|
||||||
if(exists(pool->paths.info_file) && (!is_file(pool->paths.info_file) || !can_read(pool->paths.info_file) || !can_write(pool->paths.info_file))){
|
if(exists(pool->info_file) && (!is_file(pool->info_file) || !can_read(pool->info_file) || !can_write(pool->info_file))){
|
||||||
lm_pool_path_free(pool);
|
|
||||||
lm_error_set(LM_ERR_PoolBadPaths);
|
lm_error_set(LM_ERR_PoolBadPaths);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(exists(pool->paths.list_file) && (!is_file(pool->paths.list_file) || !can_read(pool->paths.list_file) || !can_write(pool->paths.list_file))){
|
if(exists(pool->list_file) && (!is_file(pool->list_file) || !can_read(pool->list_file) || !can_write(pool->list_file))){
|
||||||
lm_pool_path_free(pool);
|
|
||||||
lm_error_set(LM_ERR_PoolBadPaths);
|
lm_error_set(LM_ERR_PoolBadPaths);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(exists(pool->paths.list_dir) && (is_file(pool->paths.list_dir) || !can_read(pool->paths.list_dir) || !can_write(pool->paths.list_dir))){
|
if(exists(pool->list_dir) && (is_file(pool->list_dir) || !can_read(pool->list_dir) || !can_write(pool->list_dir))){
|
||||||
lm_pool_path_free(pool);
|
|
||||||
lm_error_set(LM_ERR_PoolBadPaths);
|
lm_error_set(LM_ERR_PoolBadPaths);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -45,16 +48,8 @@ bool lm_pool_path_set_dir(lm_pool_t *pool, char *dir){
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool lm_pool_path_is_empty(lm_pool_t *pool){
|
bool lm_pool_path_is_empty(lm_pool_t *pool){
|
||||||
return NULL == pool->paths.info_file ||
|
return NULL == pool->info_file ||
|
||||||
NULL == pool->paths.list_file ||
|
NULL == pool->list_file ||
|
||||||
NULL == pool->paths.list_dir ||
|
NULL == pool->list_dir ||
|
||||||
NULL == pool->paths.dir;
|
NULL == pool->dir;
|
||||||
}
|
|
||||||
|
|
||||||
void lm_pool_path_free(lm_pool_t *pool){
|
|
||||||
free(pool->paths.dir);
|
|
||||||
free(pool->paths.list_dir);
|
|
||||||
free(pool->paths.info_file);
|
|
||||||
free(pool->paths.list_file);
|
|
||||||
bzero(&pool->paths, sizeof(pool->paths));
|
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,10 @@ end:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void lm_pool_free(lm_pool_t *pool) {
|
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_url_free(&pool->url);
|
||||||
lm_pool_info_free(pool);
|
lm_pool_info_free(pool);
|
||||||
lm_pool_list_free(pool);
|
lm_pool_list_free(pool);
|
||||||
|
37
src/util.c
37
src/util.c
@ -1,16 +1,17 @@
|
|||||||
#include "../include/util.h"
|
#include "../include/util.h"
|
||||||
#include "../include/error.h"
|
#include "../include/error.h"
|
||||||
#include "../include/types.h"
|
|
||||||
|
|
||||||
#include <archive.h>
|
#include <archive.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <linux/limits.h>
|
#include <linux/limits.h>
|
||||||
#include <openssl/evp.h>
|
#include <openssl/evp.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
void pdebug(const char *func, const char *fmt, ...) {
|
void pdebug(const char *func, const char *fmt, ...) {
|
||||||
if (LM_DEBUG != 1)
|
if (LM_DEBUG != 1)
|
||||||
@ -324,7 +325,7 @@ char *join_alloc(const char *base, const char *pth) {
|
|||||||
bool pkglist_contains(lm_pkg_t *list, lm_pkg_t *pkg) {
|
bool pkglist_contains(lm_pkg_t *list, lm_pkg_t *pkg) {
|
||||||
lm_pkg_t *cur = list;
|
lm_pkg_t *cur = list;
|
||||||
while (cur) {
|
while (cur) {
|
||||||
if (eq(pkg->name, cur->name))
|
if (eq(pkg->data.name, cur->data.name))
|
||||||
return true;
|
return true;
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
@ -340,7 +341,7 @@ lm_pkg_t *pkglist_del(lm_pkg_t *list, lm_pkg_t *pkg) {
|
|||||||
if (NULL == list)
|
if (NULL == list)
|
||||||
return list;
|
return list;
|
||||||
|
|
||||||
if (eq(list->name, pkg->name)) {
|
if (eq(list->data.name, pkg->data.name)) {
|
||||||
list = NULL;
|
list = NULL;
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@ -349,7 +350,7 @@ lm_pkg_t *pkglist_del(lm_pkg_t *list, lm_pkg_t *pkg) {
|
|||||||
lm_pkg_t *found = NULL;
|
lm_pkg_t *found = NULL;
|
||||||
|
|
||||||
while (NULL != cur->next) {
|
while (NULL != cur->next) {
|
||||||
if (eq(cur->next->name, pkg->name)) {
|
if (eq(cur->next->data.name, pkg->data.name)) {
|
||||||
found = cur->next;
|
found = cur->next;
|
||||||
cur->next = cur->next->next;
|
cur->next = cur->next->next;
|
||||||
break;
|
break;
|
||||||
@ -469,3 +470,31 @@ char *get_md5(char *path) {
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_empty(char *p) {
|
||||||
|
char buf[1];
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
bzero(buf, sizeof(buf));
|
||||||
|
bzero(&st, sizeof(st));
|
||||||
|
stat(p, &st);
|
||||||
|
|
||||||
|
if (st.st_size <= 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (st.st_size > 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int fd = open(p, O_RDONLY);
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
if (read(fd, buf, 1) != 1)
|
||||||
|
goto end;
|
||||||
|
|
||||||
|
if (buf[0] == ' ' || buf[0] == '\n')
|
||||||
|
ret = true;
|
||||||
|
|
||||||
|
end:
|
||||||
|
close(fd);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user