Cleanup from the fallout of porting file locking to win32

This commit is contained in:
Mark Vejvoda 2010-04-13 17:14:42 +00:00
parent 0657004da2
commit 8b90f2bf64
1 changed files with 12 additions and 1 deletions

View File

@ -71,7 +71,11 @@ void SystemFlags::Close() {
SystemFlags::fileStream.close(); SystemFlags::fileStream.close();
} }
if(SystemFlags::lockfilename != "") { if(SystemFlags::lockfilename != "") {
#ifndef WIN32
close(SystemFlags::lockFile);
#else
_close(SystemFlags::lockFile); _close(SystemFlags::lockFile);
#endif
remove(SystemFlags::lockfilename.c_str()); remove(SystemFlags::lockfilename.c_str());
SystemFlags::lockfilename = ""; SystemFlags::lockfilename = "";
} }
@ -107,16 +111,23 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
lockfile += lock_file_name; lockfile += lock_file_name;
SystemFlags::lockfilename = lockfile; SystemFlags::lockfilename = lockfile;
#ifndef WIN32
//SystemFlags::lockFile = open(lockfile.c_str(), O_WRONLY | O_CREAT | O_EXCL, S_IRUSR|S_IWUSR); //SystemFlags::lockFile = open(lockfile.c_str(), O_WRONLY | O_CREAT | O_EXCL, S_IRUSR|S_IWUSR);
SystemFlags::lockFile = open(lockfile.c_str(), O_WRONLY | O_CREAT, S_IREAD | S_IWRITE);
#else
SystemFlags::lockFile = _open(lockfile.c_str(), O_WRONLY | O_CREAT, S_IREAD | S_IWRITE); SystemFlags::lockFile = _open(lockfile.c_str(), O_WRONLY | O_CREAT, S_IREAD | S_IWRITE);
#endif
if (SystemFlags::lockFile < 0 || acquire_file_lock(SystemFlags::lockFile) == false) { if (SystemFlags::lockFile < 0 || acquire_file_lock(SystemFlags::lockFile) == false) {
string newlockfile = lockfile; string newlockfile = lockfile;
int idx = 1; int idx = 1;
for(idx = 1; idx <= 100; ++idx) { for(idx = 1; idx <= 100; ++idx) {
newlockfile = lockfile + intToStr(idx); newlockfile = lockfile + intToStr(idx);
//SystemFlags::lockFile = open(newlockfile.c_str(), O_WRONLY | O_CREAT | O_EXCL, S_IRUSR|S_IWUSR); //SystemFlags::lockFile = open(newlockfile.c_str(), O_WRONLY | O_CREAT | O_EXCL, S_IRUSR|S_IWUSR);
#ifndef WIN32
SystemFlags::lockFile = open(newlockfile.c_str(), O_WRONLY | O_CREAT, S_IREAD | S_IWRITE);
#else
SystemFlags::lockFile = _open(newlockfile.c_str(), O_WRONLY | O_CREAT, S_IREAD | S_IWRITE); SystemFlags::lockFile = _open(newlockfile.c_str(), O_WRONLY | O_CREAT, S_IREAD | S_IWRITE);
#endif
if(SystemFlags::lockFile >= 0 && acquire_file_lock(SystemFlags::lockFile) == true) { if(SystemFlags::lockFile >= 0 && acquire_file_lock(SystemFlags::lockFile) == true) {
break; break;
} }