]> Repositorios git - scryer-prolog.git/commitdiff
Add make_directory_path/1 predicate to the files library
authorPaulo Moura <[email protected]>
Mon, 17 May 2021 23:21:11 +0000 (00:21 +0100)
committerPaulo Moura <[email protected]>
Mon, 17 May 2021 23:21:11 +0000 (00:21 +0100)
src/clause_types.rs
src/lib/files.pl
src/machine/system_calls.rs

index 7820a9fd80b29b9e58c87d341be7c865aad0f027..15d14c308c9ec7dbd5f3b492362cda2b9555864b 100644 (file)
@@ -173,6 +173,7 @@ pub(crate) enum SystemClauseType {
     DirectoryExists,
     DirectorySeparator,
     MakeDirectory,
+    MakeDirectoryPath,
     DeleteFile,
     WorkingDirectory,
     PathCanonical,
@@ -334,6 +335,7 @@ impl SystemClauseType {
             &SystemClauseType::DirectoryExists => clause_name!("$directory_exists"),
             &SystemClauseType::DirectorySeparator => clause_name!("$directory_separator"),
             &SystemClauseType::MakeDirectory => clause_name!("$make_directory"),
+            &SystemClauseType::MakeDirectoryPath => clause_name!("$make_directory_path"),
             &SystemClauseType::DeleteFile => clause_name!("$delete_file"),
             &SystemClauseType::WorkingDirectory => clause_name!("$working_directory"),
             &SystemClauseType::PathCanonical => clause_name!("$path_canonical"),
@@ -743,6 +745,7 @@ impl SystemClauseType {
             ("$directory_exists", 1) => Some(SystemClauseType::DirectoryExists),
             ("$directory_separator", 1) => Some(SystemClauseType::DirectorySeparator),
             ("$make_directory", 1) => Some(SystemClauseType::MakeDirectory),
+            ("$make_directory_path", 1) => Some(SystemClauseType::MakeDirectoryPath),
             ("$delete_file", 1) => Some(SystemClauseType::DeleteFile),
             ("$working_directory", 2) => Some(SystemClauseType::WorkingDirectory),
             ("$path_canonical", 2) => Some(SystemClauseType::PathCanonical),
index e88f53a204b34ca7fc1ca6b0413b8a2d3538f3c1..812ab361186fb79f2bebe4816a4c031a7bd7aee9 100644 (file)
@@ -52,6 +52,7 @@
                   directory_exists/1,
                   delete_file/1,
                   make_directory/1,
+                  make_directory_path/1,
                   working_directory/2,
                   path_canonical/2,
                   path_segments/2,
@@ -90,6 +91,10 @@ make_directory(Directory) :-
         list_of_chars(Directory),
         '$make_directory'(Directory).
 
+make_directory_path(Directory) :-
+        list_of_chars(Directory),
+        '$make_directory_path'(Directory).
+
 delete_file(File) :-
         file_must_exist(File, delete_file/1),
         list_of_chars(File),
index 6e54145da5842410047b85e8fa8b9a13fd9f6463..2075bbabe865a31a0c192bea2c2795623106412f 100644 (file)
@@ -878,6 +878,17 @@ impl MachineState {
                     }
                 }
             }
+            &SystemClauseType::MakeDirectoryPath => {
+                let directory = self.heap_pstr_iter(self[temp_v!(1)]).to_string();
+
+                match fs::create_dir_all(directory) {
+                    Ok(_) => {}
+                    _ => {
+                        self.fail = true;
+                        return Ok(());
+                    }
+                }
+            }
             &SystemClauseType::DeleteFile => {
                 let file = self.heap_pstr_iter(self[temp_v!(1)]).to_string();