|
|
@ -4,6 +4,7 @@ use std::path::PathBuf;
|
|
|
|
use directories::ProjectDirs;
|
|
|
|
use directories::ProjectDirs;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use crate::config::Config;
|
|
|
|
use crate::config::Config;
|
|
|
|
use crate::plan::{convert_old, Plan, PlanMetadata};
|
|
|
|
use crate::plan::{convert_old, Plan, PlanMetadata};
|
|
|
|
|
|
|
|
|
|
|
@ -101,13 +102,13 @@ impl Storage {
|
|
|
|
Some(plan)
|
|
|
|
Some(plan)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn save_plan_at_store_path(file_name: &str, plan: Plan) -> Result<(), Box<dyn Error>> {
|
|
|
|
pub fn save_plan_at_store_path(file_name: &str, mut plan: Plan) -> Result<PathBuf, Box<dyn Error>> {
|
|
|
|
let plan_dir = match Self::plan_dir() {
|
|
|
|
let plan_dir = match Self::plan_dir() {
|
|
|
|
Some(dir) => dir,
|
|
|
|
Some(dir) => dir,
|
|
|
|
None => return Err("No plan dir".into()),
|
|
|
|
None => return Err("No plan dir".into()),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let file_path = plan_dir.with_file_name(file_name).with_extension("json");
|
|
|
|
let file_path = plan_dir.join(file_name).with_extension("json");
|
|
|
|
|
|
|
|
|
|
|
|
//Disallow overwriting.
|
|
|
|
//Disallow overwriting.
|
|
|
|
if file_path.exists() {
|
|
|
|
if file_path.exists() {
|
|
|
@ -115,11 +116,11 @@ impl Storage {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: Determine necessity
|
|
|
|
//TODO: Determine necessity
|
|
|
|
// plan.set_stored_path(file_path.clone());
|
|
|
|
plan.set_stored_path(Some(file_path.clone()));
|
|
|
|
|
|
|
|
|
|
|
|
std::fs::write(file_path, serde_json::to_string(&plan)?)?;
|
|
|
|
std::fs::write(&file_path, serde_json::to_string(&plan)?)?;
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
Ok(file_path.clone())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn enumerate_plans() -> Vec<PlanMetadata> {
|
|
|
|
pub fn enumerate_plans() -> Vec<PlanMetadata> {
|
|
|
|