From c3eb30c01d39e74501c0a506de02eb6ebb9e3cb5 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Tue, 5 Jun 2018 11:58:05 +0900 Subject: [PATCH] (refs #2048)Fix archive downloading --- .../RepositoryViewerController.scala | 44 ++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala index 61642c739..a99973b7e 100644 --- a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala @@ -822,12 +822,43 @@ trait RepositoryViewerControllerBase extends ControllerBase { }) /** - * Download repository contents as an archive as compatible URL. + * Download repository contents as a zip archive as compatible URL. */ - get("/:owner/:repository/archive/:branch.:suffix")(referrersOnly { repository => + get("/:owner/:repository/archive/:branch.zip")(referrersOnly { repository => val branch = params("branch") - val suffix = params("suffix") - archiveRepository(branch, branch + "." + suffix, repository, "") + archiveRepository(branch, branch + ".zip", repository, "") + }) + + /** + * Download repository contents as a tar.gz archive as compatible URL. + */ + get("/:owner/:repository/archive/:branch.tar.gz")(referrersOnly { repository => + val branch = params("branch") + archiveRepository(branch, branch + ".tar.gz", repository, "") + }) + + /** + * Download repository contents as a tar.gz archive as compatible URL. + */ + get("/:owner/:repository/archive/:branch.tar.gz")(referrersOnly { repository => + val branch = params("branch") + archiveRepository(branch, branch + ".tar.gz", repository, "") + }) + + /** + * Download repository contents as a tar.bz2 archive as compatible URL. + */ + get("/:owner/:repository/archive/:branch.tar.bz2")(referrersOnly { repository => + val branch = params("branch") + archiveRepository(branch, branch + ".tar.bz2", repository, "") + }) + + /** + * Download repository contents as a tar.xz archive as compatible URL. + */ + get("/:owner/:repository/archive/:branch.tar.xz")(referrersOnly { repository => + val branch = params("branch") + archiveRepository(branch, branch + ".tar.bz2", repository, "") }) /** @@ -1134,7 +1165,7 @@ trait RepositoryViewerControllerBase extends ControllerBase { } } - def archiveRepository( + private def archiveRepository( revision: String, filename: String, repository: RepositoryService.RepositoryInfo, @@ -1176,7 +1207,8 @@ trait RepositoryViewerControllerBase extends ControllerBase { } } - val suffix = path.split("/").lastOption.map("-" + _).getOrElse("") + val suffix = + path.split("/").lastOption.collect { case x if x.length > 0 => "-" + x.replace('/', '_') }.getOrElse("") val zipRe = """(.+)\.zip$""".r val tarRe = """(.+)\.tar\.(gz|bz2|xz)$""".r