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

Method deleteFile

packages/shell/src/filesystem.ts:990–1015  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

988 }
989
990 async deleteFile(path: string): Promise<boolean> {
991 await this.ensureInit();
992 const normalized = normalizePath(path);
993 const T = this.tableName;
994 const rows = await this.sql.query<{
995 type: string;
996 storage_backend: string;
997 r2_key: string | null;
998 }>(
999 `SELECT type, storage_backend, r2_key FROM ${T} WHERE path = ?`,
1000 normalized
1001 );
1002 if (!rows[0]) return false;
1003 if (rows[0].type === "directory")
1004 throw new Error(`EISDIR: ${path} is a directory — use rm() instead`);
1005
1006 if (rows[0].storage_backend === "r2" && rows[0].r2_key) {
1007 const r2 = this.getR2();
1008 if (r2) await r2.delete(rows[0].r2_key);
1009 }
1010
1011 await this.sql.run(`DELETE FROM ${T} WHERE path = ?`, normalized);
1012 this.emit("delete", normalized, rows[0].type as EntryType);
1013 this._observe("workspace:delete", { path: normalized });
1014 return true;
1015 }
1016
1017 async fileExists(path: string): Promise<boolean> {
1018 await this.ensureInit();

Callers 6

mvMethod · 0.95
deleteMethod · 0.45
onChatMessageMethod · 0.45
deleteFileAtPathMethod · 0.45
clearWorkspaceMethod · 0.45
buildAppMethod · 0.45

Calls 7

ensureInitMethod · 0.95
getR2Method · 0.95
emitMethod · 0.95
_observeMethod · 0.95
normalizePathFunction · 0.70
deleteMethod · 0.65
runMethod · 0.65

Tested by

no test coverage detected