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

Function ensureFile

apps/kimi-code/src/native/native-assets.ts:181–206  ·  view source on GitHub ↗
(path: string, bytes: Buffer, expectedSha256: string, mode?: number)

Source from the content-addressed store, hash-verified

179}
180
181function ensureFile(path: string, bytes: Buffer, expectedSha256: string, mode?: number): void {
182 if (readFileSha256(path) === expectedSha256) return;
183
184 mkdirSync(dirname(path), { recursive: true });
185 const tempPath = `${path}.${process.pid}.${Date.now()}.tmp`;
186 writeFileSync(tempPath, bytes, { mode: mode ?? 0o644 });
187
188 try {
189 renameSync(tempPath, path);
190 return;
191 } catch {
192 if (readFileSha256(path) === expectedSha256) {
193 rmSync(tempPath, { force: true });
194 return;
195 }
196 }
197
198 try {
199 rmSync(path, { force: true });
200 renameSync(tempPath, path);
201 } catch (error) {
202 rmSync(tempPath, { force: true });
203 if (readFileSha256(path) === expectedSha256) return;
204 throw error;
205 }
206}
207
208function ensureEntryFile(cacheRoot: string): void {
209 const entryPath = join(cacheRoot, 'node_modules', '.kimi-native-entry.cjs');

Callers 2

ensureEntryFileFunction · 0.70
ensureNativeAssetTreeFunction · 0.70

Calls 2

readFileSha256Function · 0.70
nowMethod · 0.65

Tested by

no test coverage detected