From 418a1b586cec78df237fcdc4cef9bffc9c2f6fa1 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Wed, 13 May 2020 08:14:52 -0700 Subject: [PATCH] [opam] do not crash when the switch does not exist Summary: Fixes #1258. Reviewed By: martintrojer Differential Revision: D21548073 fbshipit-source-id: ddb994910 --- scripts/opam_utils.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/opam_utils.sh b/scripts/opam_utils.sh index 02d638ad1..2e4ec1eeb 100644 --- a/scripts/opam_utils.sh +++ b/scripts/opam_utils.sh @@ -58,8 +58,11 @@ opam_switch_create_if_needed () { break fi done + opam_root="${OPAMROOT:-}" if [ "$switch_exists" = "no" ]; then - rm -rf "$OPAMROOT/$switch" + if [ -n "$opam_root" ]; then + rm -rf "$opam_root/$switch" || true + fi opam switch create "$switch" "$compiler" fi }