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 (
"errors"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"
"regexp"
"strconv"
)
...
...
@@ -31,43 +29,40 @@ func lfsAuthorizeHandler(handleFunc serviceHandleFunc) serviceHandleFunc {
return
}
handleFunc
(
w
,
r
)
},
""
)
}
func
handleStoreLfsObject
(
handleFunc
serviceHandleFunc
)
serviceHandleFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
if
r
.
LfsOid
==
""
{
fail500
(
w
,
"lfsAuthorizeHandler"
,
errors
.
New
(
"Lfs object oid not specified."
))
return
}
urlPath
:=
r
.
URL
.
Path
regExp
:=
regexp
.
MustCompile
(
`([0-9a-f]{64})/([0-9]+)`
)
matches
:=
regExp
.
FindStringSubmatch
(
urlPath
)
if
r
.
LfsSize
==
""
{
fail500
(
w
,
"lfsAuthorizeHandler"
,
errors
.
New
(
"Lfs object size not specified."
))
return
}
if
matches
==
nil
{
log
.
Printf
(
"Found no object info in path: %s"
,
urlPath
)
tmpDir
:=
r
.
StoreLFSPath
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
}
}
oid
:=
matches
[
1
]
size
:=
matches
[
2
]
log
.
Printf
(
"Found oid: %s and size: %s"
,
oid
,
size
)
handleFunc
(
w
,
r
)
},
""
)
}
sha
:=
sha256
.
New
()
sha
.
Write
([]
byte
(
oid
))
tmp_hash
:=
hex
.
EncodeToString
(
sha
.
Sum
(
nil
))
tmpPath
:=
filepath
.
Join
(
r
.
StoreLFSPath
,
"tmp"
)
func
handleStoreLfsObject
(
handleFunc
serviceHandleFunc
)
serviceHandleFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
oid
:=
r
.
LfsOid
size
:=
r
.
LfsSize
var
body
io
.
ReadCloser
body
=
r
.
Body
defer
body
.
Close
()
dir
:=
filepath
.
Dir
(
tmpPath
)
if
err
:=
os
.
MkdirAll
(
dir
,
0700
);
err
!=
nil
{
fail500
(
w
,
"Couldn't create directory for storing LFS objects."
,
err
)
return
}
file
,
err
:=
ioutil
.
TempFile
(
tmpPath
,
tmp_hash
)
tmpPath
:=
r
.
StoreLFSPath
file
,
err
:=
ioutil
.
TempFile
(
tmpPath
,
""
)
if
err
!=
nil
{
fail500
(
w
,
"Couldn't open tmp file for writing."
,
err
)
return
...
...
upstream.go
View file @
c165c876
...
...
@@ -44,10 +44,13 @@ type authorizationResponse struct {
// 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.
CommitId
string
// StoreLFSPath is provided by the GitLab Rails application
// to mark where the tmp file should be placed
StoreLFSPath
string
// LFS object id
LfsOid
string
// LFS object size
LfsSize
string
}
// 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