Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cp] Add test for cycle symlink #1045

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cp.js
Expand Up @@ -179,7 +179,7 @@ function cpcheckcycle(sourceDir, srcFile) {
// Do cycle check. For example:
// $ mkdir -p 1/2/3/4
// $ cd 1/2/3/4
// $ ln -s ../../3 link
// $ ln -s .. link
// $ cd ../../../..
// $ cp -RL 1 copy
var cyclecheck = common.statFollowLinks(srcFile);
Expand Down
32 changes: 13 additions & 19 deletions test/cp.js
Expand Up @@ -623,26 +623,20 @@ test('Test max depth.', t => {
// Check last directory to exist is below maxdepth.
t.truthy(shell.test('-d', `${t.context.tmp}/copytestdepth${directory32deep}`));
t.falsy(shell.test('-d', `${t.context.tmp}/copytestdepth${directory32deep}/32`));
utils.skipOnWinForEPERM(shell.ln.bind(shell, '-s', `${t.context.tmp}/0`, `${t.context.tmp}/symlinktest`), () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete it because it doesn't create symlinks to check for cycle.

if (!shell.test('-L', `${t.context.tmp}/symlinktest`)) {
t.fail();
}

// Create symlinks to check for cycle.
shell.cd(`${t.context.tmp}/0/1/2/3/4`);
t.falsy(shell.error());
shell.ln('-s', '../../../2', 'link');
t.falsy(shell.error());
shell.ln('-s', './5/6/7', 'link1');
t.falsy(shell.error());
shell.cd('../../../../../..');
t.falsy(shell.error());
t.truthy(shell.test('-d', t.context.tmp));
});

shell.cp('-r', `${t.context.tmp}/0/1`, `${t.context.tmp}/copytestdepth`);
t.falsy(shell.error());
t.truthy(shell.test('-d', `${t.context.tmp}/copytestdepth/1/2/3/4/link/3/4/link/3/4`));
});
test('Test with cycle symlink', t => {
utils.skipOnWinForEPERM(shell.ln.bind(shell, '-s', `${t.context.tmp}/0`, `${t.context.tmp}/symlinktest`), () => {
shell.mkdir('-p', `${t.context.tmp}/sub/sub1/sub2/sub3`);
shell.cd(`${t.context.tmp}/sub/sub1/sub2/sub3`);
shell.ln('-s', '..', 'link');
shell.cd('../../../../');
const result = shell.cp('-rL', 'sub', 'newsub');
t.falsy(shell.error());
t.is(result.code, 0);
t.falsy(result.stderr);
t.truthy(shell.test('-d', 'sub/sub1/sub2/sub3/link/sub3/link/sub3/link/sub3/link'));
});
});

test('cp -L follows symlinks', t => {
Expand Down