From 86cb8e32f7396ee97ea17e02cdd2241d3b5b5730 Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Fri, 19 May 2017 12:26:27 +0200 Subject: [PATCH] mediaapi/writers/upload: Clarify order of moving file and storing metadata --- src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go b/src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go index 38e7c8a61..917060368 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go @@ -190,7 +190,9 @@ func writeFileWithLimitAndHash(r io.Reader, cfg *config.MediaAPI, logger *log.En // storeFileAndMetadata first moves a temporary file named content from tmpDir to its // final path (see getPathFromMediaMetadata for details.) Once the file is moved, the -// metadata about the file is written into the media repository database. +// metadata about the file is written into the media repository database. This order +// of operations is important as it avoids metadata entering the database before the file +// is ready and if we fail to move the file, it never gets added to the database. // In case of any error, appropriate files and directories are cleaned up a // util.JSONResponse error is returned. func storeFileAndMetadata(tmpDir types.Path, absBasePath types.Path, mediaMetadata *types.MediaMetadata, db *storage.Database, logger *log.Entry) *util.JSONResponse {