fix missing log when removed directory names have same prefix
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
parent
6a0db02230
commit
f2d345e7b1
@ -123,14 +123,21 @@ class CmFileModel {
|
|||||||
}
|
}
|
||||||
int removeUnreadCount = 0;
|
int removeUnreadCount = 0;
|
||||||
if (data.dir) {
|
if (data.dir) {
|
||||||
|
bool isChild(String parent, String child) {
|
||||||
|
if (child.startsWith(parent) && child.length > parent.length) {
|
||||||
|
final suffix = child.substring(parent.length);
|
||||||
|
return suffix.startsWith('/') || suffix.startsWith('\\');
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
removeUnreadCount = jobTable
|
removeUnreadCount = jobTable
|
||||||
.where((e) =>
|
.where((e) =>
|
||||||
e.action == CmFileAction.remove &&
|
e.action == CmFileAction.remove &&
|
||||||
e.fileName.startsWith(data.path))
|
isChild(data.path, e.fileName))
|
||||||
.length;
|
.length;
|
||||||
jobTable.removeWhere((e) =>
|
jobTable.removeWhere((e) =>
|
||||||
e.action == CmFileAction.remove &&
|
e.action == CmFileAction.remove && isChild(data.path, e.fileName));
|
||||||
e.fileName.startsWith(data.path));
|
|
||||||
}
|
}
|
||||||
jobTable.add(CmFileLog()
|
jobTable.add(CmFileLog()
|
||||||
..id = data.id
|
..id = data.id
|
||||||
|
@ -49,6 +49,7 @@ use sha2::{Digest, Sha256};
|
|||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::{
|
use std::{
|
||||||
num::NonZeroI64,
|
num::NonZeroI64,
|
||||||
|
path::PathBuf,
|
||||||
sync::{atomic::AtomicI64, mpsc as std_mpsc},
|
sync::{atomic::AtomicI64, mpsc as std_mpsc},
|
||||||
};
|
};
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
@ -2953,12 +2954,17 @@ impl FileRemoveLogControl {
|
|||||||
|
|
||||||
fn on_remove_dir(&mut self, d: FileRemoveDir) -> Option<ipc::Data> {
|
fn on_remove_dir(&mut self, d: FileRemoveDir) -> Option<ipc::Data> {
|
||||||
self.instant = Instant::now();
|
self.instant = Instant::now();
|
||||||
self.removed_files.retain(|f| !f.path.starts_with(&d.path));
|
let direct_child = |parent: &str, child: &str| {
|
||||||
self.removed_dirs.retain(|x| !x.path.starts_with(&d.path));
|
PathBuf::from(child).parent().map(|x| x.to_path_buf()) == Some(PathBuf::from(parent))
|
||||||
|
};
|
||||||
|
self.removed_files
|
||||||
|
.retain(|f| !direct_child(&f.path, &d.path));
|
||||||
|
self.removed_dirs
|
||||||
|
.retain(|x| !direct_child(&d.path, &x.path));
|
||||||
if !self
|
if !self
|
||||||
.removed_dirs
|
.removed_dirs
|
||||||
.iter()
|
.iter()
|
||||||
.any(|x| d.path.starts_with(&x.path))
|
.any(|x| direct_child(&x.path, &d.path))
|
||||||
{
|
{
|
||||||
self.removed_dirs.push(d.clone());
|
self.removed_dirs.push(d.clone());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user