Fix MRF policies to also work with Update
[akkoma] / lib / pleroma / otp_version.ex
index 0be189304b9404240de3aabdaad0dc762698c1f7..a5ac1b07277d5569981c7938c77f2bdd3f3107fc 100644 (file)
@@ -1,63 +1,28 @@
-defmodule Pleroma.OTPVersion do
-  @type check_status() :: :undefined | {:error, String.t()} | :ok
-
-  require Logger
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
 
-  @spec check_version() :: check_status()
-  def check_version do
+defmodule Pleroma.OTPVersion do
+  @spec version() :: String.t() | nil
+  def version do
     # OTP Version https://erlang.org/doc/system_principles/versions.html#otp-version
-    paths = [
+    [
       Path.join(:code.root_dir(), "OTP_VERSION"),
       Path.join([:code.root_dir(), "releases", :erlang.system_info(:otp_release), "OTP_VERSION"])
     ]
-
-    :tesla
-    |> Application.get_env(:adapter)
-    |> get_and_check_version(paths)
+    |> get_version_from_files()
   end
 
-  @spec get_and_check_version(module(), [Path.t()]) :: check_status()
-  def get_and_check_version(Tesla.Adapter.Gun, paths) do
-    paths
-    |> check_files()
-    |> check_version()
-  end
-
-  def get_and_check_version(_, _), do: :ok
-
-  defp check_files([]), do: nil
+  @spec get_version_from_files([Path.t()]) :: String.t() | nil
+  def get_version_from_files([]), do: nil
 
-  defp check_files([path | paths]) do
+  def get_version_from_files([path | paths]) do
     if File.exists?(path) do
-      File.read!(path)
+      path
+      |> File.read!()
+      |> String.replace(~r/\r|\n|\s/, "")
     else
-      check_files(paths)
-    end
-  end
-
-  defp check_version(nil), do: :undefined
-
-  defp check_version(version) do
-    try do
-      version = String.replace(version, ~r/\r|\n|\s/, "")
-
-      formatted =
-        version
-        |> String.split(".")
-        |> Enum.map(&String.to_integer/1)
-        |> Enum.take(2)
-
-      with [major, minor] when length(formatted) == 2 <- formatted,
-           true <- (major == 22 and minor >= 2) or major > 22 do
-        :ok
-      else
-        false -> {:error, version}
-        _ -> :undefined
-      end
-    rescue
-      _ -> :undefined
-    catch
-      _ -> :undefined
+      get_version_from_files(paths)
     end
   end
 end