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 /src | |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/lfs.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -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)); |