First
[anni] / lib / pleroma / otp_version.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.OTPVersion do
6   @spec version() :: String.t() | nil
7   def version do
8     # OTP Version https://erlang.org/doc/system_principles/versions.html#otp-version
9     [
10       Path.join(:code.root_dir(), "OTP_VERSION"),
11       Path.join([:code.root_dir(), "releases", :erlang.system_info(:otp_release), "OTP_VERSION"])
12     ]
13     |> get_version_from_files()
14   end
15
16   @spec get_version_from_files([Path.t()]) :: String.t() | nil
17   def get_version_from_files([]), do: nil
18
19   def get_version_from_files([path | paths]) do
20     if File.exists?(path) do
21       path
22       |> File.read!()
23       |> String.replace(~r/\r|\n|\s/, "")
24     else
25       get_version_from_files(paths)
26     end
27   end
28 end