aboutsummaryrefslogtreecommitdiff
path: root/src/pkg.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg.c')
-rw-r--r--src/pkg.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/pkg.c b/src/pkg.c
index 5e8ecaf..852f555 100644
--- a/src/pkg.c
+++ b/src/pkg.c
@@ -23,6 +23,7 @@
#include <unistd.h>
#include "common.h"
+#include "files.h"
#include "log.h"
#include "pkg.h"
#include "state.h"
@@ -30,7 +31,9 @@
static str get_destdir(str *cwd, str *arg) {
str result = {0};
- if (str_first(arg) == '.' && arg->len == 1) {
+ if (is_directory(arg->data)) {
+ result = str_format("%.*s", str_fmt(arg));
+ } else if (str_first(arg) == '.' && arg->len == 1) {
result = str_format("%.*s/%.*s",
str_fmt(&config.inst_dirs.src), str_fmt(cwd));
} else { str name = {0};
@@ -44,10 +47,11 @@ static str get_destdir(str *cwd, str *arg) {
return result;
}
-static void set_pkgsrc(package_t *pkg) {
+static void set_pkgsrc(package_t *pkg, str *cwd, bool is_installed_locally) {
pkg->root = str_format("%.*s/%.*s",
str_fmt(&config.inst_dirs.src), str_fmt(&pkg->name));
- if (pkg->is_local) pkg->src = pkg->root;
+ if (is_installed_locally) str_copy_into(&pkg->src, cwd);
+ else if (pkg->is_local) pkg->src = pkg->root;
else pkg->src = str_format("%.*s/%.*s/%.*s",
str_fmt(&config.inst_dirs.src), str_fmt(&pkg->name),
str_fmt(&pkg->version));
@@ -69,6 +73,7 @@ package_t pkg_create(str *arg) {
getcwd(cwd_cstr, MAX_PATH_LEN);
str cwd = mstr(cwd_cstr);
str destdir = get_destdir(&cwd, arg);
+ bool is_installed_locally = is_directory(destdir.data);
if (strncmp(arg->data, "http", 4) == 0
|| strncmp(arg->data, "ssh", 3) == 0) {
@@ -81,19 +86,19 @@ package_t pkg_create(str *arg) {
} else if (pkg_exists(arg)) {
str_copy_into(&pkg.name, arg);
pkg.url = pkg_get_url(&pkg);
-// } else if (is_installed_locally) {
-// str_copy_cstr_into(&pkg.url, "");
-// pkg.name = str_from_after_delim(&destdir, '/');
-// pkg.is_local = true;
+ } else if (is_installed_locally) {
+ str_copy_cstr_into(&pkg.url, "");
+ pkg.name = str_from_after_delim(&destdir, '/');
+ pkg.is_local = true;
} else {
log_error("'%.*s' is not a valid package", str_fmt(arg));
str_free(&cwd);
str_free(&destdir);
str_free(arg);
- abort();
+ exit(1);
}
- set_pkgsrc(&pkg);
+ set_pkgsrc(&pkg, &cwd, is_installed_locally);
str_free(&cwd);
str_free(&destdir);