@@ -15,25 +15,38 @@ const {
1515 mkdirSync,
1616 symlinkSync,
1717 writeFileSync,
18+ readFileSync,
19+ statSync
1820} = require ( 'fs' ) ;
1921
2022const {
2123 join,
2224} = require ( 'path' ) ;
2325
26+ const assert = require ( 'assert/strict' ) ;
27+
2428const tmpdir = require ( '../common/tmpdir' ) ;
2529tmpdir . refresh ( ) ;
2630
27- const pathA = join ( tmpdir . path , 'a' ) ;
28- const pathB = join ( tmpdir . path , 'b' ) ;
29- const pathC = join ( tmpdir . path , 'c' ) ;
30- const pathD = join ( tmpdir . path , 'd' ) ;
31+ const pathA = join ( tmpdir . path , 'a' ) ; // file
32+ const pathB = join ( tmpdir . path , 'b' ) ; // directory
33+ const pathC = join ( tmpdir . path , 'c' ) ; // c -> b
34+ const pathD = join ( tmpdir . path , 'd' ) ; // d -> b
3135
3236writeFileSync ( pathA , 'file a' ) ;
3337mkdirSync ( pathB ) ;
3438symlinkSync ( pathB , pathC , 'dir' ) ;
3539symlinkSync ( pathB , pathD , 'dir' ) ;
3640
37- cp ( pathA , pathD , { dereference : false } , common . mustSucceed ( ) ) ;
41+ cp ( pathA , pathD , { dereference : false } , common . mustSucceed ( ( ) => {
42+ // d is now a file, not a symlink
43+ assert . strictEqual ( readFileSync ( pathA , 'utf-8' ) , readFileSync ( pathD , 'utf-8' ) ) ;
44+ assert . ok ( statSync ( pathA ) . isFile ( ) ) ;
45+ assert . ok ( statSync ( pathD ) . isFile ( ) ) ;
46+ } ) ) ;
3847
3948cpSync ( pathA , pathC , { dereference : false } ) ;
49+
50+ assert . strictEqual ( readFileSync ( pathA , 'utf-8' ) , readFileSync ( pathC , 'utf-8' ) ) ;
51+ assert . ok ( statSync ( pathA ) . isFile ( ) ) ;
52+ assert . ok ( statSync ( pathC ) . isFile ( ) ) ;
0 commit comments