test: add known issue test for fs.cpSync dereference bug · nodejs/node@f9f3dc9

1+

'use strict';

2+3+

// Refs: https://github.com/nodejs/node/issues/58939

4+

//

5+

// The cpSync function is not correctly handling the `dereference` option.

6+

// In this test, both the cp and cpSync functions are attempting to copy

7+

// a file over a symlinked directory. In the cp case it works fine. In the

8+

// cpSync case it fails with an error.

9+10+

const common = require('../common');

11+12+

const {

13+

cp,

14+

cpSync,

15+

mkdirSync,

16+

symlinkSync,

17+

writeFileSync,

18+

} = require('fs');

19+20+

const {

21+

join,

22+

} = require('path');

23+24+

const tmpdir = require('../common/tmpdir');

25+

tmpdir.refresh();

26+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+32+

writeFileSync(pathA, 'file a');

33+

mkdirSync(pathB);

34+

symlinkSync(pathB, pathC, 'dir');

35+

symlinkSync(pathB, pathD, 'dir');

36+37+

cp(pathA, pathD, { dereference: false }, common.mustSucceed());

38+39+

cpSync(pathA, pathC, { dereference: false });