Skip to content

Commit 263df0a

Browse files
committed
Ensure extracted tarball files are readable
Tarballs may contain files with restrictive permissions that prevent reading after extraction. Fix permissions on unreadable files.
1 parent 58c787b commit 263df0a

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

lib/diff/hex/hex.ex

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,29 @@ defmodule Diff.Hex do
5757
def unpack_tarball(tarball_path, output_path) do
5858
with {:ok, _} <-
5959
:hex_tarball.unpack({:file, to_charlist(tarball_path)}, to_charlist(output_path)) do
60+
ensure_readable(output_path)
6061
:ok
6162
end
6263
end
6364

65+
defp ensure_readable(dir) do
66+
dir
67+
|> Path.join("**")
68+
|> Path.wildcard(match_dot: true)
69+
|> Enum.each(fn path ->
70+
case File.stat(path) do
71+
{:ok, %{type: :directory, access: access}} when access in [:none, :write] ->
72+
File.chmod(path, 0o755)
73+
74+
{:ok, %{type: :regular, access: access}} when access in [:none, :write] ->
75+
File.chmod(path, 0o644)
76+
77+
_ ->
78+
:ok
79+
end
80+
end)
81+
end
82+
6483
def get_checksums(package, versions) do
6584
with {:ok, {200, _, releases}} <- :hex_repo.get_package(config(), package) do
6685
checksums =

0 commit comments

Comments
 (0)