Change argument type of write_asc_to_file from const char * to &Path

This commit is contained in:
Dmitry Bogatov
2019-09-12 07:23:59 +00:00
parent 7c4d7fb3dd
commit f47652e72d
2 changed files with 5 additions and 8 deletions

View File

@@ -1093,7 +1093,7 @@ unsafe fn export_key_to_asc_file(
}
info!(context, "Exporting key {}", as_str(file_name),);
dc_delete_file(context, as_path(file_name));
if !key.write_asc_to_file(file_name, context) {
if !key.write_asc_to_file(as_path(file_name), context) {
error!(context, "Cannot write key to {}", as_str(file_name),);
} else {
context.call_cb(

View File

@@ -1,6 +1,7 @@
use std::collections::BTreeMap;
use std::ffi::{CStr, CString};
use std::io::Cursor;
use std::path::Path;
use libc;
use pgp::composed::{Deserializable, SignedPublicKey, SignedSecretKey};
@@ -216,17 +217,13 @@ impl Key {
.expect("failed to serialize key")
}
pub fn write_asc_to_file(&self, file: *const libc::c_char, context: &Context) -> bool {
if file.is_null() {
return false;
}
pub fn write_asc_to_file(&self, file: impl AsRef<Path>, context: &Context) -> bool {
let file_content = self.to_asc(None).into_bytes();
if dc_write_file_safe(context, as_path(file), &file_content) {
if dc_write_file_safe(context, &file, &file_content) {
return true;
} else {
error!(context, "Cannot write key to {}", as_str(file));
error!(context, "Cannot write key to {}", file.as_ref().display());
return false;
}
}