Skip to content

Commit 3f96287

Browse files
author
Endo Renberg
authored
Use a non-mmap backend for Plan9 (#75)
Tested on 9FRONT.
1 parent 59b5287 commit 3f96287

File tree

10 files changed

+62
-5
lines changed

10 files changed

+62
-5
lines changed

db_mmap_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//go:build !plan9
2+
// +build !plan9
3+
4+
package pogreb
5+
6+
import (
7+
"github.com/akrylysov/pogreb/fs"
8+
)
9+
10+
var testFileSystems = []fs.FileSystem{fs.Mem, fs.OSMMap, fs.OS}

db_rpc_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//go:build plan9
2+
// +build plan9
3+
4+
package pogreb
5+
6+
import (
7+
"github.com/akrylysov/pogreb/fs"
8+
)
9+
10+
var testFileSystems = []fs.FileSystem{fs.Mem, fs.OS}

db_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestMain(m *testing.M) {
3232
SetLogger(log.New(io.Discard, "", 0))
3333
}
3434
// Run tests against all file systems.
35-
for _, fsys := range []fs.FileSystem{fs.Mem, fs.OSMMap, fs.OS} {
35+
for _, fsys := range testFileSystems {
3636
var tmpDir string
3737
if fsys == fs.Mem {
3838
testFS = fsys

fs/os_mmap.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !plan9
2+
13
package fs
24

35
import (
@@ -161,3 +163,8 @@ func (f *osMMapFile) Close() error {
161163
}
162164
return f.File.Close()
163165
}
166+
167+
// Return a default FileSystem for this platform.
168+
func DefaultFileSystem() FileSystem {
169+
return OSMMap
170+
}

fs/os_mmap_unix.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//go:build !windows
1+
//go:build !(plan9 || windows)
2+
// +build !plan9,!windows
23

34
package fs
45

fs/os_mmap_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//go:build windows
2+
// +build windows
23

34
package fs
45

fs/os_plan9.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//go:build plan9
2+
// +build plan9
3+
4+
package fs
5+
6+
import (
7+
"os"
8+
"syscall"
9+
)
10+
11+
func createLockFile(name string, perm os.FileMode) (LockFile, bool, error) {
12+
acquiredExisting := false
13+
if _, err := os.Stat(name); err == nil {
14+
acquiredExisting = true
15+
}
16+
f, err := os.OpenFile(name, os.O_RDWR|os.O_CREATE, syscall.DMEXCL|perm)
17+
if err != nil {
18+
return nil, false, err
19+
}
20+
return &osLockFile{f, name}, acquiredExisting, nil
21+
}
22+
23+
// Return a default FileSystem for this platform.
24+
func DefaultFileSystem() FileSystem {
25+
return OS
26+
}

fs/os_unix.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//go:build !windows
1+
//go:build !(plan9 || windows)
2+
// +build !plan9,!windows
23

34
package fs
45

fs/os_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//go:build windows
2+
// +build windows
23

34
package fs
45

options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type Options struct {
2626
//
2727
// Default: fs.OSMMap.
2828
FileSystem fs.FileSystem
29-
rootFS fs.FileSystem
29+
rootFS fs.FileSystem
3030

3131
maxSegmentSize uint32
3232
compactionMinSegmentSize uint32
@@ -39,7 +39,7 @@ func (src *Options) copyWithDefaults(path string) *Options {
3939
opts = *src
4040
}
4141
if opts.FileSystem == nil {
42-
opts.FileSystem = fs.OSMMap
42+
opts.FileSystem = fs.DefaultFileSystem()
4343
}
4444
opts.rootFS = opts.FileSystem
4545
opts.FileSystem = fs.Sub(opts.FileSystem, path)

0 commit comments

Comments
 (0)