Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
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
Show more breadcrumbs
Timo Ley
synapse
Commits
2cf6a7bc
Commit
2cf6a7bc
authored
7 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Use better file consumer
parent
4a53f3a3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/rest/media/v1/media_storage.py
+10
-5
10 additions, 5 deletions
synapse/rest/media/v1/media_storage.py
with
10 additions
and
5 deletions
synapse/rest/media/v1/media_storage.py
+
10
−
5
View file @
2cf6a7bc
...
@@ -15,10 +15,10 @@
...
@@ -15,10 +15,10 @@
from
twisted.internet
import
defer
,
threads
from
twisted.internet
import
defer
,
threads
from
twisted.protocols.basic
import
FileSender
from
twisted.protocols.basic
import
FileSender
from
twisted.protocols.ftp
import
FileConsumer
# This isn't FTP specific
from
._base
import
Responder
from
._base
import
Responder
from
synapse.util.file_consumer
import
BackgroundFileConsumer
from
synapse.util.logcontext
import
make_deferred_yieldable
from
synapse.util.logcontext
import
make_deferred_yieldable
import
contextlib
import
contextlib
...
@@ -27,6 +27,7 @@ import logging
...
@@ -27,6 +27,7 @@ import logging
import
shutil
import
shutil
import
sys
import
sys
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -168,12 +169,17 @@ class MediaStorage(object):
...
@@ -168,12 +169,17 @@ class MediaStorage(object):
if
os
.
path
.
exists
(
local_path
):
if
os
.
path
.
exists
(
local_path
):
defer
.
returnValue
(
local_path
)
defer
.
returnValue
(
local_path
)
dirname
=
os
.
path
.
dirname
(
local_path
)
if
not
os
.
path
.
exists
(
dirname
):
os
.
makedirs
(
dirname
)
for
provider
in
self
.
storage_providers
:
for
provider
in
self
.
storage_providers
:
res
=
yield
provider
.
fetch
(
path
,
file_info
)
res
=
yield
provider
.
fetch
(
path
,
file_info
)
if
res
:
if
res
:
with
res
:
with
res
:
with
open
(
local_path
,
"
w
"
)
as
f
:
consumer
=
BackgroundFileConsumer
(
open
(
local_path
,
"
w
"
))
res
.
write_to_consumer
(
FileConsumer
(
f
))
yield
res
.
write_to_consumer
(
consumer
)
yield
consumer
.
wait
()
defer
.
returnValue
(
local_path
)
defer
.
returnValue
(
local_path
)
raise
Exception
(
"
file could not be found
"
)
raise
Exception
(
"
file could not be found
"
)
...
@@ -247,9 +253,8 @@ class FileResponder(Responder):
...
@@ -247,9 +253,8 @@ class FileResponder(Responder):
def
__init__
(
self
,
open_file
):
def
__init__
(
self
,
open_file
):
self
.
open_file
=
open_file
self
.
open_file
=
open_file
@defer.inlineCallbacks
def
write_to_consumer
(
self
,
consumer
):
def
write_to_consumer
(
self
,
consumer
):
yield
FileSender
().
beginFileTransfer
(
self
.
open_file
,
consumer
)
return
FileSender
().
beginFileTransfer
(
self
.
open_file
,
consumer
)
def
__exit__
(
self
,
exc_type
,
exc_val
,
exc_tb
):
def
__exit__
(
self
,
exc_type
,
exc_val
,
exc_tb
):
self
.
open_file
.
close
()
self
.
open_file
.
close
()
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