Merge pull request #11010 from zhongwencool/fs-delete-SUITE-data

chore: delete emqx_utils_fs_SUITE_data dir
This commit is contained in:
Ilya Averyanov 2023-06-12 10:40:48 +03:00 committed by GitHub
commit bf2c768182
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 84 additions and 8 deletions

View File

@ -26,6 +26,51 @@
all() -> all() ->
emqx_common_test_helpers:all(?MODULE). emqx_common_test_helpers:all(?MODULE).
%% a
%% b
%% foo
%% 42
%% Я
%% link -> ../c
%% c
%% bar
%%
%% link -> ../a
%% d
%% e
%% baz
%% needle
%% haystack
init_per_suite(Config) ->
Root = ?config(data_dir, Config),
A = filename:join([Root, "a", "b", "foo"]),
C = filename:join([Root, "c", "bar"]),
D = filename:join([Root, "d", "e", "baz"]),
F42 = filename:join([A, "42"]),
F42_1 = filename:join([A, "Я"]),
FBar = filename:join([C, "中文"]),
FNeedle = filename:join([D, "needle"]),
FHayStack = filename:join([Root, "d", "haystack"]),
Files = [F42, F42_1, FBar, FNeedle, FHayStack],
lists:foreach(fun filelib:ensure_dir/1, Files),
%% create files
lists:foreach(fun(File) -> file:write_file(File, <<"">>, [write]) end, Files),
%% create links
ALink = filename:join([Root, "a", "link"]),
CLink = filename:join([Root, "c", "link"]),
make_symlink("../c", ALink),
make_symlink("../a", CLink),
Config.
end_per_suite(Config) ->
Root = ?config(data_dir, Config),
ok = file:del_dir_r(filename:join([Root, "a"])),
ok = file:del_dir_r(filename:join([Root, "c"])),
ok = file:del_dir_r(filename:join([Root, "d"])),
ok.
t_fold_single_level(Config) -> t_fold_single_level(Config) ->
Root = ?config(data_dir, Config), Root = ?config(data_dir, Config),
?assertMatch( ?assertMatch(
@ -248,3 +293,7 @@ cons(Entry, Acc) ->
sort(L) when is_list(L) -> sort(L) when is_list(L) ->
lists:sort(L). lists:sort(L).
make_symlink(FileOrDir, NewLink) ->
_ = file:delete(NewLink),
ok = file:make_symlink(FileOrDir, NewLink).

View File

@ -1 +0,0 @@
Zhōngwén

View File

@ -26,6 +26,33 @@
all() -> all() ->
emqx_common_test_helpers:all(?MODULE). emqx_common_test_helpers:all(?MODULE).
init_per_suite(Config) ->
Root = ?config(data_dir, Config),
D1 = filename:join([Root, "nonempty", "d1/"]),
D2 = filename:join([Root, "nonempty", "d2/"]),
F1 = filename:join([D1, "1"]),
F2 = filename:join([D1, "2"]),
DeepDir = filename:join([Root, "nonempty", "d2", "deep", "down/"]),
DeepFile = filename:join([DeepDir, "here"]),
Files = [F1, F2, DeepFile],
lists:foreach(fun filelib:ensure_dir/1, Files),
D1LinkMutrec = filename:join([D1, "mutrec"]),
D2LinkMutrec = filename:join([D2, "deep", "mutrec"]),
lists:foreach(fun(File) -> file:write_file(File, <<"">>, [write]) end, Files),
chmod_file(D1, 8#00777),
chmod_file(DeepFile, 8#00600),
make_symlink(DeepDir, D1LinkMutrec),
%% can't file:make_link("../../d1", D2Mutrec) on mac, return {error, eperm}
make_symlink("../../d1", D2LinkMutrec),
{ok, D2MutrecInfo} = file:read_link_info(D2LinkMutrec),
ct:pal("~ts 's file_info is ~p~n", [D2LinkMutrec, D2MutrecInfo]),
Config.
end_per_suite(Config) ->
Root = ?config(data_dir, Config),
ok = file:del_dir_r(filename:join([Root, "nonempty"])),
ok.
%% %%
t_traverse_dir(Config) -> t_traverse_dir(Config) ->
@ -115,3 +142,11 @@ t_canonicalize_non_utf8(_) ->
badarg, badarg,
emqx_utils_fs:canonicalize(<<128, 128, 128>>) emqx_utils_fs:canonicalize(<<128, 128, 128>>)
). ).
chmod_file(File, Mode) ->
{ok, FileInfo} = file:read_file_info(File),
ok = file:write_file_info(File, FileInfo#file_info{mode = Mode}).
make_symlink(FileOrDir, NewLink) ->
_ = file:delete(NewLink),
ok = file:make_symlink(FileOrDir, NewLink).

View File

@ -1 +0,0 @@
../d2/deep/down