]> Repositorios git - scryer-prolog.git/commitdiff
ADDED: delete_file/1, addressing a remaining aspect of #511
authorMarkus Triska <[email protected]>
Tue, 14 Jul 2020 20:16:15 +0000 (22:16 +0200)
committerMarkus Triska <[email protected]>
Tue, 14 Jul 2020 20:21:46 +0000 (22:21 +0200)
src/clause_types.rs
src/lib/files.pl
src/machine/system_calls.rs

index 09cab2bb451a22a3889a44d2d46089906e196cc1..a2608d053c54421d2ce77af472ae0e4828421154 100644 (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)),
index b53b9bbb29d69367c1a33d4acc71d8c3c7554e37..be83ae6cacc06be82a7f8b260dc91f12884fb9a1 100644 (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).
index 20bf70e495aa4609ae13dd065cd22436d8584c94..7a6bc9c63b8244343a4371d539186efc8c2d0261 100644 (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;