objectstorage: honor write size in posix objectstorage

This commit is contained in:
Simone Gotti 2019-06-05 14:56:56 +02:00
parent 6d095cbe50
commit 8e4555373d
2 changed files with 5 additions and 2 deletions

View File

@ -23,6 +23,7 @@ import (
"github.com/sorintlab/agola/internal/objectstorage/common"
"github.com/sorintlab/agola/internal/objectstorage/types"
errors "golang.org/x/xerrors"
)
@ -97,8 +98,9 @@ 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)
return common.WriteFileAtomicFunc(fspath, s.dataDir, s.tmpDir, 0660, persist, func(f io.Writer) error {
_, err := io.Copy(f, data)
_, err := io.Copy(f, lr)
return err
})
}

View File

@ -275,8 +275,9 @@ 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)
return common.WriteFileAtomicFunc(fspath, s.dataDir, s.tmpDir, 0660, persist, func(f io.Writer) error {
_, err := io.Copy(f, data)
_, err := io.Copy(f, lr)
return err
})
}