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

Fix removal of symbolic links on Windows #81

Merged
merged 2 commits into from
Jul 11, 2023
Merged

Conversation

ericcornelissen
Copy link
Owner

@ericcornelissen ericcornelissen commented Jul 7, 2023

Closes #1

Summary

Update how symlinks on Windows are removed as well as how it is tested.

Tests involving symlinks are now run conditionally on the (new) test-symlink feature on Windows in order to avoid unexpected test failures due to the elevated privileges requirement for working with symlinks on Windows.

The implementation for removing symlinks is updated such that, on Windows, removing a symlink of a directory uses std::fs::remove_dir. This appears to be necessary for removing symbolic links of directories, while using std::fs::remove_file is appears to be necessary for removing symbolic links of files.

Add conditional ignore attributes to all tests involving symlinks to
prevent them from running on Windows. Per [1,2], creating symlinks is
considered a privileged action on Windows systems. As a result, all
these tests currently fail on Windows systems unless they're run as
administrator (or similar)[^1].

To address this, the test_feature "test-symlink" has been created to
allow Windows contributors to run tests involving symbolic links
conditionally. This is documented in the Contributing Guidelines. This
test_feature is enabled by default when running `ci-*` variants of Just
commands (like other test_features).

Note that tests with pre-existing ignores for Windows due to symlinks
(i.e. those with the ignore comment "TODO: investigate symlink test
errors on Windows") are not included here. This is because those tests
fail due to a bug in the implementation of this software for Windows
where symbolic links to folders cannot be removed.

--
^1: This was not the case in the CI because (I presume) GitHub Actions
    runs things as administrator (or similar) by default.
--
1. https://doc.rust-lang.org/stable/std/os/windows/fs/fn.symlink_dir.html
2. https://doc.rust-lang.org/stable/std/os/windows/fs/fn.symlink_file.html
@ericcornelissen ericcornelissen changed the title Ignore all tests with symlinks for Windows Fix removal of symbolic links on Windows Jul 11, 2023
@codecov
Copy link

codecov bot commented Jul 11, 2023

Codecov Report

Merging #81 (7f45c96) into main (3c36ed0) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main      #81   +/-   ##
=======================================
  Coverage   98.97%   98.98%           
=======================================
  Files           1        1           
  Lines         294      295    +1     
=======================================
+ Hits          291      292    +1     
  Misses          3        3           
Impacted Files Coverage Δ
src/main.rs 98.98% <100.00%> (+<0.01%) ⬆️

@ericcornelissen ericcornelissen marked this pull request as ready for review July 11, 2023 19:48
Update the implementation of `rm::remove` to, conditionally on the
target platform, remove symbolic files either:
1. On non-Windows systems always as files (unchanged), or
2. On Windows systems as either a directory or file depending on what
   the link is pointing to.

The latter is necessary for removal of symbolic links on Windows because
otherwise users will get a `PermissionDenied` error.

All tests that were disabled on Windows for this reason previously now
run conditionally on the `test-symlink` test feature, just like all
other symlink-related tests. Except for the unit test named `symlink_to_
dir_at_ location_of_a_dir_toctou`. With the current implementation of
the `remove` function this TOCTOU scenario is handled differently on
Windows from non-Windows systems, but both outcomes are considered okay
(both versions of the test are kept to notice changes/regressions on any
platform).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working os:windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Symlink tests not working on Windows
1 participant