vs_core/service/
migrate.rs1use crate::{App, CoreError, MigrateSummary};
4
5impl App {
6 pub fn migrate(&self, source: Option<String>) -> Result<MigrateSummary, CoreError> {
8 let source_home = source
9 .map(|source| self.normalize_source_path(&source))
10 .or_else(|| self.home_layout.migration_candidates.first().cloned())
11 .ok_or(CoreError::MissingMigrationSource)?;
12
13 let mut copied_roots = 0;
14 for relative in ["config.yaml", "global", "registry", "plugins", "cache"] {
15 let source_path = source_home.join(relative);
16 let destination_path = if relative == "cache" {
17 self.runtime_root().to_path_buf()
18 } else {
19 self.home().join(relative)
20 };
21 if !source_path.exists() {
22 continue;
23 }
24 if source_path.is_dir() {
25 self.copy_tree(&source_path, &destination_path)?;
26 } else {
27 if let Some(parent) = destination_path.parent() {
28 std::fs::create_dir_all(parent)?;
29 }
30 std::fs::copy(&source_path, &destination_path)?;
31 }
32 copied_roots += 1;
33 }
34
35 Ok(MigrateSummary {
36 source_home,
37 copied_roots,
38 })
39 }
40}