diff options
| author | dacctal <donotcontactmevia@email.invalid> | 2026-08-20 10:51:26 +0000 |
|---|---|---|
| committer | dacctal <donotcontactmevia@email.invalid> | 2026-08-20 10:51:26 +0000 |
| commit | d62326ee93521de490e5bc8d37bf234111187e20 (patch) | |
| tree | 8d270aa3b737af47871bfb47937b17154e81f4f9 | |
| parent | 51983b47b22db7bf819e9880caa2b72bdb8c9942 (diff) | |
barebones update functionality
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | include/lua_state.h | 2 | ||||
| -rw-r--r-- | include/pkg.h | 4 | ||||
| -rw-r--r-- | src/hooks.c | 11 | ||||
| -rw-r--r-- | src/recipes.c | 37 |
5 files changed, 49 insertions, 7 deletions
@@ -21,7 +21,7 @@ GIT_DATE := $(shell git log -1 --format='%ad' --date='format:%y.%m.%d') GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD) GIT_REMOTE := $(shell git remote get-url origin) GIT_TAG := $(shell git describe --tags --exact-match HEAD 2>/dev/null) -VERSION := $(if $(GIT_TAG),$(GIT_TAG),$(GIT_DATE)_$(GIT_BRANCH) ($(GIT_HASH))) +VERSION := $(if $(GIT_TAG),$(GIT_TAG),$(GIT_DATE)_$(GIT_BRANCH) [ commit $(GIT_HASH) ]) CC ?= cc RM = rm -f diff --git a/include/lua_state.h b/include/lua_state.h index 97740e7..0caf62f 100644 --- a/include/lua_state.h +++ b/include/lua_state.h @@ -14,6 +14,8 @@ bool init_lua_config(void); void free_lua_state(void); void free_lua_config(void); +bool config_hook_on_update(void); + #define lua_get_field_type(name, type, file, pop_num) \ do { \ lua_getfield(L, -1, name); \ diff --git a/include/pkg.h b/include/pkg.h index d6e6cf0..6b13e71 100644 --- a/include/pkg.h +++ b/include/pkg.h @@ -12,8 +12,6 @@ typedef struct package_t { package_t pkg_create(str *arg); bool pkg_exists(str *name); -bool pkg_hook_url(package_t *pkg); -str pkg_get_url(package_t *pkg); bool pkg_hook_setup(package_t *pkg); bool pkg_hook_build(package_t *pkg); bool pkg_hook_install(package_t *pkg); @@ -22,6 +20,8 @@ bool pkg_hook_on_update(package_t *pkg); bool pkg_hook_fetch_sources(package_t *pkg); bool pkg_hook_fetch_latest_version(package_t *pkg); str pkg_get_latest_version(package_t *pkg); +bool pkg_hook_url(package_t *pkg); +str pkg_get_url(package_t *pkg); bool pkg_setup(package_t *pkg); bool pkg_build(package_t *pkg); diff --git a/src/hooks.c b/src/hooks.c index 448c7a4..18ad31c 100644 --- a/src/hooks.c +++ b/src/hooks.c @@ -134,3 +134,14 @@ bool pkg_hook_on_update(package_t *pkg) { pkg_hook_recipe("on_update", pkg); return true; } + +bool config_hook_on_update(void) { + lua_get_field_type("on_update", function, &config.init_path, 1); + lua_run_function("on_update", &config.init_path, 0, 1, 1); + if (!lua_isnumber(L, -1) || lua_tonumber(L, -1) != 0) { + lua_pop(L, 1); + return false; + } + lua_pop(L, 1); + return true; +} diff --git a/src/recipes.c b/src/recipes.c index 206d7d2..d94ee3c 100644 --- a/src/recipes.c +++ b/src/recipes.c @@ -18,11 +18,14 @@ */ +#include <dirent.h> +#include <string.h> #include <unistd.h> #include "common.h" #include "files.h" #include "log.h" +#include "lua_state.h" #include "pkg.h" #include "state.h" @@ -98,7 +101,7 @@ static bool pkg_enter(package_t *pkg) { bool pkg_setup(package_t *pkg) { if (pkg_read_status('s', pkg)) return true; - try_pkg_fn(pkg_enter, pkg, "enter", 'e'); + if (!pkg_enter(pkg)) return false; try_pkg_fn(pkg_hook_setup, pkg, "setup", 's'); log_success("'%.*s' set up", str_fmt(&pkg->name)); return true; @@ -106,7 +109,7 @@ bool pkg_setup(package_t *pkg) { bool pkg_build(package_t *pkg) { if (pkg_read_status('b', pkg)) return true; - try_pkg_fn(pkg_enter, pkg, "enter", 'e'); + if (!pkg_enter(pkg)) return false; try_pkg_fn(pkg_hook_build, pkg, "build", 'b'); log_success("'%.*s' built", str_fmt(&pkg->name)); return true; @@ -115,7 +118,7 @@ bool pkg_build(package_t *pkg) { bool pkg_install(package_t *pkg) { if (is_pkg_installed(pkg) && !flags.force) return true; try_pkg_fn(pkg_fetch_sources, pkg, "fetch", 'f'); - try_pkg_fn(pkg_enter, pkg, "enter", 'e'); + if (!pkg_enter(pkg)) return false; try_pkg_fn(pkg_hook_setup, pkg, "setup", 's'); try_pkg_fn(pkg_hook_build, pkg, "build", 'b'); try_pkg_fn(pkg_hook_install, pkg, "install", 'i'); @@ -133,6 +136,32 @@ bool pkg_remove(package_t *pkg) { bool pkg_update(package_t *pkg) { pkg_install(pkg); - log_success("'%.*s' updated", str_fmt(&pkg->name)); + log_success("'%.*s' is up to date", str_fmt(&pkg->name)); + return true; +} + +bool all_update(void) { + struct dirent* dirent_ptr; + DIR* dir_ptr; + if ((dir_ptr = opendir(config.inst_dirs.src.data)) == NULL) { + log_error("could not open %s", str_fmt(&config.inst_dirs.src)); + } + while ((dirent_ptr = readdir(dir_ptr)) != NULL) { + if ( + strcmp(dirent_ptr->d_name, "..") == 0 || + strcmp(dirent_ptr->d_name, ".") == 0 + ) continue; + str pkg_name = mstr(dirent_ptr->d_name); + if (!pkg_exists(&pkg_name)) { + str_free(&pkg_name); + continue; + } + package_t pkg = pkg_create(&pkg_name); + pkg_update(&pkg); + pkg_free(&pkg); + if (str_is_valid(&pkg_name)) str_free(&pkg_name); + } + closedir(dir_ptr); + config_hook_on_update(); return true; } |
