aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrik Nyblom <[email protected]>2010-11-30 12:31:33 +0100
committerPatrik Nyblom <[email protected]>2010-11-30 16:38:22 +0100
commitb21d33041ef30182cbb8e74c0023dc282d069a26 (patch)
tree429cd1c57ed2c39503e69c964846a366ec8e350f
parentc9d45aa9f32a76a4b08edd1d6010764d9ab02f9b (diff)
downloadotp-b21d33041ef30182cbb8e74c0023dc282d069a26.tar.gz
otp-b21d33041ef30182cbb8e74c0023dc282d069a26.tar.bz2
otp-b21d33041ef30182cbb8e74c0023dc282d069a26.zip
Teach filelib to use re in unicode mode when filenames are not raw
-rwxr-xr-xerts/emulator/drivers/win32/win_efile.c3
-rw-r--r--erts/test/z_SUITE.erl2
-rw-r--r--lib/kernel/test/file_name_SUITE.erl84
-rw-r--r--lib/stdlib/src/filelib.erl29
4 files changed, 79 insertions, 39 deletions
diff --git a/erts/emulator/drivers/win32/win_efile.c b/erts/emulator/drivers/win32/win_efile.c
index d0f13437dc..4ec9579529 100755
--- a/erts/emulator/drivers/win32/win_efile.c
+++ b/erts/emulator/drivers/win32/win_efile.c
@@ -1519,9 +1519,6 @@ efile_altname(Efile_error* errInfo, char* orig_name, char* buffer, size_t size)
return 1;
}
-/*
- * XXX: link and symlink Implemented in pu (?), will need conversion
- */
int
efile_link(Efile_error* errInfo, char* old, char* new)
diff --git a/erts/test/z_SUITE.erl b/erts/test/z_SUITE.erl
index 8faddeb0d3..9f13a7083d 100644
--- a/erts/test/z_SUITE.erl
+++ b/erts/test/z_SUITE.erl
@@ -253,6 +253,8 @@ core_file_search(#core_search_conf{search_dir = Base,
core_cand(Conf, Core, Cores);
"core." ++ _ ->
core_cand(Conf, Core, Cores);
+ Bin when is_binary(Bin) -> %Icky filename; ignore
+ Cores;
BName ->
case lists:suffix(".core", BName) of
true -> core_cand(Conf, Core, Cores);
diff --git a/lib/kernel/test/file_name_SUITE.erl b/lib/kernel/test/file_name_SUITE.erl
index 3faae93bea..d91bc32d11 100644
--- a/lib/kernel/test/file_name_SUITE.erl
+++ b/lib/kernel/test/file_name_SUITE.erl
@@ -140,36 +140,46 @@ icky(suite) ->
icky(doc) ->
"Check file operations on normal file names regardless of unicode mode";
icky(Config) when is_list(Config) ->
- {ok,Dir} = file:get_cwd(),
- try
- Priv = ?config(priv_dir, Config),
- file:set_cwd(Priv),
- put(file_module,prim_file),
- ok = check_icky(prim_file),
- put(file_module,file),
- ok = check_icky(file)
- after
- file:set_cwd(Dir)
+ case hopeless_darwin() of
+ true ->
+ {skipped,"This version of darwin does not support icky names at all."};
+ false ->
+ {ok,Dir} = file:get_cwd(),
+ try
+ Priv = ?config(priv_dir, Config),
+ file:set_cwd(Priv),
+ put(file_module,prim_file),
+ ok = check_icky(prim_file),
+ put(file_module,file),
+ ok = check_icky(file)
+ after
+ file:set_cwd(Dir)
+ end
end.
very_icky(suite) ->
[];
very_icky(doc) ->
"Check file operations on normal file names regardless of unicode mode";
very_icky(Config) when is_list(Config) ->
- {ok,Dir} = file:get_cwd(),
- try
- Priv = ?config(priv_dir, Config),
- file:set_cwd(Priv),
- put(file_module,prim_file),
- case check_very_icky(prim_file) of
- need_unicode_mode ->
- {skipped,"VM needs to be started in Unicode filename mode"};
- ok ->
- put(file_module,file),
- ok = check_very_icky(file)
- end
- after
- file:set_cwd(Dir)
+ case hopeless_darwin() of
+ true ->
+ {skipped,"This version of darwin does not support icky names at all."};
+ false ->
+ {ok,Dir} = file:get_cwd(),
+ try
+ Priv = ?config(priv_dir, Config),
+ file:set_cwd(Priv),
+ put(file_module,prim_file),
+ case check_very_icky(prim_file) of
+ need_unicode_mode ->
+ {skipped,"VM needs to be started in Unicode filename mode"};
+ ok ->
+ put(file_module,file),
+ ok = check_very_icky(file)
+ end
+ after
+ file:set_cwd(Dir)
+ end
end.
@@ -481,6 +491,21 @@ check_very_icky(Mod) ->
FI#file_info{mode = NewMode2}),
?line {ok,#file_info{mode = NewMode2}} =
Mod:read_file_info([956,965,963,954,959,49]),
+ ?line NumOK0 = case has_links() of
+ true -> 5;
+ false -> 3
+ end,
+ ?line NumNOK0 = case has_links() of
+ true -> 4;
+ false -> 3
+ end,
+ ?line {NumOK,NumNOK} = case is_binary(treat_icky(<<"foo">>)) of
+ false ->
+ {NumOK0+NumNOK0,0};
+ true ->
+ {NumOK0,NumNOK0}
+ end,
+ ?line {NumOK,NumNOK} = filelib:fold_files(".",".*",true,fun(_F,{N,M}) when is_list(_F) -> io:format("~ts~n",[_F]),{N+1,M}; (_F,{N,M}) -> io:format("~p~n",[_F]),{N,M+1} end,{0,0}),
ok
catch
throw:need_unicode_mode ->
@@ -548,6 +573,7 @@ rm_r2(Mod,Dir) ->
chk_cre_dir(_,[]) ->
ok;
chk_cre_dir(Mod,[{regular,Name,Content}|T]) ->
+ %io:format("~p~n",[Name]),
ok = Mod:write_file(Name,Content),
chk_cre_dir(Mod,T);
chk_cre_dir(Mod,[{link,Name,Target}|T]) ->
@@ -558,7 +584,9 @@ chk_cre_dir(Mod,[{symlink,Name,Target}|T]) ->
chk_cre_dir(Mod,T);
chk_cre_dir(Mod,[{directory,Name,Content}|T]) ->
ok = Mod:make_dir(Name),
+ %io:format("Content = ~p~n",[Content]),
Content2 = [{Ty,filename:join(Name,N),case Ty of link -> filename:join(Name,C); _ -> C end} || {Ty,N,C} <- Content ],
+ %io:format("Content2 = ~p~n",[Content2]),
chk_cre_dir(Mod,Content2),
chk_cre_dir(Mod,T).
@@ -627,6 +655,14 @@ linkify(Passed,[{directory, Name, Content}|T]) ->
linkify(Passed,[H|T]) ->
[H|linkify([H|Passed],T)].
+hopeless_darwin() ->
+ case {os:type(),os:version()} of
+ {{unix,darwin},{Major,_,_}} when Major < 9 ->
+ true;
+ _ ->
+ false
+ end.
+
icky_dir() ->
[{regular,"fil1","fil1"},
{regular,"���2","���2"}] ++
diff --git a/lib/stdlib/src/filelib.erl b/lib/stdlib/src/filelib.erl
index d5ddf9ed7e..eaaca750ab 100644
--- a/lib/stdlib/src/filelib.erl
+++ b/lib/stdlib/src/filelib.erl
@@ -166,36 +166,41 @@ do_is_regular(File, Mod) ->
%% If <Recursive> is true all sub-directories to <Dir> are processed
do_fold_files(Dir, RegExp, Recursive, Fun, Acc, Mod) ->
- {ok, Re1} = re:compile(RegExp),
- do_fold_files1(Dir, Re1, Recursive, Fun, Acc, Mod).
+ {ok, Re1} = re:compile(RegExp,[unicode]),
+ do_fold_files1(Dir, Re1, RegExp, Recursive, Fun, Acc, Mod).
-do_fold_files1(Dir, RegExp, Recursive, Fun, Acc, Mod) ->
+do_fold_files1(Dir, RegExp, OrigRE, Recursive, Fun, Acc, Mod) ->
case eval_list_dir(Dir, Mod) of
- {ok, Files} -> do_fold_files2(Files, Dir, RegExp, Recursive, Fun, Acc, Mod);
+ {ok, Files} -> do_fold_files2(Files, Dir, RegExp, OrigRE,
+ Recursive, Fun, Acc, Mod);
{error, _} -> Acc
end.
-do_fold_files2([], _Dir, _RegExp, _Recursive, _Fun, Acc, _Mod) ->
+%% OrigRE is not to be compiled as it's for non conforming filenames,
+%% i.e. for filenames that does not comply to the current encoding, which should
+%% be very rare. We use it only in those cases and do not want to precompile.
+do_fold_files2([], _Dir, _RegExp, _OrigRE, _Recursive, _Fun, Acc, _Mod) ->
Acc;
-do_fold_files2([File|T], Dir, RegExp, Recursive, Fun, Acc0, Mod) ->
+do_fold_files2([File|T], Dir, RegExp, OrigRE, Recursive, Fun, Acc0, Mod) ->
FullName = filename:join(Dir, File),
case do_is_regular(FullName, Mod) of
true ->
- case re:run(File, RegExp, [{capture,none}]) of
+ case re:run(File, if is_binary(File) -> OrigRE; true -> RegExp end,
+ [{capture,none}]) of
match ->
Acc = Fun(FullName, Acc0),
- do_fold_files2(T, Dir, RegExp, Recursive, Fun, Acc, Mod);
+ do_fold_files2(T, Dir, RegExp, OrigRE, Recursive, Fun, Acc, Mod);
nomatch ->
- do_fold_files2(T, Dir, RegExp, Recursive, Fun, Acc0, Mod)
+ do_fold_files2(T, Dir, RegExp, OrigRE, Recursive, Fun, Acc0, Mod)
end;
false ->
case Recursive andalso do_is_dir(FullName, Mod) of
true ->
- Acc1 = do_fold_files1(FullName, RegExp, Recursive,
+ Acc1 = do_fold_files1(FullName, RegExp, OrigRE, Recursive,
Fun, Acc0, Mod),
- do_fold_files2(T, Dir, RegExp, Recursive, Fun, Acc1, Mod);
+ do_fold_files2(T, Dir, RegExp, OrigRE, Recursive, Fun, Acc1, Mod);
false ->
- do_fold_files2(T, Dir, RegExp, Recursive, Fun, Acc0, Mod)
+ do_fold_files2(T, Dir, RegExp, OrigRE, Recursive, Fun, Acc0, Mod)
end
end.