cover/Elixir.Sweep.html

1 defmodule Sweep do
2 import Path, only: [join: 2]
3 import System, only: [get_env: 2, os_time: 1]
4 import File, only: [ls: 1, rm: 1, stat: 1]
5 import Enum, only: [each: 2]
6
7 def sweep do
8 1 with {:ok, names} <- ls(dir()) do
9 1 each(names, &purge(&1, os_time(:second) - 604_800))
10 end
11 end
12
13 defp purge(name, cutoff) do
14 17 with {:ok, s} <- stat(join(dir(), name)), true <- s.mtime < cutoff do
15
:-(
rm(join(dir(), name))
16 end
17 end
18
19 defp dir do
20 18 join(get_env("HOME", "~"), ".elita/sessions")
21 end
22 end
Line Hits Source