Files
sqlite3/vfs/registry.go

53 lines
1.0 KiB
Go
Raw Normal View History

2023-06-01 18:11:37 +01:00
package vfs
2023-05-23 14:44:25 +01:00
import "sync"
var (
2023-05-31 12:57:18 +01:00
// +checklocks:vfsRegistryMtx
2023-05-23 14:44:25 +01:00
vfsRegistry map[string]VFS
2023-06-02 03:32:13 +01:00
vfsRegistryMtx sync.RWMutex
2023-05-23 14:44:25 +01:00
)
// Find returns a VFS given its name.
// If there is no match, nil is returned.
2025-12-19 16:37:47 +00:00
// If name is empty or "os", the default VFS is returned.
2023-05-23 14:44:25 +01:00
//
2023-11-09 16:35:45 +00:00
// https://sqlite.org/c3ref/vfs_find.html
2023-05-23 14:44:25 +01:00
func Find(name string) VFS {
2023-06-02 03:32:13 +01:00
if name == "" || name == "os" {
return vfsOS{}
}
2025-12-19 16:37:47 +00:00
return find(name)
}
func find(name string) VFS {
2023-06-02 03:32:13 +01:00
vfsRegistryMtx.RLock()
defer vfsRegistryMtx.RUnlock()
2023-05-23 14:44:25 +01:00
return vfsRegistry[name]
}
// Register registers a VFS.
// Empty and "os" are reserved names.
2023-05-23 14:44:25 +01:00
//
2023-11-09 16:35:45 +00:00
// https://sqlite.org/c3ref/vfs_find.html
2023-05-23 14:44:25 +01:00
func Register(name string, vfs VFS) {
2023-06-02 03:32:13 +01:00
if name == "" || name == "os" {
return
}
2023-05-23 14:44:25 +01:00
vfsRegistryMtx.Lock()
if vfsRegistry == nil {
vfsRegistry = map[string]VFS{}
}
vfsRegistry[name] = vfs
2025-12-19 16:37:47 +00:00
vfsRegistryMtx.Unlock()
2023-05-23 14:44:25 +01:00
}
// Unregister unregisters a VFS.
//
2023-11-09 16:35:45 +00:00
// https://sqlite.org/c3ref/vfs_find.html
2023-05-23 14:44:25 +01:00
func Unregister(name string) {
vfsRegistryMtx.Lock()
delete(vfsRegistry, name)
2025-12-19 16:37:47 +00:00
vfsRegistryMtx.Unlock()
2023-05-23 14:44:25 +01:00
}