Trait openat_ext::OpenatDirExt[][src]

pub trait OpenatDirExt {
    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 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<'a>(&'a 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<()> { ... } }

Helper functions for openat::Dir

Required methods

fn open_file_optional<P: AsPath>(&self, p: P) -> Result<Option<File>>[src]

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.

fn read_to_string<P: AsPath>(&self, p: P) -> Result<String>[src]

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

fn read_to_string_optional<P: AsPath>(&self, p: P) -> Result<Option<String>>[src]

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

fn remove_file_optional<P: AsPath>(&self, p: P) -> Result<bool>[src]

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.

fn remove_dir_optional<P: AsPath>(&self, p: P) -> Result<bool>[src]

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.

fn sub_dir_optional<P: AsPath>(&self, p: P) -> Result<Option<Dir>>[src]

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

fn metadata_optional<P: AsPath>(&self, p: P) -> Result<Option<Metadata>>[src]

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

fn get_file_type(&self, e: &Entry) -> Result<SimpleType>[src]

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

fn exists<P: AsPath>(&self, p: P) -> Result<bool>[src]

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

fn ensure_dir<P: AsPath>(&self, p: P, mode: mode_t) -> Result<()>[src]

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

fn ensure_dir_all<P: AsPath>(&self, p: P, mode: mode_t) -> Result<()>[src]

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

fn remove_all<P: AsPath>(&self, p: P) -> Result<bool>[src]

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

fn copy_file<S: AsPath, D: AsPath>(&self, s: S, d: D) -> Result<()>[src]

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.

fn copy_file_at<S: AsPath, D: AsPath>(
    &self,
    s: S,
    target_dir: &Dir,
    d: D
) -> Result<()>
[src]

Copy a regular file.

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

fn new_file_writer<'a>(&'a self, mode: mode_t) -> Result<FileWriter<'_>>[src]

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.

Loading content...

Provided methods

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>, 
[src]

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.

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>, 
[src]

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

fn write_file_contents<P: AsRef<Path>, C: AsRef<[u8]>>(
    &self,
    destname: P,
    mode: mode_t,
    contents: C
) -> Result<()>
[src]

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

Loading content...

Implementations on Foreign Types

impl OpenatDirExt for Dir[src]

Loading content...

Implementors

Loading content...