Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
soledad
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
leap
soledad
Commits
ad1e3a4a
Verified
Commit
ad1e3a4a
authored
7 years ago
by
drebs
Browse files
Options
Downloads
Patches
Plain Diff
[refactor] make delete_blob() return a deferred
parent
06ade52b
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!169
#9007 - improve and document IBlobsBackend
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/leap/soledad/server/_blobs.py
+9
-4
9 additions, 4 deletions
src/leap/soledad/server/_blobs.py
src/leap/soledad/server/interfaces.py
+3
-0
3 additions, 0 deletions
src/leap/soledad/server/interfaces.py
tests/blobs/test_fs_backend.py
+4
-2
4 additions, 2 deletions
tests/blobs/test_fs_backend.py
with
16 additions
and
6 deletions
src/leap/soledad/server/_blobs.py
+
9
−
4
View file @
ad1e3a4a
...
...
@@ -147,6 +147,7 @@ class FilesystemBlobsBackend(object):
os
.
unlink
(
blob_path
+
'
.flags
'
)
except
Exception
:
pass
return
defer
.
succeed
(
None
)
def
get_blob_size
(
self
,
user
,
blob_id
,
namespace
=
''
):
blob_path
=
self
.
_get_path
(
user
,
blob_id
,
namespace
)
...
...
@@ -303,13 +304,17 @@ class BlobsResource(resource.Resource):
def
render_DELETE
(
self
,
request
):
logger
.
info
(
"
http put: %s
"
%
request
.
path
)
user
,
blob_id
,
namespace
=
self
.
_validate
(
request
)
try
:
self
.
_handler
.
delete_blob
(
user
,
blob_id
,
namespace
=
namespace
)
return
''
except
BlobNotFound
:
def
catchBlobNotFound
(
failure
):
failure
.
trap
(
BlobNotFound
)
request
.
setResponseCode
(
404
)
return
"
Blob doesn
'
t exists: %s
"
%
blob_id
d
=
self
.
_handler
.
delete_blob
(
user
,
blob_id
,
namespace
=
namespace
)
d
.
addCallback
(
lambda
_
:
request
.
finish
())
d
.
addErrback
(
catchBlobNotFound
)
return
NOT_DONE_YET
def
render_PUT
(
self
,
request
):
logger
.
info
(
"
http put: %s
"
%
request
.
path
)
user
,
blob_id
,
namespace
=
self
.
_validate
(
request
)
...
...
This diff is collapsed.
Click to expand it.
src/leap/soledad/server/interfaces.py
+
3
−
0
View file @
ad1e3a4a
...
...
@@ -69,6 +69,9 @@ class IBlobsBackend(Interface):
:type blob_id: str
:param namespace: An optional namespace for the blob.
:type namespace: str
:return: A deferred that fires when the blob has been deleted.
:rtype: twisted.internet.defer.Deferred
"""
def
get_blob_size
(
user
,
blob_id
,
namespace
=
''
):
...
...
This diff is collapsed.
Click to expand it.
tests/blobs/test_fs_backend.py
+
4
−
2
View file @
ad1e3a4a
...
...
@@ -170,6 +170,7 @@ class FilesystemBackendTestCase(unittest.TestCase):
@pytest.mark.usefixtures
(
"
method_tmpdir
"
)
@mock.patch
(
'
leap.soledad.server._blobs.os.unlink
'
)
@defer.inlineCallbacks
def
test_delete_blob
(
self
,
unlink_mock
):
backend
=
_blobs
.
FilesystemBlobsBackend
(
blobs_path
=
self
.
tempdir
)
# write a blob...
...
...
@@ -178,7 +179,7 @@ class FilesystemBackendTestCase(unittest.TestCase):
with
open
(
path
,
"
w
"
)
as
f
:
f
.
write
(
"
bl0b
"
)
# ...and delete it
backend
.
delete_blob
(
'
user
'
,
'
blob_id
'
)
yield
backend
.
delete_blob
(
'
user
'
,
'
blob_id
'
)
unlink_mock
.
assert_any_call
(
backend
.
_get_path
(
'
user
'
,
'
blob_id
'
))
unlink_mock
.
assert_any_call
(
backend
.
_get_path
(
'
user
'
,
...
...
@@ -186,6 +187,7 @@ class FilesystemBackendTestCase(unittest.TestCase):
@pytest.mark.usefixtures
(
"
method_tmpdir
"
)
@mock.patch
(
'
leap.soledad.server._blobs.os.unlink
'
)
@defer.inlineCallbacks
def
test_delete_blob_custom_namespace
(
self
,
unlink_mock
):
backend
=
_blobs
.
FilesystemBlobsBackend
(
blobs_path
=
self
.
tempdir
)
# write a blob...
...
...
@@ -194,7 +196,7 @@ class FilesystemBackendTestCase(unittest.TestCase):
with
open
(
path
,
"
w
"
)
as
f
:
f
.
write
(
"
bl0b
"
)
# ...and delete it
backend
.
delete_blob
(
'
user
'
,
'
blob_id
'
,
namespace
=
'
trash
'
)
yield
backend
.
delete_blob
(
'
user
'
,
'
blob_id
'
,
namespace
=
'
trash
'
)
unlink_mock
.
assert_any_call
(
backend
.
_get_path
(
'
user
'
,
'
blob_id
'
,
'
trash
'
))
...
...
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