diff --git a/embed/README.md b/embed/README.md index 725313d..191867c 100644 --- a/embed/README.md +++ b/embed/README.md @@ -1,6 +1,6 @@ # Embeddable WASM build of SQLite -This folder includes an embeddable WASM build of SQLite 3.43.0 for use with +This folder includes an embeddable WASM build of SQLite 3.43.1 for use with [`github.com/ncruces/go-sqlite3`](https://pkg.go.dev/github.com/ncruces/go-sqlite3). The following optional features are compiled in: diff --git a/vfs/file.go b/vfs/file.go index 84d1368..160a949 100644 --- a/vfs/file.go +++ b/vfs/file.go @@ -9,7 +9,6 @@ import ( "path/filepath" "runtime" "syscall" - "time" ) type vfsOS struct{} @@ -124,11 +123,10 @@ func (vfsOS) OpenParams(name string, flags OpenFlag, params url.Values) (File, O type vfsFile struct { *os.File - lockTimeout time.Duration - lock LockLevel - psow bool - syncDir bool - readOnly bool + lock LockLevel + psow bool + syncDir bool + readOnly bool } var ( diff --git a/vfs/lock.go b/vfs/lock.go index d7aa446..a2b9651 100644 --- a/vfs/lock.go +++ b/vfs/lock.go @@ -4,7 +4,6 @@ package vfs import ( "os" - "time" "github.com/ncruces/go-sqlite3/internal/util" ) @@ -50,7 +49,7 @@ func (f *vfsFile) Lock(lock LockLevel) error { if f.lock != LOCK_NONE { panic(util.AssertErr()) } - if rc := osGetSharedLock(f.File, f.lockTimeout); rc != _OK { + if rc := osGetSharedLock(f.File); rc != _OK { return rc } f.lock = LOCK_SHARED @@ -61,7 +60,7 @@ func (f *vfsFile) Lock(lock LockLevel) error { if f.lock != LOCK_SHARED { panic(util.AssertErr()) } - if rc := osGetReservedLock(f.File, f.lockTimeout); rc != _OK { + if rc := osGetReservedLock(f.File); rc != _OK { return rc } f.lock = LOCK_RESERVED @@ -79,7 +78,7 @@ func (f *vfsFile) Lock(lock LockLevel) error { } f.lock = LOCK_PENDING } - if rc := osGetExclusiveLock(f.File, f.lockTimeout); rc != _OK { + if rc := osGetExclusiveLock(f.File); rc != _OK { return rc } f.lock = LOCK_EXCLUSIVE @@ -136,9 +135,9 @@ func (f *vfsFile) CheckReservedLock() (bool, error) { return osCheckReservedLock(f.File) } -func osGetReservedLock(file *os.File, timeout time.Duration) _ErrorCode { +func osGetReservedLock(file *os.File) _ErrorCode { // Acquire the RESERVED lock. - return osWriteLock(file, _RESERVED_BYTE, 1, timeout) + return osWriteLock(file, _RESERVED_BYTE, 1, 0) } func osGetPendingLock(file *os.File) _ErrorCode { diff --git a/vfs/lock_test.go b/vfs/lock_test.go index a94079c..db1c4df 100644 --- a/vfs/lock_test.go +++ b/vfs/lock_test.go @@ -203,9 +203,4 @@ func Test_vfsLock(t *testing.T) { if got := util.ReadUint32(mod, pOutput); got != uint32(LOCK_SHARED) { t.Error("invalid lock state", got) } - - rc = vfsFileControl(ctx, mod, pFile1, _FCNTL_LOCK_TIMEOUT, 1) - if rc != _OK { - t.Fatal("returned", rc) - } } diff --git a/vfs/os_unix.go b/vfs/os_unix.go index cba8ef5..3a0c9c4 100644 --- a/vfs/os_unix.go +++ b/vfs/os_unix.go @@ -33,22 +33,18 @@ func osSetMode(file *os.File, modeof string) error { return nil } -func osGetSharedLock(file *os.File, timeout time.Duration) _ErrorCode { +func osGetSharedLock(file *os.File) _ErrorCode { // Test the PENDING lock before acquiring a new SHARED lock. if pending, _ := osCheckLock(file, _PENDING_BYTE, 1); pending { return _BUSY } // Acquire the SHARED lock. - return osReadLock(file, _SHARED_FIRST, _SHARED_SIZE, timeout) + return osReadLock(file, _SHARED_FIRST, _SHARED_SIZE, 0) } -func osGetExclusiveLock(file *os.File, timeout time.Duration) _ErrorCode { - if timeout == 0 { - timeout = time.Millisecond - } - +func osGetExclusiveLock(file *os.File) _ErrorCode { // Acquire the EXCLUSIVE lock. - return osWriteLock(file, _SHARED_FIRST, _SHARED_SIZE, timeout) + return osWriteLock(file, _SHARED_FIRST, _SHARED_SIZE, time.Millisecond) } func osDowngradeLock(file *os.File, state LockLevel) _ErrorCode { diff --git a/vfs/os_windows.go b/vfs/os_windows.go index 6e1f9e0..0b2d8f2 100644 --- a/vfs/os_windows.go +++ b/vfs/os_windows.go @@ -25,9 +25,9 @@ func osOpenFile(name string, flag int, perm fs.FileMode) (*os.File, error) { return os.NewFile(uintptr(r), name), nil } -func osGetSharedLock(file *os.File, timeout time.Duration) _ErrorCode { +func osGetSharedLock(file *os.File) _ErrorCode { // Acquire the PENDING lock temporarily before acquiring a new SHARED lock. - rc := osReadLock(file, _PENDING_BYTE, 1, timeout) + rc := osReadLock(file, _PENDING_BYTE, 1, 0) if rc == _OK { // Acquire the SHARED lock. @@ -39,16 +39,12 @@ func osGetSharedLock(file *os.File, timeout time.Duration) _ErrorCode { return rc } -func osGetExclusiveLock(file *os.File, timeout time.Duration) _ErrorCode { - if timeout == 0 { - timeout = time.Millisecond - } - +func osGetExclusiveLock(file *os.File) _ErrorCode { // Release the SHARED lock. osUnlock(file, _SHARED_FIRST, _SHARED_SIZE) // Acquire the EXCLUSIVE lock. - rc := osWriteLock(file, _SHARED_FIRST, _SHARED_SIZE, timeout) + rc := osWriteLock(file, _SHARED_FIRST, _SHARED_SIZE, time.Millisecond) if rc != _OK { // Reacquire the SHARED lock. diff --git a/vfs/vfs.go b/vfs/vfs.go index e9a1d31..d945b67 100644 --- a/vfs/vfs.go +++ b/vfs/vfs.go @@ -264,14 +264,6 @@ func vfsFileControl(ctx context.Context, mod api.Module, pFile uint32, op _Fcntl return _OK } - case _FCNTL_LOCK_TIMEOUT: - if file, ok := file.(*vfsFile); ok { - millis := file.lockTimeout.Milliseconds() - file.lockTimeout = time.Duration(util.ReadUint32(mod, pArg)) * time.Millisecond - util.WriteUint32(mod, pArg, uint32(millis)) - return _OK - } - case _FCNTL_POWERSAFE_OVERWRITE: if file, ok := file.(FilePowersafeOverwrite); ok { switch util.ReadUint32(mod, pArg) { @@ -339,10 +331,8 @@ func vfsFileControl(ctx context.Context, mod api.Module, pFile uint32, op _Fcntl } // Consider also implementing these opcodes (in use by SQLite): - // _FCNTL_PDB // _FCNTL_BUSYHANDLER // _FCNTL_CHUNK_SIZE - // _FCNTL_OVERWRITE // _FCNTL_PRAGMA // _FCNTL_SYNC return _NOTFOUND