From a4300eefc4f33ead873bb9dd41437e633ea0491f Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Wed, 31 May 2017 07:08:21 +0200 Subject: [PATCH] mediaapi/fileutils: Fix and comment os.IsNotExist bug --- .../matrix-org/dendrite/mediaapi/fileutils/fileutils.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/github.com/matrix-org/dendrite/mediaapi/fileutils/fileutils.go b/src/github.com/matrix-org/dendrite/mediaapi/fileutils/fileutils.go index 975dd4308..77d88640a 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/fileutils/fileutils.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/fileutils/fileutils.go @@ -76,7 +76,9 @@ func MoveFileWithHashCheck(tmpDir types.Path, mediaMetadata *types.MediaMetadata } var stat os.FileInfo - if stat, err = os.Stat(finalPath); os.IsExist(err) { + // Note: The double-negative is intentional as os.IsExist(err) != !os.IsNotExist(err). + // The functions are error checkers to be used in different cases. + if stat, err = os.Stat(finalPath); !os.IsNotExist(err) { duplicate = true if stat.Size() == int64(mediaMetadata.FileSizeBytes) { return types.Path(finalPath), duplicate, nil