From 60e71dfc664c1dbc5b204fe486efa3cfb37675a1 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Sun, 14 Apr 2019 14:54:32 -0400 Subject: [PATCH] rust: Update to 2018 edition This mostly involves adjusting our path uses to be anchored, e.g. at `self::` or `crate::`. I took the opportunity to also tweak `use` ordering so that we consistently list modules in external crates first before our own. Closes: #1812 Approved by: lucab --- rust/Cargo.toml | 1 + rust/src/composepost.rs | 9 +++++---- rust/src/ffiutil.rs | 3 +-- rust/src/journal.rs | 4 +++- rust/src/lib.rs | 22 +++++++++++----------- rust/src/progress.rs | 3 ++- rust/src/treefile.rs | 7 ++++--- rust/src/utils.rs | 3 ++- 8 files changed, 29 insertions(+), 23 deletions(-) diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 9003a807..a4517830 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -2,6 +2,7 @@ name = "rpmostree-rust" version = "0.1.0" authors = ["Colin Walters ", "Jonathan Lebon "] +edition = "2018" [dependencies] failure = "0.1.3" diff --git a/rust/src/composepost.rs b/rust/src/composepost.rs index 4618e03b..b863cdad 100644 --- a/rust/src/composepost.rs +++ b/rust/src/composepost.rs @@ -23,7 +23,7 @@ use std::io; use std::io::{BufRead, Write}; use std::path::Path; -use openat_utils::OpenatDirExt; +use crate::openat_utils::OpenatDirExt; // rpm-ostree uses /home → /var/home by default as generated by our // rootfs; we don't expect people to change this. Let's be nice @@ -37,7 +37,7 @@ use openat_utils::OpenatDirExt; fn postprocess_useradd(rootfs_dfd: &openat::Dir) -> Fallible<()> { let path = Path::new("usr/etc/default/useradd"); if let Some(f) = rootfs_dfd.open_file_optional(path)? { - let mut f = io::BufReader::new(f); + let f = io::BufReader::new(f); let tmp_path = path.parent().unwrap().join("useradd.tmp"); let o = rootfs_dfd.write_file(&tmp_path, 0o644)?; let mut bufw = io::BufWriter::new(&o); @@ -82,7 +82,7 @@ enable ostree-finalize-staged.path fn postprocess_subs_dist(rootfs_dfd: &openat::Dir) -> Fallible<()> { let path = Path::new("usr/etc/selinux/targeted/contexts/files/file_contexts.subs_dist"); if let Some(f) = rootfs_dfd.open_file_optional(path)? { - let mut f = io::BufReader::new(f); + let f = io::BufReader::new(f); let tmp_path = path.parent().unwrap().join("file_contexts.subs_dist.tmp"); let o = rootfs_dfd.write_file(&tmp_path, 0o644)?; let mut bufw = io::BufWriter::new(&o); @@ -117,10 +117,11 @@ fn compose_postprocess_final(rootfs_dfd: &openat::Dir) -> Fallible<()> { mod ffi { use super::*; - use ffiutil::*; use glib_sys; use libc; + use crate::ffiutil::*; + #[no_mangle] pub extern "C" fn ror_compose_postprocess_final( rootfs_dfd: libc::c_int, diff --git a/rust/src/ffiutil.rs b/rust/src/ffiutil.rs index 8804abbf..254f6101 100644 --- a/rust/src/ffiutil.rs +++ b/rust/src/ffiutil.rs @@ -19,6 +19,7 @@ use gio_sys; use glib_sys; use libc; +use openat; use std::ffi::CString; use std::ffi::{CStr, OsStr}; use std::fmt::Display; @@ -26,8 +27,6 @@ use std::os::unix::ffi::OsStrExt; use std::os::unix::io::{FromRawFd, IntoRawFd}; use std::ptr; -use openat; - /* Helper functions for FFI between C and Rust. * * This code assumes that it was compiled with the system allocator: diff --git a/rust/src/journal.rs b/rust/src/journal.rs index 26201300..06e5186b 100644 --- a/rust/src/journal.rs +++ b/rust/src/journal.rs @@ -147,9 +147,11 @@ fn journal_print_staging_failure() -> Fallible<()> { mod ffi { use super::*; - use ffiutil::*; use glib_sys; use libc; + + use crate::ffiutil::*; + #[no_mangle] pub extern "C" fn ror_journal_print_staging_failure( gerror: *mut *mut glib_sys::GError, diff --git a/rust/src/lib.rs b/rust/src/lib.rs index af03118d..2f6bab8c 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -39,15 +39,15 @@ extern crate serde_json; extern crate serde_yaml; mod ffiutil; - -mod treefile; -pub use treefile::*; -mod composepost; -pub use composepost::*; -mod progress; -pub use progress::*; -mod journal; -pub use journal::*; -mod utils; -pub use utils::*; mod openat_utils; + +mod composepost; +pub use self::composepost::*; +mod journal; +pub use self::journal::*; +mod progress; +pub use self::progress::*; +mod treefile; +pub use self::treefile::*; +mod utils; +pub use self::utils::*; diff --git a/rust/src/progress.rs b/rust/src/progress.rs index 0430040c..85b4e4b3 100644 --- a/rust/src/progress.rs +++ b/rust/src/progress.rs @@ -168,10 +168,11 @@ mod tests { mod ffi { use super::*; - use ffiutil::*; use libc; use std::sync::MutexGuard; + use crate::ffiutil::*; + fn assert_empty(m: &MutexGuard>) { if let Some(ref state) = **m { panic!("Overwriting task: \"{}\"", state.message) diff --git a/rust/src/treefile.rs b/rust/src/treefile.rs index aafc2fe5..d080b641 100644 --- a/rust/src/treefile.rs +++ b/rust/src/treefile.rs @@ -30,7 +30,8 @@ use std::collections::HashMap; use std::io::prelude::*; use std::path::Path; use std::{collections, fs, io}; -use utils; + +use crate::utils; const INCLUDE_MAXDEPTH: u32 = 50; @@ -990,14 +991,14 @@ packages: mod ffi { use super::*; - use ffiutil::*; use glib_sys; use libc; - use std::io::Seek; use std::os::unix::io::{AsRawFd, RawFd}; use std::{fs, io, ptr}; + use crate::ffiutil::*; + // Some of our file descriptors may be read multiple times. // We try to consistently seek to the start to make that // convenient from the C side. Note that this function diff --git a/rust/src/utils.rs b/rust/src/utils.rs index 4a1f7f39..58501542 100644 --- a/rust/src/utils.rs +++ b/rust/src/utils.rs @@ -116,7 +116,6 @@ mod tests { mod ffi { use super::*; - use ffiutil::*; use glib; use glib_sys; use libc; @@ -124,6 +123,8 @@ mod ffi { use std::os::unix::io::IntoRawFd; use std::ptr; + use crate::ffiutil::*; + #[no_mangle] pub extern "C" fn ror_download_to_fd( url: *const libc::c_char,