Skip to content

Commit 368f3a1

Browse files
committed
fix: clean up windows directories
1 parent dba41b1 commit 368f3a1

File tree

2 files changed

+78
-89
lines changed

2 files changed

+78
-89
lines changed

crates/fig_util/src/directories.rs

Lines changed: 53 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,6 @@ pub enum DirectoryError {
7070

7171
type Result<T, E = DirectoryError> = std::result::Result<T, E>;
7272

73-
/// The fig directory
74-
///
75-
/// - Linux: `$HOME/.local/share/amazon-q`
76-
/// - MacOS: `$HOME/Library/Application Support/amazon-q`
77-
/// - Windows: `%LOCALAPPDATA%\Fig`
78-
pub fn fig_dir() -> Result<PathBuf> {
79-
cfg_if::cfg_if! {
80-
if #[cfg(unix)] {
81-
Ok(dirs::data_local_dir()
82-
.ok_or(DirectoryError::NoHomeDirectory)?
83-
.join("amazon-q"))
84-
} else if #[cfg(windows)] {
85-
Ok(dirs::data_local_dir()
86-
.ok_or(DirectoryError::NoHomeDirectory)?
87-
.join("Fig"))
88-
}
89-
}
90-
}
91-
9273
/// The directory of the users home
9374
///
9475
/// - Linux: /home/Alice
@@ -148,29 +129,26 @@ pub fn config_dir() -> Result<PathBuf> {
148129
/// This should be removed at some point in the future, once all our users have migrated
149130
/// - MacOS: `$HOME/Library/Application Support/codewhisperer`
150131
pub fn old_fig_data_dir() -> Result<PathBuf> {
151-
cfg_if::cfg_if! {
152-
if #[cfg(unix)] {
153-
Ok(dirs::data_local_dir()
154-
.ok_or(DirectoryError::NoHomeDirectory)?
155-
.join("codewhisperer"))
156-
} else if #[cfg(windows)] {
157-
Ok(fig_dir()?.join("userdata"))
158-
}
159-
}
132+
Ok(dirs::data_local_dir()
133+
.ok_or(DirectoryError::NoHomeDirectory)?
134+
.join("codewhisperer"))
160135
}
161136

162137
/// The q data directory
163138
///
164139
/// - Linux: `$XDG_DATA_HOME/amazon-q` or `$HOME/.local/share/amazon-q`
165140
/// - MacOS: `$HOME/Library/Application Support/amazon-q`
141+
/// - Windows: `%LOCALAPPDATA%\AmazonQ`
166142
pub fn fig_data_dir() -> Result<PathBuf> {
167143
cfg_if::cfg_if! {
168144
if #[cfg(unix)] {
169145
Ok(dirs::data_local_dir()
170146
.ok_or(DirectoryError::NoHomeDirectory)?
171147
.join("amazon-q"))
172148
} else if #[cfg(windows)] {
173-
Ok(fig_dir()?.join("userdata"))
149+
Ok(dirs::data_local_dir()
150+
.ok_or(DirectoryError::NoHomeDirectory)?
151+
.join("AmazonQ"))
174152
}
175153
}
176154
}
@@ -208,14 +186,17 @@ pub fn local_data_dir<Ctx: FsProvider + EnvProvider + PlatformProvider>(ctx: &Ct
208186
///
209187
/// - Linux: `$XDG_CACHE_HOME/amazon-q` or `$HOME/.cache/amazon-q`
210188
/// - MacOS: `$HOME/Library/Caches/amazon-q`
189+
/// - Windows: `%LOCALAPPDATA%\AmazonQ\cache`
211190
pub fn cache_dir() -> Result<PathBuf> {
212191
cfg_if::cfg_if! {
213192
if #[cfg(unix)] {
214193
Ok(dirs::cache_dir()
215194
.ok_or(DirectoryError::NoHomeDirectory)?
216195
.join("amazon-q"))
217196
} else if #[cfg(windows)] {
218-
Ok(fig_dir()?.join("cache"))
197+
Ok(dirs::cache_dir()
198+
.ok_or(DirectoryError::NoHomeDirectory)?
199+
.join("AmazonQ"))
219200
}
220201
}
221202
}
@@ -265,12 +246,13 @@ pub fn runtime_dir() -> Result<PathBuf> {
265246
///
266247
/// - Linux: $XDG_RUNTIME_DIR/cwrun
267248
/// - MacOS: $TMPDIR/cwrun
249+
/// - Windows: %TEMP%\sockets
268250
pub fn sockets_dir() -> Result<PathBuf> {
269251
cfg_if::cfg_if! {
270252
if #[cfg(unix)] {
271253
Ok(runtime_dir()?.join(RUNTIME_DIR_NAME))
272254
} else if #[cfg(windows)] {
273-
Ok(fig_dir()?.join("sockets"))
255+
Ok(runtime_dir()?.join("sockets"))
274256
}
275257
}
276258
}
@@ -282,6 +264,7 @@ pub fn sockets_dir() -> Result<PathBuf> {
282264
///
283265
/// - Linux: $XDG_RUNTIME_DIR/cwrun
284266
/// - MacOS: $TMPDIR/cwrun
267+
/// - Windows: %TEMP%\sockets
285268
pub fn host_sockets_dir() -> Result<PathBuf> {
286269
// TODO: make this work again
287270
// #[cfg(target_os = "linux")]
@@ -320,27 +303,24 @@ pub fn autocomplete_specs_dir() -> Result<PathBuf> {
320303
/// The directory to all the fig logs
321304
/// - Linux: `/tmp/fig/$USER/logs`
322305
/// - MacOS: `$TMPDIR/logs`
323-
/// - Windows: `%TEMP%\fig\logs`
306+
/// - Windows: `%TEMP%\AmazonQ\logs`
324307
pub fn logs_dir() -> Result<PathBuf> {
325308
cfg_if::cfg_if! {
326309
if #[cfg(unix)] {
327310
use crate::CLI_BINARY_NAME;
328311
Ok(runtime_dir()?.join(format!("{CLI_BINARY_NAME}log")))
329312
} else if #[cfg(windows)] {
330-
Ok(std::env::temp_dir().join("amazon-q").join("logs"))
313+
Ok(std::env::temp_dir().join("AmazonQ").join("logs"))
331314
}
332315
}
333316
}
334317

335318
/// The directory where fig places all data-sensitive backups
319+
///
320+
/// - Linux/MacOS: `$HOME/.amazon-q.dotfiles.bak`
321+
/// - Windows: `%USERPROFILE%\.amazon-q.dotfiles.bak`
336322
pub fn backups_dir() -> Result<PathBuf> {
337-
cfg_if::cfg_if! {
338-
if #[cfg(unix)] {
339-
Ok(home_dir()?.join(".amazon-q.dotfiles.bak"))
340-
} else if #[cfg(windows)] {
341-
Ok(fig_data_dir()?.join("backups"))
342-
}
343-
}
323+
Ok(home_dir()?.join(".amazon-q.dotfiles.bak"))
344324
}
345325

346326
/// The directory for time based data-sensitive backups
@@ -371,7 +351,7 @@ pub fn chat_profiles_dir<Ctx: FsProvider + EnvProvider>(ctx: &Ctx) -> Result<Pat
371351
///
372352
/// - MacOS: `$TMPDIR/cwrun/desktop.sock`
373353
/// - Linux: `$XDG_RUNTIME_DIR/cwrun/desktop.sock`
374-
/// - Windows: `%APPDATA%/Fig/desktop.sock`
354+
/// - Windows: `%TEMP%\sockets\desktop.sock`
375355
pub fn desktop_socket_path() -> Result<PathBuf> {
376356
Ok(host_sockets_dir()?.join("desktop.sock"))
377357
}
@@ -381,8 +361,9 @@ pub fn desktop_socket_path() -> Result<PathBuf> {
381361
// - Linux/MacOS not on ssh:
382362
/// - MacOS: `$TMPDIR/cwrun/remote.sock`
383363
/// - Linux: `$XDG_RUNTIME_DIR/cwrun/remote.sock`
384-
/// - Windows: `%APPDATA%/Fig/%USER%/remote.sock`
364+
/// - Windows: `%TEMP%\sockets\remote.sock`
385365
pub fn remote_socket_path() -> Result<PathBuf> {
366+
// Normal implementation for non-test code
386367
// TODO(grant): This is only enabled on Linux for now to prevent public dist
387368
if is_remote() && !in_cloudshell() && cfg!(target_os = "linux") {
388369
if let Some(parent_socket) = std::env::var_os(Q_PARENT) {
@@ -399,7 +380,7 @@ pub fn remote_socket_path() -> Result<PathBuf> {
399380
///
400381
/// - MacOS: `$TMPDIR/cwrun/remote.sock`
401382
/// - Linux: `$XDG_RUNTIME_DIR/cwrun/remote.sock`
402-
/// - Windows: `%APPDATA%/Fig/%USER%/remote.sock`
383+
/// - Windows: `%TEMP%\sockets\remote.sock`
403384
pub fn local_remote_socket_path() -> Result<PathBuf> {
404385
Ok(host_sockets_dir()?.join("remote.sock"))
405386
}
@@ -409,30 +390,24 @@ pub fn local_remote_socket_path() -> Result<PathBuf> {
409390
/// - Linux/Macos: `/var/tmp/fig/%USERNAME%/figterm/$SESSION_ID.sock`
410391
/// - MacOS: `$TMPDIR/cwrun/t/$SESSION_ID.sock`
411392
/// - Linux: `$XDG_RUNTIME_DIR/cwrun/t/$SESSION_ID.sock`
412-
/// - Windows: `%LOCALAPPDATA%\Fig\sockets\figterm\$SESSION_ID.sock`
393+
/// - Windows: `%TEMP%\sockets\t\$SESSION_ID.sock`
413394
pub fn figterm_socket_path(session_id: impl Display) -> Result<PathBuf> {
414-
cfg_if::cfg_if! {
415-
if #[cfg(unix)] {
416-
Ok(sockets_dir()?.join("t").join(format!("{session_id}.sock")))
417-
} else if #[cfg(windows)] {
418-
Ok(sockets_dir()?.join("figterm").join(format!("{session_id}.sock")))
419-
}
420-
}
395+
Ok(sockets_dir()?.join("t").join(format!("{session_id}.sock")))
421396
}
422397

423398
/// The path to the resources directory
424399
///
425400
/// - MacOS: "/Applications/Amazon Q.app/Contents/Resources"
426401
/// - Linux: "/usr/share/fig"
427-
/// - Windows: "%LOCALAPPDATA%\Fig\resources"
402+
/// - Windows: "%LOCALAPPDATA%\AmazonQ\resources"
428403
pub fn resources_path() -> Result<PathBuf> {
429404
cfg_if::cfg_if! {
430405
if #[cfg(all(unix, not(target_os = "macos")))] {
431406
Ok(std::path::Path::new("/usr/share/fig").into())
432407
} else if #[cfg(target_os = "macos")] {
433408
Ok(crate::app_bundle_path().join(crate::macos::BUNDLE_CONTENTS_RESOURCE_PATH))
434409
} else if #[cfg(windows)] {
435-
Ok(fig_dir()?.join("resources"))
410+
Ok(fig_data_dir()?.join("resources"))
436411
}
437412
}
438413
}
@@ -451,29 +426,25 @@ pub fn resources_path_ctx<Ctx: EnvProvider + PlatformProvider>(ctx: &Ctx) -> Res
451426
Ok(format!("/usr/share/{}", PACKAGE_NAME).into())
452427
}
453428
},
454-
fig_os_shim::Os::Windows => Ok(fig_dir()?.join("resources")),
429+
fig_os_shim::Os::Windows => Ok(fig_data_dir()?.join("resources")),
455430
_ => Err(DirectoryError::UnsupportedOs(os)),
456431
}
457432
}
458433

459434
/// The path to the managed binaries directory
460435
///
461-
/// - Windows: "%LOCALAPPDATA%\Fig\bin"
436+
/// - Linux: "/usr/share/fig"
437+
/// - MacOS: "/Applications/Amazon Q.app/Contents/Resources"
438+
/// - Windows: "%LOCALAPPDATA%\AmazonQ\resources\bin"
462439
pub fn managed_binaries_dir() -> Result<PathBuf> {
463-
cfg_if::cfg_if! {
464-
if #[cfg(windows)] {
465-
Ok(fig_dir()?.join("bin"))
466-
} else {
467-
Ok(resources_path()?)
468-
}
469-
}
440+
Ok(resources_path()?.join("bin"))
470441
}
471442

472443
/// The path to the fig install manifest
473444
///
474445
/// - MacOS: "/Applications/Amazon Q.app/Contents/Resources/manifest.json"
475446
/// - Linux: "/usr/share/fig/manifest.json"
476-
/// - Windows: "%LOCALAPPDATA%\Fig\bin\manifest.json"
447+
/// - Windows: "%LOCALAPPDATA%\AmazonQ\resources\bin\manifest.json"
477448
pub fn manifest_path() -> Result<PathBuf> {
478449
cfg_if::cfg_if! {
479450
if #[cfg(unix)] {
@@ -497,11 +468,19 @@ pub fn bundle_metadata_path<Ctx: EnvProvider + PlatformProvider>(ctx: &Ctx) -> R
497468
}
498469

499470
/// The path to the fig settings file
471+
///
472+
/// - Linux: `$HOME/.local/share/amazon-q/settings.json`
473+
/// - MacOS: `$HOME/Library/Application Support/amazon-q/settings.json`
474+
/// - Windows: `%LOCALAPPDATA%\AmazonQ\settings.json`
500475
pub fn settings_path() -> Result<PathBuf> {
501476
Ok(fig_data_dir()?.join("settings.json"))
502477
}
503478

504479
/// The path to the lock file used to indicate that the app is updating
480+
///
481+
/// - Linux: `$HOME/.local/share/amazon-q/update.lock`
482+
/// - MacOS: `$HOME/Library/Application Support/amazon-q/update.lock`
483+
/// - Windows: `%LOCALAPPDATA%\AmazonQ\update.lock`
505484
pub fn update_lock_path(ctx: &impl FsProvider) -> Result<PathBuf> {
506485
Ok(fig_data_dir_ctx(ctx)?.join("update.lock"))
507486
}
@@ -578,7 +557,6 @@ pub fn local_webview_data_dir<Ctx: FsProvider + EnvProvider + PlatformProvider>(
578557
utf8_dir!(home_dir);
579558
#[cfg(unix)]
580559
utf8_dir!(home_local_bin);
581-
utf8_dir!(fig_dir);
582560
utf8_dir!(fig_data_dir);
583561
utf8_dir!(sockets_dir);
584562
utf8_dir!(remote_socket_path);
@@ -599,7 +577,6 @@ mod linux_tests {
599577
assert!(home_dir().is_ok());
600578
#[cfg(unix)]
601579
assert!(home_local_bin().is_ok());
602-
assert!(fig_dir().is_ok());
603580
assert!(fig_data_dir().is_ok());
604581
assert!(sockets_dir().is_ok());
605582
assert!(remote_socket_path().is_ok());
@@ -731,89 +708,82 @@ mod tests {
731708
macos!(home_local_bin(), @"$HOME/.local/bin");
732709
}
733710

734-
#[test]
735-
fn snapshot_fig_dir() {
736-
linux!(fig_dir(), @"$HOME/.local/share/amazon-q");
737-
macos!(fig_dir(), @"$HOME/Library/Application Support/amazon-q");
738-
windows!(fig_dir(), @r"C:\Users\$USER\AppData\Local\Fig");
739-
}
740-
741711
#[test]
742712
fn snapshot_fig_data_dir() {
743713
linux!(fig_data_dir(), @"$HOME/.local/share/amazon-q");
744714
macos!(fig_data_dir(), @"$HOME/Library/Application Support/amazon-q");
745-
windows!(fig_data_dir(), @r"C:\Users\$USER\AppData\Local\Fig\userdata");
715+
windows!(fig_data_dir(), @r"C:\Users\$USER\AppData\Local\AmazonQ");
746716
}
747717

748718
#[test]
749719
fn snapshot_sockets_dir() {
750720
linux!(sockets_dir(), @"$XDG_RUNTIME_DIR/cwrun");
751721
macos!(sockets_dir(), @"$TMPDIR/cwrun");
752-
windows!(sockets_dir(), @r"C:\Users\$USER\AppData\Local\Fig\sockets");
722+
windows!(sockets_dir(), @r"C:\Users\$USER\AppData\Local\Temp\sockets");
753723
}
754724

755725
#[test]
756726
fn snapshot_themes_dir() {
757727
linux!(themes_dir(&Context::new()), @"/usr/share/fig/themes");
758728
macos!(themes_dir(&Context::new()), @"/Applications/Amazon Q.app/Contents/Resources/themes");
759-
windows!(themes_dir(&Context::new()), @r"C:\Users\$USER\AppData\Local\Fig\resources\themes");
729+
windows!(themes_dir(&Context::new()), @r"C:\Users\$USER\AppData\Local\AmazonQ\resources\themes");
760730
}
761731

762732
#[test]
763733
fn snapshot_backups_dir() {
764734
linux!(backups_dir(), @"$HOME/.amazon-q.dotfiles.bak");
765735
macos!(backups_dir(), @"$HOME/.amazon-q.dotfiles.bak");
766-
windows!(backups_dir(), @r"C:\Users\$USER\AppData\Local\Fig\userdata\backups");
736+
windows!(backups_dir(), @r"C:\Users\$USER\.amazon-q.dotfiles.bak");
767737
}
768738

769739
#[test]
770740
fn snapshot_fig_socket_path() {
771741
linux!(desktop_socket_path(), @"$XDG_RUNTIME_DIR/cwrun/desktop.sock");
772742
macos!(desktop_socket_path(), @"$TMPDIR/cwrun/desktop.sock");
773-
windows!(desktop_socket_path(), @r"C:\Users\$USER\AppData\Local\Fig\sockets\desktop.sock");
743+
windows!(desktop_socket_path(), @r"C:\Users\$USER\AppData\Local\Temp\sockets\desktop.sock");
774744
}
775745

776746
#[test]
777747
fn snapshot_remote_socket_path() {
778748
linux!(remote_socket_path(), @"$XDG_RUNTIME_DIR/cwrun/remote.sock");
779749
macos!(remote_socket_path(), @"$TMPDIR/cwrun/remote.sock");
780-
windows!(remote_socket_path(), @r"C:\Users\$USER\AppData\Local\Fig\sockets\remote.sock");
750+
windows!(remote_socket_path(), @r"C:\Users\$USER\AppData\Local\Temp\sockets\remote.sock");
781751
}
782752

783753
#[test]
784754
fn snapshot_local_remote_socket_path() {
785755
linux!(local_remote_socket_path(), @"$XDG_RUNTIME_DIR/cwrun/remote.sock");
786756
macos!(local_remote_socket_path(), @"$TMPDIR/cwrun/remote.sock");
787-
windows!(local_remote_socket_path(), @r"C:\Users\$USER\AppData\Local\Fig\sockets\remote.sock");
757+
windows!(local_remote_socket_path(), @r"C:\Users\$USER\AppData\Local\Temp\sockets\remote.sock");
788758
}
789759

790760
#[test]
791761
fn snapshot_figterm_socket_path() {
792762
linux!(figterm_socket_path("$SESSION_ID"), @"$XDG_RUNTIME_DIR/cwrun/t/$SESSION_ID.sock");
793763
macos!(figterm_socket_path("$SESSION_ID"), @"$TMPDIR/cwrun/t/$SESSION_ID.sock");
794-
windows!(figterm_socket_path("$SESSION_ID"), @r"C:\Users\$USER\AppData\Local\Fig\sockets\figterm\$SESSION_ID.sock");
764+
windows!(figterm_socket_path("$SESSION_ID"), @r"C:\Users\$USER\AppData\Local\Temp\sockets\t\$SESSION_ID.sock");
795765
}
796766

797767
#[test]
798768
fn snapshot_managed_binaries_dir() {
799769
linux!(managed_binaries_dir(), @"/usr/share/fig");
800770
macos!(managed_binaries_dir(), @"/Applications/Amazon Q.app/Contents/Resources");
801-
windows!(managed_binaries_dir(), @r"C:\Users\$USER\AppData\Local\Fig\bin");
771+
windows!(managed_binaries_dir(), @r"C:\Users\$USER\AppData\Local\AmazonQ\resources\bin");
802772
}
803773

804774
#[test]
805775
fn snapshot_settings_path() {
806776
linux!(settings_path(), @"$HOME/.local/share/amazon-q/settings.json");
807777
macos!(settings_path(), @"$HOME/Library/Application Support/amazon-q/settings.json");
808-
windows!(settings_path(), @r"C:\Users\$USER\AppData\Local\Fig\userdata\settings.json");
778+
windows!(settings_path(), @r"C:\Users\$USER\AppData\Local\AmazonQ\settings.json");
809779
}
810780

811781
#[test]
812782
fn snapshot_update_lock_path() {
813783
let ctx = Context::new();
814784
linux!(update_lock_path(&ctx), @"$HOME/.local/share/amazon-q/update.lock");
815785
macos!(update_lock_path(&ctx), @"$HOME/Library/Application Support/amazon-q/update.lock");
816-
windows!(update_lock_path(&ctx), @r"C:\Users\$USER\AppData\Local\Fig\userdata\update.lock");
786+
windows!(update_lock_path(&ctx), @r"C:\Users\$USER\AppData\Local\AmazonQ\update.lock");
817787
}
818788

819789
#[test]

0 commit comments

Comments
 (0)