diff options
| author | mascarenhas <mascarenhas> | 2009-04-24 22:24:06 +0000 |
|---|---|---|
| committer | mascarenhas <mascarenhas> | 2009-04-24 22:24:06 +0000 |
| commit | c1eff3de6befe526c17da32210887ce38c0cb78f (patch) | |
| tree | 4b926927bd0a83d92205baecc41dd1fce3c68d62 | |
| parent | b80d2baaccae36fbcdfd3f0e5ce41194a25e45e6 (diff) | |
| download | luafilesystem-c1eff3de6befe526c17da32210887ce38c0cb78f.tar.gz luafilesystem-c1eff3de6befe526c17da32210887ce38c0cb78f.tar.bz2 luafilesystem-c1eff3de6befe526c17da32210887ce38c0cb78f.zip | |
fixing lfs.lock_dir on windows to return "File exists" instead of looping, plus
documenting lfs.lock_dir
| -rw-r--r-- | doc/us/manual.html | 12 | ||||
| -rw-r--r-- | src/lfs.c | 13 |
2 files changed, 20 insertions, 5 deletions
diff --git a/doc/us/manual.html b/doc/us/manual.html index 9d53037..ee80703 100644 --- a/doc/us/manual.html +++ b/doc/us/manual.html | |||
| @@ -171,6 +171,16 @@ LuaFileSystem offers the following functions: | |||
| 171 | <code>path</code>.<br /> | 171 | <code>path</code>.<br /> |
| 172 | Returns <code>true</code> in case of success or <code>nil</code> plus an | 172 | Returns <code>true</code> in case of success or <code>nil</code> plus an |
| 173 | error string.</dd> | 173 | error string.</dd> |
| 174 | |||
| 175 | <dt><a name="chdir"></a><strong><code>lfs.lock_dir(path, [seconds_stale])</code></strong></dt> | ||
| 176 | <dd>Creates a lockfile (called lockfile.lfs) in <code>path</code> if it does not | ||
| 177 | exist and returns the lock. If the lock already exists checks it | ||
| 178 | it's stale, using the second parameter (default for the second | ||
| 179 | parameter is <code>INT_MAX</code>, which in practice means the lock will never | ||
| 180 | be stale. To free the the lock call <code>lock:free()</code>. <br/> | ||
| 181 | In case of any errors it returns nil and the error message. In | ||
| 182 | particular, if the lock exists and is not stale it returns the | ||
| 183 | "File exists" message.</dd> | ||
| 174 | 184 | ||
| 175 | <dt><a name="getcwd"></a><strong><code>lfs.currentdir ()</code></strong></dt> | 185 | <dt><a name="getcwd"></a><strong><code>lfs.currentdir ()</code></strong></dt> |
| 176 | <dd>Returns a string with the current working directory or <code>nil</code> | 186 | <dd>Returns a string with the current working directory or <code>nil</code> |
| @@ -251,7 +261,7 @@ LuaFileSystem offers the following functions: | |||
| 251 | 261 | ||
| 252 | <div id="about"> | 262 | <div id="about"> |
| 253 | <p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p> | 263 | <p><a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0!</a></p> |
| 254 | <p><small>$Id: manual.html,v 1.43 2008/05/08 18:45:15 carregal Exp $</small></p> | 264 | <p><small>$Id: manual.html,v 1.44 2009/04/24 22:24:06 mascarenhas Exp $</small></p> |
| 255 | </div> <!-- id="about" --> | 265 | </div> <!-- id="about" --> |
| 256 | 266 | ||
| 257 | </div> <!-- id="container" --> | 267 | </div> <!-- id="container" --> |
| @@ -9,6 +9,7 @@ | |||
| 9 | ** lfs.currentdir () | 9 | ** lfs.currentdir () |
| 10 | ** lfs.dir (path) | 10 | ** lfs.dir (path) |
| 11 | ** lfs.lock (fh, mode) | 11 | ** lfs.lock (fh, mode) |
| 12 | ** lfs.lock_dir (path) | ||
| 12 | ** lfs.mkdir (path) | 13 | ** lfs.mkdir (path) |
| 13 | ** lfs.rmdir (path) | 14 | ** lfs.rmdir (path) |
| 14 | ** lfs.setmode (filepath, mode) | 15 | ** lfs.setmode (filepath, mode) |
| @@ -16,7 +17,7 @@ | |||
| 16 | ** lfs.touch (filepath [, atime [, mtime]]) | 17 | ** lfs.touch (filepath [, atime [, mtime]]) |
| 17 | ** lfs.unlock (fh) | 18 | ** lfs.unlock (fh) |
| 18 | ** | 19 | ** |
| 19 | ** $Id: lfs.c,v 1.58 2009/04/24 22:11:12 mascarenhas Exp $ | 20 | ** $Id: lfs.c,v 1.59 2009/04/24 22:24:07 mascarenhas Exp $ |
| 20 | */ | 21 | */ |
| 21 | 22 | ||
| 22 | #ifndef _WIN32 | 23 | #ifndef _WIN32 |
| @@ -222,11 +223,15 @@ static int lfs_lock_dir(lua_State *L) { | |||
| 222 | lua_pushnil(L); lua_pushstring(L, strerror(errno)); return 2; | 223 | lua_pushnil(L); lua_pushstring(L, strerror(errno)); return 2; |
| 223 | } | 224 | } |
| 224 | strcpy(ln, path); strcat(ln, lockfile); | 225 | strcpy(ln, path); strcat(ln, lockfile); |
| 225 | while((fd = CreateFile(ln, GENERIC_WRITE, 0, NULL, CREATE_NEW, | 226 | if((fd = CreateFile(ln, GENERIC_WRITE, 0, NULL, CREATE_NEW, |
| 226 | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, NULL)) == INVALID_HANDLE_VALUE) { | 227 | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, NULL)) == INVALID_HANDLE_VALUE) { |
| 227 | int en = GetLastError(); | 228 | int en = GetLastError(); |
| 228 | if(en == ERROR_FILE_EXISTS || en == ERROR_SHARING_VIOLATION) continue; | 229 | free(ln); lua_pushnil(L); |
| 229 | free(ln); lua_pushnil(L); lua_pushstring(L, strerror(errno)); return 2; | 230 | if(en == ERROR_FILE_EXISTS || en == ERROR_SHARING_VIOLATION) |
| 231 | lua_pushstring(L, "File exists"); | ||
| 232 | else | ||
| 233 | lua_pushstring(L, strerror(en)); | ||
| 234 | return 2; | ||
| 230 | } | 235 | } |
| 231 | free(ln); | 236 | free(ln); |
| 232 | lock = (lfs_Lock*)lua_newuserdata(L, sizeof(lfs_Lock)); | 237 | lock = (lfs_Lock*)lua_newuserdata(L, sizeof(lfs_Lock)); |
