aboutsummaryrefslogtreecommitdiffstats
path: root/modules/lfs/content_store.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-11-01 04:51:48 +0800
committerGitHub <noreply@github.com>2020-10-31 16:51:48 -0400
commite4e85a3e51066f4987a87762c9c69acda093f6ca (patch)
tree14c00ee9e19dcec4ac2a93e6b5a0f0ec343f824c /modules/lfs/content_store.go
parente7750e0f6a4fb032bb0f717caf2b8a10a6ede873 (diff)
downloadgitea-e4e85a3e51066f4987a87762c9c69acda093f6ca.tar.gz
gitea-e4e85a3e51066f4987a87762c9c69acda093f6ca.zip
Storage configuration support `[storage]` (#13314)
* Fix minio bug * Add tests for storage configuration * Change the Seek flag to keep compitable minio? * Fix test when first-byte-pos of all ranges is greater than the resource length Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'modules/lfs/content_store.go')
-rw-r--r--modules/lfs/content_store.go23
1 files changed, 22 insertions, 1 deletions
diff --git a/modules/lfs/content_store.go b/modules/lfs/content_store.go
index cf0a05d644..247191a1bf 100644
--- a/modules/lfs/content_store.go
+++ b/modules/lfs/content_store.go
@@ -8,6 +8,7 @@ import (
"crypto/sha256"
"encoding/hex"
"errors"
+ "fmt"
"io"
"os"
@@ -21,6 +22,21 @@ var (
errSizeMismatch = errors.New("Content size does not match")
)
+// ErrRangeNotSatisfiable represents an error which request range is not satisfiable.
+type ErrRangeNotSatisfiable struct {
+ FromByte int64
+}
+
+func (err ErrRangeNotSatisfiable) Error() string {
+ return fmt.Sprintf("Requested range %d is not satisfiable", err.FromByte)
+}
+
+// IsErrRangeNotSatisfiable returns true if the error is an ErrRangeNotSatisfiable
+func IsErrRangeNotSatisfiable(err error) bool {
+ _, ok := err.(ErrRangeNotSatisfiable)
+ return ok
+}
+
// ContentStore provides a simple file system based storage.
type ContentStore struct {
storage.ObjectStorage
@@ -35,7 +51,12 @@ func (s *ContentStore) Get(meta *models.LFSMetaObject, fromByte int64) (io.ReadC
return nil, err
}
if fromByte > 0 {
- _, err = f.Seek(fromByte, os.SEEK_CUR)
+ if fromByte >= meta.Size {
+ 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)
}