Permalink
Browse files

Re-use code from file_server.erl's implementation of the open call to…

… avoid linking to a process spawned by evfs_file_server.

It should link to the original caller instead.
  • Loading branch information...
1 parent a9960a3 commit 88ae0bfe2344c8d9a042fc8f787cbf694a027fd5 @yrashk committed Jul 13, 2011
Showing with 22 additions and 10 deletions.
  1. +15 −3 src/evfs_default_handler.erl
  2. +2 −2 src/evfs_file_server.erl
  3. +1 −1 src/evfs_handler.erl
  4. +2 −2 src/evfs_httpc_handler.erl
  5. +2 −2 test/evfs_test_fs.erl
@@ -1,7 +1,7 @@
-module(evfs_default_handler).
-behaviour(evfs_handler).
-export([init/1, supports/2, terminate/2]).
--export([open/3,
+-export([open/4,
read_file/2,
write_file/3,
set_cwd/2,
@@ -49,8 +49,20 @@ supports(_, State) ->
%% Filesystem API
-open(Filename, Mode, FileServer) ->
- {ok, gen_server:call(FileServer, {open, filename(Filename), Mode}), FileServer}.
+-define(FILE_IO_SERVER_TABLE, file_io_servers).
+-define(FILE_IO_SERVER, file_io_server). % Module
+
+open(Pid, Filename, Mode, FileServer) ->
+ %% Had to copy this from file_server.erl to avoid direct linking
+ %% to the process spawned in evfs_file_server
+ Child = ?FILE_IO_SERVER:start_link(Pid, Filename, Mode),
+ case Child of
+ {ok, P} when is_pid(P) ->
+ ets:insert(?FILE_IO_SERVER_TABLE, {P, Filename});
+ _ ->
+ ok
+ end,
+ {ok, Child, FileServer}.
read_file(Filename, FileServer) ->
{ok, gen_server:call(FileServer, {read_file, filename(Filename)}), FileServer}.
@@ -150,8 +150,8 @@ handle_call({filename, flatten, [Filename]}, From, State) ->
%%
-handle_call({open, Filename, ModeList}, From, State) ->
- call_handler(From, Filename, open, [Filename, ModeList], State);
+handle_call({open, Filename, ModeList}, {Pid, _Tag} = From, State) ->
+ call_handler(From, Filename, open, [Pid, Filename, ModeList], State);
handle_call({read_file, Filename}, From, State) ->
call_handler(From, Filename, read_file, [Filename], State);
@@ -6,7 +6,7 @@ behaviour_info(callbacks) ->
{supports, 2},
{terminate, 2},
%% File system API
- {open,3},
+ {open,4},
{read_file,2},
{write_file,3},
{set_cwd,2},
@@ -1,7 +1,7 @@
-module(evfs_httpc_handler).
-behaviour(evfs_handler).
-export([init/1, supports/2, terminate/2]).
--export([open/3,
+-export([open/4,
read_file/2,
write_file/3,
set_cwd/2,
@@ -56,7 +56,7 @@ supports(_, State) ->
%% Filesystem API
-open(Filename, _Mode, Profile) ->
+open(_Pid, Filename, _Mode, Profile) -> %% TODO: use this Pid
Child = evfs_io_server:start_link(?MODULE, {Filename, Profile}),
{ok, Child, Profile}.
@@ -2,7 +2,7 @@
-behaviour(evfs_handler).
-behaviour(evfs_io_server).
-export([init/1, supports/2, terminate/2]).
--export([open/3,
+-export([open/4,
read_file/2,
write_file/3,
set_cwd/2,
@@ -35,7 +35,7 @@ supports(_, State) ->
%% Filesystem API
-open(Filename, _Mode, State) ->
+open(_Pid, Filename, _Mode, State) ->
Child = evfs_io_server:start_link(?MODULE, Filename),
{ok, Child, State}.

0 comments on commit 88ae0bf

Please sign in to comment.