diff --git a/db_mmap_test.go b/db_mmap_test.go new file mode 100644 index 0000000..41ab462 --- /dev/null +++ b/db_mmap_test.go @@ -0,0 +1,10 @@ +//go:build !plan9 +// +build !plan9 + +package pogreb + +import ( + "github.com/akrylysov/pogreb/fs" +) + +var testFileSystems = []fs.FileSystem{fs.Mem, fs.OSMMap, fs.OS} diff --git a/db_rpc_test.go b/db_rpc_test.go new file mode 100644 index 0000000..b0761f0 --- /dev/null +++ b/db_rpc_test.go @@ -0,0 +1,10 @@ +//go:build plan9 +// +build plan9 + +package pogreb + +import ( + "github.com/akrylysov/pogreb/fs" +) + +var testFileSystems = []fs.FileSystem{fs.Mem, fs.OS} diff --git a/db_test.go b/db_test.go index e25b145..bd7a2d3 100644 --- a/db_test.go +++ b/db_test.go @@ -32,7 +32,7 @@ func TestMain(m *testing.M) { SetLogger(log.New(io.Discard, "", 0)) } // Run tests against all file systems. - for _, fsys := range []fs.FileSystem{fs.Mem, fs.OSMMap, fs.OS} { + for _, fsys := range testFileSystems { var tmpDir string if fsys == fs.Mem { testFS = fsys diff --git a/fs/os_mmap.go b/fs/os_mmap.go index 3fbe40b..deabf1d 100644 --- a/fs/os_mmap.go +++ b/fs/os_mmap.go @@ -1,3 +1,5 @@ +//go:build !plan9 + package fs import ( @@ -161,3 +163,8 @@ func (f *osMMapFile) Close() error { } return f.File.Close() } + +// Return a default FileSystem for this platform. +func DefaultFileSystem() FileSystem { + return OSMMap +} diff --git a/fs/os_mmap_unix.go b/fs/os_mmap_unix.go index bb2e295..ea6fc7a 100644 --- a/fs/os_mmap_unix.go +++ b/fs/os_mmap_unix.go @@ -1,4 +1,5 @@ -//go:build !windows +//go:build !(plan9 || windows) +// +build !plan9,!windows package fs diff --git a/fs/os_mmap_windows.go b/fs/os_mmap_windows.go index af8434b..ff7ccd7 100644 --- a/fs/os_mmap_windows.go +++ b/fs/os_mmap_windows.go @@ -1,4 +1,5 @@ //go:build windows +// +build windows package fs diff --git a/fs/os_plan9.go b/fs/os_plan9.go new file mode 100644 index 0000000..8819013 --- /dev/null +++ b/fs/os_plan9.go @@ -0,0 +1,26 @@ +//go:build plan9 +// +build plan9 + +package fs + +import ( + "os" + "syscall" +) + +func createLockFile(name string, perm os.FileMode) (LockFile, bool, error) { + acquiredExisting := false + if _, err := os.Stat(name); err == nil { + acquiredExisting = true + } + f, err := os.OpenFile(name, os.O_RDWR|os.O_CREATE, syscall.DMEXCL|perm) + if err != nil { + return nil, false, err + } + return &osLockFile{f, name}, acquiredExisting, nil +} + +// Return a default FileSystem for this platform. +func DefaultFileSystem() FileSystem { + return OS +} diff --git a/fs/os_unix.go b/fs/os_unix.go index bcc6230..f410c3f 100644 --- a/fs/os_unix.go +++ b/fs/os_unix.go @@ -1,4 +1,5 @@ -//go:build !windows +//go:build !(plan9 || windows) +// +build !plan9,!windows package fs diff --git a/fs/os_windows.go b/fs/os_windows.go index 097a23f..c5ca330 100644 --- a/fs/os_windows.go +++ b/fs/os_windows.go @@ -1,4 +1,5 @@ //go:build windows +// +build windows package fs diff --git a/options.go b/options.go index 78e7138..cee92e8 100644 --- a/options.go +++ b/options.go @@ -26,7 +26,7 @@ type Options struct { // // Default: fs.OSMMap. FileSystem fs.FileSystem - rootFS fs.FileSystem + rootFS fs.FileSystem maxSegmentSize uint32 compactionMinSegmentSize uint32 @@ -39,7 +39,7 @@ func (src *Options) copyWithDefaults(path string) *Options { opts = *src } if opts.FileSystem == nil { - opts.FileSystem = fs.OSMMap + opts.FileSystem = fs.DefaultFileSystem() } opts.rootFS = opts.FileSystem opts.FileSystem = fs.Sub(opts.FileSystem, path)