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
778ec11d
Verified
Commit
778ec11d
authored
7 years ago
by
drebs
Browse files
Options
Downloads
Patches
Plain Diff
[bug] handle path exceptions using twisted failures
parent
054a68f4
No related branches found
Branches containing commit
No related tags found
1 merge request
!169
#9007 - improve and document IBlobsBackend
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/leap/soledad/server/_blobs.py
+42
-11
42 additions, 11 deletions
src/leap/soledad/server/_blobs.py
tests/blobs/test_fs_backend.py
+5
-4
5 additions, 4 deletions
tests/blobs/test_fs_backend.py
with
47 additions
and
15 deletions
src/leap/soledad/server/_blobs.py
+
42
−
11
View file @
778ec11d
...
...
@@ -95,13 +95,19 @@ class FilesystemBlobsBackend(object):
def
read_blob
(
self
,
user
,
blob_id
,
namespace
=
''
):
logger
.
info
(
'
reading blob: %s - %s@%s
'
%
(
user
,
blob_id
,
namespace
))
path
=
self
.
_get_path
(
user
,
blob_id
,
namespace
)
try
:
path
=
self
.
_get_path
(
user
,
blob_id
,
namespace
)
except
Exception
as
e
:
return
defer
.
fail
(
e
)
logger
.
debug
(
'
blob path: %s
'
%
path
)
fd
=
open
(
path
)
return
defer
.
succeed
(
fd
)
def
get_flags
(
self
,
user
,
blob_id
,
namespace
=
''
):
path
=
self
.
_get_path
(
user
,
blob_id
,
namespace
)
try
:
path
=
self
.
_get_path
(
user
,
blob_id
,
namespace
)
except
Exception
as
e
:
return
defer
.
fail
(
e
)
if
not
os
.
path
.
isfile
(
path
):
return
defer
.
fail
(
BlobNotFound
())
if
not
os
.
path
.
isfile
(
path
+
'
.flags
'
):
...
...
@@ -111,7 +117,10 @@ class FilesystemBlobsBackend(object):
return
defer
.
succeed
(
flags
)
def
set_flags
(
self
,
user
,
blob_id
,
flags
,
namespace
=
''
):
path
=
self
.
_get_path
(
user
,
blob_id
,
namespace
)
try
:
path
=
self
.
_get_path
(
user
,
blob_id
,
namespace
)
except
Exception
as
e
:
return
defer
.
fail
(
e
)
if
not
os
.
path
.
isfile
(
path
):
return
defer
.
fail
(
BlobNotFound
())
for
flag
in
flags
:
...
...
@@ -142,7 +151,10 @@ class FilesystemBlobsBackend(object):
yield
self
.
semaphore
.
release
()
def
delete_blob
(
self
,
user
,
blob_id
,
namespace
=
''
):
blob_path
=
self
.
_get_path
(
user
,
blob_id
,
namespace
)
try
:
blob_path
=
self
.
_get_path
(
user
,
blob_id
,
namespace
)
except
Exception
as
e
:
return
defer
.
fail
(
e
)
if
not
os
.
path
.
isfile
(
blob_path
):
return
defer
.
fail
(
BlobNotFound
())
self
.
__touch
(
blob_path
+
'
.deleted
'
)
...
...
@@ -154,12 +166,18 @@ class FilesystemBlobsBackend(object):
return
defer
.
succeed
(
None
)
def
get_blob_size
(
self
,
user
,
blob_id
,
namespace
=
''
):
blob_path
=
self
.
_get_path
(
user
,
blob_id
,
namespace
)
try
:
blob_path
=
self
.
_get_path
(
user
,
blob_id
,
namespace
)
except
Exception
as
e
:
return
defer
.
fail
(
e
)
size
=
os
.
stat
(
blob_path
).
st_size
return
defer
.
succeed
(
size
)
def
count
(
self
,
user
,
namespace
=
''
):
base_path
=
self
.
_get_path
(
user
,
namespace
=
namespace
)
try
:
base_path
=
self
.
_get_path
(
user
,
namespace
=
namespace
)
except
Exception
as
e
:
return
defer
.
fail
(
e
)
count
=
0
for
_
,
_
,
filenames
in
os
.
walk
(
base_path
):
count
+=
len
(
filter
(
lambda
i
:
not
i
.
endswith
(
'
.flags
'
),
filenames
))
...
...
@@ -169,7 +187,10 @@ class FilesystemBlobsBackend(object):
filter_flag
=
False
):
namespace
=
namespace
or
'
default
'
blob_ids
=
[]
base_path
=
self
.
_get_path
(
user
,
namespace
=
namespace
)
try
:
base_path
=
self
.
_get_path
(
user
,
namespace
=
namespace
)
except
Exception
as
e
:
return
defer
.
fail
(
e
)
def
match
(
name
):
if
deleted
:
...
...
@@ -202,10 +223,17 @@ class FilesystemBlobsBackend(object):
yield
blob_path
def
get_total_storage
(
self
,
user
):
return
self
.
_get_disk_usage
(
self
.
_get_path
(
user
))
try
:
path
=
self
.
_get_path
(
user
)
except
Exception
as
e
:
return
defer
.
fail
(
e
)
return
self
.
_get_disk_usage
(
path
)
def
get_tag
(
self
,
user
,
blob_id
,
namespace
=
''
):
blob_path
=
self
.
_get_path
(
user
,
blob_id
,
namespace
)
try
:
blob_path
=
self
.
_get_path
(
user
,
blob_id
,
namespace
)
except
Exception
as
e
:
return
defer
.
fail
(
e
)
if
not
os
.
path
.
isfile
(
blob_path
):
return
defer
.
fail
(
BlobNotFound
())
with
open
(
blob_path
)
as
doc_file
:
...
...
@@ -236,8 +264,11 @@ class FilesystemBlobsBackend(object):
return
desired_path
def
exists
(
self
,
user
,
blob_id
,
namespace
):
return
os
.
path
.
isfile
(
self
.
_get_path
(
user
,
blob_id
=
blob_id
,
namespace
=
namespace
))
try
:
path
=
self
.
_get_path
(
user
,
blob_id
=
blob_id
,
namespace
=
namespace
)
except
Exception
as
e
:
return
defer
.
fail
(
e
)
return
os
.
path
.
isfile
(
path
)
def
_get_path
(
self
,
user
,
blob_id
=
''
,
namespace
=
''
):
parts
=
[
user
]
...
...
This diff is collapsed.
Click to expand it.
tests/blobs/test_fs_backend.py
+
5
−
4
View file @
778ec11d
...
...
@@ -142,18 +142,19 @@ class FilesystemBackendTestCase(unittest.TestCase):
target_dir
=
os
.
path
.
join
(
self
.
tempdir
,
'
user
'
,
'
incoming
'
)
walk_mock
.
assert_called_once_with
(
target_dir
)
@defer.inlineCallbacks
@pytest.mark.usefixtures
(
"
method_tmpdir
"
)
def
test_path_validation_on_read_blob
(
self
):
blobs_path
,
request
=
self
.
tempdir
,
DummyRequest
([
''
])
backend
=
_blobs
.
FilesystemBlobsBackend
(
blobs_path
=
blobs_path
)
with
pytest
.
raises
(
Exception
):
backend
.
read_blob
(
'
..
'
,
'
..
'
,
request
)
yield
backend
.
read_blob
(
'
..
'
,
'
..
'
,
request
)
with
pytest
.
raises
(
Exception
):
backend
.
read_blob
(
'
user
'
,
'
../../../
'
,
request
)
yield
backend
.
read_blob
(
'
user
'
,
'
../../../
'
,
request
)
with
pytest
.
raises
(
Exception
):
backend
.
read_blob
(
'
../../../
'
,
'
blob_id
'
,
request
)
yield
backend
.
read_blob
(
'
../../../
'
,
'
blob_id
'
,
request
)
with
pytest
.
raises
(
Exception
):
backend
.
read_blob
(
'
user
'
,
'
blob_id
'
,
request
,
namespace
=
'
..
'
)
yield
backend
.
read_blob
(
'
user
'
,
'
blob_id
'
,
request
,
namespace
=
'
..
'
)
@pytest.mark.usefixtures
(
"
method_tmpdir
"
)
@defer.inlineCallbacks
...
...
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