aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-07-14 19:53:36 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-07-14 20:20:48 +0100
commit594db2100920c1082b3527aa5f14282bbe659242 (patch)
tree4ab398acadb2b535746cee2c94d8e9f4c2903750
parent79a31da2b8271f688abf286de274cf9ed7929dc8 (diff)
downloadpaludis-594db2100920c1082b3527aa5f14282bbe659242.tar.gz
paludis-594db2100920c1082b3527aa5f14282bbe659242.tar.xz
Refactor
-rw-r--r--paludis/repositories/e/e_installed_repository.cc35
-rw-r--r--paludis/repositories/e/e_installed_repository.hh5
2 files changed, 29 insertions, 11 deletions
diff --git a/paludis/repositories/e/e_installed_repository.cc b/paludis/repositories/e/e_installed_repository.cc
index 0883ede..96b6680 100644
--- a/paludis/repositories/e/e_installed_repository.cc
+++ b/paludis/repositories/e/e_installed_repository.cc
@@ -41,6 +41,7 @@
#include <paludis/util/process.hh>
#include <paludis/util/fs_stat.hh>
#include <paludis/util/join.hh>
+#include <paludis/util/is_file_with_extension.hh>
#include <paludis/action.hh>
#include <paludis/package_id.hh>
@@ -200,22 +201,34 @@ EInstalledRepository::get_environment_variable(
}
else if ((ver_dir / "environment.bz2").stat().is_regular_file_or_symlink_to_regular_file())
{
- std::stringstream p;
- Process env_process(ProcessCommand({"bash", "-c", "( bunzip2 < " + stringify(ver_dir / "environment.bz2" ) +
- " ; echo echo \\$" + var + " ) | bash -O extglob 2>/dev/null"}));
- env_process.capture_stdout(p);
- int exit_status(env_process.run().wait());
- std::string result(strip_trailing_string(std::string(
- (std::istreambuf_iterator<char>(p)),
- std::istreambuf_iterator<char>()), "\n"));
- if (0 != exit_status)
- throw ActionFailedError("Could not load environment.bz2");
- return result;
+ return snoop_variable_from_environment_file(ver_dir / "environment.bz2", var);
}
else
throw ActionFailedError("Could not get variable '" + var + "' for '" + stringify(*id) + "'");
}
+std::string
+EInstalledRepository::snoop_variable_from_environment_file(
+ const FSPath & f,
+ const std::string & var) const
+{
+ std::string x("cat");
+ if (is_file_with_extension(f, ".bz2", { }))
+ x = "bunzip2";
+
+ std::stringstream p;
+ Process env_process(ProcessCommand({"bash", "-c", "( " + x + " < " + stringify(f) +
+ " ; echo echo \\$" + var + " ) | bash -O extglob 2>/dev/null"}));
+ env_process.capture_stdout(p);
+ int exit_status(env_process.run().wait());
+ std::string result(strip_trailing_string(std::string(
+ (std::istreambuf_iterator<char>(p)),
+ std::istreambuf_iterator<char>()), "\n"));
+ if (0 != exit_status)
+ throw ActionFailedError("Could not load environment.bz2");
+ return result;
+}
+
void
EInstalledRepository::perform_config(
const std::shared_ptr<const ERepositoryID> & id,
diff --git a/paludis/repositories/e/e_installed_repository.hh b/paludis/repositories/e/e_installed_repository.hh
index 43363dd..3656263 100644
--- a/paludis/repositories/e/e_installed_repository.hh
+++ b/paludis/repositories/e/e_installed_repository.hh
@@ -53,6 +53,11 @@ namespace paludis
EInstalledRepository(const EInstalledRepositoryParams &, const RepositoryName &, const RepositoryCapabilities &);
~EInstalledRepository();
+ std::string snoop_variable_from_environment_file(
+ const FSPath &,
+ const std::string & var) const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+
public:
/* RepositoryEnvironmentVariableInterface */