From 956f011dd3cb09d78f4cb2fb09b1cb4f50d23473 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 16 May 2014 13:41:08 -0400 Subject: [PATCH] Fix #186 --- README.md | 2 +- README_ZH.md | 2 +- cmd/web.go | 1 + gogs.go | 2 +- models/repo.go | 6 +++--- routers/repo/download.go | 42 ++++++++++++++++++++++++++++++------- templates/release/list.tmpl | 2 +- 7 files changed, 43 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 650946db4..080bced08 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language ![Demo](http://gowalker.org/public/gogs_demo.gif) -##### Current version: 0.3.4 Alpha +##### Current version: 0.3.5 Alpha ### NOTICES diff --git a/README_ZH.md b/README_ZH.md index 18fa0acf3..65e7baa40 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个由 Go 语言编写的自助 Git 托管服务。 ![Demo](http://gowalker.org/public/gogs_demo.gif) -##### 当前版本:0.3.4 Alpha +##### 当前版本:0.3.5 Alpha ## 开发目的 diff --git a/cmd/web.go b/cmd/web.go index 5a0bd167e..2eeca9fa3 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -218,6 +218,7 @@ func runWeb(*cli.Context) { r.Get("/commit/:branchname/**", repo.Diff) r.Get("/releases", repo.Releases) r.Get("/archive/:branchname/:reponame.zip", repo.ZipDownload) + r.Get("/archive/:branchname/:reponame.tar.gz", repo.TarGzDownload) }, ignSignIn, middleware.RepoAssignment(true, true)) m.Group("/:username", func(r martini.Router) { diff --git a/gogs.go b/gogs.go index cb0989392..a21d8eae0 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/base" ) -const APP_VER = "0.3.4.0515 Alpha" +const APP_VER = "0.3.5.0516 Alpha" func init() { base.AppVer = APP_VER diff --git a/models/repo.go b/models/repo.go index 0594c6c6f..7f13940be 100644 --- a/models/repo.go +++ b/models/repo.go @@ -125,8 +125,8 @@ func (repo *Repository) GetOwner() (err error) { } // IsRepositoryExist returns true if the repository with given name under user has already existed. -func IsRepositoryExist(user *User, repoName string) (bool, error) { - repo := Repository{OwnerId: user.Id} +func IsRepositoryExist(u *User, repoName string) (bool, error) { + repo := Repository{OwnerId: u.Id} has, err := orm.Where("lower_name = ?", strings.ToLower(repoName)).Get(&repo) if err != nil { return has, err @@ -134,7 +134,7 @@ func IsRepositoryExist(user *User, repoName string) (bool, error) { return false, nil } - return com.IsDir(RepoPath(user.Name, repoName)), nil + return com.IsDir(RepoPath(u.Name, repoName)), nil } var ( diff --git a/routers/repo/download.go b/routers/repo/download.go index 017d95715..d94e47665 100644 --- a/routers/repo/download.go +++ b/routers/repo/download.go @@ -11,6 +11,8 @@ import ( "github.com/Unknwon/com" "github.com/go-martini/martini" + "github.com/gogits/git" + "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/middleware" ) @@ -43,7 +45,7 @@ func SingleDownload(ctx *middleware.Context, params martini.Params) { func ZipDownload(ctx *middleware.Context, params martini.Params) { commitId := ctx.Repo.CommitId - archivesPath := filepath.Join(ctx.Repo.GitRepo.Path, "archives") + archivesPath := filepath.Join(ctx.Repo.GitRepo.Path, "archives/zip") if !com.IsDir(archivesPath) { if err := os.Mkdir(archivesPath, 0755); err != nil { ctx.Handle(404, "ZipDownload -> os.Mkdir(archivesPath)", err) @@ -51,18 +53,44 @@ func ZipDownload(ctx *middleware.Context, params martini.Params) { } } - zipPath := filepath.Join(archivesPath, commitId+".zip") + archivePath := filepath.Join(archivesPath, commitId+".zip") + + if com.IsFile(archivePath) { + ctx.ServeFile(archivePath, ctx.Repo.Repository.Name+".zip") + return + } + + err := ctx.Repo.Commit.CreateArchive(archivePath, git.AT_ZIP) + if err != nil { + ctx.Handle(404, "ZipDownload -> CreateArchive "+archivePath, err) + return + } + + ctx.ServeFile(archivePath, ctx.Repo.Repository.Name+".zip") +} + +func TarGzDownload(ctx *middleware.Context, params martini.Params) { + commitId := ctx.Repo.CommitId + archivesPath := filepath.Join(ctx.Repo.GitRepo.Path, "archives/targz") + if !com.IsDir(archivesPath) { + if err := os.Mkdir(archivesPath, 0755); err != nil { + ctx.Handle(404, "TarGzDownload -> os.Mkdir(archivesPath)", err) + return + } + } + + archivePath := filepath.Join(archivesPath, commitId+".tar.gz") - if com.IsFile(zipPath) { - ctx.ServeFile(zipPath, ctx.Repo.Repository.Name+".zip") + if com.IsFile(archivePath) { + ctx.ServeFile(archivePath, ctx.Repo.Repository.Name+".tar.gz") return } - err := ctx.Repo.Commit.CreateArchive(zipPath) + err := ctx.Repo.Commit.CreateArchive(archivePath, git.AT_TARGZ) if err != nil { - ctx.Handle(404, "ZipDownload -> CreateArchive "+zipPath, err) + ctx.Handle(404, "TarGzDownload -> CreateArchive "+archivePath, err) return } - ctx.ServeFile(zipPath, ctx.Repo.Repository.Name+".zip") + ctx.ServeFile(archivePath, ctx.Repo.Repository.Name+".tar.gz") } diff --git a/templates/release/list.tmpl b/templates/release/list.tmpl index 11f96aa54..313877959 100644 --- a/templates/release/list.tmpl +++ b/templates/release/list.tmpl @@ -31,7 +31,7 @@

Source Code (ZIP) - + Source Code (TAR.GZ)