(src, dest, opts)
| 71 | } |
| 72 | |
| 73 | async function checkPaths(src, dest, opts) { |
| 74 | if (opts.filter && !(await opts.filter(src, dest))) { |
| 75 | return { __proto__: null, skipped: true }; |
| 76 | } |
| 77 | const { 0: srcStat, 1: destStat } = await getStats(src, dest, opts); |
| 78 | if (destStat) { |
| 79 | if (areIdentical(srcStat, destStat)) { |
| 80 | throw new ERR_FS_CP_EINVAL({ |
| 81 | message: 'src and dest cannot be the same', |
| 82 | path: dest, |
| 83 | syscall: 'cp', |
| 84 | errno: EINVAL, |
| 85 | code: 'EINVAL', |
| 86 | }); |
| 87 | } |
| 88 | if (srcStat.isDirectory() && !destStat.isDirectory()) { |
| 89 | throw new ERR_FS_CP_DIR_TO_NON_DIR({ |
| 90 | message: `cannot overwrite non-directory ${dest} ` + |
| 91 | `with directory ${src}`, |
| 92 | path: dest, |
| 93 | syscall: 'cp', |
| 94 | errno: EISDIR, |
| 95 | code: 'EISDIR', |
| 96 | }); |
| 97 | } |
| 98 | if (!srcStat.isDirectory() && destStat.isDirectory()) { |
| 99 | throw new ERR_FS_CP_NON_DIR_TO_DIR({ |
| 100 | message: `cannot overwrite directory ${dest} ` + |
| 101 | `with non-directory ${src}`, |
| 102 | path: dest, |
| 103 | syscall: 'cp', |
| 104 | errno: ENOTDIR, |
| 105 | code: 'ENOTDIR', |
| 106 | }); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | if (srcStat.isDirectory() && isSrcSubdir(src, dest)) { |
| 111 | throw new ERR_FS_CP_EINVAL({ |
| 112 | message: `cannot copy ${src} to a subdirectory of self ${dest}`, |
| 113 | path: dest, |
| 114 | syscall: 'cp', |
| 115 | errno: EINVAL, |
| 116 | code: 'EINVAL', |
| 117 | }); |
| 118 | } |
| 119 | return { __proto__: null, srcStat, destStat, skipped: false }; |
| 120 | } |
| 121 | |
| 122 | function areIdentical(srcStat, destStat) { |
| 123 | return destStat.ino && destStat.dev && destStat.ino === srcStat.ino && |
no test coverage detected
searching dependent graphs…