ADDED: file_creation_time/2 and file_access_time/2.

The code can be simplified once if- and while-let-chains are available:

    https://github.com/rust-lang/rust/issues/53667
This commit is contained in:
Markus Triska
2020-07-17 18:48:39 +02:00
parent f0c8056334
commit 17dd9239b6
3 changed files with 39 additions and 9 deletions

View File

@@ -943,13 +943,32 @@ impl MachineState {
}
}
}
&SystemClauseType::FileModificationTime => {
&SystemClauseType::FileTime => {
let file = self.heap_pstr_iter(self[temp_v!(1)]).to_string();
let which = match self.store(self.deref(self[temp_v!(2)])) {
Addr::Con(h) if self.heap.atom_at(h) => {
if let HeapCellValue::Atom(ref atom, _) = &self.heap[h] {
atom.as_str()
} else {
unreachable!()
}
}
_ => {
unreachable!()
}
};
if let Ok(md) = fs::metadata(file) {
if let Ok(time) = md.modified() {
if let Ok(time) =
match which {
"modification" => { md.modified() }
"access" => { md.accessed() }
"creation" => { md.created() }
_ => { unreachable!() }
} {
let chars = self.systemtime_to_timestamp(time);
self.unify(self[temp_v!(2)], chars);
self.unify(self[temp_v!(3)], chars);
} else {
self.fail = true;
return Ok(());