ElyPDF: an OS permission error shows as an error, never a missing text key (P-01); component library f834f55
This commit is contained in:
17 files changed
+90
-25
No files matched your search
@@ -136,7 +136,7 @@ impl Viewer {
|
||||
}
|
||||
|
||||
fn failed_write(&self, name: &str, error: &io::Error, cx: &mut App) {
|
||||
if error.kind() == io::ErrorKind::PermissionDenied {
|
||||
if ely_pdf_engine::refused(error).is_some() {
|
||||
return self.failed(error, cx);
|
||||
}
|
||||
let text = Self::text(cx, "office.error.save", &[("name", name), ("error", &error.to_string())]);
|
||||
|
||||
@@ -46,9 +46,9 @@ fn masked(window: &mut Window, cx: &mut Context<Viewer>) -> Entity<TextInput> {
|
||||
impl Viewer {
|
||||
/// A refusal names what is missing.
|
||||
pub(crate) fn failed(&self, error: &io::Error, cx: &mut App) {
|
||||
match error.kind() {
|
||||
io::ErrorKind::PermissionDenied => self.toast(crate::view::restricted(&error.to_string(), cx), Severity::Warning, cx),
|
||||
_ => self.panel_failed(&error.to_string(), cx),
|
||||
match ely_pdf_engine::refused(error) {
|
||||
Some(needed) => self.toast(crate::view::restricted(needed, cx), Severity::Warning, cx),
|
||||
None => self.panel_failed(&error.to_string(), cx),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,39 @@ fn pages_export_as_images_and_text() {
|
||||
assert!(text.contains("First") && text.contains("Second"), "{text}");
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn a_write_the_system_refuses_reports_it_without_a_crash() {
|
||||
use std::os::unix::fs::PermissionsExt as _;
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
let mut cx = TestAppContext::single();
|
||||
let path = file(dir.path(), "doc.pdf", &[(612.0, 792.0, &["First"])]);
|
||||
let (viewer, cx) = windowed(&mut cx, dir.path(), &[path], true);
|
||||
shown(cx, &viewer);
|
||||
let locked = dir.path().join("locked");
|
||||
std::fs::create_dir(&locked).expect("a folder");
|
||||
std::fs::set_permissions(&locked, std::fs::Permissions::from_mode(0o500)).expect("read-only");
|
||||
let id = cx.update(|_, app| viewer.read(app).core.tabs[0].id);
|
||||
let txt = locked.join("doc.txt");
|
||||
let how = Optimizing { compress: true, from: 300, to: 0 };
|
||||
// The window's toasts live on its root.
|
||||
let root = cx.update(|window, app| {
|
||||
let root = ely_ui::document_root(ely_platform::AppId::Pdf, viewer.clone().into(), &ely_ui::commands::FILE, Vec::new(), window, app);
|
||||
viewer.update(app, |viewer, _| viewer.core.root = root.downgrade());
|
||||
root
|
||||
});
|
||||
cx.update(|_, app| viewer.update(app, |viewer, cx| viewer.write_export(id, Kind::Text, how, txt.clone(), cx)));
|
||||
let failed = |app: &gpui::App| {
|
||||
let toasts = root.read(app).toasts(app);
|
||||
toasts.iter().any(|(text, severity)| {
|
||||
*severity == Some(ely_gpui_component::primitives::Severity::Danger) && text.contains("Permission denied")
|
||||
})
|
||||
};
|
||||
settle(cx, failed);
|
||||
std::fs::set_permissions(&locked, std::fs::Permissions::from_mode(0o700)).expect("writable again");
|
||||
assert!(!txt.exists(), "nothing is written");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_damaged_file_opens_repaired_and_saves_as_a_new_file() {
|
||||
let dir = tempfile::tempdir().expect("a temp dir");
|
||||
|
||||
@@ -227,10 +227,10 @@ impl PdfView {
|
||||
pub fn fail(&self, what: &str, error: &io::Error, cx: &mut Context<Self>) {
|
||||
// Engine text may quote the document: the user sees it.
|
||||
log::error!("pdf: {what} failed ({:?})", error.kind());
|
||||
let text = match error.kind() {
|
||||
let text = match ely_pdf_engine::refused(error) {
|
||||
_ if ely_pdf_engine::is_stale(error) => ely_ui::i18n::text(cx, "pdf.object.changed", &[]),
|
||||
io::ErrorKind::PermissionDenied => restricted(&error.to_string(), cx),
|
||||
_ => ely_ui::i18n::text(cx, "pdf.failed", &[("what", what), ("error", &error.to_string())]),
|
||||
Some(needed) => restricted(needed, cx),
|
||||
None => ely_ui::i18n::text(cx, "pdf.failed", &[("what", what), ("error", &error.to_string())]),
|
||||
};
|
||||
cx.emit(Failed(text.to_string()));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user