mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Make downgrading apkgs depend on meta version
This commit is contained in:
parent
c65d1818ed
commit
06cc44a3ed
2 changed files with 32 additions and 10 deletions
|
@ -19,7 +19,6 @@ use crate::{
|
||||||
},
|
},
|
||||||
io::{atomic_rename, tempfile_in_parent_of},
|
io::{atomic_rename, tempfile_in_parent_of},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
storage::SchemaVersion,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Collection {
|
impl Collection {
|
||||||
|
@ -41,8 +40,18 @@ impl Collection {
|
||||||
.path()
|
.path()
|
||||||
.to_str()
|
.to_str()
|
||||||
.ok_or_else(|| AnkiError::IoError("tempfile with non-unicode name".into()))?;
|
.ok_or_else(|| AnkiError::IoError("tempfile with non-unicode name".into()))?;
|
||||||
let data =
|
let meta = if legacy {
|
||||||
self.export_into_collection_file(temp_col_path, search, with_scheduling, with_media)?;
|
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 {
|
let media = if let Some(media_fn) = media_fn {
|
||||||
media_fn(data.media_paths)
|
media_fn(data.media_paths)
|
||||||
|
@ -52,11 +61,7 @@ impl Collection {
|
||||||
let col_size = temp_col.as_file().metadata()?.len() as usize;
|
let col_size = temp_col.as_file().metadata()?.len() as usize;
|
||||||
|
|
||||||
export_collection(
|
export_collection(
|
||||||
if legacy {
|
meta,
|
||||||
Meta::new_legacy()
|
|
||||||
} else {
|
|
||||||
Meta::new()
|
|
||||||
},
|
|
||||||
temp_apkg.path(),
|
temp_apkg.path(),
|
||||||
&mut temp_col,
|
&mut temp_col,
|
||||||
col_size,
|
col_size,
|
||||||
|
@ -70,6 +75,7 @@ impl Collection {
|
||||||
|
|
||||||
fn export_into_collection_file(
|
fn export_into_collection_file(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
meta: &Meta,
|
||||||
path: &str,
|
path: &str,
|
||||||
search: impl TryIntoSearch,
|
search: impl TryIntoSearch,
|
||||||
with_scheduling: bool,
|
with_scheduling: bool,
|
||||||
|
@ -85,7 +91,7 @@ impl Collection {
|
||||||
temp_col.insert_data(&data)?;
|
temp_col.insert_data(&data)?;
|
||||||
temp_col.set_creation_stamp(self.storage.creation_stamp()?)?;
|
temp_col.set_creation_stamp(self.storage.creation_stamp()?)?;
|
||||||
temp_col.set_creation_utc_offset(data.creation_utc_offset)?;
|
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)
|
Ok(data)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use prost::Message;
|
||||||
use zip::ZipArchive;
|
use zip::ZipArchive;
|
||||||
|
|
||||||
pub(super) use crate::backend_proto::{package_metadata::Version, PackageMetadata as Meta};
|
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 {
|
impl Version {
|
||||||
pub(super) fn collection_filename(&self) -> &'static str {
|
pub(super) fn collection_filename(&self) -> &'static str {
|
||||||
|
@ -18,6 +18,16 @@ impl Version {
|
||||||
Version::Latest => "collection.anki21b",
|
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 {
|
impl Meta {
|
||||||
|
@ -62,6 +72,12 @@ impl Meta {
|
||||||
self.version().collection_filename()
|
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 {
|
pub(super) fn zstd_compressed(&self) -> bool {
|
||||||
!self.is_legacy()
|
!self.is_legacy()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue