Commit 6e8e12b579
6e8e12b57970d91528aa09b0365c58cc805be69a
parent: 3da9835a17
Unregistered key
Ulyssa <git@ulyssa.dev> · 2023-07-08 03:35 UTC
Need fallback behaviour when dirs::download_dir returns None (#118)
Layout: unified · split
src/base.rs
+3
| @@ -349,6 +349,9 @@ pub enum IambError { |
| 349 | #[error("Serialization/deserialization error: {0}")] |
349 | #[error("Serialization/deserialization error: {0}")] |
| 350 | Serde(#[from] serde_json::Error), |
350 | Serde(#[from] serde_json::Error), |
| 351 | |
351 | |
| |
352 | #[error("No download directory configured")] |
| |
353 | NoDownloadDir, |
| |
354 | |
| 352 | #[error("Selected message does not have any attachments")] |
355 | #[error("Selected message does not have any attachments")] |
| 353 | NoAttachment, |
356 | NoAttachment, |
| 354 | |
357 | |
src/config.rs
+2 −5
| @@ -319,7 +319,7 @@ impl Tunables { |
| 319 | pub struct DirectoryValues { |
319 | pub struct DirectoryValues { |
| 320 | pub cache: PathBuf, |
320 | pub cache: PathBuf, |
| 321 | pub logs: PathBuf, |
321 | pub logs: PathBuf, |
| 322 | pub downloads: PathBuf, |
322 | pub downloads: Option<PathBuf>, |
| 323 | } |
323 | } |
| 324 | |
324 | |
| 325 | #[derive(Clone, Default, Deserialize)] |
325 | #[derive(Clone, Default, Deserialize)] |
| @@ -354,10 +354,7 @@ impl Directories { |
| 354 | dir |
354 | dir |
| 355 | }); |
355 | }); |
| 356 | |
356 | |
| 357 | let downloads = self |
357 | let downloads = self.downloads.or_else(dirs::download_dir); |
| 358 | .downloads |
| |
| 359 | .or_else(dirs::download_dir) |
| |
| 360 | .expect("no dirs.downloads value configured!"); |
| |
| 361 | |
358 | |
| 362 | DirectoryValues { cache, logs, downloads } |
359 | DirectoryValues { cache, logs, downloads } |
| 363 | } |
360 | } |
src/tests.rs
+1 −1
| @@ -169,7 +169,7 @@ pub fn mock_dirs() -> DirectoryValues { |
| 169 | DirectoryValues { |
169 | DirectoryValues { |
| 170 | cache: PathBuf::new(), |
170 | cache: PathBuf::new(), |
| 171 | logs: PathBuf::new(), |
171 | logs: PathBuf::new(), |
| 172 | downloads: PathBuf::new(), |
172 | downloads: None, |
| 173 | } |
173 | } |
| 174 | } |
174 | } |
| 175 | |
175 | |
src/windows/room/chat.rs
+4 −3
| @@ -186,9 +186,10 @@ impl ChatState { |
| 186 | if let MessageEvent::Original(ev) = &msg.event { |
186 | if let MessageEvent::Original(ev) = &msg.event { |
| 187 | let media = client.media(); |
187 | let media = client.media(); |
| 188 | |
188 | |
| 189 | let mut filename = match filename { |
189 | let mut filename = match (filename, &settings.dirs.downloads) { |
| 190 | Some(f) => PathBuf::from(f), |
190 | (Some(f), _) => PathBuf::from(f), |
| 191 | None => settings.dirs.downloads.clone(), |
191 | (None, Some(downloads)) => downloads.clone(), |
| |
192 | (None, None) => return Err(IambError::NoDownloadDir.into()), |
| 192 | }; |
193 | }; |
| 193 | |
194 | |
| 194 | let (source, msg_filename) = match &ev.content.msgtype { |
195 | let (source, msg_filename) = match &ev.content.msgtype { |