Skip to content

Commit 68aae43

Browse files
committed
Revert "Add each_directory to File.rm_rf, closes #15308 (#15311)"
This reverts commit d02e61d. It did not address the original root problem.
1 parent 2019de2 commit 68aae43

4 files changed

Lines changed: 11 additions & 62 deletions

File tree

lib/elixir/lib/file.ex

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,13 +1619,6 @@ defmodule File do
16191619
directories removed in no specific order, `{:error, reason, file}`
16201620
otherwise.
16211621
1622-
## Options
1623-
1624-
* `:each_directory` - (since v1.20.0) a callback invoked for each
1625-
directory before its contents are deleted. The callback receives the
1626-
directory path as a binary. It is useful, for example, to grant write
1627-
permission to a directory before attempting to delete it.
1628-
16291622
## Examples
16301623
16311624
File.rm_rf("samples")
@@ -1637,28 +1630,24 @@ defmodule File do
16371630
File.rm_rf("/tmp")
16381631
#=> {:error, :eperm, "/tmp"}
16391632
"""
1640-
@spec rm_rf(Path.t(), each_directory: (Path.t() -> term)) ::
1641-
{:ok, [binary]} | {:error, posix | :badarg, binary}
1642-
def rm_rf(path, options \\ []) do
1633+
@spec rm_rf(Path.t()) :: {:ok, [binary]} | {:error, posix | :badarg, binary}
1634+
def rm_rf(path) do
16431635
{major, _} = :os.type()
1644-
each_directory = Keyword.get(options, :each_directory, fn _ -> :ok end)
16451636

16461637
path
16471638
|> IO.chardata_to_string()
16481639
|> assert_no_null_byte!("File.rm_rf/1")
1649-
|> do_rm_rf([], major, each_directory)
1640+
|> do_rm_rf([], major)
16501641
end
16511642

1652-
defp do_rm_rf(path, acc, major, each_directory) do
1643+
defp do_rm_rf(path, acc, major) do
16531644
case safe_list_dir(path, major) do
16541645
{:ok, files} when is_list(files) ->
1655-
each_directory.(path)
1656-
16571646
acc =
16581647
Enum.reduce(files, acc, fn file, acc ->
16591648
# In case we can't delete, continue anyway, we might succeed
16601649
# to delete it on Windows due to how they handle symlinks.
1661-
case do_rm_rf(Path.join(path, file), acc, major, each_directory) do
1650+
case do_rm_rf(Path.join(path, file), acc, major) do
16621651
{:ok, acc} -> acc
16631652
{:error, _, _} -> acc
16641653
end
@@ -1734,7 +1723,7 @@ defmodule File do
17341723
end
17351724

17361725
@doc """
1737-
Same as `rm_rf/2` but raises a `File.Error` exception in case of failures,
1726+
Same as `rm_rf/1` but raises a `File.Error` exception in case of failures,
17381727
otherwise returns the list of files or directories removed.
17391728
17401729
## Examples
@@ -1748,9 +1737,9 @@ defmodule File do
17481737
File.rm_rf!("/tmp")
17491738
** (File.Error) could not remove files and directories recursively from "/tmp": not owner
17501739
"""
1751-
@spec rm_rf!(Path.t(), each_directory: (Path.t() -> term)) :: [binary]
1752-
def rm_rf!(path, options \\ []) do
1753-
case rm_rf(path, options) do
1740+
@spec rm_rf!(Path.t()) :: [binary]
1741+
def rm_rf!(path) do
1742+
case rm_rf(path) do
17541743
{:ok, files} ->
17551744
files
17561745

lib/elixir/test/elixir/file_test.exs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,46 +1473,6 @@ defmodule FileTest do
14731473
assert File.rm_rf(dir) == {:ok, [dir, subdir]}
14741474
end
14751475

1476-
test "rm_rf with each_directory callback" do
1477-
fixture = tmp_path("tmp")
1478-
File.mkdir(fixture)
1479-
File.cp_r!(fixture_path("cp_r"), fixture)
1480-
me = self()
1481-
1482-
{:ok, files} =
1483-
File.rm_rf(fixture, each_directory: fn path -> send(me, {:dir, path}) end)
1484-
1485-
assert length(files) == 7
1486-
1487-
assert_received {:dir, ^fixture}
1488-
assert_received {:dir, _}
1489-
assert_received {:dir, _}
1490-
end
1491-
1492-
@tag :unix
1493-
test "rm_rf with each_directory callback for read-only dir" do
1494-
dir = tmp_path("tmp")
1495-
subdir = Path.join(dir, "read-only")
1496-
File.mkdir_p!(subdir)
1497-
File.write!(Path.join(subdir, "file.txt"), "hello")
1498-
File.chmod!(subdir, 0o444)
1499-
1500-
me = self()
1501-
1502-
{:ok, files} =
1503-
File.rm_rf(dir,
1504-
each_directory: fn path ->
1505-
send(me, {:dir, path})
1506-
File.chmod(path, 0o755)
1507-
end
1508-
)
1509-
1510-
assert length(files) == 3
1511-
refute File.exists?(dir)
1512-
assert_received {:dir, ^dir}
1513-
assert_received {:dir, ^subdir}
1514-
end
1515-
15161476
test "rm_rf with unknown" do
15171477
fixture = tmp_path("tmp.unknown")
15181478
assert File.rm_rf(fixture) == {:ok, []}

lib/mix/test/mix/release_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ defmodule Mix.ReleaseTest do
2727
end
2828

2929
setup do
30-
File.rm_rf!(tmp_path("mix_release"), each_directory: &File.chmod(&1, 0o755))
30+
File.rm_rf!(tmp_path("mix_release"))
3131
File.mkdir_p!(tmp_path("mix_release"))
3232
:ok
3333
end

lib/mix/test/test_helper.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ defmodule MixTest.Case do
175175
dest = tmp_path(String.replace(tmp, ":", "_"))
176176
flag = String.to_charlist(tmp_path())
177177

178-
File.rm_rf!(dest, each_directory: &File.chmod(&1, 0o755))
178+
File.rm_rf!(dest)
179179
File.mkdir_p!(dest)
180180
File.cp_r!(src, dest)
181181

0 commit comments

Comments
 (0)