mirror of https://github.com/go-gitea/gitea.git
Fix #186
This commit is contained in:
parent
16e162b669
commit
956f011dd3
|
@ -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)
|
![Demo](http://gowalker.org/public/gogs_demo.gif)
|
||||||
|
|
||||||
##### Current version: 0.3.4 Alpha
|
##### Current version: 0.3.5 Alpha
|
||||||
|
|
||||||
### NOTICES
|
### NOTICES
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个由 Go 语言编写的自助 Git 托管服务。
|
||||||
|
|
||||||
![Demo](http://gowalker.org/public/gogs_demo.gif)
|
![Demo](http://gowalker.org/public/gogs_demo.gif)
|
||||||
|
|
||||||
##### 当前版本:0.3.4 Alpha
|
##### 当前版本:0.3.5 Alpha
|
||||||
|
|
||||||
## 开发目的
|
## 开发目的
|
||||||
|
|
||||||
|
|
|
@ -218,6 +218,7 @@ func runWeb(*cli.Context) {
|
||||||
r.Get("/commit/:branchname/**", repo.Diff)
|
r.Get("/commit/:branchname/**", repo.Diff)
|
||||||
r.Get("/releases", repo.Releases)
|
r.Get("/releases", repo.Releases)
|
||||||
r.Get("/archive/:branchname/:reponame.zip", repo.ZipDownload)
|
r.Get("/archive/:branchname/:reponame.zip", repo.ZipDownload)
|
||||||
|
r.Get("/archive/:branchname/:reponame.tar.gz", repo.TarGzDownload)
|
||||||
}, ignSignIn, middleware.RepoAssignment(true, true))
|
}, ignSignIn, middleware.RepoAssignment(true, true))
|
||||||
|
|
||||||
m.Group("/:username", func(r martini.Router) {
|
m.Group("/:username", func(r martini.Router) {
|
||||||
|
|
2
gogs.go
2
gogs.go
|
@ -17,7 +17,7 @@ import (
|
||||||
"github.com/gogits/gogs/modules/base"
|
"github.com/gogits/gogs/modules/base"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.3.4.0515 Alpha"
|
const APP_VER = "0.3.5.0516 Alpha"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
base.AppVer = APP_VER
|
base.AppVer = APP_VER
|
||||||
|
|
|
@ -125,8 +125,8 @@ func (repo *Repository) GetOwner() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsRepositoryExist returns true if the repository with given name under user has already existed.
|
// IsRepositoryExist returns true if the repository with given name under user has already existed.
|
||||||
func IsRepositoryExist(user *User, repoName string) (bool, error) {
|
func IsRepositoryExist(u *User, repoName string) (bool, error) {
|
||||||
repo := Repository{OwnerId: user.Id}
|
repo := Repository{OwnerId: u.Id}
|
||||||
has, err := orm.Where("lower_name = ?", strings.ToLower(repoName)).Get(&repo)
|
has, err := orm.Where("lower_name = ?", strings.ToLower(repoName)).Get(&repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return has, err
|
return has, err
|
||||||
|
@ -134,7 +134,7 @@ func IsRepositoryExist(user *User, repoName string) (bool, error) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return com.IsDir(RepoPath(user.Name, repoName)), nil
|
return com.IsDir(RepoPath(u.Name, repoName)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -11,6 +11,8 @@ import (
|
||||||
"github.com/Unknwon/com"
|
"github.com/Unknwon/com"
|
||||||
"github.com/go-martini/martini"
|
"github.com/go-martini/martini"
|
||||||
|
|
||||||
|
"github.com/gogits/git"
|
||||||
|
|
||||||
"github.com/gogits/gogs/modules/base"
|
"github.com/gogits/gogs/modules/base"
|
||||||
"github.com/gogits/gogs/modules/middleware"
|
"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) {
|
func ZipDownload(ctx *middleware.Context, params martini.Params) {
|
||||||
commitId := ctx.Repo.CommitId
|
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 !com.IsDir(archivesPath) {
|
||||||
if err := os.Mkdir(archivesPath, 0755); err != nil {
|
if err := os.Mkdir(archivesPath, 0755); err != nil {
|
||||||
ctx.Handle(404, "ZipDownload -> os.Mkdir(archivesPath)", err)
|
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(zipPath) {
|
if com.IsFile(archivePath) {
|
||||||
ctx.ServeFile(zipPath, ctx.Repo.Repository.Name+".zip")
|
ctx.ServeFile(archivePath, ctx.Repo.Repository.Name+".zip")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := ctx.Repo.Commit.CreateArchive(zipPath)
|
err := ctx.Repo.Commit.CreateArchive(archivePath, git.AT_ZIP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(404, "ZipDownload -> CreateArchive "+zipPath, err)
|
ctx.Handle(404, "ZipDownload -> CreateArchive "+archivePath, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.ServeFile(zipPath, ctx.Repo.Repository.Name+".zip")
|
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(archivePath) {
|
||||||
|
ctx.ServeFile(archivePath, ctx.Repo.Repository.Name+".tar.gz")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err := ctx.Repo.Commit.CreateArchive(archivePath, git.AT_TARGZ)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(404, "TarGzDownload -> CreateArchive "+archivePath, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.ServeFile(archivePath, ctx.Repo.Repository.Name+".tar.gz")
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
</div>
|
</div>
|
||||||
<p class="download">
|
<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}}.zip" rel="nofollow"><i class="fa fa-download"></i>Source Code (ZIP)</a>
|
||||||
<!-- <a class="btn btn-default" href="{release_download_link}"><i class="fa fa-download"></i>Source Code (TAR.GZ)</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>
|
||||||
</p>
|
</p>
|
||||||
<span class="dot"> </span>
|
<span class="dot"> </span>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue