summaryrefslogtreecommitdiffstats
path: root/modules/lfs/content_store.go
diff options
context:
space:
mode:
authorKN4CK3R <KN4CK3R@users.noreply.github.com>2021-04-06 15:22:34 +0200
committerGitHub <noreply@github.com>2021-04-06 21:22:34 +0800
commit5f18404045f1979fab34583277ad2a1bfab81ed9 (patch)
treefcb23d5303749901dbda0e9c67d198425beabfdf /modules/lfs/content_store.go
parent1ba8b95eb472c5ec089ac947acdf822457d33378 (diff)
downloadgitea-5f18404045f1979fab34583277ad2a1bfab81ed9.tar.gz
gitea-5f18404045f1979fab34583277ad2a1bfab81ed9.zip
Close file on invalid range (Addition to #15166) (#15268)
* Close file on invalid range. * Close on seek error Signed-off-by: Andrew Thornton <art27@cantab.net> * Moved 'Seek' into server. * io.ReadSeekCloser is only available in Go 1.16 Co-authored-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'modules/lfs/content_store.go')
-rw-r--r--modules/lfs/content_store.go23
1 files changed, 2 insertions, 21 deletions
diff --git a/modules/lfs/content_store.go b/modules/lfs/content_store.go
index b4f2bb6044..520caa4c99 100644
--- a/modules/lfs/content_store.go
+++ b/modules/lfs/content_store.go
@@ -44,32 +44,13 @@ type ContentStore struct {
}
// Get takes a Meta object and retrieves the content from the store, returning
-// it as an io.Reader. If fromByte > 0, the reader starts from that byte
-func (s *ContentStore) Get(meta *models.LFSMetaObject, fromByte int64) (io.ReadCloser, error) {
+// it as an io.ReadSeekCloser.
+func (s *ContentStore) Get(meta *models.LFSMetaObject) (storage.Object, error) {
f, err := s.Open(meta.RelativePath())
if err != nil {
log.Error("Whilst trying to read LFS OID[%s]: Unable to open Error: %v", meta.Oid, err)
return nil, err
}
- if fromByte > 0 {
- if fromByte >= meta.Size {
- err = f.Close()
- if err != nil {
- log.Error("Whilst trying to read LFS OID[%s]: Unable to close Error: %v", meta.Oid, err)
- }
- return nil, ErrRangeNotSatisfiable{
- FromByte: fromByte,
- }
- }
- _, err = f.Seek(fromByte, io.SeekStart)
- if err != nil {
- log.Error("Whilst trying to read LFS OID[%s]: Unable to seek to %d Error: %v", meta.Oid, fromByte, err)
- errClose := f.Close()
- if errClose != nil {
- log.Error("Whilst trying to read LFS OID[%s]: Unable to close Error: %v", meta.Oid, errClose)
- }
- }
- }
return f, err
}