Skip to content

Commit

Permalink
Merge pull request #4642 from dra27/state-caches
Browse files Browse the repository at this point in the history
Allow multiple state caches
dra27 authored Apr 30, 2021
2 parents 471f767 + 2d35b75 commit a70ed4f
Showing 4 changed files with 19 additions and 7 deletions.
4 changes: 3 additions & 1 deletion master_changes.md
Original file line number Diff line number Diff line change
@@ -116,7 +116,9 @@ New option/command/subcommand are prefixed with ◈.
*

## State
*
* Rename state.cache to include the OpamVersion.magic() string. All .cache files are deleted if any
cache file is written to, allowing multiple versions of the library to co-exist without constantly
regenerating it [#4642 @dra27 - fix #4554]

# Opam file format
*
4 changes: 3 additions & 1 deletion src/format/opamPath.ml
Original file line number Diff line number Diff line change
@@ -25,7 +25,9 @@ let init_config_files () =
OpamFilename.Dir.of_string (OpamStd.Sys.home ()) // ".opamrc";
]

let state_cache t = t / "repo" // "state.cache"
let state_cache_dir t = t / "repo"

let state_cache t = state_cache_dir t // Printf.sprintf "state-%s.cache" (OpamVersion.magic ())

let lock t = t // "lock"

3 changes: 3 additions & 0 deletions src/format/opamPath.mli
Original file line number Diff line number Diff line change
@@ -21,6 +21,9 @@ type t = dirname
(** State cache *)
val state_cache: t -> filename

(** Directory containing state cache *)
val state_cache_dir: t -> dirname

(** Global lock file for the whole opamroot. Opam should generally read-lock
this (e.g. initialisation and format upgrades require a write lock) *)
val lock: t -> filename
15 changes: 10 additions & 5 deletions src/state/opamRepositoryState.ml
Original file line number Diff line number Diff line change
@@ -27,6 +27,15 @@ module Cache = struct
let name = "repository"
end)

let remove () =
let root = OpamStateConfig.(!r.root_dir) in
let cache_dir = OpamPath.state_cache_dir root in
let remove_cache_file file =
if OpamFilename.check_suffix file ".cache" then
OpamFilename.remove file
in
List.iter remove_cache_file (OpamFilename.files cache_dir)

let save rt =
let file = OpamPath.state_cache rt.repos_global.root in
(* Repository without remote are not cached, they are intended to be
@@ -49,6 +58,7 @@ module Cache = struct
(filter_out_nourl rt.repo_opams);
}
in
remove ();
C.save file t

let load root =
@@ -60,11 +70,6 @@ module Cache = struct
OpamRepositoryName.Map.of_list cache.cached_opams)
| None -> None

let remove () =
let root = OpamStateConfig.(!r.root_dir) in
let file = OpamPath.state_cache root in
C.remove file

end

let load_opams_from_dir repo_name repo_root =

0 comments on commit a70ed4f

Please sign in to comment.