return higher precision times in lfs.attributes

This commit is contained in:
Hisham Muhammad
2021-01-23 15:16:20 -03:00
parent 442fabb11a
commit 6adf412a25
2 changed files with 20 additions and 5 deletions

View File

@@ -876,22 +876,37 @@ static void push_st_rdev(lua_State * L, STAT_STRUCT * info)
lua_pushinteger(L, (lua_Integer) info->st_rdev);
}
#define push_stat_timespec(field) \
lua_pushnumber(L, info->FIELDNAME(field).tv_sec \
+ info->FIELDNAME(field).tv_nsec / 1000000000.0)
#if _POSIX_VERSION >= 200809L
#define FIELDNAME(field) field
#define push_stat_time(field) push_stat_timespec(field)
#elif __APPLE__
#define FIELDNAME(field) field ## espec
#define push_stat_time(field) push_stat_timespec(field)
#else
#define FIELDNAME(field) field ## e
#define push_stat_time(field) lua_pushinteger(L, info->FIELDNAME(field))
#endif
/* time of last access */
static void push_st_atime(lua_State * L, STAT_STRUCT * info)
{
lua_pushinteger(L, (lua_Integer) info->st_atime);
push_stat_time(st_atim);
}
/* time of last data modification */
static void push_st_mtime(lua_State * L, STAT_STRUCT * info)
{
lua_pushinteger(L, (lua_Integer) info->st_mtime);
push_stat_time(st_mtim);
}
/* time of last file status change */
static void push_st_ctime(lua_State * L, STAT_STRUCT * info)
{
lua_pushinteger(L, (lua_Integer) info->st_ctime);
push_stat_time(st_ctim);
}
/* file size, in bytes */

View File

@@ -151,8 +151,8 @@ io.flush()
-- Restore access time to current value
assert (lfs.touch (tmpfile, attrib.access, attrib.modification))
new_att = assert (lfs.attributes (tmpfile))
assert (new_att.access == attrib.access)
assert (new_att.modification == attrib.modification)
assert (new_att.access - attrib.access < 1)
assert (new_att.modification - attrib.modification < 1)
io.write(".")
io.flush()