Filbytes fix (#85)

* test(sqlite): add some tests for houskeeping methods

* fix(tools): handle faile metadata call
This commit is contained in:
Friedel Ziegelmayer
2019-05-27 11:59:25 +02:00
committed by Lars-Magnus Skog
parent 41cecb32c7
commit e383752b67
2 changed files with 66 additions and 5 deletions

View File

@@ -1323,11 +1323,14 @@ pub unsafe fn dc_get_filebytes(
return 0;
}
let filebytes = {
let p = std::ffi::CStr::from_ptr(pathNfilename_abs)
.to_str()
.unwrap();
fs::metadata(p).unwrap().len()
let p = std::ffi::CStr::from_ptr(pathNfilename_abs)
.to_str()
.unwrap();
let filebytes = match fs::metadata(p) {
Ok(meta) => meta.len(),
Err(_err) => {
return 0;
}
};
free(pathNfilename_abs as *mut libc::c_void);