Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions modules/lfs/content_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"hash"
"io"
"os"
Expand All @@ -24,21 +23,6 @@ var (
ErrSizeMismatch = errors.New("Content size does not match")
)

// ErrRangeNotSatisfiable represents an error which request range is not satisfiable.
type ErrRangeNotSatisfiable struct {
FromByte int64
}

// IsErrRangeNotSatisfiable returns true if the error is an ErrRangeNotSatisfiable
func IsErrRangeNotSatisfiable(err error) bool {
_, ok := err.(ErrRangeNotSatisfiable)
return ok
}

func (err ErrRangeNotSatisfiable) Error() string {
return fmt.Sprintf("Requested range %d is not satisfiable", err.FromByte)
}

// ContentStore provides a simple file system based storage.
type ContentStore struct {
storage.ObjectStorage
Expand Down
15 changes: 15 additions & 0 deletions services/lfs/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ func DownloadHandler(ctx *context.Context) {
}
}

stat, err := content.Stat()
if err != nil {
log.Error("Unable to stat LFS OID[%s]. Error: %v", meta.Oid, err)

writeStatus(ctx, http.StatusInternalServerError)
return
}

if toByte+1 > stat.Size() {
log.Error("Whilst trying to read LFS OID[%s]: Unable to read to %d Error: %v", meta.Oid, toByte, err)

writeStatus(ctx, http.StatusRequestedRangeNotSatisfiable)
return
}

contentLength := toByte + 1 - fromByte
ctx.Resp.Header().Set("Content-Length", strconv.FormatInt(contentLength, 10))
ctx.Resp.Header().Set("Content-Type", "application/octet-stream")
Expand Down