aboutsummaryrefslogtreecommitdiff
path: root/src/recipes.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/recipes.c')
-rw-r--r--src/recipes.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/src/recipes.c b/src/recipes.c
index d94ee3c..41af109 100644
--- a/src/recipes.c
+++ b/src/recipes.c
@@ -58,8 +58,13 @@ static bool pkg_read_status(const char desired, package_t *pkg) {
bool success = false;
str pkgit_status = str_format("%.*s/.pkgit_status",
str_fmt(&pkg->src));
+ if (!file_exists(pkgit_status.data)) {
+ log_info("%.*s doesn't exist", str_fmt(&pkgit_status));
+ str_free(&pkgit_status);
+ return false;
+ }
str status = file_read(&pkgit_status);
- success = str_find_char(&status, desired);
+ success = (str_find_char(&status, desired) == 0);
str_free(&pkgit_status);
str_free(&status);
return success;
@@ -119,8 +124,11 @@ bool pkg_install(package_t *pkg) {
if (is_pkg_installed(pkg) && !flags.force) return true;
try_pkg_fn(pkg_fetch_sources, pkg, "fetch", 'f');
if (!pkg_enter(pkg)) return false;
- try_pkg_fn(pkg_hook_setup, pkg, "setup", 's');
- try_pkg_fn(pkg_hook_build, pkg, "build", 'b');
+ pkg_setup(pkg);
+ //try_pkg_fn(pkg_hook_setup, pkg, "setup", 's');
+ pkg_build(pkg);
+ //try_pkg_fn(pkg_hook_build, pkg, "build", 'b');
+ printf("test\n");
try_pkg_fn(pkg_hook_install, pkg, "install", 'i');
log_success("'%.*s' installed", str_fmt(&pkg->name));
return true;
@@ -134,9 +142,29 @@ bool pkg_remove(package_t *pkg) {
return true;
}
+static bool is_latest(package_t *pkg) {
+ bool result = false;
+ if (str_is_valid(&pkg->src) && pkg->src.len > 0 &&
+ chdir(pkg->src.data) != 0) return result;
+ str latest_version = pkg_get_latest_version(pkg);
+ result = (strcmp(pkg->version.data, latest_version.data) != 0);
+ str_free(&latest_version);
+ return result;
+}
+
bool pkg_update(package_t *pkg) {
- pkg_install(pkg);
- log_success("'%.*s' is up to date", str_fmt(&pkg->name));
+ if (!is_latest(pkg)) {
+ if (pkg_install(pkg)) log_success(
+ "'%.*s' is up to date", str_fmt(&pkg->name)
+ );
+ } else if (flags.force) {
+ log_warn("'%.*s' is already up to date", str_fmt(&pkg->name));
+ if (pkg_install(pkg)) log_success(
+ "'%.*s' is up to date", str_fmt(&pkg->name)
+ );
+ } else {
+ log_info("'%.*s' is already up to date", str_fmt(&pkg->name));
+ }
return true;
}