mirror of
https://github.com/lunarmodules/luafilesystem.git
synced 2026-07-23 19:43:06 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8014725009 | ||
|
|
0a82aae451 | ||
|
|
a86072a7ec | ||
|
|
e798c4f07f | ||
|
|
5422c7ac6b | ||
|
|
8f2949974a | ||
|
|
a0ca710cea | ||
|
|
40171f36b3 | ||
|
|
9db234cc10 | ||
|
|
c0552d59a4 | ||
|
|
97f2308f40 | ||
|
|
ebe20b66f0 | ||
|
|
601b4e5498 | ||
|
|
4437e19455 | ||
|
|
6b178640f0 |
33
.travis.yml
Normal file
33
.travis.yml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
language: c
|
||||||
|
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- LUAROCKS=2.2.0-rc1
|
||||||
|
matrix:
|
||||||
|
- LUA=lua5.1
|
||||||
|
- LUA=lua5.2
|
||||||
|
- LUA=lua5.3
|
||||||
|
- LUA=luajit
|
||||||
|
|
||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- bash .travis/setup_lua.sh
|
||||||
|
- sudo pip install cpp-coveralls
|
||||||
|
|
||||||
|
install:
|
||||||
|
- sudo luarocks make rockspecs/luafilesystem-cvs-3.rockspec CFLAGS="-O2 -fPIC -ftest-coverage -fprofile-arcs" LIBFLAG="-shared --coverage"
|
||||||
|
|
||||||
|
script:
|
||||||
|
- cd tests
|
||||||
|
- sudo lua test.lua
|
||||||
|
|
||||||
|
after_success:
|
||||||
|
- coveralls -b .. -r .. -E usr
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
email:
|
||||||
|
on_success: change
|
||||||
|
on_failure: always
|
||||||
15
.travis/platform.sh
Normal file
15
.travis/platform.sh
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
if [ -z "$PLATFORM" ]; then
|
||||||
|
PLATFORM=$TRAVIS_OS_NAME;
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$PLATFORM" == "osx" ]; then
|
||||||
|
PLATFORM="macosx";
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$PLATFORM" ]; then
|
||||||
|
if [ "$(uname)" == "Linux" ]; then
|
||||||
|
PLATFORM="linux";
|
||||||
|
else
|
||||||
|
PLATFORM="macosx";
|
||||||
|
fi;
|
||||||
|
fi
|
||||||
101
.travis/setup_lua.sh
Normal file
101
.travis/setup_lua.sh
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
# A script for setting up environment for travis-ci testing.
|
||||||
|
# Sets up Lua and Luarocks.
|
||||||
|
# LUA must be "lua5.1", "lua5.2" or "luajit".
|
||||||
|
# luajit2.0 - master v2.0
|
||||||
|
# luajit2.1 - master v2.1
|
||||||
|
|
||||||
|
LUAJIT_BASE="LuaJIT-2.0.3"
|
||||||
|
|
||||||
|
source .travis/platform.sh
|
||||||
|
|
||||||
|
LUAJIT="no"
|
||||||
|
|
||||||
|
if [ "$PLATFORM" == "macosx" ]; then
|
||||||
|
if [ "$LUA" == "luajit" ]; then
|
||||||
|
LUAJIT="yes";
|
||||||
|
fi
|
||||||
|
if [ "$LUA" == "luajit2.0" ]; then
|
||||||
|
LUAJIT="yes";
|
||||||
|
fi
|
||||||
|
if [ "$LUA" == "luajit2.1" ]; then
|
||||||
|
LUAJIT="yes";
|
||||||
|
fi;
|
||||||
|
elif [ "$(expr substr $LUA 1 6)" == "luajit" ]; then
|
||||||
|
LUAJIT="yes";
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$LUAJIT" == "yes" ]; then
|
||||||
|
|
||||||
|
if [ "$LUA" == "luajit" ]; then
|
||||||
|
curl http://luajit.org/download/$LUAJIT_BASE.tar.gz | tar xz;
|
||||||
|
else
|
||||||
|
git clone http://luajit.org/git/luajit-2.0.git $LUAJIT_BASE;
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd $LUAJIT_BASE
|
||||||
|
|
||||||
|
if [ "$LUA" == "luajit2.1" ]; then
|
||||||
|
git checkout v2.1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
make && sudo make install
|
||||||
|
|
||||||
|
if [ "$LUA" == "luajit2.1" ]; then
|
||||||
|
sudo ln -s /usr/local/bin/luajit-2.1.0-alpha /usr/local/bin/luajit
|
||||||
|
sudo ln -s /usr/local/bin/luajit /usr/local/bin/lua;
|
||||||
|
else
|
||||||
|
sudo ln -s /usr/local/bin/luajit /usr/local/bin/lua;
|
||||||
|
fi;
|
||||||
|
|
||||||
|
else
|
||||||
|
if [ "$LUA" == "lua5.1" ]; then
|
||||||
|
curl http://www.lua.org/ftp/lua-5.1.5.tar.gz | tar xz
|
||||||
|
cd lua-5.1.5;
|
||||||
|
elif [ "$LUA" == "lua5.2" ]; then
|
||||||
|
curl http://www.lua.org/ftp/lua-5.2.3.tar.gz | tar xz
|
||||||
|
cd lua-5.2.3;
|
||||||
|
elif [ "$LUA" == "lua5.3" ]; then
|
||||||
|
curl http://www.lua.org/work/lua-5.3.0-beta.tar.gz | tar xz
|
||||||
|
cd lua-5.3.0-beta;
|
||||||
|
fi
|
||||||
|
sudo make $PLATFORM install;
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd $TRAVIS_BUILD_DIR;
|
||||||
|
|
||||||
|
LUAROCKS_BASE=luarocks-$LUAROCKS
|
||||||
|
|
||||||
|
# curl http://luarocks.org/releases/$LUAROCKS_BASE.tar.gz | tar xz
|
||||||
|
|
||||||
|
git clone https://github.com/keplerproject/luarocks.git $LUAROCKS_BASE
|
||||||
|
cd $LUAROCKS_BASE
|
||||||
|
|
||||||
|
git checkout v$LUAROCKS
|
||||||
|
|
||||||
|
if [ "$LUA" == "luajit" ]; then
|
||||||
|
./configure --lua-suffix=jit --with-lua-include=/usr/local/include/luajit-2.0;
|
||||||
|
elif [ "$LUA" == "luajit2.0" ]; then
|
||||||
|
./configure --lua-suffix=jit --with-lua-include=/usr/local/include/luajit-2.0;
|
||||||
|
elif [ "$LUA" == "luajit2.1" ]; then
|
||||||
|
./configure --lua-suffix=jit --with-lua-include=/usr/local/include/luajit-2.1;
|
||||||
|
else
|
||||||
|
./configure;
|
||||||
|
fi
|
||||||
|
|
||||||
|
make build && sudo make install
|
||||||
|
|
||||||
|
cd $TRAVIS_BUILD_DIR
|
||||||
|
|
||||||
|
rm -rf $LUAROCKS_BASE
|
||||||
|
|
||||||
|
if [ "$LUAJIT" == "yes" ]; then
|
||||||
|
rm -rf $LUAJIT_BASE;
|
||||||
|
elif [ "$LUA" == "lua5.1" ]; then
|
||||||
|
rm -rf lua-5.1.5;
|
||||||
|
elif [ "$LUA" == "lua5.2" ]; then
|
||||||
|
rm -rf lua-5.2.3;
|
||||||
|
elif [ "$LUA" == "lua5.3" ]; then
|
||||||
|
rm -rf lua-5.3.0-beta;
|
||||||
|
fi
|
||||||
3
Makefile
3
Makefile
@@ -14,6 +14,9 @@ lib: src/lfs.so
|
|||||||
src/lfs.so: $(OBJS)
|
src/lfs.so: $(OBJS)
|
||||||
MACOSX_DEPLOYMENT_TARGET="10.3"; export MACOSX_DEPLOYMENT_TARGET; $(CC) $(CFLAGS) $(LIB_OPTION) -o src/lfs.so $(OBJS)
|
MACOSX_DEPLOYMENT_TARGET="10.3"; export MACOSX_DEPLOYMENT_TARGET; $(CC) $(CFLAGS) $(LIB_OPTION) -o src/lfs.so $(OBJS)
|
||||||
|
|
||||||
|
test: lib
|
||||||
|
LUA_CPATH=./src/?.so lua tests/test.lua
|
||||||
|
|
||||||
install:
|
install:
|
||||||
mkdir -p $(LUA_LIBDIR)
|
mkdir -p $(LUA_LIBDIR)
|
||||||
cp src/lfs.so $(LUA_LIBDIR)
|
cp src/lfs.so $(LUA_LIBDIR)
|
||||||
|
|||||||
4
README
4
README
@@ -22,6 +22,10 @@ Please check the documentation at doc/us/ for more information.
|
|||||||
History
|
History
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
Version 1.6.3 [15/Jan/2012]
|
||||||
|
* Lua 5.3 compatibility
|
||||||
|
* Assorted bugfixes
|
||||||
|
|
||||||
Version 1.6.2 [??/Oct/2012]
|
Version 1.6.2 [??/Oct/2012]
|
||||||
* Full Lua 5.2 compatibility (with Lua 5.1 fallbacks)
|
* Full Lua 5.2 compatibility (with Lua 5.1 fallbacks)
|
||||||
|
|
||||||
|
|||||||
@@ -71,8 +71,7 @@ the underlying directory structure and file attributes.</p>
|
|||||||
|
|
||||||
<h2><a name="status"></a>Status</h2>
|
<h2><a name="status"></a>Status</h2>
|
||||||
|
|
||||||
<p>Current version is 1.6.2. It was developed for Lua 5.1 but also
|
<p>Current version is 1.6.3. It works with Lua 5.1, 5.2 and 5.3.</p>
|
||||||
works with Lua 5.2.</p>
|
|
||||||
|
|
||||||
<h2><a name="download"></a>Download</h2>
|
<h2><a name="download"></a>Download</h2>
|
||||||
|
|
||||||
@@ -83,6 +82,12 @@ page.</p>
|
|||||||
<h2><a name="history"></a>History</h2>
|
<h2><a name="history"></a>History</h2>
|
||||||
|
|
||||||
<dl class="history">
|
<dl class="history">
|
||||||
|
<dt><strong>Version 1.6.3</strong> [15/Jan/2015]</dt>
|
||||||
|
<dd><ul>
|
||||||
|
<li>Lua 5.3 support.</li>
|
||||||
|
<li>Assorted bugfixes.</li>
|
||||||
|
</ul></dd>
|
||||||
|
|
||||||
<dt><strong>Version 1.6.2</strong> [??/Oct/2012]</dt>
|
<dt><strong>Version 1.6.2</strong> [??/Oct/2012]</dt>
|
||||||
<dd><ul>
|
<dd><ul>
|
||||||
<li>Full Lua 5.2 compatibility (with Lua 5.1 fallbacks)</li>
|
<li>Full Lua 5.2 compatibility (with Lua 5.1 fallbacks)</li>
|
||||||
|
|||||||
28
rockspecs/luafilesystem-1.6.3-1.rockspec
Normal file
28
rockspecs/luafilesystem-1.6.3-1.rockspec
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package = "LuaFileSystem"
|
||||||
|
version = "1.6.3-1"
|
||||||
|
source = {
|
||||||
|
url = "git://github.com/keplerproject/luafilesystem",
|
||||||
|
tag = "v_1_6_3",
|
||||||
|
}
|
||||||
|
description = {
|
||||||
|
summary = "File System Library for the Lua Programming Language",
|
||||||
|
detailed = [[
|
||||||
|
LuaFileSystem is a Lua library developed to complement the set of
|
||||||
|
functions related to file systems offered by the standard Lua
|
||||||
|
distribution. LuaFileSystem offers a portable way to access the
|
||||||
|
underlying directory structure and file attributes.
|
||||||
|
]],
|
||||||
|
license = "MIT/X11",
|
||||||
|
}
|
||||||
|
dependencies = {
|
||||||
|
"lua >= 5.1"
|
||||||
|
}
|
||||||
|
build = {
|
||||||
|
type = "builtin",
|
||||||
|
modules = {
|
||||||
|
lfs = "src/lfs.c"
|
||||||
|
},
|
||||||
|
copy_directories = {
|
||||||
|
"doc", "tests"
|
||||||
|
}
|
||||||
|
}
|
||||||
27
rockspecs/luafilesystem-cvs-3.rockspec
Normal file
27
rockspecs/luafilesystem-cvs-3.rockspec
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package = "LuaFileSystem"
|
||||||
|
|
||||||
|
version = "cvs-3"
|
||||||
|
|
||||||
|
source = {
|
||||||
|
url = "git://github.com/keplerproject/luafilesystem.git",
|
||||||
|
}
|
||||||
|
|
||||||
|
description = {
|
||||||
|
summary = "File System Library for the Lua Programming Language",
|
||||||
|
detailed = [[
|
||||||
|
LuaFileSystem is a Lua library developed to complement the set of
|
||||||
|
functions related to file systems offered by the standard Lua
|
||||||
|
distribution. LuaFileSystem offers a portable way to access the
|
||||||
|
underlying directory structure and file attributes.
|
||||||
|
]]
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies = {
|
||||||
|
"lua >= 5.1, < 5.4"
|
||||||
|
}
|
||||||
|
|
||||||
|
build = {
|
||||||
|
type = "builtin",
|
||||||
|
modules = { lfs = "src/lfs.c" },
|
||||||
|
copy_directories = { "doc", "tests" }
|
||||||
|
}
|
||||||
93
src/lfs.c
93
src/lfs.c
@@ -20,6 +20,7 @@
|
|||||||
** $Id: lfs.c,v 1.61 2009/07/04 02:10:16 mascarenhas Exp $
|
** $Id: lfs.c,v 1.61 2009/07/04 02:10:16 mascarenhas Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef LFS_DO_NOT_USE_LARGE_FILE
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#ifndef _AIX
|
#ifndef _AIX
|
||||||
#define _FILE_OFFSET_BITS 64 /* Linux, Solaris and HP-UX */
|
#define _FILE_OFFSET_BITS 64 /* Linux, Solaris and HP-UX */
|
||||||
@@ -27,8 +28,11 @@
|
|||||||
#define _LARGE_FILES 1 /* AIX */
|
#define _LARGE_FILES 1 /* AIX */
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LFS_DO_NOT_USE_LARGE_FILE
|
||||||
#define _LARGEFILE64_SOURCE
|
#define _LARGEFILE64_SOURCE
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -62,9 +66,17 @@
|
|||||||
|
|
||||||
#include "lfs.h"
|
#include "lfs.h"
|
||||||
|
|
||||||
#define LFS_VERSION "1.6.2"
|
#define LFS_VERSION "1.6.3"
|
||||||
#define LFS_LIBNAME "lfs"
|
#define LFS_LIBNAME "lfs"
|
||||||
|
|
||||||
|
#if LUA_VERSION_NUM >= 503 /* Lua 5.3 */
|
||||||
|
|
||||||
|
#ifndef luaL_optlong
|
||||||
|
#define luaL_optlong luaL_optinteger
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#if LUA_VERSION_NUM < 502
|
#if LUA_VERSION_NUM < 502
|
||||||
# define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l))
|
# define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l))
|
||||||
#endif
|
#endif
|
||||||
@@ -363,8 +375,8 @@ static int lfs_f_setmode(lua_State *L) {
|
|||||||
static int file_lock (lua_State *L) {
|
static int file_lock (lua_State *L) {
|
||||||
FILE *fh = check_file (L, 1, "lock");
|
FILE *fh = check_file (L, 1, "lock");
|
||||||
const char *mode = luaL_checkstring (L, 2);
|
const char *mode = luaL_checkstring (L, 2);
|
||||||
const long start = luaL_optlong (L, 3, 0);
|
const long start = (long) luaL_optinteger (L, 3, 0);
|
||||||
long len = luaL_optlong (L, 4, 0);
|
long len = (long) luaL_optinteger (L, 4, 0);
|
||||||
if (_file_lock (L, fh, mode, start, len, "lock")) {
|
if (_file_lock (L, fh, mode, start, len, "lock")) {
|
||||||
lua_pushboolean (L, 1);
|
lua_pushboolean (L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -384,8 +396,8 @@ static int file_lock (lua_State *L) {
|
|||||||
*/
|
*/
|
||||||
static int file_unlock (lua_State *L) {
|
static int file_unlock (lua_State *L) {
|
||||||
FILE *fh = check_file (L, 1, "unlock");
|
FILE *fh = check_file (L, 1, "unlock");
|
||||||
const long start = luaL_optlong (L, 2, 0);
|
const long start = (long) luaL_optinteger (L, 2, 0);
|
||||||
long len = luaL_optlong (L, 3, 0);
|
long len = (long) luaL_optinteger (L, 3, 0);
|
||||||
if (_file_lock (L, fh, "u", start, len, "unlock")) {
|
if (_file_lock (L, fh, "u", start, len, "unlock")) {
|
||||||
lua_pushboolean (L, 1);
|
lua_pushboolean (L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -438,6 +450,7 @@ static int make_dir (lua_State *L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Removes a directory.
|
** Removes a directory.
|
||||||
** @param #1 Directory path.
|
** @param #1 Directory path.
|
||||||
@@ -457,6 +470,7 @@ static int remove_dir (lua_State *L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Directory iterator
|
** Directory iterator
|
||||||
*/
|
*/
|
||||||
@@ -569,6 +583,7 @@ static int dir_create_meta (lua_State *L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Creates lock metatable.
|
** Creates lock metatable.
|
||||||
*/
|
*/
|
||||||
@@ -649,7 +664,7 @@ static int file_utime (lua_State *L) {
|
|||||||
buf = NULL;
|
buf = NULL;
|
||||||
else {
|
else {
|
||||||
utb.actime = (time_t)luaL_optnumber (L, 2, 0);
|
utb.actime = (time_t)luaL_optnumber (L, 2, 0);
|
||||||
utb.modtime = (time_t)luaL_optnumber (L, 3, utb.actime);
|
utb.modtime = (time_t) luaL_optinteger (L, 3, utb.actime);
|
||||||
buf = &utb;
|
buf = &utb;
|
||||||
}
|
}
|
||||||
if (utime (file, buf)) {
|
if (utime (file, buf)) {
|
||||||
@@ -668,60 +683,54 @@ static void push_st_mode (lua_State *L, STAT_STRUCT *info) {
|
|||||||
}
|
}
|
||||||
/* device inode resides on */
|
/* device inode resides on */
|
||||||
static void push_st_dev (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_dev (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, (lua_Number)info->st_dev);
|
lua_pushinteger (L, (lua_Integer) info->st_dev);
|
||||||
}
|
}
|
||||||
/* inode's number */
|
/* inode's number */
|
||||||
static void push_st_ino (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_ino (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, (lua_Number)info->st_ino);
|
lua_pushinteger (L, (lua_Integer) info->st_ino);
|
||||||
}
|
}
|
||||||
/* number of hard links to the file */
|
/* number of hard links to the file */
|
||||||
static void push_st_nlink (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_nlink (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, (lua_Number)info->st_nlink);
|
lua_pushinteger (L, (lua_Integer)info->st_nlink);
|
||||||
}
|
}
|
||||||
/* user-id of owner */
|
/* user-id of owner */
|
||||||
static void push_st_uid (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_uid (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, (lua_Number)info->st_uid);
|
lua_pushinteger (L, (lua_Integer)info->st_uid);
|
||||||
}
|
}
|
||||||
/* group-id of owner */
|
/* group-id of owner */
|
||||||
static void push_st_gid (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_gid (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, (lua_Number)info->st_gid);
|
lua_pushinteger (L, (lua_Integer)info->st_gid);
|
||||||
}
|
}
|
||||||
/* device type, for special file inode */
|
/* device type, for special file inode */
|
||||||
static void push_st_rdev (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_rdev (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, (lua_Number)info->st_rdev);
|
lua_pushinteger (L, (lua_Integer) info->st_rdev);
|
||||||
}
|
}
|
||||||
/* time of last access */
|
/* time of last access */
|
||||||
static void push_st_atime (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_atime (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, info->st_atime);
|
lua_pushinteger (L, (lua_Integer) info->st_atime);
|
||||||
}
|
}
|
||||||
/* time of last data modification */
|
/* time of last data modification */
|
||||||
static void push_st_mtime (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_mtime (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, info->st_mtime);
|
lua_pushinteger (L, (lua_Integer) info->st_mtime);
|
||||||
}
|
}
|
||||||
/* time of last file status change */
|
/* time of last file status change */
|
||||||
static void push_st_ctime (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_ctime (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, info->st_ctime);
|
lua_pushinteger (L, (lua_Integer) info->st_ctime);
|
||||||
}
|
}
|
||||||
/* file size, in bytes */
|
/* file size, in bytes */
|
||||||
static void push_st_size (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_size (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, (lua_Number)info->st_size);
|
lua_pushinteger (L, (lua_Integer)info->st_size);
|
||||||
}
|
}
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
/* blocks allocated for file */
|
/* blocks allocated for file */
|
||||||
static void push_st_blocks (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_blocks (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, (lua_Number)info->st_blocks);
|
lua_pushinteger (L, (lua_Integer)info->st_blocks);
|
||||||
}
|
}
|
||||||
/* optimal file system I/O blocksize */
|
/* optimal file system I/O blocksize */
|
||||||
static void push_st_blksize (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_blksize (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, (lua_Number)info->st_blksize);
|
lua_pushinteger (L, (lua_Integer)info->st_blksize);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
static void push_invalid (lua_State *L, STAT_STRUCT *info) {
|
|
||||||
luaL_error(L, "invalid attribute name");
|
|
||||||
#ifndef _WIN32
|
|
||||||
info->st_blksize = 0; /* never reached */
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Convert the inode protection mode to a permission list.
|
** Convert the inode protection mode to a permission list.
|
||||||
@@ -729,7 +738,7 @@ static void push_invalid (lua_State *L, STAT_STRUCT *info) {
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static const char *perm2string (unsigned short mode) {
|
static const char *perm2string (unsigned short mode) {
|
||||||
static char perms[10] = "---------\0";
|
static char perms[10] = "---------";
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<9;i++) perms[i]='-';
|
for (i=0;i<9;i++) perms[i]='-';
|
||||||
if (mode & _S_IREAD)
|
if (mode & _S_IREAD)
|
||||||
@@ -742,7 +751,7 @@ static const char *perm2string (unsigned short mode) {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static const char *perm2string (mode_t mode) {
|
static const char *perm2string (mode_t mode) {
|
||||||
static char perms[10] = "---------\0";
|
static char perms[10] = "---------";
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<9;i++) perms[i]='-';
|
for (i=0;i<9;i++) perms[i]='-';
|
||||||
if (mode & S_IRUSR) perms[0] = 'r';
|
if (mode & S_IRUSR) perms[0] = 'r';
|
||||||
@@ -787,16 +796,16 @@ struct _stat_members members[] = {
|
|||||||
{ "blocks", push_st_blocks },
|
{ "blocks", push_st_blocks },
|
||||||
{ "blksize", push_st_blksize },
|
{ "blksize", push_st_blksize },
|
||||||
#endif
|
#endif
|
||||||
{ NULL, push_invalid }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Get file or symbolic link information
|
** Get file or symbolic link information
|
||||||
*/
|
*/
|
||||||
static int _file_info_ (lua_State *L, int (*st)(const char*, STAT_STRUCT*)) {
|
static int _file_info_ (lua_State *L, int (*st)(const char*, STAT_STRUCT*)) {
|
||||||
int i;
|
|
||||||
STAT_STRUCT info;
|
STAT_STRUCT info;
|
||||||
const char *file = luaL_checkstring (L, 1);
|
const char *file = luaL_checkstring (L, 1);
|
||||||
|
int i;
|
||||||
|
|
||||||
if (st(file, &info)) {
|
if (st(file, &info)) {
|
||||||
lua_pushnil (L);
|
lua_pushnil (L);
|
||||||
@@ -804,23 +813,21 @@ static int _file_info_ (lua_State *L, int (*st)(const char*, STAT_STRUCT*)) {
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
if (lua_isstring (L, 2)) {
|
if (lua_isstring (L, 2)) {
|
||||||
int v;
|
|
||||||
const char *member = lua_tostring (L, 2);
|
const char *member = lua_tostring (L, 2);
|
||||||
if (strcmp (member, "mode") == 0) v = 0;
|
for (i = 0; members[i].name; i++) {
|
||||||
#ifndef _WIN32
|
if (strcmp(members[i].name, member) == 0) {
|
||||||
else if (strcmp (member, "blocks") == 0) v = 11;
|
/* push member value and return */
|
||||||
else if (strcmp (member, "blksize") == 0) v = 12;
|
members[i].push (L, &info);
|
||||||
#endif
|
return 1;
|
||||||
else /* look for member */
|
}
|
||||||
for (v = 1; members[v].name; v++)
|
}
|
||||||
if (*members[v].name == *member)
|
/* member not found */
|
||||||
break;
|
return luaL_error(L, "invalid attribute name");
|
||||||
/* push member value and return */
|
}
|
||||||
members[v].push (L, &info);
|
/* creates a table if none is given */
|
||||||
return 1;
|
if (!lua_istable (L, 2)) {
|
||||||
} else if (!lua_istable (L, 2))
|
|
||||||
/* creates a table if none is given */
|
|
||||||
lua_newtable (L);
|
lua_newtable (L);
|
||||||
|
}
|
||||||
/* stores all members in table on top of the stack */
|
/* stores all members in table on top of the stack */
|
||||||
for (i = 0; members[i].name; i++) {
|
for (i = 0; members[i].name; i++) {
|
||||||
lua_pushstring (L, members[i].name);
|
lua_pushstring (L, members[i].name);
|
||||||
|
|||||||
@@ -11,6 +11,14 @@
|
|||||||
#define chdir_error "Function 'chdir' not provided by system"
|
#define chdir_error "Function 'chdir' not provided by system"
|
||||||
#else
|
#else
|
||||||
#define chdir_error strerror(errno)
|
#define chdir_error strerror(errno)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define chdir(p) (_chdir(p))
|
||||||
|
#define getcwd(d, s) (_getcwd(d, s))
|
||||||
|
#define rmdir(p) (_rmdir(p))
|
||||||
|
#define fileno(f) (_fileno(f))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -120,6 +120,13 @@ assert (new_att.modification == attrib.modification)
|
|||||||
io.write(".")
|
io.write(".")
|
||||||
io.flush()
|
io.flush()
|
||||||
|
|
||||||
|
-- Check consistency of lfs.attributes values
|
||||||
|
local attr = lfs.attributes (tmpfile)
|
||||||
|
for key, value in pairs(attr) do
|
||||||
|
assert (value == lfs.attributes (tmpfile, key),
|
||||||
|
"lfs.attributes values not consistent")
|
||||||
|
end
|
||||||
|
|
||||||
-- Remove new file and directory
|
-- Remove new file and directory
|
||||||
assert (os.remove (tmpfile), "could not remove new file")
|
assert (os.remove (tmpfile), "could not remove new file")
|
||||||
assert (lfs.rmdir (tmpdir), "could not remove new directory")
|
assert (lfs.rmdir (tmpdir), "could not remove new directory")
|
||||||
|
|||||||
Reference in New Issue
Block a user