utop
utop copied to clipboard
Move histfile to the system's "state" folder
I'm not exactly sure how to create the directory if it doesn't exist, I'm still new to OCaml and not yet familiar with most libraries.
I'm not sure that adding Bos
as a dependency is something we want, but I'm not the one who can make the decision here.
If it's OK to have it, then, you should probably match on the result and print a warning/fail if the dir hasn't been created - and not use ignore
.
If it's not, you could just reimplement the part of Bos.OS.Dir.create
that is relevant here.
Adding more dependencies for something very small is probably not optimal, no.
The code below can be used to create a directory, including parent directories. If this is what you need.
(** create a directory but doesn't raise an exception if the directory already exist *)
let mkdir_safe dir perm =
try Unix.mkdir dir perm with Unix.Unix_error (Unix.EEXIST, _, _) -> ()
(** create a directory, and create parent if doesn't exist *)
let mkdir_rec dir perm =
let rec p_mkdir dir =
let p_name = Filename.dirname dir in
if p_name <> "/" && p_name <> "."
then p_mkdir p_name;
mkdir_safe dir perm in
p_mkdir dir
Thanks for making this PR ! This is a detail but shouldn't the file be in XDG_STATE_HOME instead of XDG_CACHE_HOME ? At least that's what the specification (https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) mentions.
Oh, I didn't know about it thanks ! It's been introduced in the latest basedir spec. I'll add it to directories. :)
Done, should be available soon, see ocaml/opam-repository#20409.
Thanks @exorcist365. I believe the PR can be merged but I don't have the rights to do it...
Hi! I feel like adding a transitive dependency to ctypes
on windows (through directories
) is a bit heavy. Is there a way to have native bindings to the corresponding APIs?
Note that some effort has been made not to depend on ctypes.foreign
and libffi
but only ctypes.stubs
and ctypes
. Regarding native bindings, I personally won't go into the trouble of it.
Sure, I understand. To give you some context, we're making sure that a selection of packages (including utop) are available as soon as new versions of the ocaml compiler are released. Adding ctypes on windows to the mix seems difficult but I'll check with the rest of the team.
It looks like xdg
is going to provide this kind of support on windows without the ctypes dependency: https://github.com/ocaml/dune/pull/5943
If this works in the context of this PR, I think that this would be preferable in terms of dependencies.
Well, in the current state the PR doesn't look correct to me (I commented there), but if it ends up providing a proper way to get the cache directory without ctypes it's great.
I'm not willing to take a dependency on ctypes at the moment, but please reopen if you're willing to implement this on top of xdg
or a similar lighter alternative. thanks!
lambda-term
has included support for the XDG Base Directory spec since version 3.0.0, including legacy fallback handling.
Perhaps this can be used to avoid a dependency.