settings/
storage_migrations.rs1use crate::base::SettingType;
6use crate::migration::{MigrationError, MigrationManager, MigrationManagerBuilder};
7use fidl_fuchsia_io::DirectoryProxy;
8use fidl_fuchsia_stash::StoreProxy;
9use std::collections::HashSet;
10use v1653667208_light_migration::V1653667208LightMigration;
11use v1653667210_light_migration_teardown::V1653667210LightMigrationTeardown;
12
13mod v1653667208_light_migration;
14mod v1653667210_light_migration_teardown;
15
16pub(crate) fn register_migrations(
17 settings: &HashSet<SettingType>,
18 migration_dir: DirectoryProxy,
19 store_proxy: StoreProxy,
20) -> Result<MigrationManager, MigrationError> {
21 let mut builder = MigrationManagerBuilder::new();
22 builder.set_migration_dir(migration_dir);
23 if settings.contains(&SettingType::Light) {
24 builder.register(V1653667208LightMigration(store_proxy.clone()))?;
25 builder.register(V1653667210LightMigrationTeardown(store_proxy))?;
26 }
27 Ok(builder.build())
28}
29
30#[cfg(test)]
31mod tests {
32 use super::*;
33 use fidl::endpoints::create_proxy;
34 use fidl_fuchsia_io::DirectoryMarker;
35 use fidl_fuchsia_stash::StoreMarker;
36 use fuchsia_async as fasync;
37
38 #[fasync::run_until_stalled(test)]
41 async fn ensure_unique_ids() {
42 let mut settings = HashSet::new();
43 let _ = settings.insert(SettingType::Accessibility);
44 let _ = settings.insert(SettingType::Audio);
45 let _ = settings.insert(SettingType::Display);
46 let _ = settings.insert(SettingType::DoNotDisturb);
47 let _ = settings.insert(SettingType::FactoryReset);
48 let _ = settings.insert(SettingType::Input);
49 let _ = settings.insert(SettingType::Intl);
50 let _ = settings.insert(SettingType::Keyboard);
51 let _ = settings.insert(SettingType::Light);
52 let _ = settings.insert(SettingType::NightMode);
53 let _ = settings.insert(SettingType::Privacy);
54 let _ = settings.insert(SettingType::Setup);
55 let (directory_proxy, _) = create_proxy::<DirectoryMarker>();
56 let (store_proxy, _) = create_proxy::<StoreMarker>();
57 if let Err(e) = register_migrations(&settings, directory_proxy, store_proxy) {
58 panic!("Unable to register migrations: Err({e:?})");
59 }
60 }
61
62 pub(crate) fn open_tempdir(tempdir: &tempfile::TempDir) -> DirectoryProxy {
64 fuchsia_fs::directory::open_in_namespace(
65 tempdir.path().to_str().expect("tempdir path is not valid UTF-8"),
66 fuchsia_fs::PERM_READABLE | fuchsia_fs::PERM_WRITABLE,
67 )
68 .expect("failed to open connection to tempdir")
69 }
70}