Merge pull request #44 from stefan991/fix-attribute-lookup

Fix attributes `blksize` and `blocks`
This commit is contained in:
Hisham Muhammad
2014-08-09 14:54:41 -03:00
3 changed files with 25 additions and 24 deletions

View File

@@ -14,6 +14,9 @@ lib: src/lfs.so
src/lfs.so: $(OBJS) src/lfs.so: $(OBJS)
MACOSX_DEPLOYMENT_TARGET="10.3"; export MACOSX_DEPLOYMENT_TARGET; $(CC) $(CFLAGS) $(LIB_OPTION) -o 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: install:
mkdir -p $(LUA_LIBDIR) mkdir -p $(LUA_LIBDIR)
cp src/lfs.so $(LUA_LIBDIR) cp src/lfs.so $(LUA_LIBDIR)

View File

@@ -716,12 +716,6 @@ static void push_st_blksize (lua_State *L, STAT_STRUCT *info) {
lua_pushnumber (L, (lua_Number)info->st_blksize); lua_pushnumber (L, (lua_Number)info->st_blksize);
} }
#endif #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. ** Convert the inode protection mode to a permission list.
@@ -787,14 +781,13 @@ struct _stat_members members[] = {
{ "blocks", push_st_blocks }, { "blocks", push_st_blocks },
{ "blksize", push_st_blksize }, { "blksize", push_st_blksize },
#endif #endif
{ NULL, push_invalid } { NULL, NULL }
}; };
/* /*
** Get file or symbolic link information ** Get file or symbolic link information
*/ */
static int _file_info_ (lua_State *L, int (*st)(const char*, STAT_STRUCT*)) { static int _file_info_ (lua_State *L, int (*st)(const char*, STAT_STRUCT*)) {
int i;
STAT_STRUCT info; STAT_STRUCT info;
const char *file = luaL_checkstring (L, 1); 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; return 2;
} }
if (lua_isstring (L, 2)) { if (lua_isstring (L, 2)) {
int v;
const char *member = lua_tostring (L, 2); const char *member = lua_tostring (L, 2);
if (strcmp (member, "mode") == 0) v = 0; for (int i = 0; members[i].name; i++) {
#ifndef _WIN32 if (strcmp(members[i].name, member) == 0) {
else if (strcmp (member, "blocks") == 0) v = 11; /* push member value and return */
else if (strcmp (member, "blksize") == 0) v = 12; members[i].push (L, &info);
#endif return 1;
else /* look for member */ }
for (v = 1; members[v].name; v++) }
if (*members[v].name == *member) /* member not found */
break; return luaL_error(L, "invalid attribute name");
/* push member value and return */ }
members[v].push (L, &info); /* creates a table if none is given */
return 1; if (!lua_istable (L, 2)) {
} else if (!lua_istable (L, 2))
/* creates a table if none is given */
lua_newtable (L); lua_newtable (L);
}
/* stores all members in table on top of the stack */ /* 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); lua_pushstring (L, members[i].name);
members[i].push (L, &info); members[i].push (L, &info);
lua_rawset (L, -3); lua_rawset (L, -3);

View File

@@ -120,6 +120,13 @@ assert (new_att.modification == attrib.modification)
io.write(".") io.write(".")
io.flush() 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 -- Remove new file and directory
assert (os.remove (tmpfile), "could not remove new file") assert (os.remove (tmpfile), "could not remove new file")
assert (lfs.rmdir (tmpdir), "could not remove new directory") assert (lfs.rmdir (tmpdir), "could not remove new directory")