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
c165c876
Commit
c165c876
authored
Nov 09, 2015
by
Marin Jankovski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove parsing of url and receive required data from GitLab Rails.
parent
e6c7d974
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
28 deletions
+26
-28
lfs.go
lfs.go
+22
-27
upstream.go
upstream.go
+4
-1
No files found.
lfs.go
View file @
c165c876
...
@@ -10,11 +10,9 @@ import (
...
@@ -10,11 +10,9 @@ import (
"errors"
"errors"
"io"
"io"
"io/ioutil"
"io/ioutil"
"log"
"net/http"
"net/http"
"os"
"os"
"path/filepath"
"path/filepath"
"regexp"
"strconv"
"strconv"
)
)
...
@@ -31,43 +29,40 @@ func lfsAuthorizeHandler(handleFunc serviceHandleFunc) serviceHandleFunc {
...
@@ -31,43 +29,40 @@ func lfsAuthorizeHandler(handleFunc serviceHandleFunc) serviceHandleFunc {
return
return
}
}
handleFunc
(
w
,
r
)
if
r
.
LfsOid
==
""
{
},
""
)
fail500
(
w
,
"lfsAuthorizeHandler"
,
errors
.
New
(
"Lfs object oid not specified."
))
}
return
}
func
handleStoreLfsObject
(
handleFunc
serviceHandleFunc
)
serviceHandleFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
urlPath
:=
r
.
URL
.
Path
if
r
.
LfsSize
==
""
{
regExp
:=
regexp
.
MustCompile
(
`([0-9a-f]{64})/([0-9]+)`
)
fail500
(
w
,
"lfsAuthorizeHandler"
,
errors
.
New
(
"Lfs object size not specified."
))
matches
:=
regExp
.
FindStringSubmatch
(
urlPath
)
return
}
if
matches
==
nil
{
tmpDir
:=
r
.
StoreLFSPath
log
.
Printf
(
"Found no object info in path: %s"
,
urlPath
)
if
_
,
err
:=
os
.
Stat
(
tmpDir
);
os
.
IsNotExist
(
err
)
{
if
err
:=
os
.
Mkdir
(
tmpDir
,
0700
);
err
!=
nil
{
fail500
(
w
,
"Couldn't create directory for storing LFS tmp objects."
,
err
)
return
return
}
}
}
oid
:=
matches
[
1
]
handleFunc
(
w
,
r
)
size
:=
matches
[
2
]
},
""
)
log
.
Printf
(
"Found oid: %s and size: %s"
,
oid
,
size
)
}
sha
:=
sha256
.
New
()
func
handleStoreLfsObject
(
handleFunc
serviceHandleFunc
)
serviceHandleFunc
{
sha
.
Write
([]
byte
(
oid
))
return
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
tmp_hash
:=
hex
.
EncodeToString
(
sha
.
Sum
(
nil
))
oid
:=
r
.
LfsOid
tmpPath
:=
filepath
.
Join
(
r
.
StoreLFSPath
,
"tmp"
)
size
:=
r
.
LfsSize
var
body
io
.
ReadCloser
var
body
io
.
ReadCloser
body
=
r
.
Body
body
=
r
.
Body
defer
body
.
Close
()
defer
body
.
Close
()
dir
:=
filepath
.
Dir
(
tmpPath
)
tmpPath
:=
r
.
StoreLFSPath
if
err
:=
os
.
MkdirAll
(
dir
,
0700
);
err
!=
nil
{
file
,
err
:=
ioutil
.
TempFile
(
tmpPath
,
""
)
fail500
(
w
,
"Couldn't create directory for storing LFS objects."
,
err
)
return
}
file
,
err
:=
ioutil
.
TempFile
(
tmpPath
,
tmp_hash
)
if
err
!=
nil
{
if
err
!=
nil
{
fail500
(
w
,
"Couldn't open tmp file for writing."
,
err
)
fail500
(
w
,
"Couldn't open tmp file for writing."
,
err
)
return
return
...
...
upstream.go
View file @
c165c876
...
@@ -44,10 +44,13 @@ type authorizationResponse struct {
...
@@ -44,10 +44,13 @@ type authorizationResponse struct {
// CommitId is used do prevent race conditions between the 'time of check'
// CommitId is used do prevent race conditions between the 'time of check'
// in the GitLab Rails app and the 'time of use' in gitlab-workhorse.
// in the GitLab Rails app and the 'time of use' in gitlab-workhorse.
CommitId
string
CommitId
string
// StoreLFSPath is provided by the GitLab Rails application
// StoreLFSPath is provided by the GitLab Rails application
// to mark where the tmp file should be placed
// to mark where the tmp file should be placed
StoreLFSPath
string
StoreLFSPath
string
// LFS object id
LfsOid
string
// LFS object size
LfsSize
string
}
}
// A gitReqest is an *http.Request decorated with attributes returned by the
// A gitReqest is an *http.Request decorated with attributes returned by the
...
...
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