Skip to content

Commit 9222193

Browse files
authored
Return {0, -1} for missing files in last_modified_and_size/1, closes #15258 (#15259)
1 parent 245066b commit 9222193

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

lib/mix/lib/mix/compilers/elixir.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ defmodule Mix.Compilers.Elixir do
500500

501501
defp stale_external?({external, {mtime, size}, digest}, sources_stats) do
502502
case sources_stats do
503-
%{^external => {0, 0}} ->
503+
%{^external => {0, -1}} ->
504504
digest != nil
505505

506506
%{^external => {last_mtime, last_size}} ->

lib/mix/lib/mix/utils.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ defmodule Mix.Utils do
249249
Returns the date the given path was last modified in posix time
250250
and the size.
251251
252-
If the path does not exist, it returns the Unix epoch
253-
(1970-01-01 00:00:00).
252+
If the path does not exist, it returns `{0, -1}` (the Unix epoch
253+
with size -1 to distinguish from actual 0-byte files).
254254
"""
255255
def last_modified_and_size(path) do
256256
now = System.os_time(:second)
@@ -268,7 +268,7 @@ defmodule Mix.Utils do
268268
{mtime, size}
269269

270270
{:error, _} ->
271-
{0, 0}
271+
{0, -1}
272272
end
273273
end
274274

lib/mix/test/mix/utils_test.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ defmodule Mix.UtilsTest do
5858
assert Mix.Utils.extract_files([""], ".ex") == []
5959
end
6060

61+
test "last_modified_and_size returns {0, -1} for missing files" do
62+
assert Mix.Utils.last_modified_and_size("nonexistent") == {0, -1}
63+
end
64+
6165
test "extract stale" do
6266
# 2038-01-01 00:00:00
6367
time = 2_145_916_800

0 commit comments

Comments
 (0)