···106106107107 (*tries to get the logging dir for macos and linux*)
108108 let get_log_dir () =
109109- let os = poll_os () in
110110- let state_home =
111111- try
112112- match os with
113113- | Some "linux" ->
114114- Some (Unix.getenv "XDG_STATE_HOME")
115115- | Some "macos" ->
116116- Some "~/Library/Logs"
117117- | Some "windows" ->
118118- Some "~/AppData/Local"
109109+ try
110110+ let os = poll_os () in
111111+ let state_home =
112112+ try
113113+ match os with
114114+ | Some "linux" ->
115115+ Sys.getenv_opt "XDG_STATE_HOME"
116116+ | Some "macos" ->
117117+ let pwd = Unix.getpwuid (Unix.getuid ()) in
118118+ Some (pwd.pw_dir ^ "/Library/Logs")
119119+ | _ ->
120120+ None
121121+ with
119122 | _ ->
120123 None
121121- with
122122- | _ ->
123123- None
124124- in
125125- let state_home =
126126- Option.bind state_home (fun x -> if Sys.is_directory x then Some x else None)
127127- in
128128- match state_home with
129129- | None ->
130130- (try
131131- Unix.mkdir "~/.jj_tui" 0o755;
132132- Some "~/.jj_tui"
133133- with
134134- | Unix.Unix_error (Unix.EEXIST, _, _) ->
135135- None)
136136- | a ->
137137- a
124124+ in
125125+ let state_home =
126126+ Option.bind state_home (fun x ->
127127+ if Sys.file_exists x && Sys.is_directory x then Some x else None)
128128+ in
129129+ match state_home with
130130+ | None ->
131131+ Unix.mkdir "~/.jj_tui" 0o755;
132132+ Some "~/.jj_tui"
133133+ | a ->
134134+ a
135135+ with
136136+ |_->
137137+ None
138138 ;;
139139140140 let init_logging () =
···179179 cleanup_logs ();
180180 [%log debug "Old logs cleaned up"]
181181 | None ->
182182+ (*just no logging if we can't find a log file*)
183183+ (*TODO: log to stderr *)
182184 ()
183185 ;;
184186end