aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/hooks.c11
-rw-r--r--src/recipes.c37
2 files changed, 44 insertions, 4 deletions
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;
}