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:
@@ -179,7 +179,7 @@ pub enum SystemClauseType {
|
||||
DeleteFile,
|
||||
WorkingDirectory,
|
||||
PathCanonical,
|
||||
FileModificationTime,
|
||||
FileTime,
|
||||
DeleteAttribute,
|
||||
DeleteHeadAttribute,
|
||||
DynamicModuleResolution(usize),
|
||||
@@ -348,7 +348,7 @@ impl SystemClauseType {
|
||||
&SystemClauseType::DeleteFile => clause_name!("$delete_file"),
|
||||
&SystemClauseType::WorkingDirectory => clause_name!("$working_directory"),
|
||||
&SystemClauseType::PathCanonical => clause_name!("$path_canonical"),
|
||||
&SystemClauseType::FileModificationTime => clause_name!("$file_modification_time"),
|
||||
&SystemClauseType::FileTime => clause_name!("$file_time"),
|
||||
&SystemClauseType::REPL(REPLCodePtr::CompileBatch) => clause_name!("$compile_batch"),
|
||||
&SystemClauseType::REPL(REPLCodePtr::UseModule) => clause_name!("$use_module"),
|
||||
&SystemClauseType::REPL(REPLCodePtr::UseQualifiedModule) => {
|
||||
@@ -686,7 +686,7 @@ impl SystemClauseType {
|
||||
("$delete_file", 1) => Some(SystemClauseType::DeleteFile),
|
||||
("$working_directory", 2) => Some(SystemClauseType::WorkingDirectory),
|
||||
("$path_canonical", 2) => Some(SystemClauseType::PathCanonical),
|
||||
("$file_modification_time", 2) => Some(SystemClauseType::FileModificationTime),
|
||||
("$file_time", 3) => Some(SystemClauseType::FileTime),
|
||||
("$use_module", 1) => Some(SystemClauseType::REPL(REPLCodePtr::UseModule)),
|
||||
("$use_module_from_file", 1) =>
|
||||
Some(SystemClauseType::REPL(REPLCodePtr::UseModuleFromFile)),
|
||||
|
||||
@@ -54,7 +54,9 @@
|
||||
make_directory/1,
|
||||
working_directory/2,
|
||||
path_canonical/2,
|
||||
file_modification_time/2]).
|
||||
file_modification_time/2,
|
||||
file_creation_time/2,
|
||||
file_access_time/2]).
|
||||
|
||||
:- use_module(library(error)).
|
||||
:- use_module(library(lists)).
|
||||
@@ -123,12 +125,21 @@ path_canonical(Ps, Cs) :-
|
||||
'$path_canonical'(Ps, Cs).
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
T is the modification time of File.
|
||||
T is, respectively, the modification, access or creation time of File.
|
||||
T is a time stamp, suitable for use in format_time//2 in library(time).
|
||||
|
||||
For two time stamps A and B, if A precedes B, then A @< B holds.
|
||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
file_modification_time(File, T) :-
|
||||
'$file_modification_time'(File, T0),
|
||||
file_time_(File, modification, T).
|
||||
|
||||
file_access_time(File, T) :-
|
||||
file_time_(File, access, T).
|
||||
|
||||
file_creation_time(File, T) :-
|
||||
file_time_(File, creation, T).
|
||||
|
||||
file_time_(File, Which, T) :-
|
||||
'$file_time'(File, Which, T0),
|
||||
read_term_from_chars(T0, T).
|
||||
|
||||
@@ -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(());
|
||||
|
||||
Reference in New Issue
Block a user