mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-12-24 00:59:23 -05:00
Don't close prematurely..
This commit is contained in:
parent
cc505b4b5e
commit
4ae85ae121
@ -97,11 +97,12 @@ class MediaRepository(object):
|
|||||||
os.makedirs(dirname)
|
os.makedirs(dirname)
|
||||||
|
|
||||||
@staticmethod
|
@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
|
source.seek(0) # Ensure we read from the start of the file
|
||||||
with open(fname, "wb") as f:
|
with open(fname, "wb") as f:
|
||||||
shutil.copyfileobj(source, f)
|
shutil.copyfileobj(source, f)
|
||||||
|
|
||||||
|
if close_source:
|
||||||
source.close()
|
source.close()
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@ -148,10 +149,12 @@ class MediaRepository(object):
|
|||||||
yield preserve_context_over_fn(
|
yield preserve_context_over_fn(
|
||||||
threads.deferToThread,
|
threads.deferToThread,
|
||||||
self._write_file_synchronously, source, backup_fname,
|
self._write_file_synchronously, source, backup_fname,
|
||||||
|
close_source=True,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
preserve_fn(threads.deferToThread)(
|
preserve_fn(threads.deferToThread)(
|
||||||
self._write_file_synchronously, source, backup_fname,
|
self._write_file_synchronously, source, backup_fname,
|
||||||
|
close_source=True,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
source.close()
|
source.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user