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