Skip to content

Commit eab44e7

Browse files
authored
Add CI, remove warnings on Elixir v1.17-dev (#89)
1 parent 2219fa8 commit eab44e7

16 files changed

+411
-195
lines changed

.formatter.exs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"]
3+
]

.github/workflows/ci.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-20.04
12+
env:
13+
MIX_ENV: test
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
include:
18+
- pair:
19+
elixir: 1.12.4
20+
otp: 23.3
21+
- pair:
22+
elixir: 1.15.7
23+
otp: 26.1
24+
lint: lint
25+
steps:
26+
- uses: actions/checkout@v3
27+
28+
- uses: erlef/setup-beam@v1
29+
with:
30+
otp-version: ${{matrix.pair.otp}}
31+
elixir-version: ${{matrix.pair.elixir}}
32+
33+
- uses: actions/cache@v3
34+
with:
35+
path: |
36+
deps
37+
_build
38+
key: ${{ runner.os }}-mix-${{matrix.pair.elixir}}-${{matrix.pair.otp}}-${{ hashFiles('**/mix.lock') }}
39+
restore-keys: |
40+
${{ runner.os }}-mix-
41+
42+
- run: mix deps.get
43+
44+
- run: mix format --check-formatted
45+
if: ${{ matrix.lint }}
46+
47+
- run: mix deps.unlock --check-unused
48+
if: ${{ matrix.lint }}
49+
50+
- run: mix deps.compile
51+
52+
- run: mix compile --warnings-as-errors
53+
if: ${{ matrix.lint }}
54+
55+
- run: mix test

.travis.yml

-40
This file was deleted.

config/config.exs

-5
This file was deleted.

lib/file_system.ex

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ defmodule FileSystem do
4141
iex> FileSystem.subscribe(:worker)
4242
4343
"""
44-
@spec start_link(Keyword.t) :: GenServer.on_start()
44+
@spec start_link(Keyword.t()) :: GenServer.on_start()
4545
def start_link(options) do
4646
FileSystem.Worker.start_link(options)
4747
end
@@ -55,7 +55,7 @@ defmodule FileSystem do
5555
{:file_event, worker_pid, :stop}
5656
5757
"""
58-
@spec subscribe(GenServer.server) :: :ok
58+
@spec subscribe(GenServer.server()) :: :ok
5959
def subscribe(pid) do
6060
GenServer.call(pid, :subscribe)
6161
end

lib/file_system/backend.ex

+31-17
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ defmodule FileSystem.Backend do
2424
def backend(backend) do
2525
with {:ok, module} <- backend_module(backend),
2626
:ok <- validate_os(backend, module),
27-
:ok <- module.bootstrap
28-
do
27+
:ok <- module.bootstrap() do
2928
{:ok, module}
3029
else
3130
{:error, reason} -> {:error, reason}
@@ -34,40 +33,55 @@ defmodule FileSystem.Backend do
3433

3534
defp backend_module(nil) do
3635
case :os.type() do
37-
{:unix, :darwin} -> :fs_mac
38-
{:unix, :linux} -> :fs_inotify
39-
{:unix, :freebsd} -> :fs_inotify
40-
{:unix, :openbsd} -> :fs_inotify
41-
{:win32, :nt} -> :fs_windows
42-
system -> {:unsupported_system, system}
43-
end |> backend_module
36+
{:unix, :darwin} -> :fs_mac
37+
{:unix, :linux} -> :fs_inotify
38+
{:unix, :freebsd} -> :fs_inotify
39+
{:unix, :openbsd} -> :fs_inotify
40+
{:win32, :nt} -> :fs_windows
41+
system -> {:unsupported_system, system}
42+
end
43+
|> backend_module
4444
end
45-
defp backend_module(:fs_mac), do: {:ok, FileSystem.Backends.FSMac}
45+
46+
defp backend_module(:fs_mac), do: {:ok, FileSystem.Backends.FSMac}
4647
defp backend_module(:fs_inotify), do: {:ok, FileSystem.Backends.FSInotify}
4748
defp backend_module(:fs_windows), do: {:ok, FileSystem.Backends.FSWindows}
48-
defp backend_module(:fs_poll), do: {:ok, FileSystem.Backends.FSPoll}
49+
defp backend_module(:fs_poll), do: {:ok, FileSystem.Backends.FSPoll}
50+
4951
defp backend_module({:unsupported_system, system}) do
50-
Logger.error "I'm so sorry but `file_system` does NOT support your current system #{inspect system} for now."
52+
Logger.error(
53+
"I'm so sorry but `file_system` does NOT support your current system #{inspect(system)} for now."
54+
)
55+
5156
{:error, :unsupported_system}
5257
end
58+
5359
defp backend_module(module) do
5460
functions = module.__info__(:functions)
55-
{:start_link, 1} in functions &&
56-
{:bootstrap, 0} in functions &&
57-
{:supported_systems, 0} in functions ||
61+
62+
({:start_link, 1} in functions &&
63+
{:bootstrap, 0} in functions &&
64+
{:supported_systems, 0} in functions) ||
5865
raise "illegal backend"
5966
rescue
6067
_ ->
61-
Logger.error "You are using custom backend `#{inspect module}`, make sure it's a legal file_system backend module."
68+
Logger.error(
69+
"You are using custom backend `#{inspect(module)}`, make sure it's a legal file_system backend module."
70+
)
71+
6272
{:error, :illegal_backend}
6373
end
6474

6575
defp validate_os(backend, module) do
6676
os_type = :os.type()
77+
6778
if os_type in module.supported_systems() do
6879
:ok
6980
else
70-
Logger.error "The backend `#{backend}` you are using does NOT support your current system #{inspect os_type}."
81+
Logger.error(
82+
"The backend `#{backend}` you are using does NOT support your current system #{inspect(os_type)}."
83+
)
84+
7185
{:error, :unsupported_system}
7286
end
7387
end

lib/file_system/backends/fs_inotify.ex

+66-26
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ defmodule FileSystem.Backends.FSInotify do
3939

4040
def bootstrap do
4141
exec_file = executable_path()
42+
4243
if is_nil(exec_file) do
43-
Logger.error "`inotify-tools` is needed to run `file_system` for your system, check https://github.com/rvoicilas/inotify-tools/wiki for more information about how to install it. If it's already installed but not be found, appoint executable file with `config.exs` or `FILESYSTEM_FSINOTIFY_EXECUTABLE_FILE` env."
44+
Logger.error(
45+
"`inotify-tools` is needed to run `file_system` for your system, check https://github.com/rvoicilas/inotify-tools/wiki for more information about how to install it. If it's already installed but not be found, appoint executable file with `config.exs` or `FILESYSTEM_FSINOTIFY_EXECUTABLE_FILE` env."
46+
)
47+
4448
{:error, :fs_inotify_bootstrap_error}
4549
else
4650
:ok
@@ -74,32 +78,56 @@ defmodule FileSystem.Backends.FSInotify do
7478
def parse_options(options) do
7579
case Keyword.pop(options, :dirs) do
7680
{nil, _} ->
77-
Logger.error "required argument `dirs` is missing"
81+
Logger.error("required argument `dirs` is missing")
7882
{:error, :missing_dirs_argument}
83+
7984
{dirs, rest} ->
8085
format = ["%w", "%e", "%f"] |> Enum.join(@sep_char) |> to_charlist
86+
8187
args = [
82-
'-e', 'modify', '-e', 'close_write', '-e', 'moved_to', '-e', 'moved_from',
83-
'-e', 'create', '-e', 'delete', '-e', 'attrib', '--format', format, '--quiet', '-m', '-r'
88+
~c"-e",
89+
~c"modify",
90+
~c"-e",
91+
~c"close_write",
92+
~c"-e",
93+
~c"moved_to",
94+
~c"-e",
95+
~c"moved_from",
96+
~c"-e",
97+
~c"create",
98+
~c"-e",
99+
~c"delete",
100+
~c"-e",
101+
~c"attrib",
102+
~c"--format",
103+
format,
104+
~c"--quiet",
105+
~c"-m",
106+
~c"-r"
84107
| dirs |> Enum.map(&Path.absname/1) |> Enum.map(&to_charlist/1)
85108
]
109+
86110
parse_options(rest, args)
87111
end
88112
end
89113

90114
defp parse_options([], result), do: {:ok, result}
115+
91116
defp parse_options([{:recursive, true} | t], result) do
92117
parse_options(t, result)
93118
end
119+
94120
defp parse_options([{:recursive, false} | t], result) do
95-
parse_options(t, result -- ['-r'])
121+
parse_options(t, result -- [~c"-r"])
96122
end
123+
97124
defp parse_options([{:recursive, value} | t], result) do
98-
Logger.error "unknown value `#{inspect value}` for recursive, ignore"
125+
Logger.error("unknown value `#{inspect(value)}` for recursive, ignore")
99126
parse_options(t, result)
100127
end
128+
101129
defp parse_options([h | t], result) do
102-
Logger.error "unknown option `#{inspect h}`, ignore"
130+
Logger.error("unknown option `#{inspect(h)}`, ignore")
103131
parse_options(t, result)
104132
end
105133

@@ -112,21 +140,32 @@ defmodule FileSystem.Backends.FSInotify do
112140

113141
case parse_options(rest) do
114142
{:ok, port_args} ->
115-
bash_args = ['-c', '#{executable_path()} "$0" "$@" & PID=$!; read a; kill -KILL $PID']
143+
bash_args = [
144+
~c"-c",
145+
~c"#{executable_path()} \"$0\" \"$@\" & PID=$!; read a; kill -KILL $PID"
146+
]
116147

117148
all_args =
118149
case :os.type() do
119150
{:unix, :freebsd} ->
120-
bash_args ++ ['--'] ++ port_args
151+
bash_args ++ [~c"--"] ++ port_args
121152

122153
_ ->
123154
bash_args ++ port_args
124155
end
125156

126-
port = Port.open(
127-
{:spawn_executable, '/bin/sh'},
128-
[:binary, :stream, :exit_status, {:line, 16384}, {:args, all_args}, {:cd, System.tmp_dir!()}]
129-
)
157+
port =
158+
Port.open(
159+
{:spawn_executable, ~c"/bin/sh"},
160+
[
161+
:binary,
162+
:stream,
163+
:exit_status,
164+
{:line, 16384},
165+
{:args, all_args},
166+
{:cd, System.tmp_dir!()}
167+
]
168+
)
130169

131170
Process.link(port)
132171
Process.flag(:trap_exit, true)
@@ -138,18 +177,18 @@ defmodule FileSystem.Backends.FSInotify do
138177
end
139178
end
140179

141-
def handle_info({port, {:data, {:eol, line}}}, %{port: port}=state) do
180+
def handle_info({port, {:data, {:eol, line}}}, %{port: port} = state) do
142181
{file_path, events} = line |> parse_line
143182
send(state.worker_pid, {:backend_file_event, self(), {file_path, events}})
144183
{:noreply, state}
145184
end
146185

147-
def handle_info({port, {:exit_status, _}}, %{port: port}=state) do
186+
def handle_info({port, {:exit_status, _}}, %{port: port} = state) do
148187
send(state.worker_pid, {:backend_file_event, self(), :stop})
149188
{:stop, :normal, state}
150189
end
151190

152-
def handle_info({:EXIT, port, _reason}, %{port: port}=state) do
191+
def handle_info({:EXIT, port, _reason}, %{port: port} = state) do
153192
send(state.worker_pid, {:backend_file_event, self(), :stop})
154193
{:stop, :normal, state}
155194
end
@@ -162,19 +201,20 @@ defmodule FileSystem.Backends.FSInotify do
162201
{path, flags} =
163202
case String.split(line, @sep_char, trim: true) do
164203
[dir, flags, file] -> {Path.join(dir, file), flags}
165-
[path, flags] -> {path, flags}
204+
[path, flags] -> {path, flags}
166205
end
206+
167207
{path, flags |> String.split(",") |> Enum.map(&convert_flag/1)}
168208
end
169209

170-
defp convert_flag("CREATE"), do: :created
171-
defp convert_flag("MOVED_TO"), do: :moved_to
172-
defp convert_flag("DELETE"), do: :deleted
173-
defp convert_flag("MOVED_FROM"), do: :moved_from
174-
defp convert_flag("ISDIR"), do: :isdir
175-
defp convert_flag("MODIFY"), do: :modified
210+
defp convert_flag("CREATE"), do: :created
211+
defp convert_flag("MOVED_TO"), do: :moved_to
212+
defp convert_flag("DELETE"), do: :deleted
213+
defp convert_flag("MOVED_FROM"), do: :moved_from
214+
defp convert_flag("ISDIR"), do: :isdir
215+
defp convert_flag("MODIFY"), do: :modified
176216
defp convert_flag("CLOSE_WRITE"), do: :modified
177-
defp convert_flag("CLOSE"), do: :closed
178-
defp convert_flag("ATTRIB"), do: :attribute
179-
defp convert_flag(_), do: :undefined
217+
defp convert_flag("CLOSE"), do: :closed
218+
defp convert_flag("ATTRIB"), do: :attribute
219+
defp convert_flag(_), do: :undefined
180220
end

0 commit comments

Comments
 (0)