Skip to content

Consider adding a Dir::into_fd() method #1455

@linkmauve

Description

@linkmauve

Currently, once an OwnedFd has been passed to rustix::fs::Dir, there is no way to reuse it.

My usecase is to call rustix::fs::openat() and rustix::fs::statat() on it after I’m done with the iteration (or even during, I don’t think there is any issue with that since getdents64(2) is stateless).

My current solution is to call rustix::io::dup() on the fd before creating the Dir, but that shouldn’t be needed and wastes one fd. Another solution would be to rustix::fs::open() it again once the iteration is done, but that’s wasteful too.

rustix::fs::Dir::read_from has the same issue, it implements dup(2) manually by calling fcntl(4, F_GETFL) then openat(4, ".", …) with 4 being the fd being passed to it.

And since getdents64(2) is stateless, I believe there is no unsoundness issue with e.g. multiple rustix::fs::Dir being created around the same fd.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions