File.mkdir_p -> Pleroma.Backports.mkdir_p
This commit is contained in:
parent
00d536d9e2
commit
a69e417020
19 changed files with 32 additions and 32 deletions
|
|
@ -271,7 +271,7 @@ defmodule Mix.Tasks.Pleroma.Instance do
|
||||||
[config_dir, psql_dir, static_dir, uploads_dir]
|
[config_dir, psql_dir, static_dir, uploads_dir]
|
||||||
|> Enum.reject(&File.exists?/1)
|
|> Enum.reject(&File.exists?/1)
|
||||||
|> Enum.each(fn dir ->
|
|> Enum.each(fn dir ->
|
||||||
File.mkdir_p!(dir)
|
Pleroma.Backports.mkdir_p!(dir)
|
||||||
File.chmod!(dir, 0o700)
|
File.chmod!(dir, 0o700)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ defmodule Mix.Tasks.Pleroma.RobotsTxt do
|
||||||
static_dir = Pleroma.Config.get([:instance, :static_dir], "instance/static/")
|
static_dir = Pleroma.Config.get([:instance, :static_dir], "instance/static/")
|
||||||
|
|
||||||
if !File.exists?(static_dir) do
|
if !File.exists?(static_dir) do
|
||||||
File.mkdir_p!(static_dir)
|
Pleroma.Backports.mkdir_p!(static_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
robots_txt_path = Path.join(static_dir, "robots.txt")
|
robots_txt_path = Path.join(static_dir, "robots.txt")
|
||||||
|
|
|
||||||
|
|
@ -488,7 +488,7 @@ defmodule Pleroma.Emoji.Pack do
|
||||||
with true <- String.contains?(file_path, "/"),
|
with true <- String.contains?(file_path, "/"),
|
||||||
path <- Path.dirname(file_path),
|
path <- Path.dirname(file_path),
|
||||||
false <- File.exists?(path) do
|
false <- File.exists?(path) do
|
||||||
File.mkdir_p!(path)
|
Pleroma.Backports.mkdir_p!(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -536,7 +536,7 @@ defmodule Pleroma.Emoji.Pack do
|
||||||
emoji_path = emoji_path()
|
emoji_path = emoji_path()
|
||||||
# Create the directory first if it does not exist. This is probably the first request made
|
# Create the directory first if it does not exist. This is probably the first request made
|
||||||
# with the API so it should be sufficient
|
# with the API so it should be sufficient
|
||||||
with {:create_dir, :ok} <- {:create_dir, File.mkdir_p(emoji_path)},
|
with {:create_dir, :ok} <- {:create_dir, Pleroma.Backports.mkdir_p(emoji_path)},
|
||||||
{:ls, {:ok, results}} <- {:ls, File.ls(emoji_path)} do
|
{:ls, {:ok, results}} <- {:ls, File.ls(emoji_path)} do
|
||||||
{:ok, Enum.sort(results)}
|
{:ok, Enum.sort(results)}
|
||||||
else
|
else
|
||||||
|
|
@ -561,7 +561,7 @@ defmodule Pleroma.Emoji.Pack do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp unzip(archive, pack_info, remote_pack, local_pack) do
|
defp unzip(archive, pack_info, remote_pack, local_pack) do
|
||||||
with :ok <- File.mkdir_p!(local_pack.path) do
|
with :ok <- Pleroma.Backports.mkdir_p!(local_pack.path) do
|
||||||
files = Enum.map(remote_pack["files"], fn {_, path} -> path end)
|
files = Enum.map(remote_pack["files"], fn {_, path} -> path end)
|
||||||
# Fallback cannot contain a pack.json file
|
# Fallback cannot contain a pack.json file
|
||||||
files = if pack_info[:fallback], do: files, else: ["pack.json" | files]
|
files = if pack_info[:fallback], do: files, else: ["pack.json" | files]
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ defmodule Pleroma.Frontend do
|
||||||
|
|
||||||
def unzip(zip, dest) do
|
def unzip(zip, dest) do
|
||||||
File.rm_rf!(dest)
|
File.rm_rf!(dest)
|
||||||
File.mkdir_p!(dest)
|
Pleroma.Backports.mkdir_p!(dest)
|
||||||
|
|
||||||
case Pleroma.SafeZip.unzip_data(zip, dest) do
|
case Pleroma.SafeZip.unzip_data(zip, dest) do
|
||||||
{:ok, _} -> :ok
|
{:ok, _} -> :ok
|
||||||
|
|
@ -90,7 +90,7 @@ defmodule Pleroma.Frontend do
|
||||||
defp install_frontend(frontend_info, source, dest) do
|
defp install_frontend(frontend_info, source, dest) do
|
||||||
from = frontend_info["build_dir"] || "dist"
|
from = frontend_info["build_dir"] || "dist"
|
||||||
File.rm_rf!(dest)
|
File.rm_rf!(dest)
|
||||||
File.mkdir_p!(dest)
|
Pleroma.Backports.mkdir_p!(dest)
|
||||||
File.cp_r!(Path.join([source, from]), dest)
|
File.cp_r!(Path.join([source, from]), dest)
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ defmodule Pleroma.Uploaders.Local do
|
||||||
|
|
||||||
[file | folders] ->
|
[file | folders] ->
|
||||||
path = Path.join([upload_path()] ++ Enum.reverse(folders))
|
path = Path.join([upload_path()] ++ Enum.reverse(folders))
|
||||||
File.mkdir_p!(path)
|
Pleroma.Backports.mkdir_p!(path)
|
||||||
{path, file}
|
{path, file}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ defmodule Pleroma.User.Backup do
|
||||||
backup = Repo.preload(backup, :user)
|
backup = Repo.preload(backup, :user)
|
||||||
tempfile = Path.join([backup.tempdir, backup.file_name])
|
tempfile = Path.join([backup.tempdir, backup.file_name])
|
||||||
|
|
||||||
with {_, :ok} <- {:mkdir, File.mkdir_p(backup.tempdir)},
|
with {_, :ok} <- {:mkdir, Pleroma.Backports.mkdir_p(backup.tempdir)},
|
||||||
{_, :ok} <- {:actor, actor(backup.tempdir, backup.user)},
|
{_, :ok} <- {:actor, actor(backup.tempdir, backup.user)},
|
||||||
{_, :ok} <- {:statuses, statuses(backup.tempdir, backup.user)},
|
{_, :ok} <- {:statuses, statuses(backup.tempdir, backup.user)},
|
||||||
{_, :ok} <- {:likes, likes(backup.tempdir, backup.user)},
|
{_, :ok} <- {:likes, likes(backup.tempdir, backup.user)},
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy do
|
||||||
Path.join(Config.get([:instance, :static_dir]), "emoji/stolen")
|
Path.join(Config.get([:instance, :static_dir]), "emoji/stolen")
|
||||||
)
|
)
|
||||||
|
|
||||||
File.mkdir_p(emoji_dir_path)
|
Pleroma.Backports.mkdir_p(emoji_dir_path)
|
||||||
|
|
||||||
new_emojis =
|
new_emojis =
|
||||||
foreign_emojis
|
foreign_emojis
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ defmodule Pleroma.Web.InstanceDocument do
|
||||||
|
|
||||||
defp put_file(origin_path, destination_path) do
|
defp put_file(origin_path, destination_path) do
|
||||||
with destination <- instance_static_dir(destination_path),
|
with destination <- instance_static_dir(destination_path),
|
||||||
{_, :ok} <- {:mkdir_p, File.mkdir_p(Path.dirname(destination))},
|
{_, :ok} <- {:mkdir_p, Pleroma.Backports.mkdir_p(Path.dirname(destination))},
|
||||||
{_, {:ok, _}} <- {:copy, File.copy(origin_path, destination)} do
|
{_, {:ok, _}} <- {:copy, File.copy(origin_path, destination)} do
|
||||||
:ok
|
:ok
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ defmodule Mix.Tasks.Pleroma.FrontendTest do
|
||||||
@dir "test/frontend_static_test"
|
@dir "test/frontend_static_test"
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
File.mkdir_p!(@dir)
|
Pleroma.Backports.mkdir_p!(@dir)
|
||||||
clear_config([:instance, :static_dir], @dir)
|
clear_config([:instance, :static_dir], @dir)
|
||||||
|
|
||||||
on_exit(fn ->
|
on_exit(fn ->
|
||||||
|
|
@ -50,7 +50,7 @@ defmodule Mix.Tasks.Pleroma.FrontendTest do
|
||||||
|
|
||||||
folder = Path.join([@dir, "frontends", "pleroma", "fantasy"])
|
folder = Path.join([@dir, "frontends", "pleroma", "fantasy"])
|
||||||
previously_existing = Path.join([folder, "temp"])
|
previously_existing = Path.join([folder, "temp"])
|
||||||
File.mkdir_p!(folder)
|
Pleroma.Backports.mkdir_p!(folder)
|
||||||
File.write!(previously_existing, "yey")
|
File.write!(previously_existing, "yey")
|
||||||
assert File.exists?(previously_existing)
|
assert File.exists?(previously_existing)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ defmodule Mix.Tasks.Pleroma.InstanceTest do
|
||||||
use Pleroma.DataCase
|
use Pleroma.DataCase
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
File.mkdir_p!(tmp_path())
|
Pleroma.Backports.mkdir_p!(tmp_path())
|
||||||
|
|
||||||
on_exit(fn ->
|
on_exit(fn ->
|
||||||
File.rm_rf(tmp_path())
|
File.rm_rf(tmp_path())
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ defmodule Mix.Tasks.Pleroma.UploadsTest do
|
||||||
upload_dir = Config.get([Pleroma.Uploaders.Local, :uploads])
|
upload_dir = Config.get([Pleroma.Uploaders.Local, :uploads])
|
||||||
|
|
||||||
if not File.exists?(upload_dir) || File.ls!(upload_dir) == [] do
|
if not File.exists?(upload_dir) || File.ls!(upload_dir) == [] do
|
||||||
File.mkdir_p(upload_dir)
|
Pleroma.Backports.mkdir_p(upload_dir)
|
||||||
|
|
||||||
Path.join([upload_dir, "file.txt"])
|
Path.join([upload_dir, "file.txt"])
|
||||||
|> File.touch()
|
|> File.touch()
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ defmodule Pleroma.Emoji.PackTest do
|
||||||
test "skips existing emojis when adding from zip file", %{pack: pack} do
|
test "skips existing emojis when adding from zip file", %{pack: pack} do
|
||||||
# First, let's create a test pack with a "bear" emoji
|
# First, let's create a test pack with a "bear" emoji
|
||||||
test_pack_path = Path.join(@emoji_path, "test_bear_pack")
|
test_pack_path = Path.join(@emoji_path, "test_bear_pack")
|
||||||
File.mkdir_p(test_pack_path)
|
Pleroma.Backports.mkdir_p(test_pack_path)
|
||||||
|
|
||||||
# Create a pack.json file
|
# Create a pack.json file
|
||||||
File.write!(Path.join(test_pack_path, "pack.json"), """
|
File.write!(Path.join(test_pack_path, "pack.json"), """
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ defmodule Pleroma.FrontendTest do
|
||||||
@dir "test/frontend_static_test"
|
@dir "test/frontend_static_test"
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
File.mkdir_p!(@dir)
|
Pleroma.Backports.mkdir_p!(@dir)
|
||||||
clear_config([:instance, :static_dir], @dir)
|
clear_config([:instance, :static_dir], @dir)
|
||||||
|
|
||||||
on_exit(fn ->
|
on_exit(fn ->
|
||||||
|
|
@ -46,7 +46,7 @@ defmodule Pleroma.FrontendTest do
|
||||||
|
|
||||||
folder = Path.join([@dir, "frontends", "pleroma", "fantasy"])
|
folder = Path.join([@dir, "frontends", "pleroma", "fantasy"])
|
||||||
previously_existing = Path.join([folder, "temp"])
|
previously_existing = Path.join([folder, "temp"])
|
||||||
File.mkdir_p!(folder)
|
Pleroma.Backports.mkdir_p!(folder)
|
||||||
File.write!(previously_existing, "yey")
|
File.write!(previously_existing, "yey")
|
||||||
assert File.exists?(previously_existing)
|
assert File.exists?(previously_existing)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ defmodule Pleroma.ObjectTest do
|
||||||
|
|
||||||
uploads_dir = Pleroma.Config.get!([Pleroma.Uploaders.Local, :uploads])
|
uploads_dir = Pleroma.Config.get!([Pleroma.Uploaders.Local, :uploads])
|
||||||
|
|
||||||
File.mkdir_p!(uploads_dir)
|
Pleroma.Backports.mkdir_p!(uploads_dir)
|
||||||
|
|
||||||
file = %Plug.Upload{
|
file = %Plug.Upload{
|
||||||
content_type: "image/jpeg",
|
content_type: "image/jpeg",
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,12 @@ defmodule Pleroma.SafeZipTest do
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
# Ensure tmp directory exists
|
# Ensure tmp directory exists
|
||||||
File.mkdir_p!(@tmp_dir)
|
Pleroma.Backports.mkdir_p!(@tmp_dir)
|
||||||
|
|
||||||
on_exit(fn ->
|
on_exit(fn ->
|
||||||
# Clean up any files created during tests
|
# Clean up any files created during tests
|
||||||
File.rm_rf!(@tmp_dir)
|
File.rm_rf!(@tmp_dir)
|
||||||
File.mkdir_p!(@tmp_dir)
|
Pleroma.Backports.mkdir_p!(@tmp_dir)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
|
|
@ -89,7 +89,7 @@ defmodule Pleroma.SafeZipTest do
|
||||||
# For this test, we'll manually check if the file exists in the archive
|
# For this test, we'll manually check if the file exists in the archive
|
||||||
# by extracting it and verifying it exists
|
# by extracting it and verifying it exists
|
||||||
extract_dir = Path.join(@tmp_dir, "extract_check")
|
extract_dir = Path.join(@tmp_dir, "extract_check")
|
||||||
File.mkdir_p!(extract_dir)
|
Pleroma.Backports.mkdir_p!(extract_dir)
|
||||||
{:ok, files} = SafeZip.unzip_file(zip_path, extract_dir)
|
{:ok, files} = SafeZip.unzip_file(zip_path, extract_dir)
|
||||||
|
|
||||||
# Verify the root file was extracted
|
# Verify the root file was extracted
|
||||||
|
|
@ -145,7 +145,7 @@ defmodule Pleroma.SafeZipTest do
|
||||||
test "can create zip with directories" do
|
test "can create zip with directories" do
|
||||||
# Create a directory structure
|
# Create a directory structure
|
||||||
dir_path = Path.join(@tmp_dir, "test_dir")
|
dir_path = Path.join(@tmp_dir, "test_dir")
|
||||||
File.mkdir_p!(dir_path)
|
Pleroma.Backports.mkdir_p!(dir_path)
|
||||||
|
|
||||||
file_in_dir_path = Path.join(dir_path, "file_in_dir.txt")
|
file_in_dir_path = Path.join(dir_path, "file_in_dir.txt")
|
||||||
File.write!(file_in_dir_path, "file in directory")
|
File.write!(file_in_dir_path, "file in directory")
|
||||||
|
|
@ -428,7 +428,7 @@ defmodule Pleroma.SafeZipTest do
|
||||||
|
|
||||||
# Create a directory and a file in it
|
# Create a directory and a file in it
|
||||||
dir_path = Path.join(@tmp_dir, "file_in_dir")
|
dir_path = Path.join(@tmp_dir, "file_in_dir")
|
||||||
File.mkdir_p!(dir_path)
|
Pleroma.Backports.mkdir_p!(dir_path)
|
||||||
|
|
||||||
file_in_dir_path = Path.join(dir_path, "test_file.txt")
|
file_in_dir_path = Path.join(dir_path, "test_file.txt")
|
||||||
File.write!(file_in_dir_path, "file in directory content")
|
File.write!(file_in_dir_path, "file in directory content")
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ defmodule Pleroma.Web.AdminAPI.FrontendControllerTest do
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
clear_config([:instance, :static_dir], @dir)
|
clear_config([:instance, :static_dir], @dir)
|
||||||
File.mkdir_p!(Pleroma.Frontend.dir())
|
Pleroma.Backports.mkdir_p!(Pleroma.Frontend.dir())
|
||||||
|
|
||||||
on_exit(fn ->
|
on_exit(fn ->
|
||||||
File.rm_rf(@dir)
|
File.rm_rf(@dir)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ defmodule Pleroma.Web.AdminAPI.InstanceDocumentControllerTest do
|
||||||
@default_instance_panel ~s(<p>Welcome to <a href="https://pleroma.social" target="_blank">Pleroma!</a></p>)
|
@default_instance_panel ~s(<p>Welcome to <a href="https://pleroma.social" target="_blank">Pleroma!</a></p>)
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
File.mkdir_p!(@dir)
|
Pleroma.Backports.mkdir_p!(@dir)
|
||||||
on_exit(fn -> File.rm_rf(@dir) end)
|
on_exit(fn -> File.rm_rf(@dir) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
||||||
@dir "test/tmp/instance_static"
|
@dir "test/tmp/instance_static"
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
File.mkdir_p!(@dir)
|
Pleroma.Backports.mkdir_p!(@dir)
|
||||||
on_exit(fn -> File.rm_rf(@dir) end)
|
on_exit(fn -> File.rm_rf(@dir) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
||||||
clear_config([:frontends, :primary], %{"name" => name, "ref" => ref})
|
clear_config([:frontends, :primary], %{"name" => name, "ref" => ref})
|
||||||
path = "#{@dir}/frontends/#{name}/#{ref}"
|
path = "#{@dir}/frontends/#{name}/#{ref}"
|
||||||
|
|
||||||
File.mkdir_p!(path)
|
Pleroma.Backports.mkdir_p!(path)
|
||||||
File.write!("#{path}/index.html", "from frontend plug")
|
File.write!("#{path}/index.html", "from frontend plug")
|
||||||
|
|
||||||
index = get(conn, "/")
|
index = get(conn, "/")
|
||||||
|
|
@ -52,7 +52,7 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
||||||
clear_config([:frontends, :admin], %{"name" => name, "ref" => ref})
|
clear_config([:frontends, :admin], %{"name" => name, "ref" => ref})
|
||||||
path = "#{@dir}/frontends/#{name}/#{ref}"
|
path = "#{@dir}/frontends/#{name}/#{ref}"
|
||||||
|
|
||||||
File.mkdir_p!(path)
|
Pleroma.Backports.mkdir_p!(path)
|
||||||
File.write!("#{path}/index.html", "from frontend plug")
|
File.write!("#{path}/index.html", "from frontend plug")
|
||||||
|
|
||||||
index = get(conn, "/pleroma/admin/")
|
index = get(conn, "/pleroma/admin/")
|
||||||
|
|
@ -67,7 +67,7 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
||||||
clear_config([:frontends, :primary], %{"name" => name, "ref" => ref})
|
clear_config([:frontends, :primary], %{"name" => name, "ref" => ref})
|
||||||
path = "#{@dir}/frontends/#{name}/#{ref}"
|
path = "#{@dir}/frontends/#{name}/#{ref}"
|
||||||
|
|
||||||
File.mkdir_p!("#{path}/proxy/rr/ss")
|
Pleroma.Backports.mkdir_p!("#{path}/proxy/rr/ss")
|
||||||
File.write!("#{path}/proxy/rr/ss/Ek7w8WPVcAApOvN.jpg:large", "FB image")
|
File.write!("#{path}/proxy/rr/ss/Ek7w8WPVcAApOvN.jpg:large", "FB image")
|
||||||
|
|
||||||
ConfigMock
|
ConfigMock
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ defmodule Pleroma.Web.Plugs.InstanceStaticTest do
|
||||||
@dir "test/tmp/instance_static"
|
@dir "test/tmp/instance_static"
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
File.mkdir_p!(@dir)
|
Pleroma.Backports.mkdir_p!(@dir)
|
||||||
on_exit(fn -> File.rm_rf(@dir) end)
|
on_exit(fn -> File.rm_rf(@dir) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -34,7 +34,7 @@ defmodule Pleroma.Web.Plugs.InstanceStaticTest do
|
||||||
refute html_response(bundled_index, 200) == "from frontend plug"
|
refute html_response(bundled_index, 200) == "from frontend plug"
|
||||||
|
|
||||||
path = "#{@dir}/frontends/#{name}/#{ref}"
|
path = "#{@dir}/frontends/#{name}/#{ref}"
|
||||||
File.mkdir_p!(path)
|
Pleroma.Backports.mkdir_p!(path)
|
||||||
File.write!("#{path}/index.html", "from frontend plug")
|
File.write!("#{path}/index.html", "from frontend plug")
|
||||||
|
|
||||||
index = get(conn, "/")
|
index = get(conn, "/")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue