DeleteFile,
WorkingDirectory,
PathCanonical,
- FileModificationTime,
+ FileTime,
DeleteAttribute,
DeleteHeadAttribute,
DynamicModuleResolution(usize),
&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) => {
("$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)),
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)).
'$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).
}
}
}
- &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(());