File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -3193,7 +3193,7 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
3193
3193
3194
3194
std::string dest_path_str = dest_path.string ();
3195
3195
// Check if dest_path is a subdirectory of src_path.
3196
- if (src_is_dir && dest_path_str .starts_with (src_path.string ())) {
3196
+ if (src_is_dir && dest_path. parent_path (). string () .starts_with (src_path.string ())) {
3197
3197
std::string message = " Cannot copy " + src_path.string () +
3198
3198
" to a subdirectory of self " + dest_path.string ();
3199
3199
return THROW_ERR_FS_CP_EINVAL (env, message.c_str ());
Original file line number Diff line number Diff line change @@ -24,8 +24,8 @@ import tmpdir from '../common/tmpdir.js';
24
24
tmpdir . refresh ( ) ;
25
25
26
26
let dirc = 0 ;
27
- function nextdir ( ) {
28
- return tmpdir . resolve ( `copy_${ ++ dirc } ` ) ;
27
+ function nextdir ( dirname ) {
28
+ return tmpdir . resolve ( dirname || `copy_${ ++ dirc } ` ) ;
29
29
}
30
30
31
31
// Synchronous implementation of copy.
@@ -312,6 +312,17 @@ function nextdir() {
312
312
) ;
313
313
}
314
314
315
+ // It must not throw error if attempt is made to copy to dest
316
+ // directory with same prefix as src directory
317
+ // regression test for https://github.com/nodejs/node/issues/54285
318
+ {
319
+ const src = nextdir ( 'prefix' ) ;
320
+ const dest = nextdir ( 'prefix-a' ) ;
321
+ mkdirSync ( src ) ;
322
+ mkdirSync ( dest ) ;
323
+ cpSync ( src , dest , { recursive : true } ) ;
324
+ }
325
+
315
326
// It throws error if attempt is made to copy to subdirectory of self.
316
327
{
317
328
const src = './test/fixtures/copy/kitchen-sink' ;
You can’t perform that action at this time.
0 commit comments