Skip to content

cp: implement sparse copy support for windows#12686

Merged
sylvestre merged 8 commits into
uutils:mainfrom
nikolalukovic:fix/12186
Jul 7, 2026
Merged

cp: implement sparse copy support for windows#12686
sylvestre merged 8 commits into
uutils:mainfrom
nikolalukovic:fix/12186

Conversation

@nikolalukovic

Copy link
Copy Markdown
Contributor

Attempts to fix: #12186

@oech3

This comment was marked as resolved.

@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)
Skip an intermittent issue tests/pr/bounded-memory (was skipped on 'main', now failing)
Skip an intermittent issue tests/tail/tail-n0f (was skipped on 'main', now failing)

@nikolalukovic

Copy link
Copy Markdown
Contributor Author

@oech3 Ready for review. Failing check is unrelated to these changes.

@sylvestre

Copy link
Copy Markdown
Contributor

please add or enable relevant tests, thanks

@nikolalukovic

Copy link
Copy Markdown
Contributor Author

please add or enable relevant tests, thanks

There are three new tests for this feature on windows, since this is windows specific PR. Is there anything else I could have done that I missed?

@nikolalukovic

Copy link
Copy Markdown
Contributor Author

@sylvestre bump

1 similar comment
@nikolalukovic

Copy link
Copy Markdown
Contributor Author

@sylvestre bump

@Alonely0 Alonely0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Barring a few issues, this looks like a great addition. However, I find myself wishing we could use a safe API of the windows-*/winapi_util crates, instead of raw win32 unsafe calls. If it's not available there, would you add safe wrappers of these to uucore::fs and use them here?

Also, can someone more familiar with Windows I/O take a second look? I can only comment on my limited experience here.

Comment thread src/uu/cp/src/platform/windows.rs Outdated
Comment thread src/uu/cp/src/platform/windows.rs Outdated
Comment thread src/uu/cp/src/platform/windows.rs Outdated
Comment thread src/uu/cp/src/platform/windows.rs Outdated
Comment thread src/uu/cp/src/platform/windows.rs Outdated
Comment thread src/uu/cp/src/platform/windows.rs Outdated
Comment thread src/uu/cp/src/platform/windows.rs
@nikolalukovic
nikolalukovic requested review from Alonely0 and oech3 July 5, 2026 17:34

@Alonely0 Alonely0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Super nice! This has definitely improved a lot since I last took a lot at it; I especially like the safe wrappers around winapi. I don't have much to comment, but I have spotted a few issues that are worth taking a look at.

Comment thread src/uu/cp/src/platform/windows.rs Outdated
copy_debug.sparse_detection = SparseDebug::Zeros;
sparse_copy(&mut src_file, dest).map_err(context_err)?;
} else {
std::fs::copy(source, dest).map_err(context_err)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can't we just reuse the open handle and do std::io::copy(&src_file, dest)? This especially concerns me due to possible TOCTOUs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Eh, here we get to decide which way to go. If we keep fs::copy(CopyFileExW) we get kernel copy path, auto ReFS block cloning and SMB offload on hotpaths. And while there could be a race we never get incorrect content. We would give up all of that if we go with io::copy. I'm for fs::copy but if the pros don't matter I'll revert to io::copy.

@Alonely0 Alonely0 Jul 6, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm it's true there's no really room for harm, as with the other one. It can be kept as-is then, but please document it as intentional :)

EDIT: it seems it was already, but GitHub decided not to update the diff lol. Okay, this is an A-OK from me.

Comment thread src/uu/cp/src/platform/windows.rs Outdated
Comment thread src/uu/cp/src/platform/windows.rs Outdated
@nikolalukovic
nikolalukovic requested a review from Alonely0 July 6, 2026 15:16

@Alonely0 Alonely0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A-OK. High quality code that enables missing functionality on Windows.

@sylvestre
sylvestre merged commit 2adb6cd into uutils:main Jul 7, 2026
176 checks passed
oech3 pushed a commit to oech3/coreutils that referenced this pull request Jul 7, 2026
@nikolalukovic
nikolalukovic deleted the fix/12186 branch July 7, 2026 11:26
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.

truncate and cp: sparse could be supported on Windows

4 participants