| 271 | 271 | | } |
| 272 | 272 | | } |
| 273 | 273 | | |
| 274 | + | /// Where the runner keeps everything: its program, registrations, log and |
| 275 | + | /// the sandbox's VM. In the app's local data, which stays on this computer: |
| 276 | + | /// roaming data (Windows' %APPDATA%) is copied to a profile server on |
| 277 | + | /// networks with roaming profiles, and a VM's disk and a runner's |
| 278 | + | /// credential have no business there. A computer whose runner already |
| 279 | + | /// lives in roaming data keeps it there: its WSL distribution is |
| 280 | + | /// registered at that path, and moving its disk would break it. On macOS |
| 281 | + | /// and Linux the two are the same folder. |
| 274 | 282 | | fn folder(app: &AppHandle) -> PathBuf { |
| 275 | | − | app.path().app_data_dir().unwrap_or_else(|_| std::env::temp_dir().join("sh.g1t.desktop")).join("runner") |
| 283 | + | let fallback = || std::env::temp_dir().join("sh.g1t.desktop"); |
| 284 | + | let local = app.path().app_local_data_dir().unwrap_or_else(|_| fallback()).join("runner"); |
| 285 | + | let roaming = app.path().app_data_dir().unwrap_or_else(|_| fallback()).join("runner"); |
| 286 | + | chosen_folder(local, roaming) |
| 276 | 287 | | } |
| 277 | 288 | | |
| 289 | + | /// The local folder, unless the runner was set up in the roaming one before. |
| 290 | + | fn chosen_folder(local: PathBuf, roaming: PathBuf) -> PathBuf { |
| 291 | + | if !local.exists() && roaming.exists() { roaming } else { local } |
| 292 | + | } |
| 293 | + | |
| 278 | 294 | | impl Registration { |
| 279 | 295 | | fn path(app: &AppHandle) -> PathBuf { |
| 280 | 296 | | folder(app).join("registration.json") |
| ⋯ |
| 2204 | 2220 | | } |
| 2205 | 2221 | | |
| 2206 | 2222 | | #[test] |
| 2223 | + | fn a_new_runner_lives_in_local_data_and_an_old_one_stays_put() { |
| 2224 | + | let base = std::env::temp_dir().join(format!("g1t-desktop-folders-{}", std::process::id())); |
| 2225 | + | let _ = std::fs::remove_dir_all(&base); |
| 2226 | + | let (local, roaming) = (base.join("local").join("runner"), base.join("roaming").join("runner")); |
| 2227 | + | assert_eq!(chosen_folder(local.clone(), roaming.clone()), local); |
| 2228 | + | std::fs::create_dir_all(&roaming).unwrap(); |
| 2229 | + | assert_eq!(chosen_folder(local.clone(), roaming.clone()), roaming); |
| 2230 | + | std::fs::create_dir_all(&local).unwrap(); |
| 2231 | + | assert_eq!(chosen_folder(local.clone(), roaming), local); |
| 2232 | + | let _ = std::fs::remove_dir_all(&base); |
| 2233 | + | } |
| 2234 | + | |
| 2235 | + | #[test] |
| 2207 | 2236 | | fn when_is_said_as_the_site_reads_it() { |
| 2208 | 2237 | | let at = |seconds: u64| rfc3339(SystemTime::UNIX_EPOCH + Duration::from_secs(seconds)); |
| 2209 | 2238 | | assert_eq!(at(0), "1970-01-01T00:00:00Z"); |