Skip to content

Commit 4d5033a

Browse files
moyodiallorjbou
authored andcommitted
Move last-env OPAM_LAST_ENV files outside the switch.
The last-env files are now stored in `~/.opam/.last-env` dir.
1 parent 391333d commit 4d5033a

File tree

8 files changed

+30
-29
lines changed

8 files changed

+30
-29
lines changed

master_changes.md

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ users)
3636
* Allow to parse opam 2.1 switch import files containing extra-files [#5943 @kit-ty-kate - fix #5941]
3737

3838
## Config
39+
* Move last-env `OPAM_LAST_ENV` files outside the switch to be in the `opam root` [#5962 @moyodiallo - fix #5823]
3940

4041
## Pin
4142

@@ -152,6 +153,7 @@ users)
152153
## opam-solver
153154

154155
## opam-format
156+
* `OpamPath`: remove `OpamPath.Switch.last_env` function in favor to `OpamPath.last_env` as the files are no more stored in switch directory [#5962 @moyodiallo - fix #5823]
155157

156158
## opam-core
157159
* `OpamStd.String`: add `split_quoted` that preserves quoted separator [#5935 @dra27]

src/client/opamCommands.ml

-1
Original file line numberDiff line numberDiff line change
@@ -4205,7 +4205,6 @@ let clean cli =
42054205
cleandir (OpamPath.Switch.build_dir root sw);
42064206
cleandir (OpamPath.Switch.remove_dir root sw);
42074207
cleandir (OpamPath.Switch.extra_files_dir root sw);
4208-
cleandir (OpamPath.Switch.last_env root sw);
42094208
let pinning_overlay_dirs =
42104209
List.map
42114210
(fun nv -> OpamPath.Switch.Overlay.package root sw nv.name)

src/client/opamConfigCommand.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ let load_and_verify_env ~set_opamroot ~set_opamswitch ~force_path
259259
(* Returns [Some file] where [file] contains [updates]. [hash] should be
260260
[OpamEnv.hash_env_updates updates] and [n] should initially be [0]. If for
261261
whatever reason the file cannot be created, returns [None]. *)
262-
let write_last_env_file gt switch updates =
262+
let write_last_env_file gt updates =
263263
let updates = check_writeable updates in
264-
let temp_dir = OpamPath.Switch.last_env gt.root switch in
264+
let temp_dir = OpamPath.last_env gt.root in
265265
let hash = OpamEnv.hash_env_updates updates in
266266
let rec aux n =
267267
(* The principal aim here is not to spam /tmp with gazillions of files, but
@@ -310,7 +310,7 @@ let ensure_env_aux ?(base=[]) ?(set_opamroot=false) ?(set_opamswitch=false)
310310
updates
311311
in
312312
let last_env_file =
313-
write_last_env_file gt switch
313+
write_last_env_file gt
314314
(* We remove OPAMSWITCH & OPAMROOT as they are not supposed
315315
to be reverted *)
316316
(List.filter (fun upd ->

src/format/opamFile.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ external open_env_updates:
548548
(* cf. tests/lib/typeGymnastics.ml *)
549549

550550
(** Cached environment updates (<switch>/.opam-switch/environment
551-
<switch>/.opam-switch/last-env/env-* last env files) *)
551+
<opam-root>/.last-env/env-* last env files) *)
552552

553553
module Environment = struct include LineFile(struct
554554

src/format/opamPath.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ let plugin t name =
7979
assert (sname <> "bin");
8080
plugins t / sname
8181

82+
let last_env t = t / ".last-env"
83+
8284
module type LAYOUT = sig
8385
type ctx
8486
val root : dirname -> ctx -> dirname
@@ -140,8 +142,6 @@ module Switch = struct
140142

141143
let environment t a = meta t a /- env_filename
142144

143-
let last_env t a = meta t a / "last-env"
144-
145145
let env_relative_to_prefix pfx = pfx / meta_dirname /- env_filename
146146

147147
let installed_opams t a = meta t a / "packages"

src/format/opamPath.mli

+3-2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ val plugin_bin: t -> name -> filename
7878
forbidden. *)
7979
val plugin: t -> name -> dirname
8080

81+
(** The last environment used regardless the switch *)
82+
val last_env: t -> dirname
83+
8184
module type LAYOUT = sig
8285
type ctx
8386
val root : dirname -> ctx -> dirname
@@ -174,8 +177,6 @@ module Switch: sig
174177
(** Cached environment updates. *)
175178
val environment: t -> switch -> OpamFile.Environment.t OpamFile.t
176179

177-
val last_env: t -> switch -> dirname
178-
179180
(** Like [environment], but from the switch prefix dir *)
180181
val env_relative_to_prefix: dirname -> OpamFile.Environment.t OpamFile.t
181182

tests/reftests/clean.test

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ rm -rf "${BASEDIR}/OPAM/clean/.opam-switch/backup"/*
7373
rm -rf "${BASEDIR}/OPAM/clean/.opam-switch/build"/*
7474
rm -rf "${BASEDIR}/OPAM/clean/.opam-switch/remove"/*
7575
rm -rf "${BASEDIR}/OPAM/clean/.opam-switch/extra-files-cache"/*
76-
rm -rf "${BASEDIR}/OPAM/clean/.opam-switch/last-env"/*
7776
### opam clean --untracked
7877
Cleaning up switch clean
7978
Remaining directories and files:

tests/reftests/env.test

+19-19
Original file line numberDiff line numberDiff line change
@@ -518,13 +518,13 @@ Done.
518518
### opam env --readonly --debug-level=-3 | grep "A_VAR\|FILE\\(environment\\)\|CONFIG\|^STATE" | '[0-9a-f]{32}' -> 'hash' | ';' -> ':'
519519
CONFIG config-env
520520
FILE(environment) Read ${BASEDIR}/OPAM/switch1/.opam-switch/environment in 0.000s
521-
FILE(environment) Wrote ${BASEDIR}/OPAM/switch1/.opam-switch/last-env/env-hash-0 atomically in 0.000s
522-
FILE(environment) Read ${BASEDIR}/OPAM/switch1/.opam-switch/last-env/env-hash-0 in 0.000s
521+
FILE(environment) Wrote ${BASEDIR}/OPAM/.last-env/env-hash-0 atomically in 0.000s
522+
FILE(environment) Read ${BASEDIR}/OPAM/.last-env/env-hash-0 in 0.000s
523523
A_VAR='${BASEDIR}/OPAM/switch1/lib': export A_VAR:
524524
### opam env --debug-level=-3 | grep "A_VAR\|FILE\\(environment\\)\|CONFIG\|^STATE" | '[0-9a-f]{32}' -> 'hash' | ';' -> ':'
525525
CONFIG config-env
526526
FILE(environment) Read ${BASEDIR}/OPAM/switch1/.opam-switch/environment in 0.000s
527-
FILE(environment) Read ${BASEDIR}/OPAM/switch1/.opam-switch/last-env/env-hash-0 in 0.000s
527+
FILE(environment) Read ${BASEDIR}/OPAM/.last-env/env-hash-0 in 0.000s
528528
A_VAR='${BASEDIR}/OPAM/switch1/lib': export A_VAR:
529529
### # missing environment file
530530
### rm $OPAMROOT/switch1/.opam-switch/environment
@@ -533,27 +533,27 @@ CONFIG config-env
533533
CONFIG Missing environment file, regenerate it
534534
STATE LOAD-SWITCH-STATE @ switch1
535535
STATE Switch state loaded in 0.000s
536-
FILE(environment) Read ${BASEDIR}/OPAM/switch1/.opam-switch/last-env/env-hash-0 in 0.000s
536+
FILE(environment) Read ${BASEDIR}/OPAM/.last-env/env-hash-0 in 0.000s
537537
A_VAR='${BASEDIR}/OPAM/switch1/lib': export A_VAR:
538538
### opam env --debug-level=-3 | grep "A_VAR\|FILE\\(environment\\)\|CONFIG\|^STATE" | '[0-9a-f]{32}' -> 'hash' | ';' -> ':'
539539
CONFIG config-env
540540
CONFIG Missing environment file, regenerate it
541541
STATE LOAD-SWITCH-STATE @ switch1
542542
STATE Switch state loaded in 0.000s
543543
FILE(environment) Wrote ${BASEDIR}/OPAM/switch1/.opam-switch/environment atomically in 0.000s
544-
FILE(environment) Read ${BASEDIR}/OPAM/switch1/.opam-switch/last-env/env-hash-0 in 0.000s
544+
FILE(environment) Read ${BASEDIR}/OPAM/.last-env/env-hash-0 in 0.000s
545545
A_VAR='${BASEDIR}/OPAM/switch1/lib': export A_VAR:
546546
### # set via OPAMSWITCH
547547
### OPAMSWITCH=switch2 opam env --readonly --debug-level=-3 | grep "A_VAR\|FILE\\(environment\\)\|CONFIG\|^STATE" | '[0-9a-f]{32}' -> 'hash' | ';' -> ':'
548548
CONFIG config-env
549549
FILE(environment) Read ${BASEDIR}/OPAM/switch2/.opam-switch/environment in 0.000s
550-
FILE(environment) Wrote ${BASEDIR}/OPAM/switch2/.opam-switch/last-env/env-hash-0 atomically in 0.000s
551-
FILE(environment) Read ${BASEDIR}/OPAM/switch2/.opam-switch/last-env/env-hash-0 in 0.000s
550+
FILE(environment) Wrote ${BASEDIR}/OPAM/.last-env/env-hash-0 atomically in 0.000s
551+
FILE(environment) Read ${BASEDIR}/OPAM/.last-env/env-hash-0 in 0.000s
552552
A_VAR='${BASEDIR}/OPAM/switch2/lib': export A_VAR:
553553
### OPAMSWITCH=switch2 opam env --debug-level=-3 | grep "A_VAR\|FILE\\(environment\\)\|CONFIG\|^STATE" | '[0-9a-f]{32}' -> 'hash' | ';' -> ':'
554554
CONFIG config-env
555555
FILE(environment) Read ${BASEDIR}/OPAM/switch2/.opam-switch/environment in 0.000s
556-
FILE(environment) Read ${BASEDIR}/OPAM/switch2/.opam-switch/last-env/env-hash-0 in 0.000s
556+
FILE(environment) Read ${BASEDIR}/OPAM/.last-env/env-hash-0 in 0.000s
557557
A_VAR='${BASEDIR}/OPAM/switch2/lib': export A_VAR:
558558
### # entering directory
559559
### mkdir local-sw
@@ -568,13 +568,13 @@ Done.
568568
### sh -c "cd local-sw ; opam env --readonly --debug-level=-3" | grep "A_VAR\|FILE\\(environment\\)\|CONFIG\|^STATE" | '[0-9a-f]{32}' -> 'hash' | "\(\\\\\|/\)_opam\(\\\\|/\)lib" -> '/_opam/lib' | ';' -> ':'
569569
CONFIG config-env
570570
FILE(environment) Read ${BASEDIR}/local-sw/_opam/.opam-switch/environment in 0.000s
571-
FILE(environment) Wrote ${BASEDIR}/local-sw/_opam/.opam-switch/last-env/env-hash-0 atomically in 0.000s
572-
FILE(environment) Read ${BASEDIR}/local-sw/_opam/.opam-switch/last-env/env-hash-0 in 0.000s
571+
FILE(environment) Wrote ${BASEDIR}/OPAM/.last-env/env-hash-0 atomically in 0.000s
572+
FILE(environment) Read ${BASEDIR}/OPAM/.last-env/env-hash-0 in 0.000s
573573
A_VAR='${BASEDIR}/local-sw/_opam/lib': export A_VAR:
574574
### sh -c "cd local-sw ; opam env --debug-level=-3" | grep "A_VAR\|FILE\\(environment\\)\|CONFIG\|^STATE" | '[0-9a-f]{32}' -> 'hash' | "\(\\\\\|/\)_opam\(\\\\|/\)lib" -> '/_opam/lib' | ';' -> ':'
575575
CONFIG config-env
576576
FILE(environment) Read ${BASEDIR}/local-sw/_opam/.opam-switch/environment in 0.000s
577-
FILE(environment) Read ${BASEDIR}/local-sw/_opam/.opam-switch/last-env/env-hash-0 in 0.000s
577+
FILE(environment) Read ${BASEDIR}/OPAM/.last-env/env-hash-0 in 0.000s
578578
A_VAR='${BASEDIR}/local-sw/_opam/lib': export A_VAR:
579579
### # moving a switch
580580
### mv local-sw local-sw.new
@@ -585,8 +585,8 @@ CONFIG Switch has moved from ${BASEDIR}/local-sw/_opam
585585
CONFIG Regenerating environment file
586586
STATE LOAD-SWITCH-STATE @ ${BASEDIR}/local-sw.new
587587
STATE Switch state loaded in 0.000s
588-
FILE(environment) Wrote ${BASEDIR}/local-sw.new/_opam/.opam-switch/last-env/env-hash-0 atomically in 0.000s
589-
FILE(environment) Read ${BASEDIR}/local-sw.new/_opam/.opam-switch/last-env/env-hash-0 in 0.000s
588+
FILE(environment) Wrote ${BASEDIR}/OPAM/.last-env/env-hash-0 atomically in 0.000s
589+
FILE(environment) Read ${BASEDIR}/OPAM/.last-env/env-hash-0 in 0.000s
590590
A_VAR='${BASEDIR}/local-sw.new/_opam/lib': export A_VAR:
591591
### opam env --switch ./local-sw.new --debug-level=-3 | grep "A_VAR\|FILE\\(environment\\)\|CONFIG\|^STATE" | '[0-9a-f]{32}' -> 'hash' | "\(\\\\\|/\)_opam\(\\\\|/\)lib" -> '/_opam/lib' | ';' -> ':'
592592
CONFIG config-env
@@ -596,33 +596,33 @@ CONFIG Regenerating environment file
596596
STATE LOAD-SWITCH-STATE @ ${BASEDIR}/local-sw.new
597597
STATE Switch state loaded in 0.000s
598598
FILE(environment) Wrote ${BASEDIR}/local-sw.new/_opam/.opam-switch/environment atomically in 0.000s
599-
FILE(environment) Read ${BASEDIR}/local-sw.new/_opam/.opam-switch/last-env/env-hash-0 in 0.000s
599+
FILE(environment) Read ${BASEDIR}/OPAM/.last-env/env-hash-0 in 0.000s
600600
A_VAR='${BASEDIR}/local-sw.new/_opam/lib': export A_VAR:
601601
### opam env --switch ./local-sw.new --debug-level=-3 | grep "A_VAR\|FILE\\(environment\\)\|CONFIG\|^STATE" | '[0-9a-f]{32}' -> 'hash' | "\(\\\\\|/\)_opam\(\\\\|/\)lib" -> '/_opam/lib' | ';' -> ':'
602602
CONFIG config-env
603603
FILE(environment) Read ${BASEDIR}/local-sw.new/_opam/.opam-switch/environment in 0.000s
604-
FILE(environment) Read ${BASEDIR}/local-sw.new/_opam/.opam-switch/last-env/env-hash-0 in 0.000s
604+
FILE(environment) Read ${BASEDIR}/OPAM/.last-env/env-hash-0 in 0.000s
605605
A_VAR='${BASEDIR}/local-sw.new/_opam/lib': export A_VAR:
606606
### : opam exec & environment regeneration :
607607
### opam exec --debug-level=-3 -- sh -c "echo $A_VAR" | grep "A_VAR\|FILE\\(environment\\)\|CONFIG\|^STATE" | grep -v PROC | '[0-9a-f]{32}' -> 'hash' | ';' -> ':'
608608
CONFIG config-exec command=sh -c echo $A_VAR
609609
FILE(environment) Read ${BASEDIR}/OPAM/switch1/.opam-switch/environment in 0.000s
610-
FILE(environment) Read ${BASEDIR}/OPAM/switch1/.opam-switch/last-env/env-hash-0 in 0.000s
610+
FILE(environment) Read ${BASEDIR}/OPAM/.last-env/env-hash-0 in 0.000s
611611
### rm $OPAMROOT/switch1/.opam-switch/environment
612612
### opam exec --readonly --debug-level=-3 -- sh -c "echo $A_VAR" | grep "A_VAR\|FILE\\(environment\\)\|CONFIG\|^STATE" | grep -v PROC | '[0-9a-f]{32}' -> 'hash' | ';' -> ':'
613613
CONFIG config-exec command=sh -c echo $A_VAR
614614
CONFIG Missing environment file, regenerate it
615615
STATE LOAD-SWITCH-STATE @ switch1
616616
STATE Switch state loaded in 0.000s
617-
FILE(environment) Read ${BASEDIR}/OPAM/switch1/.opam-switch/last-env/env-hash-0 in 0.000s
617+
FILE(environment) Read ${BASEDIR}/OPAM/.last-env/env-hash-0 in 0.000s
618618
### opam exec --debug-level=-3 -- sh -c "echo $A_VAR" | grep "A_VAR\|FILE\\(environment\\)\|CONFIG\|^STATE" | grep -v PROC | '[0-9a-f]{32}' -> 'hash' | ';' -> ':'
619619
CONFIG config-exec command=sh -c echo $A_VAR
620620
CONFIG Missing environment file, regenerate it
621621
STATE LOAD-SWITCH-STATE @ switch1
622622
STATE Switch state loaded in 0.000s
623623
FILE(environment) Wrote ${BASEDIR}/OPAM/switch1/.opam-switch/environment atomically in 0.000s
624-
FILE(environment) Read ${BASEDIR}/OPAM/switch1/.opam-switch/last-env/env-hash-0 in 0.000s
624+
FILE(environment) Read ${BASEDIR}/OPAM/.last-env/env-hash-0 in 0.000s
625625
### opam exec --debug-level=-3 -- sh -c "echo $A_VAR" | grep "A_VAR\|FILE\\(environment\\)\|CONFIG\|^STATE" | grep -v PROC | '[0-9a-f]{32}' -> 'hash' | ';' -> ':'
626626
CONFIG config-exec command=sh -c echo $A_VAR
627627
FILE(environment) Read ${BASEDIR}/OPAM/switch1/.opam-switch/environment in 0.000s
628-
FILE(environment) Read ${BASEDIR}/OPAM/switch1/.opam-switch/last-env/env-hash-0 in 0.000s
628+
FILE(environment) Read ${BASEDIR}/OPAM/.last-env/env-hash-0 in 0.000s

0 commit comments

Comments
 (0)