From b446c097f4b33bae65502eac8f3aae8426df83f6 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 15 May 2019 13:49:20 +0800 Subject: [PATCH] Do not allow actions to create dirs outside of build dir Signed-off-by: Rudi Grinberg --- CHANGES.md | 6 +++++- src/action_exec.ml | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 828240cce389..c3cf0a5e9246 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -30,7 +30,7 @@ unreleased - Add a 'cookies' option to ppx_rewriter/deriver flags in library stanzas (#2106, @mlasson @diml). This allow to specify cookie requests from - variables expanded at each invocation of the preprocessor. + variables expanded at each invocation of the preprocessor. - Add more opam metadata and use it to generate `.opam` files. In particular, a `package` field has been added to specify package specific information. @@ -65,6 +65,10 @@ unreleased - Make `dune subst` add a `(version ...)` field to the `dune-project` file (#2148, @diml) +- Fine tune directory creation in dune. Dune will never complain if the + directory exists but forbid the user from creating source or external + directories with the `mkdir` action. (#2159, fix #2158, @rgrinberg) + 1.9.3 (06/05/2019) ------------------ diff --git a/src/action_exec.ml b/src/action_exec.ml index 0c591e1fa02a..23c3d4d17ba8 100644 --- a/src/action_exec.ml +++ b/src/action_exec.ml @@ -108,7 +108,15 @@ let rec exec t ~ectx ~dir ~env ~stdout_to ~stderr_to = Path.rm_rf path; Fiber.return () | Mkdir path -> - Path.mkdir_p path; + begin + if Path.is_in_build_dir path then + Path.mkdir_p path + else if Path.exists path then + () + else + die "action attempted to create %a outside of the build directory" + Path.pp path + end; Fiber.return () | Digest_files paths -> let s =