diff options
Diffstat (limited to 'src/repo.c')
| -rw-r--r-- | src/repo.c | 59 |
1 files changed, 42 insertions, 17 deletions
@@ -1,4 +1,27 @@ +/* + + pow! - the pow!erful package manager + + Copyright (C) 2026 forever2k38 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + #include "repo.h" +#include "config.h" +#include "log.h" #include "dirent.h" #include "limits.h" @@ -7,10 +30,10 @@ #include "stdio.h" #include <lua.h> -int pow_repo_get_package(pow_repo **repos, size_t repo_count, pow_package *pkg, +int pow_repo_get_package(pow_config *cfg, pow_package *pkg, const char *query) { - if (!repos) { - printf("no repos defined in your config, please define them\n"); + if (!cfg->repos) { + pow_log_error("no repos defined in your config, please define them"); return 1; } @@ -18,21 +41,21 @@ int pow_repo_get_package(pow_repo **repos, size_t repo_count, pow_package *pkg, DIR *dp; struct dirent *ep; - for (size_t i = 0; i < repo_count; i++) { + for (size_t i = 0; i < cfg->repos_count; i++) { char *package_path = malloc(PATH_MAX); if (!package_path) { - printf("failed to allocate package_path, sizeof %d\n", PATH_MAX); + pow_log_error("failed to allocate package_path, sizeof %d", PATH_MAX); return 1; } int written = - snprintf(package_path, PATH_MAX, "%s/%s", repos[i]->path, query); + snprintf(package_path, PATH_MAX, "%s/%s", cfg->repos[i]->path, query); if (written >= PATH_MAX) { - printf("something went seriously wrong. the path for the package %s is " - "too long?\n", + pow_log_error("something went seriously wrong. the path for the package %s is " + "too long?", query); free(package_path); @@ -48,14 +71,14 @@ int pow_repo_get_package(pow_repo **repos, size_t repo_count, pow_package *pkg, continue; } - printf("found package %s in repo %s\n", query, repos[i]->path); + pow_log_info("found package %s in repo %s", query, cfg->repos[i]->path); char *full_path = malloc(PATH_MAX); if (!full_path) { free(package_path); - printf("failed to malloc full path for build script\n"); + pow_log_error("failed to malloc full path for build script"); return 1; } @@ -63,9 +86,9 @@ int pow_repo_get_package(pow_repo **repos, size_t repo_count, pow_package *pkg, written = snprintf(full_path, PATH_MAX, "%s/%s", package_path, "build.lua"); if (written >= PATH_MAX) { - printf("something went seriously wrong. the path for the package build " + pow_log_error("something went seriously wrong. the path for the package build " "script %s is " - "too long?\n", + "too long?", query); free(package_path); @@ -76,29 +99,31 @@ int pow_repo_get_package(pow_repo **repos, size_t repo_count, pow_package *pkg, free(package_path); - pow_package_open(pkg, full_path); + pow_package_open(pkg, cfg, full_path); free(full_path); closedir(dp); + + return 0; } - return 0; + return 1; } -int pow_repo_check_package(pow_repo **repos, size_t repo_count, +int pow_repo_check_package(pow_config *cfg, const char *query) { int err; pow_package *pkg = malloc(sizeof(pow_package)); if (!pkg) { - printf("failed to malloc pow_package\n"); + pow_log_error("failed to malloc pow_package"); return 1; } - err = pow_repo_get_package(repos, repo_count, pkg, query); + err = pow_repo_get_package(cfg, pkg, query); if (err) { return 1; |
