Skip to content

Commit

Permalink
The socket file was moved from /tmp to the user's runtime folder in U…
Browse files Browse the repository at this point in the history
…nix systems and to the %AppData% folder in Windows
  • Loading branch information
barshaul committed Jun 26, 2023
1 parent fdd4250 commit f16dbea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions babushka-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ integer-encoding = "3.0.4"
thiserror = "1"
rand = "0.8.5"
futures-intrusive = "0.5.0"
directories = "5.0"

[dev-dependencies]
rsevents = "0.3.1"
Expand Down
14 changes: 13 additions & 1 deletion babushka-core/src/socket_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::redis_request::{Command, RedisRequest, RequestType, Transaction};
use crate::response;
use crate::response::Response;
use crate::retry_strategies::get_fixed_interval_backoff;
use directories::BaseDirs;
use dispose::{Disposable, Dispose};
use futures::stream::StreamExt;
use logger_core::{log_debug, log_error, log_info, log_trace};
Expand Down Expand Up @@ -619,8 +620,19 @@ impl fmt::Display for ClosingError {
}
}

/// Get the socket full path.
/// The socket file name will contain the process ID and will be saved into the user's runtime directory (e.g. /run/user/1000)
/// in Unix systems, or in %AppData%\Local in Windows
pub fn get_socket_path_from_name(socket_name: String) -> String {
std::env::temp_dir()
let base_dirs = BaseDirs::new().expect("Failed to create BaseDirs");
let folder = if cfg!(windows) {
base_dirs.data_local_dir()
} else {
base_dirs
.runtime_dir()
.expect("Failed to find the user's runtime folder")
};
folder
.join(socket_name)
.into_os_string()
.into_string()
Expand Down

0 comments on commit f16dbea

Please sign in to comment.