From 82982e037dea53b334070699471e682fb023dc9e Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 12 Dec 2022 13:25:19 +0300 Subject: Support detecting inaccessible/dangling entries in dir_iterator, path_search() --- tests/dir-iterator/driver.cxx | 13 +++++++++++-- tests/dir-iterator/testscript | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) (limited to 'tests/dir-iterator') diff --git a/tests/dir-iterator/driver.cxx b/tests/dir-iterator/driver.cxx index 4a2ff53..92b0b57 100644 --- a/tests/dir-iterator/driver.cxx +++ b/tests/dir-iterator/driver.cxx @@ -26,7 +26,7 @@ operator<< (ostream& os, entry_type e) return os << entry_type_string[static_cast (e)]; } -// Usage: argv[0] [-v] [-i] +// Usage: argv[0] [-v] [-i|-d] // // Iterates over a directory filesystem sub-entries, obtains their types and // target types for symlinks. @@ -45,6 +45,7 @@ main (int argc, const char* argv[]) bool verbose (false); bool ignore_dangling (false); + bool detect_dangling (false); int i (1); for (; i != argc; ++i) @@ -55,6 +56,8 @@ main (int argc, const char* argv[]) verbose = true; else if (v == "-i") ignore_dangling = true; + else if (v == "-d") + detect_dangling = true; else break; } @@ -65,11 +68,17 @@ main (int argc, const char* argv[]) return 1; } + assert (!ignore_dangling || !detect_dangling); + const char* d (argv[i]); try { - for (const dir_entry& de: dir_iterator (dir_path (d), ignore_dangling)) + for (const dir_entry& de: + dir_iterator (dir_path (d), + (ignore_dangling ? dir_iterator::ignore_dangling : + detect_dangling ? dir_iterator::detect_dangling : + dir_iterator::no_follow))) { entry_type lt (de.ltype ()); entry_type t (lt == entry_type::symlink ? de.type () : lt); diff --git a/tests/dir-iterator/testscript b/tests/dir-iterator/testscript index 30cf6d7..9ecc58b 100644 --- a/tests/dir-iterator/testscript +++ b/tests/dir-iterator/testscript @@ -54,6 +54,12 @@ if ($test.target == $build.host) $* ../wd >- 2>! != 0 : keep $* -i ../wd >'reg f': skip + + : detect + : + $* -d ../wd >>~%EOO% + %(reg f|sym unk l)%{2} + EOO } : dir @@ -71,6 +77,12 @@ if ($test.target == $build.host) $* ../wd >- 2>! != 0 : keep $* -i ../wd >'dir d': skip + + : detect + : + $* -d ../wd >>~%EOO% + %(dir d|sym unk l)%{2} + EOO } } @@ -89,5 +101,11 @@ if ($test.target == $build.host) $* ../wd >- 2>! != 0 : keep $* -i ../wd >'dir d': skip + + : detect + : + $* -d ../wd >>~%EOO% + %(dir d|sym unk l)%{2} + EOO } } -- cgit v1.1