Main concept here is a
Dir which holds
O_PATH file descriptor, you
can create it with:
Dir::open("/some/path")– open this directory as a file descriptor
Dir::from_raw_fd(fd)– uses a file descriptor provided elsewhere
Note after opening file descriptors refer to same directory regardless of
where it’s moved or mounted (with
mount --move). It may
also be unmounted or be out of chroot and you will still be able to
access files relative to it.
Note2: The constructor
Dir::cwd() is deprecated, and it’s recommended
Most other operations are done on
Dir object and are executed relative
Functions that expect path relative to the directory accept both the
traditional path-like objects, such as Path, PathBuf and &str, and
Entry type returned from
list_dir(). The latter is faster as underlying
system call wants
CString and we keep that in entry.
Note that if path supplied to any method of dir is absolute the Dir file descriptor is ignored.
Also while all methods of dir accept any path if you want to prevent certain symlink attacks and race condition you should only use a single-component path. I.e. open one part of a chain at a time.
- A safe wrapper around directory file descriptor
- Iterator over directory entries
- Entry returned by iterating over
- A file metadata
- This is a simplified file type enum that is easy to match
- The purpose of this is similar to
AsRef<Path>but it’s optimized for things that can be directly used as
CStr(which is type passed to the underlying system call).
- Create a hardlink to a file
- Rename (move) a file between directories