Skip to content

Commit 33ab167

Browse files
committed
Warn and reset mime on future files
1 parent f2b1263 commit 33ab167

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/mix/lib/mix/utils.ex

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,17 @@ defmodule Mix.Utils do
9999
end
100100

101101
def last_modified(path) do
102+
now = :calendar.local_time
103+
102104
case File.stat(path) do
103-
{:ok, %File.Stat{mtime: mtime}} -> mtime
104-
{:error, _} -> {{1970, 1, 1}, {0, 0, 0}}
105+
{:ok, %File.Stat{mtime: mtime}} when mtime > now ->
106+
Mix.shell.error("warning: mtime (modified time) for \"#{path}\" was set to the future, resetting to now")
107+
File.touch!(path, now)
108+
mtime
109+
{:ok, %File.Stat{mtime: mtime}} ->
110+
mtime
111+
{:error, _} ->
112+
{{1970, 1, 1}, {0, 0, 0}}
105113
end
106114
end
107115

lib/mix/test/mix/tasks/compile.elixir_test.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ defmodule Mix.Tasks.Compile.ElixirTest do
7979
File.touch!("lib/a.ex", future)
8080
Mix.Tasks.Compile.Elixir.run []
8181

82+
assert_received {:mix_shell, :error, ["warning: mtime (modified time) for \"lib/a.ex\" was set to the future, resetting to now"]}
83+
refute_received {:mix_shell, :error, ["warning: mtime (modified time) for \"lib/b.ex\" was set to the future, resetting to now"]}
84+
8285
assert_received {:mix_shell, :info, ["Compiled lib/a.ex"]}
8386
refute_received {:mix_shell, :info, ["Compiled lib/b.ex"]}
8487

0 commit comments

Comments
 (0)