Skip to content

Commit

Permalink
Error on "dune init" if dir exists named "dune" (#6705)
Browse files Browse the repository at this point in the history
When running `dune init (exe|lib|test)` in a directory which contains a
directory named "dune", prior to this change, the error would be:
Error: Is a directory

Following this change, the error is now:
Error: "/path/to/dune" already exists and is a directory

Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
  • Loading branch information
gridbugs authored Dec 15, 2022
1 parent 4a9afe1 commit ead16cd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Unreleased
----------

- Report an error if `dune init ...` would create a "dune" file in a location
which already contains a "dune" directory (#6705, @gridbugs)

- Fix the parsing of alerts. They will now show up in diagnostics correctly.
(#6678, @rginberg)

Expand Down
5 changes: 5 additions & 0 deletions bin/dune_init.ml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ module File = struct
let full_path = Path.relative path name in
let content =
if not (Path.exists full_path) then []
else if Path.is_directory full_path then
User_error.raise
[ Pp.textf "\"%s\" already exists and is a directory"
(Path.to_absolute_filename full_path)
]
else
match Io.with_lexbuf_from_file ~f:Dune_lang.Format.parse full_path with
| Dune_lang.Format.Sexps content -> content
Expand Down
22 changes: 22 additions & 0 deletions test/blackbox-tests/test-cases/init-error-if-dune-is-directory.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Report an error if `dune init ...` would create a "dune" file in a location
which already has a "dune" directory.

$ mkdir dune

$ dune init exe foo
Error:
"$TESTCASE_ROOT/dune"
already exists and is a directory
[1]

$ dune init lib foo
Error:
"$TESTCASE_ROOT/dune"
already exists and is a directory
[1]

$ dune init test foo
Error:
"$TESTCASE_ROOT/dune"
already exists and is a directory
[1]

0 comments on commit ead16cd

Please sign in to comment.