aboutsummaryrefslogtreecommitdiff
path: root/lpm.c
diff options
context:
space:
mode:
authorAdam <adamdharrison@gmail.com>2022-09-27 20:38:29 -0400
committerAdam <adamdharrison@gmail.com>2022-09-27 20:38:29 -0400
commitd6a4e9f4904ceff72c04d147d9abe78586e4d139 (patch)
tree515bcc921310dd7c6c3a732979e09747eabce41b /lpm.c
parent8cf423ce22e03e3d5bfc87ece071bdc27a36ad8b (diff)
downloadlite-xl-plugin-manager-d6a4e9f4904ceff72c04d147d9abe78586e4d139.tar.gz
lite-xl-plugin-manager-d6a4e9f4904ceff72c04d147d9abe78586e4d139.zip
Bottles now working.
Diffstat (limited to 'lpm.c')
-rw-r--r--lpm.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/lpm.c b/lpm.c
index b58edf3..4d9db68 100644
--- a/lpm.c
+++ b/lpm.c
@@ -269,7 +269,7 @@ static int lpm_stat(lua_State *L) {
free(wpath);
#else
struct stat s;
- int err = stat(path, &s);
+ int err = lstat(path, &s);
#endif
if (err < 0) {
lua_pushnil(L);
@@ -278,6 +278,21 @@ static int lpm_stat(lua_State *L) {
}
lua_newtable(L);
+#if __linux__
+ if (S_ISLNK(s.st_mode)) {
+ char buffer[PATH_MAX];
+ ssize_t len = readlink(path, buffer, sizeof(buffer));
+ if (len < 0)
+ return 0;
+ lua_pushlstring(L, buffer, len);
+ } else
+ lua_pushnil(L);
+ lua_setfield(L, -2, "symlink");
+ if (S_ISLNK(s.st_mode))
+ err = stat(path, &s);
+ if (err)
+ return 1;
+#endif
lua_pushinteger(L, s.st_mtime);
lua_setfield(L, -2, "modified");
@@ -292,15 +307,6 @@ static int lpm_stat(lua_State *L) {
lua_pushnil(L);
}
lua_setfield(L, -2, "type");
-
-#if __linux__
- if (S_ISDIR(s.st_mode)) {
- if (lstat(path, &s) == 0) {
- lua_pushboolean(L, S_ISLNK(s.st_mode));
- lua_setfield(L, -2, "symlink");
- }
- }
-#endif
return 1;
}
/** END STOLEN LITE CODE **/