( src: string | URL, dest: string | URL, options: InternalCopyOptions, )
| 42 | } |
| 43 | |
| 44 | async 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 | |
| 72 | function ensureValidCopySync( |
| 73 | src: string | URL, |
no outgoing calls
no test coverage detected