BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
cb13980d
Commit
cb13980d
authored
Oct 08, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Let gitlab-git-http-server handle archive downloads
This change relies on changes in gitlab_git and gitlab-git-http-server.
parent
a2af080a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
70 deletions
+54
-70
repositories_controller.rb
app/controllers/projects/repositories_controller.rb
+4
-13
archive_repository_service.rb
app/services/archive_repository_service.rb
+3
-42
repositories.rb
lib/api/repositories.rb
+1
-12
grack_auth.rb
lib/gitlab/backend/grack_auth.rb
+8
-1
gitlab
lib/support/nginx/gitlab
+19
-1
gitlab-ssl
lib/support/nginx/gitlab-ssl
+19
-1
No files found.
app/controllers/projects/repositories_controller.rb
View file @
cb13980d
...
...
@@ -11,18 +11,9 @@ class Projects::RepositoriesController < Projects::ApplicationController
end
def
archive
begin
file_path
=
ArchiveRepositoryService
.
new
(
@project
,
params
[
:ref
],
params
[
:format
]).
execute
rescue
return
head
:not_found
end
if
file_path
# Send file to user
response
.
headers
[
"Content-Length"
]
=
File
.
open
(
file_path
).
size
.
to_s
send_file
file_path
else
redirect_to
request
.
fullpath
end
render
json:
ArchiveRepositoryService
.
new
(
@project
,
params
[
:ref
],
params
[
:format
]).
execute
rescue
=>
ex
logger
.
error
(
"
#{
self
.
class
.
name
}
:
#{
ex
}
"
)
return
git_not_found!
end
end
app/services/archive_repository_service.rb
View file @
cb13980d
...
...
@@ -9,17 +9,10 @@ class ArchiveRepositoryService
def
execute
(
options
=
{})
project
.
repository
.
clean_old_archives
raise
"No archive file path"
unless
file_path
metadata
=
project
.
repository
.
archive_metadata
(
ref
,
storage_path
,
format
)
raise
"Repository or ref not found"
if
metadata
.
empty?
return
file_path
if
archived?
unless
archiving?
RepositoryArchiveWorker
.
perform_async
(
project
.
id
,
ref
,
format
)
end
archived
=
wait_until_archived
(
options
[
:timeout
]
||
5.0
)
file_path
if
archived
metadata
end
private
...
...
@@ -27,36 +20,4 @@ class ArchiveRepositoryService
def
storage_path
Gitlab
.
config
.
gitlab
.
repository_downloads_path
end
def
file_path
@file_path
||=
project
.
repository
.
archive_file_path
(
ref
,
storage_path
,
format
)
end
def
pid_file_path
@pid_file_path
||=
project
.
repository
.
archive_pid_file_path
(
ref
,
storage_path
,
format
)
end
def
archived?
File
.
exist?
(
file_path
)
end
def
archiving?
File
.
exist?
(
pid_file_path
)
end
def
wait_until_archived
(
timeout
=
5.0
)
return
archived?
if
timeout
==
0.0
t1
=
Time
.
now
begin
sleep
0.1
success
=
archived?
t2
=
Time
.
now
end
until
success
||
t2
-
t1
>=
timeout
success
end
end
lib/api/repositories.rb
View file @
cb13980d
...
...
@@ -133,7 +133,7 @@ module API
authorize!
:download_code
,
user_project
begin
file_path
=
ArchiveRepositoryService
.
new
(
ArchiveRepositoryService
.
new
(
user_project
,
params
[
:sha
],
params
[
:format
]
...
...
@@ -141,17 +141,6 @@ module API
rescue
not_found!
(
'File'
)
end
if
file_path
&&
File
.
exists?
(
file_path
)
data
=
File
.
open
(
file_path
,
'rb'
).
read
basename
=
File
.
basename
(
file_path
)
header
[
'Content-Disposition'
]
=
"attachment; filename=
\"
#{
basename
}
\"
"
content_type
MIME
::
Types
.
type_for
(
file_path
).
first
.
content_type
env
[
'api.format'
]
=
:binary
present
data
else
redirect
request
.
fullpath
end
end
# Compare two branches, tags or commits
...
...
lib/gitlab/backend/grack_auth.rb
View file @
cb13980d
...
...
@@ -193,7 +193,14 @@ module Grack
end
def
render_grack_auth_ok
[
200
,
{
"Content-Type"
=>
"application/json"
},
[
JSON
.
dump
({
'GL_ID'
=>
Gitlab
::
ShellEnv
.
gl_id
(
@user
)
})]]
[
200
,
{
"Content-Type"
=>
"application/json"
},
[
JSON
.
dump
({
'GL_ID'
=>
Gitlab
::
ShellEnv
.
gl_id
(
@user
),
'RepoPath'
=>
project
.
repository
.
path_to_repo
,
})]
]
end
def
render_not_found
...
...
lib/support/nginx/gitlab
View file @
cb13980d
...
...
@@ -113,7 +113,25 @@ server {
proxy_pass http://gitlab;
}
location ~ [-\/\w\.]+\.git\/ {
location ~ ^/[\w\.-]+/[\w\.-]+/(info/refs|git-upload-pack|git-receive-pack)$ {
# 'Error' 418 is a hack to re-use the @gitlab-git-http-server block
error_page 418 = @gitlab-git-http-server;
return 418;
}
location ~ ^/[\w\.-]+/[\w\.-]+/repository/archive {
# 'Error' 418 is a hack to re-use the @gitlab-git-http-server block
error_page 418 = @gitlab-git-http-server;
return 418;
}
location ~ ^/api/v3/projects/[0-9]+/repository/archive {
# 'Error' 418 is a hack to re-use the @gitlab-git-http-server block
error_page 418 = @gitlab-git-http-server;
return 418;
}
location @gitlab-git-http-server {
## If you use HTTPS make sure you disable gzip compression
## to be safe against BREACH attack.
# gzip off;
...
...
lib/support/nginx/gitlab-ssl
View file @
cb13980d
...
...
@@ -160,7 +160,25 @@ server {
proxy_pass http://gitlab;
}
location ~ [-\/\w\.]+\.git\/ {
location ~ ^/[\w\.-]+/[\w\.-]+/(info/refs|git-upload-pack|git-receive-pack)$ {
# 'Error' 418 is a hack to re-use the @gitlab-git-http-server block
error_page 418 = @gitlab-git-http-server;
return 418;
}
location ~ ^/[\w\.-]+/[\w\.-]+/repository/archive {
# 'Error' 418 is a hack to re-use the @gitlab-git-http-server block
error_page 418 = @gitlab-git-http-server;
return 418;
}
location ~ ^/api/v3/projects/[0-9]+/repository/archive {
# 'Error' 418 is a hack to re-use the @gitlab-git-http-server block
error_page 418 = @gitlab-git-http-server;
return 418;
}
location @gitlab-git-http-server {
## If you use HTTPS make sure you disable gzip compression
## to be safe against BREACH attack.
gzip off;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment