-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
cp: clean existing file when copy from stream #8149
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
Conversation
3f5ab10
to
0470254
Compare
This comment was marked as resolved.
This comment was marked as resolved.
GNU testsuite comparison:
|
src/uu/cp/src/platform/other_unix.rs
Outdated
.open(dest)?; | ||
|
||
let dest_filetype = dst_file.metadata()?.file_type(); | ||
let dest_is_stream = dest_filetype.is_fifo() |
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.
seems that the code is duplicated, could you please move that into a function? thanks
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.
done :)
This comment was marked as resolved.
This comment was marked as resolved.
src/uu/cp/src/cp.rs
Outdated
#[cfg(unix)] | ||
let source_is_stream = | ||
file_type.is_fifo() || file_type.is_char_device() || file_type.is_block_device(); | ||
#[cfg(not(unix))] | ||
let source_is_stream = false; | ||
|
||
source_is_stream |
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.
you can probably do:
#[cfg(unix)] | |
let source_is_stream = | |
file_type.is_fifo() || file_type.is_char_device() || file_type.is_block_device(); | |
#[cfg(not(unix))] | |
let source_is_stream = false; | |
source_is_stream | |
#[cfg(unix)] | |
file_type.is_fifo() || file_type.is_char_device() || file_type.is_block_device() | |
#[cfg(not(unix))] | |
false |
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.
I got diagnostic:
attributes on expressions are experimental
see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
this compiler was built on 2025-04-26; consider upgrading it if it is out of date
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.
ok, please ignore me then :)
GNU testsuite comparison:
|
Is there any description for this line? coreutils/src/uu/cp/src/platform/other_unix.rs Lines 54 to 56 in f111113
edit: According to my tests, GNU cp doesn't reset target's permission just because the source is fifo, so I just remove these lines. |
GNU testsuite comparison:
|
GNU testsuite comparison:
|
GNU testsuite comparison:
|
4f6be64
to
7396d17
Compare
GNU testsuite comparison:
|
7396d17
to
1d175f3
Compare
GNU testsuite comparison:
|
GNU testsuite comparison:
|
Thanks! |
fixes #7885
copy_stream
doesn't clear the dest file, if dest is not a stream, clear it manually.