@@ -11,7 +11,6 @@ import (
11
11
"time"
12
12
13
13
"code.gitea.io/gitea/models/db"
14
- "code.gitea.io/gitea/modules/git"
15
14
"code.gitea.io/gitea/modules/timeutil"
16
15
"code.gitea.io/gitea/modules/util"
17
16
@@ -27,11 +26,46 @@ const (
27
26
ArchiverReady // it's ready
28
27
)
29
28
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
+
30
64
// RepoArchiver represents all archivers
31
65
type 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)"`
35
69
Status ArchiverStatus
36
70
CommitID string `xorm:"VARCHAR(64) unique(s)"`
37
71
CreatedUnix timeutil.TimeStamp `xorm:"INDEX NOT NULL created"`
@@ -56,15 +90,15 @@ func repoArchiverForRelativePath(relativePath string) (*RepoArchiver, error) {
56
90
if err != nil {
57
91
return nil , util .NewInvalidArgumentErrorf ("invalid storage path: invalid repo id" )
58
92
}
59
- commitID , archiveType := git . SplitArchiveNameType (parts [2 ])
60
- if archiveType == git . ArchiveUnknown {
93
+ commitID , archiveType := SplitArchiveNameType (parts [2 ])
94
+ if archiveType == ArchiveUnknown {
61
95
return nil , util .NewInvalidArgumentErrorf ("invalid storage path: invalid archive type" )
62
96
}
63
97
return & RepoArchiver {RepoID : repoID , CommitID : commitID , Type : archiveType }, nil
64
98
}
65
99
66
100
// 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 ) {
68
102
var archiver RepoArchiver
69
103
has , err := db .GetEngine (ctx ).Where ("repo_id=?" , repoID ).And ("`type`=?" , tp ).And ("commit_id=?" , commitID ).Get (& archiver )
70
104
if err != nil {
0 commit comments