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: Fix broken symlinks to parent-dir #6464

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

luigieli
Copy link

According to the GNU cp official documentation, a symlink is only created if all source paths are absolute, unless the destination files are in the current directory.

This fix solves this GNU cp incompatibility by:

  • Adding verifications when handling symlinks, to ensure that a symlink with relative path are only created if the destination is within the current directory.
  • Adding unit tests to cover this modifications, and ensure the behavior is correctly align with GNU documentation.

Fixes #6385.

According to the GNU cp official documentation[1], a symlink is only
created if all source paths are absolute, unless the destination files
are in the current directory.

This fix solves this GNU cp incompatibility by:
- Adding verifications when handling symlinks, to ensure that a symlink
  with relative path are only created if the destination is within the
  current directory.
- Adding unit tests to cover this modifications, and ensure the behavior
  is correctly align with GNU documentation.

[1]:
https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html#index-_002ds-16
@cakebaker cakebaker force-pushed the cp-fix-broken-symlinks-to-parent-dir branch from 61f114c to 0589e94 Compare June 14, 2024 11:59
Copy link

GNU testsuite comparison:

GNU test failed: tests/timeout/timeout. tests/timeout/timeout is passing on 'main'. Maybe you have to rebase?
Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)

Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/timeout/timeout is no longer failing!

Copy link
Collaborator

@BenWiederhake BenWiederhake left a comment

Choose a reason for hiding this comment

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

Looks good! The new feature is in a sensible place, the tests cover both the positive and the negative case, awesome.

I can't merge this yet because GitHub says there are conflicts (even though they actually are only trivial conflicts), and also because one of the tests is broken (see below).

ucmd.args(&["--symbolic", "file", "dir"])
.fails()
.no_stdout()
.stderr_is("cp: dir/file: can make relative symbolic links only in current directory\n");
Copy link
Collaborator

Choose a reason for hiding this comment

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

This fails on Windows, because there it generates the error message with a backslash.

Copy link
Author

Choose a reason for hiding this comment

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

Oh I see! Really appreciate the review. About the broken test in Windows, I think stderr_contains() can be used instead of stderr_is() to address this, I'm going to try it to solve this compatibility issue with Windows, along with the conflicts.

luigieli and others added 2 commits July 5, 2024 21:16
Due to the nature of Windows using backslash instead of regular slash to
separate the directories, the test would fail because it was using a
hardcoded output. To address that was changed the method to evaluate the
output to a more flexible one, that way the backslash would not be a
problem.
Copy link

github-actions bot commented Jul 6, 2024

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)

@luigieli luigieli marked this pull request as draft July 6, 2024 11:02
@luigieli luigieli marked this pull request as ready for review July 6, 2024 11:23
@BenWiederhake
Copy link
Collaborator

CI still says the new test is broken, and at first glance the error message seems reasonable.

@luigieli
Copy link
Author

luigieli commented Jul 7, 2024

CI still says the new test is broken, and at first glance the error message seems reasonable.

The error caused by the backslash in Windows was solved, but there are still 4 tests failing only in Windows, I'll try to figure out why of those failures.

@luigieli luigieli marked this pull request as draft July 22, 2024 01:17
@sylvestre
Copy link
Contributor

@luigieli do you have an update on this? thanks

@luigieli
Copy link
Author

@sylvestre Sorry for disappearing, I was really busy due to college, so I couldn't exhaust my debugging options and the bugs in Windows are still persisting. Would it be okay if I bring you a more detailed update on this by Monday?

@luigieli
Copy link
Author

As I promised, I tried to debug the Windows errors. I used a virtual machine with Windows 11 in it to try reproducing the errors, but it was unsuccessful, for some reason when I cargo test in the VM, almost no tests were made, after activating developer mode in Windows, I could indeed run the tests, but all of them passed, even the ones that are failing in the CI. I'm not so used to windows, so I would appreciate any ideas on how to proceed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cp: Should refuse to create broken symlinks to parent-dir
3 participants