@@ -116,31 +116,22 @@ function checkPathsSync(src, dest, opts) {
116
116
}
117
117
118
118
function getStatsSync ( src , dest , opts ) {
119
- let destStat ;
120
- const statFunc = opts . dereference ?
121
- ( file ) => statSync ( file , { bigint : true } ) :
122
- ( file ) => lstatSync ( file , { bigint : true } ) ;
123
- const srcStat = statFunc ( src ) ;
124
- try {
125
- destStat = statFunc ( dest ) ;
126
- } catch ( err ) {
127
- if ( err . code === 'ENOENT' ) return { srcStat, destStat : null } ;
128
- throw err ;
129
- }
119
+ const statFunc = opts . dereference ? statSync : lstatSync ;
120
+ const srcStat = statFunc ( src , { bigint : true , throwIfNoEntry : true } ) ;
121
+ const destStat = statFunc ( dest , { bigint : true , throwIfNoEntry : false } ) ;
130
122
return { srcStat, destStat } ;
131
123
}
132
124
133
125
function checkParentPathsSync ( src , srcStat , dest ) {
134
126
const srcParent = resolve ( dirname ( src ) ) ;
135
127
const destParent = resolve ( dirname ( dest ) ) ;
136
128
if ( destParent === srcParent || destParent === parse ( destParent ) . root ) return ;
137
- let destStat ;
138
- try {
139
- destStat = statSync ( destParent , { bigint : true } ) ;
140
- } catch ( err ) {
141
- if ( err . code === 'ENOENT' ) return ;
142
- throw err ;
129
+ const destStat = statSync ( destParent , { bigint : true , throwIfNoEntry : false } ) ;
130
+
131
+ if ( destStat === undefined ) {
132
+ return ;
143
133
}
134
+
144
135
if ( areIdentical ( srcStat , destStat ) ) {
145
136
throw new ERR_FS_CP_EINVAL ( {
146
137
message : `cannot copy ${ src } to a subdirectory of self ${ dest } ` ,
0 commit comments