mirror of
https://github.com/lunarmodules/luafilesystem.git
synced 2026-07-23 19:43:06 +00:00
Compare commits
73 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77c0e0f992 | ||
|
|
3c4e563d9c | ||
|
|
50919ed69f | ||
|
|
4cf702d850 | ||
|
|
32b355a990 | ||
|
|
080f74f785 | ||
|
|
a332bde584 | ||
|
|
7fae11cdb5 | ||
|
|
6e0dc7b27c | ||
|
|
81e5b165bf | ||
|
|
8d5f9661e9 | ||
|
|
b37e88b3d6 | ||
|
|
8f167ef1de | ||
|
|
8b85d257a6 | ||
|
|
d186dda4d7 | ||
|
|
1937ba848b | ||
|
|
732f9e9309 | ||
|
|
03e01ff953 | ||
|
|
3789521838 | ||
|
|
5220452e3b | ||
|
|
12d1f260f3 | ||
|
|
e5458bfa74 | ||
|
|
dd6376411f | ||
|
|
e3253069b9 | ||
|
|
83b8fa6c6b | ||
|
|
1146cc2b33 | ||
|
|
a9a95acd68 | ||
|
|
210322f493 | ||
|
|
9cbb967b55 | ||
|
|
2d4d609d81 | ||
|
|
436bc441fa | ||
|
|
e519c13036 | ||
|
|
c1e9c70214 | ||
|
|
655ec8baa3 | ||
|
|
695def20ef | ||
|
|
ba6d0e1ad9 | ||
|
|
95d946e0fe | ||
|
|
22d539e199 | ||
|
|
3674e4f52f | ||
|
|
5daddd4c2b | ||
|
|
6232ca6dbd | ||
|
|
7ede630d6d | ||
|
|
5131a28067 | ||
|
|
9e7f97ea4c | ||
|
|
488304b5a5 | ||
|
|
222330973c | ||
|
|
c0965e8048 | ||
|
|
6d039ff385 | ||
|
|
dc00750ea9 | ||
|
|
b6d5b37c1b | ||
|
|
c315150aff | ||
|
|
5f8b6461a2 | ||
|
|
75eed716c6 | ||
|
|
3f9f2a5afd | ||
|
|
6fcb1bb8ad | ||
|
|
644c9c32ca | ||
|
|
3cc1a84c93 | ||
|
|
25ecbd31db | ||
|
|
8014725009 | ||
|
|
0a82aae451 | ||
|
|
a86072a7ec | ||
|
|
e798c4f07f | ||
|
|
5422c7ac6b | ||
|
|
8f2949974a | ||
|
|
a0ca710cea | ||
|
|
40171f36b3 | ||
|
|
9db234cc10 | ||
|
|
c0552d59a4 | ||
|
|
97f2308f40 | ||
|
|
ebe20b66f0 | ||
|
|
601b4e5498 | ||
|
|
4437e19455 | ||
|
|
6b178640f0 |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.so
|
||||||
|
|
||||||
35
.travis.yml
Normal file
35
.travis.yml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
language: c
|
||||||
|
|
||||||
|
sudo: false
|
||||||
|
|
||||||
|
env:
|
||||||
|
- LUA="lua 5.1"
|
||||||
|
- LUA="lua 5.2"
|
||||||
|
- LUA="lua 5.3"
|
||||||
|
- LUA="luajit 2.0"
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- pip install --user cpp-coveralls hererocks
|
||||||
|
- hererocks env --$LUA --luarocks latest
|
||||||
|
- export PATH="$PWD/env/bin:$PATH"
|
||||||
|
- luarocks install Lua-cURL --server=https://luarocks.org/dev
|
||||||
|
- luarocks install lua-path
|
||||||
|
- luarocks install lua-cjson
|
||||||
|
- luarocks install luacov
|
||||||
|
# install luacov-coveralls, but avoids installing luafilesystem
|
||||||
|
- luarocks install luacov-coveralls --server=https://luarocks.org/dev --deps-mode=none
|
||||||
|
|
||||||
|
install:
|
||||||
|
- luarocks make rockspecs/luafilesystem-cvs-3.rockspec CFLAGS="-O2 -fPIC -ftest-coverage -fprofile-arcs" LIBFLAG="-shared --coverage"
|
||||||
|
|
||||||
|
script:
|
||||||
|
- lua -lluacov tests/test.lua
|
||||||
|
|
||||||
|
after_success:
|
||||||
|
- coveralls -b . -i src --dump c.report.json
|
||||||
|
- luacov-coveralls -j c.report.json -v
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
email:
|
||||||
|
on_success: change
|
||||||
|
on_failure: always
|
||||||
5
Makefile
5
Makefile
@@ -12,7 +12,10 @@ OBJS= src/$T.o
|
|||||||
lib: src/lfs.so
|
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) $(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)
|
||||||
|
|||||||
78
README
78
README
@@ -1,78 +0,0 @@
|
|||||||
LuaFileSystem - File System Library for Lua
|
|
||||||
Copyright 2003 Kepler Project
|
|
||||||
http://www.keplerproject.org/luafilesystem
|
|
||||||
|
|
||||||
Description
|
|
||||||
-----------
|
|
||||||
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.
|
|
||||||
LuaFileSystem is free software and uses the same license as Lua 5.1
|
|
||||||
|
|
||||||
LuaRocks Installation
|
|
||||||
---------------------
|
|
||||||
luarocks install luafilesystem
|
|
||||||
|
|
||||||
|
|
||||||
Documentation
|
|
||||||
-------------
|
|
||||||
Please check the documentation at doc/us/ for more information.
|
|
||||||
|
|
||||||
History
|
|
||||||
-------
|
|
||||||
|
|
||||||
Version 1.6.2 [??/Oct/2012]
|
|
||||||
* Full Lua 5.2 compatibility (with Lua 5.1 fallbacks)
|
|
||||||
|
|
||||||
Version 1.6.1 [01/Oct/2012]
|
|
||||||
* fix build for Lua 5.2
|
|
||||||
|
|
||||||
Version 1.6.0 [26/Sep/2012]
|
|
||||||
* getcwd fix for Android
|
|
||||||
* support for Lua 5.2
|
|
||||||
* add lfs.link
|
|
||||||
* other bug fixes
|
|
||||||
|
|
||||||
Version 1.5.0 [20/Oct/2009]
|
|
||||||
* added explicit next and close methods to second return value of lfs.dir (the directory object), for explicit iteration or explicit closing.
|
|
||||||
* added directory locking via lfs.lock_dir function (see the manual).
|
|
||||||
|
|
||||||
Version 1.4.2 [03/Feb/2009]
|
|
||||||
|
|
||||||
* fixed bug [#13198] lfs.attributes(filename, 'size') overflow on files > 2 Gb again (bug report and patch by KUBO Takehiro).
|
|
||||||
* fixed bug [#39794] Compile error on Solaris 10 (bug report and patch by Aaron B).
|
|
||||||
* fixed compilation problems with Borland C.
|
|
||||||
|
|
||||||
Version 1.4.1 [07/May/2008]
|
|
||||||
|
|
||||||
* documentation review
|
|
||||||
* fixed Windows compilation issues
|
|
||||||
* fixed bug in the Windows tests (patch by Shmuel Zeigerman)
|
|
||||||
* fixed bug [#2185] lfs.attributes(filename, 'size') overflow on files > 2 Gb
|
|
||||||
|
|
||||||
Version 1.4.0 [13/Feb/2008]
|
|
||||||
|
|
||||||
* added function lfs.setmode (works only in Windows systems).
|
|
||||||
* lfs.attributes raises an error if attribute does not exist
|
|
||||||
|
|
||||||
Version 1.3.0 [26/Oct/2007]
|
|
||||||
|
|
||||||
* added function lfs.symlinkattributes (works only in non Windows systems).
|
|
||||||
|
|
||||||
Version 1.2.1 [08/May/2007]
|
|
||||||
|
|
||||||
* compatible only with Lua 5.1 (Lua 5.0 support was dropped)
|
|
||||||
|
|
||||||
Version 1.2 [15/Mar/2006]
|
|
||||||
|
|
||||||
* added optional argument to lfs.attributes
|
|
||||||
* added function lfs.rmdir
|
|
||||||
* bug correction on lfs.dir
|
|
||||||
|
|
||||||
Version 1.1 [30/May/2005]
|
|
||||||
|
|
||||||
* added function lfs.touch.
|
|
||||||
|
|
||||||
Version 1.0 [21/Jan/2005]
|
|
||||||
Version 1.0 Beta [10/Nov/2004]
|
|
||||||
27
README.md
Normal file
27
README.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
[](LICENCE.txt)
|
||||||
|
[](https://travis-ci.org/keplerproject/luafilesystem)
|
||||||
|
[](https://ci.appveyor.com/project/ignacio/luafilesystem)
|
||||||
|
[](https://coveralls.io/r/keplerproject/luafilesystem)
|
||||||
|
|
||||||
|
# LuaFileSystem - File System Library for Lua
|
||||||
|
Copyright 2003-2016 Kepler Project
|
||||||
|
|
||||||
|
http://keplerproject.github.io/luafilesystem
|
||||||
|
|
||||||
|
# Description
|
||||||
|
|
||||||
|
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.
|
||||||
|
LuaFileSystem is free software and uses the same license as Lua 5.1
|
||||||
|
|
||||||
|
# LuaRocks Installation
|
||||||
|
|
||||||
|
```
|
||||||
|
luarocks install luafilesystem
|
||||||
|
```
|
||||||
|
|
||||||
|
# Documentation
|
||||||
|
|
||||||
|
Please check the documentation at doc/us/ for more information.
|
||||||
42
appveyor.yml
Normal file
42
appveyor.yml
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
version: 0.0.1.{build}-test
|
||||||
|
|
||||||
|
# Use default image unless needed
|
||||||
|
#os:
|
||||||
|
#- Windows Server 2012 R2
|
||||||
|
|
||||||
|
shallow_clone: true
|
||||||
|
|
||||||
|
environment:
|
||||||
|
matrix:
|
||||||
|
- LUA: "lua 5.1"
|
||||||
|
- LUA: "lua 5.2 --compat none"
|
||||||
|
- LUA: "lua 5.3 --compat none"
|
||||||
|
- LUA: "luajit 2.0"
|
||||||
|
- LUA: "luajit 2.1"
|
||||||
|
|
||||||
|
# Abuse this section so we can have a matrix with different Compiler versions
|
||||||
|
configuration:
|
||||||
|
- mingw
|
||||||
|
- vs_32
|
||||||
|
- vs_64
|
||||||
|
|
||||||
|
install:
|
||||||
|
- set PATH=%CD%\env\bin;C:\Python27\Scripts;C:\MinGW\bin;%PATH%
|
||||||
|
- pip install hererocks
|
||||||
|
- hererocks env --%LUA% --target %configuration% --luarocks latest
|
||||||
|
|
||||||
|
before_build:
|
||||||
|
# @todo
|
||||||
|
- echo "Installing external deps"
|
||||||
|
|
||||||
|
build_script:
|
||||||
|
- luarocks make rockspecs/luafilesystem-cvs-3.rockspec
|
||||||
|
|
||||||
|
before_test:
|
||||||
|
|
||||||
|
test_script:
|
||||||
|
- echo "Testing..."
|
||||||
|
- lua tests/test.lua
|
||||||
|
|
||||||
|
after_test:
|
||||||
|
# @todo
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
<div id="product">
|
<div id="product">
|
||||||
<div id="product_logo">
|
<div id="product_logo">
|
||||||
<a href="http://www.keplerproject.org">
|
<a href="http://keplerproject.github.io/luafilesystem">
|
||||||
<img alt="LuaFileSystem" src="luafilesystem.png"/>
|
<img alt="LuaFileSystem" src="luafilesystem.png"/>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
@@ -33,7 +33,6 @@
|
|||||||
<li><a href="index.html#download">Download</a></li>
|
<li><a href="index.html#download">Download</a></li>
|
||||||
<li><a href="index.html#history">History</a></li>
|
<li><a href="index.html#history">History</a></li>
|
||||||
<li><a href="index.html#credits">Credits</a></li>
|
<li><a href="index.html#credits">Credits</a></li>
|
||||||
<li><a href="index.html#contact">Contact us</a></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li><a href="manual.html">Manual</a>
|
<li><a href="manual.html">Manual</a>
|
||||||
@@ -94,7 +93,6 @@ attrdir (".")
|
|||||||
|
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p>
|
<p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p>
|
||||||
<p><small>$Id: examples.html,v 1.8 2007/12/14 15:28:04 carregal Exp $</small></p>
|
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
|
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
<div id="product">
|
<div id="product">
|
||||||
<div id="product_logo">
|
<div id="product_logo">
|
||||||
<a href="http://www.keplerproject.org">
|
<a href="http://keplerproject.github.io/luafilesystem">
|
||||||
<img alt="LuaFileSystem" src="luafilesystem.png"/>
|
<img alt="LuaFileSystem" src="luafilesystem.png"/>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
@@ -33,7 +33,6 @@
|
|||||||
<li><a href="index.html#download">Download</a></li>
|
<li><a href="index.html#download">Download</a></li>
|
||||||
<li><a href="index.html#history">History</a></li>
|
<li><a href="index.html#history">History</a></li>
|
||||||
<li><a href="index.html#credits">Credits</a></li>
|
<li><a href="index.html#credits">Credits</a></li>
|
||||||
<li><a href="index.html#contact">Contact us</a></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li><a href="manual.html">Manual</a>
|
<li><a href="manual.html">Manual</a>
|
||||||
@@ -67,12 +66,11 @@ systems offered by the standard Lua distribution.</p>
|
|||||||
the underlying directory structure and file attributes.</p>
|
the underlying directory structure and file attributes.</p>
|
||||||
|
|
||||||
<p>LuaFileSystem is free software and uses the same
|
<p>LuaFileSystem is free software and uses the same
|
||||||
<a href="license.html">license</a> as Lua 5.1.</p>
|
<a href="license.html">license</a> as Lua 5.x (MIT).</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 +81,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>
|
||||||
@@ -110,9 +114,9 @@ page.</p>
|
|||||||
<dt><strong>Version 1.4.2</strong> [03/Feb/2009]</dt>
|
<dt><strong>Version 1.4.2</strong> [03/Feb/2009]</dt>
|
||||||
<dd>
|
<dd>
|
||||||
<ul>
|
<ul>
|
||||||
<li>fixed bug [<a href="http://luaforge.net/tracker/?func=detail&group_id=66&aid=13198&atid=356">#13198</a>]
|
<li>fixed bug
|
||||||
lfs.attributes(filename, 'size') overflow on files > 2 Gb again (bug report and patch by KUBO Takehiro).</li>
|
<code>lfs.attributes(filename, 'size')</code> overflow on files > 2 Gb again (bug report and patch by KUBO Takehiro).</li>
|
||||||
<li>fixed bug [<a href="http://luaforge.net/tracker/?group_id=66&atid=356&func=detail&aid=39794">#39794</a>]
|
<li>fixed bug
|
||||||
Compile error on Solaris 10 (bug report and patch by Aaron B).</li>
|
Compile error on Solaris 10 (bug report and patch by Aaron B).</li>
|
||||||
<li>fixed compilation problems with Borland C.</li>
|
<li>fixed compilation problems with Borland C.</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -124,7 +128,7 @@ page.</p>
|
|||||||
<li>documentation review</li>
|
<li>documentation review</li>
|
||||||
<li>fixed Windows compilation issues</li>
|
<li>fixed Windows compilation issues</li>
|
||||||
<li>fixed bug in the Windows tests (patch by Shmuel Zeigerman)</li>
|
<li>fixed bug in the Windows tests (patch by Shmuel Zeigerman)</li>
|
||||||
<li>fixed bug [<a href="http://luaforge.net/tracker/?func=detail&group_id=66&aid=2185&atid=356">#2185</a>]
|
<li>fixed bug
|
||||||
<code>lfs.attributes(filename, 'size')</code> overflow on files > 2 Gb
|
<code>lfs.attributes(filename, 'size')</code> overflow on files > 2 Gb
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -186,25 +190,15 @@ page.</p>
|
|||||||
|
|
||||||
<p>LuaFileSystem was designed by Roberto Ierusalimschy,
|
<p>LuaFileSystem was designed by Roberto Ierusalimschy,
|
||||||
André Carregal and Tomás Guisasola as part of the
|
André Carregal and Tomás Guisasola as part of the
|
||||||
<a href="http://www.keplerproject.org">Kepler Project</a>,
|
<a href="https://github.com/keplerproject">Kepler Project</a>,
|
||||||
which holds its copyright. LuaFileSystem is currently maintained by Fábio Mascarenhas.</p>
|
which holds its copyright. LuaFileSystem is currently maintained by Fábio Mascarenhas.</p>
|
||||||
|
|
||||||
<h2><a name="contact"></a>Contact us</h2>
|
|
||||||
|
|
||||||
<p>For more information please
|
|
||||||
<a href="mailto:info-NO-SPAM-THANKS@keplerproject.org">contact us</a>.
|
|
||||||
Comments are welcome!</p>
|
|
||||||
|
|
||||||
<p>You can also reach other Kepler developers and users on the Kepler Project
|
|
||||||
<a href="http://luaforge.net/mail/?group_id=104">mailing list</a>.</p>
|
|
||||||
|
|
||||||
</div> <!-- id="content" -->
|
</div> <!-- id="content" -->
|
||||||
|
|
||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
|
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p>
|
<p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p>
|
||||||
<p><small>$Id: index.html,v 1.44 2009/02/04 21:21:33 carregal Exp $</small></p>
|
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
|
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
<div id="product">
|
<div id="product">
|
||||||
<div id="product_logo">
|
<div id="product_logo">
|
||||||
<a href="http://www.keplerproject.org">
|
<a href="http://keplerproject.github.io/luafilesystem">
|
||||||
<img alt="LuaFileSystem" src="luafilesystem.png"/>
|
<img alt="LuaFileSystem" src="luafilesystem.png"/>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
@@ -33,7 +33,6 @@
|
|||||||
<li><a href="index.html#download">Download</a></li>
|
<li><a href="index.html#download">Download</a></li>
|
||||||
<li><a href="index.html#history">History</a></li>
|
<li><a href="index.html#history">History</a></li>
|
||||||
<li><a href="index.html#credits">Credits</a></li>
|
<li><a href="index.html#credits">Credits</a></li>
|
||||||
<li><a href="index.html#contact">Contact us</a></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li><a href="manual.html">Manual</a>
|
<li><a href="manual.html">Manual</a>
|
||||||
@@ -47,7 +46,7 @@
|
|||||||
<li><a href="examples.html">Examples</a></li>
|
<li><a href="examples.html">Examples</a></li>
|
||||||
<li><a href="https://github.com/keplerproject/luafilesystem">Project</a>
|
<li><a href="https://github.com/keplerproject/luafilesystem">Project</a>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="https://github.com/keplerproject/luafilesystem/issues/">Bug Tracker</a></li>
|
<li><a href="https://github.com/keplerproject/luafilesystem/issues">Bug Tracker</a></li>
|
||||||
<li><a href="https://github.com/keplerproject/luafilesystem">Git</a></li>
|
<li><a href="https://github.com/keplerproject/luafilesystem">Git</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
@@ -69,7 +68,7 @@ software.
|
|||||||
Its licenses are compatible with
|
Its licenses are compatible with
|
||||||
<a href="http://www.gnu.org/licenses/gpl.html">GPL</a>.
|
<a href="http://www.gnu.org/licenses/gpl.html">GPL</a>.
|
||||||
LuaFileSystem is not in the public domain and the
|
LuaFileSystem is not in the public domain and the
|
||||||
<a href="http://www.keplerproject.org">Kepler Project</a>
|
<a href="https://github.com/keplerproject">Kepler Project</a>
|
||||||
keep its copyright.
|
keep its copyright.
|
||||||
The legal details are below.
|
The legal details are below.
|
||||||
</p>
|
</p>
|
||||||
@@ -113,7 +112,6 @@ SOFTWARE.</p>
|
|||||||
|
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p>
|
<p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p>
|
||||||
<p><small>$Id: license.html,v 1.13 2008/02/11 22:42:21 carregal Exp $</small></p>
|
|
||||||
</div><!-- id="about" -->
|
</div><!-- id="about" -->
|
||||||
|
|
||||||
</div><!-- id="container" -->
|
</div><!-- id="container" -->
|
||||||
|
|||||||
@@ -13,7 +13,9 @@
|
|||||||
|
|
||||||
<div id="product">
|
<div id="product">
|
||||||
<div id="product_logo">
|
<div id="product_logo">
|
||||||
<a href="http://www.keplerproject.org"><img alt="LuaFileSystem" src="luafilesystem.png"/></a>
|
<a href="http://keplerproject.github.io/luafilesystem">
|
||||||
|
<img alt="LuaFileSystem" src="luafilesystem.png"/>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div id="product_name"><big><strong>LuaFileSystem</strong></big></div>
|
<div id="product_name"><big><strong>LuaFileSystem</strong></big></div>
|
||||||
<div id="product_description">File System Library for the Lua Programming Language</div>
|
<div id="product_description">File System Library for the Lua Programming Language</div>
|
||||||
@@ -31,7 +33,6 @@
|
|||||||
<li><a href="index.html#download">Download</a></li>
|
<li><a href="index.html#download">Download</a></li>
|
||||||
<li><a href="index.html#history">History</a></li>
|
<li><a href="index.html#history">History</a></li>
|
||||||
<li><a href="index.html#credits">Credits</a></li>
|
<li><a href="index.html#credits">Credits</a></li>
|
||||||
<li><a href="index.html#contact">Contact us</a></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li><strong>Manual</strong>
|
<li><strong>Manual</strong>
|
||||||
@@ -101,14 +102,15 @@ LuaFileSystem offers the following functions:
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<dl class="reference">
|
<dl class="reference">
|
||||||
<dt><a name="attributes"></a><strong><code>lfs.attributes (filepath [, aname])</code></strong></dt>
|
<dt><a name="attributes"></a><strong><code>lfs.attributes (filepath [, aname | atable])</code></strong></dt>
|
||||||
<dd>Returns a table with the file attributes corresponding to
|
<dd>Returns a table with the file attributes corresponding to
|
||||||
<code>filepath</code> (or <code>nil</code> followed by an error message
|
<code>filepath</code> (or <code>nil</code> followed by an error message and a system-dependent error code
|
||||||
in case of error).
|
in case of error).
|
||||||
If the second optional argument is given, then only the value of the
|
If the second optional argument is given and is a string, then only the value of the
|
||||||
named attribute is returned (this use is equivalent to
|
named attribute is returned (this use is equivalent to
|
||||||
<code>lfs.attributes(filepath).aname</code>, but the table is not created
|
<code>lfs.attributes(filepath)[aname]</code>, but the table is not created
|
||||||
and only one attribute is retrieved from the O.S.).
|
and only one attribute is retrieved from the O.S.).
|
||||||
|
if a table is passed as the second argument, it is filled with attributes and returned instead of a new table.
|
||||||
The attributes are described as follows;
|
The attributes are described as follows;
|
||||||
attribute <code>mode</code> is a string, all the others are numbers,
|
attribute <code>mode</code> is a string, all the others are numbers,
|
||||||
and the time related attributes use the same time reference of
|
and the time related attributes use the same time reference of
|
||||||
@@ -152,6 +154,9 @@ LuaFileSystem offers the following functions:
|
|||||||
<dt><strong><code>size</code></strong></dt>
|
<dt><strong><code>size</code></strong></dt>
|
||||||
<dd>file size, in bytes</dd>
|
<dd>file size, in bytes</dd>
|
||||||
|
|
||||||
|
<dt><strong><code>permissions</code></strong></dt>
|
||||||
|
<dd>file permissions string</dd>
|
||||||
|
|
||||||
<dt><strong><code>blocks</code></strong></dt>
|
<dt><strong><code>blocks</code></strong></dt>
|
||||||
<dd>block allocated for file; (Unix only)</dd>
|
<dd>block allocated for file; (Unix only)</dd>
|
||||||
|
|
||||||
@@ -172,7 +177,7 @@ LuaFileSystem offers the following functions:
|
|||||||
Returns <code>true</code> in case of success or <code>nil</code> plus an
|
Returns <code>true</code> in case of success or <code>nil</code> plus an
|
||||||
error string.</dd>
|
error string.</dd>
|
||||||
|
|
||||||
<dt><a name="chdir"></a><strong><code>lfs.lock_dir(path, [seconds_stale])</code></strong></dt>
|
<dt><a name="lock_dir"></a><strong><code>lfs.lock_dir(path, [seconds_stale])</code></strong></dt>
|
||||||
<dd>Creates a lockfile (called lockfile.lfs) in <code>path</code> if it does not
|
<dd>Creates a lockfile (called lockfile.lfs) in <code>path</code> if it does not
|
||||||
exist and returns the lock. If the lock already exists checks if
|
exist and returns the lock. If the lock already exists checks if
|
||||||
it's stale, using the second parameter (default for the second
|
it's stale, using the second parameter (default for the second
|
||||||
@@ -182,7 +187,7 @@ LuaFileSystem offers the following functions:
|
|||||||
particular, if the lock exists and is not stale it returns the
|
particular, if the lock exists and is not stale it returns the
|
||||||
"File exists" message.</dd>
|
"File exists" message.</dd>
|
||||||
|
|
||||||
<dt><a name="getcwd"></a><strong><code>lfs.currentdir ()</code></strong></dt>
|
<dt><a name="currentdir"></a><strong><code>lfs.currentdir ()</code></strong></dt>
|
||||||
<dd>Returns a string with the current working directory or <code>nil</code>
|
<dd>Returns a string with the current working directory or <code>nil</code>
|
||||||
plus an error string.</dd>
|
plus an error string.</dd>
|
||||||
|
|
||||||
@@ -217,14 +222,14 @@ LuaFileSystem offers the following functions:
|
|||||||
<dt><a name="mkdir"></a><strong><code>lfs.mkdir (dirname)</code></strong></dt>
|
<dt><a name="mkdir"></a><strong><code>lfs.mkdir (dirname)</code></strong></dt>
|
||||||
<dd>Creates a new directory. The argument is the name of the new
|
<dd>Creates a new directory. The argument is the name of the new
|
||||||
directory.<br />
|
directory.<br />
|
||||||
Returns <code>true</code> if the operation was successful;
|
Returns <code>true</code> in case of success or <code>nil</code>, an error message and
|
||||||
in case of error, it returns <code>nil</code> plus an error string.
|
a system-dependent error code in case of error.
|
||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
<dt><a name="rmdir"></a><strong><code>lfs.rmdir (dirname)</code></strong></dt>
|
<dt><a name="rmdir"></a><strong><code>lfs.rmdir (dirname)</code></strong></dt>
|
||||||
<dd>Removes an existing directory. The argument is the name of the directory.<br />
|
<dd>Removes an existing directory. The argument is the name of the directory.<br />
|
||||||
Returns <code>true</code> if the operation was successful;
|
Returns <code>true</code> in case of success or <code>nil</code>, an error message and
|
||||||
in case of error, it returns <code>nil</code> plus an error string.</dd>
|
a system-dependent error code in case of error.
|
||||||
|
|
||||||
<dt><a name="setmode"></a><strong><code>lfs.setmode (file, mode)</code></strong></dt>
|
<dt><a name="setmode"></a><strong><code>lfs.setmode (file, mode)</code></strong></dt>
|
||||||
<dd>Sets the writing mode for a file. The mode string can be either <code>"binary"</code> or <code>"text"</code>.
|
<dd>Sets the writing mode for a file. The mode string can be either <code>"binary"</code> or <code>"text"</code>.
|
||||||
@@ -237,6 +242,8 @@ LuaFileSystem offers the following functions:
|
|||||||
<dt><a name="symlinkattributes"></a><strong><code>lfs.symlinkattributes (filepath [, aname])</code></strong></dt>
|
<dt><a name="symlinkattributes"></a><strong><code>lfs.symlinkattributes (filepath [, aname])</code></strong></dt>
|
||||||
<dd>Identical to <a href="#attributes">lfs.attributes</a> except that
|
<dd>Identical to <a href="#attributes">lfs.attributes</a> except that
|
||||||
it obtains information about the link itself (not the file it refers to).
|
it obtains information about the link itself (not the file it refers to).
|
||||||
|
It also adds a <strong><code>target</code></strong> field, containing
|
||||||
|
the file name that the symlink points to.
|
||||||
On Windows this function does not yet support links, and is identical to
|
On Windows this function does not yet support links, and is identical to
|
||||||
<code>lfs.attributes</code>.
|
<code>lfs.attributes</code>.
|
||||||
</dd>
|
</dd>
|
||||||
@@ -250,8 +257,8 @@ LuaFileSystem offers the following functions:
|
|||||||
Lua standard function <code>os.time</code>).
|
Lua standard function <code>os.time</code>).
|
||||||
If the modification time is omitted, the access time provided is used;
|
If the modification time is omitted, the access time provided is used;
|
||||||
if both times are omitted, the current time is used.<br />
|
if both times are omitted, the current time is used.<br />
|
||||||
Returns <code>true</code> if the operation was successful;
|
Returns <code>true</code> in case of success or <code>nil</code>, an error message and
|
||||||
in case of error, it returns <code>nil</code> plus an error string.
|
a system-dependent error code in case of error.
|
||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
<dt><a name="unlock"></a><strong><code>lfs.unlock (filehandle[, start[, length]])</code></strong></dt>
|
<dt><a name="unlock"></a><strong><code>lfs.unlock (filehandle[, start[, length]])</code></strong></dt>
|
||||||
@@ -271,7 +278,6 @@ LuaFileSystem offers the following functions:
|
|||||||
|
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p>
|
<p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p>
|
||||||
<p><small>$Id: manual.html,v 1.45 2009/06/03 20:53:55 mascarenhas Exp $</small></p>
|
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
|
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
|
|||||||
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" }
|
||||||
|
}
|
||||||
400
src/lfs.c
400
src/lfs.c
@@ -1,25 +1,25 @@
|
|||||||
/*
|
/*
|
||||||
** LuaFileSystem
|
** LuaFileSystem
|
||||||
** Copyright Kepler Project 2003 (http://www.keplerproject.org/luafilesystem)
|
** Copyright Kepler Project 2003 - 2016 (http://keplerproject.github.io/luafilesystem)
|
||||||
**
|
**
|
||||||
** File system manipulation library.
|
** File system manipulation library.
|
||||||
** This library offers these functions:
|
** This library offers these functions:
|
||||||
** lfs.attributes (filepath [, attributename])
|
** lfs.attributes (filepath [, attributename | attributetable])
|
||||||
** lfs.chdir (path)
|
** lfs.chdir (path)
|
||||||
** lfs.currentdir ()
|
** lfs.currentdir ()
|
||||||
** lfs.dir (path)
|
** lfs.dir (path)
|
||||||
|
** lfs.link (old, new[, symlink])
|
||||||
** lfs.lock (fh, mode)
|
** lfs.lock (fh, mode)
|
||||||
** lfs.lock_dir (path)
|
** lfs.lock_dir (path)
|
||||||
** lfs.mkdir (path)
|
** lfs.mkdir (path)
|
||||||
** lfs.rmdir (path)
|
** lfs.rmdir (path)
|
||||||
** lfs.setmode (filepath, mode)
|
** lfs.setmode (filepath, mode)
|
||||||
** lfs.symlinkattributes (filepath [, attributename]) -- thanks to Sam Roberts
|
** lfs.symlinkattributes (filepath [, attributename])
|
||||||
** lfs.touch (filepath [, atime [, mtime]])
|
** lfs.touch (filepath [, atime [, mtime]])
|
||||||
** lfs.unlock (fh)
|
** lfs.unlock (fh)
|
||||||
**
|
|
||||||
** $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 +27,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>
|
||||||
@@ -38,22 +41,26 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <sys/locking.h>
|
#include <sys/locking.h>
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
#include <utime.h>
|
#include <utime.h>
|
||||||
|
#else
|
||||||
|
#include <sys/utime.h>
|
||||||
|
#endif
|
||||||
|
#include <fcntl.h>
|
||||||
|
/* MAX_PATH seems to be 260. Seems kind of small. Is there a better one? */
|
||||||
|
#define LFS_MAXPATHLEN MAX_PATH
|
||||||
#else
|
#else
|
||||||
#include <sys/utime.h>
|
#include <unistd.h>
|
||||||
#endif
|
#include <dirent.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#else
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <utime.h>
|
||||||
#include <dirent.h>
|
#include <sys/param.h> /* for MAXPATHLEN */
|
||||||
#include <fcntl.h>
|
#define LFS_MAXPATHLEN MAXPATHLEN
|
||||||
#include <sys/types.h>
|
|
||||||
#include <utime.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
@@ -62,9 +69,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
|
||||||
@@ -74,22 +89,6 @@
|
|||||||
#define strerror(_) "System unable to describe the error"
|
#define strerror(_) "System unable to describe the error"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Define 'getcwd' for systems that do not implement it */
|
|
||||||
#ifdef NO_GETCWD
|
|
||||||
#define getcwd(p,s) NULL
|
|
||||||
#define getcwd_error "Function 'getcwd' not provided by system"
|
|
||||||
#else
|
|
||||||
#define getcwd_error strerror(errno)
|
|
||||||
#ifdef _WIN32
|
|
||||||
/* MAX_PATH seems to be 260. Seems kind of small. Is there a better one? */
|
|
||||||
#define LFS_MAXPATHLEN MAX_PATH
|
|
||||||
#else
|
|
||||||
/* For MAXPATHLEN: */
|
|
||||||
#include <sys/param.h>
|
|
||||||
#define LFS_MAXPATHLEN MAXPATHLEN
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define DIR_METATABLE "directory metatable"
|
#define DIR_METATABLE "directory metatable"
|
||||||
typedef struct dir_data {
|
typedef struct dir_data {
|
||||||
int closed;
|
int closed;
|
||||||
@@ -105,10 +104,10 @@ typedef struct dir_data {
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
#define lfs_setmode(L,file,m) ((void)L, setmode(_fileno(file), m))
|
#define lfs_setmode(file, m) (setmode(_fileno(file), m))
|
||||||
#define STAT_STRUCT struct stati64
|
#define STAT_STRUCT struct stati64
|
||||||
#else
|
#else
|
||||||
#define lfs_setmode(L,file,m) ((void)L, _setmode(_fileno(file), m))
|
#define lfs_setmode(file, m) (_setmode(_fileno(file), m))
|
||||||
#define STAT_STRUCT struct _stati64
|
#define STAT_STRUCT struct _stati64
|
||||||
#endif
|
#endif
|
||||||
#define STAT_FUNC _stati64
|
#define STAT_FUNC _stati64
|
||||||
@@ -116,12 +115,19 @@ typedef struct dir_data {
|
|||||||
#else
|
#else
|
||||||
#define _O_TEXT 0
|
#define _O_TEXT 0
|
||||||
#define _O_BINARY 0
|
#define _O_BINARY 0
|
||||||
#define lfs_setmode(L,file,m) ((void)L, (void)file, (void)m, 0)
|
#define lfs_setmode(file, m) ((void)file, (void)m, 0)
|
||||||
#define STAT_STRUCT struct stat
|
#define STAT_STRUCT struct stat
|
||||||
#define STAT_FUNC stat
|
#define STAT_FUNC stat
|
||||||
#define LSTAT_FUNC lstat
|
#define LSTAT_FUNC lstat
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define lfs_mkdir _mkdir
|
||||||
|
#else
|
||||||
|
#define lfs_mkdir(path) (mkdir((path), \
|
||||||
|
S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH))
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Utility functions
|
** Utility functions
|
||||||
*/
|
*/
|
||||||
@@ -136,12 +142,13 @@ static int pusherror(lua_State *L, const char *info)
|
|||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pushresult(lua_State *L, int i, const char *info)
|
static int pushresult(lua_State *L, int res, const char *info) {
|
||||||
{
|
if (res == -1) {
|
||||||
if (i==-1)
|
return pusherror(L, info);
|
||||||
return pusherror(L, info);
|
} else {
|
||||||
lua_pushinteger(L, i);
|
lua_pushboolean(L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -167,33 +174,58 @@ static int change_dir (lua_State *L) {
|
|||||||
** and a string describing the error
|
** and a string describing the error
|
||||||
*/
|
*/
|
||||||
static int get_dir (lua_State *L) {
|
static int get_dir (lua_State *L) {
|
||||||
char *path;
|
#ifdef NO_GETCWD
|
||||||
/* Passing (NULL, 0) is not guaranteed to work. Use a temp buffer and size instead. */
|
|
||||||
char buf[LFS_MAXPATHLEN];
|
|
||||||
if ((path = getcwd(buf, LFS_MAXPATHLEN)) == NULL) {
|
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
lua_pushstring(L, getcwd_error);
|
lua_pushstring(L, "Function 'getcwd' not provided by system");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
#else
|
||||||
else {
|
char *path = NULL;
|
||||||
lua_pushstring(L, path);
|
/* Passing (NULL, 0) is not guaranteed to work. Use a temp buffer and size instead. */
|
||||||
return 1;
|
size_t size = LFS_MAXPATHLEN; /* initial buffer size */
|
||||||
}
|
int result;
|
||||||
|
while (1) {
|
||||||
|
path = realloc(path, size);
|
||||||
|
if (!path) /* failed to allocate */
|
||||||
|
return pusherror(L, "get_dir realloc() failed");
|
||||||
|
if (getcwd(path, size) != NULL) {
|
||||||
|
/* success, push the path to the Lua stack */
|
||||||
|
lua_pushstring(L, path);
|
||||||
|
result = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (errno != ERANGE) { /* unexpected error */
|
||||||
|
result = pusherror(L, "get_dir getcwd() failed");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* ERANGE = insufficient buffer capacity, double size and retry */
|
||||||
|
size *= 2;
|
||||||
|
}
|
||||||
|
free(path);
|
||||||
|
return result;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Check if the given element on the stack is a file and returns it.
|
** Check if the given element on the stack is a file and returns it.
|
||||||
*/
|
*/
|
||||||
static FILE *check_file (lua_State *L, int idx, const char *funcname) {
|
static FILE *check_file (lua_State *L, int idx, const char *funcname) {
|
||||||
|
#if LUA_VERSION_NUM == 501
|
||||||
FILE **fh = (FILE **)luaL_checkudata (L, idx, "FILE*");
|
FILE **fh = (FILE **)luaL_checkudata (L, idx, "FILE*");
|
||||||
if (fh == NULL) {
|
if (*fh == NULL) {
|
||||||
luaL_error (L, "%s: not a file", funcname);
|
|
||||||
return 0;
|
|
||||||
} else if (*fh == NULL) {
|
|
||||||
luaL_error (L, "%s: closed file", funcname);
|
luaL_error (L, "%s: closed file", funcname);
|
||||||
return 0;
|
return 0;
|
||||||
} else
|
} else
|
||||||
return *fh;
|
return *fh;
|
||||||
|
#elif LUA_VERSION_NUM >= 502 && LUA_VERSION_NUM <= 503
|
||||||
|
luaL_Stream *fh = (luaL_Stream *)luaL_checkudata (L, idx, "FILE*");
|
||||||
|
if (fh->closef == 0 || fh->f == NULL) {
|
||||||
|
luaL_error (L, "%s: closed file", funcname);
|
||||||
|
return 0;
|
||||||
|
} else
|
||||||
|
return fh->f;
|
||||||
|
#else
|
||||||
|
#error unsupported Lua version
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -280,7 +312,7 @@ static int lfs_lock_dir(lua_State *L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
static int lfs_unlock_dir(lua_State *L) {
|
static int lfs_unlock_dir(lua_State *L) {
|
||||||
lfs_Lock *lock = luaL_checkudata(L, 1, LOCK_METATABLE);
|
lfs_Lock *lock = (lfs_Lock *)luaL_checkudata(L, 1, LOCK_METATABLE);
|
||||||
if(lock->fd != INVALID_HANDLE_VALUE) {
|
if(lock->fd != INVALID_HANDLE_VALUE) {
|
||||||
CloseHandle(lock->fd);
|
CloseHandle(lock->fd);
|
||||||
lock->fd=INVALID_HANDLE_VALUE;
|
lock->fd=INVALID_HANDLE_VALUE;
|
||||||
@@ -313,7 +345,7 @@ static int lfs_lock_dir(lua_State *L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
static int lfs_unlock_dir(lua_State *L) {
|
static int lfs_unlock_dir(lua_State *L) {
|
||||||
lfs_Lock *lock = luaL_checkudata(L, 1, LOCK_METATABLE);
|
lfs_Lock *lock = (lfs_Lock *)luaL_checkudata(L, 1, LOCK_METATABLE);
|
||||||
if(lock->ln) {
|
if(lock->ln) {
|
||||||
unlink(lock->ln);
|
unlink(lock->ln);
|
||||||
free(lock->ln);
|
free(lock->ln);
|
||||||
@@ -327,25 +359,20 @@ static int lfs_g_setmode (lua_State *L, FILE *f, int arg) {
|
|||||||
static const int mode[] = {_O_BINARY, _O_TEXT};
|
static const int mode[] = {_O_BINARY, _O_TEXT};
|
||||||
static const char *const modenames[] = {"binary", "text", NULL};
|
static const char *const modenames[] = {"binary", "text", NULL};
|
||||||
int op = luaL_checkoption(L, arg, NULL, modenames);
|
int op = luaL_checkoption(L, arg, NULL, modenames);
|
||||||
int res = lfs_setmode(L, f, mode[op]);
|
int res = lfs_setmode(f, mode[op]);
|
||||||
if (res != -1) {
|
if (res != -1) {
|
||||||
int i;
|
int i;
|
||||||
lua_pushboolean(L, 1);
|
lua_pushboolean(L, 1);
|
||||||
for (i = 0; modenames[i] != NULL; i++) {
|
for (i = 0; modenames[i] != NULL; i++) {
|
||||||
if (mode[i] == res) {
|
if (mode[i] == res) {
|
||||||
lua_pushstring(L, modenames[i]);
|
lua_pushstring(L, modenames[i]);
|
||||||
goto exit;
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
exit:
|
|
||||||
return 2;
|
return 2;
|
||||||
} else {
|
} else {
|
||||||
int en = errno;
|
return pusherror(L, NULL);
|
||||||
lua_pushnil(L);
|
|
||||||
lua_pushfstring(L, "%s", strerror(en));
|
|
||||||
lua_pushinteger(L, en);
|
|
||||||
return 3;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,8 +390,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 +411,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;
|
||||||
@@ -403,15 +430,20 @@ static int file_unlock (lua_State *L) {
|
|||||||
** @param #2 Name of link.
|
** @param #2 Name of link.
|
||||||
** @param #3 True if link is symbolic (optional).
|
** @param #3 True if link is symbolic (optional).
|
||||||
*/
|
*/
|
||||||
static int make_link(lua_State *L)
|
static int make_link (lua_State *L) {
|
||||||
{
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
const char *oldpath = luaL_checkstring(L, 1);
|
const char *oldpath = luaL_checkstring(L, 1);
|
||||||
const char *newpath = luaL_checkstring(L, 2);
|
const char *newpath = luaL_checkstring(L, 2);
|
||||||
return pushresult(L,
|
int res = (lua_toboolean(L,3) ? symlink : link)(oldpath, newpath);
|
||||||
(lua_toboolean(L,3) ? symlink : link)(oldpath, newpath), NULL);
|
if (res == -1) {
|
||||||
|
return pusherror(L, NULL);
|
||||||
|
} else {
|
||||||
|
lua_pushinteger(L, 0);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
return pusherror(L, "make_link is not supported on Windows");
|
errno = ENOSYS; /* = "Function not implemented" */
|
||||||
|
return pushresult(L, -1, "make_link is not supported on Windows");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -421,42 +453,21 @@ static int make_link(lua_State *L)
|
|||||||
** @param #1 Directory path.
|
** @param #1 Directory path.
|
||||||
*/
|
*/
|
||||||
static int make_dir (lua_State *L) {
|
static int make_dir (lua_State *L) {
|
||||||
const char *path = luaL_checkstring (L, 1);
|
const char *path = luaL_checkstring(L, 1);
|
||||||
int fail;
|
return pushresult(L, lfs_mkdir(path), NULL);
|
||||||
#ifdef _WIN32
|
|
||||||
fail = _mkdir (path);
|
|
||||||
#else
|
|
||||||
fail = mkdir (path, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP |
|
|
||||||
S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH );
|
|
||||||
#endif
|
|
||||||
if (fail) {
|
|
||||||
lua_pushnil (L);
|
|
||||||
lua_pushfstring (L, "%s", strerror(errno));
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
lua_pushboolean (L, 1);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Removes a directory.
|
** Removes a directory.
|
||||||
** @param #1 Directory path.
|
** @param #1 Directory path.
|
||||||
*/
|
*/
|
||||||
static int remove_dir (lua_State *L) {
|
static int remove_dir (lua_State *L) {
|
||||||
const char *path = luaL_checkstring (L, 1);
|
const char *path = luaL_checkstring(L, 1);
|
||||||
int fail;
|
return pushresult(L, rmdir(path), NULL);
|
||||||
|
|
||||||
fail = rmdir (path);
|
|
||||||
|
|
||||||
if (fail) {
|
|
||||||
lua_pushnil (L);
|
|
||||||
lua_pushfstring (L, "%s", strerror(errno));
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
lua_pushboolean (L, 1);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Directory iterator
|
** Directory iterator
|
||||||
*/
|
*/
|
||||||
@@ -569,6 +580,7 @@ static int dir_create_meta (lua_State *L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Creates lock metatable.
|
** Creates lock metatable.
|
||||||
*/
|
*/
|
||||||
@@ -639,26 +651,24 @@ static const char *mode2string (mode_t mode) {
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Set access time and modification values for file
|
** Set access time and modification values for a file.
|
||||||
|
** @param #1 File path.
|
||||||
|
** @param #2 Access time in seconds, current time is used if missing.
|
||||||
|
** @param #3 Modification time in seconds, access time is used if missing.
|
||||||
*/
|
*/
|
||||||
static int file_utime (lua_State *L) {
|
static int file_utime (lua_State *L) {
|
||||||
const char *file = luaL_checkstring (L, 1);
|
const char *file = luaL_checkstring(L, 1);
|
||||||
struct utimbuf utb, *buf;
|
struct utimbuf utb, *buf;
|
||||||
|
|
||||||
if (lua_gettop (L) == 1) /* set to current date/time */
|
if (lua_gettop (L) == 1) /* set to current date/time */
|
||||||
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)) {
|
|
||||||
lua_pushnil (L);
|
return pushresult(L, utime(file, buf), NULL);
|
||||||
lua_pushfstring (L, "%s", strerror (errno));
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
lua_pushboolean (L, 1);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -668,60 +678,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 +733,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 +746,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,40 +791,40 @@ 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);
|
||||||
lua_pushfstring (L, "cannot obtain information from file `%s'", file);
|
lua_pushfstring(L, "cannot obtain information from file '%s': %s", file, strerror(errno));
|
||||||
return 2;
|
lua_pushinteger(L, errno);
|
||||||
|
return 3;
|
||||||
}
|
}
|
||||||
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 '%s'", member);
|
||||||
/* push member value and return */
|
}
|
||||||
members[v].push (L, &info);
|
/* creates a table if none is given, removes extra arguments */
|
||||||
return 1;
|
lua_settop(L, 2);
|
||||||
} else if (!lua_istable (L, 2))
|
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);
|
||||||
@@ -839,11 +843,58 @@ static int file_info (lua_State *L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Push the symlink target to the top of the stack.
|
||||||
|
** Assumes the file name is at position 1 of the stack.
|
||||||
|
** Returns 1 if successful (with the target on top of the stack),
|
||||||
|
** 0 on failure (with stack unchanged, and errno set).
|
||||||
|
*/
|
||||||
|
static int push_link_target(lua_State *L) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
errno = ENOSYS;
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
const char *file = luaL_checkstring(L, 1);
|
||||||
|
char *target = NULL;
|
||||||
|
int tsize, size = 256; /* size = initial buffer capacity */
|
||||||
|
while (1) {
|
||||||
|
target = realloc(target, size);
|
||||||
|
if (!target) /* failed to allocate */
|
||||||
|
return 0;
|
||||||
|
tsize = readlink(file, target, size);
|
||||||
|
if (tsize < 0) { /* a readlink() error occurred */
|
||||||
|
free(target);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (tsize < size)
|
||||||
|
break;
|
||||||
|
/* possibly truncated readlink() result, double size and retry */
|
||||||
|
size *= 2;
|
||||||
|
}
|
||||||
|
target[tsize] = '\0';
|
||||||
|
lua_pushlstring(L, target, tsize);
|
||||||
|
free(target);
|
||||||
|
return 1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Get symbolic link information using lstat.
|
** Get symbolic link information using lstat.
|
||||||
*/
|
*/
|
||||||
static int link_info (lua_State *L) {
|
static int link_info (lua_State *L) {
|
||||||
return _file_info_ (L, LSTAT_FUNC);
|
int ret;
|
||||||
|
if (lua_isstring (L, 2) && (strcmp(lua_tostring(L, 2), "target") == 0)) {
|
||||||
|
int ok = push_link_target(L);
|
||||||
|
return ok ? 1 : pusherror(L, "could not obtain link target");
|
||||||
|
}
|
||||||
|
ret = _file_info_ (L, LSTAT_FUNC);
|
||||||
|
if (ret == 1 && lua_type(L, -1) == LUA_TTABLE) {
|
||||||
|
int ok = push_link_target(L);
|
||||||
|
if (ok) {
|
||||||
|
lua_setfield(L, -2, "target");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -851,15 +902,12 @@ static int link_info (lua_State *L) {
|
|||||||
** Assumes the table is on top of the stack.
|
** Assumes the table is on top of the stack.
|
||||||
*/
|
*/
|
||||||
static void set_info (lua_State *L) {
|
static void set_info (lua_State *L) {
|
||||||
lua_pushliteral (L, "_COPYRIGHT");
|
lua_pushliteral(L, "Copyright (C) 2003-2016 Kepler Project");
|
||||||
lua_pushliteral (L, "Copyright (C) 2003-2012 Kepler Project");
|
lua_setfield(L, -2, "_COPYRIGHT");
|
||||||
lua_settable (L, -3);
|
lua_pushliteral(L, "LuaFileSystem is a Lua library developed to complement the set of functions related to file systems offered by the standard Lua distribution");
|
||||||
lua_pushliteral (L, "_DESCRIPTION");
|
lua_setfield(L, -2, "_DESCRIPTION");
|
||||||
lua_pushliteral (L, "LuaFileSystem is a Lua library developed to complement the set of functions related to file systems offered by the standard Lua distribution");
|
lua_pushliteral(L, "LuaFileSystem " LFS_VERSION);
|
||||||
lua_settable (L, -3);
|
lua_setfield(L, -2, "_VERSION");
|
||||||
lua_pushliteral (L, "_VERSION");
|
|
||||||
lua_pushliteral (L, "LuaFileSystem "LFS_VERSION);
|
|
||||||
lua_settable (L, -3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -880,7 +928,7 @@ static const struct luaL_Reg fslib[] = {
|
|||||||
{NULL, NULL},
|
{NULL, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
int luaopen_lfs (lua_State *L) {
|
LFS_EXPORT int luaopen_lfs (lua_State *L) {
|
||||||
dir_create_meta (L);
|
dir_create_meta (L);
|
||||||
lock_create_meta (L);
|
lock_create_meta (L);
|
||||||
luaL_newlib (L, fslib);
|
luaL_newlib (L, fslib);
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
LIBRARY lfs.dll
|
LIBRARY lfs.dll
|
||||||
DESCRIPTION "LuaFileSystem"
|
VERSION 1.6
|
||||||
VERSION 1.5.0
|
|
||||||
EXPORTS
|
EXPORTS
|
||||||
luaopen_lfs
|
luaopen_lfs
|
||||||
|
|||||||
31
src/lfs.h
31
src/lfs.h
@@ -1,17 +1,34 @@
|
|||||||
/*
|
/*
|
||||||
** LuaFileSystem
|
** LuaFileSystem
|
||||||
** Copyright Kepler Project 2003 (http://www.keplerproject.org/luafilesystem)
|
** Copyright Kepler Project 2003 - 2016 (http://keplerproject.github.io/luafilesystem)
|
||||||
**
|
|
||||||
** $Id: lfs.h,v 1.5 2008/02/19 20:08:23 mascarenhas Exp $
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Define 'chdir' for systems that do not implement it */
|
/* Define 'chdir' for systems that do not implement it */
|
||||||
#ifdef NO_CHDIR
|
#ifdef NO_CHDIR
|
||||||
#define chdir(p) (-1)
|
#define chdir(p) (-1)
|
||||||
#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
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define chdir(p) (_chdir(p))
|
||||||
|
#define getcwd(d, s) (_getcwd(d, s))
|
||||||
|
#define rmdir(p) (_rmdir(p))
|
||||||
|
#define LFS_EXPORT __declspec (dllexport)
|
||||||
|
#ifndef fileno
|
||||||
|
#define fileno(f) (_fileno(f))
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define LFS_EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
int luaopen_lfs (lua_State *L);
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
LFS_EXPORT int luaopen_lfs (lua_State *L);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -91,6 +91,8 @@ io.flush()
|
|||||||
if lfs.link (tmpfile, "_a_link_for_test_", true) then
|
if lfs.link (tmpfile, "_a_link_for_test_", true) then
|
||||||
assert (lfs.attributes"_a_link_for_test_".mode == "file")
|
assert (lfs.attributes"_a_link_for_test_".mode == "file")
|
||||||
assert (lfs.symlinkattributes"_a_link_for_test_".mode == "link")
|
assert (lfs.symlinkattributes"_a_link_for_test_".mode == "link")
|
||||||
|
assert (lfs.symlinkattributes"_a_link_for_test_".target == tmpfile)
|
||||||
|
assert (lfs.symlinkattributes("_a_link_for_test_", "target") == tmpfile)
|
||||||
assert (lfs.link (tmpfile, "_a_hard_link_for_test_"))
|
assert (lfs.link (tmpfile, "_a_hard_link_for_test_"))
|
||||||
assert (lfs.attributes (tmpfile, "nlink") == 2)
|
assert (lfs.attributes (tmpfile, "nlink") == 2)
|
||||||
assert (os.remove"_a_link_for_test_")
|
assert (os.remove"_a_link_for_test_")
|
||||||
@@ -107,6 +109,9 @@ assert(result) -- on non-Windows platforms, mode is always returned as "binary"
|
|||||||
result, mode = lfs.setmode(f, "text")
|
result, mode = lfs.setmode(f, "text")
|
||||||
assert(result and mode == "binary")
|
assert(result and mode == "binary")
|
||||||
f:close()
|
f:close()
|
||||||
|
local ok, err = pcall(lfs.setmode, f, "binary")
|
||||||
|
assert(not ok, "could setmode on closed file")
|
||||||
|
assert(err:find("closed file"), "bad error message for setmode on closed file")
|
||||||
|
|
||||||
io.write(".")
|
io.write(".")
|
||||||
io.flush()
|
io.flush()
|
||||||
@@ -120,6 +125,24 @@ 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
|
||||||
|
|
||||||
|
-- Check that lfs.attributes accepts a table as second argument
|
||||||
|
local attr2 = {}
|
||||||
|
lfs.attributes(tmpfile, attr2)
|
||||||
|
for key, value in pairs(attr2) do
|
||||||
|
assert (value == lfs.attributes (tmpfile, key),
|
||||||
|
"lfs.attributes values with table argument not consistent")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Check that extra arguments are ignored
|
||||||
|
lfs.attributes(tmpfile, attr2, nil)
|
||||||
|
|
||||||
-- 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")
|
||||||
@@ -129,7 +152,10 @@ io.write(".")
|
|||||||
io.flush()
|
io.flush()
|
||||||
|
|
||||||
-- Trying to get attributes of a non-existent file
|
-- Trying to get attributes of a non-existent file
|
||||||
assert (lfs.attributes ("this couldn't be an actual file") == nil, "could get attributes of a non-existent file")
|
local attr_ok, err, errno = lfs.attributes("this couldn't be an actual file")
|
||||||
|
assert(attr_ok == nil, "could get attributes of a non-existent file")
|
||||||
|
assert(type(err) == "string", "failed lfs.attributes did not return an error message")
|
||||||
|
assert(type(errno) == "number", "failed lfs.attributes did not return error code")
|
||||||
assert (type(lfs.attributes (upper)) == "table", "couldn't get attributes of upper directory")
|
assert (type(lfs.attributes (upper)) == "table", "couldn't get attributes of upper directory")
|
||||||
|
|
||||||
io.write(".")
|
io.write(".")
|
||||||
|
|||||||
Reference in New Issue
Block a user