use nix to remove many uses of unsafe

This commit is contained in:
Scott Lamb
2019-07-11 21:59:01 -07:00
parent d75157af56
commit bb227491b6
11 changed files with 142 additions and 139 deletions

View File

@@ -303,7 +303,7 @@ fn edit_dir_dialog(db: &Arc<db::Database>, siv: &mut Cursive, dir_id: i32) {
l.open_sample_file_dirs(&[dir_id]).unwrap(); // TODO: don't unwrap.
let dir = l.sample_file_dirs_by_id().get(&dir_id).unwrap();
let stat = dir.get().unwrap().statfs().unwrap();
fs_capacity = stat.f_bsize as i64 * stat.f_bavail as i64 + total_used;
fs_capacity = stat.block_size() as i64 * stat.blocks_available() as i64 + total_used;
path = dir.path.clone();
}
Rc::new(RefCell::new(Model {

View File

@@ -31,7 +31,7 @@
use db::dir;
use docopt;
use failure::{Error, Fail};
use libc;
use nix::fcntl::FlockArg;
use rusqlite;
use serde::Deserialize;
use std::path::Path;
@@ -84,7 +84,7 @@ enum OpenMode {
fn open_dir(db_dir: &str, mode: OpenMode) -> Result<dir::Fd, Error> {
let dir = dir::Fd::open(db_dir, mode == OpenMode::Create)?;
let ro = mode == OpenMode::ReadOnly;
dir.lock(if ro { libc::LOCK_SH } else { libc::LOCK_EX } | libc::LOCK_NB)
dir.lock(if ro { FlockArg::LockExclusiveNonblock } else { FlockArg::LockSharedNonblock })
.map_err(|e| e.context(format!("db dir {:?} already in use; can't get {} lock",
db_dir, if ro { "shared" } else { "exclusive" })))?;
Ok(dir)