From 000bd4ab9e70379b2205c4c6dfe361e379484b85 Mon Sep 17 00:00:00 2001 From: rabite Date: Wed, 3 Apr 2019 00:43:02 +0200 Subject: also import tags --- src/files.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/files.rs') diff --git a/src/files.rs b/src/files.rs index 01620bd..afe684d 100644 --- a/src/files.rs +++ b/src/files.rs @@ -51,8 +51,16 @@ fn make_pool(sender: Option>) -> ThreadPool { pub fn load_tags() -> HResult<()> { std::thread::spawn(|| -> HResult<()> { let tag_path = crate::paths::tagfile_path()?; + + if !tag_path.exists() { + import_tags().log(); + } + let tags = std::fs::read_to_string(tag_path)?; - let mut tags = tags.lines().map(|f| PathBuf::from(f)).collect::>(); + let mut tags = tags.lines() + .map(|f| + PathBuf::from(f)) + .collect::>(); let mut tag_lock = TAGS.write()?; tag_lock.0 = true; tag_lock.1.append(&mut tags); @@ -61,6 +69,17 @@ pub fn load_tags() -> HResult<()> { 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 { tags_loaded()?; let tagged = TAGS.read()?.1.contains(path); -- cgit v1.2.3