Corrected the last commit's problem with file locking, which is that

there was no distinction between a locked file and a new cell
(initial state) before writing to disk.  This prevents any new cell
from being saved!  Also:  Revised the behavior of the "select short"
search, but this still has issues with long run-times on complex
layouts, so this is an ongoing effort.
This commit is contained in:
Tim Edwards
2022-01-03 16:00:31 -05:00
parent 1bb4cb92ea
commit 1fceef6acd
4 changed files with 168 additions and 150 deletions
+12 -7
View File
@@ -1205,7 +1205,7 @@ DBCellRead(cellDef, name, ignoreTech, dereference, errptr)
#ifdef FILE_LOCKS
/* Close files that were locked by another user */
if (cellDef->cd_fd == -1) fclose(f);
if (cellDef->cd_fd == -2) fclose(f);
#else
/* When using fcntl() to enforce file locks, we can't */
/* close the file descriptor without losing the lock. */
@@ -1261,10 +1261,10 @@ dbReadOpen(cellDef, name, setFileName, errptr)
bool is_locked;
#ifdef FILE_LOCKS
if (cellDef->cd_fd != -1)
if (cellDef->cd_fd >= 0)
{
close(cellDef->cd_fd);
cellDef->cd_fd = -1;
cellDef->cd_fd = -1; /* Set to initial state */
}
#endif
@@ -1385,7 +1385,9 @@ dbReadOpen(cellDef, name, setFileName, errptr)
else
cellDef->cd_flags &= ~CDNOEDIT;
if (is_locked == FALSE)
if (is_locked == TRUE)
cellDef->cd_fd = -2; /* Indicates locked file */
else
cellDef->cd_fd = fileno(f);
cellDef->cd_flags &= ~CDNOTFOUND;
}
@@ -3235,7 +3237,7 @@ DBCellWrite(cellDef, fileName)
}
#ifdef FILE_LOCKS
if (cellDef->cd_fd == -1)
if (cellDef->cd_fd == -2)
{
TxPrintf("File %s is locked by another user and "
"cannot be written\n", realname);
@@ -3307,10 +3309,10 @@ DBCellWrite(cellDef, fileName)
}
#ifdef FILE_LOCKS
if (cellDef->cd_fd != -1)
if (cellDef->cd_fd >= 0)
{
close(cellDef->cd_fd);
cellDef->cd_fd = -1;
cellDef->cd_fd = -1; /* Set to initial state */
}
#endif
@@ -3430,8 +3432,11 @@ DBCellWrite(cellDef, fileName)
}
#ifdef FILE_LOCKS
cellDef->cd_fd = -1;
if (FileLocking && (is_locked == FALSE))
cellDef->cd_fd = fd;
else if (FileLocking && (is_locked == TRUE))
cellDef->cd_fd = -2;
else
#endif
fclose(realf);