MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / save

Method save

packages/oauth/src/storage.ts:90–117  ·  view source on GitHub ↗
(name: string, token: TokenInfo)

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 4

ensureDirMethod · 0.95
pathForMethod · 0.95
tokenToWireFunction · 0.90
toStringMethod · 0.65

Tested by

no test coverage detected