mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-11-27 20:58:56 -05:00
use nix to remove many uses of unsafe
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user