Skip to content

Commit 5fa953b

Browse files
committed
feat(directories): Parameterize data directory names and backup paths
1 parent fa79d22 commit 5fa953b

File tree

4 files changed

+53
-62
lines changed

4 files changed

+53
-62
lines changed

crates/chat-cli/src/util/directories.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ pub fn logs_dir() -> Result<PathBuf> {
117117
if #[cfg(unix)] {
118118
Ok(runtime_dir()?.join("qlog"))
119119
} else if #[cfg(windows)] {
120-
Ok(std::env::temp_dir().join("amazon-q").join("logs"))
120+
use crate::util::paths::application::DATA_DIR_NAME;
121+
Ok(std::env::temp_dir().join(DATA_DIR_NAME).join("logs"))
121122
}
122123
}
123124
}

crates/chat-cli/src/util/paths.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ pub mod application {
2929
//! Application data paths (system-specific)
3030
#[cfg(unix)]
3131
pub const DATA_DIR_NAME: &str = "amazon-q";
32+
#[cfg(windows)]
33+
pub const DATA_DIR_NAME: &str = "AmazonQ";
3234
pub const SETTINGS_FILE: &str = "settings.json";
3335
pub const DATABASE_FILE: &str = "data.sqlite3";
3436
}
@@ -78,22 +80,13 @@ pub fn home_dir(#[cfg_attr(windows, allow(unused_variables))] os: &Os) -> Result
7880
}
7981

8082
/// The application data directory
81-
/// - Linux: `$XDG_DATA_HOME/amazon-q` or `$HOME/.local/share/amazon-q`
82-
/// - MacOS: `$HOME/Library/Application Support/amazon-q`
83-
/// - Windows: `%LOCALAPPDATA%\AmazonQ`
83+
/// - Linux: `$XDG_DATA_HOME/{data_dir}` or `$HOME/.local/share/{data_dir}`
84+
/// - MacOS: `$HOME/Library/Application Support/{data_dir}`
85+
/// - Windows: `%LOCALAPPDATA%\{data_dir}`
8486
pub fn app_data_dir() -> Result<PathBuf> {
85-
#[cfg(unix)]
86-
{
87-
Ok(dirs::data_local_dir()
88-
.ok_or(DirectoryError::NoHomeDirectory)?
89-
.join(application::DATA_DIR_NAME))
90-
}
91-
#[cfg(windows)]
92-
{
93-
Ok(dirs::data_local_dir()
94-
.ok_or(DirectoryError::NoHomeDirectory)?
95-
.join("AmazonQ"))
96-
}
87+
Ok(dirs::data_local_dir()
88+
.ok_or(DirectoryError::NoHomeDirectory)?
89+
.join(application::DATA_DIR_NAME))
9790
}
9891

9992
/// Path resolver with hierarchy-aware methods

crates/fig_util/src/consts.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ pub const PRODUCT_NAME: &str = "Amazon Q";
2525

2626
pub const RUNTIME_DIR_NAME: &str = "cwrun";
2727

28+
/// Data directory name used in paths like ~/.local/share/{DATA_DIR_NAME}
29+
#[cfg(unix)]
30+
pub const DATA_DIR_NAME: &str = "amazon-q";
31+
#[cfg(windows)]
32+
pub const DATA_DIR_NAME: &str = "AmazonQ";
33+
34+
/// Backup directory name
35+
pub const BACKUP_DIR_NAME: &str = ".amazon-q.dotfiles.bak";
36+
2837
// These are the old "CodeWhisperer" branding, used anywhere we will not update to Amazon Q
2938
pub const OLD_PRODUCT_NAME: &str = "CodeWhisperer";
3039
pub const OLD_CLI_BINARY_NAMES: &[&str] = &["cw"];

crates/fig_util/src/directories.rs

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use time::OffsetDateTime;
1616

1717
#[cfg(unix)]
1818
use crate::RUNTIME_DIR_NAME;
19-
use crate::TAURI_PRODUCT_NAME;
2019
use crate::env_var::{
2120
Q_BUNDLE_METADATA_PATH,
2221
Q_PARENT,
@@ -26,6 +25,11 @@ use crate::system_info::{
2625
in_cloudshell,
2726
is_remote,
2827
};
28+
use crate::{
29+
BACKUP_DIR_NAME,
30+
DATA_DIR_NAME,
31+
TAURI_PRODUCT_NAME,
32+
};
2933

3034
macro_rules! utf8_dir {
3135
($name:ident, $($arg:ident: $type:ty),*) => {
@@ -136,21 +140,13 @@ pub fn old_fig_data_dir() -> Result<PathBuf> {
136140

137141
/// The q data directory
138142
///
139-
/// - Linux: `$XDG_DATA_HOME/amazon-q` or `$HOME/.local/share/amazon-q`
140-
/// - MacOS: `$HOME/Library/Application Support/amazon-q`
141-
/// - Windows: `%LOCALAPPDATA%\AmazonQ`
143+
/// - Linux: `$XDG_DATA_HOME/{data_dir}` or `$HOME/.local/share/{data_dir}`
144+
/// - MacOS: `$HOME/Library/Application Support/{data_dir}`
145+
/// - Windows: `%LOCALAPPDATA%\{data_dir}`
142146
pub fn fig_data_dir() -> Result<PathBuf> {
143-
cfg_if::cfg_if! {
144-
if #[cfg(unix)] {
145-
Ok(dirs::data_local_dir()
146-
.ok_or(DirectoryError::NoHomeDirectory)?
147-
.join("amazon-q"))
148-
} else if #[cfg(windows)] {
149-
Ok(dirs::data_local_dir()
150-
.ok_or(DirectoryError::NoHomeDirectory)?
151-
.join("AmazonQ"))
152-
}
153-
}
147+
Ok(dirs::data_local_dir()
148+
.ok_or(DirectoryError::NoHomeDirectory)?
149+
.join(DATA_DIR_NAME))
154150
}
155151

156152
pub fn fig_data_dir_ctx(fs: &impl FsProvider) -> Result<PathBuf> {
@@ -184,21 +180,13 @@ pub fn local_data_dir<Ctx: FsProvider + EnvProvider + PlatformProvider>(ctx: &Ct
184180

185181
/// The q cache directory
186182
///
187-
/// - Linux: `$XDG_CACHE_HOME/amazon-q` or `$HOME/.cache/amazon-q`
188-
/// - MacOS: `$HOME/Library/Caches/amazon-q`
189-
/// - Windows: `%LOCALAPPDATA%\AmazonQ\cache`
183+
/// - Linux: `$XDG_CACHE_HOME/{data_dir}` or `$HOME/.cache/{data_dir}`
184+
/// - MacOS: `$HOME/Library/Caches/{data_dir}`
185+
/// - Windows: `%LOCALAPPDATA%\{data_dir}\cache`
190186
pub fn cache_dir() -> Result<PathBuf> {
191-
cfg_if::cfg_if! {
192-
if #[cfg(unix)] {
193-
Ok(dirs::cache_dir()
194-
.ok_or(DirectoryError::NoHomeDirectory)?
195-
.join("amazon-q"))
196-
} else if #[cfg(windows)] {
197-
Ok(dirs::cache_dir()
198-
.ok_or(DirectoryError::NoHomeDirectory)?
199-
.join("AmazonQ"))
200-
}
201-
}
187+
Ok(dirs::cache_dir()
188+
.ok_or(DirectoryError::NoHomeDirectory)?
189+
.join(DATA_DIR_NAME))
202190
}
203191

204192
/// Get the macos tempdir from the `confstr` function
@@ -246,13 +234,13 @@ pub fn runtime_dir() -> Result<PathBuf> {
246234
///
247235
/// - Linux: $XDG_RUNTIME_DIR/cwrun
248236
/// - MacOS: $TMPDIR/cwrun
249-
/// - Windows: %TEMP%\sockets
237+
/// - Windows: %TEMP%\{data_dir}\sockets
250238
pub fn sockets_dir() -> Result<PathBuf> {
251239
cfg_if::cfg_if! {
252240
if #[cfg(unix)] {
253241
Ok(runtime_dir()?.join(RUNTIME_DIR_NAME))
254242
} else if #[cfg(windows)] {
255-
Ok(runtime_dir()?.join("AmazonQ").join("sockets"))
243+
Ok(runtime_dir()?.join(DATA_DIR_NAME).join("sockets"))
256244
}
257245
}
258246
}
@@ -303,24 +291,24 @@ pub fn autocomplete_specs_dir() -> Result<PathBuf> {
303291
/// The directory to all the fig logs
304292
/// - Linux: `/tmp/fig/$USER/logs`
305293
/// - MacOS: `$TMPDIR/logs`
306-
/// - Windows: `%TEMP%\AmazonQ\logs`
294+
/// - Windows: `%TEMP%\{data_dir}\logs`
307295
pub fn logs_dir() -> Result<PathBuf> {
308296
cfg_if::cfg_if! {
309297
if #[cfg(unix)] {
310298
use crate::CLI_BINARY_NAME;
311299
Ok(runtime_dir()?.join(format!("{CLI_BINARY_NAME}log")))
312300
} else if #[cfg(windows)] {
313-
Ok(std::env::temp_dir().join("AmazonQ").join("logs"))
301+
Ok(std::env::temp_dir().join(DATA_DIR_NAME).join("logs"))
314302
}
315303
}
316304
}
317305

318306
/// The directory where fig places all data-sensitive backups
319307
///
320-
/// - Linux/MacOS: `$HOME/.amazon-q.dotfiles.bak`
321-
/// - Windows: `%USERPROFILE%\.amazon-q.dotfiles.bak`
308+
/// - Linux/MacOS: `$HOME/{backup_dir}`
309+
/// - Windows: `%USERPROFILE%\{backup_dir}`
322310
pub fn backups_dir() -> Result<PathBuf> {
323-
Ok(home_dir()?.join(".amazon-q.dotfiles.bak"))
311+
Ok(home_dir()?.join(BACKUP_DIR_NAME))
324312
}
325313

326314
/// The directory for time based data-sensitive backups
@@ -397,9 +385,9 @@ pub fn figterm_socket_path(session_id: impl Display) -> Result<PathBuf> {
397385

398386
/// The path to the resources directory
399387
///
400-
/// - MacOS: "/Applications/Amazon Q.app/Contents/Resources"
388+
/// - MacOS: "/Applications/{app_name}.app/Contents/Resources"
401389
/// - Linux: "/usr/share/fig"
402-
/// - Windows: "%LOCALAPPDATA%\AmazonQ\resources"
390+
/// - Windows: "%LOCALAPPDATA%\{data_dir}\resources"
403391
pub fn resources_path() -> Result<PathBuf> {
404392
cfg_if::cfg_if! {
405393
if #[cfg(all(unix, not(target_os = "macos")))] {
@@ -433,9 +421,9 @@ pub fn resources_path_ctx<Ctx: EnvProvider + PlatformProvider>(ctx: &Ctx) -> Res
433421

434422
/// The path to the fig install manifest
435423
///
436-
/// - MacOS: "/Applications/Amazon Q.app/Contents/Resources/manifest.json"
424+
/// - MacOS: "/Applications/{app_name}.app/Contents/Resources/manifest.json"
437425
/// - Linux: "/usr/share/fig/manifest.json"
438-
/// - Windows: "%LOCALAPPDATA%\AmazonQ\resources\bin\manifest.json"
426+
/// - Windows: "%LOCALAPPDATA%\{data_dir}\resources\bin\manifest.json"
439427
pub fn manifest_path() -> Result<PathBuf> {
440428
cfg_if::cfg_if! {
441429
if #[cfg(unix)] {
@@ -460,18 +448,18 @@ pub fn bundle_metadata_path<Ctx: EnvProvider + PlatformProvider>(ctx: &Ctx) -> R
460448

461449
/// The path to the fig settings file
462450
///
463-
/// - Linux: `$HOME/.local/share/amazon-q/settings.json`
464-
/// - MacOS: `$HOME/Library/Application Support/amazon-q/settings.json`
465-
/// - Windows: `%LOCALAPPDATA%\AmazonQ\settings.json`
451+
/// - Linux: `$HOME/.local/share/{data_dir}/settings.json`
452+
/// - MacOS: `$HOME/Library/Application Support/{data_dir}/settings.json`
453+
/// - Windows: `%LOCALAPPDATA%\{data_dir}\settings.json`
466454
pub fn settings_path() -> Result<PathBuf> {
467455
Ok(fig_data_dir()?.join("settings.json"))
468456
}
469457

470458
/// The path to the lock file used to indicate that the app is updating
471459
///
472-
/// - Linux: `$HOME/.local/share/amazon-q/update.lock`
473-
/// - MacOS: `$HOME/Library/Application Support/amazon-q/update.lock`
474-
/// - Windows: `%LOCALAPPDATA%\AmazonQ\update.lock`
460+
/// - Linux: `$HOME/.local/share/{data_dir}/update.lock`
461+
/// - MacOS: `$HOME/Library/Application Support/{data_dir}/update.lock`
462+
/// - Windows: `%LOCALAPPDATA%\{data_dir}\update.lock`
475463
pub fn update_lock_path(ctx: &impl FsProvider) -> Result<PathBuf> {
476464
Ok(fig_data_dir_ctx(ctx)?.join("update.lock"))
477465
}

0 commit comments

Comments
 (0)