diff options
-rw-r--r-- | src/lpm.c | 23 | ||||
-rw-r--r-- | src/lpm.lua | 2 |
2 files changed, 20 insertions, 5 deletions
@@ -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 |