@@ -11,7 +11,6 @@ use crate::errors::{error_message, error_type, RequestErrorType};
11
11
use crate :: response;
12
12
use crate :: response:: Response ;
13
13
use bytes:: Bytes ;
14
- use directories:: BaseDirs ;
15
14
use logger_core:: { log_debug, log_error, log_info, log_trace, log_warn} ;
16
15
use once_cell:: sync:: Lazy ;
17
16
use protobuf:: { Chars , Message } ;
@@ -24,8 +23,8 @@ use std::cell::Cell;
24
23
use std:: collections:: HashSet ;
25
24
use std:: ptr:: from_mut;
26
25
use std:: rc:: Rc ;
26
+ use std:: str;
27
27
use std:: sync:: RwLock ;
28
- use std:: { env, str} ;
29
28
use std:: { io, thread} ;
30
29
use thiserror:: Error ;
31
30
use tokio:: net:: { UnixListener , UnixStream } ;
@@ -39,7 +38,8 @@ use ClosingReason::*;
39
38
use PipeListeningResult :: * ;
40
39
41
40
/// The socket file name
42
- const SOCKET_FILE_NAME : & str = "glide-socket" ;
41
+ const SOCKET_FILE_NAME : & str = "glide-socket.sock" ;
42
+ const SOCKET_FOLDER : & str = "valkey-glide" ;
43
43
44
44
/// The maximum length of a request's arguments to be passed as a vector of
45
45
/// strings instead of a pointer
@@ -582,6 +582,8 @@ async fn create_client(
582
582
Err ( err) => return Err ( ClientCreationError :: ConnectionError ( err) ) ,
583
583
} ;
584
584
write_result ( Ok ( Value :: Okay ) , 0 , writer) . await ?;
585
+
586
+ log_info ( "create_client" , "Client created successfully" ) ;
585
587
Ok ( client)
586
588
}
587
589
@@ -780,32 +782,22 @@ struct ClosingError {
780
782
err_message : String ,
781
783
}
782
784
783
- /// Get the socket full path.
784
- /// The socket file name will contain the process ID and will try to be saved into the user's runtime directory
785
- /// (e.g. /run/user/1000) in Unix systems. If the runtime dir isn't found, the socket file will be saved to the temp dir.
786
- /// For Windows, the socket file will be saved to %AppData%\Local.
787
- pub fn get_socket_path_from_name ( socket_name : String ) -> String {
788
- let base_dirs = BaseDirs :: new ( ) . expect ( "Failed to create BaseDirs" ) ;
789
- let tmp_dir;
790
- let folder = if cfg ! ( windows) {
791
- base_dirs. data_local_dir ( )
792
- } else {
793
- base_dirs. runtime_dir ( ) . unwrap_or ( {
794
- tmp_dir = env:: temp_dir ( ) ;
795
- tmp_dir. as_path ( )
796
- } )
797
- } ;
798
- folder
799
- . join ( socket_name)
800
- . into_os_string ( )
801
- . into_string ( )
802
- . expect ( "Couldn't create socket path" )
803
- }
804
-
805
785
/// Get the socket path as a string
806
786
pub fn get_socket_path ( ) -> String {
807
- let socket_name = format ! ( "{}-{}" , SOCKET_FILE_NAME , std:: process:: id( ) ) ;
808
- get_socket_path_from_name ( socket_name)
787
+ // Remove the socket folder if it exists, to ensure there are no conflicts with the socket file
788
+ // that will be created.
789
+ let tmp_dir = std:: env:: temp_dir ( ) ;
790
+ let socket_folder = tmp_dir
791
+ . join ( SOCKET_FOLDER )
792
+ . join ( std:: process:: id ( ) . to_string ( ) ) ;
793
+
794
+ let _ = std:: fs:: remove_dir_all ( & socket_folder) ;
795
+
796
+ let _ = std:: fs:: create_dir_all ( & socket_folder) ;
797
+ socket_folder
798
+ . join ( SOCKET_FILE_NAME )
799
+ . to_string_lossy ( )
800
+ . into_owned ( )
809
801
}
810
802
811
803
/// This function is exposed only for the sake of testing with a nonstandard `socket_path`.
0 commit comments