From 826822df31d9af01851f7f1b8b6381c0ba3e678c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Wed, 15 May 2019 18:06:09 +0200 Subject: [PATCH] Copy and delete instead of rename Fixes: https://github.com/ooni/probe-cli/issues/21 --- internal/database/models.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/database/models.go b/internal/database/models.go index 720b1e6..8e26de5 100644 --- a/internal/database/models.go +++ b/internal/database/models.go @@ -6,6 +6,7 @@ import ( "path/filepath" "time" + "github.com/ooni/probe-cli/internal/shutil" "github.com/pkg/errors" "upper.io/db.v3/lib/sqlbuilder" ) @@ -161,9 +162,13 @@ func (m *Measurement) AddToResult(sess sqlbuilder.Database, result *Result) erro // If the finalPath already exists, it means it has already been moved there. // This happens in multi input reports if _, err = os.Stat(finalPath); os.IsNotExist(err) { - err = os.Rename(m.ReportFilePath, finalPath) + err := shutil.CopyFile(m.ReportFilePath, finalPath, false) if err != nil { - return errors.Wrap(err, "moving report file") + return errors.Wrap(err, "copying report file") + } + err = os.Remove(m.ReportFilePath) + if err != nil { + return errors.Wrap(err, "deleting report file") } } m.ReportFilePath = finalPath