diff options
author | Janos Guljas <janos@resenje.org> | 2018-09-25 22:57:31 +0800 |
---|---|---|
committer | Janos Guljas <janos@resenje.org> | 2018-09-25 22:57:31 +0800 |
commit | 24349144b6c0642755569268bab56b9033743212 (patch) | |
tree | 9d9d2b6659fd8a56512dfc807aafe4b733165ae1 /accounts/keystore/key.go | |
parent | 7d56602391e155e2ce9ba7c261300a1804ab9972 (diff) | |
parent | d3441ebb563439bac0837d70591f92e2c6080303 (diff) | |
download | go-tangerine-24349144b6c0642755569268bab56b9033743212.tar go-tangerine-24349144b6c0642755569268bab56b9033743212.tar.gz go-tangerine-24349144b6c0642755569268bab56b9033743212.tar.bz2 go-tangerine-24349144b6c0642755569268bab56b9033743212.tar.lz go-tangerine-24349144b6c0642755569268bab56b9033743212.tar.xz go-tangerine-24349144b6c0642755569268bab56b9033743212.tar.zst go-tangerine-24349144b6c0642755569268bab56b9033743212.zip |
Merge branch 'master' into max-stream-peer-servers
Diffstat (limited to 'accounts/keystore/key.go')
-rw-r--r-- | accounts/keystore/key.go | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/accounts/keystore/key.go b/accounts/keystore/key.go index 211fa863d..9e3e4856c 100644 --- a/accounts/keystore/key.go +++ b/accounts/keystore/key.go @@ -179,26 +179,34 @@ func storeNewKey(ks keyStore, rand io.Reader, auth string) (*Key, accounts.Accou return key, a, err } -func writeKeyFile(file string, content []byte) error { +func writeTemporaryKeyFile(file string, content []byte) (string, error) { // Create the keystore directory with appropriate permissions // in case it is not present yet. const dirPerm = 0700 if err := os.MkdirAll(filepath.Dir(file), dirPerm); err != nil { - return err + return "", err } // Atomic write: create a temporary hidden file first // then move it into place. TempFile assigns mode 0600. f, err := ioutil.TempFile(filepath.Dir(file), "."+filepath.Base(file)+".tmp") if err != nil { - return err + return "", err } if _, err := f.Write(content); err != nil { f.Close() os.Remove(f.Name()) - return err + return "", err } f.Close() - return os.Rename(f.Name(), file) + return f.Name(), nil +} + +func writeKeyFile(file string, content []byte) error { + name, err := writeTemporaryKeyFile(file, content) + if err != nil { + return err + } + return os.Rename(name, file) } // keyFileName implements the naming convention for keyfiles: |