Fix endless errors on invalid root path
This commit is contained in:
parent
bb575d705d
commit
01ebf99c5e
2 changed files with 14 additions and 4 deletions
|
@ -22,6 +22,7 @@ pub struct FilesStatement {
|
||||||
recursive: Option<bool>,
|
recursive: Option<bool>,
|
||||||
// state
|
// state
|
||||||
file_iter: Option<FileIter>,
|
file_iter: Option<FileIter>,
|
||||||
|
has_tried: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for FilesStatement {
|
impl Display for FilesStatement {
|
||||||
|
@ -29,7 +30,7 @@ impl Display for FilesStatement {
|
||||||
write!(f, "files(")?;
|
write!(f, "files(")?;
|
||||||
let mut preceding = false;
|
let mut preceding = false;
|
||||||
if let Some(folder) = &self.folder {
|
if let Some(folder) = &self.folder {
|
||||||
write!(f, "folder={}", folder)?;
|
write!(f, "folder=`{}`", folder)?;
|
||||||
preceding = true;
|
preceding = true;
|
||||||
}
|
}
|
||||||
if let Some(regex) = &self.regex {
|
if let Some(regex) = &self.regex {
|
||||||
|
@ -38,7 +39,7 @@ impl Display for FilesStatement {
|
||||||
} else {
|
} else {
|
||||||
preceding = true;
|
preceding = true;
|
||||||
}
|
}
|
||||||
write!(f, "regex={}", regex)?;
|
write!(f, "regex=`{}`", regex)?;
|
||||||
}
|
}
|
||||||
if let Some(recursive) = self.recursive {
|
if let Some(recursive) = self.recursive {
|
||||||
if preceding {
|
if preceding {
|
||||||
|
@ -58,6 +59,7 @@ impl std::clone::Clone for FilesStatement {
|
||||||
regex: self.regex.clone(),
|
regex: self.regex.clone(),
|
||||||
recursive: self.recursive.clone(),
|
recursive: self.recursive.clone(),
|
||||||
file_iter: None,
|
file_iter: None,
|
||||||
|
has_tried: self.has_tried,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,6 +69,11 @@ impl Iterator for FilesStatement {
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
if self.file_iter.is_none() {
|
if self.file_iter.is_none() {
|
||||||
|
if self.has_tried {
|
||||||
|
return None;
|
||||||
|
} else {
|
||||||
|
self.has_tried = true;
|
||||||
|
}
|
||||||
let self_clone = self.clone();
|
let self_clone = self.clone();
|
||||||
let iter = self.context.as_mut().unwrap().filesystem.raw(
|
let iter = self.context.as_mut().unwrap().filesystem.raw(
|
||||||
self.folder.as_deref(),
|
self.folder.as_deref(),
|
||||||
|
@ -218,6 +225,7 @@ impl MpsFunctionFactory<FilesStatement> for FilesFunctionFactory {
|
||||||
regex: pattern,
|
regex: pattern,
|
||||||
recursive: recursive,
|
recursive: recursive,
|
||||||
file_iter: None,
|
file_iter: None,
|
||||||
|
has_tried: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,10 +252,12 @@ impl Iterator for FileIter {
|
||||||
Some(item) => Some(Ok(item)),
|
Some(item) => Some(Ok(item)),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// should be impossible to get here
|
|
||||||
self.dir_iters.push(match self.root.read_dir() {
|
self.dir_iters.push(match self.root.read_dir() {
|
||||||
Ok(x) => x.into(),
|
Ok(x) => x.into(),
|
||||||
Err(e) => return Some(Err(format!("Directory read error: {}", e))),
|
Err(e) => {
|
||||||
|
self.is_complete = true;
|
||||||
|
return Some(Err(format!("Directory read error: {}", e)));
|
||||||
|
},
|
||||||
});
|
});
|
||||||
return self.next();
|
return self.next();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue