chore: dc_is_blobdir_path() -> bool

This commit is contained in:
Lars-Magnus Skog
2019-06-07 21:17:45 +02:00
parent a1e790b91b
commit fd4de4dd2f
3 changed files with 15 additions and 28 deletions
+2 -3
View File
@@ -443,7 +443,7 @@ unsafe fn prepare_msg_common<'a>(
(*msg).type_0 as libc::c_int,
);
current_block = 2171833246886114521;
} else if (*msg).state == 18i32 && 0 == dc_is_blobdir_path(context, pathNfilename) {
} else if (*msg).state == 18i32 && !dc_is_blobdir_path(context, pathNfilename) {
dc_log_error(
context,
0i32,
@@ -1105,8 +1105,7 @@ unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t
pathNfilename = dc_param_get((*msg).param, 'f' as i32, 0 as *const libc::c_char);
if pathNfilename.is_null() {
current_block = 14513523936503887211;
} else if 0 != dc_msg_is_increation(msg)
&& 0 == dc_is_blobdir_path(context, pathNfilename)
} else if 0 != dc_msg_is_increation(msg) && !dc_is_blobdir_path(context, pathNfilename)
{
current_block = 14513523936503887211;
} else if 0 == dc_make_rel_and_copy(context, &mut pathNfilename) {
+4 -10
View File
@@ -1386,15 +1386,9 @@ pub unsafe fn dc_get_fine_pathNfilename(
ret
}
// TODO should return bool /rtn
pub unsafe fn dc_is_blobdir_path(context: &Context, path: *const libc::c_char) -> libc::c_int {
if strncmp(path, context.get_blobdir(), strlen(context.get_blobdir())) == 0i32
|| strncmp(path, b"$BLOBDIR\x00" as *const u8 as *const libc::c_char, 8) == 0i32
{
return 1i32;
}
0
pub unsafe fn dc_is_blobdir_path(context: &Context, path: *const libc::c_char) -> bool {
(strncmp(path, context.get_blobdir(), strlen(context.get_blobdir())) == 0
|| strncmp(path, b"$BLOBDIR\x00" as *const u8 as *const libc::c_char, 8) == 0)
}
pub unsafe fn dc_make_rel_path(context: &Context, path: *mut *mut libc::c_char) {
@@ -1416,7 +1410,7 @@ pub unsafe fn dc_make_rel_and_copy(context: &Context, path: *mut *mut libc::c_ch
let mut filename: *mut libc::c_char = 0 as *mut libc::c_char;
let mut blobdir_path: *mut libc::c_char = 0 as *mut libc::c_char;
if !(path.is_null() || (*path).is_null()) {
if 0 != dc_is_blobdir_path(context, *path) {
if dc_is_blobdir_path(context, *path) {
dc_make_rel_path(context, path);
success = 1i32
} else {
+9 -15
View File
@@ -122,21 +122,15 @@ unsafe fn stress_functions(context: &Context) {
context.get_blobdir(),
b"foobar\x00" as *const u8 as *const libc::c_char,
);
assert_ne!(0, dc_is_blobdir_path(context, abs_path));
assert_ne!(
0,
dc_is_blobdir_path(
context,
b"$BLOBDIR/fofo\x00" as *const u8 as *const libc::c_char,
)
);
assert_eq!(
0,
dc_is_blobdir_path(
context,
b"/BLOBDIR/fofo\x00" as *const u8 as *const libc::c_char,
)
);
assert!(dc_is_blobdir_path(context, abs_path));
assert!(dc_is_blobdir_path(
context,
b"$BLOBDIR/fofo\x00" as *const u8 as *const libc::c_char,
));
assert!(!dc_is_blobdir_path(
context,
b"/BLOBDIR/fofo\x00" as *const u8 as *const libc::c_char,
));
assert_ne!(0, dc_file_exist(context, abs_path));
free(abs_path as *mut libc::c_void);
assert_ne!(