MCPcopy Create free account
hub / github.com/cloudflare/agents / cp

Method cp

packages/shell/src/filesystem.ts:1221–1262  ·  view source on GitHub ↗
(
    src: string,
    dest: string,
    opts?: { recursive?: boolean }
  )

Source from the content-addressed store, hash-verified

1219 // ── Copy / Move ───────────────────────────────────────────────
1220
1221 async cp(
1222 src: string,
1223 dest: string,
1224 opts?: { recursive?: boolean }
1225 ): Promise<void> {
1226 await this.ensureInit();
1227 const srcNorm = normalizePath(src);
1228 const destNorm = normalizePath(dest);
1229 const srcStat = await this.lstat(srcNorm);
1230 if (!srcStat) throw new Error(`ENOENT: no such file or directory: ${src}`);
1231
1232 if (srcStat.type === "symlink") {
1233 const target = await this.readlink(srcNorm);
1234 await this.symlink(target, destNorm);
1235 return;
1236 }
1237
1238 if (srcStat.type === "directory") {
1239 if (!opts?.recursive) {
1240 throw new Error(
1241 `EISDIR: cannot copy directory without recursive: ${src}`
1242 );
1243 }
1244 await this.mkdir(destNorm, { recursive: true });
1245 for (const child of await this.readDir(srcNorm)) {
1246 await this.cp(child.path, `${destNorm}/${child.name}`, opts);
1247 }
1248 return;
1249 }
1250
1251 const bytes = await this.readFileBytes(srcNorm);
1252 if (bytes) {
1253 await this.writeFileBytes(destNorm, bytes, srcStat.mimeType);
1254 } else {
1255 await this.writeFile(destNorm, "", srcStat.mimeType);
1256 }
1257 this._observe("workspace:cp", {
1258 src: srcNorm,
1259 dest: destNorm,
1260 recursive: !!opts?.recursive
1261 });
1262 }
1263
1264 async mv(
1265 src: string,

Callers 1

mvMethod · 0.95

Calls 11

ensureInitMethod · 0.95
lstatMethod · 0.95
readlinkMethod · 0.95
symlinkMethod · 0.95
mkdirMethod · 0.95
readDirMethod · 0.95
readFileBytesMethod · 0.95
writeFileBytesMethod · 0.95
writeFileMethod · 0.95
_observeMethod · 0.95
normalizePathFunction · 0.70

Tested by

no test coverage detected