mirror of
https://github.com/youwen5/iamb.git
synced 2025-06-20 05:39:52 -07:00
Need fallback behaviour when dirs::download_dir returns None (#118)
This commit is contained in:
parent
3da9835a17
commit
6e8e12b579
4 changed files with 10 additions and 9 deletions
|
@ -349,6 +349,9 @@ pub enum IambError {
|
||||||
#[error("Serialization/deserialization error: {0}")]
|
#[error("Serialization/deserialization error: {0}")]
|
||||||
Serde(#[from] serde_json::Error),
|
Serde(#[from] serde_json::Error),
|
||||||
|
|
||||||
|
#[error("No download directory configured")]
|
||||||
|
NoDownloadDir,
|
||||||
|
|
||||||
#[error("Selected message does not have any attachments")]
|
#[error("Selected message does not have any attachments")]
|
||||||
NoAttachment,
|
NoAttachment,
|
||||||
|
|
||||||
|
|
|
@ -319,7 +319,7 @@ impl Tunables {
|
||||||
pub struct DirectoryValues {
|
pub struct DirectoryValues {
|
||||||
pub cache: PathBuf,
|
pub cache: PathBuf,
|
||||||
pub logs: PathBuf,
|
pub logs: PathBuf,
|
||||||
pub downloads: PathBuf,
|
pub downloads: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Default, Deserialize)]
|
#[derive(Clone, Default, Deserialize)]
|
||||||
|
@ -354,10 +354,7 @@ impl Directories {
|
||||||
dir
|
dir
|
||||||
});
|
});
|
||||||
|
|
||||||
let downloads = self
|
let downloads = self.downloads.or_else(dirs::download_dir);
|
||||||
.downloads
|
|
||||||
.or_else(dirs::download_dir)
|
|
||||||
.expect("no dirs.downloads value configured!");
|
|
||||||
|
|
||||||
DirectoryValues { cache, logs, downloads }
|
DirectoryValues { cache, logs, downloads }
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,7 +169,7 @@ pub fn mock_dirs() -> DirectoryValues {
|
||||||
DirectoryValues {
|
DirectoryValues {
|
||||||
cache: PathBuf::new(),
|
cache: PathBuf::new(),
|
||||||
logs: PathBuf::new(),
|
logs: PathBuf::new(),
|
||||||
downloads: PathBuf::new(),
|
downloads: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -186,9 +186,10 @@ impl ChatState {
|
||||||
if let MessageEvent::Original(ev) = &msg.event {
|
if let MessageEvent::Original(ev) = &msg.event {
|
||||||
let media = client.media();
|
let media = client.media();
|
||||||
|
|
||||||
let mut filename = match filename {
|
let mut filename = match (filename, &settings.dirs.downloads) {
|
||||||
Some(f) => PathBuf::from(f),
|
(Some(f), _) => PathBuf::from(f),
|
||||||
None => settings.dirs.downloads.clone(),
|
(None, Some(downloads)) => downloads.clone(),
|
||||||
|
(None, None) => return Err(IambError::NoDownloadDir.into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let (source, msg_filename) = match &ev.content.msgtype {
|
let (source, msg_filename) = match &ev.content.msgtype {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue