mirror of
https://github.com/lunarmodules/luafilesystem.git
synced 2026-07-22 02:53:06 +00:00
Merge pull request #44 from stefan991/fix-attribute-lookup
Fix attributes `blksize` and `blocks`
This commit is contained in:
3
Makefile
3
Makefile
@@ -14,6 +14,9 @@ lib: src/lfs.so
|
||||
src/lfs.so: $(OBJS)
|
||||
MACOSX_DEPLOYMENT_TARGET="10.3"; export MACOSX_DEPLOYMENT_TARGET; $(CC) $(CFLAGS) $(LIB_OPTION) -o src/lfs.so $(OBJS)
|
||||
|
||||
test: lib
|
||||
LUA_CPATH=./src/?.so lua tests/test.lua
|
||||
|
||||
install:
|
||||
mkdir -p $(LUA_LIBDIR)
|
||||
cp src/lfs.so $(LUA_LIBDIR)
|
||||
|
||||
39
src/lfs.c
39
src/lfs.c
@@ -716,12 +716,6 @@ static void push_st_blksize (lua_State *L, STAT_STRUCT *info) {
|
||||
lua_pushnumber (L, (lua_Number)info->st_blksize);
|
||||
}
|
||||
#endif
|
||||
static void push_invalid (lua_State *L, STAT_STRUCT *info) {
|
||||
luaL_error(L, "invalid attribute name");
|
||||
#ifndef _WIN32
|
||||
info->st_blksize = 0; /* never reached */
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert the inode protection mode to a permission list.
|
||||
@@ -787,14 +781,13 @@ struct _stat_members members[] = {
|
||||
{ "blocks", push_st_blocks },
|
||||
{ "blksize", push_st_blksize },
|
||||
#endif
|
||||
{ NULL, push_invalid }
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
/*
|
||||
** Get file or symbolic link information
|
||||
*/
|
||||
static int _file_info_ (lua_State *L, int (*st)(const char*, STAT_STRUCT*)) {
|
||||
int i;
|
||||
STAT_STRUCT info;
|
||||
const char *file = luaL_checkstring (L, 1);
|
||||
|
||||
@@ -804,25 +797,23 @@ static int _file_info_ (lua_State *L, int (*st)(const char*, STAT_STRUCT*)) {
|
||||
return 2;
|
||||
}
|
||||
if (lua_isstring (L, 2)) {
|
||||
int v;
|
||||
const char *member = lua_tostring (L, 2);
|
||||
if (strcmp (member, "mode") == 0) v = 0;
|
||||
#ifndef _WIN32
|
||||
else if (strcmp (member, "blocks") == 0) v = 11;
|
||||
else if (strcmp (member, "blksize") == 0) v = 12;
|
||||
#endif
|
||||
else /* look for member */
|
||||
for (v = 1; members[v].name; v++)
|
||||
if (*members[v].name == *member)
|
||||
break;
|
||||
/* push member value and return */
|
||||
members[v].push (L, &info);
|
||||
return 1;
|
||||
} else if (!lua_istable (L, 2))
|
||||
/* creates a table if none is given */
|
||||
for (int i = 0; members[i].name; i++) {
|
||||
if (strcmp(members[i].name, member) == 0) {
|
||||
/* push member value and return */
|
||||
members[i].push (L, &info);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/* member not found */
|
||||
return luaL_error(L, "invalid attribute name");
|
||||
}
|
||||
/* creates a table if none is given */
|
||||
if (!lua_istable (L, 2)) {
|
||||
lua_newtable (L);
|
||||
}
|
||||
/* stores all members in table on top of the stack */
|
||||
for (i = 0; members[i].name; i++) {
|
||||
for (int i = 0; members[i].name; i++) {
|
||||
lua_pushstring (L, members[i].name);
|
||||
members[i].push (L, &info);
|
||||
lua_rawset (L, -3);
|
||||
|
||||
@@ -120,6 +120,13 @@ assert (new_att.modification == attrib.modification)
|
||||
io.write(".")
|
||||
io.flush()
|
||||
|
||||
-- Check consistency of lfs.attributes values
|
||||
local attr = lfs.attributes (tmpfile)
|
||||
for key, value in pairs(attr) do
|
||||
assert (value == lfs.attributes (tmpfile, key),
|
||||
"lfs.attributes values not consistent")
|
||||
end
|
||||
|
||||
-- Remove new file and directory
|
||||
assert (os.remove (tmpfile), "could not remove new file")
|
||||
assert (lfs.rmdir (tmpdir), "could not remove new directory")
|
||||
|
||||
Reference in New Issue
Block a user