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 rm for symlinks pointing to directory on windows (issue #11461) #11463
Fix rm for symlinks pointing to directory on windows (issue #11461) #11463
Conversation
As above, I got 2 test failure on my Windows (Japanese), but these passed on my ubuntu.
|
// In Windows, symlink pointing to a directory can be removed using | ||
// std::fs::remove_dir instead of std::fs::remove_file. | ||
#[cfg(windows)] | ||
match f.metadata() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using and_then
?
f.metadata().and_then(|metadata|
if metadata.is_dir() { std::fs::remove_dir(&f) }
else { std::fs::remove_file(&f) }
}?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using and_then?
Indeed, it's a better way.
I'm going to refactor it.
I remember it's because windows CI have git bash installed |
Oh, it makes sense. Then, should we change the tests to be independent on platforms? Or should we note in CONTRIBUTING.md that |
We should not rely on git bash being installed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM!
For the failing test on windows, I think we can cover it in separate pr :-D
Thanks for your contribution!
- related PR: #11463 # Description Currently, `commands::complete::basic` fails on Windows without git bash. This pr fixes it. # User-Facing Changes (none) # Tests + Formatting - [x] (on Windows) `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - [x] (on Windows) `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - [x] (on Windows without git bash, Windows with git bash and Ubuntu) `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - on my Windows with Japanese lang pack: 1 test still fails. (see #11463) - [x] (on Windows and Ubuntu) `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library # After Submitting (none)
…1461) (nushell#11463) <!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> - this PR closes nushell#11461 # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> Using `std::fs::remove_dir` instead of `std::fs::remove_file` when try remove symlinks pointing to a directory on Windows. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> none # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> - [x] `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - [x] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - [x] `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - I got 2 test fails on my Windows devenv; these fails in main branch too - `commands::complete::basic` : passed on Ubuntu, failed on Windows (a bug?) - `commands::cp::copy_file_with_read_permission`: failed on Windows with Japanese environment (This test refers error message, so that fails on environments using a language except for english.) - [x] `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> This fix has no changes to user-facing interface.
- related PR: nushell#11463 # Description Currently, `commands::complete::basic` fails on Windows without git bash. This pr fixes it. # User-Facing Changes (none) # Tests + Formatting - [x] (on Windows) `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - [x] (on Windows) `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - [x] (on Windows without git bash, Windows with git bash and Ubuntu) `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - on my Windows with Japanese lang pack: 1 test still fails. (see nushell#11463) - [x] (on Windows and Ubuntu) `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library # After Submitting (none)
Description
Using
std::fs::remove_dir
instead ofstd::fs::remove_file
when try remove symlinks pointing to a directory on Windows.User-Facing Changes
none
Tests + Formatting
cargo fmt --all -- --check
to check standard code formatting (cargo fmt --all
applies these changes)cargo clippy --workspace -- -D warnings -D clippy::unwrap_used
to check that you're using the standard code stylecargo test --workspace
to check that all tests pass (on Windows make sure to enable developer mode)commands::complete::basic
: passed on Ubuntu, failed on Windows (a bug?)commands::cp::copy_file_with_read_permission
: failed on Windows with Japanese environment (This test refers error message, so that fails on environments using a language except for english.)cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"
to run the tests for the standard libraryAfter Submitting
This fix has no changes to user-facing interface.