aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--src/lfs.c39
-rw-r--r--tests/test.lua7
3 files changed, 25 insertions, 24 deletions
diff --git a/Makefile b/Makefile
index 6b54f2c..b834a4d 100644
--- a/Makefile
+++ b/Makefile
@@ -14,6 +14,9 @@ lib: src/lfs.so
14src/lfs.so: $(OBJS) 14src/lfs.so: $(OBJS)
15 MACOSX_DEPLOYMENT_TARGET="10.3"; export MACOSX_DEPLOYMENT_TARGET; $(CC) $(CFLAGS) $(LIB_OPTION) -o src/lfs.so $(OBJS) 15 MACOSX_DEPLOYMENT_TARGET="10.3"; export MACOSX_DEPLOYMENT_TARGET; $(CC) $(CFLAGS) $(LIB_OPTION) -o src/lfs.so $(OBJS)
16 16
17test: lib
18 LUA_CPATH=./src/?.so lua tests/test.lua
19
17install: 20install:
18 mkdir -p $(LUA_LIBDIR) 21 mkdir -p $(LUA_LIBDIR)
19 cp src/lfs.so $(LUA_LIBDIR) 22 cp src/lfs.so $(LUA_LIBDIR)
diff --git a/src/lfs.c b/src/lfs.c
index ccbba5e..b2322c9 100644
--- a/src/lfs.c
+++ b/src/lfs.c
@@ -716,12 +716,6 @@ static void push_st_blksize (lua_State *L, STAT_STRUCT *info) {
716 lua_pushnumber (L, (lua_Number)info->st_blksize); 716 lua_pushnumber (L, (lua_Number)info->st_blksize);
717} 717}
718#endif 718#endif
719static void push_invalid (lua_State *L, STAT_STRUCT *info) {
720 luaL_error(L, "invalid attribute name");
721#ifndef _WIN32
722 info->st_blksize = 0; /* never reached */
723#endif
724}
725 719
726 /* 720 /*
727** Convert the inode protection mode to a permission list. 721** Convert the inode protection mode to a permission list.
@@ -787,14 +781,13 @@ struct _stat_members members[] = {
787 { "blocks", push_st_blocks }, 781 { "blocks", push_st_blocks },
788 { "blksize", push_st_blksize }, 782 { "blksize", push_st_blksize },
789#endif 783#endif
790 { NULL, push_invalid } 784 { NULL, NULL }
791}; 785};
792 786
793/* 787/*
794** Get file or symbolic link information 788** Get file or symbolic link information
795*/ 789*/
796static int _file_info_ (lua_State *L, int (*st)(const char*, STAT_STRUCT*)) { 790static int _file_info_ (lua_State *L, int (*st)(const char*, STAT_STRUCT*)) {
797 int i;
798 STAT_STRUCT info; 791 STAT_STRUCT info;
799 const char *file = luaL_checkstring (L, 1); 792 const char *file = luaL_checkstring (L, 1);
800 793
@@ -804,25 +797,23 @@ static int _file_info_ (lua_State *L, int (*st)(const char*, STAT_STRUCT*)) {
804 return 2; 797 return 2;
805 } 798 }
806 if (lua_isstring (L, 2)) { 799 if (lua_isstring (L, 2)) {
807 int v;
808 const char *member = lua_tostring (L, 2); 800 const char *member = lua_tostring (L, 2);
809 if (strcmp (member, "mode") == 0) v = 0; 801 for (int i = 0; members[i].name; i++) {
810#ifndef _WIN32 802 if (strcmp(members[i].name, member) == 0) {
811 else if (strcmp (member, "blocks") == 0) v = 11; 803 /* push member value and return */
812 else if (strcmp (member, "blksize") == 0) v = 12; 804 members[i].push (L, &info);
813#endif 805 return 1;
814 else /* look for member */ 806 }
815 for (v = 1; members[v].name; v++) 807 }
816 if (*members[v].name == *member) 808 /* member not found */
817 break; 809 return luaL_error(L, "invalid attribute name");
818 /* push member value and return */ 810 }
819 members[v].push (L, &info); 811 /* creates a table if none is given */
820 return 1; 812 if (!lua_istable (L, 2)) {
821 } else if (!lua_istable (L, 2))
822 /* creates a table if none is given */
823 lua_newtable (L); 813 lua_newtable (L);
814 }
824 /* stores all members in table on top of the stack */ 815 /* stores all members in table on top of the stack */
825 for (i = 0; members[i].name; i++) { 816 for (int i = 0; members[i].name; i++) {
826 lua_pushstring (L, members[i].name); 817 lua_pushstring (L, members[i].name);
827 members[i].push (L, &info); 818 members[i].push (L, &info);
828 lua_rawset (L, -3); 819 lua_rawset (L, -3);
diff --git a/tests/test.lua b/tests/test.lua
index 4990aec..abfbd4d 100644
--- a/tests/test.lua
+++ b/tests/test.lua
@@ -120,6 +120,13 @@ assert (new_att.modification == attrib.modification)
120io.write(".") 120io.write(".")
121io.flush() 121io.flush()
122 122
123-- Check consistency of lfs.attributes values
124local attr = lfs.attributes (tmpfile)
125for key, value in pairs(attr) do
126 assert (value == lfs.attributes (tmpfile, key),
127 "lfs.attributes values not consistent")
128end
129
123-- Remove new file and directory 130-- Remove new file and directory
124assert (os.remove (tmpfile), "could not remove new file") 131assert (os.remove (tmpfile), "could not remove new file")
125assert (lfs.rmdir (tmpdir), "could not remove new directory") 132assert (lfs.rmdir (tmpdir), "could not remove new directory")