Handle renaming documents
This commit is contained in:
parent
cecfa859f8
commit
fe2a6cb857
@ -3,6 +3,8 @@ defmodule Pandoc.Watcher do
|
||||
|
||||
use GenServer
|
||||
|
||||
@events MapSet.new([:closed, :deleted, :moved_from, :moved_to])
|
||||
|
||||
def start_link(args) do
|
||||
GenServer.start_link(__MODULE__, args)
|
||||
end
|
||||
@ -18,12 +20,8 @@ defmodule Pandoc.Watcher do
|
||||
|
||||
@impl true
|
||||
def handle_info({:file_event, watcher_pid, {path, events}}, %{watcher_pid: watcher_pid} = state) do
|
||||
case {String.match?(path, state[:pattern]), :closed in events or :deleted in events} do
|
||||
{true, true} ->
|
||||
Pandoc.install_and_run(state[:profile], [Path.basename(path) | state[:extra_args]])
|
||||
|
||||
_ ->
|
||||
nil
|
||||
if String.match?(path, state[:pattern]) and update?(events) do
|
||||
Pandoc.install_and_run(state[:profile], [Path.basename(path) | state[:extra_args]])
|
||||
end
|
||||
|
||||
{:noreply, state}
|
||||
@ -32,4 +30,8 @@ defmodule Pandoc.Watcher do
|
||||
def handle_info({:file_event, watcher_pid, :stop}, %{watcher_pid: watcher_pid} = state) do
|
||||
{:noreply, state}
|
||||
end
|
||||
|
||||
defp update?(events) do
|
||||
events |> MapSet.new() |> MapSet.intersection(@events) |> MapSet.size() > 0
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user