Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
5685a07c
Commit
5685a07c
authored
9 years ago
by
Kevin S. Hahn
Browse files
Options
Downloads
Patches
Plain Diff
adds file locking to incremental uploads
parent
30cd1f29
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core.py
+18
-19
18 additions, 19 deletions
core.py
with
18 additions
and
19 deletions
core.py
+
18
−
19
View file @
5685a07c
...
...
@@ -10,6 +10,7 @@ import hashlib
import
tarfile
import
zipfile
import
datetime
import
lockfile
import
markdown
import
jsonschema
import
collections
...
...
@@ -218,8 +219,6 @@ class Core(base.RequestHandler):
filename
=
self
.
request
.
get
(
'
filename
'
)
content_md5
=
self
.
request
.
headers
.
get
(
'
Content-MD5
'
)
upload_path
=
self
.
app
.
config
.
get
(
'
upload_path
'
)
if
not
content_md5
:
self
.
abort
(
400
,
'
no content md5 header
'
)
def
write_to_tar
(
fp
,
mode
,
fn
,
fobj
,
content_md5
,
arcname
=
None
):
"""
...
...
@@ -236,23 +235,23 @@ class Core(base.RequestHandler):
if
not
arcname
:
# get the arcname from the last file in the archive
with
tarfile
.
open
(
fp
,
'
r
'
)
as
tf
:
arcname
=
os
.
path
.
dirname
(
tf
.
getnames
()[
-
1
])
with
tarfile
.
open
(
fp
,
mode
)
as
tf
:
with
tempfile
.
TemporaryDirectory
()
as
tempdir_path
:
hash_
=
hashlib
.
sha1
()
tempfn
=
os
.
path
.
join
(
tempdir_path
,
fn
)
with
open
(
tempfn
,
'
wb
'
)
as
fd
:
for
chunk
in
iter
(
lambda
:
fobj
.
read
(
2
**
20
),
''
):
hash_
.
update
(
chunk
)
fd
.
write
(
chunk
)
if
hash_
.
hexdigest
()
!=
content_md5
:
status
=
400
detail
=
'
Content-MD5 mismatch.
'
else
:
tf
.
add
(
tempfn
,
arcname
=
arcname
)
status
=
200
detail
=
'
OK
'
arcname
=
os
.
path
.
dirname
(
tf
.
getnames
()[
0
])
with
lockfile
.
LockFile
(
fp
):
with
tarfile
.
open
(
fp
,
mode
)
as
tf
:
with
tempfile
.
TemporaryDirectory
()
as
tempdir_path
:
hash_
=
hashlib
.
sha1
()
tempfn
=
os
.
path
.
join
(
tempdir_path
,
fn
)
with
open
(
tempfn
,
'
wb
'
)
as
fd
:
for
chunk
in
iter
(
lambda
:
fobj
.
read
(
2
**
20
),
''
):
hash_
.
update
(
chunk
)
fd
.
write
(
chunk
)
if
hash_
.
hexdigest
()
!=
content_md5
:
status
=
400
detail
=
'
Content-MD5 mismatch.
'
else
:
tf
.
add
(
tempfn
,
arcname
=
os
.
path
.
join
(
arcname
,
fn
)
)
status
=
200
detail
=
'
OK
'
return
status
,
detail
if
not
upload_id
and
filename
.
lower
()
==
'
metadata.json
'
:
# create a new temporary file for staging
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment