[−][src]Trait openat_ext::OpenatDirExt
Helper functions for openat::Dir
Required methods
fn open_file_optional<P: AsPath>(&self, p: P) -> Result<Option<File>>
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 remove_file_optional<P: AsPath>(&self, p: P) -> Result<()>
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>
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>>
Like open_file_optional()
except opens a directory via openat::dir::sub_dir
.
fn metadata_optional<P: AsPath>(&self, p: P) -> Result<Option<Metadata>>
Like metadata()
except returns Ok(None)
for nonexistent paths.
fn get_file_type(&self, e: &Entry) -> Result<SimpleType>
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>
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<()>
Create a directory but don't error if it already exists.
fn ensure_dir_all<P: AsPath>(&self, p: P, mode: mode_t) -> Result<()>
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>
Remove all content at the target path, returns true
if something existed there.
fn new_file_writer<'a, P: AsRef<Path>>(
&'a self,
destname: P,
mode: mode_t
) -> Result<FileWriter<'_>>
&'a self,
destname: P,
mode: mode_t
) -> Result<FileWriter<'_>>
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
fn write_file_with<P: AsRef<Path>, F, T, E>(
&self,
destname: P,
mode: mode_t,
f: F
) -> Result<T, E> where
F: Fn(&mut BufWriter<File>) -> Result<T, E>,
E: From<Error>,
&self,
destname: P,
mode: mode_t,
f: F
) -> Result<T, E> where
F: Fn(&mut BufWriter<File>) -> Result<T, E>,
E: From<Error>,
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,
f: F
) -> Result<T, E> where
F: Fn(&mut BufWriter<File>) -> Result<T, E>,
E: From<Error>,
&self,
destname: P,
mode: mode_t,
f: F
) -> Result<T, E> where
F: Fn(&mut BufWriter<File>) -> Result<T, E>,
E: From<Error>,
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<()>
&self,
destname: P,
mode: mode_t,
contents: C
) -> Result<()>
Atomically create or replace the destination file with the provided contents.
Implementations on Foreign Types
impl OpenatDirExt for Dir
[src]
fn open_file_optional<P: AsPath>(&self, p: P) -> Result<Option<File>>
[src]
fn remove_file_optional<P: AsPath>(&self, p: P) -> Result<()>
[src]
fn remove_dir_optional<P: AsPath>(&self, p: P) -> Result<bool>
[src]
fn metadata_optional<P: AsPath>(&self, p: P) -> Result<Option<Metadata>>
[src]
fn sub_dir_optional<P: AsPath>(&self, p: P) -> Result<Option<Dir>>
[src]
fn get_file_type(&self, e: &Entry) -> Result<SimpleType>
[src]
fn exists<P: AsPath>(&self, p: P) -> Result<bool>
[src]
fn ensure_dir<P: AsPath>(&self, p: P, mode: mode_t) -> Result<()>
[src]
fn ensure_dir_all<P: AsPath>(&self, p: P, mode: mode_t) -> Result<()>
[src]
fn remove_all<P: AsPath>(&self, p: P) -> Result<bool>
[src]
fn new_file_writer<'a, P: AsRef<Path>>(
&'a self,
destname: P,
mode: mode_t
) -> Result<FileWriter<'_>>
[src]
&'a self,
destname: P,
mode: mode_t
) -> Result<FileWriter<'_>>