Merge pull request #633 from triska/file_time
ADDED: file_creation_time/2 and file_access_time/2.
This commit is contained in:
@@ -179,7 +179,7 @@ pub enum SystemClauseType {
|
|||||||
DeleteFile,
|
DeleteFile,
|
||||||
WorkingDirectory,
|
WorkingDirectory,
|
||||||
PathCanonical,
|
PathCanonical,
|
||||||
FileModificationTime,
|
FileTime,
|
||||||
DeleteAttribute,
|
DeleteAttribute,
|
||||||
DeleteHeadAttribute,
|
DeleteHeadAttribute,
|
||||||
DynamicModuleResolution(usize),
|
DynamicModuleResolution(usize),
|
||||||
@@ -348,7 +348,7 @@ impl SystemClauseType {
|
|||||||
&SystemClauseType::DeleteFile => clause_name!("$delete_file"),
|
&SystemClauseType::DeleteFile => clause_name!("$delete_file"),
|
||||||
&SystemClauseType::WorkingDirectory => clause_name!("$working_directory"),
|
&SystemClauseType::WorkingDirectory => clause_name!("$working_directory"),
|
||||||
&SystemClauseType::PathCanonical => clause_name!("$path_canonical"),
|
&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::CompileBatch) => clause_name!("$compile_batch"),
|
||||||
&SystemClauseType::REPL(REPLCodePtr::UseModule) => clause_name!("$use_module"),
|
&SystemClauseType::REPL(REPLCodePtr::UseModule) => clause_name!("$use_module"),
|
||||||
&SystemClauseType::REPL(REPLCodePtr::UseQualifiedModule) => {
|
&SystemClauseType::REPL(REPLCodePtr::UseQualifiedModule) => {
|
||||||
@@ -686,7 +686,7 @@ impl SystemClauseType {
|
|||||||
("$delete_file", 1) => Some(SystemClauseType::DeleteFile),
|
("$delete_file", 1) => Some(SystemClauseType::DeleteFile),
|
||||||
("$working_directory", 2) => Some(SystemClauseType::WorkingDirectory),
|
("$working_directory", 2) => Some(SystemClauseType::WorkingDirectory),
|
||||||
("$path_canonical", 2) => Some(SystemClauseType::PathCanonical),
|
("$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", 1) => Some(SystemClauseType::REPL(REPLCodePtr::UseModule)),
|
||||||
("$use_module_from_file", 1) =>
|
("$use_module_from_file", 1) =>
|
||||||
Some(SystemClauseType::REPL(REPLCodePtr::UseModuleFromFile)),
|
Some(SystemClauseType::REPL(REPLCodePtr::UseModuleFromFile)),
|
||||||
|
|||||||
@@ -54,7 +54,9 @@
|
|||||||
make_directory/1,
|
make_directory/1,
|
||||||
working_directory/2,
|
working_directory/2,
|
||||||
path_canonical/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(error)).
|
||||||
:- use_module(library(lists)).
|
:- use_module(library(lists)).
|
||||||
@@ -123,12 +125,21 @@ path_canonical(Ps, Cs) :-
|
|||||||
'$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).
|
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.
|
For two time stamps A and B, if A precedes B, then A @< B holds.
|
||||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
|
||||||
file_modification_time(File, T) :-
|
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).
|
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 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(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);
|
let chars = self.systemtime_to_timestamp(time);
|
||||||
self.unify(self[temp_v!(2)], chars);
|
self.unify(self[temp_v!(3)], chars);
|
||||||
} else {
|
} else {
|
||||||
self.fail = true;
|
self.fail = true;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|||||||
Reference in New Issue
Block a user