@@ -3,6 +3,7 @@ use std::{
33 env,
44 fs:: File ,
55 io:: { ErrorKind , Read } ,
6+ path:: PathBuf ,
67} ;
78
89use mio:: Token ;
@@ -198,18 +199,35 @@ fn list_listeners(server: &mut Server, client: &mut ClientSession) {
198199}
199200
200201fn save_state ( server : & mut Server , client : & mut ClientSession , path : & str ) {
201- debug ! ( "saving state to file {}" , path) ;
202- let mut file = match File :: create ( path) {
202+ let mut path = PathBuf :: from ( path) ;
203+ if path. is_relative ( ) {
204+ match std:: env:: current_dir ( ) {
205+ Ok ( cwd) => path = cwd. join ( path) ,
206+ Err ( error) => {
207+ client. finish_failure ( format ! ( "Cannot get Sōzu working directory: {error}" , ) ) ;
208+ return ;
209+ }
210+ }
211+ }
212+
213+ debug ! ( "saving state to file {}" , & path. display( ) ) ;
214+ let mut file = match File :: create ( & path) {
203215 Ok ( file) => file,
204216 Err ( error) => {
205- client. finish_failure ( format ! ( "Cannot create file at path {path}: {error}" ) ) ;
217+ client. finish_failure ( format ! (
218+ "Cannot create file at path {}: {error}" ,
219+ path. display( )
220+ ) ) ;
206221 return ;
207222 }
208223 } ;
209224
210225 match server. state . write_requests_to_file ( & mut file) {
211226 Ok ( counter) => {
212- client. finish_ok ( format ! ( "Saved {counter} config messages to {path}" ) ) ;
227+ client. finish_ok ( format ! (
228+ "Saved {counter} config messages to {}" ,
229+ & path. display( )
230+ ) ) ;
213231 }
214232 Err ( error) => {
215233 client. finish_failure ( format ! ( "Failed writing state to file: {error}" ) ) ;
0 commit comments