aboutsummaryrefslogtreecommitdiff
path: root/src/clients/cave/cmd_print_id_executables.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/clients/cave/cmd_print_id_executables.cc')
-rw-r--r--src/clients/cave/cmd_print_id_executables.cc91
1 files changed, 6 insertions, 85 deletions
diff --git a/src/clients/cave/cmd_print_id_executables.cc b/src/clients/cave/cmd_print_id_executables.cc
index 822821d..6610cf8 100644
--- a/src/clients/cave/cmd_print_id_executables.cc
+++ b/src/clients/cave/cmd_print_id_executables.cc
@@ -19,19 +19,10 @@
#include "cmd_print_id_executables.hh"
#include "command_command_line.hh"
+#include "executables_common.hh"
#include <paludis/args/args.hh>
#include <paludis/args/do_help.hh>
-#include <paludis/contents.hh>
-#include <paludis/environment.hh>
-#include <paludis/filter.hh>
-#include <paludis/filtered_generator.hh>
-#include <paludis/generator.hh>
-#include <paludis/metadata_key.hh>
-#include <paludis/package_database.hh>
-#include <paludis/package_id.hh>
-#include <paludis/selection.hh>
-#include <paludis/user_dep_spec.hh>
#include <paludis/util/fs_entry.hh>
#include <paludis/util/indirect_iterator-impl.hh>
#include <paludis/util/make_shared_ptr.hh>
@@ -76,56 +67,10 @@ namespace
}
};
- class ExecutablesDisplayer
+ void print_fsentry(const FSEntry & e)
{
- private:
- const std::set<std::string> & _paths;
-
- bool is_executable_in_path(const FSEntry & file)
- {
- try
- {
- return file.exists() &&
- (file.has_permission(fs_ug_owner, fs_perm_execute) ||
- file.has_permission(fs_ug_group, fs_perm_execute) ||
- file.has_permission(fs_ug_others, fs_perm_execute)) &&
- _paths.end() != _paths.find(stringify(file.dirname()));
- }
- catch (const paludis::FSError &)
- {
- return false;
- }
- }
-
- public:
- ExecutablesDisplayer(const std::set<std::string> & p) :
- _paths(p)
- {
- }
-
- void visit(const ContentsFileEntry & e)
- {
- if (is_executable_in_path(e.location_key()->value()))
- cout << e.location_key()->value() << endl;
- }
-
- void visit(const ContentsSymEntry & e)
- {
- FSEntry symlink(e.location_key()->value());
- FSEntry real_file(symlink.realpath_if_exists());
-
- if (symlink != real_file && is_executable_in_path(symlink))
- cout << e.location_key()->value() << endl;
- }
-
- void visit(const ContentsDirEntry &)
- {
- }
-
- void visit(const ContentsOtherEntry &)
- {
- }
- };
+ cout << e << endl;
+ }
}
int
@@ -146,32 +91,7 @@ PrintIDExecutablesCommand::run(
if (1 != std::distance(cmdline.begin_parameters(), cmdline.end_parameters()))
throw args::DoHelp("print-id-executables takes exactly one parameter");
- std::tr1::shared_ptr<const PackageIDSequence> entries(
- (*env)[selection::AllVersionsSorted(generator::Matches(
- PackageDepSpec(parse_user_package_dep_spec(
- *cmdline.begin_parameters(), env.get(),
- UserPackageDepSpecOptions() + updso_allow_wildcards,
- filter::InstalledAtRoot(env->root()))),
- MatchPackageOptions()) | filter::InstalledAtRoot(env->root()))]);
-
- if (entries->empty())
- throw NoSuchPackageError(*cmdline.begin_parameters());
-
- const std::string path(getenv_or_error("PATH"));
- std::set<std::string> paths;
- tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(path, ":", "", std::inserter(paths, paths.begin()));
- ExecutablesDisplayer ed(paths);
-
- for (PackageIDSequence::ConstIterator t(entries->begin()), t_end(entries->end()) ; t != t_end ; ++t)
- {
- if ((*t)->contents_key())
- {
- std::tr1::shared_ptr<const Contents> contents((*t)->contents_key()->value());
- std::for_each(indirect_iterator(contents->begin()), indirect_iterator(contents->end()), accept_visitor(ed));
- }
- }
-
- return EXIT_SUCCESS;
+ return executables_common(env, *cmdline.begin_parameters(), &print_fsentry);
}
std::tr1::shared_ptr<args::ArgsHandler>
@@ -179,3 +99,4 @@ PrintIDExecutablesCommand::make_doc_cmdline()
{
return make_shared_ptr(new PrintIDExecutablesCommandLine);
}
+