diff options
Diffstat (limited to 'vendor/github.com/ncruces/go-sqlite3/vfs')
10 files changed, 68 insertions, 36 deletions
diff --git a/vendor/github.com/ncruces/go-sqlite3/vfs/file.go b/vendor/github.com/ncruces/go-sqlite3/vfs/file.go index 93a2f7ece..176b2507b 100644 --- a/vendor/github.com/ncruces/go-sqlite3/vfs/file.go +++ b/vendor/github.com/ncruces/go-sqlite3/vfs/file.go @@ -69,6 +69,7 @@ func (vfsOS) Access(name string, flags AccessFlag) (bool, error) { } func (vfsOS) Open(name string, flags OpenFlag) (File, OpenFlag, error) { + // notest // OpenFilename is called instead return nil, 0, _CANTOPEN } diff --git a/vendor/github.com/ncruces/go-sqlite3/vfs/filename.go b/vendor/github.com/ncruces/go-sqlite3/vfs/filename.go index e23575bbb..51d0b8dda 100644 --- a/vendor/github.com/ncruces/go-sqlite3/vfs/filename.go +++ b/vendor/github.com/ncruces/go-sqlite3/vfs/filename.go @@ -20,8 +20,8 @@ type Filename struct { stack [2]uint64 } -// OpenFilename is an internal API users should not call directly. -func OpenFilename(ctx context.Context, mod api.Module, id uint32, flags OpenFlag) *Filename { +// GetFilename is an internal API users should not call directly. +func GetFilename(ctx context.Context, mod api.Module, id uint32, flags OpenFlag) *Filename { if id == 0 { return nil } @@ -66,6 +66,10 @@ func (n *Filename) path(method string) string { if n == nil || n.zPath == 0 { return "" } + if n.flags&(OPEN_MAIN_DB|OPEN_MAIN_JOURNAL|OPEN_WAL) == 0 { + return "" + } + n.stack[0] = uint64(n.zPath) fn := n.mod.ExportedFunction(method) if err := fn.CallWithStack(n.ctx, n.stack[:]); err != nil { diff --git a/vendor/github.com/ncruces/go-sqlite3/vfs/memdb/api.go b/vendor/github.com/ncruces/go-sqlite3/vfs/memdb/api.go index 5a2b84c71..843488966 100644 --- a/vendor/github.com/ncruces/go-sqlite3/vfs/memdb/api.go +++ b/vendor/github.com/ncruces/go-sqlite3/vfs/memdb/api.go @@ -10,7 +10,10 @@ package memdb import ( + "fmt" + "net/url" "sync" + "testing" "github.com/ncruces/go-sqlite3/vfs" ) @@ -39,8 +42,9 @@ func Create(name string, data []byte) { size: int64(len(data)), } - // Convert data from WAL to rollback journal. - if len(data) >= 20 && data[18] == 2 && data[19] == 2 { + // Convert data from WAL/2 to rollback journal. + if len(data) >= 20 && (data[18] == 2 && data[19] == 2 || + data[18] == 3 && data[19] == 3) { data[18] = 1 data[19] = 1 } @@ -66,3 +70,30 @@ func Delete(name string) { defer memoryMtx.Unlock() delete(memoryDBs, name) } + +// TestDB creates an empty shared memory database for the test to use. +// The database is automatically deleted when the test and all its subtests complete. +// Each subsequent call to TestDB returns a unique database. +func TestDB(tb testing.TB, params ...url.Values) string { + tb.Helper() + + name := fmt.Sprintf("%s_%p", tb.Name(), tb) + tb.Cleanup(func() { Delete(name) }) + Create(name, nil) + + p := url.Values{"vfs": {"memdb"}} + for _, v := range params { + for k, v := range v { + for _, v := range v { + p.Add(k, v) + } + } + } + + return (&url.URL{ + Scheme: "file", + OmitHost: true, + Path: "/" + name, + RawQuery: p.Encode(), + }).String() +} diff --git a/vendor/github.com/ncruces/go-sqlite3/vfs/memdb/memdb.go b/vendor/github.com/ncruces/go-sqlite3/vfs/memdb/memdb.go index f21335d8e..d313b45d1 100644 --- a/vendor/github.com/ncruces/go-sqlite3/vfs/memdb/memdb.go +++ b/vendor/github.com/ncruces/go-sqlite3/vfs/memdb/memdb.go @@ -30,6 +30,7 @@ func (memVFS) Open(name string, flags vfs.OpenFlag) (vfs.File, vfs.OpenFlag, err vfs.OPEN_TEMP_DB | vfs.OPEN_TEMP_JOURNAL if flags&types == 0 { + // notest // OPEN_MEMORY return nil, flags, sqlite3.CANTOPEN } @@ -82,7 +83,7 @@ type memDB struct { size int64 // +checklocks:lockMtx - shared int + shared int32 // +checklocks:lockMtx reserved bool // +checklocks:lockMtx @@ -136,7 +137,7 @@ func (m *memFile) ReadAt(b []byte, off int64) (n int, err error) { } n = copy(b, (*m.data[base])[rest:have]) if n < len(b) { - // Assume reads are page aligned. + // notest // assume reads are page aligned return 0, io.ErrNoProgress } return n, nil @@ -153,7 +154,7 @@ func (m *memFile) WriteAt(b []byte, off int64) (n int, err error) { } n = copy((*m.data[base])[rest:], b) if n < len(b) { - // Assume writes are page aligned. + // notest // assume writes are page aligned return n, io.ErrShortWrite } if size := off + int64(len(b)); size > m.size { @@ -226,9 +227,6 @@ func (m *memFile) Lock(lock vfs.LockLevel) error { case vfs.LOCK_EXCLUSIVE: if m.lock < vfs.LOCK_PENDING { - if m.pending { - return sqlite3.BUSY - } m.lock = vfs.LOCK_PENDING m.pending = true } @@ -269,6 +267,7 @@ func (m *memFile) Unlock(lock vfs.LockLevel) error { } func (m *memFile) CheckReservedLock() (bool, error) { + // notest // OPEN_MEMORY if m.lock >= vfs.LOCK_RESERVED { return true, nil } @@ -278,6 +277,7 @@ func (m *memFile) CheckReservedLock() (bool, error) { } func (m *memFile) SectorSize() int { + // notest // IOCAP_POWERSAFE_OVERWRITE return sectorSize } diff --git a/vendor/github.com/ncruces/go-sqlite3/vfs/os_darwin.go b/vendor/github.com/ncruces/go-sqlite3/vfs/os_darwin.go index 8bfe96bb1..c8d84dc36 100644 --- a/vendor/github.com/ncruces/go-sqlite3/vfs/os_darwin.go +++ b/vendor/github.com/ncruces/go-sqlite3/vfs/os_darwin.go @@ -5,6 +5,7 @@ package vfs import ( "io" "os" + "runtime" "time" "golang.org/x/sys/unix" @@ -68,7 +69,7 @@ func osUnlock(file *os.File, start, len int64) _ErrorCode { } func osLock(file *os.File, typ int16, start, len int64, timeout time.Duration, def _ErrorCode) _ErrorCode { - lock := flocktimeout_t{fl: unix.Flock_t{ + lock := &flocktimeout_t{fl: unix.Flock_t{ Type: typ, Start: start, Len: len, @@ -82,6 +83,7 @@ func osLock(file *os.File, typ int16, start, len int64, timeout time.Duration, d default: lock.timeout = unix.NsecToTimespec(int64(timeout / time.Nanosecond)) err = unix.FcntlFlock(file.Fd(), _F_OFD_SETLKWTIMEOUT, &lock.fl) + runtime.KeepAlive(lock) } return osLockErrorCode(err, def) } diff --git a/vendor/github.com/ncruces/go-sqlite3/vfs/os_f2fs_linux.go b/vendor/github.com/ncruces/go-sqlite3/vfs/os_f2fs_linux.go index a9f0e333c..487f0c7d9 100644 --- a/vendor/github.com/ncruces/go-sqlite3/vfs/os_f2fs_linux.go +++ b/vendor/github.com/ncruces/go-sqlite3/vfs/os_f2fs_linux.go @@ -16,6 +16,8 @@ const ( _F2FS_FEATURE_ATOMIC_WRITE = 4 ) +// notest + func osBatchAtomic(file *os.File) bool { flags, err := unix.IoctlGetInt(int(file.Fd()), _F2FS_IOC_GET_FEATURES) return err == nil && flags&_F2FS_FEATURE_ATOMIC_WRITE != 0 diff --git a/vendor/github.com/ncruces/go-sqlite3/vfs/os_unix_lock.go b/vendor/github.com/ncruces/go-sqlite3/vfs/os_unix_lock.go index 85a7b0fc0..ffa1f5e19 100644 --- a/vendor/github.com/ncruces/go-sqlite3/vfs/os_unix_lock.go +++ b/vendor/github.com/ncruces/go-sqlite3/vfs/os_unix_lock.go @@ -50,6 +50,7 @@ func osDowngradeLock(file *os.File, state LockLevel) _ErrorCode { // indicates that the other process is not following the locking // protocol. If this happens, return IOERR_RDLOCK. Returning // BUSY would confuse the upper layer. + // notest return _IOERR_RDLOCK } } @@ -98,6 +99,7 @@ func osLockErrorCode(err error, def _ErrorCode) _ErrorCode { case unix.EPERM: return _PERM } + // notest // usually EWOULDBLOCK == EAGAIN if errno == unix.EWOULDBLOCK && unix.EWOULDBLOCK != unix.EAGAIN { return _BUSY } diff --git a/vendor/github.com/ncruces/go-sqlite3/vfs/os_windows.go b/vendor/github.com/ncruces/go-sqlite3/vfs/os_windows.go index 83b952b16..7425b5581 100644 --- a/vendor/github.com/ncruces/go-sqlite3/vfs/os_windows.go +++ b/vendor/github.com/ncruces/go-sqlite3/vfs/os_windows.go @@ -66,6 +66,7 @@ func osDowngradeLock(file *os.File, state LockLevel) _ErrorCode { if rc := osReadLock(file, _SHARED_FIRST, _SHARED_SIZE, 0); rc != _OK { // This should never happen. // We should always be able to reacquire the read lock. + // notest return _IOERR_RDLOCK } } diff --git a/vendor/github.com/ncruces/go-sqlite3/vfs/shm_bsd.go b/vendor/github.com/ncruces/go-sqlite3/vfs/shm_bsd.go index ffeb3e0a0..65674ed2e 100644 --- a/vendor/github.com/ncruces/go-sqlite3/vfs/shm_bsd.go +++ b/vendor/github.com/ncruces/go-sqlite3/vfs/shm_bsd.go @@ -72,28 +72,28 @@ func (s *vfsShm) Close() error { return nil } - // Unlock everything. - s.shmLock(0, _SHM_NLOCK, _SHM_UNLOCK) - vfsShmFilesMtx.Lock() defer vfsShmFilesMtx.Unlock() + // Unlock everything. + s.shmLock(0, _SHM_NLOCK, _SHM_UNLOCK) + // Decrease reference count. if s.vfsShmFile.refs > 1 { s.vfsShmFile.refs-- s.vfsShmFile = nil return nil } + + err := s.File.Close() for i, g := range vfsShmFiles { if g == s.vfsShmFile { vfsShmFiles[i] = nil - break + s.vfsShmFile = nil + return err } } - - err := s.File.Close() - s.vfsShmFile = nil - return err + panic(util.AssertErr()) } func (s *vfsShm) shmOpen() (rc _ErrorCode) { @@ -234,6 +234,8 @@ func (s *vfsShm) shmLock(offset, n int32, flags _ShmFlag) _ErrorCode { s.vfsShmFile.lock[i] = -1 s.lock[i] = true } + default: + panic(util.AssertErr()) } return _OK @@ -256,5 +258,4 @@ func (s *vfsShm) shmUnmap(delete bool) { os.Remove(s.path) } s.Close() - s.vfsShmFile = nil } diff --git a/vendor/github.com/ncruces/go-sqlite3/vfs/vfs.go b/vendor/github.com/ncruces/go-sqlite3/vfs/vfs.go index d624aa78c..983f28560 100644 --- a/vendor/github.com/ncruces/go-sqlite3/vfs/vfs.go +++ b/vendor/github.com/ncruces/go-sqlite3/vfs/vfs.go @@ -132,26 +132,20 @@ func vfsAccess(ctx context.Context, mod api.Module, pVfs, zPath uint32, flags Ac func vfsOpen(ctx context.Context, mod api.Module, pVfs, zPath, pFile uint32, flags OpenFlag, pOutFlags, pOutVFS uint32) _ErrorCode { vfs := vfsGet(mod, pVfs) - - var path string - if zPath != 0 { - path = util.ReadString(mod, zPath, _MAX_PATHNAME) - } + name := GetFilename(ctx, mod, zPath, flags) var file File var err error if ffs, ok := vfs.(VFSFilename); ok { - name := OpenFilename(ctx, mod, zPath, flags) file, flags, err = ffs.OpenFilename(name, flags) } else { - file, flags, err = vfs.Open(path, flags) + file, flags, err = vfs.Open(name.String(), flags) } if err != nil { return vfsErrorCode(err, _CANTOPEN) } if file, ok := file.(FilePowersafeOverwrite); ok { - name := OpenFilename(ctx, mod, zPath, flags) if b, ok := util.ParseBool(name.URIParameter("psow")); ok { file.SetPowersafeOverwrite(b) } @@ -169,10 +163,7 @@ func vfsOpen(ctx context.Context, mod api.Module, pVfs, zPath, pFile uint32, fla func vfsClose(ctx context.Context, mod api.Module, pFile uint32) _ErrorCode { err := vfsFileClose(ctx, mod, pFile) - if err != nil { - return vfsErrorCode(err, _IOERR_CLOSE) - } - return _OK + return vfsErrorCode(err, _IOERR_CLOSE) } func vfsRead(ctx context.Context, mod api.Module, pFile, zBuf uint32, iAmt int32, iOfst int64) _ErrorCode { @@ -195,10 +186,7 @@ func vfsWrite(ctx context.Context, mod api.Module, pFile, zBuf uint32, iAmt int3 buf := util.View(mod, zBuf, uint64(iAmt)) _, err := file.WriteAt(buf, iOfst) - if err != nil { - return vfsErrorCode(err, _IOERR_WRITE) - } - return _OK + return vfsErrorCode(err, _IOERR_WRITE) } func vfsTruncate(ctx context.Context, mod api.Module, pFile uint32, nByte int64) _ErrorCode { |