Skip to content

Commit

Permalink
edition 2018
Browse files Browse the repository at this point in the history
  • Loading branch information
drahnr committed Nov 18, 2020
1 parent e1e2477 commit d16da7b
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 57 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ description = """
The type-safe wrapper around mount system call
"""
license = "MIT/Apache-2.0"
edition = "2018"
readme = "README.md"
keywords = ["linux", "container", "mount", "volume", "filesystem"]
homepage = "http://github.com/tailhook/libmount"
Expand Down
14 changes: 7 additions & 7 deletions src/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use std::path::Path;

use nix::mount::{MsFlags, mount};

use {OSError, Error};
use util::{path_to_cstring, as_path};
use explain::{Explainable, exists, user};
use remount::Remount;
use crate::{OSError, Error};
use crate::util::{path_to_cstring, as_path};
use crate::explain::{Explainable, exists, user};
use crate::remount::Remount;


/// A mount bind definition
Expand Down Expand Up @@ -72,10 +72,10 @@ impl BindMount {
return Err(OSError::from_nix(err, Box::new(self)));
}
if self.readonly {
try!(Remount::new(OsStr::from_bytes(self.target.as_bytes()))
Remount::new(OsStr::from_bytes(self.target.as_bytes()))
.bind(true)
.readonly(true)
.bare_remount());
.bare_remount()?;
}
Ok(())
}
Expand All @@ -89,7 +89,7 @@ impl BindMount {
impl fmt::Display for BindMount {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
if self.recursive {
try!(write!(fmt, "recursive "));
write!(fmt, "recursive ")?;
}
write!(fmt, "bind mount {:?} -> {:?}",
as_path(&self.source), as_path(&self.target))
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ pub mod mountinfo;

use std::io;

use explain::Explainable;
use crate::explain::Explainable;
pub use bind::BindMount;
pub use overlay::Overlay;
pub use tmpfs::Tmpfs;
pub use modify::Move;
pub use remount::{Remount,RemountError};
pub use crate::remount::{Remount,RemountError};

#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
Expand Down
6 changes: 3 additions & 3 deletions src/modify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use std::path::Path;

use nix::mount::{MsFlags, mount};

use {OSError, Error};
use util::{path_to_cstring, as_path};
use explain::{Explainable, exists};
use crate::{OSError, Error};
use crate::util::{path_to_cstring, as_path};
use crate::explain::{Explainable, exists};

/// A move operation definition
///
Expand Down
42 changes: 21 additions & 21 deletions src/mountinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,16 @@ pub(crate) fn parse_mount_point<'a>(row: &'a [u8])
return Ok(None);
}

let (mount_id, row) = try!(parse_int(row));
let (parent_id, row) = try!(parse_int(row));
let (major, minor, row) = try!(parse_major_minor(row));
let (root, row) = try!(parse_os_str(row));
let (mount_point, row) = try!(parse_os_str(row));
let (mount_options, row) = try!(parse_os_str(row));
let (optional_fields, row) = try!(parse_optional(row));
let (fstype, row) = try!(parse_os_str(row));
let (mount_source, row) = try!(parse_os_str(row));
let (super_options, _) = try!(parse_os_str(row));
let (mount_id, row) = parse_int(row)?;
let (parent_id, row) = parse_int(row)?;
let (major, minor, row) = parse_major_minor(row)?;
let (root, row) = parse_os_str(row)?;
let (mount_point, row) = parse_os_str(row)?;
let (mount_options, row) = parse_os_str(row)?;
let (optional_fields, row) = parse_optional(row)?;
let (fstype, row) = parse_os_str(row)?;
let (mount_source, row) = parse_os_str(row)?;
let (super_options, _) = parse_os_str(row)?;
// TODO: should we ignore extra fields?
Ok(Some(MountPoint {
mount_id: mount_id,
Expand Down Expand Up @@ -235,38 +235,38 @@ fn parse_field<'a>(data: &'a [u8], delimit: &'a [u8])
fn parse_os_str<'a>(data: &'a [u8])
-> Result<(Cow<'a, OsStr>, &'a [u8]), ParseRowError>
{
let (field, tail) = try!(parse_field(data, b" "));
let (field, tail) = parse_field(data, b" ")?;
Ok((unescape_octals(OsStr::from_bytes(field)), tail))
}

fn parse_int(data: &[u8])
-> Result<(c_ulong, &[u8]), ParseRowError>
{
let (field, tail) = try!(parse_field(data, b" "));
let v = try!(std::str::from_utf8(field).map_err(|e| {
let (field, tail) = parse_field(data, b" ")?;
let v = std::str::from_utf8(field).map_err(|e| {
ParseRowError(format!("Cannot parse integer {:?}: {}",
String::from_utf8_lossy(field).into_owned(), e))}));
String::from_utf8_lossy(field).into_owned(), e))})?;

let v = try!(c_ulong::from_str_radix(v, 10).map_err(|e| {
let v = c_ulong::from_str_radix(v, 10).map_err(|e| {
ParseRowError(format!("Cannot parse integer {:?}: {}",
String::from_utf8_lossy(field).into_owned(), e))}));
String::from_utf8_lossy(field).into_owned(), e))})?;
Ok((v, tail))
}

fn parse_major_minor(data: &[u8])
-> Result<(c_ulong, c_ulong, &[u8]), ParseRowError>
{
let (major_field, data) = try!(parse_field(data, b":"));
let (minor_field, tail) = try!(parse_field(data, b" "));
let (major, _) = try!(parse_int(major_field));
let (minor, _) = try!(parse_int(minor_field));
let (major_field, data) = parse_field(data, b":")?;
let (minor_field, tail) = parse_field(data, b" ")?;
let (major, _) = parse_int(major_field)?;
let (minor, _) = parse_int(minor_field)?;
Ok((major, minor, tail))
}

fn parse_optional<'a>(data: &'a [u8])
-> Result<(Cow<'a, OsStr>, &'a [u8]), ParseRowError>
{
let (field, tail) = try!(parse_field(data, b"- "));
let (field, tail) = parse_field(data, b"- ")?;
let field = rstrip_whitespaces(field);
Ok((unescape_octals(OsStr::from_bytes(field)), tail))
}
Expand Down
6 changes: 3 additions & 3 deletions src/overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use std::os::unix::ffi::OsStrExt;

use nix::mount::{MsFlags, mount};

use util::{path_to_cstring, as_path};
use {OSError, Error};
use explain::{Explainable, exists, user};
use crate::util::{path_to_cstring, as_path};
use crate::{OSError, Error};
use crate::explain::{Explainable, exists, user};


/// An overlay mount point
Expand Down
36 changes: 18 additions & 18 deletions src/remount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use std::default::Default;

use nix::mount::{MsFlags, mount};

use {OSError, Error};
use util::path_to_cstring;
use explain::{Explainable, exists, user};
use mountinfo::{parse_mount_point};
use crate::{OSError, Error};
use crate::util::path_to_cstring;
use crate::explain::{Explainable, exists, user};
use crate::mountinfo::{parse_mount_point};

/// A remount definition
///
Expand Down Expand Up @@ -182,51 +182,51 @@ impl fmt::Display for MountFlags {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let mut prefix = "";
if let Some(true) = self.bind {
try!(write!(fmt, "{}bind", prefix));
write!(fmt, "{}bind", prefix)?;
prefix = ",";
}
if let Some(true) = self.readonly {
try!(write!(fmt, "{}ro", prefix));
write!(fmt, "{}ro", prefix)?;
prefix = ",";
}
if let Some(true) = self.nodev {
try!(write!(fmt, "{}nodev", prefix));
write!(fmt, "{}nodev", prefix)?;
prefix = ",";
}
if let Some(true) = self.noexec {
try!(write!(fmt, "{}noexec", prefix));
write!(fmt, "{}noexec", prefix)?;
prefix = ",";
}
if let Some(true) = self.nosuid {
try!(write!(fmt, "{}nosuid", prefix));
write!(fmt, "{}nosuid", prefix)?;
prefix = ",";
}
if let Some(true) = self.noatime {
try!(write!(fmt, "{}noatime", prefix));
write!(fmt, "{}noatime", prefix)?;
prefix = ",";
}
if let Some(true) = self.nodiratime {
try!(write!(fmt, "{}nodiratime", prefix));
write!(fmt, "{}nodiratime", prefix)?;
prefix = ",";
}
if let Some(true) = self.relatime {
try!(write!(fmt, "{}relatime", prefix));
write!(fmt, "{}relatime", prefix)?;
prefix = ",";
}
if let Some(true) = self.strictatime {
try!(write!(fmt, "{}strictatime", prefix));
write!(fmt, "{}strictatime", prefix)?;
prefix = ",";
}
if let Some(true) = self.dirsync {
try!(write!(fmt, "{}dirsync", prefix));
write!(fmt, "{}dirsync", prefix)?;
prefix = ",";
}
if let Some(true) = self.synchronous {
try!(write!(fmt, "{}sync", prefix));
write!(fmt, "{}sync", prefix)?;
prefix = ",";
}
if let Some(true) = self.mandlock {
try!(write!(fmt, "{}mand", prefix));
write!(fmt, "{}mand", prefix)?;
}
Ok(())
}
Expand All @@ -235,7 +235,7 @@ impl fmt::Display for MountFlags {
impl fmt::Display for Remount {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
if !self.flags.apply_to_flags(MsFlags::empty()).is_empty() {
try!(write!(fmt, "{} ", self.flags));
write!(fmt, "{} ", self.flags)?;
}
write!(fmt, "remount {:?}", &self.path)
}
Expand All @@ -254,7 +254,7 @@ fn get_mountpoint_flags(path: &Path) -> Result<MsFlags, RemountError> {
let mount_path = if path.is_absolute() {
path.to_path_buf()
} else {
let mut mpath = try!(current_dir());
let mut mpath = current_dir()?;
mpath.push(path);
mpath
};
Expand Down
6 changes: 3 additions & 3 deletions src/tmpfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use std::path::Path;
use libc::{uid_t, gid_t, mode_t};
use nix::mount::{MsFlags, mount};

use {OSError, Error};
use util::{path_to_cstring, as_path};
use explain::{Explainable, exists, user};
use crate::{OSError, Error};
use crate::util::{path_to_cstring, as_path};
use crate::explain::{Explainable, exists, user};


#[derive(Debug, Clone, Copy)]
Expand Down

0 comments on commit d16da7b

Please sign in to comment.