mirror of https://github.com/bobwen-dev/hunter
also import tags
This commit is contained in:
parent
0519f65392
commit
000bd4ab9e
21
src/files.rs
21
src/files.rs
|
@ -51,8 +51,16 @@ fn make_pool(sender: Option<Sender<Events>>) -> ThreadPool {
|
||||||
pub fn load_tags() -> HResult<()> {
|
pub fn load_tags() -> HResult<()> {
|
||||||
std::thread::spawn(|| -> HResult<()> {
|
std::thread::spawn(|| -> HResult<()> {
|
||||||
let tag_path = crate::paths::tagfile_path()?;
|
let tag_path = crate::paths::tagfile_path()?;
|
||||||
|
|
||||||
|
if !tag_path.exists() {
|
||||||
|
import_tags().log();
|
||||||
|
}
|
||||||
|
|
||||||
let tags = std::fs::read_to_string(tag_path)?;
|
let tags = std::fs::read_to_string(tag_path)?;
|
||||||
let mut tags = tags.lines().map(|f| PathBuf::from(f)).collect::<Vec<PathBuf>>();
|
let mut tags = tags.lines()
|
||||||
|
.map(|f|
|
||||||
|
PathBuf::from(f))
|
||||||
|
.collect::<Vec<PathBuf>>();
|
||||||
let mut tag_lock = TAGS.write()?;
|
let mut tag_lock = TAGS.write()?;
|
||||||
tag_lock.0 = true;
|
tag_lock.0 = true;
|
||||||
tag_lock.1.append(&mut tags);
|
tag_lock.1.append(&mut tags);
|
||||||
|
@ -61,6 +69,17 @@ pub fn load_tags() -> HResult<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn import_tags() -> HResult<()> {
|
||||||
|
let mut ranger_tags = crate::paths::ranger_path()?;
|
||||||
|
ranger_tags.push("tagged");
|
||||||
|
|
||||||
|
if ranger_tags.exists() {
|
||||||
|
let tag_path = crate::paths::tagfile_path()?;
|
||||||
|
std::fs::copy(ranger_tags, tag_path)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn check_tag(path: &PathBuf) -> HResult<bool> {
|
pub fn check_tag(path: &PathBuf) -> HResult<bool> {
|
||||||
tags_loaded()?;
|
tags_loaded()?;
|
||||||
let tagged = TAGS.read()?.1.contains(path);
|
let tagged = TAGS.read()?.1.contains(path);
|
||||||
|
|
Loading…
Reference in New Issue