]> source.dussan.org Git - gitea.git/commitdiff
Fix download archive issue
authorUnknwon <joe2010xtmf@163.com>
Wed, 24 Sep 2014 21:43:33 +0000 (17:43 -0400)
committerUnknwon <joe2010xtmf@163.com>
Wed, 24 Sep 2014 21:43:33 +0000 (17:43 -0400)
cmd/web.go
gogs.go
modules/middleware/repo.go
routers/repo/repo.go
templates/.VERSION
templates/repo/release/list.tmpl

index 0d472cd73a54a0322e6b49a5c9c702f8f42d22de..2376fd2126de0ba88a07aa989f34c8c25cf91ae0 100644 (file)
@@ -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))
 
diff --git a/gogs.go b/gogs.go
index 0821dbc2202d53a3d66cbec4f680788aee6e0e49..6956b9f50a01c9ba9999007d975cd20f5ae5b4f9 100644 (file)
--- a/gogs.go
+++ b/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())
index e447ee3a4d746bb85f7315ae9462d165ad6fb28a..c0290b2e8f0f3b4ab9ad9ccd4b94a6267b1c5349 100644 (file)
@@ -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()
index ae599f9fa2173f96b5aa8d056dc294015c43fd72..5562a8400a7fdc23e7a7c4cd56f13f312d40e10e 100644 (file)
@@ -244,18 +244,25 @@ func Action(ctx *middleware.Context) {
 }
 
 func Download(ctx *middleware.Context) {
-       ext := "." + ctx.Params(":ext")
-
-       var archivePath string
-       switch ext {
-       case ".zip":
+       var (
+               uri         = ctx.Params("*")
+               refName     string
+               ext         string
+               archivePath string
+       )
+
+       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)
 }
index 23f5f0fe591343661ae783bac2f02da597ed1fa3..49d86b406c1c6b07156b65dc1618ea7aecd935e9 100644 (file)
@@ -1 +1 @@
-0.5.4.0923 Beta
\ No newline at end of file
+0.5.4.0924 Beta
\ No newline at end of file
index 58a050ab56564558342f969a6f7a69a7d66377d4..1eb11fc5e6f14774b390a2dd63046b22dd3609cd 100644 (file)
@@ -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">&nbsp;</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">&nbsp;</span>
                 </div>