pleroma/lib/pleroma/otp_version.ex

29 lines
851 B
Elixir
Raw Normal View History

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