mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-08-06 17:40:59 +00:00
fix(config): attempt to deserialize deep directory structure before flat
This meant that if you had set the directory structure, than it would always deserialize as "Flat". We also migrate the newly migrated media to the deep directory structure, if configured.
This commit is contained in:
parent
c5901b90ee
commit
a566a5687b
2 changed files with 39 additions and 4 deletions
|
@ -527,8 +527,8 @@ impl Default for DirectoryStructure {
|
|||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum ShadowDirectoryStructure {
|
||||
Flat {},
|
||||
Deep { length: NonZeroU8, depth: NonZeroU8 },
|
||||
Flat {},
|
||||
}
|
||||
|
||||
impl TryFrom<ShadowDirectoryStructure> for DirectoryStructure {
|
||||
|
|
|
@ -459,7 +459,7 @@ impl KeyValueDatabase {
|
|||
}
|
||||
|
||||
// If the database has any data, perform data migrations before starting
|
||||
let latest_database_version = 17;
|
||||
let latest_database_version = 18;
|
||||
|
||||
if services().users.count()? > 0 {
|
||||
// MIGRATIONS
|
||||
|
@ -1050,9 +1050,44 @@ impl KeyValueDatabase {
|
|||
return Err(e);
|
||||
}
|
||||
}
|
||||
services().globals.bump_database_version(17)?;
|
||||
services().globals.bump_database_version(18)?;
|
||||
|
||||
warn!("Migration: 16 -> 17 finished");
|
||||
warn!("Migration: 16 -> 18 finished");
|
||||
}
|
||||
|
||||
if services().globals.database_version()? < 18 {
|
||||
if let crate::config::MediaBackendConfig::FileSystem {
|
||||
path,
|
||||
directory_structure: crate::config::DirectoryStructure::Deep { length, depth },
|
||||
} = &services().globals.config.media.backend
|
||||
{
|
||||
for file in fs::read_dir(path)
|
||||
.unwrap()
|
||||
.filter_map(Result::ok)
|
||||
.filter(|entry| {
|
||||
entry.file_name().len() == 64
|
||||
&& entry.path().parent().and_then(|parent| parent.to_str())
|
||||
== Some(path.as_str())
|
||||
})
|
||||
{
|
||||
tokio::fs::rename(
|
||||
file.path(),
|
||||
services().globals.get_media_path(
|
||||
path.as_str(),
|
||||
&crate::config::DirectoryStructure::Deep {
|
||||
length: *length,
|
||||
depth: *depth,
|
||||
},
|
||||
file.file_name().to_str().unwrap(),
|
||||
)?,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
services().globals.bump_database_version(18)?;
|
||||
|
||||
warn!("Migration: 17 -> 18 finished");
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue