akkoma/lib/pleroma/otp_version.ex

29 lines
851 B
Elixir
Raw Permalink Normal View History

2020-03-03 09:19:29 +00:00
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
2020-03-03 09:19:29 +00:00
# SPDX-License-Identifier: AGPL-3.0-only
2020-02-11 07:12:57 +00:00
2020-03-03 09:19:29 +00:00
defmodule Pleroma.OTPVersion do
2020-03-04 06:23:42 +00:00
@spec version() :: String.t() | nil
def version do
2020-02-11 07:12:57 +00:00
# OTP Version https://erlang.org/doc/system_principles/versions.html#otp-version
2020-03-03 09:19:29 +00:00
[
2020-02-11 07:12:57 +00:00
Path.join(:code.root_dir(), "OTP_VERSION"),
Path.join([:code.root_dir(), "releases", :erlang.system_info(:otp_release), "OTP_VERSION"])
]
2020-03-03 09:19:29 +00:00
|> get_version_from_files()
2020-02-11 07:12:57 +00:00
end
2020-03-04 06:23:42 +00:00
@spec get_version_from_files([Path.t()]) :: String.t() | nil
def get_version_from_files([]), do: nil
2020-02-11 07:12:57 +00:00
2020-03-04 06:23:42 +00:00
def get_version_from_files([path | paths]) do
2020-02-11 07:12:57 +00:00
if File.exists?(path) do
2020-03-04 06:23:42 +00:00
path
|> File.read!()
|> String.replace(~r/\r|\n|\s/, "")
2020-02-11 07:12:57 +00:00
else
2020-03-03 09:19:29 +00:00
get_version_from_files(paths)
2020-02-11 07:12:57 +00:00
end
end
end