Skip to content

Commit

Permalink
send event after file process is complete;
Browse files Browse the repository at this point in the history
  • Loading branch information
jalpedersen committed Nov 30, 2018
1 parent 129596a commit cceb76c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -13,7 +13,7 @@ The package can be installed by adding `exsftpd` to your list of dependencies in
```elixir
def deps do
[
{:exsftpd, "~> 0.5.0"}
{:exsftpd, "~> 0.6.0"}
]
end
```
Expand Down
43 changes: 25 additions & 18 deletions lib/sftpd_file_handler.ex
Expand Up @@ -10,6 +10,13 @@ defmodule Exsftpd.SftpFileHandler do
Watcher.on_event({event_name, user, meta})
end

defp after_event({event_name, meta}, state, result) do
user = state[:user]
Watcher.on_event({event_name, user, meta})
result
end


defp get_file_info(io_device) do
case :file.pid2name(io_device) do
{:ok, filename} -> {io_device, filename}
Expand All @@ -18,18 +25,18 @@ defmodule Exsftpd.SftpFileHandler do
end

def close(io_device, state) do
on_event({:close, get_file_info(io_device)}, state)
{:file.close(io_device), state}
after_event({:close, get_file_info(io_device)}, state,
{:file.close(io_device), state})
end

def delete(path, state) do
on_event({:delete, path}, state)
{:file.delete(user_path(path, state)), state}
after_event({:delete, path}, state,
{:file.delete(user_path(path, state)), state})
end

def del_dir(path, state) do
on_event({:del_dir, path}, state)
{:file.del_dir(user_path(path, state)), state}
after_event({:del_dir, path}, state,
{:file.del_dir(user_path(path, state)), state})
end

def get_cwd(state) do
Expand All @@ -45,13 +52,13 @@ defmodule Exsftpd.SftpFileHandler do
end

def make_dir(dir, state) do
on_event({:make_dir, dir}, state)
{:file.make_dir(user_path(dir, state)), state}
after_event({:make_dir, dir}, state,
{:file.make_dir(user_path(dir, state)), state})
end

def make_symlink(path2, path, state) do
on_event({:make_symlink, {path2, path}}, state)
{:file.make_symlink(user_path(path2, state), user_path(path, state)), state}
after_event({:make_symlink, {path2, path}}, state,
{:file.make_symlink(user_path(path2, state), user_path(path, state)), state})
end

def open(path, flags, state) do
Expand All @@ -68,8 +75,8 @@ defmodule Exsftpd.SftpFileHandler do
end

def read(io_device, len, state) do
on_event({:read, get_file_info(io_device)}, state)
{:file.read(io_device, len), state}
after_event({:read, get_file_info(io_device)}, state,
{:file.read(io_device, len), state})
end

def read_link(path, state) do
Expand All @@ -85,17 +92,17 @@ defmodule Exsftpd.SftpFileHandler do
end

def rename(path, path2, state) do
on_event({:rename, {path, path2}}, state)
{:file.rename(user_path(path, state), user_path(path2, state)), state}
after_event({:rename, {path, path2}}, state,
{:file.rename(user_path(path, state), user_path(path2, state)), state})
end

def write(io_device, data, state) do
on_event({:write, get_file_info(io_device)}, state)
{:file.write(io_device, data), state}
after_event({:write, get_file_info(io_device)}, state,
{:file.write(io_device, data), state})
end

def write_file_info(path, info, state) do
on_event({:write_file_info, {path, info}}, state)
{:file.write_file_info(user_path(path, state), info), state}
after_event({:write_file_info, {path, info}}, state,
{:file.write_file_info(user_path(path, state), info), state})
end
end
2 changes: 1 addition & 1 deletion mix.exs
Expand Up @@ -5,7 +5,7 @@ defmodule Exsftpd.MixProject do
[
app: :exsftpd,
description: description(),
version: "0.5.0",
version: "0.6.0",
elixir: "~> 1.4 or ~> 1.5 or ~> 1.6 or ~> 1.7",
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
Expand Down

0 comments on commit cceb76c

Please sign in to comment.