aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Harrison <adamdharrison@gmail.com>2023-07-03 17:53:23 -0400
committerAdam Harrison <adamdharrison@gmail.com>2023-07-03 17:53:23 -0400
commited800ce62f77a1c14a69173d09b9a75f8601b2dc (patch)
tree3d19f6b5f0d36bf7187afa71ff5cf7a92e9b8bec
parent7b0dbf800bdfe7fe499dd0be293e0929708e9447 (diff)
downloadlite-xl-plugin-manager-ed800ce62f77a1c14a69173d09b9a75f8601b2dc.tar.gz
lite-xl-plugin-manager-ed800ce62f77a1c14a69173d09b9a75f8601b2dc.zip
Fixed issue with non-existent symbolic links not getting removed, and also realpath returning the absolute path of a link target, rather than a link. Also, ensured that the lxl datadir is properly detected.
-rw-r--r--src/lpm.c23
-rw-r--r--src/lpm.lua2
2 files changed, 20 insertions, 5 deletions
diff --git a/src/lpm.c b/src/lpm.c
index e390512..473e3c0 100644
--- a/src/lpm.c
+++ b/src/lpm.c
@@ -7,6 +7,8 @@
#include <netdb.h>
#include <sys/socket.h>
#include <arpa/inet.h>
+ #include <libgen.h>
+
#define MAX_PATH PATH_MAX
#endif
@@ -232,16 +234,29 @@ static int lpm_mkdir(lua_State *L) {
static int lpm_stat(lua_State *L) {
const char *path = luaL_checkstring(L, 1);
#ifdef _WIN32
- wchar_t fullpath[MAX_PATH];
+ wchar_t full_path[MAX_PATH];
struct _stat s;
LPCWSTR wpath = lua_toutf16(L, path);
int err = _wstat(wpath, &s);
- const char *abs_path = !err && _wfullpath(fullpath, wpath, MAX_PATH) ? lua_toutf8(L, (LPCWSTR)fullpath) : NULL;
+ const char *abs_path = !err && _wfullpath(full_path, wpath, MAX_PATH) ? lua_toutf8(L, (LPCWSTR)fullpath) : NULL;
#else
- char fullpath[MAX_PATH];
+ char full_path[MAX_PATH];
struct stat s;
int err = lstat(path, &s);
- const char *abs_path = !err ? realpath(path, fullpath) : NULL;
+ const char *abs_path = NULL;
+ if (!err) {
+ if (S_ISLNK(s.st_mode)) {
+ char folder_path[MAX_PATH];
+ strcpy(folder_path, path);
+ abs_path = realpath(dirname(folder_path), full_path);
+ if (abs_path) {
+ strcat(full_path, "/");
+ strcpy(folder_path, path);
+ strcat(full_path, basename(folder_path));
+ }
+ } else
+ abs_path = realpath(path, full_path);
+ }
#endif
if (err || !abs_path) {
lua_pushnil(L);
diff --git a/src/lpm.lua b/src/lpm.lua
index 5a4acb7..df5aef7 100644
--- a/src/lpm.lua
+++ b/src/lpm.lua
@@ -2246,7 +2246,7 @@ not commonly used publically.
system_lite_xl = common.first(lite_xls, function(e) return e.version == "system" end)
local directory = common.dirname(lite_xl_binary)
- local lite_xl_datadirs = { DATADIR, directory .. PATHSEP .. "data", directory:find(PATHSEP .. "bin$") and common.dirname(directory .. PATHSEP .. "share" .. PATHSEP .. "lite-xl"), directory .. PATHSEP .. "data" }
+ local lite_xl_datadirs = { DATADIR or "", directory .. PATHSEP .. "data", directory:find(PATHSEP .. "bin$") and common.dirname(directory) .. PATHSEP .. "share" .. PATHSEP .. "lite-xl" or "", directory .. PATHSEP .. "data" }
local lite_xl_datadir = common.first(lite_xl_datadirs, function(p) return p and system.stat(p) end)
if not BINARY and not DATADIR and system_lite_xl then error("can't find existing system lite (does " .. system_lite_xl:get_binary_path() .. " exist? was it moved?); run `lpm purge`, or specify --binary and --datadir.") end