Skip to content

Commit ead16cd

Browse files
authored
Error on "dune init" if dir exists named "dune" (#6705)
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>
1 parent 4a9afe1 commit ead16cd

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Unreleased
22
----------
33

4+
- Report an error if `dune init ...` would create a "dune" file in a location
5+
which already contains a "dune" directory (#6705, @gridbugs)
6+
47
- Fix the parsing of alerts. They will now show up in diagnostics correctly.
58
(#6678, @rginberg)
69

bin/dune_init.ml

+5
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ module File = struct
118118
let full_path = Path.relative path name in
119119
let content =
120120
if not (Path.exists full_path) then []
121+
else if Path.is_directory full_path then
122+
User_error.raise
123+
[ Pp.textf "\"%s\" already exists and is a directory"
124+
(Path.to_absolute_filename full_path)
125+
]
121126
else
122127
match Io.with_lexbuf_from_file ~f:Dune_lang.Format.parse full_path with
123128
| Dune_lang.Format.Sexps content -> content
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Report an error if `dune init ...` would create a "dune" file in a location
2+
which already has a "dune" directory.
3+
4+
$ mkdir dune
5+
6+
$ dune init exe foo
7+
Error:
8+
"$TESTCASE_ROOT/dune"
9+
already exists and is a directory
10+
[1]
11+
12+
$ dune init lib foo
13+
Error:
14+
"$TESTCASE_ROOT/dune"
15+
already exists and is a directory
16+
[1]
17+
18+
$ dune init test foo
19+
Error:
20+
"$TESTCASE_ROOT/dune"
21+
already exists and is a directory
22+
[1]

0 commit comments

Comments
 (0)