Files

86 lines
2.0 KiB
Go
Raw Permalink Normal View History

2023-06-01 18:11:37 +01:00
package readervfs
import (
"github.com/ncruces/go-sqlite3"
2024-01-03 00:54:30 +00:00
"github.com/ncruces/go-sqlite3/util/ioutil"
2023-06-01 18:11:37 +01:00
"github.com/ncruces/go-sqlite3/vfs"
)
type readerVFS struct{}
func (readerVFS) Open(name string, flags vfs.OpenFlag) (vfs.File, vfs.OpenFlag, error) {
2025-12-29 20:45:44 +00:00
// Temporary files use the default VFS.
if name == "" || flags&vfs.OPEN_DELETEONCLOSE != 0 {
2025-12-19 16:37:47 +00:00
return vfs.Find("").Open(name, flags)
2025-08-05 14:15:21 +01:00
}
// Refuse to open all other file types.
2023-06-01 18:11:37 +01:00
if flags&vfs.OPEN_MAIN_DB == 0 {
return nil, flags, sqlite3.CANTOPEN
}
readerMtx.RLock()
defer readerMtx.RUnlock()
if ra, ok := readerDBs[name]; ok {
return readerFile{ra}, flags | vfs.OPEN_READONLY, nil
}
return nil, flags, sqlite3.CANTOPEN
}
func (readerVFS) Delete(name string, dirSync bool) error {
2025-08-05 14:15:21 +01:00
// notest // IOCAP_IMMUTABLE
2023-06-01 18:11:37 +01:00
return sqlite3.IOERR_DELETE
}
func (readerVFS) Access(name string, flag vfs.AccessFlag) (bool, error) {
2025-08-05 14:15:21 +01:00
// notest // IOCAP_IMMUTABLE
2025-07-22 22:41:29 +01:00
return false, sqlite3.IOERR_ACCESS
2023-06-01 18:11:37 +01:00
}
func (readerVFS) FullPathname(name string) (string, error) {
return name, nil
}
2024-01-03 00:54:30 +00:00
type readerFile struct{ ioutil.SizeReaderAt }
2023-06-01 18:11:37 +01:00
2023-06-12 13:04:37 +01:00
func (readerFile) Close() error {
2023-06-01 18:11:37 +01:00
return nil
}
func (readerFile) WriteAt(b []byte, off int64) (n int, err error) {
2025-08-05 14:15:21 +01:00
// notest // IOCAP_IMMUTABLE
2025-07-22 22:41:29 +01:00
return 0, sqlite3.IOERR_WRITE
2023-06-01 18:11:37 +01:00
}
func (readerFile) Truncate(size int64) error {
2025-08-05 14:15:21 +01:00
// notest // IOCAP_IMMUTABLE
2025-07-22 22:41:29 +01:00
return sqlite3.IOERR_TRUNCATE
2023-06-01 18:11:37 +01:00
}
func (readerFile) Sync(flag vfs.SyncFlag) error {
2025-08-05 14:15:21 +01:00
// notest // IOCAP_IMMUTABLE
2025-07-22 22:41:29 +01:00
return sqlite3.IOERR_FSYNC
2023-06-01 18:11:37 +01:00
}
func (readerFile) Lock(lock vfs.LockLevel) error {
2025-08-05 14:15:21 +01:00
// notest // IOCAP_IMMUTABLE
2025-07-22 22:41:29 +01:00
return sqlite3.IOERR_LOCK
2023-06-01 18:11:37 +01:00
}
func (readerFile) Unlock(lock vfs.LockLevel) error {
2025-08-05 14:15:21 +01:00
// notest // IOCAP_IMMUTABLE
2025-07-22 22:41:29 +01:00
return sqlite3.IOERR_UNLOCK
2023-06-01 18:11:37 +01:00
}
func (readerFile) CheckReservedLock() (bool, error) {
2025-08-05 14:15:21 +01:00
// notest // IOCAP_IMMUTABLE
2025-07-22 22:41:29 +01:00
return false, sqlite3.IOERR_CHECKRESERVEDLOCK
2023-06-01 18:11:37 +01:00
}
func (readerFile) SectorSize() int {
2025-08-05 14:15:21 +01:00
// notest // IOCAP_IMMUTABLE
2023-06-01 18:11:37 +01:00
return 0
}
func (readerFile) DeviceCharacteristics() vfs.DeviceCharacteristic {
2024-11-26 11:39:31 +00:00
return vfs.IOCAP_IMMUTABLE | vfs.IOCAP_SUBPAGE_READ
2023-06-01 18:11:37 +01:00
}