diff options
author | 2010-11-25 21:43:18 +0000 | |
---|---|---|
committer | 2010-11-25 21:43:18 +0000 | |
commit | e9fb16a16c005848e20ffd2c65c3cb9db69c2ad9 (patch) | |
tree | 1841b91419100ea388efc6343a26c4aab5f275c4 | |
parent | cc200cc8be80e8309f0a00fe5a33acc7d93d5ddf (diff) | |
download | paludis-e9fb16a16c005848e20ffd2c65c3cb9db69c2ad9.tar.gz paludis-e9fb16a16c005848e20ffd2c65c3cb9db69c2ad9.tar.xz |
cave owner --dereference
Fixes: ticket:1044
-rw-r--r-- | src/clients/cave/cmd_owner.cc | 8 | ||||
-rw-r--r-- | src/clients/cave/cmd_print_owners.cc | 2 | ||||
-rw-r--r-- | src/clients/cave/owner_common.cc | 13 | ||||
-rw-r--r-- | src/clients/cave/owner_common.hh | 1 |
4 files changed, 21 insertions, 3 deletions
diff --git a/src/clients/cave/cmd_owner.cc b/src/clients/cave/cmd_owner.cc index 82abc7f20..9361f9091 100644 --- a/src/clients/cave/cmd_owner.cc +++ b/src/clients/cave/cmd_owner.cc @@ -64,6 +64,7 @@ namespace args::ArgsGroup g_owner_options; args::EnumArg a_match; + args::SwitchArg a_dereference; OwnerCommandLine() : g_owner_options(main_options_section(), "Owner options", "Alter how the search is performed."), @@ -73,7 +74,9 @@ namespace ("basename", "Basename match") ("full", "Full match") ("partial", "Partial match"), - "auto") + "auto"), + a_dereference(&g_owner_options, "dereference", 'd', "If the pattern is a path that exists and is a symbolic link, " + "dereference it recursively, and then search for the real path.", true) { add_usage_line("[ --match algorithm ] pattern"); } @@ -103,7 +106,8 @@ OwnerCommand::run( if (std::distance(cmdline.begin_parameters(), cmdline.end_parameters()) != 1) throw args::DoHelp("owner takes exactly one parameter"); - return owner_common(env, cmdline.a_match.argument(), *cmdline.begin_parameters(), &format_id); + return owner_common(env, cmdline.a_match.argument(), *cmdline.begin_parameters(), + cmdline.a_dereference.specified(), &format_id); } std::shared_ptr<args::ArgsHandler> diff --git a/src/clients/cave/cmd_print_owners.cc b/src/clients/cave/cmd_print_owners.cc index 462439962..15d5afa91 100644 --- a/src/clients/cave/cmd_print_owners.cc +++ b/src/clients/cave/cmd_print_owners.cc @@ -92,7 +92,7 @@ PrintOwnersCommand::run( if (std::distance(cmdline.begin_parameters(), cmdline.end_parameters()) != 1) throw args::DoHelp("print-owners takes exactly one parameter"); - return owner_common(env, cmdline.a_match.argument(), *cmdline.begin_parameters(), &print_package_id); + return owner_common(env, cmdline.a_match.argument(), *cmdline.begin_parameters(), false, &print_package_id); } std::shared_ptr<args::ArgsHandler> diff --git a/src/clients/cave/owner_common.cc b/src/clients/cave/owner_common.cc index b051c146e..156c4a1c3 100644 --- a/src/clients/cave/owner_common.cc +++ b/src/clients/cave/owner_common.cc @@ -33,6 +33,7 @@ #include <paludis/selection.hh> #include <paludis/util/indirect_iterator-impl.hh> #include <paludis/util/wrapped_forward_iterator.hh> +#include <paludis/util/fs_stat.hh> #include <algorithm> #include <functional> @@ -61,12 +62,24 @@ paludis::cave::owner_common( const std::shared_ptr<Environment> & env, const std::string & match, const std::string & q, + const bool dereference, const std::function<void (const std::shared_ptr<const PackageID> &)> & callback) { bool found(false); std::function<bool (const std::string &, const std::shared_ptr<const ContentsEntry> &)> handler; std::string query(q); + if (dereference) + { + FSPath query_path(query); + FSStat query_path_stat(query_path); + if (query_path_stat.exists()) + { + if (query_path_stat.is_symlink()) + query = stringify(query_path.realpath_if_exists()); + } + } + if (query.length() >= 2 && '/' == query.at(query.length() - 1)) query.erase(query.length() - 1); diff --git a/src/clients/cave/owner_common.hh b/src/clients/cave/owner_common.hh index 12dabc8f6..3181fd725 100644 --- a/src/clients/cave/owner_common.hh +++ b/src/clients/cave/owner_common.hh @@ -36,6 +36,7 @@ namespace paludis const std::shared_ptr<Environment> & env, const std::string & match, const std::string & query, + const bool dereference, const std::function<void (const std::shared_ptr<const PackageID> &)> &); } } |