diff options
author | rabite <rabite@posteo.de> | 2019-04-03 00:43:02 +0200 |
---|---|---|
committer | rabite <rabite@posteo.de> | 2019-04-03 00:43:02 +0200 |
commit | 000bd4ab9e70379b2205c4c6dfe361e379484b85 (patch) | |
tree | a240ecefa3c141ec45624ee4956802d721ead785 | |
parent | 0519f65392289bfdce6e8d140b31384019bd2748 (diff) |
also import tags
-rw-r--r-- | src/files.rs | 21 |
1 files changed, 20 insertions, 1 deletions
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<Sender<Events>>) -> 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::<Vec<PathBuf>>(); + let mut tags = tags.lines() + .map(|f| + PathBuf::from(f)) + .collect::<Vec<PathBuf>>(); 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<bool> { tags_loaded()?; let tagged = TAGS.read()?.1.contains(path); |