From adc9aad3ea3002f26eabebae1ead5351a43926be Mon Sep 17 00:00:00 2001 From: zoten <luca.deizotti@gmail.com> Date: Tue, 22 Sep 2020 18:31:41 +0200 Subject: [PATCH] Restore "renamed" flag on file rename event (#68) * Restore "renamed" flag on file rename event * More granular events for file moves See discussion [here](https://github.com/falood/file_system/issues/67) Co-authored-by: Luca Dei Zotti <luca.deizotti@athonet.com> --- lib/file_system/backends/fs_inotify.ex | 4 ++-- test/backends/fs_inotify_test.exs | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/file_system/backends/fs_inotify.ex b/lib/file_system/backends/fs_inotify.ex index 366040c..8fd5566 100644 --- a/lib/file_system/backends/fs_inotify.ex +++ b/lib/file_system/backends/fs_inotify.ex @@ -157,9 +157,9 @@ defmodule FileSystem.Backends.FSInotify do end defp convert_flag("CREATE"), do: :created - defp convert_flag("MOVED_TO"), do: :created + defp convert_flag("MOVED_TO"), do: :moved_to defp convert_flag("DELETE"), do: :deleted - defp convert_flag("MOVED_FROM"), do: :deleted + defp convert_flag("MOVED_FROM"), do: :moved_from defp convert_flag("ISDIR"), do: :isdir defp convert_flag("MODIFY"), do: :modified defp convert_flag("CLOSE_WRITE"), do: :modified diff --git a/test/backends/fs_inotify_test.exs b/test/backends/fs_inotify_test.exs index 414ed56..1482eff 100644 --- a/test/backends/fs_inotify_test.exs +++ b/test/backends/fs_inotify_test.exs @@ -42,10 +42,15 @@ defmodule FileSystem.Backends.FSInotifyTest do end test "dir moved to" do - assert {"/one/two/file", [:created]} == + assert {"/one/two/file", [:moved_to]} == ~w|/one/two/ MOVED_TO file| |> to_port_line |> parse_line end + test "dir moved from" do + assert {"/one/two/file", [:moved_from]} == + ~w|/one/two/ MOVED_FROM file| |> to_port_line |> parse_line + end + test "dir is_dir create" do assert {"/one/two/dir", [:created, :isdir]} == ~w|/one/two/ CREATE,ISDIR dir| |> to_port_line |> parse_line -- GitLab