Skip to content

sync: open file with nonblock#10765

Open
reubenwong97 wants to merge 4 commits intouutils:mainfrom
reubenwong97:patch/sync-timeout
Open

sync: open file with nonblock#10765
reubenwong97 wants to merge 4 commits intouutils:mainfrom
reubenwong97:patch/sync-timeout

Conversation

@reubenwong97
Copy link
Contributor

Closes #10736

open_file in tail opened files with the correct flags for fifo. it has been moved to uucore::fs, and re-used in sync. invalid command now exits immediately.

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

GNU testsuite comparison:

GNU test failed: tests/factor/t10. tests/factor/t10 is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/factor/t27. tests/factor/t27 is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/factor/t30. tests/factor/t30 is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/factor/t31. tests/factor/t31 is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/factor/t32. tests/factor/t32 is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/factor/t35. tests/factor/t35 is passing on 'main'. Maybe you have to rebase?

#[cfg(any(target_os = "linux", target_os = "android"))]
fn open_and_reset_nonblock(path: &str) -> UResult<File> {
let f = File::open(path).map_err_context(|| path.to_string())?;
let f = open_file(path.as_ref(), true).map_err_context(|| path.to_string())?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm sorry, now that I'm testing the implementation with tail is not passing a bunch of use cases that I was thinking of and I think we won't actually be able to share the tail implementation. I'm going to post those use cases soon

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ideally we should make the cases that we are different from the gnu implementation into integration test cases

Copy link
Collaborator

Choose a reason for hiding this comment

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

These are the main issues I see, because some of these behaviors are different than tail it looks like we are unable to use the same file:

#Write-only file uutils fails
echo test > /tmp/t && chmod 200 /tmp/t && sync --data /tmp/t

 # FIFO without flags uutils does global sync (ignores file)
 mkfifo /tmp/f && timeout 2 sync /tmp/f

 # FIFO --data — both error, but different messages
 mkfifo /tmp/f && timeout 2 sync --data /tmp/f
 # GNU:   "sync: error syncing '/tmp/f': Invalid argument"
 # uutils: "sync: Invalid input"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe just for now can we start with just replacing this with:

  let file = match OpenOptions::new()
      .read(true)
      .custom_flags(libc::O_NONBLOCK)
      .open(path)

and adding the integration test for the use case in the issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, will do. I couldn't find a good common place as well. feature::fs was my first thought, but that's feature gated and I wasn't too sure about forcing sync to have that feature as well.

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

GNU testsuite comparison:

Skipping an intermittent issue tests/shuf/shuf-reservoir (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/sort/sort-stale-thread-mem (passes in this run but fails in the 'main' branch)

@reubenwong97 reubenwong97 changed the title fs, sync: move open_file to shared helper sync: open file with nonblock Feb 6, 2026
@reubenwong97
Copy link
Contributor Author

reubenwong97 commented Feb 6, 2026

Hi @ChrisDryden ,
I've updated the file read and added a test case. Thanks!

path = "src/sync.rs"

[dependencies]
libc = { workspace = true }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry for the nits, should be good to go right after this but can you use nix:libc so that we don't have to add a new dependency here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out, removed the extra dependency

let f = OpenOptions::new()
.read(true)
.custom_flags(libc::O_NONBLOCK)
.open(path)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Whoops missed this, the error message changed here?

.map_err_context(|| path.to_string()) 

Mind adding the error message to the integration test so we don't regress?

Copy link
Contributor Author

@reubenwong97 reubenwong97 Feb 7, 2026

Choose a reason for hiding this comment

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

Added new messages to the locales and mapped_err_context to the syncfs and fdatasync calls so we can get:

❯ timeout 2 ~/code/projects/rust/coreutils/target/release/coreutils sync --data /tmp/testfifo
sync: error syncing '/tmp/testfifo': Invalid input

instead of just:

timeout 2 ~/code/projects/rust/coreutils/target/release/coreutils sync --data /tmp/testfifo
sync: Invalid input

Updated the test to reflect this.

@github-actions
Copy link

github-actions bot commented Feb 7, 2026

GNU testsuite comparison:

Congrats! The gnu test tests/tail/retry is no longer failing!

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.

sync: gnu compatibility for FIFO's

3 participants