Compare commits

...

1 Commits

Author SHA1 Message Date
link2xt
d6d4ba7aca 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.
2021-06-14 21:53:51 +03:00
2 changed files with 22 additions and 14 deletions

View File

@@ -612,8 +612,13 @@ async fn import_backup_old(context: &Context, backup_to_import: &Path) -> Result
let mut all_files_extracted = true;
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
let (file_name, file_blob) = context
match context
.sql
.query_row(
"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))
},
)
.await?;
if context.shall_stop_ongoing().await {
all_files_extracted = false;
break;
.await
{
Ok((file_name, file_blob)) => {
let path_filename = context.get_blobdir().join(file_name);
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;
if permille < 10 {
permille = 10
@@ -638,12 +648,6 @@ async fn import_backup_old(context: &Context, backup_to_import: &Path) -> Result
permille = 990
}
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 {

View File

@@ -641,8 +641,12 @@ async fn maybe_add_from_param(
paramsv![],
|row| row.get::<_, String>(0),
|rows| {
for row in rows {
let param: Params = row?.parse().unwrap_or_default();
// Rows that can't be parsed, for example if they are
// 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) {
maybe_add_file(files_in_use, file);
}