Add LFS object verification step after upload (#2868)

* Add LFS object verification step after upload

* Fix file verification condition and small refactor

* Fix URLs

* Remove newline and return status 422 on failed verification

* Better error hadling
This commit is contained in:
Lauris BH 2017-11-08 15:04:19 +02:00 committed by GitHub
parent 61f5c22503
commit ba2e0240c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 2 deletions

View file

@ -1,13 +1,14 @@
package lfs
import (
"code.gitea.io/gitea/models"
"crypto/sha256"
"encoding/hex"
"errors"
"io"
"os"
"path/filepath"
"code.gitea.io/gitea/models"
)
var (
@ -82,6 +83,20 @@ func (s *ContentStore) Exists(meta *models.LFSMetaObject) bool {
return true
}
// Verify returns true if the object exists in the content store and size is correct.
func (s *ContentStore) Verify(meta *models.LFSMetaObject) (bool, error) {
path := filepath.Join(s.BasePath, transformKey(meta.Oid))
fi, err := os.Stat(path)
if os.IsNotExist(err) || err == nil && fi.Size() != meta.Size {
return false, nil
} else if err != nil {
return false, err
}
return true, nil
}
func transformKey(key string) string {
if len(key) < 5 {
return key