Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Run sandbox checker in temp directory #4787

Merged
merged 2 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Run sandbox checker in temp directory
The sandbox will attempt to mount the current working directory which
may fail (and which we don't necessarily have any business doing).
  • Loading branch information
dra27 committed Aug 6, 2021
commit ffba047677ad4abf2dd0c20187b5048f646315bb
2 changes: 1 addition & 1 deletion master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ users)
*

## Init
*
* Run the sandbox check in the temporary directory [#4787 @dra27 - fix #4783]

## Config report
*
Expand Down
4 changes: 3 additions & 1 deletion src/client/opamAuxCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,9 @@ let check_and_revert_sandboxing root config =
Array.append [| "OPAM_SWITCH_PREFIX=/dev/null" |] (Unix.environment ())
in
try
OpamSystem.read_command_output ~env ~allow_stdin:false (cmd @ test_cmd)
(* Don't assume that we can mount the CWD *)
OpamSystem.in_tmp_dir @@ fun () ->
OpamSystem.read_command_output ~env ~allow_stdin:false (cmd @ test_cmd)
= ["SUCCESS"]
with e ->
(OpamConsole.error "Sandboxing is not working on your platform%s:\n%s"
Expand Down
4 changes: 4 additions & 0 deletions src/core/opamSystem.ml
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ let with_tmp_dir fn =
OpamStd.Exn.finalise e @@ fun () ->
remove_dir dir

let in_tmp_dir fn =
with_tmp_dir @@ fun dir ->
in_dir dir fn

let with_tmp_dir_job fjob =
let dir = mk_temp_dir () in
mkdir dir;
Expand Down
6 changes: 5 additions & 1 deletion src/core/opamSystem.mli
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ exception Internal_error of string
(** Raise [Internal_error] *)
val internal_error: ('a, unit, string, 'b) format4 -> 'a

(** [with_tmp_dir fn] executes [fn] in a tempory directory *)
(** [with_tmp_dir fn] executes [fn] creates a temporary directory and
passes its name to [fn]. The directory is alwasy removed on completion. *)
val with_tmp_dir: (string -> 'a) -> 'a

(** [in_tmp_dir fn] executes [fn] in a temporary directory. *)
val in_tmp_dir: (unit -> 'a) -> 'a
rjbou marked this conversation as resolved.
Show resolved Hide resolved

(** Runs a job with a temp dir that is cleaned up afterwards *)
val with_tmp_dir_job: (string -> 'a OpamProcess.job) -> 'a OpamProcess.job

Expand Down