Ensure we don't atomically write an empty file

This commit is contained in:
miruka
2020-03-17 12:09:08 -04:00
parent 9a66afb4eb
commit e4d47b9b9c
3 changed files with 36 additions and 11 deletions

View File

@@ -138,8 +138,9 @@ class Media:
self.local_path.parent.mkdir(parents=True, exist_ok=True)
async with atomic_write(self.local_path, binary=True) as file:
async with atomic_write(self.local_path, binary=True) as (file, done):
await file.write(data)
done()
return self.local_path
@@ -212,8 +213,11 @@ class Media:
media.local_path.parent.mkdir(parents=True, exist_ok=True)
if not media.local_path.exists() or overwrite:
async with atomic_write(media.local_path, binary=True) as file:
path = media.local_path
async with atomic_write(path, binary=True) as (file, done):
await file.write(data)
done()
return media