Skip to content

Commit

Permalink
lpm: support creating symlinks on Windows when Dev Mode is enabled (#151
Browse files Browse the repository at this point in the history
)
  • Loading branch information
takase1121 authored Dec 4, 2024
1 parent 4e09d07 commit 18a35f6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,12 @@ static int lpm_symlink(lua_State* L) {
return luaL_error(L, "can't create symlink %s: %s", luaL_checkstring(L, 2), strerror(errno));
return 0;
#else
return luaL_error(L, "can't create symbolic link %s: your operating system sucks", luaL_checkstring(L, 2));
DWORD flags = SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE | ((GetFileAttributesW(lua_toutf16(L, luaL_checkstring(L, 2))) & FILE_ATTRIBUTE_DIRECTORY) ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0);
if (!CreateSymbolicLinkW(lua_toutf16(L, luaL_checkstring(L, 2)), lua_toutf16(L, luaL_checkstring(L, 1)), flags)) {
DWORD err = GetLastError();
return luaL_win32_error(L, err, "can't create symbolic link %s%s", luaL_checkstring(L, 2), err == ERROR_PRIVILEGE_NOT_HELD ? " (did you enable Windows Developer Mode?)" : "");
}
return 0;
#endif
}

Expand Down

0 comments on commit 18a35f6

Please sign in to comment.