From f375f276afb90b08a2863c56a0f6b8393b472389 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Sun, 18 Sep 2016 06:04:31 +0100 Subject: [PATCH] safeio: Prefix temporary files with "." To avoid user and automation confusion, prefix the temporary files with a ".". That way, if something scans the directory for files, it's less likely to encounter one of our temporary files. This will become very relevant in subsequent patches. --- internal/safeio/safeio.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/safeio/safeio.go b/internal/safeio/safeio.go index 127c506..e8cce16 100644 --- a/internal/safeio/safeio.go +++ b/internal/safeio/safeio.go @@ -17,7 +17,9 @@ import ( func WriteFile(filename string, data []byte, perm os.FileMode) error { // Note we create the temporary file in the same directory, otherwise we // would have no expectation of Rename being atomic. - tmpf, err := ioutil.TempFile(path.Dir(filename), path.Base(filename)) + // We make the file names start with "." so there's no confusion with the + // originals. + tmpf, err := ioutil.TempFile(path.Dir(filename), "."+path.Base(filename)) if err != nil { return err }