do not rename inuse files

This commit is contained in:
Knic Knic 2020-02-21 22:45:05 -08:00
parent 95760fff0f
commit 522e08872a

View File

@ -133,6 +133,8 @@ func (p *Passwd) Write(passwdFile string) error {
} }
func writePasswords(passwdFile string, records [][]string) error { func writePasswords(passwdFile string, records [][]string) error {
err := func() error {
// ensure to close tmp file before rename for filesystems like NTFS
out, err := os.Create(passwdFile + ".tmp") out, err := os.Create(passwdFile + ".tmp")
if err != nil { if err != nil {
return err return err
@ -143,7 +145,9 @@ func writePasswords(passwdFile string, records [][]string) error {
return err return err
} }
if err := csv.NewWriter(out).WriteAll(records); err != nil { return csv.NewWriter(out).WriteAll(records)
}()
if err != nil {
return err return err
} }