git » chasquid » commit f375f27

safeio: Prefix temporary files with "."

author Alberto Bertogli
2016-09-18 05:04:31 UTC
committer Alberto Bertogli
2016-10-09 23:51:03 UTC
parent 394067bbd3b489a6b8c10bb68b5a26e43dcff2ce

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 +3 -1

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
 	}