diff options
| author | tomas <tomas> | 2007-06-07 01:28:08 +0000 |
|---|---|---|
| committer | tomas <tomas> | 2007-06-07 01:28:08 +0000 |
| commit | 57a64a5cfee378f331ae425945a8026bcc668a8b (patch) | |
| tree | 77101c424f96ca8bb594c24e303c86136c60fab9 | |
| parent | 47f40e5705c53425ca0d22662f31c6742c2a5569 (diff) | |
| download | luafilesystem-57a64a5cfee378f331ae425945a8026bcc668a8b.tar.gz luafilesystem-57a64a5cfee378f331ae425945a8026bcc668a8b.tar.bz2 luafilesystem-57a64a5cfee378f331ae425945a8026bcc668a8b.zip | |
Adding function symlinkatributes. Updating version to 1.3.0
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | doc/us/index.html | 12 | ||||
| -rw-r--r-- | doc/us/manual.html | 13 | ||||
| -rw-r--r-- | src/lfs.c | 30 | ||||
| -rw-r--r-- | tests/test.lua | 6 |
5 files changed, 54 insertions, 11 deletions
| @@ -1,7 +1,7 @@ | |||
| 1 | # $Id: Makefile,v 1.29 2006/12/04 15:28:53 mascarenhas Exp $ | 1 | # $Id: Makefile,v 1.30 2007/06/07 01:28:08 tomas Exp $ |
| 2 | 2 | ||
| 3 | T= lfs | 3 | T= lfs |
| 4 | V= 1.2.1 | 4 | V= 1.3.0 |
| 5 | CONFIG= ./config | 5 | CONFIG= ./config |
| 6 | 6 | ||
| 7 | include $(CONFIG) | 7 | include $(CONFIG) |
diff --git a/doc/us/index.html b/doc/us/index.html index c48b19a..f0d78f5 100644 --- a/doc/us/index.html +++ b/doc/us/index.html | |||
| @@ -71,7 +71,7 @@ the underlying directory structure and file attributes.</p> | |||
| 71 | 71 | ||
| 72 | <h2><a name="status"></a>Status</h2> | 72 | <h2><a name="status"></a>Status</h2> |
| 73 | 73 | ||
| 74 | <p>Current version is 1.2.1. It was developed for Lua 5.1.</p> | 74 | <p>Current version is 1.3.0. It was developed for Lua 5.1.</p> |
| 75 | 75 | ||
| 76 | <h2><a name="download"></a>Download</h2> | 76 | <h2><a name="download"></a>Download</h2> |
| 77 | 77 | ||
| @@ -84,6 +84,14 @@ version of LuaFileSystem can be found at the same LuaForge page.</p> | |||
| 84 | <h2><a name="history"></a>History</h2> | 84 | <h2><a name="history"></a>History</h2> |
| 85 | 85 | ||
| 86 | <dl class="history"> | 86 | <dl class="history"> |
| 87 | <dt><strong>Version 1.3.0</strong> [?/Jun/2007]</dt> | ||
| 88 | <dd> | ||
| 89 | <ul> | ||
| 90 | <li>added function | ||
| 91 | <a href="manual.html#symlinkattributes"><code>lfs.symlinkattributes</code></a></li> | ||
| 92 | </ul> | ||
| 93 | </dd> | ||
| 94 | |||
| 87 | <dt><strong>Version 1.2.1</strong> [08/May/2007]</dt> | 95 | <dt><strong>Version 1.2.1</strong> [08/May/2007]</dt> |
| 88 | <dd> | 96 | <dd> |
| 89 | <ul> | 97 | <ul> |
| @@ -139,7 +147,7 @@ Comments are welcome!</p> | |||
| 139 | <div id="about"> | 147 | <div id="about"> |
| 140 | <p><a href="http://validator.w3.org/check?uri=referer"> | 148 | <p><a href="http://validator.w3.org/check?uri=referer"> |
| 141 | <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p> | 149 | <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p> |
| 142 | <p><small>$Id: index.html,v 1.35 2007/05/08 19:23:12 carregal Exp $</small></p> | 150 | <p><small>$Id: index.html,v 1.36 2007/06/07 01:28:08 tomas Exp $</small></p> |
| 143 | </div> <!-- id="about" --> | 151 | </div> <!-- id="about" --> |
| 144 | 152 | ||
| 145 | </div> <!-- id="container" --> | 153 | </div> <!-- id="container" --> |
diff --git a/doc/us/manual.html b/doc/us/manual.html index c7b7a5f..04e490a 100644 --- a/doc/us/manual.html +++ b/doc/us/manual.html | |||
| @@ -153,6 +153,12 @@ LuaFileSystem offers the following functions: | |||
| 153 | <dt><strong><code>blksize</code></strong></dt> | 153 | <dt><strong><code>blksize</code></strong></dt> |
| 154 | <dd>optimal file system I/O blocksize; (Unix only)</dd> | 154 | <dd>optimal file system I/O blocksize; (Unix only)</dd> |
| 155 | </dl> | 155 | </dl> |
| 156 | This function uses <code>stat</code> internally thus if the given | ||
| 157 | <code>filepath</code> is a symbolic link, it is followed (if it points to | ||
| 158 | another link the chain is followed recursively) and the information | ||
| 159 | is about the file it refers to. | ||
| 160 | To obtain information about the link itself, see function | ||
| 161 | <a href="#symlinkattributes">lfs.symlinkattributes</a>. | ||
| 156 | </dd> | 162 | </dd> |
| 157 | 163 | ||
| 158 | <dt><a name="chdir"></a><strong><code>lfs.chdir (path)</code></strong></dt> | 164 | <dt><a name="chdir"></a><strong><code>lfs.chdir (path)</code></strong></dt> |
| @@ -197,6 +203,11 @@ LuaFileSystem offers the following functions: | |||
| 197 | Returns <code>true</code> if the operation was successful; | 203 | Returns <code>true</code> if the operation was successful; |
| 198 | in case of error, it returns <code>nil</code> plus an error string.</dd> | 204 | in case of error, it returns <code>nil</code> plus an error string.</dd> |
| 199 | 205 | ||
| 206 | <dt><a name="symlinkattributes"></a><strong><code>lfs.symlinkattributes (filepath [, aname])</code></strong></dt> | ||
| 207 | <dd>Identical to <a href="#attributes">lfs.attributes</a> except that | ||
| 208 | it obtains information about the link itself (not the file it refers to). | ||
| 209 | </dd> | ||
| 210 | |||
| 200 | <dt><a name="touch"></a><strong><code>lfs.touch (filepath [, atime [, mtime]])</code></strong></dt> | 211 | <dt><a name="touch"></a><strong><code>lfs.touch (filepath [, atime [, mtime]])</code></strong></dt> |
| 201 | <dd>Set access and modification times of a file. This function is | 212 | <dd>Set access and modification times of a file. This function is |
| 202 | a bind to <code>utime</code> function. The first argument is the | 213 | a bind to <code>utime</code> function. The first argument is the |
| @@ -228,7 +239,7 @@ LuaFileSystem offers the following functions: | |||
| 228 | <div id="about"> | 239 | <div id="about"> |
| 229 | <p><a href="http://validator.w3.org/check?uri=referer"> | 240 | <p><a href="http://validator.w3.org/check?uri=referer"> |
| 230 | <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p> | 241 | <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p> |
| 231 | <p><small>$Id: manual.html,v 1.35 2007/05/17 23:08:56 carregal Exp $</small></p> | 242 | <p><small>$Id: manual.html,v 1.36 2007/06/07 01:28:08 tomas Exp $</small></p> |
| 232 | </div> <!-- id="about" --> | 243 | </div> <!-- id="about" --> |
| 233 | 244 | ||
| 234 | </div> <!-- id="container" --> | 245 | </div> <!-- id="container" --> |
| @@ -1,6 +1,6 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** LuaFileSystem | 2 | ** LuaFileSystem |
| 3 | ** Copyright Kepler Project 2004-2006 (http://www.keplerproject.org/luafilesystem) | 3 | ** Copyright Kepler Project 2004-2007 (http://www.keplerproject.org/luafilesystem) |
| 4 | ** | 4 | ** |
| 5 | ** File system manipulation library. | 5 | ** File system manipulation library. |
| 6 | ** This library offers these functions: | 6 | ** This library offers these functions: |
| @@ -11,10 +11,11 @@ | |||
| 11 | ** lfs.lock (fh, mode) | 11 | ** lfs.lock (fh, mode) |
| 12 | ** lfs.mkdir (path) | 12 | ** lfs.mkdir (path) |
| 13 | ** lfs.rmdir (path) | 13 | ** lfs.rmdir (path) |
| 14 | ** lfs.symlinkattributes (filepath [, attributename]) -- thanks to Sam Roberts | ||
| 14 | ** lfs.touch (filepath [, atime [, mtime]]) | 15 | ** lfs.touch (filepath [, atime [, mtime]]) |
| 15 | ** lfs.unlock (fh) | 16 | ** lfs.unlock (fh) |
| 16 | ** | 17 | ** |
| 17 | ** $Id: lfs.c,v 1.37 2007/05/15 12:58:35 tomas Exp $ | 18 | ** $Id: lfs.c,v 1.38 2007/06/07 01:28:08 tomas Exp $ |
| 18 | */ | 19 | */ |
| 19 | 20 | ||
| 20 | #include <errno.h> | 21 | #include <errno.h> |
| @@ -511,14 +512,14 @@ struct _stat_members members[] = { | |||
| 511 | }; | 512 | }; |
| 512 | 513 | ||
| 513 | /* | 514 | /* |
| 514 | ** Get file information | 515 | ** Get file or symbolic link information |
| 515 | */ | 516 | */ |
| 516 | static int file_info (lua_State *L) { | 517 | static int _file_info_ (lua_State *L, int (*st)(const char*, struct stat*)) { |
| 517 | int i; | 518 | int i; |
| 518 | struct stat info; | 519 | struct stat info; |
| 519 | const char *file = luaL_checkstring (L, 1); | 520 | const char *file = luaL_checkstring (L, 1); |
| 520 | 521 | ||
| 521 | if (stat(file, &info)) { | 522 | if (st(file, &info)) { |
| 522 | lua_pushnil (L); | 523 | lua_pushnil (L); |
| 523 | lua_pushfstring (L, "cannot obtain information from file `%s'", file); | 524 | lua_pushfstring (L, "cannot obtain information from file `%s'", file); |
| 524 | return 2; | 525 | return 2; |
| @@ -551,6 +552,22 @@ static int file_info (lua_State *L) { | |||
| 551 | 552 | ||
| 552 | 553 | ||
| 553 | /* | 554 | /* |
| 555 | ** Get file information using stat. | ||
| 556 | */ | ||
| 557 | static int file_info (lua_State *L) { | ||
| 558 | return _file_info_ (L, stat); | ||
| 559 | } | ||
| 560 | |||
| 561 | |||
| 562 | /* | ||
| 563 | ** Get symbolic link information using lstat. | ||
| 564 | */ | ||
| 565 | static int link_info (lua_State *L) { | ||
| 566 | return _file_info_ (L, lstat); | ||
| 567 | } | ||
| 568 | |||
| 569 | |||
| 570 | /* | ||
| 554 | ** Assumes the table is on top of the stack. | 571 | ** Assumes the table is on top of the stack. |
| 555 | */ | 572 | */ |
| 556 | static void set_info (lua_State *L) { | 573 | static void set_info (lua_State *L) { |
| @@ -561,7 +578,7 @@ static void set_info (lua_State *L) { | |||
| 561 | 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"); | 578 | 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"); |
| 562 | lua_settable (L, -3); | 579 | lua_settable (L, -3); |
| 563 | lua_pushliteral (L, "_VERSION"); | 580 | lua_pushliteral (L, "_VERSION"); |
| 564 | lua_pushliteral (L, "LuaFileSystem 1.2.1"); | 581 | lua_pushliteral (L, "LuaFileSystem 1.3.0"); |
| 565 | lua_settable (L, -3); | 582 | lua_settable (L, -3); |
| 566 | } | 583 | } |
| 567 | 584 | ||
| @@ -574,6 +591,7 @@ static const struct luaL_reg fslib[] = { | |||
| 574 | {"lock", file_lock}, | 591 | {"lock", file_lock}, |
| 575 | {"mkdir", make_dir}, | 592 | {"mkdir", make_dir}, |
| 576 | {"rmdir", remove_dir}, | 593 | {"rmdir", remove_dir}, |
| 594 | {"symlinkattributes", link_info}, | ||
| 577 | {"touch", file_utime}, | 595 | {"touch", file_utime}, |
| 578 | {"unlock", file_unlock}, | 596 | {"unlock", file_unlock}, |
| 579 | {NULL, NULL}, | 597 | {NULL, NULL}, |
diff --git a/tests/test.lua b/tests/test.lua index 94338b0..b7479e4 100644 --- a/tests/test.lua +++ b/tests/test.lua | |||
| @@ -69,6 +69,12 @@ local new_att = assert (lfs.attributes (tmpfile)) | |||
| 69 | assert (new_att.access == testdate2, "could not set access time") | 69 | assert (new_att.access == testdate2, "could not set access time") |
| 70 | assert (new_att.modification == testdate1, "could not set modification time") | 70 | assert (new_att.modification == testdate1, "could not set modification time") |
| 71 | 71 | ||
| 72 | -- Checking symbolic link information | ||
| 73 | assert (os.execute ("ln -s "..tmpfile.." _a_link_for_test_")) | ||
| 74 | assert (lfs.attributes"_a_link_for_test_".mode == "file") | ||
| 75 | assert (lfs.symlinkattributes"_a_link_for_test_".mode == "link") | ||
| 76 | assert (os.remove"_a_link_for_test_") | ||
| 77 | |||
| 72 | -- Restore access time to current value | 78 | -- Restore access time to current value |
| 73 | assert (lfs.touch (tmpfile, attrib.access, attrib.modification)) | 79 | assert (lfs.touch (tmpfile, attrib.access, attrib.modification)) |
| 74 | new_att = assert (lfs.attributes (tmpfile)) | 80 | new_att = assert (lfs.attributes (tmpfile)) |
