MCPcopy Create free account
hub / github.com/denoland/std / ensureValidCopy

Function ensureValidCopy

fs/copy.ts:44–70  ·  view source on GitHub ↗
(
  src: string | URL,
  dest: string | URL,
  options: InternalCopyOptions,
)

Source from the content-addressed store, hash-verified

42}
43
44async function ensureValidCopy(
45 src: string | URL,
46 dest: string | URL,
47 options: InternalCopyOptions,
48): Promise<Deno.FileInfo | undefined> {
49 let destStat: Deno.FileInfo;
50
51 try {
52 destStat = await Deno.lstat(dest);
53 } catch (err) {
54 if (err instanceof Deno.errors.NotFound) {
55 return;
56 }
57 throw err;
58 }
59
60 if (options.isFolder && !destStat.isDirectory) {
61 throw new Error(
62 `Cannot overwrite non-directory '${dest}' with directory '${src}'`,
63 );
64 }
65 if (!options.overwrite) {
66 throw new Deno.errors.AlreadyExists(`'${dest}' already exists.`);
67 }
68
69 return destStat;
70}
71
72function ensureValidCopySync(
73 src: string | URL,

Callers 3

copyFileFunction · 0.85
copySymLinkFunction · 0.85
copyDirFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected