mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
do not rename inuse files
This commit is contained in:
parent
95760fff0f
commit
522e08872a
@ -133,19 +133,23 @@ func (p *Passwd) Write(passwdFile string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func writePasswords(passwdFile string, records [][]string) error {
|
func writePasswords(passwdFile string, records [][]string) error {
|
||||||
out, err := os.Create(passwdFile + ".tmp")
|
err := func() error {
|
||||||
|
// ensure to close tmp file before rename for filesystems like NTFS
|
||||||
|
out, err := os.Create(passwdFile + ".tmp")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer out.Close()
|
||||||
|
|
||||||
|
if err := out.Chmod(0600); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return csv.NewWriter(out).WriteAll(records)
|
||||||
|
}()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer out.Close()
|
|
||||||
|
|
||||||
if err := out.Chmod(0600); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := csv.NewWriter(out).WriteAll(records); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return os.Rename(passwdFile+".tmp", passwdFile)
|
return os.Rename(passwdFile+".tmp", passwdFile)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user