Skip to content

Commit

Permalink
fix(file): call sync via exec to avoid breaking the loop event.
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
  • Loading branch information
zhaojh329 committed Nov 25, 2023
1 parent f007ede commit a60b9ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
7 changes: 0 additions & 7 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,6 @@ static int eco_file_basename(lua_State *L)
return 1;
}

static int eco_file_sync(lua_State *L)
{
sync();
return 0;
}

static int eco_file_flock(lua_State *L)
{
int fd = luaL_checkinteger(L, 1);
Expand Down Expand Up @@ -472,7 +466,6 @@ static const luaL_Reg funcs[] = {
{"chown", eco_file_chown},
{"dirname", eco_file_dirname},
{"basename", eco_file_basename},
{"sync", eco_file_sync},
{"flock", eco_file_flock},
{NULL, NULL}
};
Expand Down
11 changes: 11 additions & 0 deletions file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,15 @@ function M.flock(fd, operation, timeout)
end
end

function M.sync()
local pid, err = sys.exec('sync')
if not pid then
return nil, err
end

eco.watcher(eco.CHILD, pid):wait()

return true
end

return setmetatable(M, { __index = file })

0 comments on commit a60b9ca

Please sign in to comment.