Merge pull request #153 from sgotti/objectstorage_posix_limitreader_only_size_gt_0
objectstorage posix: use limitreader only when size is specified.
This commit is contained in:
commit
4c88bb75a3
|
@ -23,6 +23,11 @@ import (
|
|||
type Storage interface {
|
||||
Stat(filepath string) (*types.ObjectInfo, error)
|
||||
ReadObject(filepath string) (types.ReadSeekCloser, error)
|
||||
// WriteObject atomically writes an object. If size is greater or equal to
|
||||
// zero then only size bytes will be read from data and wrote. If size is
|
||||
// less than zero data will be wrote until EOF. When persist is true the
|
||||
// implementation must ensure that data is persisted to the underlying
|
||||
// storage.
|
||||
WriteObject(filepath string, data io.Reader, size int64, persist bool) error
|
||||
DeleteObject(filepath string) error
|
||||
List(prefix, startWith, delimiter string, doneCh <-chan struct{}) <-chan types.ObjectInfo
|
||||
|
|
|
@ -98,9 +98,13 @@ func (s *PosixStorage) WriteObject(p string, data io.Reader, size int64, persist
|
|||
if err := os.MkdirAll(path.Dir(fspath), 0770); err != nil {
|
||||
return err
|
||||
}
|
||||
lr := io.LimitReader(data, size)
|
||||
|
||||
r := data
|
||||
if size >= 0 {
|
||||
r = io.LimitReader(data, size)
|
||||
}
|
||||
return common.WriteFileAtomicFunc(fspath, s.dataDir, s.tmpDir, 0660, persist, func(f io.Writer) error {
|
||||
_, err := io.Copy(f, lr)
|
||||
_, err := io.Copy(f, r)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
|
|
@ -274,9 +274,13 @@ func (s *PosixFlatStorage) WriteObject(p string, data io.Reader, size int64, per
|
|||
if err := os.MkdirAll(path.Dir(fspath), 0770); err != nil {
|
||||
return err
|
||||
}
|
||||
lr := io.LimitReader(data, size)
|
||||
|
||||
r := data
|
||||
if size >= 0 {
|
||||
r = io.LimitReader(data, size)
|
||||
}
|
||||
return common.WriteFileAtomicFunc(fspath, s.dataDir, s.tmpDir, 0660, persist, func(f io.Writer) error {
|
||||
_, err := io.Copy(f, lr)
|
||||
_, err := io.Copy(f, r)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue