diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2014-08-09 14:54:41 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2014-08-09 14:54:41 -0300 |
| commit | 601b4e54981d685d0a3c6049622453e897e55c01 (patch) | |
| tree | f8db6b102a3ac4226fbfbb52310e1896dbae2ad2 | |
| parent | 95573506c5b92d2fdc32b162a3ad86d2da8d4f15 (diff) | |
| parent | 4437e194558279b31878965d1c4b2188b1a8cf39 (diff) | |
| download | luafilesystem-601b4e54981d685d0a3c6049622453e897e55c01.tar.gz luafilesystem-601b4e54981d685d0a3c6049622453e897e55c01.tar.bz2 luafilesystem-601b4e54981d685d0a3c6049622453e897e55c01.zip | |
Merge pull request #44 from stefan991/fix-attribute-lookup
Fix attributes `blksize` and `blocks`
| -rw-r--r-- | Makefile | 3 | ||||
| -rw-r--r-- | src/lfs.c | 39 | ||||
| -rw-r--r-- | tests/test.lua | 7 |
3 files changed, 25 insertions, 24 deletions
| @@ -14,6 +14,9 @@ lib: src/lfs.so | |||
| 14 | src/lfs.so: $(OBJS) | 14 | src/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 | ||
| 17 | test: lib | ||
| 18 | LUA_CPATH=./src/?.so lua tests/test.lua | ||
| 19 | |||
| 17 | install: | 20 | install: |
| 18 | mkdir -p $(LUA_LIBDIR) | 21 | mkdir -p $(LUA_LIBDIR) |
| 19 | cp src/lfs.so $(LUA_LIBDIR) | 22 | cp src/lfs.so $(LUA_LIBDIR) |
| @@ -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 |
| 719 | static 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 | */ |
| 796 | static int _file_info_ (lua_State *L, int (*st)(const char*, STAT_STRUCT*)) { | 790 | static 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) | |||
| 120 | io.write(".") | 120 | io.write(".") |
| 121 | io.flush() | 121 | io.flush() |
| 122 | 122 | ||
| 123 | -- Check consistency of lfs.attributes values | ||
| 124 | local attr = lfs.attributes (tmpfile) | ||
| 125 | for key, value in pairs(attr) do | ||
| 126 | assert (value == lfs.attributes (tmpfile, key), | ||
| 127 | "lfs.attributes values not consistent") | ||
| 128 | end | ||
| 129 | |||
| 123 | -- Remove new file and directory | 130 | -- Remove new file and directory |
| 124 | assert (os.remove (tmpfile), "could not remove new file") | 131 | assert (os.remove (tmpfile), "could not remove new file") |
| 125 | assert (lfs.rmdir (tmpdir), "could not remove new directory") | 132 | assert (lfs.rmdir (tmpdir), "could not remove new directory") |
