-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use storage to store archive files * Fix backend lint * Add archiver table on database * Finish archive download * Fix test * Add database migrations * Add status for archiver * Fix lint * Add queue * Add doctor to check and delete old archives * Improve archive queue * Fix tests * improve archive storage * Delete repo archives * Add missing fixture * fix fixture * Fix fixture * Fix test * Fix archiver cleaning * Fix bug * Add docs for repository archive storage * remove repo-archive configuration * Fix test * Fix test * Fix lint Co-authored-by: 6543 <[email protected]> Co-authored-by: techknowlogick <[email protected]>
- Loading branch information
1 parent
c9c7afd
commit b223d36
Showing
25 changed files
with
628 additions
and
460 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
integrations/gitea-repositories-meta/user27/repo49.git/refs/heads/test/archive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
aacbdfe9e1c4b47f60abe81849045fa4e96f1d75 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] # empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migrations | ||
|
||
import ( | ||
"xorm.io/xorm" | ||
) | ||
|
||
func addRepoArchiver(x *xorm.Engine) error { | ||
// RepoArchiver represents all archivers | ||
type RepoArchiver struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
RepoID int64 `xorm:"index unique(s)"` | ||
Type int `xorm:"unique(s)"` | ||
Status int | ||
CommitID string `xorm:"VARCHAR(40) unique(s)"` | ||
CreatedUnix int64 `xorm:"INDEX NOT NULL created"` | ||
} | ||
return x.Sync2(new(RepoArchiver)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package models | ||
|
||
import ( | ||
"fmt" | ||
|
||
"code.gitea.io/gitea/modules/git" | ||
"code.gitea.io/gitea/modules/timeutil" | ||
) | ||
|
||
// RepoArchiverStatus represents repo archive status | ||
type RepoArchiverStatus int | ||
|
||
// enumerate all repo archive statuses | ||
const ( | ||
RepoArchiverGenerating = iota // the archiver is generating | ||
RepoArchiverReady // it's ready | ||
) | ||
|
||
// RepoArchiver represents all archivers | ||
type RepoArchiver struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
RepoID int64 `xorm:"index unique(s)"` | ||
Repo *Repository `xorm:"-"` | ||
Type git.ArchiveType `xorm:"unique(s)"` | ||
Status RepoArchiverStatus | ||
CommitID string `xorm:"VARCHAR(40) unique(s)"` | ||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX NOT NULL created"` | ||
} | ||
|
||
// LoadRepo loads repository | ||
func (archiver *RepoArchiver) LoadRepo() (*Repository, error) { | ||
if archiver.Repo != nil { | ||
return archiver.Repo, nil | ||
} | ||
|
||
var repo Repository | ||
has, err := x.ID(archiver.RepoID).Get(&repo) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !has { | ||
return nil, ErrRepoNotExist{ | ||
ID: archiver.RepoID, | ||
} | ||
} | ||
return &repo, nil | ||
} | ||
|
||
// RelativePath returns relative path | ||
func (archiver *RepoArchiver) RelativePath() (string, error) { | ||
repo, err := archiver.LoadRepo() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return fmt.Sprintf("%s/%s/%s.%s", repo.FullName(), archiver.CommitID[:2], archiver.CommitID, archiver.Type.String()), nil | ||
} | ||
|
||
// GetRepoArchiver get an archiver | ||
func GetRepoArchiver(ctx DBContext, repoID int64, tp git.ArchiveType, commitID string) (*RepoArchiver, error) { | ||
var archiver RepoArchiver | ||
has, err := ctx.e.Where("repo_id=?", repoID).And("`type`=?", tp).And("commit_id=?", commitID).Get(&archiver) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if has { | ||
return &archiver, nil | ||
} | ||
return nil, nil | ||
} | ||
|
||
// AddRepoArchiver adds an archiver | ||
func AddRepoArchiver(ctx DBContext, archiver *RepoArchiver) error { | ||
_, err := ctx.e.Insert(archiver) | ||
return err | ||
} | ||
|
||
// UpdateRepoArchiverStatus updates archiver's status | ||
func UpdateRepoArchiverStatus(ctx DBContext, archiver *RepoArchiver) error { | ||
_, err := ctx.e.ID(archiver.ID).Cols("status").Update(archiver) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.