aboutsummaryrefslogtreecommitdiff
path: root/src/lpm.c
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 /src/lpm.c
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.
Diffstat (limited to 'src/lpm.c')
-rw-r--r--src/lpm.c23
1 files changed, 19 insertions, 4 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);