Add trivial link_info support on Windows (using STAT_FUNC).

This commit is contained in:
Reuben Thomas
2011-06-09 14:01:37 +01:00
parent d292b3243f
commit 530c9140c7
3 changed files with 8 additions and 17 deletions

View File

@@ -228,8 +228,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).
This function is not available in Windows so you may want to make sure that On Windows this function does not yet support links, and is identical to
<code>lfs.symlinkattributes</code> exists before using it. <code>lfs.attributes</code>.
</dd> </dd>
<dt><a name="touch"></a><strong><code>lfs.touch (filepath [, atime [, mtime]])</code></strong></dt> <dt><a name="touch"></a><strong><code>lfs.touch (filepath [, atime [, mtime]])</code></strong></dt>

View File

@@ -96,6 +96,7 @@ typedef struct dir_data {
#define STAT_STRUCT struct _stati64 #define STAT_STRUCT struct _stati64
#endif #endif
#define STAT_FUNC _stati64 #define STAT_FUNC _stati64
#define LSTAT_FUNC STAT_FUNC
#else #else
#define _O_TEXT 0 #define _O_TEXT 0
#define _O_BINARY 0 #define _O_BINARY 0
@@ -743,17 +744,9 @@ static int file_info (lua_State *L) {
/* /*
** Get symbolic link information using lstat. ** Get symbolic link information using lstat.
*/ */
#ifndef _WIN32
static int link_info (lua_State *L) { static int link_info (lua_State *L) {
return _file_info_ (L, LSTAT_FUNC); return _file_info_ (L, LSTAT_FUNC);
} }
#else
static int link_info (lua_State *L) {
lua_pushboolean(L, 0);
lua_pushliteral(L, "symlinkattributes not supported on this platform");
return 2;
}
#endif
/* /*

View File

@@ -69,13 +69,11 @@ local new_att = assert (lfs.attributes (tmpfile))
assert (new_att.access == testdate2, "could not set access time") assert (new_att.access == testdate2, "could not set access time")
assert (new_att.modification == testdate1, "could not set modification time") assert (new_att.modification == testdate1, "could not set modification time")
local res, err = lfs.symlinkattributes(tmpfile) -- Checking symbolic link information (does not work in Windows)
if err ~= "symlinkattributes not supported on this platform" then if (os.execute ("ln -s "..tmpfile.." _a_link_for_test_")) then
-- Checking symbolic link information (does not work in Windows) assert (lfs.attributes"_a_link_for_test_".mode == "file")
assert (os.execute ("ln -s "..tmpfile.." _a_link_for_test_")) assert (lfs.symlinkattributes"_a_link_for_test_".mode == "link")
assert (lfs.attributes"_a_link_for_test_".mode == "file") assert (os.remove"_a_link_for_test_")
assert (lfs.symlinkattributes"_a_link_for_test_".mode == "link")
assert (os.remove"_a_link_for_test_")
end end
if lfs.setmode then if lfs.setmode then