MCPcopy Index your code
hub / github.com/nodejs/node / checkPaths

Function checkPaths

lib/internal/fs/cp/cp.js:73–120  ·  view source on GitHub ↗
(src, dest, opts)

Source from the content-addressed store, hash-verified

71}
72
73async 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
122function areIdentical(srcStat, destStat) {
123 return destStat.ino && destStat.dev && destStat.ino === srcStat.ino &&

Callers 2

cpFnFunction · 0.85
copyDirFunction · 0.85

Calls 5

areIdenticalFunction · 0.85
isSrcSubdirFunction · 0.85
getStatsFunction · 0.70
filterMethod · 0.65
isDirectoryMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…