aboutsummaryrefslogtreecommitdiffstats
path: root/modules/lfs/content_store.go
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2017-11-08 15:04:19 +0200
committerGitHub <noreply@github.com>2017-11-08 15:04:19 +0200
commitba2e0240c60873679ebfce6fc7c961b0328f706b (patch)
tree5cedd7b620bdf453cb4efe35642f726c9e43b707 /modules/lfs/content_store.go
parent61f5c2250353d5a4e51f50e356e8d9f193c509fd (diff)
downloadgitea-ba2e0240c60873679ebfce6fc7c961b0328f706b.tar.gz
gitea-ba2e0240c60873679ebfce6fc7c961b0328f706b.zip
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
Diffstat (limited to 'modules/lfs/content_store.go')
-rw-r--r--modules/lfs/content_store.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/modules/lfs/content_store.go b/modules/lfs/content_store.go
index 3e1b2f345b..895b51b8ba 100644
--- a/modules/lfs/content_store.go
+++ b/modules/lfs/content_store.go
@@ -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