@@ -6,6 +6,8 @@ use serde::Deserialize;
66use serde_json;
77use std:: fs;
88
9+ use super :: data:: project_dir;
10+
911const FILE_NAME : & str = "upgrade_check.json" ;
1012
1113/// The `UpgradeCheck` struct represents the state of the upgrade check.
@@ -35,26 +37,28 @@ impl UpgradeCheck {
3537 /// Loads the state of the upgrade check from the global configuration directory.
3638 /// If the file doesn't exist, returns a default instance of `UpgradeCheck`.
3739 pub fn load ( ) -> Result < Self , locator:: Error > {
38- let locator = locator :: Args {
39- global : false ,
40- config_dir : None ,
41- } ;
42- let path = locator . global_config_path ( ) ? . join ( FILE_NAME ) ;
40+ let path = project_dir ( )
41+ . map_err ( |_| locator :: Error :: ProjectDirsError ( ) ) ?
42+ . data_dir ( )
43+ . join ( FILE_NAME ) ;
44+
4345 if !path. exists ( ) {
4446 return Ok ( Self :: default ( ) ) ;
4547 }
48+
4649 let data = fs:: read ( & path)
4750 . map_err ( |error| locator:: Error :: UpgradeCheckReadFailed { path, error } ) ?;
51+
4852 Ok ( serde_json:: from_slice ( data. as_slice ( ) ) ?)
4953 }
5054
51- /// Saves the state of the upgrade check to the `upgrade_check.json` file in the global configuration directory.
55+ /// Saves the state of the upgrade check to the `upgrade_check.json` file in the global data directory.
5256 pub fn save ( & self ) -> Result < ( ) , locator:: Error > {
53- let locator = locator :: Args {
54- global : false ,
55- config_dir : None ,
56- } ;
57- let path = locator . global_config_path ( ) ? . join ( FILE_NAME ) ;
57+ let path = project_dir ( )
58+ . map_err ( |_| locator :: Error :: ProjectDirsError ( ) ) ?
59+ . data_dir ( )
60+ . join ( FILE_NAME ) ;
61+
5862 let path = locator:: ensure_directory ( path) ?;
5963 let data = serde_json:: to_string ( self ) . map_err ( |_| locator:: Error :: ConfigSerialization ) ?;
6064 fs:: write ( & path, data)
@@ -69,9 +73,9 @@ mod tests {
6973
7074 #[ test]
7175 fn test_upgrade_check_load_save ( ) {
72- // Set the `XDG_CONFIG_HOME ` environment variable to a temporary directory
76+ // Set the `XDG_DATA_HOME ` environment variable to a temporary directory
7377 let temp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
74- env:: set_var ( "XDG_CONFIG_HOME " , temp_dir. path ( ) ) ;
78+ env:: set_var ( "XDG_DATA_HOME " , temp_dir. path ( ) ) ;
7579 // Test default loading
7680 let default_check = UpgradeCheck :: load ( ) . unwrap ( ) ;
7781 assert_eq ! ( default_check, UpgradeCheck :: default ( ) ) ;
0 commit comments