From e007e9b060074cc7b79e8c205e2c960c1e48d8e4 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Wed, 8 Mar 2023 20:10:46 +0000 Subject: [PATCH] Windows fixes. --- embed/build.sh | 2 +- {sqlite3 => embed}/exports.txt | 0 embed/init.go | 3 +++ vfs.go | 2 ++ vfs_windows.go | 15 ++++++++++++--- 5 files changed, 18 insertions(+), 4 deletions(-) rename {sqlite3 => embed}/exports.txt (100%) diff --git a/embed/build.sh b/embed/build.sh index 363881a..73ed0d0 100755 --- a/embed/build.sh +++ b/embed/build.sh @@ -13,4 +13,4 @@ zig cc --target=wasm32-wasi -flto -g0 -Os \ -mbulk-memory -mreference-types \ -mnontrapping-fptoint -msign-ext \ -D_HAVE_SQLITE_CONFIG_H \ - $(awk '{print "-Wl,--export="$0}' ../sqlite3/exports.txt) \ No newline at end of file + $(awk '{print "-Wl,--export="$0}' exports.txt) \ No newline at end of file diff --git a/sqlite3/exports.txt b/embed/exports.txt similarity index 100% rename from sqlite3/exports.txt rename to embed/exports.txt diff --git a/embed/init.go b/embed/init.go index 9ad7c9a..3ad54f8 100644 --- a/embed/init.go +++ b/embed/init.go @@ -5,6 +5,9 @@ // // import _ "github.com/ncruces/go-sqlite3/embed" // +// The following optional features are compiled in: +// math functions, JSON, FTS3/4/5, R*Tree, GeoPoly. +// // You can obtain this build of SQLite from: // https://github.com/ncruces/go-sqlite3/tree/main/embed package embed diff --git a/vfs.go b/vfs.go index fa24827..fd37d2d 100644 --- a/vfs.go +++ b/vfs.go @@ -169,6 +169,8 @@ func vfsDelete(ctx context.Context, mod api.Module, pVfs, zPath, syncDir uint32) return _OK } if err != nil { + // TODO: fix windows.ERROR_SHARING_VIOLATION + // https://github.com/golang/go/issues/32088 return uint32(IOERR_DELETE) } if runtime.GOOS != "windows" && syncDir != 0 { diff --git a/vfs_windows.go b/vfs_windows.go index 2c7c260..6148d8b 100644 --- a/vfs_windows.go +++ b/vfs_windows.go @@ -63,6 +63,9 @@ func (vfsOSMethods) ReleaseLock(file *os.File, state vfsLockState) xErrorCode { func (vfsOSMethods) unlock(file *os.File, start, len uint32) xErrorCode { err := windows.UnlockFileEx(windows.Handle(file.Fd()), 0, len, 0, &windows.Overlapped{Offset: start}) + if err == windows.ERROR_NOT_LOCKED { + return _OK + } if err != nil { return IOERR_UNLOCK } @@ -95,8 +98,14 @@ func (vfsOSMethods) lockErrorCode(err error, def xErrorCode) xErrorCode { if err == nil { return _OK } - if errno, _ := err.(syscall.Errno); errno == windows.ERROR_INVALID_HANDLE { - return def + if errno, ok := err.(syscall.Errno); ok { + // https://devblogs.microsoft.com/oldnewthing/20140905-00/?p=63 + switch errno { + case + windows.ERROR_LOCK_VIOLATION, + windows.ERROR_IO_PENDING: + return xErrorCode(BUSY) + } } - return xErrorCode(BUSY) + return def }