ref: 81a9794fcf59bfd8c049f163f35e040b3b3fb5da
parent: cc43a4edaba3e332a975ed4df82cf5e919cd0c39
author: kvik <[email protected]>
date: Sun Apr 18 20:32:33 EDT 2021
fs: implement p9.wstat()
--- a/p9.c
+++ b/p9.c
@@ -159,6 +159,7 @@
{"access", p9_access},
{"stat", p9_stat},
+ {"wstat", p9_wstat},
{"walk", p9_walk},
{"bind", p9_bind},
--- a/test.lua
+++ b/test.lua
@@ -115,6 +115,15 @@
p₀:close(); p₁:close()
end
+-- wstat
+do
+ local name = tmp()
+ assert(p9.create(name, nil, "644")):close()
+ assert(p9.wstat(name, {name = "notyourbusiness", mode = "append 777"}))
+ local st = assert(p9.stat("/tmp/notyourbusiness"))
+ assert(st.mode.file and st.mode.append and st.mode.perm == "rwxrwxrwx")
+end
+
-- Filesystem
do
-- Create a test tree
--- a/walk.c
+++ b/walk.c
@@ -198,3 +198,34 @@
}
return 0;
}
+
+static int
+p9_wstat(lua_State *L)
+{
+ static int createperm(lua_State*, char*); /* from fs.c */
+ const char *path, *k;
+ Dir new;
+
+ path = luaL_checkstring(L, 1);
+ luaL_argexpected(L, lua_type(L, 2) == LUA_TTABLE, 2, "table");
+ nulldir(&new);
+ lua_pushnil(L);
+ while(lua_next(L, -2)){
+ k = lua_tostring(L, -2);
+ if(strcmp(k, "name") == 0)
+ new.name = (char*)lua_tostring(L, -1); /* dw */
+ else if(strcmp(k, "mode") == 0)
+ new.mode = createperm(L, lua_tostring(L, -1));
+ else if(strcmp(k, "mtime") == 0)
+ new.mtime = lua_tointeger(L, -1);
+ else if(strcmp(k, "gid") == 0)
+ new.gid = (char*)lua_tostring(L, -1);
+ else if(strcmp(k, "length") == 0)
+ new.length = lua_tointeger(L, -1);
+ lua_pop(L, 1);
+ }
+ if(dirwstat(path, &new) == -1)
+ return error(L, "wstat: %r");
+ lua_pushboolean(L, 1);
+ return 1;
+}