LFS support to be stored on minio (#12518)
* LFS support to be stored on minio * Fix test * Fix lint * Fix lint * Fix check * Fix test * Update documents and add migration for LFS * Fix some bugs
This commit is contained in:
parent
e4b3f35b8d
commit
7a5465fc56
18 changed files with 423 additions and 203 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"path"
|
||||
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
|
@ -26,6 +27,15 @@ type LFSMetaObject struct {
|
|||
CreatedUnix timeutil.TimeStamp `xorm:"created"`
|
||||
}
|
||||
|
||||
// RelativePath returns the relative path of the lfs object
|
||||
func (m *LFSMetaObject) RelativePath() string {
|
||||
if len(m.Oid) < 5 {
|
||||
return m.Oid
|
||||
}
|
||||
|
||||
return path.Join(m.Oid[0:2], m.Oid[2:4], m.Oid[4:])
|
||||
}
|
||||
|
||||
// Pointer returns the string representation of an LFS pointer file
|
||||
func (m *LFSMetaObject) Pointer() string {
|
||||
return fmt.Sprintf("%s\n%s%s\nsize %d\n", LFSMetaFileIdentifier, LFSMetaFileOidPrefix, m.Oid, m.Size)
|
||||
|
@ -202,3 +212,25 @@ func LFSAutoAssociate(metas []*LFSMetaObject, user *User, repoID int64) error {
|
|||
|
||||
return sess.Commit()
|
||||
}
|
||||
|
||||
// IterateLFS iterates lfs object
|
||||
func IterateLFS(f func(mo *LFSMetaObject) error) error {
|
||||
var start int
|
||||
const batchSize = 100
|
||||
for {
|
||||
var mos = make([]*LFSMetaObject, 0, batchSize)
|
||||
if err := x.Limit(batchSize, start).Find(&mos); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(mos) == 0 {
|
||||
return nil
|
||||
}
|
||||
start += len(mos)
|
||||
|
||||
for _, mo := range mos {
|
||||
if err := f(mo); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,6 +69,7 @@ func MainTest(m *testing.M, pathToGiteaRoot string) {
|
|||
}
|
||||
|
||||
setting.Attachment.Path = filepath.Join(setting.AppDataPath, "attachments")
|
||||
setting.LFS.ContentPath = filepath.Join(setting.AppDataPath, "lfs")
|
||||
if err = storage.Init(); err != nil {
|
||||
fatalTestError("storage.Init: %v\n", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue