utop icon indicating copy to clipboard operation
utop copied to clipboard

Move histfile to the system's "state" folder

Open exorcist365 opened this issue 3 years ago • 13 comments

exorcist365 avatar Nov 24 '21 18:11 exorcist365

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.

exorcist365 avatar Nov 25 '21 14:11 exorcist365

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.

zapashcanon avatar Nov 29 '21 14:11 zapashcanon

Adding more dependencies for something very small is probably not optimal, no.

pmetzger avatar Nov 29 '21 21:11 pmetzger

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

lindig avatar Nov 30 '21 15:11 lindig

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.

Firobe avatar Jan 08 '22 22:01 Firobe

Oh, I didn't know about it thanks ! It's been introduced in the latest basedir spec. I'll add it to directories. :)

zapashcanon avatar Jan 09 '22 01:01 zapashcanon

Done, should be available soon, see ocaml/opam-repository#20409.

zapashcanon avatar Jan 09 '22 01:01 zapashcanon

Thanks @exorcist365. I believe the PR can be merged but I don't have the rights to do it...

zapashcanon avatar Jan 29 '22 12:01 zapashcanon

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?

emillon avatar Jan 31 '22 11:01 emillon

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.

zapashcanon avatar Jan 31 '22 12:01 zapashcanon

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.

emillon avatar Feb 01 '22 10:02 emillon

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.

emillon avatar Jul 04 '22 12:07 emillon

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.

zapashcanon avatar Jul 05 '22 15:07 zapashcanon

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!

emillon avatar Feb 22 '23 10:02 emillon

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.

Skyb0rg007 avatar May 30 '23 15:05 Skyb0rg007