mirror of
https://github.com/chatmail/core.git
synced 2026-04-26 18:06:35 +03:00
Drop unsafe version of dc_get_abs_path
This commit is contained in:
@@ -183,7 +183,7 @@ impl Chat {
|
||||
pub fn get_profile_image(&self, context: &Context) -> Option<PathBuf> {
|
||||
if let Some(image_rel) = self.param.get(Param::ProfileImage) {
|
||||
if !image_rel.is_empty() {
|
||||
return Some(dc_get_abs_path_safe(context, image_rel));
|
||||
return Some(dc_get_abs_path(context, image_rel));
|
||||
}
|
||||
} else if self.typ == Chattype::Single {
|
||||
let contacts = get_chat_contacts(context, self.id);
|
||||
|
||||
@@ -73,7 +73,7 @@ impl Context {
|
||||
let value = match key {
|
||||
Config::Selfavatar => {
|
||||
let rel_path = self.sql.get_config(self, key);
|
||||
rel_path.map(|p| dc_get_abs_path_safe(self, &p).to_str().unwrap().to_string())
|
||||
rel_path.map(|p| dc_get_abs_path(self, &p).to_str().unwrap().to_string())
|
||||
}
|
||||
Config::SysVersion => Some((&*DC_VERSION_STR).clone()),
|
||||
Config::SysMsgsizeMaxRecommended => Some(format!("{}", 24 * 1024 * 1024 / 4 * 3)),
|
||||
|
||||
@@ -1289,12 +1289,10 @@ unsafe fn build_body_file(
|
||||
) as *mut libc::c_void,
|
||||
);
|
||||
mime_sub = mailmime_new_empty(content, mime_fields);
|
||||
let abs_path = dc_get_abs_path_safe(context, path_filename)
|
||||
.as_os_str()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.strdup();
|
||||
mailmime_set_body_file(mime_sub, abs_path);
|
||||
let abs_path = dc_get_abs_path(context, path_filename)
|
||||
.to_c_string()
|
||||
.unwrap();
|
||||
mailmime_set_body_file(mime_sub, dc_strdup(abs_path.as_ptr()));
|
||||
if !ret_file_name_as_sent.is_null() {
|
||||
*ret_file_name_as_sent = dc_strdup(filename_to_send)
|
||||
}
|
||||
|
||||
@@ -792,7 +792,7 @@ pub fn dc_get_filemeta(buf: &[u8]) -> Result<(u32, u32), Error> {
|
||||
///
|
||||
/// If `path` starts with "$BLOBDIR", replaces it with the blobdir path.
|
||||
/// Otherwise, returns path as is.
|
||||
pub fn dc_get_abs_path_safe<P: AsRef<std::path::Path>>(
|
||||
pub fn dc_get_abs_path<P: AsRef<std::path::Path>>(
|
||||
context: &Context,
|
||||
path: P,
|
||||
) -> std::path::PathBuf {
|
||||
@@ -808,33 +808,12 @@ pub fn dc_get_abs_path_safe<P: AsRef<std::path::Path>>(
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn dc_get_abs_path(
|
||||
context: &Context,
|
||||
path_filename: impl AsRef<str>,
|
||||
) -> *mut libc::c_char {
|
||||
let starts = path_filename.as_ref().starts_with("$BLOBDIR");
|
||||
|
||||
if starts && !context.has_blobdir() {
|
||||
return ptr::null_mut();
|
||||
}
|
||||
|
||||
let mut path_filename_abs = path_filename.as_ref().strdup();
|
||||
if starts && context.has_blobdir() {
|
||||
dc_str_replace(
|
||||
&mut path_filename_abs,
|
||||
b"$BLOBDIR\x00" as *const u8 as *const libc::c_char,
|
||||
context.get_blobdir(),
|
||||
);
|
||||
}
|
||||
path_filename_abs
|
||||
}
|
||||
|
||||
pub fn dc_file_exist(context: &Context, path: impl AsRef<std::path::Path>) -> bool {
|
||||
dc_get_abs_path_safe(context, &path).exists()
|
||||
dc_get_abs_path(context, &path).exists()
|
||||
}
|
||||
|
||||
pub fn dc_get_filebytes(context: &Context, path: impl AsRef<std::path::Path>) -> uint64_t {
|
||||
let path_abs = dc_get_abs_path_safe(context, &path);
|
||||
let path_abs = dc_get_abs_path(context, &path);
|
||||
match fs::metadata(&path_abs) {
|
||||
Ok(meta) => meta.len() as uint64_t,
|
||||
Err(_err) => 0,
|
||||
@@ -842,7 +821,7 @@ pub fn dc_get_filebytes(context: &Context, path: impl AsRef<std::path::Path>) ->
|
||||
}
|
||||
|
||||
pub fn dc_delete_file(context: &Context, path: impl AsRef<std::path::Path>) -> bool {
|
||||
let path_abs = dc_get_abs_path_safe(context, &path);
|
||||
let path_abs = dc_get_abs_path(context, &path);
|
||||
if !path_abs.is_file() {
|
||||
warn!(
|
||||
context,
|
||||
@@ -866,8 +845,8 @@ pub fn dc_copy_file(
|
||||
src: impl AsRef<std::path::Path>,
|
||||
dest: impl AsRef<std::path::Path>,
|
||||
) -> bool {
|
||||
let src_abs = dc_get_abs_path_safe(context, &src);
|
||||
let dest_abs = dc_get_abs_path_safe(context, &dest);
|
||||
let src_abs = dc_get_abs_path(context, &src);
|
||||
let dest_abs = dc_get_abs_path(context, &dest);
|
||||
match fs::copy(&src_abs, &dest_abs) {
|
||||
Ok(_) => true,
|
||||
Err(_) => {
|
||||
@@ -883,7 +862,7 @@ pub fn dc_copy_file(
|
||||
}
|
||||
|
||||
pub fn dc_create_folder(context: &Context, path: impl AsRef<std::path::Path>) -> bool {
|
||||
let path_abs = dc_get_abs_path_safe(context, &path);
|
||||
let path_abs = dc_get_abs_path(context, &path);
|
||||
if !path_abs.exists() {
|
||||
match fs::create_dir_all(path_abs) {
|
||||
Ok(_) => true,
|
||||
@@ -918,7 +897,7 @@ pub fn dc_write_file_safe<P: AsRef<std::path::Path>>(
|
||||
path: P,
|
||||
buf: &[u8],
|
||||
) -> bool {
|
||||
let path_abs = dc_get_abs_path_safe(context, &path);
|
||||
let path_abs = dc_get_abs_path(context, &path);
|
||||
if let Err(_err) = fs::write(&path_abs, buf) {
|
||||
warn!(
|
||||
context,
|
||||
@@ -953,7 +932,7 @@ pub unsafe fn dc_read_file(
|
||||
}
|
||||
|
||||
pub fn dc_read_file_safe<P: AsRef<std::path::Path>>(context: &Context, path: P) -> Option<Vec<u8>> {
|
||||
let path_abs = dc_get_abs_path_safe(context, &path);
|
||||
let path_abs = dc_get_abs_path(context, &path);
|
||||
match fs::read(&path_abs) {
|
||||
Ok(bytes) => Some(bytes),
|
||||
Err(_err) => {
|
||||
|
||||
@@ -376,7 +376,7 @@ pub fn dc_msg_guess_msgtype_from_suffix(path: &Path) -> Option<(Viewtype, &str)>
|
||||
pub unsafe fn dc_msg_get_file(context: &Context, msg: &Message) -> Option<PathBuf> {
|
||||
msg.param
|
||||
.get(Param::File)
|
||||
.map(|f| dc_get_abs_path_safe(context, f))
|
||||
.map(|f| dc_get_abs_path(context, f))
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user