[][src]Struct openat::Dir

pub struct Dir(_);

A safe wrapper around directory file descriptor

Construct it either with Dir::cwd() or Dir::open(path)

Methods

impl Dir[src]

pub fn cwd() -> Dir[src]

Deprecated since 0.1.15:

Use Dir::open(".") instead. Dir::cwd() doesn't open actual file descriptor and uses magic value instead which resolves to current dir on any syscall invocation. This is usually counter-intuitive and yields a broken file descriptor when using Dir::as_raw_fd. Will be removed in version v0.2 of the library.

Creates a directory descriptor that resolves paths relative to current working directory (AT_FDCWD)

pub fn open<P: AsPath>(path: P) -> Result<Dir>[src]

Open a directory descriptor at specified path

pub fn list_dir<P: AsPath>(&self, path: P) -> Result<DirIter>[src]

List subdirectory of this dir

You can list directory itself if "." is specified as path.

pub fn sub_dir<P: AsPath>(&self, path: P) -> Result<Dir>[src]

Open subdirectory

Read link in this directory

pub fn open_file<P: AsPath>(&self, path: P) -> Result<File>[src]

Open file for reading in this directory

pub fn write_file<P: AsPath>(&self, path: P, mode: mode_t) -> Result<File>[src]

Open file for writing, create if necessary, truncate on open

pub fn append_file<P: AsPath>(&self, path: P, mode: mode_t) -> Result<File>[src]

Open file for append, create if necessary

pub fn create_file<P: AsPath>(&self, path: P, mode: mode_t) -> Result<File>[src]

Deprecated since 0.1.7:

please use write_file instead

Create file for writing (and truncate) in this directory

Deprecated alias for write_file

pub fn new_unnamed_file<P: AsPath>(&self, _mode: mode_t) -> Result<File>[src]

Create a tmpfile in this directory which isn't linked to any filename

This works by passing O_TMPFILE into the openat call. The flag is supported only on linux. So this function always returns error on such systems.

Note: It may be unclear why creating unnamed file requires a dir. There are two reasons:

  1. It's created (and occupies space) on a real filesystem, so the directory is a way to find out which filesystem to attach file to
  2. This method is mostly needed to initialize the file then link it using link_file_at to the real directory entry. When linking it must be linked into the same filesystem. But because for most programs finding out filesystem layout is an overkill the rule of thumb is to create a file in the the target directory.

Currently, we recommend to fallback on any error if this operation can't be accomplished rather than relying on specific error codes, because semantics of errors are very ugly.

Link open file to a specified path

This is used with new_unnamed_file() to create and initialize the file before linking it into a filesystem. This requires /proc to be mounted and works only on linux.

On systems other than linux this always returns error. It's expected that in most cases this methos is not called if new_unnamed_file fails. But in obscure scenarios where /proc is not mounted this method may fail even on linux. So your code should be able to fallback to a named file if this method fails too.

pub fn new_file<P: AsPath>(&self, path: P, mode: mode_t) -> Result<File>[src]

Create file if not exists, fail if exists

This function checks existence and creates file atomically with respect to other threads and processes.

Technically it means passing O_EXCL flag to open.

pub fn update_file<P: AsPath>(&self, path: P, mode: mode_t) -> Result<File>[src]

Open file for reading and writing without truncation, create if needed

Make a symlink in this directory

Note: the order of arguments differ from symlinkat

pub fn create_dir<P: AsPath>(&self, path: P, mode: mode_t) -> Result<()>[src]

Create a subdirectory in this directory

pub fn local_rename<P: AsPath, R: AsPath>(&self, old: P, new: R) -> Result<()>[src]

Rename a file in this directory to another name (keeping same dir)

pub fn remove_dir<P: AsPath>(&self, path: P) -> Result<()>[src]

Remove a subdirectory in this directory

Note only empty directory may be removed

pub fn remove_file<P: AsPath>(&self, path: P) -> Result<()>[src]

Remove a file in this directory

pub fn recover_path(&self) -> Result<PathBuf>[src]

Get the path of this directory (if possible)

This uses symlinks in /proc/self, they sometimes may not be available so use with care.

pub fn metadata<P: AsPath>(&self, path: P) -> Result<Metadata>[src]

Returns metadata of an entry in this directory

Trait Implementations

impl Drop for Dir[src]

impl Debug for Dir[src]

impl AsRawFd for Dir[src]

impl FromRawFd for Dir[src]

impl IntoRawFd for Dir[src]

Auto Trait Implementations

impl Sync for Dir

impl Unpin for Dir

impl Send for Dir

impl UnwindSafe for Dir

impl RefUnwindSafe for Dir

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]