coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

cp: Fix broken symlinks to parent-dir

Open luigieli opened this issue 1 year ago • 12 comments

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.

luigieli avatar Jun 13 '24 21:06 luigieli

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)

github-actions[bot] avatar Jun 14 '24 12:06 github-actions[bot]

GNU testsuite comparison:

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

github-actions[bot] avatar Jun 22 '24 08:06 github-actions[bot]

GNU testsuite comparison:

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

github-actions[bot] avatar Jul 06 '24 06:07 github-actions[bot]

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

BenWiederhake avatar Jul 07 '24 20:07 BenWiederhake

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 avatar Jul 07 '24 21:07 luigieli

@luigieli do you have an update on this? thanks

sylvestre avatar Aug 13 '24 21:08 sylvestre

@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 avatar Aug 17 '24 05:08 luigieli

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.

luigieli avatar Aug 19 '24 23:08 luigieli

Fails on Windows on:


--- TRY 3 STDERR:        coreutils::tests test_cp::test_symlink_mode_overwrite ---
thread 'test_cp::test_symlink_mode_overwrite' panicked at tests\by-util\test_cp.rs:5908:14:
assertion failed: `(left == right)`

Diff < left / right > :
<cp: .\t: can make relative symbolic links only in current directory
<cp: .\t: can make relative symbolic links only in current directory
>cp: will not overwrite just-created '.\t' with 'b\t'
 


stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library/std\src\panicking.rs:662
   1: core::panicking::panic_fmt
             at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library/core\src\panicking.rs:74
   2: tests::common::util::CmdResult::stderr_is<ref$<str$> >
             at .\tests\common\util.rs:586
   3: tests::common::util::CmdResult::stderr_only<ref$<str$> >
             at .\tests\common\util.rs:642
   4: tests::test_cp::test_symlink_mode_overwrite
             at .\tests\by-util\test_cp.rs:5903
   5: tests::test_cp::test_symlink_mode_overwrite::closure$0
             at .\tests\by-util\test_cp.rs:5885
   6: core::ops::function::FnOnce::call_once<tests::test_cp::test_symlink_mode_overwrite::closure_env$0,tuple$<> >
             at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library\core\src\ops\function.rs:250
   7: core::ops::function::FnOnce::call_once
             at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library/core\src\ops\function.rs:250
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

sylvestre avatar Nov 02 '24 09:11 sylvestre

@luigieli it is still marked as draft, are you still working on it? thanks

sylvestre avatar Dec 02 '24 09:12 sylvestre

@sylvestre Yes, I'm still trying to debug and solve the fails on Windows. I'll bring news as soon as possible. Appreciate the waiting. Thanks!

luigieli avatar Dec 03 '24 01:12 luigieli

ok, thanks :)

sylvestre avatar Feb 16 '25 23:02 sylvestre

please reopen when ready!

sylvestre avatar Apr 17 '25 19:04 sylvestre