mirror of
https://github.com/lunarmodules/luafilesystem.git
synced 2026-07-22 11:03:07 +00:00
Compare commits
3 Commits
v1_8_0
...
high-preci
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d68db4ca79 | ||
|
|
6adf412a25 | ||
|
|
442fabb11a |
37
.travis.yml
37
.travis.yml
@@ -1,15 +1,34 @@
|
||||
language: c
|
||||
|
||||
language: generic
|
||||
sudo: false
|
||||
|
||||
env:
|
||||
- LUA="lua 5.1"
|
||||
- LUA="lua 5.2"
|
||||
- LUA="lua 5.3"
|
||||
- LUA="luajit 2.1"
|
||||
jobs:
|
||||
- os: linux
|
||||
env:
|
||||
- LUA="lua 5.1"
|
||||
LIBFLAG="-shared --coverage"
|
||||
- os: linux
|
||||
env:
|
||||
- LUA="lua 5.2"
|
||||
LIBFLAG="-shared --coverage"
|
||||
- os: linux
|
||||
env:
|
||||
- LUA="lua 5.3"
|
||||
LIBFLAG="-shared --coverage"
|
||||
- os: linux
|
||||
env:
|
||||
- LUA="lua 5.4"
|
||||
LIBFLAG="-shared --coverage"
|
||||
- os: linux
|
||||
env:
|
||||
- LUA="luajit 2.1"
|
||||
LIBFLAG="-shared --coverage"
|
||||
- os: osx
|
||||
env:
|
||||
- LUA="lua 5.1"
|
||||
LIBFLAG="-bundle -undefined dynamic_lookup -all_load --coverage"
|
||||
|
||||
before_install:
|
||||
- pip install --user cpp-coveralls hererocks
|
||||
- pip install cpp-coveralls hererocks
|
||||
- hererocks env --$LUA --luarocks latest
|
||||
- export PATH="$PWD/env/bin:$PATH"
|
||||
- luarocks install lua-path
|
||||
@@ -19,7 +38,7 @@ before_install:
|
||||
- luarocks install luacov-coveralls --server=https://luarocks.org/dev --deps-mode=none
|
||||
|
||||
install:
|
||||
- luarocks make CFLAGS="-O2 -fPIC -ftest-coverage -fprofile-arcs" LIBFLAG="-shared --coverage"
|
||||
- luarocks make CFLAGS="-O2 -fPIC -ftest-coverage -fprofile-arcs" LIBFLAG="$LIBFLAG"
|
||||
|
||||
script:
|
||||
- lua -lluacov tests/test.lua
|
||||
|
||||
62
src/lfs.c
62
src/lfs.c
@@ -172,6 +172,15 @@ typedef struct dir_data {
|
||||
|
||||
#endif
|
||||
|
||||
#if _POSIX_VERSION >= 200809L
|
||||
#define UTIME_FUNC(dirp, name, utb) utimensat(dirp ? dirfd(dirp) : 0, name, utb, 0)
|
||||
#define UTIME_STRUCT struct timespec
|
||||
#else
|
||||
#define UTIME_FUNC(dirp, name, utb) utime(name, utb)
|
||||
#define UTIME_STRUCT struct utimbuf
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
#define lfs_mkdir _mkdir
|
||||
#else
|
||||
@@ -820,17 +829,39 @@ static const char *mode2string(mode_t mode)
|
||||
static int file_utime(lua_State * L)
|
||||
{
|
||||
const char *file = luaL_checkstring(L, 1);
|
||||
struct utimbuf utb, *buf;
|
||||
UTIME_STRUCT utb[2];
|
||||
UTIME_STRUCT *buf;
|
||||
#ifndef _WIN32
|
||||
DIR* dirp = NULL;
|
||||
#endif
|
||||
|
||||
if (lua_gettop(L) == 1) /* set to current date/time */
|
||||
buf = NULL;
|
||||
else {
|
||||
utb.actime = (time_t) luaL_optnumber(L, 2, 0);
|
||||
utb.modtime = (time_t) luaL_optinteger(L, 3, utb.actime);
|
||||
buf = &utb;
|
||||
#if _POSIX_VERSION >= 200809L
|
||||
lua_Number acctime = luaL_optnumber(L, 2, 0);
|
||||
lua_Number modtime = luaL_optnumber(L, 3, acctime);
|
||||
utb[0].tv_sec = acctime;
|
||||
utb[0].tv_nsec = (acctime - utb[0].tv_sec) * 1000000000;
|
||||
utb[1].tv_sec = modtime;
|
||||
utb[1].tv_nsec = (modtime - utb[1].tv_sec) * 1000000000;
|
||||
if (file[0] != '/') {
|
||||
dirp = opendir(".");
|
||||
}
|
||||
#else
|
||||
utb[0].actime = (time_t) luaL_optnumber(L, 2, 0);
|
||||
utb[0].modtime = (time_t) luaL_optnumber(L, 3, utb[0].actime);
|
||||
#endif
|
||||
buf = utb;
|
||||
}
|
||||
|
||||
return pushresult(L, utime(file, buf), NULL);
|
||||
int res = UTIME_FUNC(dirp, file, buf);
|
||||
#ifndef _WIN32
|
||||
if (dirp) {
|
||||
closedir(dirp);
|
||||
}
|
||||
#endif
|
||||
return pushresult(L, res, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -876,22 +907,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 */
|
||||
|
||||
@@ -79,6 +79,19 @@ assert (new_att.modification == testdate, "could not set modification time")
|
||||
io.write(".")
|
||||
io.flush()
|
||||
|
||||
-- High-precision attributes
|
||||
local testdate_hi = os.time({ year = 2021, day = 1, month = 23, hour=0}) + 0.5555
|
||||
assert (lfs.touch (tmpfile, testdate_hi))
|
||||
local new_att_hi = assert (lfs.attributes (tmpfile))
|
||||
if new_att_hi.modification ~= testdate_hi then
|
||||
io.write("\n")
|
||||
io.write("warning: no support for high-precision timestamps\n")
|
||||
io.flush()
|
||||
end
|
||||
|
||||
io.write(".")
|
||||
io.flush()
|
||||
|
||||
-- Change access and modification time
|
||||
local testdate1 = os.time({ year = 2007, day = 10, month = 2, hour=0})
|
||||
local testdate2 = os.time({ year = 2007, day = 11, month = 2, hour=0})
|
||||
@@ -151,8 +164,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()
|
||||
@@ -194,7 +207,7 @@ io.write(".")
|
||||
io.flush()
|
||||
|
||||
-- Stressing directory iterator
|
||||
count = 0
|
||||
local count = 0
|
||||
for i = 1, 4000 do
|
||||
for file in lfs.dir (tmp) do
|
||||
count = count + 1
|
||||
|
||||
Reference in New Issue
Block a user