(name: string, token: TokenInfo)
| 88 | } |
| 89 | |
| 90 | async save(name: string, token: TokenInfo): Promise<void> { |
| 91 | this.ensureDir(); |
| 92 | const target = this.pathFor(name); |
| 93 | const tmp = `${target}.tmp.${process.pid}.${randomBytes(4).toString('hex')}`; |
| 94 | const data = Buffer.from(`${JSON.stringify(tokenToWire(token), null, 2)}\n`, 'utf-8'); |
| 95 | const fd = openSync(tmp, 'w', 0o600); |
| 96 | try { |
| 97 | let written = 0; |
| 98 | while (written < data.length) { |
| 99 | written += writeSync(fd, data, written, data.length - written); |
| 100 | } |
| 101 | fsyncSync(fd); |
| 102 | } finally { |
| 103 | closeSync(fd); |
| 104 | } |
| 105 | try { |
| 106 | // chmod again in case umask stripped bits during open |
| 107 | chmodSync(tmp, 0o600); |
| 108 | renameSync(tmp, target); |
| 109 | } catch (error) { |
| 110 | try { |
| 111 | unlinkSync(tmp); |
| 112 | } catch { |
| 113 | /* ignore */ |
| 114 | } |
| 115 | throw error; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | async remove(name: string): Promise<void> { |
| 120 | try { |
nothing calls this directly
no test coverage detected