diff --git a/mps-interpreter/src/lang/vocabulary/files.rs b/mps-interpreter/src/lang/vocabulary/files.rs index 35be613..871ca44 100644 --- a/mps-interpreter/src/lang/vocabulary/files.rs +++ b/mps-interpreter/src/lang/vocabulary/files.rs @@ -22,6 +22,7 @@ pub struct FilesStatement { recursive: Option, // state file_iter: Option, + has_tried: bool, } impl Display for FilesStatement { @@ -29,7 +30,7 @@ impl Display for FilesStatement { write!(f, "files(")?; let mut preceding = false; if let Some(folder) = &self.folder { - write!(f, "folder={}", folder)?; + write!(f, "folder=`{}`", folder)?; preceding = true; } if let Some(regex) = &self.regex { @@ -38,7 +39,7 @@ impl Display for FilesStatement { } else { preceding = true; } - write!(f, "regex={}", regex)?; + write!(f, "regex=`{}`", regex)?; } if let Some(recursive) = self.recursive { if preceding { @@ -58,6 +59,7 @@ impl std::clone::Clone for FilesStatement { regex: self.regex.clone(), recursive: self.recursive.clone(), file_iter: None, + has_tried: self.has_tried, } } } @@ -67,6 +69,11 @@ impl Iterator for FilesStatement { fn next(&mut self) -> Option { if self.file_iter.is_none() { + if self.has_tried { + return None; + } else { + self.has_tried = true; + } let self_clone = self.clone(); let iter = self.context.as_mut().unwrap().filesystem.raw( self.folder.as_deref(), @@ -218,6 +225,7 @@ impl MpsFunctionFactory for FilesFunctionFactory { regex: pattern, recursive: recursive, file_iter: None, + has_tried: false, }) } } diff --git a/mps-interpreter/src/processing/filesystem.rs b/mps-interpreter/src/processing/filesystem.rs index a1524f7..e89398c 100644 --- a/mps-interpreter/src/processing/filesystem.rs +++ b/mps-interpreter/src/processing/filesystem.rs @@ -252,10 +252,12 @@ impl Iterator for FileIter { Some(item) => Some(Ok(item)), } } else { - // should be impossible to get here self.dir_iters.push(match self.root.read_dir() { 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(); }