Skip to content

Commit

Permalink
fix builds on mac
Browse files Browse the repository at this point in the history
  • Loading branch information
nikooo777 committed Jul 27, 2022
1 parent 24add6b commit 79466ce
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 51 deletions.
32 changes: 0 additions & 32 deletions store/disk.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package store

import (
"bytes"
"io"
"io/ioutil"
"os"
"path"
Expand All @@ -11,7 +9,6 @@ import (
"github.com/lbryio/reflector.go/shared"
"github.com/lbryio/reflector.go/store/speedwalk"

"github.com/brk0v/directio"
"github.com/lbryio/lbry.go/v2/extras/errors"
)

Expand Down Expand Up @@ -67,35 +64,6 @@ func (d *DiskStore) Get(hash string, extra interface{}) ([]byte, shared.BlobTrac
return object, shared.NewBlobTrace(time.Since(start), d.Name()), nil
}

// Put stores the object on disk
func (d *DiskStore) Put(hash string, object []byte, extra interface{}) error {
err := d.ensureDirExists(d.dir(hash))
if err != nil {
return err
}

// Open file with O_DIRECT
f, err := os.OpenFile(d.tmpPath(hash), openFileFlags, 0644)
if err != nil {
return errors.Err(err)
}
defer f.Close()

// Use directio writer
dio, err := directio.New(f)
if err != nil {
return errors.Err(err)
}
defer dio.Flush()
// Write the body to file
_, err = io.Copy(dio, bytes.NewReader(object))
if err != nil {
return errors.Err(err)
}
err = os.Rename(d.tmpPath(hash), d.path(hash))
return errors.Err(err)
}

// Delete deletes the object from the store
func (d *DiskStore) Delete(hash string, extra interface{}) error {
err := os.Remove(d.path(hash))
Expand Down
36 changes: 36 additions & 0 deletions store/disk_put.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//go:build darwin
// +build darwin

package store

import (
"bytes"
"io"
"os"

"github.com/lbryio/lbry.go/v2/extras/errors"
)

var openFileFlags = os.O_WRONLY | os.O_CREATE

// Put stores the object on disk
func (d *DiskStore) Put(hash string, object []byte, extra interface{}) error {
err := d.ensureDirExists(d.dir(hash))
if err != nil {
return err
}

// Open file with O_DIRECT
f, err := os.OpenFile(d.tmpPath(hash), openFileFlags, 0644)
if err != nil {
return errors.Err(err)
}
defer f.Close()

_, err = io.Copy(f, bytes.NewReader(object))
if err != nil {
return errors.Err(err)
}
err = os.Rename(d.tmpPath(hash), d.path(hash))
return errors.Err(err)
}
42 changes: 42 additions & 0 deletions store/disk_put_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package store

import (
"bytes"
"io"
"os"
"syscall"

"github.com/brk0v/directio"
"github.com/lbryio/lbry.go/v2/extras/errors"
)

var openFileFlags = os.O_WRONLY | os.O_CREATE | syscall.O_DIRECT

// Put stores the object on disk
func (d *DiskStore) Put(hash string, object []byte, extra interface{}) error {
err := d.ensureDirExists(d.dir(hash))
if err != nil {
return err
}

// Open file with O_DIRECT
f, err := os.OpenFile(d.tmpPath(hash), openFileFlags, 0644)
if err != nil {
return errors.Err(err)
}
defer f.Close()

// Use directio writer
dio, err := directio.New(f)
if err != nil {
return errors.Err(err)
}
defer dio.Flush()
// Write the body to file
_, err = io.Copy(dio, bytes.NewReader(object))
if err != nil {
return errors.Err(err)
}
err = os.Rename(d.tmpPath(hash), d.path(hash))
return errors.Err(err)
}
9 changes: 0 additions & 9 deletions store/flags_darwin.go

This file was deleted.

10 changes: 0 additions & 10 deletions store/flags_linux.go

This file was deleted.

0 comments on commit 79466ce

Please sign in to comment.