(
src: string | URL,
dest: string | URL,
options: CopyOptions = {},
)
| 304 | * last modification and access times to the ones of the original source files. |
| 305 | */ |
| 306 | export async function copy( |
| 307 | src: string | URL, |
| 308 | dest: string | URL, |
| 309 | options: CopyOptions = {}, |
| 310 | ) { |
| 311 | src = resolve(toPathString(src)); |
| 312 | dest = resolve(toPathString(dest)); |
| 313 | |
| 314 | if (src === dest) { |
| 315 | throw new Error("Source and destination cannot be the same"); |
| 316 | } |
| 317 | |
| 318 | const srcStat = await Deno.lstat(src); |
| 319 | |
| 320 | if (srcStat.isDirectory && isSubdir(src, dest)) { |
| 321 | throw new Error( |
| 322 | `Cannot copy '${src}' to a subdirectory of itself: '${dest}'`, |
| 323 | ); |
| 324 | } |
| 325 | |
| 326 | if (srcStat.isSymlink) { |
| 327 | await copySymLink(src, dest, options); |
| 328 | } else if (srcStat.isDirectory) { |
| 329 | await copyDir(src, dest, options); |
| 330 | } else if (srcStat.isFile) { |
| 331 | await copyFile(src, dest, options); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * Synchronously copy a file or directory (along with its contents), like |
no test coverage detected