Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utop/init.ml does not respect XDG on Windows #451

Open
jonahbeckford opened this issue Jul 23, 2023 · 0 comments
Open

utop/init.ml does not respect XDG on Windows #451

jonahbeckford opened this issue Jul 23, 2023 · 0 comments

Comments

@jonahbeckford
Copy link
Contributor

Context

You can see in my utop session below that XDG correctly reports the configuration directory is LOCALAPPDATA, but some magic in utop is mangling the path badly.

You can follow along with DkML 2.0.1 at https://gitlab.com/diskuv-ocaml/distributions/dkml/-/releases/2.0.1/downloads/setup64u.exe in a Windows Sandbox or a VM. Then run utop in a Command Prompt or PowerShell.

utop # #require "utop";;

utop # let xdg = Xdg.create ~env:Sys.getenv_opt () ;;
val xdg : Xdg.t = <abstr>

utop # Xdg.config_dir xdg ;;
- : string = "C:\\Users\\WDAGUtilityAccount\\AppData\\Local"

utop # LTerm_resources.xdgbd_file ~loc:LTerm_resources.Config "utop/init.ml";;
- : string =
"C:\\Users\\WDAGUtilityAccount\\AppData\\Local\\Programs\\DiskuvOCaml\\tools\\MSYS2\\home\\WDAGUtilityAccount\\Local Settings\\utop/init.ml"

Root Cause Guess

Somehow xdgbd_file is combining both HOME and XDG (on Windows HOME should either be ignored or be the fallback to LOCALAPPDATA). My guess is that something is interpreting Xdg.config_dir xdg as a relative path (a common mistake is to assume that absolute paths have to start with a / forward slash), and then making Xdg.config_dir xdg an absolute path relative to $HOME.

That means utop can't locate the correct init.ml file:

utop/src/lib/uTop_main.ml

Lines 1406 to 1417 in 5b98d28

if Sys.file_exists ".ocamlinit" && Sys.getcwd () <> LTerm_resources.home then
Some ".ocamlinit"
else
let xdg_fn = LTerm_resources.xdgbd_file ~loc:LTerm_resources.Config "utop/init.ml" in
if Sys.file_exists xdg_fn then
Some xdg_fn
else
let fn = Filename.concat LTerm_resources.home ".ocamlinit" in
if Sys.file_exists fn then
Some fn
else
None

Related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant