From 5134e64cae6a2e2167e2189de1cb3fd7596c1632 Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Tue, 14 Jul 2020 22:16:15 +0200 Subject: [PATCH] ADDED: delete_file/1, addressing a remaining aspect of #511 --- src/clause_types.rs | 3 +++ src/lib/files.pl | 5 +++++ src/machine/system_calls.rs | 10 ++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/clause_types.rs b/src/clause_types.rs index 09cab2bb..a2608d05 100644 --- a/src/clause_types.rs +++ b/src/clause_types.rs @@ -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)), diff --git a/src/lib/files.pl b/src/lib/files.pl index b53b9bbb..be83ae6c 100644 --- a/src/lib/files.pl +++ b/src/lib/files.pl @@ -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). diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 20bf70e4..7a6bc9c6 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -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; -- 2.54.0