(credentials: Credentials, path = credentialPath())
| 143 | } |
| 144 | |
| 145 | export async function writeStore(credentials: Credentials, path = credentialPath()): Promise<void> { |
| 146 | await ensureDir(dirname(path)); |
| 147 | const body = JSON.stringify(serializeCredentials(credentials), null, 2); |
| 148 | const tmp = `${path}.${process.pid}.${Date.now()}.tmp`; |
| 149 | await fs.writeFile(tmp, `${body}\n`, { mode: FILE_MODE, encoding: "utf8" }); |
| 150 | // `mode` on `writeFile` is masked by umask and only applies on file |
| 151 | // creation — explicit chmod is the only reliable way to land on 0600. |
| 152 | // `rename` moves the (already-0600) tmp inode over the destination, |
| 153 | // so the final file carries the tmp's mode; no post-rename chmod |
| 154 | // needed even when overwriting a looser-permissioned file. |
| 155 | await fs.chmod(tmp, FILE_MODE); |
| 156 | await fs.rename(tmp, path); |
| 157 | } |
| 158 | |
| 159 | export async function deleteStore(path = credentialPath()): Promise<void> { |
| 160 | try { |
no test coverage detected