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

Function ensureFile

apps/kimi-code/src/native/web-assets.ts:78–103  ·  view source on GitHub ↗
(path: string, bytes: Buffer, expectedSha256: string)

Source from the content-addressed store, hash-verified

76}
77
78function ensureFile(path: string, bytes: Buffer, expectedSha256: string): void {
79 if (readFileSha256(path) === expectedSha256) return;
80
81 mkdirSync(dirname(path), { recursive: true });
82 const tempPath = `${path}.${process.pid}.${Date.now()}.tmp`;
83 writeFileSync(tempPath, bytes, { mode: 0o644 });
84
85 try {
86 renameSync(tempPath, path);
87 return;
88 } catch {
89 if (readFileSha256(path) === expectedSha256) {
90 rmSync(tempPath, { force: true });
91 return;
92 }
93 }
94
95 try {
96 rmSync(path, { force: true });
97 renameSync(tempPath, path);
98 } catch (error) {
99 rmSync(tempPath, { force: true });
100 if (readFileSha256(path) === expectedSha256) return;
101 throw error;
102 }
103}
104
105function assertSafeRelativePath(relativePath: string): void {
106 if (

Callers 1

getNativeWebAssetsDirFunction · 0.70

Calls 2

readFileSha256Function · 0.70
nowMethod · 0.65

Tested by

no test coverage detected