diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2015-05-09 18:43:06 -0400 |
---|---|---|
committer | Fred Hebert <mononcqc@ferd.ca> | 2015-05-09 18:43:06 -0400 |
commit | 8a22de470839fa833f019c17eeb54af3bd9460be (patch) | |
tree | cf53b0d89a20b1ca747ecea7ecb3be4fc364dd3a /src | |
parent | 81b1efda801a2bdb9c12a97cfe9e7da2a5ff9f62 (diff) | |
parent | a6f33258e210d8169a3ca411a0489feb22acca22 (diff) |
Merge pull request #411 from tsloughter/otp_version
fix failure on missing OTP_VERSION file #403
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_utils.erl | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index 4f0bc80..160d547 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -304,27 +304,30 @@ otp_release1([$R,N|_]=Rel) when is_integer(N) -> %% the "\n". otp_release1(Rel) -> File = filename:join([code:root_dir(), "releases", Rel, "OTP_VERSION"]), - {ok, Vsn} = file:read_file(File), - - %% It's fine to rely on the binary module here because we can - %% be sure that it's available when the otp_release string does - %% not begin with $R. - Size = byte_size(Vsn), - %% The shortest vsn string consists of at least two digits - %% followed by "\n". Therefore, it's safe to assume Size >= 3. - case binary:part(Vsn, {Size, -3}) of - <<"**\n">> -> - %% The OTP documentation mentions that a system patched - %% using the otp_patch_apply tool available to licensed - %% customers will leave a '**' suffix in the version as a - %% flag saying the system consists of application versions - %% from multiple OTP versions. We ignore this flag and - %% drop the suffix, given for all intents and purposes, we - %% cannot obtain relevant information from it as far as - %% tooling is concerned. - binary:bin_to_list(Vsn, {0, Size - 3}); - _ -> - binary:bin_to_list(Vsn, {0, Size - 1}) + case file:read_file(File) of + {error, _} -> + Rel; + {ok, Vsn} -> + %% It's fine to rely on the binary module here because we can + %% be sure that it's available when the otp_release string does + %% not begin with $R. + Size = byte_size(Vsn), + %% The shortest vsn string consists of at least two digits + %% followed by "\n". Therefore, it's safe to assume Size >= 3. + case binary:part(Vsn, {Size, -3}) of + <<"**\n">> -> + %% The OTP documentation mentions that a system patched + %% using the otp_patch_apply tool available to licensed + %% customers will leave a '**' suffix in the version as a + %% flag saying the system consists of application versions + %% from multiple OTP versions. We ignore this flag and + %% drop the suffix, given for all intents and purposes, we + %% cannot obtain relevant information from it as far as + %% tooling is concerned. + binary:bin_to_list(Vsn, {0, Size - 3}); + _ -> + binary:bin_to_list(Vsn, {0, Size - 1}) + end end. %% We do the shell variable substitution ourselves on Windows and hope that the |