|
1 | 1 | use std::error::Error; |
2 | 2 | use std::io::ErrorKind; |
3 | | -use std::{fs, path::Path}; |
| 3 | +use std::{env, fs, path::PathBuf}; |
4 | 4 |
|
5 | 5 | use directories::ProjectDirs; |
6 | 6 |
|
@@ -124,14 +124,27 @@ fn list_stacks_from_homedir() -> Result<Vec<String>, impl Error> { |
124 | 124 | }) |
125 | 125 | } |
126 | 126 |
|
| 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 | + |
127 | 133 | 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() |
130 | 143 | } |
131 | 144 |
|
132 | 145 | fn sigi_file(filename: &str) -> String { |
133 | 146 | 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() |
135 | 148 | } |
136 | 149 |
|
137 | 150 | /// A single stack item. Used for backwards compatibility with versions of Sigi v1. |
|
0 commit comments