From 66bda61ba4edea559fba58a530d32a07c9ce9560 Mon Sep 17 00:00:00 2001
From: "Michael V. O'Brien" <michael@michaelvobrien.com>
Date: Thu, 30 May 2019 12:54:34 -0500
Subject: [PATCH] Fix inotify backend for FreeBSD (#60)

On FreeBSD (and possibly Linux) using `inotify-tools`:

Given:

```
{:ok, pid} = FileSystem.start_link(dirs: ["/path/to/some/files"])
```

Results in the error:

```
Couldn't watch modify: No such file or directory
````

This is similar to executing `inotifywait modify` at the console.

This fix ensures arguments to 'sh' are passed properly.
---
 lib/file_system/backends/fs_inotify.ex | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/lib/file_system/backends/fs_inotify.ex b/lib/file_system/backends/fs_inotify.ex
index 4221194..0e0fa1f 100644
--- a/lib/file_system/backends/fs_inotify.ex
+++ b/lib/file_system/backends/fs_inotify.ex
@@ -98,16 +98,30 @@ defmodule FileSystem.Backends.FSInotify do
 
   def init(args) do
     {worker_pid, rest} = Keyword.pop(args, :worker_pid)
+
     case parse_options(rest) do
       {:ok, port_args} ->
         bash_args = ['-c', '#{executable_path()} $0 $@ & PID=$!; read a; kill -KILL $PID']
+
+        all_args =
+          case :os.type() do
+            {:unix, :freebsd} ->
+              bash_args ++ ['--'] ++ port_args
+
+            _ ->
+              bash_args ++ port_args
+          end
+
         port = Port.open(
           {:spawn_executable, '/bin/sh'},
-          [:stream, :exit_status, {:line, 16384}, {:args, bash_args ++ port_args}, {:cd, System.tmp_dir!()}]
+          [:stream, :exit_status, {:line, 16384}, {:args, all_args}, {:cd, System.tmp_dir!()}]
         )
+
         Process.link(port)
         Process.flag(:trap_exit, true)
+
         {:ok, %{port: port, worker_pid: worker_pid}}
+
       {:error, _} ->
         :ignore
     end
-- 
GitLab