diff options
| author | tomas <tomas> | 2004-11-01 15:27:13 +0000 |
|---|---|---|
| committer | tomas <tomas> | 2004-11-01 15:27:13 +0000 |
| commit | 4d5d1e75fa5950b39873b46b3ab21fd39028e4f1 (patch) | |
| tree | e2597be505a2ddaa87479c4549f8a51bf93a6ff1 | |
| parent | 3219f4618df9fa4f4a54d2d3bcc116380bafa217 (diff) | |
| download | luafilesystem-4d5d1e75fa5950b39873b46b3ab21fd39028e4f1.tar.gz luafilesystem-4d5d1e75fa5950b39873b46b3ab21fd39028e4f1.tar.bz2 luafilesystem-4d5d1e75fa5950b39873b46b3ab21fd39028e4f1.zip | |
Pequenas correcoes nos valores de retorno de algumas funcoes.
Acrescimo do arquivo de testes.
| -rw-r--r-- | doc/us/manual.html | 10 | ||||
| -rw-r--r-- | src/lfs.c | 15 | ||||
| -rw-r--r-- | teste.lua | 26 | ||||
| -rw-r--r-- | tests/test.lua | 40 |
4 files changed, 57 insertions, 34 deletions
diff --git a/doc/us/manual.html b/doc/us/manual.html index ae20fcc..5ca685d 100644 --- a/doc/us/manual.html +++ b/doc/us/manual.html | |||
| @@ -62,6 +62,8 @@ LuaFileSystem offers the following functions: | |||
| 62 | <li> <b><tt>lfs.chdir (path)</tt></b> <br> | 62 | <li> <b><tt>lfs.chdir (path)</tt></b> <br> |
| 63 | Changes the current | 63 | Changes the current |
| 64 | working directory to the given <tt>path</tt>. | 64 | working directory to the given <tt>path</tt>. |
| 65 | Returns <tt>true</tt> in case of success or <tt>nil</tt> plus an error | ||
| 66 | string. | ||
| 65 | 67 | ||
| 66 | <a name="getcwd"></a> | 68 | <a name="getcwd"></a> |
| 67 | <li> <b><tt>lfs.currentdir ()</tt></b> <br> | 69 | <li> <b><tt>lfs.currentdir ()</tt></b> <br> |
| @@ -83,14 +85,14 @@ LuaFileSystem offers the following functions: | |||
| 83 | The optional arguments <code>start</code> and <code>length</code> can be | 85 | The optional arguments <code>start</code> and <code>length</code> can be |
| 84 | used to specify a starting point and its length; | 86 | used to specify a starting point and its length; |
| 85 | both should be numbers. | 87 | both should be numbers. |
| 86 | This function returns a boolean indicating if the operation was successful; | 88 | Returns a boolean indicating if the operation was successful; |
| 87 | in case of error, it returns <code>false</code> plus a string describing the | 89 | in case of error, it returns <code>false</code> plus an error string. |
| 88 | error. | ||
| 89 | 90 | ||
| 90 | <a name="mkdir"></a> | 91 | <a name="mkdir"></a> |
| 91 | <li> <b><tt>lfs.mkdir (dirname)</tt></b> <br> | 92 | <li> <b><tt>lfs.mkdir (dirname)</tt></b> <br> |
| 92 | Creates a new directory. | 93 | Creates a new directory. |
| 93 | The argument is the name of the new directory. | 94 | The argument is the name of the new directory. |
| 95 | Returns a boolean indicating whether the operation succeeds or not. | ||
| 94 | 96 | ||
| 95 | <a name="unlock"></a> | 97 | <a name="unlock"></a> |
| 96 | <li> <b><tt>lfs.unlock (filehandle[, start[, length]])</tt></b> <br> | 98 | <li> <b><tt>lfs.unlock (filehandle[, start[, length]])</tt></b> <br> |
| @@ -165,7 +167,7 @@ attrdir (".") | |||
| 165 | 167 | ||
| 166 | <hr> | 168 | <hr> |
| 167 | <small> | 169 | <small> |
| 168 | $Id: manual.html,v 1.4 2004/10/29 16:15:59 tomas Exp $ | 170 | $Id: manual.html,v 1.5 2004/11/01 15:27:13 tomas Exp $ |
| 169 | </small> | 171 | </small> |
| 170 | 172 | ||
| 171 | </body> | 173 | </body> |
| @@ -9,7 +9,7 @@ | |||
| 9 | ** lfs.lock (fh, mode) | 9 | ** lfs.lock (fh, mode) |
| 10 | ** lfs.unlock (fh) | 10 | ** lfs.unlock (fh) |
| 11 | ** | 11 | ** |
| 12 | ** $Id: lfs.c,v 1.7 2004/11/01 08:57:56 tomas Exp $ | 12 | ** $Id: lfs.c,v 1.8 2004/11/01 15:27:13 tomas Exp $ |
| 13 | */ | 13 | */ |
| 14 | 14 | ||
| 15 | #include <errno.h> | 15 | #include <errno.h> |
| @@ -64,10 +64,15 @@ typedef struct dir_data { | |||
| 64 | */ | 64 | */ |
| 65 | static int change_dir (lua_State *L) { | 65 | static int change_dir (lua_State *L) { |
| 66 | const char *path = luaL_checkstring(L, 1); | 66 | const char *path = luaL_checkstring(L, 1); |
| 67 | if (chdir(path)) | 67 | if (chdir(path)) { |
| 68 | luaL_error(L,"Unable to change working directory to '%s'\n%s\n", | 68 | lua_pushnil (L); |
| 69 | lua_pushfstring (L,"Unable to change working directory to '%s'\n%s\n", | ||
| 69 | path, chdir_error); | 70 | path, chdir_error); |
| 70 | return 0; | 71 | return 2; |
| 72 | } else { | ||
| 73 | lua_pushboolean (L, 1); | ||
| 74 | return 1; | ||
| 75 | } | ||
| 71 | } | 76 | } |
| 72 | 77 | ||
| 73 | /* | 78 | /* |
| @@ -234,6 +239,8 @@ static int make_dir (lua_State *L) { | |||
| 234 | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH ); | 239 | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH ); |
| 235 | #endif | 240 | #endif |
| 236 | lua_pushboolean (L, !fail); | 241 | lua_pushboolean (L, !fail); |
| 242 | if (fail) | ||
| 243 | lua_pushfstring (L, "%s", strerror(errno)); | ||
| 237 | umask (oldmask); | 244 | umask (oldmask); |
| 238 | return 1; | 245 | return 1; |
| 239 | } | 246 | } |
diff --git a/teste.lua b/teste.lua deleted file mode 100644 index 556cab0..0000000 --- a/teste.lua +++ /dev/null | |||
| @@ -1,26 +0,0 @@ | |||
| 1 | #!/usr/local/bin/lua -i | ||
| 2 | |||
| 3 | require"lfs" | ||
| 4 | |||
| 5 | print(lfs.version) | ||
| 6 | |||
| 7 | function p () | ||
| 8 | local fh = assert (io.open ("teste", 'r')) | ||
| 9 | assert (lfs.lock (fh, 'r')) | ||
| 10 | print (fh:read"*a") | ||
| 11 | fh:close () | ||
| 12 | end | ||
| 13 | |||
| 14 | function wr () | ||
| 15 | fh = assert (io.open ("teste", 'w')) | ||
| 16 | assert (lfs.lock (fh, 'w')) | ||
| 17 | end | ||
| 18 | |||
| 19 | function op () | ||
| 20 | fh = assert (io.open ("teste", 'r')) | ||
| 21 | assert (lfs.lock (fh, 'r')) | ||
| 22 | end | ||
| 23 | |||
| 24 | function fw (x) | ||
| 25 | assert (fh:write (x)) | ||
| 26 | end | ||
diff --git a/tests/test.lua b/tests/test.lua new file mode 100644 index 0000000..5703bfb --- /dev/null +++ b/tests/test.lua | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | #!/usr/local/bin/lua | ||
| 2 | |||
| 3 | local tmp = "/tmp" | ||
| 4 | local sep = "/" | ||
| 5 | local upper = ".." | ||
| 6 | |||
| 7 | require"lfs" | ||
| 8 | |||
| 9 | function attrdir (path) | ||
| 10 | for file in lfs.dir(path) do | ||
| 11 | if file ~= "." and file ~= ".." then | ||
| 12 | local f = path..'/'..file | ||
| 13 | print ("\t=> "..f.." <=") | ||
| 14 | local attr = lfs.attributes (f) | ||
| 15 | assert (type(attr) == "table") | ||
| 16 | if attr.mode == "directory" then | ||
| 17 | attrdir (f) | ||
| 18 | else | ||
| 19 | for name, value in pairs(attr) do | ||
| 20 | print (name, value) | ||
| 21 | end | ||
| 22 | end | ||
| 23 | end | ||
| 24 | end | ||
| 25 | end | ||
| 26 | |||
| 27 | -- Checking changing directories | ||
| 28 | local current = assert (lfs.currentdir()) | ||
| 29 | local reldir = string.gsub (current, "^.*%"..sep.."([^"..sep.."])$", "%1") | ||
| 30 | assert (lfs.chdir (upper), "could not change to upper directory") | ||
| 31 | assert (lfs.chdir (reldir), "could not change back to current directory") | ||
| 32 | assert (lfs.currentdir() == current, "error trying to change directories") | ||
| 33 | assert (lfs.chdir ("this couldn't be an actual directory") == false, "could change to a non-existent directory") | ||
| 34 | -- Changing creating and removing directories | ||
| 35 | assert (lfs.mkdir (tmp.."/lfs_tmp_dir"), "could not make a new directory") | ||
| 36 | assert (os.remove (tmp.."/lfs_tmp_dir"), "could not remove new directory") | ||
| 37 | assert (lfs.mkdir (tmp.."/lfs_tmp_dir/lfs_tmp_dir") == false, "could create a directory inside a non-existent one") | ||
| 38 | -- | ||
| 39 | assert (lfs.attributes ("this couldn't be an actual file") == false, "could get attributes of a non-existent file") | ||
| 40 | assert (type(lfs.attributes (upper)) == "table", "couldn't get attributes of upper directory") | ||
