Browse Source

refactor writing to WriteToStatusFd()

tags/debian/0.9.13.exp1
Michael Vogt 8 years ago
parent
commit
f9935b1c33
2 changed files with 19 additions and 14 deletions
  1. +16
    -14
      apt-pkg/iprogress.cc
  2. +3
    -0
      apt-pkg/iprogress.h

+ 16
- 14
apt-pkg/iprogress.cc View File

@@ -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;
}



+ 3
- 0
apt-pkg/iprogress.h View File

@@ -54,9 +54,12 @@ namespace Progress {
int OutStatusFd;
int StepsDone;
int StepsTotal;
void WriteToStatusFd(std::string msg);

public:
PackageManagerProgressFd(int progress_fd);

// FIXME: rename to Start/Stop to match the pkgAcquireStatus
virtual void Started();
virtual void Finished();



Loading…
Cancel
Save