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 /src | |
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`
Diffstat (limited to 'src')
-rw-r--r-- | src/lfs.c | 39 |
1 files changed, 15 insertions, 24 deletions
@@ -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); |