fix: Js deep dir (#1784)

* fix: Js deep dir

* Delete broken.log

* Delete test.log

* fix: Remove  the == parent
This commit is contained in:
J M
2022-09-08 13:57:13 -06:00
committed by GitHub
parent f0466aaa56
commit 5442459b2d
4 changed files with 476 additions and 391 deletions

View File

@@ -772,7 +772,22 @@ mod fns {
parent: impl AsRef<Path>,
child: impl AsRef<Path>,
) -> Result<bool, AnyError> {
let child = tokio::fs::canonicalize(child).await?;
let child = {
let mut child = child.as_ref();
loop {
let meta = tokio::fs::metadata(child).await;
if meta.is_ok() {
break;
}
child = match child.parent() {
Some(child) => child,
None => {
return Ok(false);
}
};
}
tokio::fs::canonicalize(child).await?
};
let parent = tokio::fs::canonicalize(parent).await?;
Ok(child.starts_with(parent))
}