xgbtxy opened a new pull request, #9075:
URL: https://github.com/apache/opendal/pull/9075
# Which issue does this PR close?
Closes #9074.
# Rationale for this change
In `services::Fs`, `is_same_file` uses `(dev(), ino())` on Unix to catch
both symlinks and hard links before calling `tokio::fs::copy`, while non-Unix
platforms compare `tokio::fs::canonicalize(from) ==
tokio::fs::canonicalize(to)`. On Windows NTFS, hard links have distinct
canonical paths, so `is_same_file` returns `false` and `op.copy("real.txt",
"hard.txt")` fails inside `tokio::fs::copy` with `ErrorKind::Unexpected`
(`ERROR_SHARING_VIOLATION`, os error 32) instead of returning
`ErrorKind::IsSameFile`.
# What changes are included in this PR?
- Add a `#[cfg(windows)]` `windows_is_same_file` implementation in
`core/services/fs/src/core.rs` that opens both handles simultaneously and
compares `(dwVolumeSerialNumber, nFileIndexHigh, nFileIndexLow)` via
`kernel32::GetFileInformationByHandle`, falling back to `std::fs::canonicalize`
if opening fails or a filesystem reports an all-zero file ID. No new Cargo
dependencies are added.
- Add `test_copy_same_file_via_hardlink_preserves_content` covering
same-path and hard-link self-copy rejection (`ErrorKind::IsSameFile`) as well
as normal copying to a distinct file on all platforms (including Windows).
# Are there any user-facing changes?
On Windows, `services::Fs` `copy` between hard links to the same file now
returns `ErrorKind::IsSameFile` consistently with Unix instead of failing with
`ErrorKind::Unexpected` (`ERROR_SHARING_VIOLATION`).
# Breaking changes
# AI Usage Statement
- Harness: Antigravity
- Model: Gemini 3.1 Pro
- Effort: High
- Role: Investigated `is_same_file` in `opendal-service-fs`, reproduced the
Windows NTFS hard-link failure locally, implemented the
`GetFileInformationByHandle` check and cross-platform regression test, and ran
local `cargo test`, `cargo clippy`, and `cargo fmt` verification.
Unknowns/assumptions: verified on Windows 11 NTFS (`x86_64-pc-windows-msvc`);
Unix/macOS paths are validated by code inspection and CI.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]