diff options
author | Björn Gustavsson <[email protected]> | 2014-05-08 10:49:54 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2014-05-08 10:49:54 +0200 |
commit | 6bf1835ac2d6f4db6c266b2df6167f8a10e95c92 (patch) | |
tree | 5b8151cfc171e1d3d460063264acfb561289dca5 /lib/stdlib/test | |
parent | 57625b3220ed23935c2e8154a7f199e294d0741d (diff) | |
parent | f11aabdc9fec593c31e6c4f3fa25c1707e9c35df (diff) | |
download | otp-6bf1835ac2d6f4db6c266b2df6167f8a10e95c92.tar.gz otp-6bf1835ac2d6f4db6c266b2df6167f8a10e95c92.tar.bz2 otp-6bf1835ac2d6f4db6c266b2df6167f8a10e95c92.zip |
Merge branch 'bjorn/stdlib/file_lib-wildcard/OTP-11850' into maint
* bjorn/stdlib/file_lib-wildcard/OTP-11850:
filelib:wildcard() should show broken symlinks
Diffstat (limited to 'lib/stdlib/test')
-rw-r--r-- | lib/stdlib/test/filelib_SUITE.erl | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/lib/stdlib/test/filelib_SUITE.erl b/lib/stdlib/test/filelib_SUITE.erl index 4a67d68428..8203a03a7a 100644 --- a/lib/stdlib/test/filelib_SUITE.erl +++ b/lib/stdlib/test/filelib_SUITE.erl @@ -23,7 +23,7 @@ init_per_group/2,end_per_group/2, init_per_testcase/2,end_per_testcase/2, wildcard_one/1,wildcard_two/1,wildcard_errors/1, - fold_files/1,otp_5960/1,ensure_dir_eexist/1]). + fold_files/1,otp_5960/1,ensure_dir_eexist/1,symlinks/1]). -import(lists, [foreach/2]). @@ -43,7 +43,7 @@ suite() -> [{ct_hooks,[ts_install_cth]}]. all() -> [wildcard_one, wildcard_two, wildcard_errors, - fold_files, otp_5960, ensure_dir_eexist]. + fold_files, otp_5960, ensure_dir_eexist, symlinks]. groups() -> []. @@ -366,3 +366,39 @@ ensure_dir_eexist(Config) when is_list(Config) -> ?line {error, eexist} = filelib:ensure_dir(NeedFile), ?line {error, eexist} = filelib:ensure_dir(NeedFileB), ok. + +symlinks(Config) when is_list(Config) -> + PrivDir = ?config(priv_dir, Config), + Dir = filename:join(PrivDir, ?MODULE_STRING++"_symlinks"), + SubDir = filename:join(Dir, "sub"), + AFile = filename:join(SubDir, "a_file"), + Alias = filename:join(Dir, "symlink"), + ok = file:make_dir(Dir), + ok = file:make_dir(SubDir), + ok = file:write_file(AFile, "not that big\n"), + case file:make_symlink(AFile, Alias) of + {error, enotsup} -> + {skip, "Links not supported on this platform"}; + {error, eperm} -> + {win32,_} = os:type(), + {skip, "Windows user not privileged to create symlinks"}; + ok -> + ["sub","symlink"] = + basenames(Dir, filelib:wildcard(filename:join(Dir, "*"))), + ["symlink"] = + basenames(Dir, filelib:wildcard(filename:join(Dir, "symlink"))), + ok = file:delete(AFile), + %% The symlink should still be visible even when its target + %% has been deleted. + ["sub","symlink"] = + basenames(Dir, filelib:wildcard(filename:join(Dir, "*"))), + ["symlink"] = + basenames(Dir, filelib:wildcard(filename:join(Dir, "symlink"))), + ok + end. + +basenames(Dir, Files) -> + [begin + Dir = filename:dirname(F), + filename:basename(F) + end || F <- Files]. |