diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lpm.c | 15 | ||||
-rw-r--r-- | src/lpm.lua | 20 |
2 files changed, 33 insertions, 2 deletions
@@ -788,6 +788,19 @@ static int lpm_get(lua_State* L) { return 2; } +static int lpm_chdir(lua_State* L) { + if (chdir(luaL_checkstring(L, 1))) + return luaL_error(L, "error chdiring: %s", strerror(errno)); + return 0; +} + +static int lpm_pwd(lua_State* L) { + char buffer[MAX_PATH]; + if (!getcwd(buffer, sizeof(buffer))) + return luaL_error(L, "error getcwd: %s", strerror(errno)); + lua_pushstring(L, buffer); + return 1; +} static const luaL_Reg system_lib[] = { { "ls", lpm_ls }, // Returns an array of files. @@ -803,6 +816,8 @@ static const luaL_Reg system_lib[] = { { "get", lpm_get }, // HTTP(s) GET request. { "extract", lpm_extract }, // Extracts .tar.gz, and .zip files. { "certs", lpm_certs }, // Sets the SSL certificate chain folder/file. + { "chdir", lpm_chdir }, // Changes directory. Only use for --post actions. + { "pwd", lpm_pwd }, // Gets existing directory. Only use for --post actions. { NULL, NULL } }; diff --git a/src/lpm.lua b/src/lpm.lua index a9db970..3d4e849 100644 --- a/src/lpm.lua +++ b/src/lpm.lua @@ -443,8 +443,15 @@ function common.reset(path, ref, type) if not pcall(system.reset, path, "refs/tags/" .. ref, type) then system.reset(path, "refs/remotes/origin/" .. ref, type) end end end +function common.chdir(dir, callback) + local wd = system.pwd() + system.chdir(dir) + local status, err = pcall(callback) + system.chdir(wd) + if not status then error(err) +end -local HOME, USERDIR, CACHEDIR, JSON, VERBOSE, MOD_VERSION, QUIET, FORCE, AUTO_PULL_REMOTES, ARCH, ASSUME_YES, NO_INSTALL_OPTIONAL, TMPDIR, DATADIR, BINARY, repositories, lite_xls, system_bottle +local HOME, USERDIR, CACHEDIR, JSON, VERBOSE, MOD_VERSION, QUIET, FORCE, AUTO_PULL_REMOTES, ARCH, ASSUME_YES, NO_INSTALL_OPTIONAL, TMPDIR, DATADIR, BINARY, POST, repositories, lite_xls, system_bottle local Plugin, Repository, LiteXL, Bottle = {}, {}, {}, {} @@ -691,6 +698,13 @@ function Plugin:install(bottle, installing) common.rmrf(temporary_install_path) error(err) else + if POST and self.post then + common.chdir(temporary_install_path, function() + if type(self.post) == "table" and not self.post[ARCH] then error("can't find post command for arch " .. ARCH) end + local code = os.system(type(self.post) == "table" and self.post[ARCH] or self.post) ~= 0 + if code ~= 0 then error("post step failed with error code " .. code) end + end) + end common.rmrf(install_path) common.mkdirp(common.dirname(install_path)) common.rename(temporary_install_path, install_path) @@ -1514,7 +1528,7 @@ Usage: lpm COMMAND [...ARGUMENTS] [--json] [--userdir=directory] [--cachedir=directory] [--quiet] [--version] [--help] [--remotes] [--ssl_certs=directory/file] [--force] [--arch=]] .. _G.ARCH .. [[] [--assume-yes] [--no-install-optional] [--verbose] [--mod-version=3] - [--datadir=directory] [--binary=path] + [--datadir=directory] [--binary=path] [--post] LPM is a package manager for `lite-xl`, written in C (and packed-in lua). @@ -1604,6 +1618,7 @@ Flags have the following effects: to all. --no-install-optional On install, anything marked as optional won't prompt. + --post Run post-install build steps. Must be explicitly enabled. ]] ) return 0 @@ -1613,6 +1628,7 @@ Flags have the following effects: JSON = ARGS["json"] or os.getenv("LPM_JSON") QUIET = ARGS["quiet"] or os.getenv("LPM_QUIET") FORCE = ARGS["force"] + POST = ARGS["post"] DATADIR = common.normalize_path(ARGS["datadir"]) BINARY = common.normalize_path(ARGS["binary"]) NO_INSTALL_OPTIONAL = ARGS["no-install-optional"] |