From f6ec2b5946cc5dd80d56e162360d54baa35812c5 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 11 Jun 2024 20:03:32 +0000 Subject: Fix a problem with rolling back hot journals using the unix-dotfile VFS. FossilOrigin-Name: 4ae3300b79e03381fd7f1033bb7978bb6367369790f17c3bdacac51e205edaf9 --- src/os_unix.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'src/os_unix.c') diff --git a/src/os_unix.c b/src/os_unix.c index c61b19060..45ba0c001 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -2279,26 +2279,17 @@ static int nolockClose(sqlite3_file *id) { /* ** This routine checks if there is a RESERVED lock held on the specified -** file by this or any other process. If such a lock is held, set *pResOut -** to a non-zero value otherwise *pResOut is set to zero. The return value -** is set to SQLITE_OK unless an I/O error occurs during lock checking. -** -** In dotfile locking, either a lock exists or it does not. So in this -** variation of CheckReservedLock(), *pResOut is set to true if any lock -** is held on the file and false if the file is unlocked. +** file by this or any other process. The caller always holds a SHARED +** lock when it is called. This means that no other connection could +** hold a RESERVED lock, as unix-dotfile uses just a single exclusive lock - +** the presence of the dotfile - for all 4 VFS locks. So this function sets +** (*pResOut) to 0 (no other connection holds RESERVED) and returns SQLITE_OK. */ static int dotlockCheckReservedLock(sqlite3_file *id, int *pResOut) { - int rc = SQLITE_OK; - int reserved = 0; - unixFile *pFile = (unixFile*)id; - SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); - - assert( pFile ); - reserved = osAccess((const char*)pFile->lockingContext, 0)==0; - OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, rc, reserved)); - *pResOut = reserved; - return rc; + assert( ((unixFile*)id)->eFileLock>=SHARED_LOCK ); + *pResOut = 0; + return SQLITE_OK; } /* -- cgit v1.2.3 From 41caf1cdfa71e4c32aa441be900d422ad59676f2 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 11 Jun 2024 20:28:56 +0000 Subject: Handle the case where unix-dotfile is used with URI parameter nolock=1. FossilOrigin-Name: 3925a5b904e159d54455cfc73fe837a9c6ea3a6d60da63afde3242b4d6f67c90 --- src/os_unix.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/os_unix.c') diff --git a/src/os_unix.c b/src/os_unix.c index 45ba0c001..c94c0c111 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -2279,16 +2279,21 @@ static int nolockClose(sqlite3_file *id) { /* ** This routine checks if there is a RESERVED lock held on the specified -** file by this or any other process. The caller always holds a SHARED -** lock when it is called. This means that no other connection could -** hold a RESERVED lock, as unix-dotfile uses just a single exclusive lock - -** the presence of the dotfile - for all 4 VFS locks. So this function sets -** (*pResOut) to 0 (no other connection holds RESERVED) and returns SQLITE_OK. +** file by this or any other process. If the caller holds a SHARED +** or greater lock when it is called, then it is assumed that no other +** client may hold RESERVED. Or, if the caller holds no lock, then it +** is assumed another client holds RESERVED if the lock-file exists. */ static int dotlockCheckReservedLock(sqlite3_file *id, int *pResOut) { + unixFile *pFile = (unixFile*)id; SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; ); - assert( ((unixFile*)id)->eFileLock>=SHARED_LOCK ); - *pResOut = 0; + + if( pFile->eFileLock>=SHARED_LOCK ){ + *pResOut = 0; + }else{ + *pResOut = osAccess((const char*)pFile->lockingContext, 0)==0; + } + OSTRACE(("TEST WR-LOCK %d %d %d (dotlock)\n", pFile->h, 0, *pResOut)); return SQLITE_OK; } -- cgit v1.2.3