DeleteFile,
#[strum_discriminants(strum(props(Arity = "2", Name = "$rename_file")))]
RenameFile,
+ #[strum_discriminants(strum(props(Arity = "2", Name = "$copy_file")))]
+ CopyFile,
#[strum_discriminants(strum(props(Arity = "2", Name = "$working_directory")))]
WorkingDirectory,
#[strum_discriminants(strum(props(Arity = "1", Name = "$delete_directory")))]
&Instruction::CallMakeDirectoryPath(_) |
&Instruction::CallDeleteFile(_) |
&Instruction::CallRenameFile(_) |
+ &Instruction::CallCopyFile(_) |
&Instruction::CallWorkingDirectory(_) |
&Instruction::CallDeleteDirectory(_) |
&Instruction::CallPathCanonical(_) |
&Instruction::ExecuteMakeDirectoryPath(_) |
&Instruction::ExecuteDeleteFile(_) |
&Instruction::ExecuteRenameFile(_) |
+ &Instruction::ExecuteCopyFile(_) |
&Instruction::ExecuteWorkingDirectory(_) |
&Instruction::ExecuteDeleteDirectory(_) |
&Instruction::ExecutePathCanonical(_) |
file_exists/1,
directory_exists/1,
delete_file/1,
- rename_file/2,
- delete_directory/1,
+ rename_file/2,
+ copy_file/2,
+ delete_directory/1,
make_directory/1,
make_directory_path/1,
working_directory/2,
must_be(chars, Renamed),
'$rename_file'(File, Renamed).
+copy_file(File, Copied) :-
+ file_must_exist(File, copy_file/2),
+ must_be(chars, Copied),
+ '$copy_file'(File, Copied).
+
%% delete_directory(+Directory).
%
% Succeeds if Directory is deleted from the current system.
self.rename_file();
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
}
+ &Instruction::CallCopyFile(_) => {
+ self.copy_file();
+ step_or_fail!(self, self.machine_st.p += 1);
+ }
+ &Instruction::ExecuteCopyFile(_) => {
+ self.copy_file();
+ step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
+ }
&Instruction::CallWorkingDirectory(_) => {
try_or_throw!(self.machine_st, self.working_directory());
step_or_fail!(self, self.machine_st.p += 1);
self.machine_st.fail = true;
}
+ #[inline(always)]
+ pub(crate) fn copy_file(&mut self) {
+ if let Some(file) = self.machine_st.value_to_str_like(self.machine_st.registers[1]) {
+ if let Some(copied) = self.machine_st.value_to_str_like(self.machine_st.registers[2]) {
+ if fs::copy(file.as_str(), copied.as_str()).is_ok() {
+ return;
+ }
+ }
+ }
+
+ self.machine_st.fail = true;
+ }
+
#[inline(always)]
pub(crate) fn delete_directory(&mut self) {
if let Some(dir) = self.machine_st.value_to_str_like(self.machine_st.registers[1]) {