force flush on temp file during consumption

file.write() does not guarantee that a file handle contains anything
without calling an accompanying file.flush()
For typical files that are larger than the OS-file buffer, this is no
problem
For small files (e.g. 64 characters in a .TXT), this race condition
leads to `inode/x-empty` because the file inode is created, but no
content is written to it
This commit is contained in:
Fabian Koller 2021-01-27 07:17:46 +01:00
parent 29ce2515ee
commit 21c501de28
No known key found for this signature in database
GPG key ID: 4EFE4C946404B82A
2 changed files with 2 additions and 5 deletions

View file

@ -383,6 +383,7 @@ class PostDocumentView(APIView):
dir=settings.SCRATCH_DIR,
delete=False) as f:
f.write(doc_data)
f.flush()
os.utime(f.name, times=(t, t))
async_task("documents.tasks.consume_file",