Merge pull request #48 from michaeladler/feature/fix-read-only-crash

Fix crash on read-only mimeapps
This commit is contained in:
Gregory 2021-07-30 16:28:11 -04:00 committed by GitHub
commit b9b71369f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -113,9 +113,10 @@ impl MimeApps {
pub fn read() -> Result<Self> { pub fn read() -> Result<Self> {
let raw_conf = { let raw_conf = {
let mut buf = String::new(); let mut buf = String::new();
let exists = std::path::Path::new(&Self::path()?).exists();
std::fs::OpenOptions::new() std::fs::OpenOptions::new()
.write(true) .write(!exists)
.create(true) .create(!exists)
.read(true) .read(true)
.open(Self::path()?)? .open(Self::path()?)?
.read_to_string(&mut buf)?; .read_to_string(&mut buf)?;