commandserver: use constant directory name under AppData\Local

Summary:
It seems the "local" directory AppData\Local (or ~/.local/share) want a
constant top-level application name. Previously we use a dynamic name
`hg-cmdserver` or `sl-cmdserver`. Switch to a constant name to better
fit other programs.

Reviewed By: zzl0

Differential Revision: D47141803

fbshipit-source-id: f82d79bd1581a655ce5291b2545e6dd60c538dcf
This commit is contained in:
Jun Wu 2023-07-03 22:36:01 -07:00 committed by Facebook GitHub Bot
parent 7ae8a24e49
commit 3961fb041e

View File

@ -42,7 +42,10 @@ pub(crate) fn prefix() -> &'static str {
/// The directory contains `SOCKET_DIR_NAME` in its path.
#[context("Creating a runtime directory")]
pub(crate) fn runtime_dir() -> anyhow::Result<PathBuf> {
let parent = match dirs::runtime_dir().or_else(dirs::data_local_dir) {
let parent = match dirs::runtime_dir().or_else(|| {
// ~/.local/share, AppData\Local
dirs::data_local_dir().map(|local| local.join("CommandServer"))
}) {
None => {
#[allow(unused_mut)]
let mut dir = std::env::temp_dir();
@ -71,7 +74,7 @@ pub(crate) fn runtime_dir() -> anyhow::Result<PathBuf> {
};
let dir = parent.join(&*SOCKET_DIR_NAME);
match fs::create_dir(&dir) {
match fs::create_dir_all(&dir) {
Err(e) if e.kind() == io::ErrorKind::AlreadyExists => {}
Err(e) => {
return Err(e).with_context(|| format!("Creating a directory at {}", dir.display()));