Skip to content
New issue

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

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

Already on GitHub? # to your account

Allow multiple state caches #4642

Merged
merged 2 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,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
*
Expand Down
4 changes: 3 additions & 1 deletion src/format/opamPath.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 3 additions & 0 deletions src/format/opamPath.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions src/state/opamRepositoryState.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,6 +58,7 @@ module Cache = struct
(filter_out_nourl rt.repo_opams);
}
in
remove ();
C.save file t

let load root =
Expand All @@ -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 =
Expand Down