ADDED: path_canonical/2, obtaining the canonical absolute path.

This addresses a remaining aspect of #511.
This commit is contained in:
Markus Triska
2020-07-15 20:24:26 +02:00
parent ec75e21898
commit 0f4667d942
3 changed files with 57 additions and 1 deletions

View File

@@ -918,6 +918,31 @@ impl MachineState {
return Ok(());
}
}
&SystemClauseType::PathCanonical => {
let path = self.heap_pstr_iter(self[temp_v!(1)]).to_string();
match fs::canonicalize(path) {
Ok(canonical) => {
let cs =
match canonical.to_str() {
Some(s) => { s }
_ => {
let stub = MachineError::functor_stub(clause_name!("path_canonical"), 2);
let err = MachineError::representation_error(RepFlag::Character);
let err = self.error_form(err, stub);
return Err(err);
}
};
let chars = self.heap.put_complete_string(cs);
self.unify(self[temp_v!(2)], chars);
}
_ => {
self.fail = true;
return Ok(());
}
}
}
&SystemClauseType::AtEndOfExpansion => {
if self.cp == LocalCodePtr::TopLevel(0, 0) {
self.at_end_of_expansion = true;