diff options
Diffstat (limited to 'fix_flatpak.rs')
-rw-r--r-- | fix_flatpak.rs | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/fix_flatpak.rs b/fix_flatpak.rs index 58147c879423..210127449468 100644 --- a/fix_flatpak.rs +++ b/fix_flatpak.rs @@ -10,41 +10,43 @@ extern "C" { #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn open64(path: *const c_char, oflag: c_int) -> c_int { +pub unsafe extern "C" fn open64(c_path: *const c_char, oflag: c_int) -> c_int { let original_open64: extern "C" fn(*const c_char, c_int) -> c_int = { let f = dlsym(RTLD_NEXT, "open64\0".as_ptr() as _); transmute(f) }; - let p = { - let p = CString::from_raw(path as _); + let c_string_path = { + let p = CString::from_raw(c_path as _); let p2 = p.clone(); + // Forget the original path, so we don't drop it before shortwave uses it std::mem::forget(p); p2 }; - if p == CString::new("/app/share/shortwave/de.haeckerfelix.Shortwave.gresource").unwrap() { + let str_path = c_string_path.to_str().unwrap(); // can fail if the path is not utf-8 + if str_path == "/app/share/shortwave/de.haeckerfelix.Shortwave.gresource" { original_open64( CString::new("/usr/share/shortwave/de.haeckerfelix.Shortwave.gresource") .unwrap() .into_raw(), oflag, ) - } else if p.to_str().unwrap().contains("favicon") || p.to_str().unwrap().contains("recording") { + } else if str_path.contains("favicon") || str_path.contains("recording") { // For some reason favicons/recording permission changes sometimes to 000 // This is probably due to how flatpak sandbox works. - // This blocks worksaround it. - let result = original_open64(p.clone().into_raw(), oflag); + // This blocks works-around it. + let result = original_open64(c_string_path.clone().into_raw(), oflag); // c_path should not be used here or it will be consumed if result == -1 { std::process::Command::new("chmod") .arg("+rw") - .arg(p.to_str().unwrap()) + .arg(str_path) .status() .unwrap(); - original_open64(path, oflag) + original_open64(c_path, oflag) } else { result } } else { - original_open64(path, oflag) + original_open64(c_path, oflag) } } |