Skip to content

Commit 74af3cf

Browse files
committed
edition 2018
1 parent e1e2477 commit 74af3cf

File tree

9 files changed

+59
-58
lines changed

9 files changed

+59
-58
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ description = """
44
The type-safe wrapper around mount system call
55
"""
66
license = "MIT/Apache-2.0"
7+
edition = "2018"
78
readme = "README.md"
89
keywords = ["linux", "container", "mount", "volume", "filesystem"]
910
homepage = "http://github.com/tailhook/libmount"

src/bind.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use std::path::Path;
55

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

8-
use {OSError, Error};
9-
use util::{path_to_cstring, as_path};
10-
use explain::{Explainable, exists, user};
11-
use remount::Remount;
8+
use crate::{OSError, Error};
9+
use crate::util::{path_to_cstring, as_path};
10+
use crate::explain::{Explainable, exists, user};
11+
use crate::remount::Remount;
1212

1313

1414
/// A mount bind definition
@@ -72,10 +72,10 @@ impl BindMount {
7272
return Err(OSError::from_nix(err, Box::new(self)));
7373
}
7474
if self.readonly {
75-
try!(Remount::new(OsStr::from_bytes(self.target.as_bytes()))
75+
Remount::new(OsStr::from_bytes(self.target.as_bytes()))
7676
.bind(true)
7777
.readonly(true)
78-
.bare_remount());
78+
.bare_remount()?;
7979
}
8080
Ok(())
8181
}
@@ -89,7 +89,7 @@ impl BindMount {
8989
impl fmt::Display for BindMount {
9090
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
9191
if self.recursive {
92-
try!(write!(fmt, "recursive "));
92+
write!(fmt, "recursive ")?;
9393
}
9494
write!(fmt, "bind mount {:?} -> {:?}",
9595
as_path(&self.source), as_path(&self.target))

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt;
33
use std::error::Error as StdError;
44

55
use crate::{OSError, Error, MountError};
6-
use remount::RemountError;
6+
use crate::remount::RemountError;
77

88
impl OSError {
99
/// Convert error to the one providing extra useful information

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ pub mod mountinfo;
3434

3535
use std::io;
3636

37-
use explain::Explainable;
37+
use crate::explain::Explainable;
3838
pub use bind::BindMount;
3939
pub use overlay::Overlay;
4040
pub use tmpfs::Tmpfs;
4141
pub use modify::Move;
42-
pub use remount::{Remount,RemountError};
42+
pub use crate::remount::{Remount,RemountError};
4343

4444
#[derive(Debug, thiserror::Error)]
4545
#[allow(missing_docs)]

src/modify.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use std::path::Path;
44

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

7-
use {OSError, Error};
8-
use util::{path_to_cstring, as_path};
9-
use explain::{Explainable, exists};
7+
use crate::{OSError, Error};
8+
use crate::util::{path_to_cstring, as_path};
9+
use crate::explain::{Explainable, exists};
1010

1111
/// A move operation definition
1212
///

src/mountinfo.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,16 @@ pub(crate) fn parse_mount_point<'a>(row: &'a [u8])
172172
return Ok(None);
173173
}
174174

175-
let (mount_id, row) = try!(parse_int(row));
176-
let (parent_id, row) = try!(parse_int(row));
177-
let (major, minor, row) = try!(parse_major_minor(row));
178-
let (root, row) = try!(parse_os_str(row));
179-
let (mount_point, row) = try!(parse_os_str(row));
180-
let (mount_options, row) = try!(parse_os_str(row));
181-
let (optional_fields, row) = try!(parse_optional(row));
182-
let (fstype, row) = try!(parse_os_str(row));
183-
let (mount_source, row) = try!(parse_os_str(row));
184-
let (super_options, _) = try!(parse_os_str(row));
175+
let (mount_id, row) = parse_int(row)?;
176+
let (parent_id, row) = parse_int(row)?;
177+
let (major, minor, row) = parse_major_minor(row)?;
178+
let (root, row) = parse_os_str(row)?;
179+
let (mount_point, row) = parse_os_str(row)?;
180+
let (mount_options, row) = parse_os_str(row)?;
181+
let (optional_fields, row) = parse_optional(row)?;
182+
let (fstype, row) = parse_os_str(row)?;
183+
let (mount_source, row) = parse_os_str(row)?;
184+
let (super_options, _) = parse_os_str(row)?;
185185
// TODO: should we ignore extra fields?
186186
Ok(Some(MountPoint {
187187
mount_id: mount_id,
@@ -235,38 +235,38 @@ fn parse_field<'a>(data: &'a [u8], delimit: &'a [u8])
235235
fn parse_os_str<'a>(data: &'a [u8])
236236
-> Result<(Cow<'a, OsStr>, &'a [u8]), ParseRowError>
237237
{
238-
let (field, tail) = try!(parse_field(data, b" "));
238+
let (field, tail) = parse_field(data, b" ")?;
239239
Ok((unescape_octals(OsStr::from_bytes(field)), tail))
240240
}
241241

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

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

256256
fn parse_major_minor(data: &[u8])
257257
-> Result<(c_ulong, c_ulong, &[u8]), ParseRowError>
258258
{
259-
let (major_field, data) = try!(parse_field(data, b":"));
260-
let (minor_field, tail) = try!(parse_field(data, b" "));
261-
let (major, _) = try!(parse_int(major_field));
262-
let (minor, _) = try!(parse_int(minor_field));
259+
let (major_field, data) = parse_field(data, b":")?;
260+
let (minor_field, tail) = parse_field(data, b" ")?;
261+
let (major, _) = parse_int(major_field)?;
262+
let (minor, _) = parse_int(minor_field)?;
263263
Ok((major, minor, tail))
264264
}
265265

266266
fn parse_optional<'a>(data: &'a [u8])
267267
-> Result<(Cow<'a, OsStr>, &'a [u8]), ParseRowError>
268268
{
269-
let (field, tail) = try!(parse_field(data, b"- "));
269+
let (field, tail) = parse_field(data, b"- ")?;
270270
let field = rstrip_whitespaces(field);
271271
Ok((unescape_octals(OsStr::from_bytes(field)), tail))
272272
}

src/overlay.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use std::os::unix::ffi::OsStrExt;
77

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

10-
use util::{path_to_cstring, as_path};
11-
use {OSError, Error};
12-
use explain::{Explainable, exists, user};
10+
use crate::util::{path_to_cstring, as_path};
11+
use crate::{OSError, Error};
12+
use crate::explain::{Explainable, exists, user};
1313

1414

1515
/// An overlay mount point

src/remount.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use std::default::Default;
99

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

12-
use {OSError, Error};
13-
use util::path_to_cstring;
14-
use explain::{Explainable, exists, user};
15-
use mountinfo::{parse_mount_point};
12+
use crate::{OSError, Error};
13+
use crate::util::path_to_cstring;
14+
use crate::explain::{Explainable, exists, user};
15+
use crate::mountinfo::{parse_mount_point};
1616

1717
/// A remount definition
1818
///
@@ -182,51 +182,51 @@ impl fmt::Display for MountFlags {
182182
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
183183
let mut prefix = "";
184184
if let Some(true) = self.bind {
185-
try!(write!(fmt, "{}bind", prefix));
185+
write!(fmt, "{}bind", prefix)?;
186186
prefix = ",";
187187
}
188188
if let Some(true) = self.readonly {
189-
try!(write!(fmt, "{}ro", prefix));
189+
write!(fmt, "{}ro", prefix)?;
190190
prefix = ",";
191191
}
192192
if let Some(true) = self.nodev {
193-
try!(write!(fmt, "{}nodev", prefix));
193+
write!(fmt, "{}nodev", prefix)?;
194194
prefix = ",";
195195
}
196196
if let Some(true) = self.noexec {
197-
try!(write!(fmt, "{}noexec", prefix));
197+
write!(fmt, "{}noexec", prefix)?;
198198
prefix = ",";
199199
}
200200
if let Some(true) = self.nosuid {
201-
try!(write!(fmt, "{}nosuid", prefix));
201+
write!(fmt, "{}nosuid", prefix)?;
202202
prefix = ",";
203203
}
204204
if let Some(true) = self.noatime {
205-
try!(write!(fmt, "{}noatime", prefix));
205+
write!(fmt, "{}noatime", prefix)?;
206206
prefix = ",";
207207
}
208208
if let Some(true) = self.nodiratime {
209-
try!(write!(fmt, "{}nodiratime", prefix));
209+
write!(fmt, "{}nodiratime", prefix)?;
210210
prefix = ",";
211211
}
212212
if let Some(true) = self.relatime {
213-
try!(write!(fmt, "{}relatime", prefix));
213+
write!(fmt, "{}relatime", prefix)?;
214214
prefix = ",";
215215
}
216216
if let Some(true) = self.strictatime {
217-
try!(write!(fmt, "{}strictatime", prefix));
217+
write!(fmt, "{}strictatime", prefix)?;
218218
prefix = ",";
219219
}
220220
if let Some(true) = self.dirsync {
221-
try!(write!(fmt, "{}dirsync", prefix));
221+
write!(fmt, "{}dirsync", prefix)?;
222222
prefix = ",";
223223
}
224224
if let Some(true) = self.synchronous {
225-
try!(write!(fmt, "{}sync", prefix));
225+
write!(fmt, "{}sync", prefix)?;
226226
prefix = ",";
227227
}
228228
if let Some(true) = self.mandlock {
229-
try!(write!(fmt, "{}mand", prefix));
229+
write!(fmt, "{}mand", prefix)?;
230230
}
231231
Ok(())
232232
}
@@ -235,7 +235,7 @@ impl fmt::Display for MountFlags {
235235
impl fmt::Display for Remount {
236236
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
237237
if !self.flags.apply_to_flags(MsFlags::empty()).is_empty() {
238-
try!(write!(fmt, "{} ", self.flags));
238+
write!(fmt, "{} ", self.flags)?;
239239
}
240240
write!(fmt, "remount {:?}", &self.path)
241241
}
@@ -254,7 +254,7 @@ fn get_mountpoint_flags(path: &Path) -> Result<MsFlags, RemountError> {
254254
let mount_path = if path.is_absolute() {
255255
path.to_path_buf()
256256
} else {
257-
let mut mpath = try!(current_dir());
257+
let mut mpath = current_dir()?;
258258
mpath.push(path);
259259
mpath
260260
};

src/tmpfs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use std::path::Path;
77
use libc::{uid_t, gid_t, mode_t};
88
use nix::mount::{MsFlags, mount};
99

10-
use {OSError, Error};
11-
use util::{path_to_cstring, as_path};
12-
use explain::{Explainable, exists, user};
10+
use crate::{OSError, Error};
11+
use crate::util::{path_to_cstring, as_path};
12+
use crate::explain::{Explainable, exists, user};
1313

1414

1515
#[derive(Debug, Clone, Copy)]

0 commit comments

Comments
 (0)