MCPcopy Create free account
hub / github.com/CPChain/chain / writeKeyFile

Function writeKeyFile

accounts/keystore/key.go:186–206  ·  view source on GitHub ↗
(file string, content []byte)

Source from the content-addressed store, hash-verified

184}
185
186func writeKeyFile(file string, content []byte) error {
187 // Create the keystore directory with appropriate permissions
188 // in case it is not present yet.
189 const dirPerm = 0700
190 if err := os.MkdirAll(filepath.Dir(file), dirPerm); err != nil {
191 return err
192 }
193 // Atomic write: create a temporary hidden file first
194 // then move it into place. TempFile assigns mode 0600.
195 f, err := ioutil.TempFile(filepath.Dir(file), "."+filepath.Base(file)+".tmp")
196 if err != nil {
197 return err
198 }
199 if _, err := f.Write(content); err != nil {
200 f.Close()
201 os.Remove(f.Name())
202 return err
203 }
204 f.Close()
205 return os.Rename(f.Name(), file)
206}
207
208// keyFileName implements the naming convention for keyfiles:
209// UTC--<created_at UTC ISO8601>-<address hex>

Callers 2

StoreKeyMethod · 0.85
StoreKeyMethod · 0.85

Calls 4

WriteMethod · 0.65
CloseMethod · 0.65
RemoveMethod · 0.45
NameMethod · 0.45

Tested by

no test coverage detected