Merge pull request #968 from pmoura/add_make_directory_path_predicate

Add make_directory_path/1 predicate to the files library
This commit is contained in:
Mark Thom
2021-05-18 10:26:06 -06:00
committed by GitHub
3 changed files with 19 additions and 0 deletions

View File

@@ -173,6 +173,7 @@ pub(crate) enum SystemClauseType {
DirectoryExists,
DirectorySeparator,
MakeDirectory,
MakeDirectoryPath,
DeleteFile,
DeleteDirectory,
WorkingDirectory,
@@ -335,6 +336,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::DeleteDirectory => clause_name!("$delete_directory"),
&SystemClauseType::WorkingDirectory => clause_name!("$working_directory"),
@@ -745,6 +747,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),
("$delete_directory", 1) => Some(SystemClauseType::DeleteDirectory),
("$working_directory", 2) => Some(SystemClauseType::WorkingDirectory),

View File

@@ -53,6 +53,7 @@
delete_file/1,
delete_directory/1,
make_directory/1,
make_directory_path/1,
working_directory/2,
path_canonical/2,
path_segments/2,
@@ -91,6 +92,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),

View 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();