summary refs log tree commit diff
path: root/synapse/rest/media
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-10-12 17:52:30 +0100
committerErik Johnston <erik@matrix.org>2017-10-12 17:52:30 +0100
commitcc505b4b5e98ba70d8576a562fc36b03d6aa5150 (patch)
tree9f7db3603657a073e2f3a6172b996614e9d8791d /synapse/rest/media
parentGet len before close (diff)
downloadsynapse-cc505b4b5e98ba70d8576a562fc36b03d6aa5150.tar.xz
getvalue closes buffer
Diffstat (limited to 'synapse/rest/media')
-rw-r--r--synapse/rest/media/v1/media_repository.py21
1 files changed, 10 insertions, 11 deletions
diff --git a/synapse/rest/media/v1/media_repository.py b/synapse/rest/media/v1/media_repository.py
index d25b98db45..ff2ddd2f18 100644
--- a/synapse/rest/media/v1/media_repository.py
+++ b/synapse/rest/media/v1/media_repository.py
@@ -258,7 +258,7 @@ class MediaRepository(object):
                                      server_name, media_id)
                     raise SynapseError(502, "Failed to fetch remote media")
 
-             # Will close the file after its done
+            # Will close the file after its done
             yield self.copy_to_backup(open(fname), fpath)
 
             media_type = headers["Content-Type"][0]
@@ -359,8 +359,6 @@ class MediaRepository(object):
         )
 
         if t_byte_source:
-            t_len = len(t_byte_source.getvalue())
-
             output_path = yield self.write_to_file(
                 t_byte_source,
                 self.filepaths.local_media_thumbnail_rel(
@@ -369,6 +367,8 @@ class MediaRepository(object):
             )
             logger.info("Stored thumbnail in file %r", output_path)
 
+            t_len = os.path.getsize(output_path)
+
             yield self.store.store_local_thumbnail_rel(
                 media_id, t_width, t_height, t_type, t_method, t_len
             )
@@ -388,7 +388,6 @@ class MediaRepository(object):
         )
 
         if t_byte_source:
-            t_len = len(t_byte_source.getvalue())
             output_path = yield self.write_to_file(
                 t_byte_source,
                 self.filepaths.remote_media_thumbnail_rel(
@@ -397,7 +396,9 @@ class MediaRepository(object):
             )
             logger.info("Stored thumbnail in file %r", output_path)
 
-            yield self.store.store_remote_media_thumbnail_rel(
+            t_len = os.path.getsize(output_path)
+
+            yield self.store.store_remote_media_thumbnail(
                 server_name, media_id, file_id,
                 t_width, t_height, t_type, t_method, t_len
             )
@@ -451,9 +452,8 @@ class MediaRepository(object):
                     media_id, t_width, t_height, t_type, t_method
                 )
 
-            t_len = len(t_byte_source.getvalue())
-
-            yield self.write_to_file(t_byte_source, file_path)
+            output_path = yield self.write_to_file(t_byte_source, file_path)
+            t_len = os.path.getsize(output_path)
 
             yield self.store.store_local_thumbnail(
                 media_id, t_width, t_height, t_type, t_method, t_len
@@ -503,9 +503,8 @@ class MediaRepository(object):
                 server_name, file_id, t_width, t_height, t_type, t_method
             )
 
-            t_len = len(t_byte_source.getvalue())
-
-            yield self.write_to_file(t_byte_source, file_path)
+            output_path = yield self.write_to_file(t_byte_source, file_path)
+            t_len = os.path.getsize(output_path)
 
             yield self.store.store_remote_media_thumbnail(
                 server_name, media_id, file_id,