mirror of
https://github.com/lunarmodules/luafilesystem.git
synced 2026-07-24 20:33:06 +00:00
Standardizing execution errors to nil followed by an error message
This commit is contained in:
12
src/lfs.c
12
src/lfs.c
@@ -14,7 +14,7 @@
|
||||
** lfs.touch (filepath [, atime [, mtime]])
|
||||
** lfs.unlock (fh)
|
||||
**
|
||||
** $Id: lfs.c,v 1.31 2006/03/13 00:06:24 tomas Exp $
|
||||
** $Id: lfs.c,v 1.32 2006/03/14 13:39:38 tomas Exp $
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
@@ -182,7 +182,7 @@ static int file_lock (lua_State *L) {
|
||||
lua_pushboolean (L, 1);
|
||||
return 1;
|
||||
} else {
|
||||
lua_pushboolean (L, 0);
|
||||
lua_pushnil (L);
|
||||
lua_pushfstring (L, "%s", strerror(errno));
|
||||
return 2;
|
||||
}
|
||||
@@ -203,7 +203,7 @@ static int file_unlock (lua_State *L) {
|
||||
lua_pushboolean (L, 1);
|
||||
return 1;
|
||||
} else {
|
||||
lua_pushboolean (L, 0);
|
||||
lua_pushnil (L);
|
||||
lua_pushfstring (L, "%s", strerror(errno));
|
||||
return 2;
|
||||
}
|
||||
@@ -221,12 +221,13 @@ static int make_dir (lua_State *L) {
|
||||
fail = mkdir (path, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP |
|
||||
S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH );
|
||||
#endif
|
||||
lua_pushboolean (L, !fail);
|
||||
if (fail) {
|
||||
lua_pushnil (L);
|
||||
lua_pushfstring (L, "%s", strerror(errno));
|
||||
return 2;
|
||||
}
|
||||
umask (oldmask);
|
||||
lua_pushboolean (L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -240,11 +241,12 @@ static int remove_dir (lua_State *L) {
|
||||
|
||||
fail = rmdir (path);
|
||||
|
||||
lua_pushboolean (L, !fail);
|
||||
if (fail) {
|
||||
lua_pushnil (L);
|
||||
lua_pushfstring (L, "%s", strerror(errno));
|
||||
return 2;
|
||||
}
|
||||
lua_pushboolean (L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ assert (new_att.modification == attrib.modification)
|
||||
-- Remove new file and directory
|
||||
assert (os.remove (tmpfile), "could not remove new file")
|
||||
assert (lfs.rmdir (tmpdir), "could not remove new directory")
|
||||
assert (lfs.mkdir (tmpdir..sep.."lfs_tmp_dir") == false, "could create a directory inside a non-existent one")
|
||||
assert (lfs.mkdir (tmpdir..sep.."lfs_tmp_dir") == nil, "could create a directory inside a non-existent one")
|
||||
|
||||
-- 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")
|
||||
|
||||
Reference in New Issue
Block a user