+
Skip to content

Conversation

Luv-Ray
Copy link
Contributor

@Luv-Ray Luv-Ray commented Jun 11, 2025

fixes #7885
copy_stream doesn't clear the dest file, if dest is not a stream, clear it manually.

@Luv-Ray Luv-Ray force-pushed the fix_cp_stream_copy branch 2 times, most recently from 3f5ab10 to 0470254 Compare June 11, 2025 02:48
@Luv-Ray

This comment was marked as resolved.

Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

.open(dest)?;

let dest_filetype = dst_file.metadata()?.file_type();
let dest_is_stream = dest_filetype.is_fifo()
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done :)

@Luv-Ray

This comment was marked as resolved.

Comment on lines 2531 to 2537
#[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
Copy link
Contributor

Choose a reason for hiding this comment

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

you can probably do:

Suggested change
#[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

Copy link
Contributor Author

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

Copy link
Contributor

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 :)

Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@Luv-Ray
Copy link
Contributor Author

Luv-Ray commented Jun 11, 2025

Is there any description for this line?

if source_is_fifo {
dst_file.set_permissions(src_file.metadata()?.permissions())?;
}

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.

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)

Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)

@Luv-Ray Luv-Ray force-pushed the fix_cp_stream_copy branch from 4f6be64 to 7396d17 Compare June 27, 2025 02:21
@Luv-Ray Luv-Ray changed the title cp: fix copy from stream cp: clean existing file when copy from stream Jun 27, 2025
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

@Luv-Ray Luv-Ray force-pushed the fix_cp_stream_copy branch from 7396d17 to 1d175f3 Compare June 27, 2025 08:48
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/tee (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)

Copy link

github-actions bot commented Jul 6, 2025

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@cakebaker cakebaker merged commit 69bc6a7 into uutils:main Jul 6, 2025
76 checks passed
@cakebaker
Copy link
Contributor

Thanks!

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.

cp is is not properly cleaning existing file

3 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载