mirror of
https://github.com/lunarmodules/luafilesystem.git
synced 2026-07-22 11:03:07 +00:00
Adding function symlinkatributes. Updating version to 1.3.0
This commit is contained in:
4
Makefile
4
Makefile
@@ -1,7 +1,7 @@
|
||||
# $Id: Makefile,v 1.29 2006/12/04 15:28:53 mascarenhas Exp $
|
||||
# $Id: Makefile,v 1.30 2007/06/07 01:28:08 tomas Exp $
|
||||
|
||||
T= lfs
|
||||
V= 1.2.1
|
||||
V= 1.3.0
|
||||
CONFIG= ./config
|
||||
|
||||
include $(CONFIG)
|
||||
|
||||
@@ -71,7 +71,7 @@ the underlying directory structure and file attributes.</p>
|
||||
|
||||
<h2><a name="status"></a>Status</h2>
|
||||
|
||||
<p>Current version is 1.2.1. It was developed for Lua 5.1.</p>
|
||||
<p>Current version is 1.3.0. It was developed for Lua 5.1.</p>
|
||||
|
||||
<h2><a name="download"></a>Download</h2>
|
||||
|
||||
@@ -84,6 +84,14 @@ version of LuaFileSystem can be found at the same LuaForge page.</p>
|
||||
<h2><a name="history"></a>History</h2>
|
||||
|
||||
<dl class="history">
|
||||
<dt><strong>Version 1.3.0</strong> [?/Jun/2007]</dt>
|
||||
<dd>
|
||||
<ul>
|
||||
<li>added function
|
||||
<a href="manual.html#symlinkattributes"><code>lfs.symlinkattributes</code></a></li>
|
||||
</ul>
|
||||
</dd>
|
||||
|
||||
<dt><strong>Version 1.2.1</strong> [08/May/2007]</dt>
|
||||
<dd>
|
||||
<ul>
|
||||
@@ -139,7 +147,7 @@ Comments are welcome!</p>
|
||||
<div id="about">
|
||||
<p><a href="http://validator.w3.org/check?uri=referer">
|
||||
<img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
|
||||
<p><small>$Id: index.html,v 1.35 2007/05/08 19:23:12 carregal Exp $</small></p>
|
||||
<p><small>$Id: index.html,v 1.36 2007/06/07 01:28:08 tomas Exp $</small></p>
|
||||
</div> <!-- id="about" -->
|
||||
|
||||
</div> <!-- id="container" -->
|
||||
|
||||
@@ -153,6 +153,12 @@ LuaFileSystem offers the following functions:
|
||||
<dt><strong><code>blksize</code></strong></dt>
|
||||
<dd>optimal file system I/O blocksize; (Unix only)</dd>
|
||||
</dl>
|
||||
This function uses <code>stat</code> internally thus if the given
|
||||
<code>filepath</code> is a symbolic link, it is followed (if it points to
|
||||
another link the chain is followed recursively) and the information
|
||||
is about the file it refers to.
|
||||
To obtain information about the link itself, see function
|
||||
<a href="#symlinkattributes">lfs.symlinkattributes</a>.
|
||||
</dd>
|
||||
|
||||
<dt><a name="chdir"></a><strong><code>lfs.chdir (path)</code></strong></dt>
|
||||
@@ -197,6 +203,11 @@ LuaFileSystem offers the following functions:
|
||||
Returns <code>true</code> if the operation was successful;
|
||||
in case of error, it returns <code>nil</code> plus an error string.</dd>
|
||||
|
||||
<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
|
||||
it obtains information about the link itself (not the file it refers to).
|
||||
</dd>
|
||||
|
||||
<dt><a name="touch"></a><strong><code>lfs.touch (filepath [, atime [, mtime]])</code></strong></dt>
|
||||
<dd>Set access and modification times of a file. This function is
|
||||
a bind to <code>utime</code> function. The first argument is the
|
||||
@@ -228,7 +239,7 @@ LuaFileSystem offers the following functions:
|
||||
<div id="about">
|
||||
<p><a href="http://validator.w3.org/check?uri=referer">
|
||||
<img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
|
||||
<p><small>$Id: manual.html,v 1.35 2007/05/17 23:08:56 carregal Exp $</small></p>
|
||||
<p><small>$Id: manual.html,v 1.36 2007/06/07 01:28:08 tomas Exp $</small></p>
|
||||
</div> <!-- id="about" -->
|
||||
|
||||
</div> <!-- id="container" -->
|
||||
|
||||
30
src/lfs.c
30
src/lfs.c
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
** LuaFileSystem
|
||||
** Copyright Kepler Project 2004-2006 (http://www.keplerproject.org/luafilesystem)
|
||||
** Copyright Kepler Project 2004-2007 (http://www.keplerproject.org/luafilesystem)
|
||||
**
|
||||
** File system manipulation library.
|
||||
** This library offers these functions:
|
||||
@@ -11,10 +11,11 @@
|
||||
** lfs.lock (fh, mode)
|
||||
** lfs.mkdir (path)
|
||||
** lfs.rmdir (path)
|
||||
** lfs.symlinkattributes (filepath [, attributename]) -- thanks to Sam Roberts
|
||||
** lfs.touch (filepath [, atime [, mtime]])
|
||||
** lfs.unlock (fh)
|
||||
**
|
||||
** $Id: lfs.c,v 1.37 2007/05/15 12:58:35 tomas Exp $
|
||||
** $Id: lfs.c,v 1.38 2007/06/07 01:28:08 tomas Exp $
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
@@ -511,14 +512,14 @@ struct _stat_members members[] = {
|
||||
};
|
||||
|
||||
/*
|
||||
** Get file information
|
||||
** Get file or symbolic link information
|
||||
*/
|
||||
static int file_info (lua_State *L) {
|
||||
static int _file_info_ (lua_State *L, int (*st)(const char*, struct stat*)) {
|
||||
int i;
|
||||
struct stat info;
|
||||
const char *file = luaL_checkstring (L, 1);
|
||||
|
||||
if (stat(file, &info)) {
|
||||
if (st(file, &info)) {
|
||||
lua_pushnil (L);
|
||||
lua_pushfstring (L, "cannot obtain information from file `%s'", file);
|
||||
return 2;
|
||||
@@ -550,6 +551,22 @@ static int file_info (lua_State *L) {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Get file information using stat.
|
||||
*/
|
||||
static int file_info (lua_State *L) {
|
||||
return _file_info_ (L, stat);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Get symbolic link information using lstat.
|
||||
*/
|
||||
static int link_info (lua_State *L) {
|
||||
return _file_info_ (L, lstat);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Assumes the table is on top of the stack.
|
||||
*/
|
||||
@@ -561,7 +578,7 @@ static void set_info (lua_State *L) {
|
||||
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_settable (L, -3);
|
||||
lua_pushliteral (L, "_VERSION");
|
||||
lua_pushliteral (L, "LuaFileSystem 1.2.1");
|
||||
lua_pushliteral (L, "LuaFileSystem 1.3.0");
|
||||
lua_settable (L, -3);
|
||||
}
|
||||
|
||||
@@ -574,6 +591,7 @@ static const struct luaL_reg fslib[] = {
|
||||
{"lock", file_lock},
|
||||
{"mkdir", make_dir},
|
||||
{"rmdir", remove_dir},
|
||||
{"symlinkattributes", link_info},
|
||||
{"touch", file_utime},
|
||||
{"unlock", file_unlock},
|
||||
{NULL, NULL},
|
||||
|
||||
@@ -69,6 +69,12 @@ local new_att = assert (lfs.attributes (tmpfile))
|
||||
assert (new_att.access == testdate2, "could not set access time")
|
||||
assert (new_att.modification == testdate1, "could not set modification time")
|
||||
|
||||
-- Checking symbolic link information
|
||||
assert (os.execute ("ln -s "..tmpfile.." _a_link_for_test_"))
|
||||
assert (lfs.attributes"_a_link_for_test_".mode == "file")
|
||||
assert (lfs.symlinkattributes"_a_link_for_test_".mode == "link")
|
||||
assert (os.remove"_a_link_for_test_")
|
||||
|
||||
-- Restore access time to current value
|
||||
assert (lfs.touch (tmpfile, attrib.access, attrib.modification))
|
||||
new_att = assert (lfs.attributes (tmpfile))
|
||||
|
||||
Reference in New Issue
Block a user