src/pxar/dir_stack.rs: style fixups

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Christian Ebner 2019-08-22 15:00:02 +02:00 committed by Wolfgang Bumiller
parent b69169e7be
commit dac88033ba
1 changed files with 17 additions and 11 deletions

View File

@ -2,14 +2,14 @@ use std::ffi::{OsStr, OsString};
use std::os::unix::io::{AsRawFd, RawFd}; use std::os::unix::io::{AsRawFd, RawFd};
use std::path::PathBuf; use std::path::PathBuf;
use super::format_definition::*; use failure::{format_err, Error};
use failure::*;
use nix::fcntl::OFlag;
use nix::errno::Errno; use nix::errno::Errno;
use nix::fcntl::OFlag;
use nix::sys::stat::Mode; use nix::sys::stat::Mode;
use nix::NixPath; use nix::NixPath;
use super::format_definition::{PxarAttributes, PxarEntry};
pub struct PxarDir { pub struct PxarDir {
pub filename: OsString, pub filename: OsString,
pub entry: PxarEntry, pub entry: PxarEntry,
@ -33,12 +33,12 @@ impl PxarDir {
} }
fn create_dir(&self, parent: RawFd, create_new: bool) -> Result<nix::dir::Dir, nix::Error> { fn create_dir(&self, parent: RawFd, create_new: bool) -> Result<nix::dir::Dir, nix::Error> {
let res = self.filename.with_nix_path(|cstr| unsafe { let res = self
libc::mkdirat(parent, cstr.as_ptr(), libc::S_IRWXU) .filename
})?; .with_nix_path(|cstr| unsafe { libc::mkdirat(parent, cstr.as_ptr(), libc::S_IRWXU) })?;
match Errno::result(res) { match Errno::result(res) {
Ok(_) => {}, Ok(_) => {}
Err(err) => { Err(err) => {
if err == nix::Error::Sys(nix::errno::Errno::EEXIST) { if err == nix::Error::Sys(nix::errno::Errno::EEXIST) {
if create_new { if create_new {
@ -50,7 +50,12 @@ impl PxarDir {
} }
} }
let dir = nix::dir::Dir::openat(parent, self.filename.as_os_str(), OFlag::O_DIRECTORY, Mode::empty())?; let dir = nix::dir::Dir::openat(
parent,
self.filename.as_os_str(),
OFlag::O_DIRECTORY,
Mode::empty(),
)?;
Ok(dir) Ok(dir)
} }
@ -99,11 +104,12 @@ impl PxarDirStack {
match &d.dir { match &d.dir {
Some(dir) => current_fd = dir.as_raw_fd(), Some(dir) => current_fd = dir.as_raw_fd(),
None => { None => {
let dir = d.create_dir(current_fd, create_new) let dir = d
.create_dir(current_fd, create_new)
.map_err(|err| format_err!("create dir failed - {}", err))?; .map_err(|err| format_err!("create dir failed - {}", err))?;
current_fd = dir.as_raw_fd(); current_fd = dir.as_raw_fd();
d.dir = Some(dir); d.dir = Some(dir);
}, }
} }
} }