Skip to content

Commit db9e332

Browse files
Copy symbolic links in the assets as actual files
1 parent 792128e commit db9e332

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/ex_doc/formatter/html.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ defmodule ExDoc.Formatter.HTML do
306306

307307
is_binary(dir_or_files) and File.dir?(dir_or_files) ->
308308
dir_or_files
309-
|> File.cp_r!(target_dir)
309+
|> File.cp_r!(target_dir, dereference_symlinks: true)
310310
|> Enum.map(&Path.relative_to(&1, output))
311311

312312
is_binary(dir_or_files) ->

test/ex_doc/formatter/html_test.exs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,4 +816,24 @@ defmodule ExDoc.Formatter.HTMLTest do
816816
after
817817
File.rm_rf!("test/tmp/html_assets")
818818
end
819+
820+
test "symbolic links in the assets should be resolved and copied as actual files",
821+
%{tmp_dir: tmp_dir} = context do
822+
File.mkdir_p!("test/tmp/html_assets/hello")
823+
File.touch!("test/tmp/html_assets/hello/world")
824+
825+
File.ln_s("world", "test/tmp/html_assets/hello/symlink_world")
826+
827+
generate_docs(
828+
doc_config(context,
829+
assets: %{"test/tmp/html_assets" => "assets"}
830+
)
831+
)
832+
833+
assert File.regular?(tmp_dir <> "/html/assets/hello/world")
834+
assert File.exists?(tmp_dir <> "/html/assets/hello/symlink_world")
835+
assert File.read_link(tmp_dir <> "/html/assets/hello/symlink_world") == {:error, :einval}
836+
after
837+
File.rm_rf!("test/tmp/html_assets")
838+
end
819839
end

0 commit comments

Comments
 (0)