Make downgrading apkgs depend on meta version

This commit is contained in:
RumovZ 2022-04-29 13:44:36 +02:00
parent c65d1818ed
commit 06cc44a3ed
2 changed files with 32 additions and 10 deletions

View file

@ -19,7 +19,6 @@ use crate::{
},
io::{atomic_rename, tempfile_in_parent_of},
prelude::*,
storage::SchemaVersion,
};
impl Collection {
@ -41,8 +40,18 @@ impl Collection {
.path()
.to_str()
.ok_or_else(|| AnkiError::IoError("tempfile with non-unicode name".into()))?;
let data =
self.export_into_collection_file(temp_col_path, search, with_scheduling, with_media)?;
let meta = if legacy {
Meta::new_legacy()
} else {
Meta::new()
};
let data = self.export_into_collection_file(
&meta,
temp_col_path,
search,
with_scheduling,
with_media,
)?;
let media = if let Some(media_fn) = media_fn {
media_fn(data.media_paths)
@ -52,11 +61,7 @@ impl Collection {
let col_size = temp_col.as_file().metadata()?.len() as usize;
export_collection(
if legacy {
Meta::new_legacy()
} else {
Meta::new()
},
meta,
temp_apkg.path(),
&mut temp_col,
col_size,
@ -70,6 +75,7 @@ impl Collection {
fn export_into_collection_file(
&mut self,
meta: &Meta,
path: &str,
search: impl TryIntoSearch,
with_scheduling: bool,
@ -85,7 +91,7 @@ impl Collection {
temp_col.insert_data(&data)?;
temp_col.set_creation_stamp(self.storage.creation_stamp()?)?;
temp_col.set_creation_utc_offset(data.creation_utc_offset)?;
temp_col.close(Some(SchemaVersion::V11))?;
temp_col.close(Some(meta.schema_version()))?;
Ok(data)
}

View file

@ -7,7 +7,7 @@ use prost::Message;
use zip::ZipArchive;
pub(super) use crate::backend_proto::{package_metadata::Version, PackageMetadata as Meta};
use crate::{error::ImportError, prelude::*};
use crate::{error::ImportError, prelude::*, storage::SchemaVersion};
impl Version {
pub(super) fn collection_filename(&self) -> &'static str {
@ -18,6 +18,16 @@ impl Version {
Version::Latest => "collection.anki21b",
}
}
/// Latest schema version that is supported by all clients supporting
/// this package version.
pub(super) fn schema_version(&self) -> SchemaVersion {
match self {
Version::Unknown => unreachable!(),
Version::Legacy1 | Version::Legacy2 => SchemaVersion::V11,
Version::Latest => SchemaVersion::V18,
}
}
}
impl Meta {
@ -62,6 +72,12 @@ impl Meta {
self.version().collection_filename()
}
/// Latest schema version that is supported by all clients supporting
/// this package version.
pub(super) fn schema_version(&self) -> SchemaVersion {
self.version().schema_version()
}
pub(super) fn zstd_compressed(&self) -> bool {
!self.is_legacy()
}