pub trait OpenatDirExt {
Show 22 methods fn open_file_optional<P: AsPath>(&self, p: P) -> Result<Option<File>>;
fn read_to_string<P: AsPath>(&self, p: P) -> Result<String>;
fn read_to_string_optional<P: AsPath>(&self, p: P) -> Result<Option<String>>;
fn remove_file_optional<P: AsPath>(&self, p: P) -> Result<bool>;
fn remove_dir_optional<P: AsPath>(&self, p: P) -> Result<bool>;
fn sub_dir_optional<P: AsPath>(&self, p: P) -> Result<Option<Dir>>;
fn metadata_optional<P: AsPath>(&self, p: P) -> Result<Option<Metadata>>;
fn get_file_type(&self, e: &Entry) -> Result<SimpleType>;
fn exists<P: AsPath>(&self, p: P) -> Result<bool>;
fn ensure_dir<P: AsPath>(&self, p: P, mode: mode_t) -> Result<()>;
fn ensure_dir_all<P: AsPath>(&self, p: P, mode: mode_t) -> Result<()>;
fn remove_all<P: AsPath>(&self, p: P) -> Result<bool>;
fn syncfs(&self) -> Result<()>;
fn local_rename_optional<P: AsRef<Path>, R: AsRef<Path>>(
        &self,
        oldpath: P,
        newpath: R
    ) -> Result<bool>;
fn update_timestamps<P: AsPath>(&self, path: P) -> Result<()>;
fn set_mode<P: AsPath>(&self, path: P, mode: mode_t) -> Result<()>;
fn copy_file<S: AsPath, D: AsPath>(&self, s: S, d: D) -> Result<()>;
fn copy_file_at<S: AsPath, D: AsPath>(
        &self,
        s: S,
        target_dir: &Dir,
        d: D
    ) -> Result<()>;
fn new_file_writer(&self, mode: mode_t) -> Result<FileWriter<'_>>; fn write_file_with<P: AsRef<Path>, F, T, E>(
        &self,
        destname: P,
        mode: mode_t,
        gen_content_fn: F
    ) -> Result<T, E>
    where
        F: FnOnce(&mut BufWriter<File>) -> Result<T, E>,
        E: From<Error>
, { ... }
fn write_file_with_sync<P: AsRef<Path>, F, T, E>(
        &self,
        destname: P,
        mode: mode_t,
        gen_content_fn: F
    ) -> Result<T, E>
    where
        F: FnOnce(&mut BufWriter<File>) -> Result<T, E>,
        E: From<Error>
, { ... }
fn write_file_contents<P: AsRef<Path>, C: AsRef<[u8]>>(
        &self,
        destname: P,
        mode: mode_t,
        contents: C
    ) -> Result<()> { ... }
}
Expand description

Helper functions for openat::Dir

Required methods

Checking for nonexistent files (ENOENT) is by far the most common case of inspecting error codes in Unix. Rust has a nice Option<> type, so this helper makes use of it and returns Ok(None) for nonexistent files. All other errors are Err, and extant files are Ok(Some<file>)) of course.

Like std::fs::read_to_string() but with a path relative to the openat::Dir.

Like read_to_string, but returns Ok(None) for nonexistent paths.

Remove a file from the given directory; does not error if the target does not exist. But will return an error if the target is a directory.

Remove an empty sub-directory from the given directory; does not error if the target does not exist. But will return an error if the target is a file or symlink.

Like open_file_optional() except opens a directory via openat::dir::sub_dir.

Like metadata() except returns Ok(None) for nonexistent paths.

On modern filesystems the directory entry contains the type; if available, return it. Otherwise invoke stat().

Returns true iff file exists (may be a directory or symlink). Symbolic links are not followed.

Create a directory but don’t error if it already exists.

Create directory and all parents as necessary; no error is returned if directory already exists.

Remove all content at the target path, returns true if something existed there.

Synchronize to disk the filesystem containing this directory.

If oldpath exists, rename it to newpath. Otherwise do nothing.

This returns true if the old path has been succesfully renamed, false otherwise.

Update timestamps (both access and modification) to the current time.

If the entry at path is a symlink, its direct timestamps are updated without following the link.

Update permissions for the given path (see fchmodat(2)).

If the entry at path is a symlink, no action is performed.

Copy a regular file. The semantics here are intended to match std::fs::copy(). If the target exists, it will be overwritten. The mode bits (permissions) will match, but owner/group will be derived from the current process. Extended attributes are not copied. However, symbolic links will not be followed; instead an error is returned. If the filesystem supports it, reflinks will be used.

Copy a regular file.

This is the same as copy_file, but can copy to an arbitrary target directory outside of self.

Create a FileWriter which provides a std::io::BufWriter and then atomically creates the file at the destination, renaming it over an existing one if necessary.

Provided methods

Atomically create or replace the destination file, calling the provided function to generate the contents. Note that the contents of the file will not be explicitly sync’d to disk; if you want to do so you need to invoke writer.flush()?; writer.get_ref().sync_all() for example.

Like write_file_with() but explicitly synchronizes the target to disk.

Atomically create or replace the destination file with the provided contents.

Implementations on Foreign Types

Implementors