summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandru Scvortov <alexandru@rabbitmq.com>2011-09-07 15:57:49 +0100
committerAlexandru Scvortov <alexandru@rabbitmq.com>2011-09-07 15:57:49 +0100
commit2b32a5680e29158fa561f64b154f49fb4733fce7 (patch)
tree2cdea9b10eef816899db774e4bb48355e7a2df98
parent9acf13278d94ccf7f16dc138988b918b89794623 (diff)
downloadrabbitmq-server-2b32a5680e29158fa561f64b154f49fb4733fce7.tar.gz
remove specs so that file2 and filelib2 compile on R12B-5
Also, forward-port the file:file_name/1 from R12B-5, because the one in R14 uses a bif not available in R12.
-rw-r--r--src/file2.erl359
-rw-r--r--src/filelib2.erl32
2 files changed, 10 insertions, 381 deletions
diff --git a/src/file2.erl b/src/file2.erl
index b58198b0..00c3be3f 100644
--- a/src/file2.erl
+++ b/src/file2.erl
@@ -1,5 +1,6 @@
%% This is a version of 'file' from R14B03, which runs calls to
-%% file_server2 thorugh the worker_pool.
+%% file_server2 thorugh the worker_pool and uses the file_name/1
+%% function from R12B-5.
%%
%% %CopyrightBegin%
@@ -78,51 +79,11 @@
-define(RAM_FILE, ram_file). % Module
%% data types
--type filename() :: string() | binary().
--type file_info() :: #file_info{}.
--type fd() :: #file_descriptor{}.
--type io_device() :: pid() | fd().
--type location() :: integer() | {'bof', Offset :: integer()}
- | {'cur', Offset :: integer()}
- | {'eof', Offset :: integer()} | 'bof' | 'cur' | 'eof'.
--type mode() :: 'read' | 'write' | 'append'
- | 'exclusive' | 'raw' | 'binary'
- | {'delayed_write',
- Size :: non_neg_integer(),
- Delay :: non_neg_integer()}
- | 'delayed_write' | {'read_ahead', Size :: pos_integer()}
- | 'read_ahead' | 'compressed'
- | {'encoding', unicode:encoding()}.
-type deep_list() :: [char() | atom() | deep_list()].
--type name() :: string() | atom() | deep_list() | (RawFilename :: binary()).
--type posix() :: 'eacces' | 'eagain' | 'ebadf' | 'ebusy' | 'edquot'
- | 'eexist' | 'efault' | 'efbig' | 'eintr' | 'einval'
- | 'eio' | 'eisdir' | 'eloop' | 'emfile' | 'emlink'
- | 'enametoolong'
- | 'enfile' | 'enodev' | 'enoent' | 'enomem' | 'enospc'
- | 'enotblk' | 'enotdir' | 'enotsup' | 'enxio' | 'eperm'
- | 'epipe' | 'erofs' | 'espipe' | 'esrch' | 'estale'
- | 'exdev'.
--type bindings() :: erl_eval:binding_struct().
-
--type date() :: {Year :: pos_integer(),
- Month :: pos_integer(),
- Day ::pos_integer()}.
--type time() :: {Hour :: non_neg_integer(),
- Minute :: non_neg_integer(),
- Second :: non_neg_integer()}.
--type date_time() :: {date(), time()}.
--type posix_file_advise() :: 'normal' | 'sequential' | 'random'
- | 'no_reuse' | 'will_need' | 'dont_need'.
%%%-----------------------------------------------------------------
%%% General functions
--spec format_error(Reason) -> Chars when
- Reason :: posix() | badarg | terminated | system_limit
- | {Line :: integer(), Mod :: module(), Term :: term()},
- Chars :: string().
-
format_error({_Line, ?MODULE, undefined_script}) ->
"no value returned from script";
format_error({Line, ?MODULE, {Class, Reason, Stacktrace}}) ->
@@ -142,10 +103,6 @@ format_error(terminated) ->
format_error(ErrorId) ->
erl_posix_msg:message(ErrorId).
--spec pid2name(Pid) -> {ok, Filename} | undefined when
- Filename :: filename(),
- Pid :: pid().
-
pid2name(Pid) when is_pid(Pid) ->
case whereis(?FILE_SERVER) of
undefined ->
@@ -163,62 +120,27 @@ pid2name(Pid) when is_pid(Pid) ->
%%% File server functions.
%%% Functions that do not operate on a single open file.
%%% Stateless.
--spec get_cwd() -> {ok, Dir} | {error, Reason} when
- Dir :: filename(),
- Reason :: posix().
-
get_cwd() ->
call(get_cwd, []).
--spec get_cwd(Drive) -> {ok, Dir} | {error, Reason} when
- Drive :: string(),
- Dir :: filename(),
- Reason :: posix() | badarg.
-
get_cwd(Drive) ->
check_and_call(get_cwd, [file_name(Drive)]).
--spec set_cwd(Dir) -> ok | {error, Reason} when
- Dir :: name(),
- Reason :: posix() | badarg.
-
set_cwd(Dirname) ->
check_and_call(set_cwd, [file_name(Dirname)]).
--spec delete(Filename) -> ok | {error, Reason} when
- Filename :: name(),
- Reason :: posix() | badarg.
-
delete(Name) ->
check_and_call(delete, [file_name(Name)]).
--spec rename(Source, Destination) -> ok | {error, Reason} when
- Source :: name(),
- Destination :: name(),
- Reason :: posix() | badarg.
-
rename(From, To) ->
check_and_call(rename, [file_name(From), file_name(To)]).
--spec make_dir(Dir) -> ok | {error, Reason} when
- Dir :: name(),
- Reason :: posix() | badarg.
-
make_dir(Name) ->
check_and_call(make_dir, [file_name(Name)]).
--spec del_dir(Dir) -> ok | {error, Reason} when
- Dir :: name(),
- Reason :: posix() | badarg.
-
del_dir(Name) ->
check_and_call(del_dir, [file_name(Name)]).
--spec read_file_info(Filename) -> {ok, FileInfo} | {error, Reason} when
- Filename :: name(),
- FileInfo :: file_info(),
- Reason :: posix() | badarg.
-
read_file_info(Name) ->
check_and_call(read_file_info, [file_name(Name)]).
@@ -227,67 +149,27 @@ read_file_info(Name) ->
altname(Name) ->
check_and_call(altname, [file_name(Name)]).
--spec read_link_info(Name) -> {ok, FileInfo} | {error, Reason} when
- Name :: name(),
- FileInfo :: file_info(),
- Reason :: posix() | badarg.
-
read_link_info(Name) ->
check_and_call(read_link_info, [file_name(Name)]).
--spec read_link(Name) -> {ok, Filename} | {error, Reason} when
- Name :: name(),
- Filename :: filename(),
- Reason :: posix() | badarg.
-
read_link(Name) ->
check_and_call(read_link, [file_name(Name)]).
--spec write_file_info(Filename, FileInfo) -> ok | {error, Reason} when
- Filename :: name(),
- FileInfo :: file_info(),
- Reason :: posix() | badarg.
-
write_file_info(Name, Info = #file_info{}) ->
check_and_call(write_file_info, [file_name(Name), Info]).
--spec list_dir(Dir) -> {ok, Filenames} | {error, Reason} when
- Dir :: name(),
- Filenames :: [filename()],
- Reason :: posix() | badarg.
-
list_dir(Name) ->
check_and_call(list_dir, [file_name(Name)]).
--spec read_file(Filename) -> {ok, Binary} | {error, Reason} when
- Filename :: name(),
- Binary :: binary(),
- Reason :: posix() | badarg | terminated | system_limit.
-
read_file(Name) ->
check_and_call(read_file, [file_name(Name)]).
--spec make_link(Existing, New) -> ok | {error, Reason} when
- Existing :: name(),
- New :: name(),
- Reason :: posix() | badarg.
-
make_link(Old, New) ->
check_and_call(make_link, [file_name(Old), file_name(New)]).
--spec make_symlink(Name1, Name2) -> ok | {error, Reason} when
- Name1 :: name(),
- Name2 :: name(),
- Reason :: posix() | badarg.
-
make_symlink(Old, New) ->
check_and_call(make_symlink, [file_name(Old), file_name(New)]).
--spec write_file(Filename, Bytes) -> ok | {error, Reason} when
- Filename :: name(),
- Bytes :: iodata(),
- Reason :: posix() | badarg | terminated | system_limit.
-
write_file(Name, Bin) ->
check_and_call(write_file, [file_name(Name), make_binary(Bin)]).
@@ -295,12 +177,6 @@ write_file(Name, Bin) ->
%% when it is time to change file server protocol again.
%% Meanwhile, it is implemented here, slightly less efficient.
--spec write_file(Filename, Bytes, Modes) -> ok | {error, Reason} when
- Filename :: name(),
- Bytes :: iodata(),
- Modes :: [mode()],
- Reason :: posix() | badarg | terminated | system_limit.
-
write_file(Name, Bin, ModeList) when is_list(ModeList) ->
case make_binary(Bin) of
B when is_binary(B) ->
@@ -353,12 +229,6 @@ raw_write_file_info(Name, #file_info{} = Info) ->
%% Contemporary mode specification - list of options
--spec open(Filename, Modes) -> {ok, IoDevice} | {error, Reason} when
- Filename :: name(),
- Modes :: [mode()],
- IoDevice :: io_device(),
- Reason :: posix() | badarg | system_limit.
-
open(Item, ModeList) when is_list(ModeList) ->
case lists:member(raw, ModeList) of
%% Raw file, use ?PRIM_FILE to handle this file
@@ -410,10 +280,6 @@ open(Item, Mode) ->
%%% The File argument must be either a Pid or a handle
%%% returned from ?PRIM_FILE:open.
--spec close(IoDevice) -> ok | {error, Reason} when
- IoDevice :: io_device(),
- Reason :: posix() | badarg | terminated.
-
close(File) when is_pid(File) ->
R = file_request(File, close),
case wait_file_reply(File, R) of
@@ -430,13 +296,6 @@ close(#file_descriptor{module = Module} = Handle) ->
close(_) ->
{error, badarg}.
--spec advise(IoDevice, Offset, Length, Advise) -> ok | {error, Reason} when
- IoDevice :: io_device(),
- Offset :: integer(),
- Length :: integer(),
- Advise :: posix_file_advise(),
- Reason :: posix() | badarg.
-
advise(File, Offset, Length, Advise) when is_pid(File) ->
R = file_request(File, {advise, Offset, Length, Advise}),
wait_file_reply(File, R);
@@ -445,12 +304,6 @@ advise(#file_descriptor{module = Module} = Handle, Offset, Length, Advise) ->
advise(_, _, _, _) ->
{error, badarg}.
--spec read(IoDevice, Number) -> {ok, Data} | eof | {error, Reason} when
- IoDevice :: io_device() | atom(),
- Number :: non_neg_integer(),
- Data :: string() | binary(),
- Reason :: posix() | badarg | terminated.
-
read(File, Sz) when (is_pid(File) orelse is_atom(File)), is_integer(Sz), Sz >= 0 ->
case io:request(File, {get_chars, '', Sz}) of
Data when is_list(Data); is_binary(Data) ->
@@ -464,11 +317,6 @@ read(#file_descriptor{module = Module} = Handle, Sz)
read(_, _) ->
{error, badarg}.
--spec read_line(IoDevice) -> {ok, Data} | eof | {error, Reason} when
- IoDevice :: io_device() | atom(),
- Data :: string() | binary(),
- Reason :: posix() | badarg | terminated.
-
read_line(File) when (is_pid(File) orelse is_atom(File)) ->
case io:request(File, {get_line, ''}) of
Data when is_list(Data); is_binary(Data) ->
@@ -481,13 +329,6 @@ read_line(#file_descriptor{module = Module} = Handle) ->
read_line(_) ->
{error, badarg}.
--spec pread(IoDevice, LocNums) -> {ok, DataL} | eof | {error, Reason} when
- IoDevice :: io_device(),
- LocNums :: [{Location :: location(), Number :: non_neg_integer()}],
- DataL :: [Data],
- Data :: string() | binary() | eof,
- Reason :: posix() | badarg | terminated.
-
pread(File, L) when is_pid(File), is_list(L) ->
pread_int(File, L, []);
pread(#file_descriptor{module = Module} = Handle, L) when is_list(L) ->
@@ -509,14 +350,6 @@ pread_int(File, [{At, Sz} | T], R) when is_integer(Sz), Sz >= 0 ->
pread_int(_, _, _) ->
{error, badarg}.
--spec pread(IoDevice, Location, Number) ->
- {ok, Data} | eof | {error, Reason} when
- IoDevice :: io_device(),
- Location :: location(),
- Number :: non_neg_integer(),
- Data :: string() | binary(),
- Reason :: posix() | badarg | terminated.
-
pread(File, At, Sz) when is_pid(File), is_integer(Sz), Sz >= 0 ->
R = file_request(File, {pread, At, Sz}),
wait_file_reply(File, R);
@@ -526,11 +359,6 @@ pread(#file_descriptor{module = Module} = Handle, Offs, Sz)
pread(_, _, _) ->
{error, badarg}.
--spec write(IoDevice, Bytes) -> ok | {error, Reason} when
- IoDevice :: io_device() | atom(),
- Bytes :: iodata(),
- Reason :: posix() | badarg | terminated.
-
write(File, Bytes) when (is_pid(File) orelse is_atom(File)) ->
case make_binary(Bytes) of
Bin when is_binary(Bin) ->
@@ -543,12 +371,6 @@ write(#file_descriptor{module = Module} = Handle, Bytes) ->
write(_, _) ->
{error, badarg}.
--spec pwrite(IoDevice, LocBytes) -> ok | {error, {N, Reason}} when
- IoDevice :: io_device(),
- LocBytes :: [{Location :: location(), Bytes :: iodata()}],
- N :: non_neg_integer(),
- Reason :: posix() | badarg | terminated.
-
pwrite(File, L) when is_pid(File), is_list(L) ->
pwrite_int(File, L, 0);
pwrite(#file_descriptor{module = Module} = Handle, L) when is_list(L) ->
@@ -568,12 +390,6 @@ pwrite_int(File, [{At, Bytes} | T], R) ->
pwrite_int(_, _, _) ->
{error, badarg}.
--spec pwrite(IoDevice, Location, Bytes) -> ok | {error, Reason} when
- IoDevice :: io_device(),
- Location :: location(),
- Bytes :: iodata(),
- Reason :: posix() | badarg | terminated.
-
pwrite(File, At, Bytes) when is_pid(File) ->
R = file_request(File, {pwrite, At, Bytes}),
wait_file_reply(File, R);
@@ -582,10 +398,6 @@ pwrite(#file_descriptor{module = Module} = Handle, Offs, Bytes) ->
pwrite(_, _, _) ->
{error, badarg}.
--spec datasync(IoDevice) -> ok | {error, Reason} when
- IoDevice :: io_device(),
- Reason :: posix() | badarg | terminated.
-
datasync(File) when is_pid(File) ->
R = file_request(File, datasync),
wait_file_reply(File, R);
@@ -594,10 +406,6 @@ datasync(#file_descriptor{module = Module} = Handle) ->
datasync(_) ->
{error, badarg}.
--spec sync(IoDevice) -> ok | {error, Reason} when
- IoDevice :: io_device(),
- Reason :: posix() | badarg | terminated.
-
sync(File) when is_pid(File) ->
R = file_request(File, sync),
wait_file_reply(File, R);
@@ -606,12 +414,6 @@ sync(#file_descriptor{module = Module} = Handle) ->
sync(_) ->
{error, badarg}.
--spec position(IoDevice, Location) -> {ok, NewPosition} | {error, Reason} when
- IoDevice :: io_device(),
- Location :: location(),
- NewPosition :: integer(),
- Reason :: posix() | badarg | terminated.
-
position(File, At) when is_pid(File) ->
R = file_request(File, {position,At}),
wait_file_reply(File, R);
@@ -620,10 +422,6 @@ position(#file_descriptor{module = Module} = Handle, At) ->
position(_, _) ->
{error, badarg}.
--spec truncate(IoDevice) -> ok | {error, Reason} when
- IoDevice :: io_device(),
- Reason :: posix() | badarg | terminated.
-
truncate(File) when is_pid(File) ->
R = file_request(File, truncate),
wait_file_reply(File, R);
@@ -632,27 +430,9 @@ truncate(#file_descriptor{module = Module} = Handle) ->
truncate(_) ->
{error, badarg}.
--spec copy(Source, Destination) -> {ok, BytesCopied} | {error, Reason} when
- Source :: io_device() | Filename | {Filename, Modes},
- Destination :: io_device() | Filename | {Filename, Modes},
- Filename :: name(),
- Modes :: [mode()],
- BytesCopied :: non_neg_integer(),
- Reason :: posix() | badarg | terminated.
-
copy(Source, Dest) ->
copy_int(Source, Dest, infinity).
--spec copy(Source, Destination, ByteCount) ->
- {ok, BytesCopied} | {error, Reason} when
- Source :: io_device() | Filename | {Filename, Modes},
- Destination :: io_device() | Filename | {Filename, Modes},
- Filename :: name(),
- Modes :: [mode()],
- ByteCount :: non_neg_integer() | infinity,
- BytesCopied :: non_neg_integer(),
- Reason :: posix() | badarg | terminated.
-
copy(Source, Dest, Length)
when is_integer(Length), Length >= 0;
is_atom(Length) ->
@@ -873,12 +653,6 @@ ipread_s32bu_p32bu_2(File,
%%% The following functions, built upon the other interface functions,
%%% provide a higher-lever interface to files.
--spec consult(Filename) -> {ok, Terms} | {error, Reason} when
- Filename :: name(),
- Terms :: [term()],
- Reason :: posix() | badarg | terminated | system_limit
- | {Line :: integer(), Mod :: module(), Term :: term()}.
-
consult(File) ->
case open(File, [read]) of
{ok, Fd} ->
@@ -889,15 +663,6 @@ consult(File) ->
Error
end.
--spec path_consult(Path, Filename) -> {ok, Terms, FullName} | {error, Reason} when
- Path :: [Dir],
- Dir :: name(),
- Filename :: name(),
- Terms :: [term()],
- FullName :: filename(),
- Reason :: posix() | badarg | terminated | system_limit
- | {Line :: integer(), Mod :: module(), Term :: term()}.
-
path_consult(Path, File) ->
case path_open(Path, File, [read]) of
{ok, Fd, Full} ->
@@ -913,20 +678,9 @@ path_consult(Path, File) ->
E2
end.
--spec eval(Filename) -> ok | {error, Reason} when
- Filename :: name(),
- Reason :: posix() | badarg | terminated | system_limit
- | {Line :: integer(), Mod :: module(), Term :: term()}.
-
eval(File) ->
eval(File, erl_eval:new_bindings()).
--spec eval(Filename, Bindings) -> ok | {error, Reason} when
- Filename :: name(),
- Bindings :: bindings(),
- Reason :: posix() | badarg | terminated | system_limit
- | {Line :: integer(), Mod :: module(), Term :: term()}.
-
eval(File, Bs) ->
case open(File, [read]) of
{ok, Fd} ->
@@ -937,25 +691,9 @@ eval(File, Bs) ->
Error
end.
--spec path_eval(Path, Filename) -> {ok, FullName} | {error, Reason} when
- Path :: [Dir :: name()],
- Filename :: name(),
- FullName :: filename(),
- Reason :: posix() | badarg | terminated | system_limit
- | {Line :: integer(), Mod :: module(), Term :: term()}.
-
path_eval(Path, File) ->
path_eval(Path, File, erl_eval:new_bindings()).
--spec path_eval(Path, Filename, Bindings) ->
- {ok, FullName} | {error, Reason} when
- Path :: [Dir :: name()],
- Filename :: name(),
- Bindings :: bindings(),
- FullName :: filename(),
- Reason :: posix() | badarg | terminated | system_limit
- | {Line :: integer(), Mod :: module(), Term :: term()}.
-
path_eval(Path, File, Bs) ->
case path_open(Path, File, [read]) of
{ok, Fd, Full} ->
@@ -971,22 +709,9 @@ path_eval(Path, File, Bs) ->
E2
end.
--spec script(Filename) -> {ok, Value} | {error, Reason} when
- Filename :: name(),
- Value :: term(),
- Reason :: posix() | badarg | terminated | system_limit
- | {Line :: integer(), Mod :: module(), Term :: term()}.
-
script(File) ->
script(File, erl_eval:new_bindings()).
--spec script(Filename, Bindings) -> {ok, Value} | {error, Reason} when
- Filename :: name(),
- Bindings :: bindings(),
- Value :: term(),
- Reason :: posix() | badarg | terminated | system_limit
- | {Line :: integer(), Mod :: module(), Term :: term()}.
-
script(File, Bs) ->
case open(File, [read]) of
{ok, Fd} ->
@@ -997,28 +722,9 @@ script(File, Bs) ->
Error
end.
--spec path_script(Path, Filename) ->
- {ok, Value, FullName} | {error, Reason} when
- Path :: [Dir :: name()],
- Filename :: name(),
- Value :: term(),
- FullName :: filename(),
- Reason :: posix() | badarg | terminated | system_limit
- | {Line :: integer(), Mod :: module(), Term :: term()}.
-
path_script(Path, File) ->
path_script(Path, File, erl_eval:new_bindings()).
--spec path_script(Path, Filename, Bindings) ->
- {ok, Value, FullName} | {error, Reason} when
- Path :: [Dir :: name()],
- Filename :: name(),
- Bindings :: bindings(),
- Value :: term(),
- FullName :: filename(),
- Reason :: posix() | badarg | terminated | system_limit
- | {Line :: integer(), Mod :: module(), Term :: term()}.
-
path_script(Path, File, Bs) ->
case path_open(Path, File, [read]) of
{ok,Fd,Full} ->
@@ -1042,15 +748,6 @@ path_script(Path, File, Bs) ->
%% Searches the Paths for file Filename which can be opened with Mode.
%% The path list is ignored if Filename contains an absolute path.
--spec path_open(Path, Filename, Modes) ->
- {ok, IoDevice, FullName} | {error, Reason} when
- Path :: [Dir :: name()],
- Filename :: name(),
- Modes :: [mode()],
- IoDevice :: io_device(),
- FullName :: filename(),
- Reason :: posix() | badarg | system_limit.
-
path_open(PathList, Name, Mode) ->
case file_name(Name) of
{error, _} = Error ->
@@ -1069,58 +766,26 @@ path_open(PathList, Name, Mode) ->
end
end.
--spec change_mode(Filename, Mode) -> ok | {error, Reason} when
- Filename :: name(),
- Mode :: integer(),
- Reason :: posix() | badarg.
-
change_mode(Name, Mode)
when is_integer(Mode) ->
write_file_info(Name, #file_info{mode=Mode}).
--spec change_owner(Filename, Uid) -> ok | {error, Reason} when
- Filename :: name(),
- Uid :: integer(),
- Reason :: posix() | badarg.
-
change_owner(Name, OwnerId)
when is_integer(OwnerId) ->
write_file_info(Name, #file_info{uid=OwnerId}).
--spec change_owner(Filename, Uid, Gid) -> ok | {error, Reason} when
- Filename :: name(),
- Uid :: integer(),
- Gid :: integer(),
- Reason :: posix() | badarg.
-
change_owner(Name, OwnerId, GroupId)
when is_integer(OwnerId), is_integer(GroupId) ->
write_file_info(Name, #file_info{uid=OwnerId, gid=GroupId}).
--spec change_group(Filename, Gid) -> ok | {error, Reason} when
- Filename :: name(),
- Gid :: integer(),
- Reason :: posix() | badarg.
-
change_group(Name, GroupId)
when is_integer(GroupId) ->
write_file_info(Name, #file_info{gid=GroupId}).
--spec change_time(Filename, Mtime) -> ok | {error, Reason} when
- Filename :: name(),
- Mtime :: date_time(),
- Reason :: posix() | badarg.
-
change_time(Name, Time)
when is_tuple(Time) ->
write_file_info(Name, #file_info{mtime=Time}).
--spec change_time(Filename, Atime, Mtime) -> ok | {error, Reason} when
- Filename :: name(),
- Atime :: date_time(),
- Mtime :: date_time(),
- Reason :: posix() | badarg.
-
change_time(Name, Atime, Mtime)
when is_tuple(Atime), is_tuple(Mtime) ->
write_file_info(Name, #file_info{atime=Atime, mtime=Mtime}).
@@ -1194,26 +859,22 @@ path_open_first([], _Name, _Mode, LastError) ->
%% Generates a flat file name from a deep list of atoms and
%% characters (integers).
-file_name(N) when is_binary(N) ->
- N;
file_name(N) ->
try
- file_name_1(N,file:native_name_encoding())
+ file_name_1(N)
catch Reason ->
{error, Reason}
end.
-file_name_1([C|T],latin1) when is_integer(C), C < 256->
- [C|file_name_1(T,latin1)];
-file_name_1([C|T],utf8) when is_integer(C) ->
- [C|file_name_1(T,utf8)];
-file_name_1([H|T],E) ->
- file_name_1(H,E) ++ file_name_1(T,E);
-file_name_1([],_) ->
+file_name_1([C|T]) when is_integer(C), C > 0, C =< 255 ->
+ [C|file_name_1(T)];
+file_name_1([H|T]) ->
+ file_name_1(H) ++ file_name_1(T);
+file_name_1([]) ->
[];
-file_name_1(N,_) when is_atom(N) ->
+file_name_1(N) when is_atom(N) ->
atom_to_list(N);
-file_name_1(_,_) ->
+file_name_1(_) ->
throw(badarg).
make_binary(Bin) when is_binary(Bin) ->
diff --git a/src/filelib2.erl b/src/filelib2.erl
index 146496f4..d3dabf05 100644
--- a/src/filelib2.erl
+++ b/src/filelib2.erl
@@ -43,19 +43,11 @@
erlang:error(UnUsUalVaRiAbLeNaMe)
end).
--type filename() :: file:name().
--type dirname() :: filename().
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--spec wildcard(Wildcard) -> [file:filename()] when
- Wildcard :: filename() | dirname().
wildcard(Pattern) when is_list(Pattern) ->
?HANDLE_ERROR(do_wildcard(Pattern, file)).
--spec wildcard(Wildcard, Cwd) -> [file:filename()] when
- Wildcard :: filename() | dirname(),
- Cwd :: dirname().
wildcard(Pattern, Cwd) when is_list(Pattern), (is_list(Cwd) or is_binary(Cwd)) ->
?HANDLE_ERROR(do_wildcard(Pattern, Cwd, file));
wildcard(Pattern, Mod) when is_list(Pattern), is_atom(Mod) ->
@@ -66,49 +58,30 @@ wildcard(Pattern, Cwd, Mod)
when is_list(Pattern), (is_list(Cwd) or is_binary(Cwd)), is_atom(Mod) ->
?HANDLE_ERROR(do_wildcard(Pattern, Cwd, Mod)).
--spec is_dir(Name) -> boolean() when
- Name :: filename() | dirname().
is_dir(Dir) ->
do_is_dir(Dir, file).
--spec is_dir(file:name(), atom()) -> boolean().
is_dir(Dir, Mod) when is_atom(Mod) ->
do_is_dir(Dir, Mod).
--spec is_file(Name) -> boolean() when
- Name :: filename() | dirname().
is_file(File) ->
do_is_file(File, file).
--spec is_file(file:name(), atom()) -> boolean().
is_file(File, Mod) when is_atom(Mod) ->
do_is_file(File, Mod).
--spec is_regular(Name) -> boolean() when
- Name :: filename().
is_regular(File) ->
do_is_regular(File, file).
--spec is_regular(file:name(), atom()) -> boolean().
is_regular(File, Mod) when is_atom(Mod) ->
do_is_regular(File, Mod).
--spec fold_files(Dir, RegExp, Recursive, Fun, AccIn) -> AccOut when
- Dir :: dirname(),
- RegExp :: string(),
- Recursive :: boolean(),
- Fun :: fun((F :: file:filename(), AccIn) -> AccOut),
- AccIn :: term(),
- AccOut :: term().
fold_files(Dir, RegExp, Recursive, Fun, Acc) ->
do_fold_files(Dir, RegExp, Recursive, Fun, Acc, file).
--spec fold_files(file:name(), string(), boolean(), fun((_,_) -> _), _, atom()) -> _.
fold_files(Dir, RegExp, Recursive, Fun, Acc, Mod) when is_atom(Mod) ->
do_fold_files(Dir, RegExp, Recursive, Fun, Acc, Mod).
--spec last_modified(Name) -> file:date_time() | 0 when
- Name :: filename() | dirname().
last_modified(File) ->
do_last_modified(File, file).
@@ -116,8 +89,6 @@ last_modified(File) ->
last_modified(File, Mod) when is_atom(Mod) ->
do_last_modified(File, Mod).
--spec file_size(Filename) -> non_neg_integer() when
- Filename :: filename().
file_size(File) ->
do_file_size(File, file).
@@ -257,9 +228,6 @@ do_file_size(File, Mod) ->
%% +type X = filename() | dirname()
%% ensures that the directory name required to create D exists
--spec ensure_dir(Name) -> 'ok' | {'error', Reason} when
- Name :: filename() | dirname(),
- Reason :: file:posix().
ensure_dir("/") ->
ok;
ensure_dir(F) ->