-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
78 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.