File tree Expand file tree Collapse file tree 3 files changed +23
-24
lines changed
Expand file tree Collapse file tree 3 files changed +23
-24
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,10 @@ impl HashFilter {
6363 return Ok ( ( ) ) ;
6464 }
6565
66+ if let Some ( dir) = self . path . as_ref ( ) . and_then ( |p| p. parent ( ) ) {
67+ std:: fs:: create_dir_all ( dir) ?;
68+ }
69+
6670 let mut file = OpenOptions :: new ( )
6771 . write ( true )
6872 . create ( true )
Original file line number Diff line number Diff line change 1-
21use directories:: ProjectDirs ;
32
43use crate :: filesdb:: FilesDb ;
@@ -7,16 +6,6 @@ use crate::settings;
76pub fn load ( ) {
87 let dirs = ProjectDirs :: from ( "" , "Freaky" , "Compactor" ) . expect ( "dirs" ) ;
98
10- if !dirs. cache_dir ( ) . exists ( ) {
11- let _ = std:: fs:: create_dir_all ( dirs. cache_dir ( ) ) ;
12- }
13-
149 FilesDb :: borrow ( ) . set_backing ( dirs. cache_dir ( ) . join ( "incompressible.dat" ) ) ;
15-
16-
17- if !dirs. config_dir ( ) . exists ( ) {
18- let _ = std:: fs:: create_dir_all ( dirs. config_dir ( ) ) ;
19- }
20-
2110 settings:: load ( dirs. config_dir ( ) . join ( "config.json" ) ) ;
2211}
Original file line number Diff line number Diff line change @@ -84,24 +84,30 @@ impl Settings {
8484 }
8585
8686 pub fn load ( & mut self ) {
87- if self . backing . is_none ( ) {
88- return ;
89- }
90-
91- if let Ok ( data ) = std :: fs :: read ( self . backing . as_ref ( ) . unwrap ( ) ) {
92- if let Ok ( c ) = serde_json :: from_slice :: < Config > ( & data ) {
93- self . set ( c ) ;
87+ match & self . backing {
88+ Some ( path ) => {
89+ if let Ok ( data ) = std :: fs :: read ( path ) {
90+ if let Ok ( c ) = serde_json :: from_slice :: < Config > ( & data ) {
91+ self . set ( c ) ;
92+ }
93+ }
9494 }
95+ None => ( ) ,
9596 }
9697 }
9798
98- pub fn save ( & mut self ) {
99- if self . backing . is_none ( ) {
100- return ;
101- }
99+ pub fn save ( & mut self ) -> std:: io:: Result < ( ) > {
100+ match & self . backing {
101+ Some ( path) => {
102+ if let Some ( dir) = path. parent ( ) {
103+ std:: fs:: create_dir_all ( dir) ?;
104+ }
102105
103- let data = serde_json:: to_string_pretty ( & self . config ) . expect ( "Serialize" ) ;
104- let _ = std:: fs:: write ( self . backing . as_ref ( ) . unwrap ( ) , & data) ;
106+ let data = serde_json:: to_string_pretty ( & self . config ) . expect ( "Serialize" ) ;
107+ std:: fs:: write ( path, & data)
108+ }
109+ None => Ok ( ( ) ) ,
110+ }
105111 }
106112
107113 pub fn set ( & mut self , c : Config ) {
You can’t perform that action at this time.
0 commit comments