@@ -2,15 +2,16 @@ use crate::config::locator;
2
2
use jsonrpsee_core:: Serialize ;
3
3
use semver:: Version ;
4
4
use serde:: Deserialize ;
5
+ use serde_json;
5
6
use std:: fs;
6
7
7
- const FILE_NAME : & str = "self_outdated_check.toml " ;
8
+ const FILE_NAME : & str = "upgrade_check.json " ;
8
9
9
10
/// The `SelfOutdatedCheck` struct represents the state of the self-outdated check.
10
- /// This state is global and stored in the `self_outdated_check.toml ` file in
11
+ /// This state is global and stored in the `self_outdated_check.json ` file in
11
12
/// the global configuration directory.
12
13
#[ derive( Serialize , Deserialize , Debug , PartialEq ) ]
13
- pub struct SelfOutdatedCheck {
14
+ pub struct UpgradeCheck {
14
15
/// The timestamp of the latest check for a new version of the CLI.
15
16
pub latest_check_time : u64 ,
16
17
/// The latest stable version of the CLI available on crates.io.
@@ -19,7 +20,7 @@ pub struct SelfOutdatedCheck {
19
20
pub max_version : Version ,
20
21
}
21
22
22
- impl Default for SelfOutdatedCheck {
23
+ impl Default for UpgradeCheck {
23
24
fn default ( ) -> Self {
24
25
Self {
25
26
latest_check_time : 0 ,
@@ -29,7 +30,7 @@ impl Default for SelfOutdatedCheck {
29
30
}
30
31
}
31
32
32
- impl SelfOutdatedCheck {
33
+ impl UpgradeCheck {
33
34
/// Loads the state of the self-outdated check from the global configuration directory.
34
35
/// If the file doesn't exist, returns a default instance of `SelfOutdatedCheck`.
35
36
pub fn load ( ) -> Result < Self , locator:: Error > {
@@ -39,14 +40,14 @@ impl SelfOutdatedCheck {
39
40
}
40
41
let data = fs:: read ( & path)
41
42
. map_err ( |error| locator:: Error :: SelfOutdatedCheckReadFailed { path, error } ) ?;
42
- Ok ( toml :: from_slice ( data. as_slice ( ) ) ?)
43
+ Ok ( serde_json :: from_slice ( data. as_slice ( ) ) ?)
43
44
}
44
45
45
- /// Saves the state of the self-outdated check to the `self_outdated_check.toml ` file in the global configuration directory.
46
+ /// Saves the state of the self-outdated check to the `self_outdated_check.json ` file in the global configuration directory.
46
47
pub fn save ( & self ) -> Result < ( ) , locator:: Error > {
47
48
let path = locator:: global_config_path ( ) ?. join ( FILE_NAME ) ;
48
49
let path = locator:: ensure_directory ( path) ?;
49
- let data = toml :: to_string ( self ) . map_err ( |_| locator:: Error :: ConfigSerialization ) ?;
50
+ let data = serde_json :: to_string ( self ) . map_err ( |_| locator:: Error :: ConfigSerialization ) ?;
50
51
fs:: write ( & path, data)
51
52
. map_err ( |error| locator:: Error :: SelfOutdatedCheckWriteFailed { path, error } )
52
53
}
@@ -64,19 +65,19 @@ mod tests {
64
65
env:: set_var ( "XDG_CONFIG_HOME" , temp_dir. path ( ) ) ;
65
66
66
67
// Test default loading
67
- let default_check = SelfOutdatedCheck :: load ( ) . unwrap ( ) ;
68
- assert_eq ! ( default_check, SelfOutdatedCheck :: default ( ) ) ;
68
+ let default_check = UpgradeCheck :: load ( ) . unwrap ( ) ;
69
+ assert_eq ! ( default_check, UpgradeCheck :: default ( ) ) ;
69
70
assert_eq ! ( default_check. latest_check_time, 0 ) ;
70
71
assert_eq ! ( default_check. max_stable_version, Version :: new( 0 , 0 , 0 ) ) ;
71
72
72
73
// Test saving and loading
73
- let saved_check = SelfOutdatedCheck {
74
+ let saved_check = UpgradeCheck {
74
75
latest_check_time : 1_234_567_890 ,
75
76
max_stable_version : Version :: new ( 1 , 2 , 3 ) ,
76
77
max_version : Version :: parse ( "1.2.4-rc.1" ) . unwrap ( ) ,
77
78
} ;
78
79
saved_check. save ( ) . unwrap ( ) ;
79
- let loaded_check = SelfOutdatedCheck :: load ( ) . unwrap ( ) ;
80
+ let loaded_check = UpgradeCheck :: load ( ) . unwrap ( ) ;
80
81
assert_eq ! ( loaded_check, saved_check) ;
81
82
}
82
83
}
0 commit comments