Skip to content

Commit

Permalink
Only recommend paths that exist and can be written into by the curren…
Browse files Browse the repository at this point in the history
…t user.
  • Loading branch information
icculus committed May 10, 2007
1 parent f6d1d35 commit 27043f7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
16 changes: 16 additions & 0 deletions lua_glue.c
Expand Up @@ -754,6 +754,20 @@ static int luahook_platform_exists(lua_State *L)
} // luahook_platform_exists


static int luahook_platform_writable(lua_State *L)
{
const char *fname = luaL_checkstring(L, 1);
return retvalBoolean(L, MojoPlatform_writable(fname));
} // luahook_platform_writable


static int luahook_platform_isdir(lua_State *L)
{
const char *dir = luaL_checkstring(L, 1);
return retvalBoolean(L, MojoPlatform_isdir(dir));
} // luahook_platform_writable


static int luahook_platform_symlink(lua_State *L)
{
const char *src = luaL_checkstring(L, 1);
Expand Down Expand Up @@ -1302,6 +1316,8 @@ boolean MojoLua_initLua(void)
lua_newtable(luaState);
set_cfunc(luaState, luahook_platform_unlink, "unlink");
set_cfunc(luaState, luahook_platform_exists, "exists");
set_cfunc(luaState, luahook_platform_writable, "writable");
set_cfunc(luaState, luahook_platform_isdir, "isdir");
set_cfunc(luaState, luahook_platform_symlink, "symlink");
set_cfunc(luaState, luahook_platform_mkdir, "mkdir");
lua_setfield(luaState, -2, "platform");
Expand Down
6 changes: 6 additions & 0 deletions platform.h
Expand Up @@ -50,6 +50,12 @@ boolean MojoPlatform_rename(const char *src, const char *dst);
// !!! FIXME: comment me.
boolean MojoPlatform_exists(const char *dir, const char *fname);

// !!! FIXME: comment me.
boolean MojoPlatform_writable(const char *fname);

// !!! FIXME: comment me.
boolean MojoPlatform_isdir(const char *dir);

// !!! FIXME: comment me.
boolean MojoPlatform_perms(const char *fname, uint16 *p);

Expand Down
19 changes: 19 additions & 0 deletions platform_unix.c
Expand Up @@ -503,6 +503,25 @@ boolean MojoPlatform_exists(const char *dir, const char *fname)
} // MojoPlatform_exists


boolean MojoPlatform_writable(const char *fname)
{
return (access(fname, W_OK) == 0);
} // MojoPlatform_writable


boolean MojoPlatform_isdir(const char *dir)
{
boolean retval = false;
struct stat statbuf;
if (stat(dir, &statbuf) != -1)
{
if (S_ISDIR(statbuf.st_mode))
retval = true;
} // if
return retval;
} // MojoPlatform_isdir


boolean MojoPlatform_perms(const char *fname, uint16 *p)
{
boolean retval = false;
Expand Down
7 changes: 4 additions & 3 deletions scripts/mojosetup_mainline.lua
Expand Up @@ -520,9 +520,10 @@ local function do_install(install)
if install.recommended_destinations ~= nil then
recommend = {}
for i,v in ipairs(install.recommended_destinations) do
-- !!! FIXME: check write access, not exists.
if MojoSetup.platform.exists(v) then
recommend[#recommend+1] = v .. "/" .. install.id
if MojoSetup.platform.isdir(v) then
if MojoSetup.platform.writable(v) then
recommend[#recommend+1] = v .. "/" .. install.id
end
end
end

Expand Down

0 comments on commit 27043f7

Please sign in to comment.