Skip to content

Commit 3fba9af

Browse files
authored
Move upgrade check check file to data dir. (#2316)
1 parent f90f573 commit 3fba9af

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

cmd/soroban-cli/src/config/locator.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ pub enum Error {
102102
SecretKeyOnly(String),
103103
#[error(transparent)]
104104
Key(#[from] key::Error),
105+
#[error("Unable to get project directory")]
106+
ProjectDirsError(),
105107
}
106108

107109
#[derive(Debug, clap::Args, Default, Clone)]

cmd/soroban-cli/src/config/upgrade_check.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use serde::Deserialize;
66
use serde_json;
77
use std::fs;
88

9+
use super::data::project_dir;
10+
911
const 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());

cmd/soroban-cli/src/env_vars.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub fn unprefixed() -> Vec<&'static str> {
1212
"NETWORK",
1313
"NETWORK_PASSPHRASE",
1414
"NO_CACHE",
15+
"NO_UPDATE_CHECK",
1516
"OPERATION_SOURCE_ACCOUNT",
1617
"RPC_HEADERS",
1718
"RPC_URL",

0 commit comments

Comments
 (0)