123123
124124-optional_callbacks ([write / 2 ]).
125125
126+ -define (DEFAULT_FILE , osiris_file_default ).
127+
126128-spec advise (Handle , Offset , Length , Advise ) -> ok | {error , Reason } when
127129 Handle :: file_handle (),
128130 Offset :: integer (),
133135advise ({Mod , Handle }, Offset , Length , Advise ) ->
134136 Mod :advise (Handle , Offset , Length , Advise );
135137advise (Handle , Offset , Length , Advise ) ->
136- file :advise (Handle , Offset , Length , Advise ).
138+ ? DEFAULT_FILE :advise (Handle , Offset , Length , Advise ).
137139
138140
139141-spec close (Handle ) -> ok | {error , Reason } when
@@ -143,7 +145,7 @@ advise(Handle, Offset, Length, Advise) ->
143145close ({Mod , Handle }) ->
144146 Mod :close (Handle );
145147close (Handle ) ->
146- file :close (Handle ).
148+ ? DEFAULT_FILE :close (Handle ).
147149
148150
149151-spec copy (Source , Destination ) -> {ok , BytesCopied } | {error , Reason } when
@@ -155,7 +157,7 @@ close(Handle) ->
155157 Reason :: file :posix () | badarg | terminated .
156158% % TODO
157159copy (Source , Destination ) ->
158- file :copy (Source , Destination ).
160+ ? DEFAULT_FILE :copy (Source , Destination ).
159161
160162-spec del_dir (Dir ) -> ok | {error , Reason } when
161163 Dir :: file :name_all (),
@@ -191,7 +193,7 @@ prim_delete(File) ->
191193 Reason :: file :posix ().
192194% % Only used for local files
193195ensure_dir (Dir ) ->
194- filelib :ensure_dir (Dir ).
196+ ? DEFAULT_FILE :ensure_dir (Dir ).
195197
196198
197199-spec list_dir (Dir ) -> {ok , Filenames } | {error , Reason } when
@@ -211,7 +213,7 @@ list_dir(Dir) ->
211213 Reason :: file :posix () | badarg .
212214% % Only used for the local segment file, no need to change it.
213215make_dir (Dir ) ->
214- file :make_dir (Dir ).
216+ ? DEFAULT_FILE :make_dir (Dir ).
215217
216218
217219-spec open (File , Modes ) -> {ok , file_handle ()} | {error , Reason } when
@@ -223,7 +225,7 @@ open(File, Options) ->
223225 case lists :member (write , Options ) of
224226 true ->
225227 % % We do not use tiered storage for writes
226- file :open (File , Options );
228+ ? DEFAULT_FILE :open (File , Options );
227229 false ->
228230 % % Here we will get the correct Mod based on config/manifest file etc.
229231 Mod = get_mod (File ),
@@ -241,7 +243,7 @@ open(File, Options) ->
241243position ({Mod , Handle }, Position ) ->
242244 Mod :position (Handle , Position );
243245position (Handle , Position ) ->
244- file :position (Handle , Position ).
246+ ? DEFAULT_FILE :position (Handle , Position ).
245247
246248
247249-spec pread (Handle , Location , Number ) ->
@@ -270,7 +272,7 @@ pread(Handle, Position, Size) ->
270272read ({Mod , Handle }, Size ) ->
271273 Mod :read (Handle , Size );
272274read (Handle , Size ) ->
273- file :read (Handle , Size ).
275+ ? DEFAULT_FILE :read (Handle , Size ).
274276
275277
276278-spec read_file_info (File ) -> {ok , FileInfo } | {error , Reason } when
@@ -283,20 +285,20 @@ read_file_info(File) ->
283285 Mod :read_file_info (File ).
284286
285287
286- -spec sendfile (Handle , Socket , Offset , Bytes , Opts ) ->
287- {ok , non_neg_integer ()} | {error , inet :posix () |
288- closed | badarg | not_owner } when
288+ -spec sendfile (Transport , Handle , Socket , Offset , Bytes ) ->
289+ ok | {error , inet :posix () |
290+ closed | badarg | not_owner } when
291+ Transport :: tcp | ssl ,
289292 Handle :: file_handle (),
290293 Socket :: inet :socket () | socket :socket () |
291294 fun ((iolist ()) -> ok | {error , inet :posix () | closed }),
292295 Offset :: non_neg_integer (),
293- Bytes :: non_neg_integer (),
294- Opts :: [sendfile_option ()].
296+ Bytes :: non_neg_integer ().
295297
296- sendfile ({Mod , Handle }, Socket , Offset , Length , Options ) ->
297- Mod :sendfile (Handle , Socket , Offset , Length , Options );
298- sendfile (Handle , Socket , Offset , Length , Options ) ->
299- file :sendfile (Handle , Socket , Offset , Length , Options ).
298+ sendfile (Transport , {Mod , Handle }, Socket , Offset , Length ) ->
299+ Mod :sendfile (Transport , Handle , Socket , Offset , Length );
300+ sendfile (Transport , Handle , Socket , Offset , Length ) ->
301+ ? DEFAULT_FILE :sendfile (Transport , Handle , Socket , Offset , Length ).
300302
301303
302304-spec truncate (Handle ) -> ok | {error , Reason } when
@@ -306,7 +308,7 @@ sendfile(Handle, Socket, Offset, Length, Options) ->
306308truncate ({Mod , Handle }) ->
307309 Mod :truncate (Handle );
308310truncate (Handle ) ->
309- file :truncate (Handle ).
311+ ? DEFAULT_FILE :truncate (Handle ).
310312
311313
312314-spec write (Handle , Bytes ) -> ok | {error , Reason } when
@@ -316,7 +318,7 @@ truncate(Handle) ->
316318write ({Mod , Handle }, Data ) ->
317319 Mod :write (Handle , Data );
318320write (Handle , Data ) ->
319- file :write (Handle , Data ).
321+ ? DEFAULT_FILE :write (Handle , Data ).
320322
321323% % -spec try_write(module(), term(), iodata()) ->
322324% % ok | {error, term()}.
@@ -329,25 +331,23 @@ write(Handle, Data) ->
329331% % end.
330332
331333
334+ % % TODO code below just hack to make it work for now.
332335-spec get_mod () -> module ().
333336
334337get_mod () ->
335- get_mod ( file ).
338+ ? DEFAULT_FILE ;
336339
337- get_mod (file ) ->
338- % % TODO. This will figure out the correct module to use, based on
339- % % info in the magical manifest file.
340- file ;
341340get_mod (prim_file ) ->
342341 % % Just temporary solutin till I figure out why
343342 % % we even use prim_file?
344- prim_file ;
343+ % % prim_file;
344+ ? DEFAULT_FILE ;
345345get_mod (File ) ->
346346 case filelib :is_file (File ) of
347347 true ->
348- file ;
348+ ? DEFAULT_FILE ;
349349 false ->
350- application :get_env (osiris , io_segment_module , file )
350+ application :get_env (osiris , io_segment_module , ? DEFAULT_FILE )
351351 end .
352352
353353
@@ -356,7 +356,7 @@ get_mod(prim_file, File) ->
356356 % % we even use prim_file?
357357 case filelib :is_file (File ) of
358358 true ->
359- prim_file ;
359+ ? DEFAULT_FILE ;
360360 false ->
361- application :get_env (osiris , io_segment_module , prim_file )
361+ application :get_env (osiris , io_segment_module , ? DEFAULT_FILE )
362362 end .
0 commit comments