Skip to content
Snippets Groups Projects
Commit 66bda61b authored by Michael V. O'Brien's avatar Michael V. O'Brien Committed by Xiangrong Hao
Browse files

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.
parent 796e0642
No related branches found
No related tags found
No related merge requests found
...@@ -98,16 +98,30 @@ defmodule FileSystem.Backends.FSInotify do ...@@ -98,16 +98,30 @@ defmodule FileSystem.Backends.FSInotify do
def init(args) do def init(args) do
{worker_pid, rest} = Keyword.pop(args, :worker_pid) {worker_pid, rest} = Keyword.pop(args, :worker_pid)
case parse_options(rest) do case parse_options(rest) do
{:ok, port_args} -> {:ok, port_args} ->
bash_args = ['-c', '#{executable_path()} $0 $@ & PID=$!; read a; kill -KILL $PID'] 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( port = Port.open(
{:spawn_executable, '/bin/sh'}, {: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.link(port)
Process.flag(:trap_exit, true) Process.flag(:trap_exit, true)
{:ok, %{port: port, worker_pid: worker_pid}} {:ok, %{port: port, worker_pid: worker_pid}}
{:error, _} -> {:error, _} ->
:ignore :ignore
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment