melib: recreate removed email if it comes back

If an email is removed by an outside actor, it is marked as removed.
Renaming files first send a Remove event and then a Rename one. So if a
removed email turns out to have been renamed by someone else, issue a
Create event to get it back.
embed
Manos Pitsidianakis 2019-08-04 00:37:48 +03:00
parent 16a5d9b28a
commit 89b1e381dc
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
1 changed files with 26 additions and 8 deletions

View File

@ -369,21 +369,39 @@ impl MailBackend for MaildirType {
let mut hash_indexes_lock = hash_indexes.lock().unwrap();
let index_lock = hash_indexes_lock.entry(folder_hash).or_default();
if index_lock.contains_key(&old_hash) {
if index_lock.contains_key(&old_hash)
&& !index_lock[&old_hash].removed
{
debug!("contains_old_key");
index_lock.entry(old_hash).and_modify(|e| {
debug!(&e.modified);
e.modified = Some(PathMod::Hash(new_hash));
});
sender.send(RefreshEvent {
hash: get_path_hash!(dest),
kind: Rename(old_hash, new_hash),
});
index_lock.entry(old_hash).and_modify(|e| {
debug!(&e.modified);
e.modified = Some(PathMod::Hash(new_hash));
e.removed = false;
});
index_lock.insert(new_hash, dest.into());
continue;
} else if !index_lock.contains_key(&new_hash) {
debug!("not contains_new_key");
} else if !index_lock.contains_key(&new_hash)
|| index_lock
.get(&old_hash)
.map(|e| e.removed)
.unwrap_or(false)
{
if index_lock
.get(&old_hash)
.map(|e| e.removed)
.unwrap_or(false)
{
index_lock.entry(old_hash).and_modify(|e| {
e.modified = Some(PathMod::Hash(new_hash));
e.removed = false;
});
debug!("contains_old_key, key was marked as removed (by external source)");
} else {
debug!("not contains_new_key");
}
let file_name = dest
.as_path()
.strip_prefix(&root_path)