1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-18 14:47:03 +00:00

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.
This commit is contained in:
Alberto Bertogli
2016-09-18 06:04:31 +01:00
parent 394067bbd3
commit f375f276af

View File

@@ -17,7 +17,9 @@ import (
func WriteFile(filename string, data []byte, perm os.FileMode) error { func WriteFile(filename string, data []byte, perm os.FileMode) error {
// Note we create the temporary file in the same directory, otherwise we // Note we create the temporary file in the same directory, otherwise we
// would have no expectation of Rename being atomic. // 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 { if err != nil {
return err return err
} }