Skip to content

directory handles: add Dir::metadata#157192

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
RalfJung:dir-metadata
May 31, 2026
Merged

directory handles: add Dir::metadata#157192
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
RalfJung:dir-metadata

Conversation

@RalfJung

Copy link
Copy Markdown
Member

Adds a metadata method to the fs::Dir type so that one can fetch the metadata of a directory directly from a handle. This is very similar to File::metadata. In fact we reuse the existing implementation, which reduces code duplication but also is a bit hacky.

r? @the8472
Tracking issue: #120426

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 31, 2026
@RalfJung

Copy link
Copy Markdown
Member Author

@bors try jobs=*apple*,*freebsd*,*various*

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request May 31, 2026
directory handles: add Dir::metadata


try-job: *apple*
try-job: *freebsd*
try-job: *various*
@the8472

the8472 commented May 31, 2026

Copy link
Copy Markdown
Member

You need to add the method to the fallback impl in fs::common too.

@RalfJung

Copy link
Copy Markdown
Member Author

@bors try jobs=*apple*,*freebsd*,*various*,x86_64-msvc*

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request May 31, 2026
directory handles: add Dir::metadata


try-job: *apple*
try-job: *freebsd*
try-job: *various*
try-job: x86_64-msvc*
@the8472

the8472 commented May 31, 2026

Copy link
Copy Markdown
Member

LGTM, r=me when tests pass

@rust-log-analyzer

This comment has been minimized.

@RalfJung

RalfJung commented May 31, 2026

Copy link
Copy Markdown
Member Author

Well that's a bit tricky... library/std/src/sys/fs/unix/dir.rs can't construct a Metadata but library/std/src/sys/fs/common.rs can't construct a FileAttr, so there's no signature for fs_imp::Dir::metadata that can be implemented everywhere. Seems like we'll have to make the field of fs::Metadata public (to the crate)?

@the8472

the8472 commented May 31, 2026

Copy link
Copy Markdown
Member

There's the std-private IntoInner trait, that should let you convert Metadata back into FileAttr.

@RalfJung

Copy link
Copy Markdown
Member Author

Thanks! I had to add an impl IntoInner<fs_imp::FileAttr> for Metadata, that seems to work. :)

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 31, 2026
@rust-bors

rust-bors Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

💔 Test for ee502b2 failed: CI. Failed jobs:

@RalfJung

Copy link
Copy Markdown
Member Author

@bors try jobs=*various*,*illumos*,*solaris*

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request May 31, 2026
directory handles: add Dir::metadata


try-job: *various*
try-job: *illumos*
try-job: *solaris*
@rust-bors

rust-bors Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 4a57b6c (4a57b6ce18b8120a25096be132fe7908b2fe585f, parent: 9e293ae9f8abecb0be5105787d181518c9012a19)

@RalfJung

Copy link
Copy Markdown
Member Author

@bors r=the8472

@rust-bors

rust-bors Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 18159d4 has been approved by the8472

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 31, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request May 31, 2026
directory handles: add Dir::metadata

Adds a `metadata` method to the `fs::Dir` type so that one can fetch the metadata of a directory directly from a handle. This is very similar to `File::metadata`. In fact we reuse the existing implementation, which reduces code duplication but also is a bit hacky.

r? @the8472
Tracking issue: rust-lang#120426
rust-bors Bot pushed a commit that referenced this pull request May 31, 2026
Rollup of 4 pull requests

Successful merges:

 - #157192 (directory handles: add Dir::metadata)
 - #157171 ( rustdoc: Separate the caches for synthetic auto trait & blanket impls)
 - #157185 (Don't lower `inner_span` multiple times)
 - #157211 (use custom `Exhaustive` enum instead of `bool`)
@rust-bors rust-bors Bot merged commit 935b856 into rust-lang:main May 31, 2026
13 checks passed
@rustbot rustbot added this to the 1.98.0 milestone May 31, 2026
rust-timer added a commit that referenced this pull request May 31, 2026
Rollup merge of #157192 - RalfJung:dir-metadata, r=the8472

directory handles: add Dir::metadata

Adds a `metadata` method to the `fs::Dir` type so that one can fetch the metadata of a directory directly from a handle. This is very similar to `File::metadata`. In fact we reuse the existing implementation, which reduces code duplication but also is a bit hacky.

r? @the8472
Tracking issue: #120426
@RalfJung RalfJung deleted the dir-metadata branch June 1, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants