ADDED: delete_file/1, addressing a remaining aspect of #511

This commit is contained in:
Markus Triska
2020-07-14 22:16:15 +02:00
parent 53d39ccb4b
commit 5134e64cae
3 changed files with 18 additions and 0 deletions

View File

@@ -176,6 +176,7 @@ pub enum SystemClauseType {
FileExists,
DirectoryExists,
MakeDirectory,
DeleteFile,
DeleteAttribute,
DeleteHeadAttribute,
DynamicModuleResolution(usize),
@@ -341,6 +342,7 @@ impl SystemClauseType {
&SystemClauseType::FileExists => clause_name!("$file_exists"),
&SystemClauseType::DirectoryExists => clause_name!("$directory_exists"),
&SystemClauseType::MakeDirectory => clause_name!("$make_directory"),
&SystemClauseType::DeleteFile => clause_name!("$delete_file"),
&SystemClauseType::REPL(REPLCodePtr::CompileBatch) => clause_name!("$compile_batch"),
&SystemClauseType::REPL(REPLCodePtr::UseModule) => clause_name!("$use_module"),
&SystemClauseType::REPL(REPLCodePtr::UseQualifiedModule) => {
@@ -675,6 +677,7 @@ impl SystemClauseType {
("$file_exists", 1) => Some(SystemClauseType::FileExists),
("$directory_exists", 1) => Some(SystemClauseType::DirectoryExists),
("$make_directory", 1) => Some(SystemClauseType::MakeDirectory),
("$delete_file", 1) => Some(SystemClauseType::DeleteFile),
("$use_module", 1) => Some(SystemClauseType::REPL(REPLCodePtr::UseModule)),
("$use_module_from_file", 1) =>
Some(SystemClauseType::REPL(REPLCodePtr::UseModuleFromFile)),

View File

@@ -50,6 +50,7 @@
file_size/2,
file_exists/1,
directory_exists/1,
delete_file/1,
make_directory/1]).
:- use_module(library(error)).
@@ -80,3 +81,7 @@ directory_exists(Directory) :-
make_directory(Directory) :-
list_of_chars(Directory),
'$make_directory'(Directory).
delete_file(File) :-
list_of_chars(File),
'$delete_file'(File).

View File

@@ -880,6 +880,16 @@ impl MachineState {
}
}
}
&SystemClauseType::DeleteFile => {
let file = self.heap_pstr_iter(self[temp_v!(1)]).to_string();
match fs::remove_file(file) {
Ok(_) => { }
_ => { self.fail = true;
return Ok(());
}
}
}
&SystemClauseType::AtEndOfExpansion => {
if self.cp == LocalCodePtr::TopLevel(0, 0) {
self.at_end_of_expansion = true;