mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
check for invalid collections in full_upload()
This commit is contained in:
parent
6fb6ffa1d7
commit
6296e93c21
2 changed files with 20 additions and 5 deletions
|
@ -5,7 +5,11 @@ pub(crate) mod timestamps;
|
|||
mod transact;
|
||||
pub(crate) mod undo;
|
||||
|
||||
use std::{collections::HashMap, path::PathBuf, sync::Arc};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
browser_table,
|
||||
|
@ -65,6 +69,15 @@ pub fn open_test_collection_with_server(server: bool) -> Collection {
|
|||
open_collection(":memory:", "", "", server, tr, log::terminal()).unwrap()
|
||||
}
|
||||
|
||||
/// Helper used by syncing to make sure the file can be opened. This should be replaced
|
||||
/// with a builder in the future.
|
||||
pub(crate) fn open_and_check_collection(col_path: &Path) -> Result<Collection> {
|
||||
use crate::log;
|
||||
let tr = I18n::template_only();
|
||||
let empty = Path::new("");
|
||||
open_collection(col_path, &empty, &empty, true, tr, log::terminal())
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct CollectionState {
|
||||
pub(crate) undo: UndoManager,
|
||||
|
|
|
@ -8,6 +8,7 @@ use tempfile::NamedTempFile;
|
|||
|
||||
use super::ChunkableIds;
|
||||
use crate::{
|
||||
collection::open_and_check_collection,
|
||||
prelude::*,
|
||||
storage::open_and_check_sqlite_file,
|
||||
sync::{
|
||||
|
@ -197,12 +198,13 @@ impl SyncServer for LocalServer {
|
|||
col_path = new_file.path();
|
||||
}
|
||||
|
||||
open_and_check_sqlite_file(col_path).map_err(|check_err| {
|
||||
match fs::remove_file(col_path) {
|
||||
// ensure it's a valid sqlite file, and a valid collection
|
||||
open_and_check_sqlite_file(col_path)
|
||||
.and_then(|_| open_and_check_collection(col_path))
|
||||
.map_err(|check_err| match fs::remove_file(col_path) {
|
||||
Ok(_) => check_err,
|
||||
Err(remove_err) => remove_err.into(),
|
||||
}
|
||||
})?;
|
||||
})?;
|
||||
|
||||
let target_col_path = self.col.col_path.clone();
|
||||
self.col.close(false)?;
|
||||
|
|
Loading…
Reference in a new issue