aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorforever2k38 <forever2k38@noreply.codeberg.org>2026-09-02 15:30:34 +0200
committerforever2k38 <forever2k38@noreply.codeberg.org>2026-09-02 15:30:34 +0200
commited979ea2b7cc0caf3abb47dce94e02ef16c73e65 (patch)
tree86ee7fda3e9fe8c708391c25e95e2b11b7aa53de
parenta2cb6e5b16bd8f5eddd778f813f3a9068be44e46 (diff)
lua work
-rw-r--r--.gitignore1
-rw-r--r--Makefile6
-rw-r--r--README.md2
-rw-r--r--src/args.c15
-rw-r--r--src/args.h1
-rw-r--r--src/build.c5
-rw-r--r--src/build.h3
-rw-r--r--src/main.c17
-rw-r--r--src/package.c7
-rw-r--r--src/package.h13
-rw-r--r--src/pow_lua.c117
-rw-r--r--src/repo.c36
-rw-r--r--src/repo.h6
-rw-r--r--testing/samurai/1.3.lua8
14 files changed, 210 insertions, 27 deletions
diff --git a/.gitignore b/.gitignore
index 7080b0e..c87c6d0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
pow
+compile_commands.json
out
diff --git a/Makefile b/Makefile
index 4d60105..158a7b9 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-CC=cc
+CC?=cc
BIN_EXT =
MKDIR = mkdir -p $(OUT_DIR) $(dir $@)
@@ -6,8 +6,8 @@ RM = rm -rf
CFLAGS=-Wall -Wpedantic
-LIBFLAGS=$(shell pkg-config --cflags --libs lua55)
-DEBUG_CFLAGS=-g
+LIBFLAGS=$(shell pkg-config --cflags --libs lua55) $(shell pkg-config --cflags --libs libarchive)
+DEBUG_CFLAGS=-g -fsanitize=address
SRC_DIR=src
OUT_DIR=out
diff --git a/README.md b/README.md
index 87bc873..03d58a4 100644
--- a/README.md
+++ b/README.md
@@ -4,3 +4,5 @@ pow! is the package manager used by einfach linux.
currently under HEAVY development. expect breaking changes.
+code quality sucks, needs more error handling and has memory leaks.
+
diff --git a/src/args.c b/src/args.c
index 44117b9..e8c0fff 100644
--- a/src/args.c
+++ b/src/args.c
@@ -82,6 +82,8 @@ int pow_args_parse(int argc, char **argv, pow_args *args) {
flags |= POW_FLAG_SYNC;
next_flag_package = true;
+
+ break;
};
case 'Q': {
if (flags & POW_FLAG_QUERY) {
@@ -91,6 +93,19 @@ int pow_args_parse(int argc, char **argv, pow_args *args) {
flags |= POW_FLAG_QUERY;
next_flag_package = true;
+
+ break;
+ }
+ case 'I': {
+ if (flags & POW_FLAG_INSTALL) {
+ printf("flag double defined, skipping\n");
+ }
+
+ flags |= POW_FLAG_INSTALL;
+
+ next_flag_package = true;
+
+ break;
}
}
}
diff --git a/src/args.h b/src/args.h
index 578eeb7..f9c7aae 100644
--- a/src/args.h
+++ b/src/args.h
@@ -5,6 +5,7 @@
#define POW_FLAG_HELP 0x01
#define POW_FLAG_SYNC 0x02
#define POW_FLAG_QUERY 0x04
+#define POW_FLAG_INSTALL 0x08
typedef struct {
int flags;
diff --git a/src/build.c b/src/build.c
new file mode 100644
index 0000000..d680cf7
--- /dev/null
+++ b/src/build.c
@@ -0,0 +1,5 @@
+#include "build.h"
+
+#include "package.h"
+
+int pow_package_build(pow_package *pkg) { return 0; }
diff --git a/src/build.h b/src/build.h
new file mode 100644
index 0000000..eea6c75
--- /dev/null
+++ b/src/build.h
@@ -0,0 +1,3 @@
+#include "package.h"
+
+int pow_package_build(pow_package *pkg);
diff --git a/src/main.c b/src/main.c
index 73617ef..9c38b18 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,8 +1,10 @@
#include "args.h"
+#include "build.h"
#include "config.h"
#include "repo.h"
#include "stdio.h"
+#include "stdlib.h"
int main(int argc, char *argv[]) {
pow_args args = {0};
@@ -20,7 +22,20 @@ int main(int argc, char *argv[]) {
pow_open_config(&config, args.cfg_path);
if (args.flags & POW_FLAG_QUERY) {
- repo_check_package(config.repos, config.repos_count, "samurai");
+ pow_repo_check_package(config.repos, config.repos_count, args.package);
+ }
+
+ if (args.flags & POW_FLAG_SYNC) {
+ pow_package *pkg = malloc(sizeof(pow_package));
+
+ if (!pow_repo_get_package(config.repos, config.repos_count, pkg,
+ args.package)) {
+ printf("error getting package\n");
+ }
+
+ pow_package_build(pkg);
+
+ pow_package_close(pkg);
}
if (args.flags == 0) {
diff --git a/src/package.c b/src/package.c
index 2e571e9..832e7da 100644
--- a/src/package.c
+++ b/src/package.c
@@ -40,10 +40,12 @@ int extract_package_info(lua_State *L, pow_package *pkg) {
printf("strdup failed trying to get package name\n");
}
+ pkg->pkg_ref = luaL_ref(L, LUA_REGISTRYINDEX);
+
return 0;
}
-int package_open(pow_package *pkg, const char *path) {
+int pow_package_open(pow_package *pkg, const char *path) {
FILE *fp;
int c;
int err;
@@ -111,11 +113,12 @@ int package_open(pow_package *pkg, const char *path) {
}
extract_package_info(L, pkg);
+ pkg->path = path;
return 0;
}
-int package_close(pow_package *pkg) {
+int pow_package_close(pow_package *pkg) {
free(pkg->name);
free(pkg->version);
diff --git a/src/package.h b/src/package.h
index a1e4595..12804bc 100644
--- a/src/package.h
+++ b/src/package.h
@@ -1,3 +1,6 @@
+#ifndef POW_PACKAGE_H
+#define POW_PACKAGE_H
+
#include "lua.h"
#include "stddef.h"
@@ -6,10 +9,16 @@ typedef struct {
const char *version;
const char *description;
+ const char *path;
+
size_t *arch;
lua_State *L;
+
+ int pkg_ref;
} pow_package;
-int package_open(pow_package *pkg, const char *path);
-int package_close(pow_package *pkg);
+int pow_package_open(pow_package *pkg, const char *path);
+int pow_package_close(pow_package *pkg);
+
+#endif
diff --git a/src/pow_lua.c b/src/pow_lua.c
index 0d0214d..70b32ad 100644
--- a/src/pow_lua.c
+++ b/src/pow_lua.c
@@ -1,11 +1,122 @@
#include "pow_lua.h"
+#include "archive.h"
+#include "archive_entry.h"
#include "lauxlib.h"
-#include "lualib.h"
+#include "stdlib.h"
+#include "string.h"
-int pow_lua_hello(lua_State *L) { printf("hi\n"); }
+int pow_lua_extract(lua_State *L) {
+ int r;
+ ssize_t size;
-luaL_Reg libpow[] = {{"hello", pow_lua_hello}};
+ struct archive *a;
+ struct archive_entry *entry;
+
+ if (!lua_isstring(L, 1)) {
+ lua_pushnil(L);
+ lua_pushstring(L, "arg 1 must be string (src)");
+
+ return 2;
+ }
+
+ if (!lua_isstring(L, 2)) {
+ lua_pushnil(L);
+ lua_pushstring(L, "arg 2 must be string (dest)");
+
+ return 2;
+ }
+
+ const char *filename = lua_tostring(L, 1);
+ const char *dest = lua_tostring(L, 2);
+
+ a = archive_read_new();
+
+ archive_read_support_filter_all(a);
+ archive_read_support_format_all(a);
+
+ if ((r = archive_read_open_filename(a, filename, 10240))) {
+ return 0;
+ }
+
+ for (;;) {
+ r = archive_read_next_header(a, &entry);
+
+ if (r == ARCHIVE_EOF)
+ break;
+ if (r < ARCHIVE_OK)
+ printf("warn while unpacking: %s\n", archive_error_string(a));
+ if (r < ARCHIVE_WARN) {
+ printf("error while unpacking: %s\n", archive_error_string(a));
+
+ lua_pop(L, 1);
+
+ char *error_msg = malloc(256);
+
+ lua_pushnil(L);
+
+ if (!error_msg) {
+ lua_pushstring(L, "error while unpacking and failed to malloc to push "
+ "real error message");
+ printf("error while unpacking and failed to push real error message\n");
+
+ return 2;
+ }
+
+ snprintf(error_msg, 256, "error while unpacking: %s",
+ archive_error_string(a));
+
+ lua_pushstring(L, error_msg);
+
+ free(error_msg);
+
+ return 2;
+ }
+
+ const char *cur = archive_entry_pathname(entry);
+
+ if (cur) {
+ size_t need = strlen(dest) + strlen(cur) + 2;
+
+ char *full = malloc(need);
+
+ if (!full) {
+ lua_pushnil(L);
+ lua_pushstring(L, "failed to malloc entry path\n");
+
+ archive_read_close(a);
+ archive_read_free(a);
+
+ return 2;
+ }
+
+ snprintf(full, need, "%s/%s", dest, cur);
+ archive_entry_set_pathname(entry, full);
+ }
+
+ r = archive_read_extract(a, entry, 0);
+
+ if (r < ARCHIVE_WARN) {
+ lua_pushnil(L);
+ lua_pushfstring(
+ L, "failed to extract '%s': %s", archive_entry_pathname(entry),
+ archive_error_string(a) ? archive_error_string(a) : "unknown");
+ archive_read_close(a);
+ archive_read_free(a);
+
+ return 2;
+ }
+ }
+
+ archive_read_close(a);
+ archive_read_free(a);
+
+ lua_pushboolean(L, 1);
+
+ return 1;
+}
+
+luaL_Reg libpow[] = {{"extract", pow_lua_extract}, {NULL, NULL}};
int pow_lua_load(lua_State *L) {
luaL_newlib(L, libpow);
diff --git a/src/repo.c b/src/repo.c
index 49d815d..71a3172 100644
--- a/src/repo.c
+++ b/src/repo.c
@@ -7,7 +7,8 @@
#include "stdio.h"
#include <lua.h>
-int repo_check_package(pow_repo **repos, size_t repo_count, const char *query) {
+int pow_repo_get_package(pow_repo **repos, size_t repo_count, pow_package *pkg,
+ const char *query) {
if (!repos) {
printf("no repos defined in your config, please define them\n");
@@ -21,7 +22,7 @@ int repo_check_package(pow_repo **repos, size_t repo_count, const char *query) {
char *package_path = malloc(PATH_MAX);
if (!package_path) {
- printf("failed to allocate package_path, sizeof %zu\n", PATH_MAX);
+ printf("failed to allocate package_path, sizeof %d\n", PATH_MAX);
return 1;
}
@@ -49,18 +50,35 @@ int repo_check_package(pow_repo **repos, size_t repo_count, const char *query) {
printf("found package %s in repo %s\n", query, repos[i]->path);
- pow_package *pkg = malloc(sizeof(pow_package));
+ pow_package_open(pkg, "./testing/samurai/1.3.lua");
- package_open(pkg, "./testing/samurai/1.3.lua");
+ closedir(dp);
+ }
- printf("Name: %s\n"
- "Version: %s\n",
- pkg->name, pkg->version);
+ return 0;
+}
- package_close(pkg);
+int pow_repo_check_package(pow_repo **repos, size_t repo_count,
+ const char *query) {
+ int err;
- closedir(dp);
+ pow_package *pkg = malloc(sizeof(pow_package));
+
+ if (!pkg) {
+ printf("failed to malloc pow_package\n");
+
+ return 1;
+ }
+
+ err = pow_repo_get_package(repos, repo_count, pkg, query);
+
+ if (err) {
+ return 1;
}
+ printf("Name: %s\n"
+ "Version: %s\n",
+ pkg->name, pkg->version);
+
return 0;
}
diff --git a/src/repo.h b/src/repo.h
index 958210d..f828def 100644
--- a/src/repo.h
+++ b/src/repo.h
@@ -1,6 +1,7 @@
#ifndef _POW_REPO_H
#define _POW_REPO_H
+#include "package.h"
#include "stddef.h"
#define POW_X86_64 1
@@ -10,6 +11,9 @@ typedef struct {
const char *path;
} pow_repo;
-int repo_check_package(pow_repo **repos, size_t repo_count, const char *query);
+int pow_repo_check_package(pow_repo **repos, size_t repo_count,
+ const char *query);
+int pow_repo_get_package(pow_repo **repos, size_t repo_count, pow_package *pkg,
+ const char *query);
#endif
diff --git a/testing/samurai/1.3.lua b/testing/samurai/1.3.lua
index c836268..1da722f 100644
--- a/testing/samurai/1.3.lua
+++ b/testing/samurai/1.3.lua
@@ -26,13 +26,9 @@ package.sources = {
package.build = function()
pow.extract("source.tar.gz", "source")
- pow.cd("source")
+ lfs.chdir("source")
- local cc = pow.exts.einfach.CC
-
- pow.setenv("CC", cc)
-
- pow.exec("make")
+ os.execute("make")
end
return package