Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
TPA
dangerzone webdav processor
Commits
11b480c1
Commit
11b480c1
authored
Jun 10, 2021
by
anarcat
Browse files
Merge branch 'error-handling' into 'main'
handle already existing remote files on move Closes
#4
See merge request
!3
parents
42f617ce
ce6ac97c
Changes
1
Hide whitespace changes
Inline
Side-by-side
processor.py
View file @
11b480c1
...
...
@@ -45,7 +45,7 @@ import tempfile
try
:
import
webdav3.client
as
wc
from
webdav3.exceptions
import
RemoteResourceNotFound
from
webdav3.exceptions
import
RemoteResourceNotFound
,
ResponseErrorCode
except
ImportError
:
print
(
"cannot find webdav.client, try `apt install python3-webdavclient` or `pip install webdavclient`"
,
...
...
@@ -372,7 +372,14 @@ class ProcessingClient(wc.Client):
if
not
self
.
dryrun
:
self
.
mkdir
(
folder
+
"/dangerzone"
)
self
.
mkdir
(
folder
+
"/dangerzone/processing"
)
self
.
move
(
remote_path_from
=
folder
+
"/"
+
path
,
remote_path_to
=
remote_processing_path
)
try
:
self
.
move
(
remote_path_from
=
folder
+
"/"
+
path
,
remote_path_to
=
remote_processing_path
)
except
ResponseErrorCode
as
e
:
# https://datatracker.ietf.org/doc/html/rfc7232#section-4.2
# actually used in WebDAV to show the file already exists
if
e
.
code
==
412
:
logging
.
warning
(
"file already being processed, skipping"
)
return
with
tempfile
.
TemporaryDirectory
()
as
tmpdir
:
# TODO: sanitize path for local use
local_path
=
tmpdir
+
"/danger/"
+
path
...
...
@@ -403,10 +410,23 @@ class ProcessingClient(wc.Client):
)
if
not
self
.
dryrun
:
self
.
mkdir
(
folder
+
"/dangerzone/rejected"
)
self
.
move
(
remote_path_from
=
remote_processing_path
,
remote_path_to
=
remote_rejected_path
,
)
try
:
self
.
move
(
remote_path_from
=
remote_processing_path
,
remote_path_to
=
remote_rejected_path
,
)
except
ResponseErrorCode
as
e
:
# https://datatracker.ietf.org/doc/html/rfc7232#section-4.2
# actually used in WebDAV to show the file already exists
if
e
.
code
==
412
:
# rejected already exists, fall back
# to delete the processing version
# altogether
#
# XXX: we actually lose data here
# which isn't nice. maybe we should
# find a unique filename instead?
self
.
clean
(
remote_processing_path
)
return
# 6. on success, upload the sanitized file to a safe/
...
...
@@ -427,10 +447,23 @@ class ProcessingClient(wc.Client):
)
if
not
self
.
dryrun
:
self
.
mkdir
(
folder
+
"/dangerzone/processed"
)
self
.
move
(
remote_path_from
=
remote_processing_path
,
remote_path_to
=
remote_processed_path
,
)
try
:
self
.
move
(
remote_path_from
=
remote_processing_path
,
remote_path_to
=
remote_processed_path
,
)
except
ResponseErrorCode
as
e
:
# https://datatracker.ietf.org/doc/html/rfc7232#section-4.2
# actually used in WebDAV to show the file already exists
if
e
.
code
==
412
:
# rejected already exists, fall back
# to delete the processing version
# altogether
#
# XXX: we actually lose data here
# which isn't nice. maybe we should
# find a unique filename instead?
self
.
clean
(
remote_processing_path
)
if
__name__
==
"__main__"
:
...
...
Write
Preview
Supports
Markdown
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