Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/host/os_islink.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ int os_islink(lua_State* L)
#else
{
struct stat buf;
if (lstat(path, &buf) == 0) {
if (lstat(path, &buf) == 0)
{
lua_pushboolean(L, S_ISLNK(buf.st_mode));
return 1;
}
Expand Down
28 changes: 24 additions & 4 deletions src/host/os_linkdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ int do_linkdir(lua_State* L, const char* src, const char* dst)
GetCurrentDirectoryW(MAX_PATH, cwd);

// Convert the source path to a relative path
wchar_t relSrcPath[MAX_PATH];
swprintf(relSrcPath, MAX_PATH, L"%c:%s", cwd[0], wSrcPath);
wchar_t relSrcPath[MAX_PATH + 2];
swprintf(relSrcPath, MAX_PATH + 2, L"%c:%s", cwd[0], wSrcPath);
relSrcPath[MAX_PATH + 1] = L'\0';

BOOLEAN res = CreateSymbolicLinkW(wDstPath, relSrcPath, SYMBOLIC_LINK_FLAG_DIRECTORY | SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE);
return res != 0;
Expand All @@ -46,8 +47,27 @@ int do_linkdir(lua_State* L, const char* src, const char* dst)
return res != 0;
}
#else
int res = symlink(src, dst);
return res == 0;
(void)L;
if (!do_isabsolute(src))
{
char cwd[PATH_MAX];
if (!do_getcwd(cwd, PATH_MAX))
{
return FALSE;
}

char relSrcPath[2 * PATH_MAX + 1];
snprintf(relSrcPath, 2 * PATH_MAX + 1, "%s/%s", cwd, src);
relSrcPath[2 * PATH_MAX] = '\0';

int res = symlink(relSrcPath, dst);
return res == 0;
}
else
{
int res = symlink(src, dst);
return res == 0;
}
#endif
}

Expand Down
28 changes: 24 additions & 4 deletions src/host/os_linkfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ int do_linkfile(lua_State* L, const char* src, const char* dst)
GetCurrentDirectoryW(MAX_PATH, cwd);

// Convert the source path to a relative path
wchar_t relSrcPath[MAX_PATH];
swprintf(relSrcPath, MAX_PATH, L"%c:%s", cwd[0], wSrcPath);
wchar_t relSrcPath[MAX_PATH + 2];
swprintf(relSrcPath, MAX_PATH + 2, L"%c:%s", cwd[0], wSrcPath);
relSrcPath[MAX_PATH + 1] = L'\0';

BOOLEAN res = CreateSymbolicLinkW(wDstPath, relSrcPath, SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE);
return res != 0;
Expand All @@ -45,8 +46,27 @@ int do_linkfile(lua_State* L, const char* src, const char* dst)
return res != 0;
}
#else
int res = symlink(src, dst);
return res == 0;
(void)L;
if (!do_isabsolute(src))
{
char cwd[PATH_MAX];
if (!do_getcwd(cwd, PATH_MAX))
{
return FALSE;
}

char relSrcPath[2 * PATH_MAX + 1];
snprintf(relSrcPath, 2 * PATH_MAX + 1, "%s/%s", cwd, src);
relSrcPath[2 * PATH_MAX] = '\0';

int res = symlink(relSrcPath, dst);
return res == 0;
}
else
{
int res = symlink(src, dst);
return res == 0;
}
#endif
}

Expand Down
11 changes: 10 additions & 1 deletion src/host/os_rmdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* \author Copyright (c) 2002-2013 Jess Perkins and the Premake project
*/

#include <sys/stat.h>
#include <stdlib.h>
#include "premake.h"

Expand All @@ -23,7 +24,15 @@ int os_rmdir(lua_State* L)

z = RemoveDirectoryW(wide_path);
#else
z = (0 == rmdir(path));
struct stat buf;
if (lstat(path, &buf) == 0 && S_ISLNK(buf.st_mode))
{
z = (0 == unlink(path));
}
else
{
z = (0 == rmdir(path));
}
#endif

if (!z)
Expand Down
4 changes: 2 additions & 2 deletions src/host/premake.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ static const luaL_Reg os_functions[] = {
{ "mkdir", os_mkdir },
#if PLATFORM_WINDOWS
// utf8 functions for Windows (assuming posix already handle utf8)
{"remove", os_remove },
{"rename", os_rename },
{ "remove", os_remove },
{ "rename", os_rename },
#endif
{ "pathsearch", os_pathsearch },
{ "realpath", os_realpath },
Expand Down
7 changes: 4 additions & 3 deletions tests/base/test_os.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,18 @@
function suite.linkdir()
test.istrue(os.linkdir("folder/subfolder", "folder/subfolder2"))
test.istrue(os.islink("folder/subfolder2"))
os.rmdir("folder/subfolder2")
test.istrue(os.rmdir("folder/subfolder2"))
test.isfalse(os.islink("folder/subfolder2"))
end

function suite.linkfile()
test.istrue(os.linkfile("folder/ok.lua", "folder/ok2.lua"))
test.istrue(os.islink("folder/ok2.lua"))
os.remove("folder/ok2.lua")
test.istrue(os.remove("folder/ok2.lua"))
test.isfalse(os.islink("folder/ok2.lua"))
end



--
-- os.matchdirs() tests
--
Expand Down
Loading