diff options
author | Michael Vogt <mvo@debian.org> | 2013-10-14 07:40:56 +0200 |
---|---|---|
committer | Michael Vogt <mvo@debian.org> | 2013-10-14 07:40:56 +0200 |
commit | f9935b1c33203b9e47ca0ff5cb441c7963b19fbc (patch) | |
tree | 75ac19e193f571f41d0024651689b58190a31172 /apt-pkg/iprogress.cc | |
parent | ca5b257835578d98145becbc3d97505394a7726c (diff) |
refactor writing to WriteToStatusFd()
Diffstat (limited to 'apt-pkg/iprogress.cc')
-rw-r--r-- | apt-pkg/iprogress.cc | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/apt-pkg/iprogress.cc b/apt-pkg/iprogress.cc index 6c5d33d4a..7d1cc6341 100644 --- a/apt-pkg/iprogress.cc +++ b/apt-pkg/iprogress.cc @@ -33,19 +33,24 @@ PackageManagerProgressFd::PackageManagerProgressFd(int progress_fd) OutStatusFd = progress_fd; } +void PackageManagerProgressFd::WriteToStatusFd(std::string s) +{ + if(OutStatusFd <= 0) + return; + FileFd::Write(OutStatusFd, s.c_str(), s.size()); +} + void PackageManagerProgressFd::Started() { _config->Set("APT::Keep-Fds::", OutStatusFd); // send status information that we are about to fork dpkg - if(OutStatusFd > 0) { - std::ostringstream status; - status << "pmstatus:dpkg-exec:" - << (StepsDone/float(StepsTotal)*100.0) - << ":" << _("Running dpkg") - << std::endl; - FileFd::Write(OutStatusFd, status.str().c_str(), status.str().size()); - } + std::ostringstream status; + status << "pmstatus:dpkg-exec:" + << (StepsDone/float(StepsTotal)*100.0) + << ":" << _("Running dpkg") + << std::endl; + WriteToStatusFd(status.str()); } void PackageManagerProgressFd::Finished() @@ -64,8 +69,7 @@ void PackageManagerProgressFd::Error(std::string PackageName, << ":" << (StepsDone/float(TotalSteps)*100.0) << ":" << ErrorMessage << std::endl; - if(OutStatusFd > 0) - FileFd::Write(OutStatusFd, status.str().c_str(), status.str().size()); + WriteToStatusFd(status.str()); } void PackageManagerProgressFd::ConffilePrompt(std::string PackageName, @@ -78,8 +82,7 @@ void PackageManagerProgressFd::ConffilePrompt(std::string PackageName, << ":" << (StepsDone/float(TotalSteps)*100.0) << ":" << ConfMessage << std::endl; - if(OutStatusFd > 0) - FileFd::Write(OutStatusFd, status.str().c_str(), status.str().size()); + WriteToStatusFd(status.str()); } @@ -97,8 +100,7 @@ bool PackageManagerProgressFd::StatusChanged(std::string PackageName, << ":" << (StepsDone/float(StepsTotal)*100.0) << ":" << pkg_action << std::endl; - if(OutStatusFd > 0) - FileFd::Write(OutStatusFd, status.str().c_str(), status.str().size()); + WriteToStatusFd(status.str()); return true; } |