finally fixed memory leak

This commit is contained in:
rabite 2019-03-31 03:28:07 +02:00
parent ed6abefc3c
commit ed32c83aca
5 changed files with 22 additions and 6 deletions

View File

@ -12,6 +12,7 @@ x11-clipboard = "*"
alphanumeric-sort = "1.0.6"
lscolors = { version = "0.5.0", features = [ "ansi_term" ] }
mime-detective = "*"
tree_magic = "0.2.1"
rayon = "1.0.3"
dirs-2 = "1.1.0"
users = "0.8"

View File

@ -10,7 +10,7 @@ use std::os::unix::ffi::{OsStringExt, OsStrExt};
use std::ffi::{OsStr, OsString};
use lscolors::LsColors;
use mime_detective;
use tree_magic;
use users::{get_current_username,
get_current_groupname,
get_user_by_uid,
@ -717,10 +717,12 @@ impl File {
Ok((size, unit))
}
pub fn get_mime(&self) -> Option<String> {
let detective = mime_detective::MimeDetective::new().ok()?;
let mime = detective.detect_filepath(&self.path).ok()?;
Some(mime.type_().as_str().to_string())
// pub fn get_mime(&self) -> String {
// tree_magic::from_filepath(&self.path)
// }
pub fn is_text(&self) -> bool {
tree_magic::match_filepath("text/plain", &self.path)
}

View File

@ -54,10 +54,18 @@ impl<T> HBox<T> where T: Widget + PartialEq {
widget
}
pub fn remove_widget(&mut self, index: usize) -> T {
self.widgets.remove(index)
}
pub fn prepend_widget(&mut self, widget: T) {
self.widgets.insert(0, widget);
}
pub fn insert_widget(&mut self, index: usize, widget: T) {
self.widgets.insert(index, widget);
}
pub fn toggle_zoom(&mut self) -> HResult<()> {
self.clear().log();
self.zoom_active = !self.zoom_active;

View File

@ -20,6 +20,7 @@ extern crate libc;
extern crate notify;
extern crate parse_ansi;
extern crate signal_notify;
extern crate tree_magic;
use failure::Fail;

View File

@ -434,6 +434,10 @@ impl Previewer {
self.widget.set_stale()
}
pub fn get_file(&self) -> Option<&File> {
self.file.as_ref()
}
pub fn set_file(&mut self,
file: &File) -> HResult<()> {
if Some(file) == self.file.as_ref() && !self.widget.is_stale()? { return Ok(()) }
@ -458,7 +462,7 @@ impl Previewer {
return preview;
}
if file.get_mime() == Some("text".to_string()) {
if file.is_text() {
return Previewer::preview_text(&file, &core, stale)
}