aboutsummaryrefslogtreecommitdiff
path: root/db.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-01-12 15:50:35 -0700
committerBen Johnson <benbjohnson@yahoo.com>2014-01-12 15:50:35 -0700
commit47224c438732d021e5aef74af30c7fd5801621d2 (patch)
tree86c3ed57636dc0794b61e6764c08ea5777bef072 /db.go
parentMock OS and File. (diff)
downloaddedo-47224c438732d021e5aef74af30c7fd5801621d2.tar.gz
dedo-47224c438732d021e5aef74af30c7fd5801621d2.tar.xz
Mock syscall.
Diffstat (limited to 'db.go')
-rw-r--r--db.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/db.go b/db.go
index d9a6274..67c1b46 100644
--- a/db.go
+++ b/db.go
@@ -27,6 +27,7 @@ type DB struct {
opened bool
os _os
+ syscall _syscall
file file
metafile file
data []byte
@@ -71,6 +72,9 @@ func (db *DB) Open(path string, mode os.FileMode) error {
if db.os == nil {
db.os = &sysos{}
}
+ if db.syscall == nil {
+ db.syscall = &syssyscall{}
+ }
// Exit if the database is currently open.
if db.opened {
@@ -145,7 +149,7 @@ func (db *DB) mmap() error {
// Determine the map size based on the file size.
var size int
- if info, err := db.os.Stat(db.file.Name()); err != nil {
+ if info, err := db.os.Stat(db.path); err != nil {
return err
} else if info.Size() < int64(db.pageSize*2) {
return &Error{"file size too small", nil}
@@ -154,7 +158,7 @@ func (db *DB) mmap() error {
}
// Memory-map the data file as a byte slice.
- if db.data, err = syscall.Mmap(int(db.file.Fd()), 0, size, syscall.PROT_READ, syscall.MAP_SHARED); err != nil {
+ if db.data, err = db.syscall.Mmap(int(db.file.Fd()), 0, size, syscall.PROT_READ, syscall.MAP_SHARED); err != nil {
return err
}