Skip to content

Commit 4ece4a7

Browse files
committed
Revert "Safety check before running File.rm_rf! in doc gen (#1707)"
Unfortunately this is generating ExDoc files with mixed entries. This reverts commit 9766ed7.
1 parent be88652 commit 4ece4a7

File tree

8 files changed

+7
-155
lines changed

8 files changed

+7
-155
lines changed

lib/ex_doc/formatter/epub.ex

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,9 @@ defmodule ExDoc.Formatter.EPUB do
1010
"""
1111
@spec run([ExDoc.ModuleNode.t()], [ExDoc.ModuleNode.t()], ExDoc.Config.t()) :: String.t()
1212
def run(project_nodes, filtered_modules, config) when is_map(config) do
13-
parent = config.output
1413
config = normalize_config(config)
15-
16-
HTML.setup_output(
17-
parent,
18-
&cleanup_output_dir(&1, config),
19-
&create_output_dir(&1, config)
20-
)
14+
File.rm_rf!(config.output)
15+
File.mkdir_p!(Path.join(config.output, "OEBPS"))
2116

2217
project_nodes =
2318
HTML.render_all(project_nodes, filtered_modules, ".xhtml", config, highlight_tag: "samp")
@@ -50,16 +45,6 @@ defmodule ExDoc.Formatter.EPUB do
5045
Path.relative_to_cwd(epub)
5146
end
5247

53-
defp create_output_dir(root, config) do
54-
File.mkdir_p!(Path.join(config.output, "OEBPS"))
55-
File.touch!(Path.join(root, ".build"))
56-
end
57-
58-
defp cleanup_output_dir(docs_root, config) do
59-
File.rm_rf!(config.output)
60-
create_output_dir(docs_root, config)
61-
end
62-
6348
defp normalize_config(config) do
6449
output =
6550
config.output

lib/ex_doc/formatter/html.ex

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ defmodule ExDoc.Formatter.HTML do
1616
config = %{config | output: Path.expand(config.output)}
1717

1818
build = Path.join(config.output, ".build")
19-
setup_output(config.output, &cleanup_output_dir(&1, config), &create_output_dir(&1, config))
19+
output_setup(build, config)
2020

2121
project_nodes = render_all(project_nodes, filtered_modules, ".html", config, [])
2222
extras = build_extras(config, ".html")
@@ -148,53 +148,18 @@ defmodule ExDoc.Formatter.HTML do
148148
|> ExDoc.DocAST.highlight(language, opts)
149149
end
150150

151-
def setup_output(root, cleanup, create) do
152-
safety_path = Path.join(root, ".build")
153-
154-
cond do
155-
File.exists?(safety_path) and File.exists?(root) ->
156-
cleanup.(root)
157-
158-
not File.exists?(root) ->
159-
create.(root)
160-
161-
File.ls!(root) == [] ->
162-
add_safety_file(root)
163-
:ok
164-
165-
true ->
166-
IO.warn(
167-
"ExDoc is outputting to an existing directory. " <>
168-
"Beware documentation output may be mixed with other entries"
169-
)
170-
171-
create.(root)
172-
end
173-
end
174-
175-
defp create_output_dir(root, _config) do
176-
File.mkdir_p!(root)
177-
add_safety_file(root)
178-
end
179-
180-
defp add_safety_file(root) do
181-
File.touch!(Path.join(root, ".build"))
182-
end
183-
184-
defp cleanup_output_dir(docs_root, config) do
185-
build = Path.join(docs_root, ".build")
186-
151+
defp output_setup(build, config) do
187152
if File.exists?(build) do
188153
build
189154
|> File.read!()
190155
|> String.split("\n", trim: true)
191-
|> Enum.map(&Path.join(docs_root, &1))
156+
|> Enum.map(&Path.join(config.output, &1))
192157
|> Enum.each(&File.rm/1)
193158

194159
File.rm(build)
195160
else
196-
File.rm_rf!(docs_root)
197-
create_output_dir(docs_root, config)
161+
File.rm_rf!(config.output)
162+
File.mkdir_p!(config.output)
198163
end
199164
end
200165

test/ex_doc/formatter/epub_io_test.exs

Lines changed: 0 additions & 38 deletions
This file was deleted.

test/ex_doc/formatter/html/erlang_test.exs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ defmodule ExDoc.Formatter.HTML.ErlangTest do
55
@moduletag :otp_eep48
66
@moduletag :tmp_dir
77

8-
setup %{tmp_dir: tmp_dir} do
9-
output = tmp_dir <> "/doc"
10-
File.mkdir!(output)
11-
File.touch!("#{output}/.build")
12-
end
13-
148
test "smoke test", c do
159
erlc(c, :foo, ~S"""
1610
%% @doc

test/ex_doc/formatter/html/search_data_test.exs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ defmodule ExDoc.Formatter.HTML.SearchDataTest do
44

55
@moduletag :tmp_dir
66

7-
setup %{tmp_dir: tmp_dir} do
8-
output = tmp_dir <> "/doc"
9-
File.mkdir!(output)
10-
File.touch!("#{output}/.build")
11-
end
12-
137
test "Elixir module", c do
148
modules =
159
elixirc(c, ~S'''

test/ex_doc/formatter/html_io_test.exs

Lines changed: 0 additions & 38 deletions
This file was deleted.

test/ex_doc/formatter/html_test.exs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ defmodule ExDoc.Formatter.HTMLTest do
66

77
@moduletag :tmp_dir
88

9-
setup %{tmp_dir: tmp_dir} do
10-
output = tmp_dir <> "/html"
11-
File.mkdir_p!(output)
12-
File.touch!(output <> "/.build")
13-
end
14-
159
defp read_wildcard!(path) do
1610
[file] = Path.wildcard(path)
1711
File.read!(file)

test/test_helper.exs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ defmodule TestHelper do
2222
def elixirc(context, filename \\ "nofile", code) do
2323
dir = context.tmp_dir
2424

25-
output_dir = context.tmp_dir <> "/html"
26-
File.mkdir_p!(output_dir)
27-
File.write!(output_dir <> "/.build", "")
28-
2925
src_path = Path.join([dir, filename])
3026
src_path |> Path.dirname() |> File.mkdir_p!()
3127
File.write!(src_path, code)

0 commit comments

Comments
 (0)