mirror of
https://github.com/solokeys/admin-app.git
synced 2026-06-20 13:16:17 -07:00
Use clientfilestore to store config after migration (migrations run before trussed is up)
This commit is contained in:
+7
-2
@@ -225,7 +225,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub fn migrate(&mut self, to_version: u32, store: impl Store) -> Result<(), ConfigError> {
|
||||
pub fn migrate<F: Filestore>(
|
||||
&mut self,
|
||||
to_version: u32,
|
||||
store: impl Store,
|
||||
filestore: &mut F,
|
||||
) -> Result<(), ConfigError> {
|
||||
let Some(current_version) = self.config.migration_version() else {
|
||||
// Migrate cannot be done for configurations that don't provide storage of the filesystem version
|
||||
return Err(ConfigError::InvalidValue);
|
||||
@@ -254,7 +259,7 @@ where
|
||||
if !self.config.set_migration_version(to_version) {
|
||||
return Err(ConfigError::InvalidValue);
|
||||
}
|
||||
config::save(&mut self.trussed, &self.config)
|
||||
config::save_filestore(filestore, &self.config)
|
||||
}
|
||||
|
||||
/// Create an admin app instance without the configuration mechanism, using the default config
|
||||
|
||||
@@ -225,6 +225,26 @@ pub fn load<F: Filestore, C: Config>(store: &mut F) -> Result<C, ConfigError> {
|
||||
cbor_deserialize(&data).map_err(|_| ConfigError::DeserializationFailed)
|
||||
}
|
||||
|
||||
pub fn save_filestore<F: Filestore, C: Config>(
|
||||
store: &mut F,
|
||||
config: &C,
|
||||
) -> Result<(), ConfigError> {
|
||||
if config == &C::default() {
|
||||
if store.exists(FILENAME, LOCATION) {
|
||||
store
|
||||
.remove_file(FILENAME, LOCATION)
|
||||
.map_err(|_| ConfigError::WriteFailed)?;
|
||||
}
|
||||
} else {
|
||||
let data: Message =
|
||||
cbor_serialize_bytes(config).map_err(|_| ConfigError::SerializationFailed)?;
|
||||
store
|
||||
.write(FILENAME, LOCATION, &data)
|
||||
.map_err(|_| ConfigError::SerializationFailed)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn save<T: Client, C: Config>(client: &mut T, config: &C) -> Result<(), ConfigError> {
|
||||
if config == &Default::default() {
|
||||
if exists(client, LOCATION, FILENAME)? {
|
||||
|
||||
Reference in New Issue
Block a user