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
Kazuhiko Shiozaki
gitlab-workhorse
Commits
24041f2e
Commit
24041f2e
authored
Nov 04, 2015
by
Marin Jankovski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check if file exists before trying to upload it.
parent
94b19e8c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
66 deletions
+78
-66
archive.go
archive.go
+1
-1
git-http.go
git-http.go
+2
-2
githandler.go
githandler.go
+17
-7
lfs.go
lfs.go
+58
-56
No files found.
archive.go
View file @
24041f2e
...
...
@@ -16,7 +16,7 @@ import (
"time"
)
func
handleGetArchive
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
format
string
)
(
callback
*
gitRequest
){
func
handleGetArchive
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
format
string
)
(
callback
*
gitRequest
)
{
archiveFilename
:=
path
.
Base
(
r
.
ArchivePath
)
if
cachedArchive
,
err
:=
os
.
Open
(
r
.
ArchivePath
);
err
==
nil
{
...
...
git-http.go
View file @
24041f2e
...
...
@@ -12,7 +12,7 @@ import (
"strings"
)
func
handleGetInfoRefs
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
_
string
)
(
callback
*
gitRequest
){
func
handleGetInfoRefs
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
_
string
)
(
callback
*
gitRequest
)
{
rpc
:=
r
.
URL
.
Query
()
.
Get
(
"service"
)
if
!
(
rpc
==
"git-upload-pack"
||
rpc
==
"git-receive-pack"
)
{
// The 'dumb' Git HTTP protocol is not supported
...
...
@@ -58,7 +58,7 @@ func handleGetInfoRefs(w http.ResponseWriter, r *gitRequest, _ string) (callback
return
}
func
handlePostRPC
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
rpc
string
)
(
callback
*
gitRequest
){
func
handlePostRPC
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
rpc
string
)
(
callback
*
gitRequest
)
{
var
body
io
.
ReadCloser
var
err
error
...
...
githandler.go
View file @
24041f2e
...
...
@@ -25,7 +25,7 @@ type gitHandler struct {
type
gitService
struct
{
method
string
regex
*
regexp
.
Regexp
handleFunc
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
rpc
string
)
(
*
gitRequest
)
handleFunc
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
rpc
string
)
*
gitRequest
rpc
string
}
...
...
@@ -169,13 +169,23 @@ func looksLikeRepo(p string) bool {
func
(
h
*
gitHandler
)
doAuthRequest
(
r
*
http
.
Request
)
(
result
*
http
.
Response
,
err
error
)
{
url
:=
h
.
authBackend
+
r
.
URL
.
RequestURI
()
authReq
:=
doRequest
(
r
,
url
)
if
authReq
!=
nil
{
return
h
.
httpClient
.
Do
(
authReq
)
authReq
,
err
:=
http
.
NewRequest
(
r
.
Method
,
url
,
nil
)
if
err
!=
nil
{
return
nil
,
err
}
return
// Forward all headers from our client to the auth backend. This includes
// HTTP Basic authentication credentials (the 'Authorization' header).
for
k
,
v
:=
range
r
.
Header
{
authReq
.
Header
[
k
]
=
v
}
// Also forward the Host header, which is excluded from the Header map by the http libary.
// This allows the Host header received by the backend to be consistent with other
// requests not going through gitlab-workhorse.
authReq
.
Host
=
r
.
Host
// Set a custom header for the request. This can be used in some
// configurations (Passenger) to solve auth request routing problems.
authReq
.
Header
.
Set
(
"GitLab-Git-HTTP-Server"
,
Version
)
return
h
.
httpClient
.
Do
(
authReq
)
}
func
(
h
*
gitHandler
)
doCallback
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
(
result
*
http
.
Response
,
err
error
)
{
...
...
lfs.go
View file @
24041f2e
...
...
@@ -23,9 +23,8 @@ var (
errSizeMismatch
=
errors
.
New
(
"Content size does not match"
)
)
func
handleStoreLfsObject
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
rpc
string
)
(
callback
*
gitRequest
){
func
handleStoreLfsObject
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
rpc
string
)
(
callback
*
gitRequest
)
{
var
body
io
.
ReadCloser
var
err
error
urlPath
:=
r
.
URL
.
Path
regExp
:=
regexp
.
MustCompile
(
`([0-9a-f]{64})/([0-9]+)`
)
...
...
@@ -40,69 +39,72 @@ func handleStoreLfsObject(w http.ResponseWriter, r *gitRequest, rpc string) (cal
size
:=
matches
[
2
]
log
.
Printf
(
"Found oid: %s and size: %s"
,
oid
,
size
)
path
:=
filepath
.
Join
(
r
.
StoreLFSPath
,
transformKey
(
oid
))
tmpPath
:=
path
+
".tmp"
storePath
:=
filepath
.
Join
(
r
.
StoreLFSPath
,
transformKey
(
oid
))
if
_
,
err
:=
os
.
Stat
(
storePath
);
os
.
IsNotExist
(
err
)
{
var
err
error
tmpPath
:=
filepath
.
Join
(
r
.
StoreLFSPath
,
"tmp"
,
oid
)
// TODO try removing gzip, possibly not needed
// The client request body may have been gzipped.
if
r
.
Header
.
Get
(
"Content-Encoding"
)
==
"gzip"
{
body
,
err
=
gzip
.
NewReader
(
r
.
Body
)
if
err
!=
nil
{
fail500
(
w
,
"Couldn't handle LFS upload request."
,
err
)
return
}
}
else
{
body
=
r
.
Body
}
defer
body
.
Close
()
// TODO try removing gzip, possibly not needed
// The client request body may have been gzipped.
if
r
.
Header
.
Get
(
"Content-Encoding"
)
==
"gzip"
{
body
,
err
=
gzip
.
NewReader
(
r
.
Body
)
if
err
!=
nil
{
fail500
(
w
,
"Couldn't handle LFS upload request."
,
err
)
// TODO maybe set dir permissions to 700
dir
:=
filepath
.
Dir
(
tmpPath
)
if
err
:=
os
.
MkdirAll
(
dir
,
0750
);
err
!=
nil
{
fail500
(
w
,
"Couldn't create directory for storing LFS objects."
,
err
)
return
}
}
else
{
body
=
r
.
Body
}
defer
body
.
Close
()
// TODO maybe set dir permissions to 700
dir
:=
filepath
.
Dir
(
path
)
if
err
:=
os
.
MkdirAll
(
dir
,
0750
);
err
!=
nil
{
fail500
(
w
,
"Couldn't create directory for storing LFS objects."
,
err
)
return
}
// TODO use go library for creating TMP files
file
,
err
:=
os
.
OpenFile
(
tmpPath
,
os
.
O_CREATE
|
os
.
O_WRONLY
|
os
.
O_EXCL
,
0640
)
if
err
!=
nil
{
fail500
(
w
,
"Couldn't open tmp file for writing."
,
err
)
return
}
defer
os
.
Remove
(
tmpPath
)
defer
file
.
Close
()
hash
:=
sha256
.
New
()
hw
:=
io
.
MultiWriter
(
hash
,
file
)
// TODO use go library for creating TMP files
file
,
err
:=
os
.
OpenFile
(
tmpPath
,
os
.
O_CREATE
|
os
.
O_WRONLY
|
os
.
O_EXCL
,
0640
)
if
err
!=
nil
{
fail500
(
w
,
"Couldn't open tmp file for writing."
,
err
)
return
}
// defer os.Remove(tmpPath)
defer
file
.
Close
()
written
,
err
:=
io
.
Copy
(
hw
,
body
)
if
err
!=
nil
{
fail500
(
w
,
"Failed to save received LFS object."
,
err
)
return
}
file
.
Close
()
hash
:=
sha256
.
New
()
hw
:=
io
.
MultiWriter
(
hash
,
file
)
sizeInt
,
err
:=
strconv
.
ParseInt
(
size
,
10
,
64
)
if
err
!=
nil
{
fail500
(
w
,
"Couldn't read size: "
,
err
)
return
}
written
,
err
:=
io
.
Copy
(
hw
,
body
)
if
err
!=
nil
{
fail500
(
w
,
"Failed to save received LFS object."
,
err
)
return
}
file
.
Close
()
if
written
!=
sizeInt
{
fail500
(
w
,
"Inconsistent size: "
,
errSizeMismatch
)
return
}
sizeInt
,
err
:=
strconv
.
ParseInt
(
size
,
10
,
64
)
if
err
!=
nil
{
fail500
(
w
,
"Couldn't read size: "
,
err
)
return
}
shaStr
:=
hex
.
EncodeToString
(
hash
.
Sum
(
nil
))
if
shaStr
!=
oid
{
fail500
(
w
,
"Inconsistent size: "
,
errSizeMismatch
)
return
}
if
written
!=
sizeInt
{
fail500
(
w
,
"Inconsistent size: "
,
errSizeMismatch
)
return
}
if
err
:=
os
.
Rename
(
tmpPath
,
path
);
err
!=
nil
{
fail500
(
w
,
"Failed to rename temporary LFS object."
,
err
)
return
shaStr
:=
hex
.
EncodeToString
(
hash
.
Sum
(
nil
))
if
shaStr
!=
oid
{
fail500
(
w
,
"Inconsistent size: "
,
errSizeMismatch
)
return
}
}
// if err := os.Rename(tmpPath, path); err != nil {
// fail500(w, "Failed to rename temporary LFS object.", err)
// return
// }
log
.
Printf
(
"Received the LFS object from client, oid: %s"
,
oid
)
...
...
@@ -110,7 +112,7 @@ func handleStoreLfsObject(w http.ResponseWriter, r *gitRequest, rpc string) (cal
}
func
handleRetreiveLfsObject
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
rpc
string
)
(
callback
*
gitRequest
){
func
handleRetreiveLfsObject
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
rpc
string
)
(
callback
*
gitRequest
)
{
log
.
Printf
(
"I should download %s"
,
r
)
urlPath
:=
r
.
URL
.
Path
...
...
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