Skip to content

Commit b697e95

Browse files
committed
add explicit permission check on dict write
1 parent 9700d3d commit b697e95

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

locale/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"Unable to update hook...": "Unable to update hook...",
2323
"Dictionary updated": "Dictionary updated",
2424
"Unable to update dictionary": "Unable to update dictionary",
25+
"Permission denied, check if the directory and files is writable": "Permission denied, check if the directory and files is writable",
2526
"Warning": "Warning",
2627
"Ok": "Ok",
2728
"Old version of translation files has been detected. It's better to delete them to avoid conflicts. Delete?": "Old version of translation files has been detected. It's better to delete them to avoid conflicts. Delete?",
@@ -30,4 +31,4 @@
3031
"Localization files successfully deleted": "Localization files successfully deleted",
3132
"No": "No",
3233
"Yes": "Yes"
33-
}
34+
}

src/logic.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
df_binary::DfBinary,
1010
dict_metadata::DictMetadata,
1111
hook_metadata::HookMetadata,
12-
localization::{t, LOCALE},
12+
localization::{LOCALE, t},
1313
persistent::Store,
1414
utils::*,
1515
};
@@ -132,7 +132,22 @@ impl App {
132132
self.dict_checksum = self.local_dict_checksum().unwrap_or(0)
133133
}
134134
Err(err) => {
135-
error!(self, t!("Unable to update dictionary"), err.to_string());
135+
let is_permission_denied = err.chain().any(|cause| {
136+
if let Some(io_err) = cause.downcast_ref::<std::io::Error>() {
137+
io_err.kind() == std::io::ErrorKind::PermissionDenied
138+
} else {
139+
false
140+
}
141+
});
142+
143+
error!(
144+
self,
145+
match is_permission_denied {
146+
true => t!("Permission denied, check if the directory and files is writable"),
147+
false => t!("Unable to update dictionary"),
148+
},
149+
err.to_string()
150+
);
136151
}
137152
};
138153
self.loading -= 1;

0 commit comments

Comments
 (0)