Copies one template flavor's store into place for `project_root`: data dir under the target profile root, global DB (only if absent), and rewrites the absolute paths embedded in config + manifest.
(flavor: &Path, project_root: &Path, targets: &SeedTargets)
| 168 | /// data dir under the target profile root, global DB (only if absent), and |
| 169 | /// rewrites the absolute paths embedded in config + manifest. |
| 170 | fn seed_store(flavor: &Path, project_root: &Path, targets: &SeedTargets) -> io::Result<()> { |
| 171 | fs::create_dir_all(project_root)?; |
| 172 | let src_home = flavor.join("home/.tracedecay"); |
| 173 | let src_data = sole_subdir(&src_home.join("projects"))?; |
| 174 | |
| 175 | let project_id = default_profile_project_id(project_root); |
| 176 | let data_dest = targets.profile_root.join("projects").join(&project_id); |
| 177 | if data_dest.exists() { |
| 178 | // A store already exists for this project (e.g. re-init); let the |
| 179 | // caller fall back to the real init path. |
| 180 | return Err(io::Error::new( |
| 181 | io::ErrorKind::AlreadyExists, |
| 182 | "store data dir already exists", |
| 183 | )); |
| 184 | } |
| 185 | copy_tree(&src_data, &data_dest)?; |
| 186 | |
| 187 | rewrite_json(&data_dest.join("config.json"), |config| { |
| 188 | config["root_dir"] = Value::String(project_root.to_string_lossy().into_owned()); |
| 189 | })?; |
| 190 | rewrite_json(&data_dest.join("store_manifest.json"), |manifest| { |
| 191 | manifest["project_id"] = Value::String(project_id.clone()); |
| 192 | manifest["project_root"] = Value::String(project_root.to_string_lossy().into_owned()); |
| 193 | manifest["data_root"] = Value::String(data_dest.to_string_lossy().into_owned()); |
| 194 | })?; |
| 195 | |
| 196 | if !targets.global_db_path.exists() { |
| 197 | if let Some(parent) = targets.global_db_path.parent() { |
| 198 | fs::create_dir_all(parent)?; |
| 199 | } |
| 200 | copy_db_files(&src_home.join("global.db"), &targets.global_db_path)?; |
| 201 | } |
| 202 | Ok(()) |
| 203 | } |
| 204 | |
| 205 | async fn template_root() -> Option<&'static Path> { |
| 206 | TEMPLATE_ROOT |
no test coverage detected