mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
Robust blob filename backup import/export
This ignores invalid UTF-8 filenames during import and export. Rust core does not produce them, but it was possible to have such filenames with C core.
This commit is contained in:
28
src/imex.rs
28
src/imex.rs
@@ -612,8 +612,13 @@ async fn import_backup_old(context: &Context, backup_to_import: &Path) -> Result
|
|||||||
|
|
||||||
let mut all_files_extracted = true;
|
let mut all_files_extracted = true;
|
||||||
for (processed_files_cnt, file_id) in file_ids.into_iter().enumerate() {
|
for (processed_files_cnt, file_id) in file_ids.into_iter().enumerate() {
|
||||||
|
if context.shall_stop_ongoing().await {
|
||||||
|
all_files_extracted = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Load a single blob into memory
|
// Load a single blob into memory
|
||||||
let (file_name, file_blob) = context
|
match context
|
||||||
.sql
|
.sql
|
||||||
.query_row(
|
.query_row(
|
||||||
"SELECT file_name, file_content FROM backup_blobs WHERE id = ?",
|
"SELECT file_name, file_content FROM backup_blobs WHERE id = ?",
|
||||||
@@ -624,12 +629,17 @@ async fn import_backup_old(context: &Context, backup_to_import: &Path) -> Result
|
|||||||
Ok((file_name, file_blob))
|
Ok((file_name, file_blob))
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?;
|
.await
|
||||||
|
{
|
||||||
if context.shall_stop_ongoing().await {
|
Ok((file_name, file_blob)) => {
|
||||||
all_files_extracted = false;
|
let path_filename = context.get_blobdir().join(file_name);
|
||||||
break;
|
dc_write_file(context, &path_filename, &file_blob).await?;
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
error!(context, "Can't import file {}: {}", file_id, err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut permille = processed_files_cnt * 1000 / total_files_cnt;
|
let mut permille = processed_files_cnt * 1000 / total_files_cnt;
|
||||||
if permille < 10 {
|
if permille < 10 {
|
||||||
permille = 10
|
permille = 10
|
||||||
@@ -638,12 +648,6 @@ async fn import_backup_old(context: &Context, backup_to_import: &Path) -> Result
|
|||||||
permille = 990
|
permille = 990
|
||||||
}
|
}
|
||||||
context.emit_event(EventType::ImexProgress(permille));
|
context.emit_event(EventType::ImexProgress(permille));
|
||||||
if file_blob.is_empty() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let path_filename = context.get_blobdir().join(file_name);
|
|
||||||
dc_write_file(context, &path_filename, &file_blob).await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if all_files_extracted {
|
if all_files_extracted {
|
||||||
|
|||||||
@@ -641,8 +641,12 @@ async fn maybe_add_from_param(
|
|||||||
paramsv![],
|
paramsv![],
|
||||||
|row| row.get::<_, String>(0),
|
|row| row.get::<_, String>(0),
|
||||||
|rows| {
|
|rows| {
|
||||||
for row in rows {
|
// Rows that can't be parsed, for example if they are
|
||||||
let param: Params = row?.parse().unwrap_or_default();
|
// not UTF-8 strings, are ignored. It is possible
|
||||||
|
// when upgrading from C core to Rust core, which
|
||||||
|
// guarantees UTF-8 strings everywhere.
|
||||||
|
for row in rows.filter_map(|row| row.ok()) {
|
||||||
|
let param: Params = row.parse().unwrap_or_default();
|
||||||
if let Some(file) = param.get(param_id) {
|
if let Some(file) = param.get(param_id) {
|
||||||
maybe_add_file(files_in_use, file);
|
maybe_add_file(files_in_use, file);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user