mj 0.4.3

My Journal - personal tool to capture ideas, work with journals, notes and tasks in your favourite text $EDITOR.
Documentation
use crate::core::*;
use std::fs;
use uuid::Uuid;

pub fn check_filename(name: &String) -> Result<()> {
  let parent = format!("{}", Uuid::new_v4());
  let root = std::env::temp_dir().join(parent);
  fs::create_dir_all(&root)?;
  let path = root.join(name);
  let is_valid =
    match fs::File::create(&path) {
      Ok(_) => true,
      Err(_) => false,
    };
  fs::remove_dir_all(root)?;
  if is_valid {
    Ok(())
  } else {
    Err(Error::InvalidName)
  }
}