Skip to content

Commit

Permalink
Merge pull request agola-io#153 from sgotti/objectstorage_posix_limit…
Browse files Browse the repository at this point in the history
…reader_only_size_gt_0

objectstorage posix: use limitreader only when size is specified.
  • Loading branch information
sgotti committed Oct 25, 2019
2 parents 80e01b7 + a0da19f commit aa870f2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions internal/objectstorage/objectstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions internal/objectstorage/posix/posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Expand Down
8 changes: 6 additions & 2 deletions internal/objectstorage/posixflat/posixflat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Expand Down

0 comments on commit aa870f2

Please sign in to comment.