| @@ -707,11 +707,11 @@ impl DirectoryValues { |
| 707 | |
707 | |
| 708 | #[derive(Clone, Default, Deserialize)] |
708 | #[derive(Clone, Default, Deserialize)] |
| 709 | pub struct Directories { |
709 | pub struct Directories { |
| 710 | pub cache: Option<PathBuf>, |
710 | pub cache: Option<String>, |
| 711 | pub data: Option<PathBuf>, |
711 | pub data: Option<String>, |
| 712 | pub logs: Option<PathBuf>, |
712 | pub logs: Option<String>, |
| 713 | pub downloads: Option<PathBuf>, |
713 | pub downloads: Option<String>, |
| 714 | pub image_previews: Option<PathBuf>, |
714 | pub image_previews: Option<String>, |
| 715 | } |
715 | } |
| 716 | |
716 | |
| 717 | impl Directories { |
717 | impl Directories { |
| @@ -728,6 +728,11 @@ impl Directories { |
| 728 | fn values(self) -> DirectoryValues { |
728 | fn values(self) -> DirectoryValues { |
| 729 | let cache = self |
729 | let cache = self |
| 730 | .cache |
730 | .cache |
| |
731 | .map(|dir| { |
| |
732 | let dir = shellexpand::full(&dir) |
| |
733 | .expect("unable to expand shell variables in dirs.cache"); |
| |
734 | Path::new(dir.as_ref()).to_owned() |
| |
735 | }) |
| 731 | .or_else(|| { |
736 | .or_else(|| { |
| 732 | let mut dir = dirs::cache_dir()?; |
737 | let mut dir = dirs::cache_dir()?; |
| 733 | dir.push("iamb"); |
738 | dir.push("iamb"); |
| @@ -737,6 +742,11 @@ impl Directories { |
| 737 | |
742 | |
| 738 | let data = self |
743 | let data = self |
| 739 | .data |
744 | .data |
| |
745 | .map(|dir| { |
| |
746 | let dir = shellexpand::full(&dir) |
| |
747 | .expect("unable to expand shell variables in dirs.cache"); |
| |
748 | Path::new(dir.as_ref()).to_owned() |
| |
749 | }) |
| 740 | .or_else(|| { |
750 | .or_else(|| { |
| 741 | let mut dir = dirs::data_dir()?; |
751 | let mut dir = dirs::data_dir()?; |
| 742 | dir.push("iamb"); |
752 | dir.push("iamb"); |
| @@ -744,19 +754,40 @@ impl Directories { |
| 744 | }) |
754 | }) |
| 745 | .expect("no dirs.data value configured!"); |
755 | .expect("no dirs.data value configured!"); |
| 746 | |
756 | |
| 747 | let logs = self.logs.unwrap_or_else(|| { |
757 | let logs = self |
| 748 | let mut dir = cache.clone(); |
758 | .logs |
| 749 | dir.push("logs"); |
759 | .map(|dir| { |
| 750 | dir |
760 | let dir = shellexpand::full(&dir) |
| 751 | }); |
761 | .expect("unable to expand shell variables in dirs.cache"); |
| 752 | |
762 | Path::new(dir.as_ref()).to_owned() |
| 753 | let downloads = self.downloads.or_else(dirs::download_dir); |
763 | }) |
| |
764 | .unwrap_or_else(|| { |
| |
765 | let mut dir = cache.clone(); |
| |
766 | dir.push("logs"); |
| |
767 | dir |
| |
768 | }); |
| 754 | |
769 | |
| 755 | let image_previews = self.image_previews.unwrap_or_else(|| { |
770 | let downloads = self |
| 756 | let mut dir = cache.clone(); |
771 | .downloads |
| 757 | dir.push("image_preview_downloads"); |
772 | .map(|dir| { |
| 758 | dir |
773 | let dir = shellexpand::full(&dir) |
| 759 | }); |
774 | .expect("unable to expand shell variables in dirs.cache"); |
| |
775 | Path::new(dir.as_ref()).to_owned() |
| |
776 | }) |
| |
777 | .or_else(dirs::download_dir); |
| |
778 | |
| |
779 | let image_previews = self |
| |
780 | .image_previews |
| |
781 | .map(|dir| { |
| |
782 | let dir = shellexpand::full(&dir) |
| |
783 | .expect("unable to expand shell variables in dirs.cache"); |
| |
784 | Path::new(dir.as_ref()).to_owned() |
| |
785 | }) |
| |
786 | .unwrap_or_else(|| { |
| |
787 | let mut dir = cache.clone(); |
| |
788 | dir.push("image_preview_downloads"); |
| |
789 | dir |
| |
790 | }); |
| 760 | |
791 | |
| 761 | DirectoryValues { cache, data, logs, downloads, image_previews } |
792 | DirectoryValues { cache, data, logs, downloads, image_previews } |
| 762 | } |
793 | } |