Fix download archive issue
This commit is contained in:
parent
612fdb98df
commit
25268577a5
6 changed files with 53 additions and 23 deletions
|
@ -343,6 +343,7 @@ func runWeb(*cli.Context) {
|
|||
r.Get("/issues/:index", repo.ViewIssue)
|
||||
r.Get("/pulls", repo.Pulls)
|
||||
r.Get("/branches", repo.Branches)
|
||||
r.Get("/archive/*", repo.Download)
|
||||
}, ignSignIn, middleware.RepoAssignment(true))
|
||||
|
||||
m.Group("/:username/:reponame", func(r *macaron.Router) {
|
||||
|
@ -355,8 +356,6 @@ func runWeb(*cli.Context) {
|
|||
r.Get("/commit/:branchname", repo.Diff)
|
||||
r.Get("/commit/:branchname/*", repo.Diff)
|
||||
r.Get("/releases", repo.Releases)
|
||||
r.Get("/archive/:branchname/*.*", repo.Download)
|
||||
r.Get("/archive/*.*", repo.Download)
|
||||
r.Get("/compare/:before([a-z0-9]+)...:after([a-z0-9]+)", repo.CompareDiff)
|
||||
}, ignSignIn, middleware.RepoAssignment(true, true))
|
||||
|
||||
|
|
2
gogs.go
2
gogs.go
|
@ -17,7 +17,7 @@ import (
|
|||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
const APP_VER = "0.5.4.0923 Beta"
|
||||
const APP_VER = "0.5.4.0924 Beta"
|
||||
|
||||
func init() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
|
|
@ -200,7 +200,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
|
|||
|
||||
ctx.Repo.Commit, err = gitRepo.GetCommitOfBranch(refName)
|
||||
if err != nil {
|
||||
ctx.Handle(404, "RepoAssignment invalid branch", nil)
|
||||
ctx.Handle(500, "RepoAssignment invalid branch", err)
|
||||
return
|
||||
}
|
||||
ctx.Repo.CommitId = ctx.Repo.Commit.Id.String()
|
||||
|
@ -209,14 +209,9 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
|
|||
ctx.Repo.IsTag = true
|
||||
ctx.Repo.BranchName = refName
|
||||
|
||||
ctx.Repo.Tag, err = gitRepo.GetTag(refName)
|
||||
ctx.Repo.Commit, err = gitRepo.GetCommitOfTag(refName)
|
||||
if err != nil {
|
||||
ctx.Handle(404, "RepoAssignment invalid tag", nil)
|
||||
return
|
||||
}
|
||||
ctx.Repo.Commit, err = ctx.Repo.Tag.Commit()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "RepoAssignment", fmt.Errorf("fail to get tag commit(%s): %v", refName, err))
|
||||
ctx.Handle(500, "RepoAssignment invalid tag", err)
|
||||
return
|
||||
}
|
||||
ctx.Repo.CommitId = ctx.Repo.Commit.Id.String()
|
||||
|
|
|
@ -244,18 +244,25 @@ func Action(ctx *middleware.Context) {
|
|||
}
|
||||
|
||||
func Download(ctx *middleware.Context) {
|
||||
ext := "." + ctx.Params(":ext")
|
||||
var (
|
||||
uri = ctx.Params("*")
|
||||
refName string
|
||||
ext string
|
||||
archivePath string
|
||||
)
|
||||
|
||||
var archivePath string
|
||||
switch ext {
|
||||
case ".zip":
|
||||
switch {
|
||||
case strings.HasSuffix(uri, ".zip"):
|
||||
ext = ".zip"
|
||||
archivePath = path.Join(ctx.Repo.GitRepo.Path, "archives/zip")
|
||||
case ".tar.gz":
|
||||
case strings.HasSuffix(uri, ".tar.gz"):
|
||||
ext = ".tar.gz"
|
||||
archivePath = path.Join(ctx.Repo.GitRepo.Path, "archives/targz")
|
||||
default:
|
||||
ctx.Error(404)
|
||||
return
|
||||
}
|
||||
refName = strings.TrimSuffix(uri, ext)
|
||||
|
||||
if !com.IsDir(archivePath) {
|
||||
if err := os.MkdirAll(archivePath, os.ModePerm); err != nil {
|
||||
|
@ -264,13 +271,42 @@ func Download(ctx *middleware.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
// Get corresponding commit.
|
||||
var (
|
||||
commit *git.Commit
|
||||
err error
|
||||
)
|
||||
gitRepo := ctx.Repo.GitRepo
|
||||
if gitRepo.IsBranchExist(refName) {
|
||||
commit, err = gitRepo.GetCommitOfBranch(refName)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "Download", err)
|
||||
return
|
||||
}
|
||||
} else if gitRepo.IsTagExist(refName) {
|
||||
commit, err = gitRepo.GetCommitOfTag(refName)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "Download", err)
|
||||
return
|
||||
}
|
||||
} else if len(refName) == 40 {
|
||||
commit, err = gitRepo.GetCommit(refName)
|
||||
if err != nil {
|
||||
ctx.Handle(404, "Download", nil)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
ctx.Error(404)
|
||||
return
|
||||
}
|
||||
|
||||
archivePath = path.Join(archivePath, ctx.Repo.CommitId+ext)
|
||||
if !com.IsFile(archivePath) {
|
||||
if err := ctx.Repo.Commit.CreateArchive(archivePath, git.ZIP); err != nil {
|
||||
if err := commit.CreateArchive(archivePath, git.ZIP); err != nil {
|
||||
ctx.Handle(500, "Download -> CreateArchive "+archivePath, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
ctx.ServeFile(archivePath, ctx.Repo.Repository.Name+"-"+base.ShortSha(ctx.Repo.CommitId)+ext)
|
||||
ctx.ServeFile(archivePath, ctx.Repo.Repository.Name+"-"+base.ShortSha(commit.Id.String())+ext)
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
0.5.4.0923 Beta
|
||||
0.5.4.0924 Beta
|
|
@ -36,8 +36,8 @@
|
|||
{{str2html .Note}}
|
||||
</div>
|
||||
<p class="download">
|
||||
<a class="btn btn-default" href="{{$.RepoLink}}/archive/{{.TagName}}/{{$.Repository.Name}}.zip" rel="nofollow"><i class="fa fa-download"></i>Source Code (ZIP)</a>
|
||||
<a class="btn btn-default" href="{{$.RepoLink}}/archive/{{.TagName}}/{{$.Repository.Name}}.tar.gz"><i class="fa fa-download"></i>Source Code (TAR.GZ)</a>
|
||||
<a class="btn btn-default" href="{{$.RepoLink}}/archive/{{.TagName}}.zip" rel="nofollow"><i class="fa fa-download"></i>Source Code (ZIP)</a>
|
||||
<a class="btn btn-default" href="{{$.RepoLink}}/archive/{{.TagName}}.tar.gz"><i class="fa fa-download"></i>Source Code (TAR.GZ)</a>
|
||||
</p>
|
||||
<span class="dot"> </span>
|
||||
</div>
|
||||
|
@ -48,8 +48,8 @@
|
|||
<div class="col-md-10">
|
||||
<h5 class="title"><a href="{{$.RepoLink}}/src/{{.TagName}}" rel="nofollow">{{.TagName}}</a><i class="fa fa-tag"></i></h5>
|
||||
<p class="download">
|
||||
<a class="download-link" href="{{$.RepoLink}}/archive/{{.TagName}}/{{$.Repository.Name}}.zip" rel="nofollow"><i class="fa fa-download"></i>zip</a>
|
||||
<a class="download-link" href="{{$.RepoLink}}/archive/{{.TagName}}/{{$.Repository.Name}}.tar.gz"><i class="fa fa-download"></i>tar.gz</a>
|
||||
<a class="download-link" href="{{$.RepoLink}}/archive/{{.TagName}}.zip" rel="nofollow"><i class="fa fa-download"></i>zip</a>
|
||||
<a class="download-link" href="{{$.RepoLink}}/archive/{{.TagName}}.tar.gz"><i class="fa fa-download"></i>tar.gz</a>
|
||||
</p>
|
||||
<span class="dot"> </span>
|
||||
</div>
|
||||
|
|
Reference in a new issue