Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
gitlab-workhorse
Commits
8972c849
Commit
8972c849
authored
Oct 08, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move some git archive stuff into helpers
parent
04e1a814
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
31 deletions
+33
-31
githandler.go
githandler.go
+33
-31
No files found.
githandler.go
View file @
8972c849
...
@@ -208,6 +208,7 @@ func handleGetInfoRefs(env gitEnv, _ string, repoPath string, w http.ResponseWri
...
@@ -208,6 +208,7 @@ func handleGetInfoRefs(env gitEnv, _ string, repoPath string, w http.ResponseWri
func
handleGetArchive
(
env
gitEnv
,
format
string
,
repoPath
string
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
handleGetArchive
(
env
gitEnv
,
format
string
,
repoPath
string
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
archiveFilename
:=
path
.
Base
(
env
.
ArchivePath
)
archiveFilename
:=
path
.
Base
(
env
.
ArchivePath
)
if
cachedArchive
,
err
:=
os
.
Open
(
env
.
ArchivePath
);
err
==
nil
{
if
cachedArchive
,
err
:=
os
.
Open
(
env
.
ArchivePath
);
err
==
nil
{
defer
cachedArchive
.
Close
()
defer
cachedArchive
.
Close
()
log
.
Printf
(
"Serving cached file %q"
,
env
.
ArchivePath
)
log
.
Printf
(
"Serving cached file %q"
,
env
.
ArchivePath
)
...
@@ -216,36 +217,14 @@ func handleGetArchive(env gitEnv, format string, repoPath string, w http.Respons
...
@@ -216,36 +217,14 @@ func handleGetArchive(env gitEnv, format string, repoPath string, w http.Respons
return
return
}
}
// Prepare tempfile to create cached archive
tempFile
,
err
:=
prepareArchiveTempfile
(
path
.
Dir
(
env
.
ArchivePath
),
archiveFilename
)
cacheDir
:=
path
.
Dir
(
env
.
ArchivePath
)
if
err
:=
os
.
MkdirAll
(
cacheDir
,
0700
);
err
!=
nil
{
fail500
(
w
,
"handleGetArchive create archive cache directory"
,
err
)
return
}
tempFile
,
err
:=
ioutil
.
TempFile
(
cacheDir
,
archiveFilename
)
if
err
!=
nil
{
if
err
!=
nil
{
fail500
(
w
,
"handleGetArchive create tempfile for archive"
,
err
)
fail500
(
w
,
"handleGetArchive create tempfile for archive"
,
err
)
return
}
}
defer
tempFile
.
Close
()
defer
tempFile
.
Close
()
defer
os
.
Remove
(
tempFile
.
Name
())
defer
os
.
Remove
(
tempFile
.
Name
())
var
compressCmd
*
exec
.
Cmd
compressCmd
,
archiveFormat
:=
parseArchiveFormat
(
format
)
var
archiveFormat
string
switch
format
{
case
"tar"
:
archiveFormat
=
"tar"
compressCmd
=
nil
case
"tar.gz"
:
archiveFormat
=
"tar"
compressCmd
=
exec
.
Command
(
"gzip"
,
"-c"
,
"-n"
)
case
"tar.bz2"
:
archiveFormat
=
"tar"
compressCmd
=
exec
.
Command
(
"bzip2"
,
"-c"
)
case
"zip"
:
archiveFormat
=
"zip"
compressCmd
=
nil
}
archiveCmd
:=
gitCommand
(
env
,
"git"
,
"--git-dir="
+
repoPath
,
"archive"
,
"--format="
+
archiveFormat
,
"--prefix="
+
env
.
ArchivePrefix
+
"/"
,
env
.
CommitId
)
archiveCmd
:=
gitCommand
(
env
,
"git"
,
"--git-dir="
+
repoPath
,
"archive"
,
"--format="
+
archiveFormat
,
"--prefix="
+
env
.
ArchivePrefix
+
"/"
,
env
.
CommitId
)
archiveStdout
,
err
:=
archiveCmd
.
StdoutPipe
()
archiveStdout
,
err
:=
archiveCmd
.
StdoutPipe
()
...
@@ -300,13 +279,8 @@ func handleGetArchive(env gitEnv, format string, repoPath string, w http.Respons
...
@@ -300,13 +279,8 @@ func handleGetArchive(env gitEnv, format string, repoPath string, w http.Respons
}
}
}
}
// Finalize cached archive
if
err
:=
finalizeCachedArchive
(
tempFile
,
env
.
ArchivePath
);
err
!=
nil
{
if
err
:=
tempFile
.
Close
();
err
!=
nil
{
logContext
(
"handleGetArchive finalize cached archive"
,
err
)
logContext
(
"handleGetArchive close cached archive"
,
err
)
return
}
if
err
:=
os
.
Link
(
tempFile
.
Name
(),
env
.
ArchivePath
);
err
!=
nil
{
logContext
(
"handleGetArchive link (finalize) cached archive"
,
err
)
return
return
}
}
}
}
...
@@ -322,6 +296,34 @@ func setArchiveHeaders(w http.ResponseWriter, format string, archiveFilename str
...
@@ -322,6 +296,34 @@ func setArchiveHeaders(w http.ResponseWriter, format string, archiveFilename str
w
.
Header
()
.
Add
(
"Cache-Control"
,
"private"
)
w
.
Header
()
.
Add
(
"Cache-Control"
,
"private"
)
}
}
func
parseArchiveFormat
(
format
string
)
(
*
exec
.
Cmd
,
string
)
{
switch
format
{
case
"tar"
:
return
nil
,
"tar"
case
"tar.gz"
:
return
exec
.
Command
(
"gzip"
,
"-c"
,
"-n"
),
"tar"
case
"tar.bz2"
:
return
exec
.
Command
(
"bzip2"
,
"-c"
),
"tar"
case
"zip"
:
return
nil
,
"zip"
}
return
nil
,
"unknown"
}
func
prepareArchiveTempfile
(
dir
string
,
prefix
string
)
(
*
os
.
File
,
error
)
{
if
err
:=
os
.
MkdirAll
(
dir
,
0700
);
err
!=
nil
{
return
nil
,
err
}
return
ioutil
.
TempFile
(
dir
,
prefix
)
}
func
finalizeCachedArchive
(
tempFile
*
os
.
File
,
archivePath
string
)
error
{
if
err
:=
tempFile
.
Close
();
err
!=
nil
{
return
err
}
return
os
.
Link
(
tempFile
.
Name
(),
archivePath
)
}
func
handlePostRPC
(
env
gitEnv
,
rpc
string
,
repoPath
string
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
handlePostRPC
(
env
gitEnv
,
rpc
string
,
repoPath
string
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
var
body
io
.
ReadCloser
var
body
io
.
ReadCloser
var
err
error
var
err
error
...
...
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