MCPcopy
hub / github.com/cloudflare/capnweb / copyAssets

Function copyAssets

packages/capnweb-validate/src/transform/run.ts:221–260  ·  view source on GitHub ↗
(
  assets: Set<string>,
  cwd: string,
  out: string,
  written: Set<string>
)

Source from the content-addressed store, hash-verified

219}
220
221async function copyAssets(
222 assets: Set<string>,
223 cwd: string,
224 out: string,
225 written: Set<string>
226): Promise<number> {
227 let copied = 0;
228 let realCwd = await realpath(cwd);
229 let realOut = await realpath(out).catch(() => out);
230 for (let src of assets) {
231 if (!isInsideOrEqual(cwd, src)) continue;
232 if (isInsideOrEqual(out, src)) continue;
233 if (hasIgnoredPathPart(src, cwd)) continue;
234 let dest = resolve(out, relative(cwd, src));
235 if (written.has(dest)) continue;
236 if (!isInsideOrEqual(out, dest)) continue;
237 let stat: Awaited<ReturnType<typeof lstat>>;
238 let copyFrom = src;
239 try {
240 if (await hasSymlinkParentPathPart(src, cwd)) continue;
241 stat = await lstat(src);
242 if (stat.isSymbolicLink()) {
243 let realSrc = await realpath(src);
244 if (!isInsideOrEqual(realCwd, realSrc)) continue;
245 if (isInsideOrEqual(realOut, realSrc)) continue;
246 if (hasIgnoredPathPart(realSrc, realCwd)) continue;
247 copyFrom = realSrc;
248 stat = await lstat(realSrc);
249 }
250 } catch {
251 continue;
252 }
253 if (!stat.isFile()) continue;
254 await mkdir(dirname(dest), { recursive: true });
255 await copyFile(copyFrom, dest);
256 written.add(dest);
257 copied++;
258 }
259 return copied;
260}

Callers 1

runBuildFunction · 0.85

Calls 4

isInsideOrEqualFunction · 0.85
hasIgnoredPathPartFunction · 0.85
hasSymlinkParentPathPartFunction · 0.85
catchMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…