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:
@@ -527,8 +527,8 @@ impl Default for DirectoryStructure {
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
enum ShadowDirectoryStructure {
|
enum ShadowDirectoryStructure {
|
||||||
Flat {},
|
|
||||||
Deep { length: NonZeroU8, depth: NonZeroU8 },
|
Deep { length: NonZeroU8, depth: NonZeroU8 },
|
||||||
|
Flat {},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<ShadowDirectoryStructure> for DirectoryStructure {
|
impl TryFrom<ShadowDirectoryStructure> for DirectoryStructure {
|
||||||
|
|||||||
@@ -459,7 +459,7 @@ impl KeyValueDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the database has any data, perform data migrations before starting
|
// 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 {
|
if services().users.count()? > 0 {
|
||||||
// MIGRATIONS
|
// MIGRATIONS
|
||||||
@@ -1050,9 +1050,44 @@ impl KeyValueDatabase {
|
|||||||
return Err(e);
|
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!(
|
assert_eq!(
|
||||||
|
|||||||
Reference in New Issue
Block a user