data/pieceStore: Expose flags in Open method

This commit is contained in:
Matt Joiner 2015-10-23 12:45:11 +11:00
parent ea0ccf6a23
commit 4c4eae20a2
4 changed files with 8 additions and 7 deletions

View File

@ -39,8 +39,8 @@ func (me *backend) GetLength(path string) (ret int64, err error) {
return return
} }
func (me *backend) Open(path string) (ret dataBackend.File, err error) { func (me *backend) Open(path string, flag int) (ret dataBackend.File, err error) {
ret, err = me.c.OpenFile(path, os.O_RDWR|os.O_CREATE) ret, err = me.c.OpenFile(path, flag)
return return
} }

View File

@ -52,8 +52,8 @@ func (me *backend) GetLength(path string) (ret int64, err error) {
return return
} }
func (me *backend) Open(path string) (ret dataBackend.File, err error) { func (me *backend) Open(path string, flag int) (ret dataBackend.File, err error) {
ret = httpfile.Open(me.urlStr(path)) ret = httpfile.Open(me.urlStr(path), flag)
err = fixErrNotFound(err) err = fixErrNotFound(err)
return return
} }

View File

@ -8,7 +8,7 @@ import (
// All functions must return ErrNotFound as required. // All functions must return ErrNotFound as required.
type I interface { type I interface {
GetLength(path string) (int64, error) GetLength(path string) (int64, error)
Open(path string) (File, error) Open(path string, flags int) (File, error)
OpenSection(path string, off, n int64) (io.ReadCloser, error) OpenSection(path string, off, n int64) (io.ReadCloser, error)
Delete(path string) error Delete(path string) error
} }
@ -19,4 +19,5 @@ type File interface {
io.Closer io.Closer
io.Seeker io.Seeker
io.Writer io.Writer
io.Reader
} }

View File

@ -141,7 +141,7 @@ func (me *store) pieceWriteAt(p metainfo.Piece, b []byte, off int64) (n int, err
defer func() { defer func() {
<-me.requestPool <-me.requestPool
}() }()
f, err := me.db.Open(me.incompletePiecePath(p)) f, err := me.db.Open(me.incompletePiecePath(p), os.O_WRONLY|os.O_CREATE)
if err != nil { if err != nil {
return return
} }
@ -264,7 +264,7 @@ func (me *store) hashCopyFile(from, to string, n int64) (hash []byte, err error)
defer src.Close() defer src.Close()
hasher := sha1.New() hasher := sha1.New()
tee := io.TeeReader(src, hasher) tee := io.TeeReader(src, hasher)
dest, err := me.db.Open(to) dest, err := me.db.Open(to, os.O_WRONLY|os.O_CREATE)
if err != nil { if err != nil {
return return
} }