summary refs log tree commit diff
path: root/synapse/rest
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-10-12 17:57:31 +0100
committerErik Johnston <erik@matrix.org>2017-10-12 17:57:31 +0100
commit4ae85ae12190015595f979f1a302ee608de6fd65 (patch)
treef3e3e4c21dd578f55c9b8a0043db1f5dff652115 /synapse/rest
parentgetvalue closes buffer (diff)
downloadsynapse-4ae85ae12190015595f979f1a302ee608de6fd65.tar.xz
Don't close prematurely..
Diffstat (limited to 'synapse/rest')
-rw-r--r--synapse/rest/media/v1/media_repository.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/synapse/rest/media/v1/media_repository.py b/synapse/rest/media/v1/media_repository.py
index ff2ddd2f18..80b14a6739 100644
--- a/synapse/rest/media/v1/media_repository.py
+++ b/synapse/rest/media/v1/media_repository.py
@@ -97,12 +97,13 @@ class MediaRepository(object):
             os.makedirs(dirname)
 
     @staticmethod
-    def _write_file_synchronously(source, fname):
+    def _write_file_synchronously(source, fname, close_source=False):
         source.seek(0)  # Ensure we read from the start of the file
         with open(fname, "wb") as f:
             shutil.copyfileobj(source, f)
 
-        source.close()
+        if close_source:
+            source.close()
 
     @defer.inlineCallbacks
     def write_to_file(self, source, path):
@@ -148,10 +149,12 @@ class MediaRepository(object):
                 yield preserve_context_over_fn(
                     threads.deferToThread,
                     self._write_file_synchronously, source, backup_fname,
+                    close_source=True,
                 )
             else:
                 preserve_fn(threads.deferToThread)(
                     self._write_file_synchronously, source, backup_fname,
+                    close_source=True,
                 )
         else:
             source.close()