Skip to content

Commit 7b01126

Browse files
icp1994J.R. Hill
authored andcommitted
Move data files from legacy location if necessary
1 parent 38c47f4 commit 7b01126

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

src/data.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::error::Error;
22
use std::io::ErrorKind;
3-
use std::{fs, path::Path};
3+
use std::{env, fs, path::PathBuf};
44

55
use directories::ProjectDirs;
66

@@ -124,14 +124,27 @@ fn list_stacks_from_homedir() -> Result<Vec<String>, impl Error> {
124124
})
125125
}
126126

127+
fn v1_sigi_path() -> PathBuf {
128+
let home = env::var("HOME").or_else(|_| env::var("HOMEDRIVE")).unwrap();
129+
let path = format!("{}/.local/share/sigi", home);
130+
PathBuf::from(&path)
131+
}
132+
127133
fn sigi_path() -> String {
128-
let path = ProjectDirs::from("rs", "sigi-cli", "sigi").unwrap();
129-
path.data_dir().to_string_lossy().to_string()
134+
let sigi_base = ProjectDirs::from("org", "sigi-cli", "sigi").unwrap();
135+
let sigi_path = sigi_base.data_dir();
136+
let v1_path = v1_sigi_path();
137+
138+
if v1_path.exists() && !sigi_path.exists() {
139+
fs::rename(v1_path, sigi_path).unwrap();
140+
}
141+
142+
sigi_path.to_string_lossy().to_string()
130143
}
131144

132145
fn sigi_file(filename: &str) -> String {
133146
let path = format!("{}/{}.json", sigi_path(), filename);
134-
Path::new(&path).to_string_lossy().to_string()
147+
PathBuf::from(&path).to_string_lossy().to_string()
135148
}
136149

137150
/// A single stack item. Used for backwards compatibility with versions of Sigi v1.

0 commit comments

Comments
 (0)