Skip to content

Add libc direct tests for unlink and symlink - #5584

Merged
RalfJung merged 3 commits into
rust-lang:masterfrom
mehmettoplu-rs:test-unlink-symlink
Nov 11, 2026
Merged

RalfJung merged 3 commits into
rust-lang:masterfrom
mehmettoplu-rs:test-unlink-symlink

Conversation

@mehmettoplu-rs

@mehmettoplu-rs mehmettoplu-rs commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Part of #3179

Windows doesn't allow regular users to create symlinks by default, so I added have_symlink_permission() to avoid test failures when the host is Windows.

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label Nov 7, 2026

@RalfJung RalfJung left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! However there are some more cases that the tests should cover.

View changes since this review

Comment thread tests/pass-dep/libc/fs.rs
fs::remove_file(&file_path).unwrap();
}

fn test_unlink() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please also test unlinking a directory.

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.

I added a test for unlinking a directory.

Comment thread tests/pass-dep/libc/fs.rs Outdated
Comment on lines +798 to +800
// Creating a symlink should succeed and point to `target`.
errno_check(unsafe { libc::symlink(c_target.as_ptr(), c_link.as_ptr()) });
assert_eq!(fs::read_link(&link).unwrap(), target);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This tests creating a symlink with an absolute path, pointing to a file. Please also test

  • pointing to a directory
  • a relative path

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.

I combined the two cases into a single block because the symlink Windows branch appends the relative target to the link's directory and then checks whether the result is a directory to decide between symlink_dir and symlink_file. This logic can only be meaningfully tested using a combination of a relative path and a directory. With an absolute path, the join does nothing; with a relative path combined with a file, even an incorrect join might coincidentally yield the correct result.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I cannot make sense of your answer. In principle there are 4 cases to consider here: relative/absolute, dir/file. Is that what you are trying to say?

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.

Yes, there are 4 cases. I misunderstood your comment, so I only added "relative + dir". I'll add "absolute + dir" and "relative + file".

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.

I have added all 4 cases.

@RalfJung

RalfJung commented Nov 7, 2026

Copy link
Copy Markdown
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: Waiting for the PR author to address review comments and removed S-waiting-on-review Status: Waiting for a review to complete labels Nov 7, 2026
@rustbot

rustbot commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@mehmettoplu-rs

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Waiting for a review to complete and removed S-waiting-on-author Status: Waiting for the PR author to address review comments labels Nov 8, 2026
Comment thread tests/pass-dep/libc/fs.rs Outdated

let dir_path = utils::prepare("miri_test_libc_unlink");
fs::create_dir(&dir_path).unwrap();
let dir_name = utils::into_c_string(&dir_path);

@RalfJung RalfJung Nov 8, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please call this c_dir_path or so. dir_name vs dir_path to indicate the C vs Rust sring distinction is not obvious at all.

View changes since the review

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.

I changed dir_name to c_dir_path.

@RalfJung

RalfJung commented Nov 8, 2026

Copy link
Copy Markdown
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: Waiting for the PR author to address review comments and removed S-waiting-on-review Status: Waiting for a review to complete labels Nov 8, 2026
@mehmettoplu-rs

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Waiting for a review to complete and removed S-waiting-on-author Status: Waiting for the PR author to address review comments labels Nov 9, 2026

@RalfJung RalfJung left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread tests/pass-dep/libc/fs.rs Resolved
Comment thread tests/pass-dep/libc/fs.rs Resolved
Comment thread tests/pass-dep/libc/fs.rs Resolved
Comment thread tests/pass-dep/libc/fs.rs Resolved
@rustbot rustbot added S-waiting-on-author Status: Waiting for the PR author to address review comments and removed S-waiting-on-review Status: Waiting for a review to complete labels Nov 10, 2026
@mehmettoplu-rs

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Waiting for a review to complete and removed S-waiting-on-author Status: Waiting for the PR author to address review comments labels Nov 10, 2026
@RalfJung
RalfJung force-pushed the test-unlink-symlink branch from b29e8d4 to 0eed2c8 Compare November 11, 2026 11:32
@rustbot

rustbot commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@RalfJung

Copy link
Copy Markdown
Member

Thanks :)

@RalfJung
RalfJung enabled auto-merge November 11, 2026 11:32
@RalfJung
RalfJung added this pull request to the merge queue Nov 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 11, 2026
@RalfJung
RalfJung enabled auto-merge November 11, 2026 12:30
@RalfJung
RalfJung added this pull request to the merge queue Nov 11, 2026
Merged via the queue into rust-lang:master with commit 443c623 Nov 11, 2026
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Waiting for a review to complete label Nov 11, 2026
@mehmettoplu-rs
mehmettoplu-rs deleted the test-unlink-symlink branch November 11, 2026 14:04
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.

3 participants