@@ -11,7 +11,6 @@ import (
1111 "time"
1212
1313 "code.gitea.io/gitea/models/db"
14- "code.gitea.io/gitea/modules/git"
1514 "code.gitea.io/gitea/modules/timeutil"
1615 "code.gitea.io/gitea/modules/util"
1716
@@ -27,11 +26,46 @@ const (
2726 ArchiverReady // it's ready
2827)
2928
29+ // ArchiveType archive types
30+ type ArchiveType int
31+
32+ const (
33+ ArchiveUnknown ArchiveType = iota
34+ ArchiveZip // 1
35+ ArchiveTarGz // 2
36+ ArchiveBundle // 3
37+ )
38+
39+ // String converts an ArchiveType to string: the extension of the archive file without prefix dot
40+ func (a ArchiveType ) String () string {
41+ switch a {
42+ case ArchiveZip :
43+ return "zip"
44+ case ArchiveTarGz :
45+ return "tar.gz"
46+ case ArchiveBundle :
47+ return "bundle"
48+ }
49+ return "unknown"
50+ }
51+
52+ func SplitArchiveNameType (s string ) (string , ArchiveType ) {
53+ switch {
54+ case strings .HasSuffix (s , ".zip" ):
55+ return strings .TrimSuffix (s , ".zip" ), ArchiveZip
56+ case strings .HasSuffix (s , ".tar.gz" ):
57+ return strings .TrimSuffix (s , ".tar.gz" ), ArchiveTarGz
58+ case strings .HasSuffix (s , ".bundle" ):
59+ return strings .TrimSuffix (s , ".bundle" ), ArchiveBundle
60+ }
61+ return s , ArchiveUnknown
62+ }
63+
3064// RepoArchiver represents all archivers
3165type RepoArchiver struct { //revive:disable-line:exported
32- ID int64 `xorm:"pk autoincr"`
33- RepoID int64 `xorm:"index unique(s)"`
34- Type git. ArchiveType `xorm:"unique(s)"`
66+ ID int64 `xorm:"pk autoincr"`
67+ RepoID int64 `xorm:"index unique(s)"`
68+ Type ArchiveType `xorm:"unique(s)"`
3569 Status ArchiverStatus
3670 CommitID string `xorm:"VARCHAR(64) unique(s)"`
3771 CreatedUnix timeutil.TimeStamp `xorm:"INDEX NOT NULL created"`
@@ -56,15 +90,15 @@ func repoArchiverForRelativePath(relativePath string) (*RepoArchiver, error) {
5690 if err != nil {
5791 return nil , util .NewInvalidArgumentErrorf ("invalid storage path: invalid repo id" )
5892 }
59- commitID , archiveType := git . SplitArchiveNameType (parts [2 ])
60- if archiveType == git . ArchiveUnknown {
93+ commitID , archiveType := SplitArchiveNameType (parts [2 ])
94+ if archiveType == ArchiveUnknown {
6195 return nil , util .NewInvalidArgumentErrorf ("invalid storage path: invalid archive type" )
6296 }
6397 return & RepoArchiver {RepoID : repoID , CommitID : commitID , Type : archiveType }, nil
6498}
6599
66100// GetRepoArchiver get an archiver
67- func GetRepoArchiver (ctx context.Context , repoID int64 , tp git. ArchiveType , commitID string ) (* RepoArchiver , error ) {
101+ func GetRepoArchiver (ctx context.Context , repoID int64 , tp ArchiveType , commitID string ) (* RepoArchiver , error ) {
68102 var archiver RepoArchiver
69103 has , err := db .GetEngine (ctx ).Where ("repo_id=?" , repoID ).And ("`type`=?" , tp ).And ("commit_id=?" , commitID ).Get (& archiver )
70104 if err != nil {
0 commit comments