From f28eef6df2a9fd2befedacf8ccd6248e5b3618db Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 11 Oct 2013 22:05:38 +0200 Subject: add missing _() around the new "Progress" string --- apt-pkg/deb/dpkgpm.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index b4d812d26..c29d21574 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -901,7 +901,7 @@ void pkgDPkgPM::SendTerminalProgress(float percentage) return; std::string progress_str; - strprintf(progress_str, "Progress: [%3i%%]", (int)percentage); + strprintf(progress_str, _("Progress: [%3i%%]"), (int)percentage); if (d->fancy_progress_output) { int row = d->nr_terminal_rows; -- cgit v1.2.3-70-g09d2 From 7794a6880e74446075d9cae19525829ada5b0d91 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 13 Oct 2013 19:33:09 +0200 Subject: fix progress-segfault in case of dpkg errors/prompts Errors and conffile prompts have a fourth information piece, which the "old" code access which isn't provided by the "new" one. This isn't checking if the messages are really well-formed, so it could still segfault on misformed messages, but this code needs more work anyway, so one step at a time. Closes: 726047 --- apt-pkg/deb/dpkgpm.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index c29d21574..1fbeabbdc 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -546,8 +546,8 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) // A dpkg error message may contain additional ":" (like // "failed in buffer_write(fd) (10, ret=-1): backend dpkg-deb ..." // so we need to ensure to not split too much - std::vector list = StringSplit(line, ": ", 3); - if(list.size() != 3) + std::vector list = StringSplit(line, ": ", 4); + if(list.size() < 3) { if (Debug == true) std::clog << "ignoring line: not enough ':'" << std::endl; -- cgit v1.2.3-70-g09d2 From fd6417a6026401f95af82608e12b4a9d105b090f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 15 Oct 2013 15:39:59 +0200 Subject: fix logic for finding what package dpkg means in the --status-fd and only send out short packagenames --- apt-pkg/deb/dpkgpm.cc | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index b4d812d26..61d8eec02 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -557,11 +557,26 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) std::string pkgname = list[1]; if (pkgname.find(":") == std::string::npos) { - string const nativeArch = _config->Find("APT::Architecture"); - pkgname = pkgname + ":" + nativeArch; + // find the package in the group that is in a touched by dpkg + // if there are multiple dpkg will send us a full pkgname:arch + pkgCache::GrpIterator Grp = Cache.FindGrp(pkgname); + if (Grp.end() == false) + { + pkgCache::PkgIterator P = Grp.PackageList(); + for (; P.end() != true; P = Grp.NextPkg(P)) + { + if(Cache[P].Mode != pkgDepCache::ModeKeep) + { + pkgname = P.FullName(); + break; + } + } + } } const char* const pkg = pkgname.c_str(); const char* action = list[2].c_str(); + + std::string short_pkgname = StringSplit(pkgname, ":")[0]; // 'processing' from dpkg looks like // 'processing: action: pkg' @@ -640,7 +655,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) PackageOpsDone[pkg]++; PackagesDone++; // build the status str - status << "pmstatus:" << pkg + status << "pmstatus:" << short_pkgname << ":" << (PackagesDone/float(PackagesTotal)*100.0) << ":" << s << endl; @@ -653,7 +668,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) std::clog << "send: '" << status.str() << "'" << endl; } if (Debug == true) - std::clog << "(parsed from dpkg) pkg: " << pkg + std::clog << "(parsed from dpkg) pkg: " << short_pkgname << " action: " << action << endl; } /*}}}*/ -- cgit v1.2.3-70-g09d2 From 42c1513b712818823e0a136c949f0d93c46907d7 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 15 Oct 2013 18:07:44 +0200 Subject: tests, do not send pkgname with arch via the status-fd --- apt-pkg/deb/dpkgpm.cc | 2 +- test/integration/framework | 10 ++- test/integration/test-apt-progress-fd | 71 ++++++++++++++++++++++ test/integration/test-apt-progress-fd-error | 22 +++++++ .../test-apt-progress-fd-error-postinst | 22 +++++++ 5 files changed, 125 insertions(+), 2 deletions(-) create mode 100755 test/integration/test-apt-progress-fd create mode 100755 test/integration/test-apt-progress-fd-error create mode 100755 test/integration/test-apt-progress-fd-error-postinst (limited to 'apt-pkg') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index d18900b9c..fe38bf697 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -649,7 +649,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) // action const char *translation = _(states[PackageOpsDone[pkg]].str); char s[200]; - snprintf(s, sizeof(s), translation, pkg); + snprintf(s, sizeof(s), translation, short_pkgname.c_str()); // we moved from one dpkg state to a new one, report that PackageOpsDone[pkg]++; diff --git a/test/integration/framework b/test/integration/framework index d899bb574..0f57d0259 100644 --- a/test/integration/framework +++ b/test/integration/framework @@ -335,6 +335,7 @@ buildsimplenativepackage() { local SECTION="${7:-others}" local PRIORITY="${8:-optional}" + local FILE_TREE="$9" local DISTSECTION if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then DISTSECTION="main" @@ -391,9 +392,16 @@ Package: $NAME" >> ${BUILDDIR}/debian/control mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch} + if [ -n "$FILE_TREE" ]; then + cp -ar "$FILE_TREE" ${BUILDDIR}/debian/tmp + fi + if [ -n "$POSTINST" ]; then + echo "$POSTINST" > ${BUILDDIR}/debian/tmp/DEBIAN/postinst + chmod +x ${BUILDDIR}/debian/tmp/DEBIAN/postinst + fi + (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$arch) (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums) - dpkg-deb --build ${BUILDDIR}/debian/tmp ${BUILDDIR}/.. 2> /dev/null > /dev/null echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist done diff --git a/test/integration/test-apt-progress-fd b/test/integration/test-apt-progress-fd new file mode 100755 index 000000000..5f73c8f8c --- /dev/null +++ b/test/integration/test-apt-progress-fd @@ -0,0 +1,71 @@ +#!/bin/sh +set -e + +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework + +setupenvironment +configarchitecture 'amd64' 'i386' + +buildsimplenativepackage 'testing' 'amd64' '0.1' 'stable' +buildsimplenativepackage 'testing' 'amd64' '0.8.15' 'stable' +buildsimplenativepackage 'testing2' 'amd64,i386' '0.8.15' 'stable' +setupaptarchive + +# install native +exec 3> apt-progress.log +testsuccess aptget install testing=0.1 -y -o APT::Status-Fd=3 +testequal "dlstatus:1:0:Retrieving file 1 of 1 +dlstatus:1:0:Retrieving file 1 of 1 +pmstatus:dpkg-exec:0:Running dpkg +pmstatus:testing:0:Installing testing +pmstatus:testing:20:Preparing testing +pmstatus:testing:40:Unpacking testing +pmstatus:testing:60:Preparing to configure testing +pmstatus:dpkg-exec:60:Running dpkg +pmstatus:testing:60:Configuring testing +pmstatus:testing:80:Configuring testing +pmstatus:testing:100:Installed testing" cat apt-progress.log + +# upgrade +exec 3> apt-progress.log +testsuccess aptget install testing=0.8.15 -y -o APT::Status-Fd=3 +testequal "dlstatus:1:0:Retrieving file 1 of 1 +dlstatus:1:0:Retrieving file 1 of 1 +pmstatus:dpkg-exec:0:Running dpkg +pmstatus:testing:20:Preparing testing +pmstatus:testing:40:Unpacking testing +pmstatus:testing:60:Preparing to configure testing +pmstatus:dpkg-exec:60:Running dpkg +pmstatus:testing:60:Configuring testing +pmstatus:testing:80:Configuring testing +pmstatus:testing:100:Installed testing" cat apt-progress.log + +# and remove +exec 3> apt-progress.log +testsuccess aptget remove testing -y -o APT::Status-Fd=3 +testequal "pmstatus:dpkg-exec:0:Running dpkg +pmstatus:testing:0:Removing testing +pmstatus:testing:33.3333:Preparing for removal of testing +pmstatus:testing:66.6667:Removing testing +pmstatus:testing:100:Removed testing" cat apt-progress.log + + +# install non-native and ensure we get proper progress info +exec 3> apt-progress.log +testsuccess aptget install testing2:i386 -y -o APT::Status-Fd=3 + +# and compare +testequal "dlstatus:1:0:Retrieving file 1 of 1 +dlstatus:1:0:Retrieving file 1 of 1 +pmstatus:dpkg-exec:0:Running dpkg +pmstatus:testing2:0:Installing testing2 +pmstatus:testing2:20:Preparing testing2 +pmstatus:testing2:40:Unpacking testing2 +pmstatus:testing2:60:Preparing to configure testing2 +pmstatus:dpkg-exec:60:Running dpkg +pmstatus:testing2:60:Configuring testing2 +pmstatus:testing2:80:Configuring testing2 +pmstatus:testing2:100:Installed testing2" cat apt-progress.log + +rm -f apt-progress*.log \ No newline at end of file diff --git a/test/integration/test-apt-progress-fd-error b/test/integration/test-apt-progress-fd-error new file mode 100755 index 000000000..0cd59410e --- /dev/null +++ b/test/integration/test-apt-progress-fd-error @@ -0,0 +1,22 @@ +#!/bin/sh +set -e + +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework + +setupenvironment +configarchitecture 'amd64' 'i386' + +mkdir -p usr/bin +touch usr/bin/file-conflict + +buildsimplenativepackage 'foo1' 'amd64,i386' '0.8.15' 'stable' '' 'pkg with file conflicts' '' '' 'usr/' +buildsimplenativepackage 'foo2' 'amd64,i386' '0.8.15' 'stable' '' 'pkg with file conflicts' '' '' 'usr/' + +setupaptarchive + +exec 3> apt-progress.log +testfailure aptget install foo1 foo2 -y -o APT::Status-Fd=3 +msgtest "Ensure correct error message" +grep -q "aptarchive/pool/foo2_0.8.15_amd64.deb :40:trying to overwrite '/usr/bin/file-conflict', which is also in package foo1 0.8.15" apt-progress.log && msgpass || msgfail + diff --git a/test/integration/test-apt-progress-fd-error-postinst b/test/integration/test-apt-progress-fd-error-postinst new file mode 100755 index 000000000..0b6e70212 --- /dev/null +++ b/test/integration/test-apt-progress-fd-error-postinst @@ -0,0 +1,22 @@ +#!/bin/sh +set -e + +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework + +setupenvironment +configarchitecture 'amd64' 'i386' + +mkdir -p DEBIAN/ +echo "#!/bin/sh\nexit 1" > DEBIAN/postinst +chmod 755 DEBIAN/postinst + +buildsimplenativepackage 'postinst-error' 'amd64,i386' '0.8.15' 'stable' '' 'pkg with posinst error' '' '' './DEBIAN' + +setupaptarchive + +exec 3> apt-progress.log +testfailure aptget install postinst-error -y -o APT::Status-Fd=3 +msgtest "Ensure correct error message for postinst error" +grep -q "pmerror:postinst-error :80:subprocess installed post-installation script returned error exit status 2" apt-progress.log && msgpass || msgfail + -- cgit v1.2.3-70-g09d2 From c420fe0096985234e861aaafc2b9908b6259a1bb Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 17 Oct 2013 07:47:15 +0200 Subject: fix broken clean when apt was finished and ensure that terminal progress is updated when a new dpkg-loop is entered in dpkgpm.cc --- apt-pkg/deb/dpkgpm.cc | 28 +++++++++++++++++++--------- apt-pkg/deb/dpkgpm.h | 1 + 2 files changed, 20 insertions(+), 9 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index fe38bf697..f870fab93 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -993,6 +993,20 @@ void pkgDPkgPM::SetupTerminalScrollArea(int nr_rows) std::flush(std::cout); } +void pkgDPkgPM::CleanupTerminal() +{ + // reset scroll area + SetupTerminalScrollArea(d->nr_terminal_rows + 1); + if(d->fancy_progress_output) + { + // override the progress line (sledgehammer) + static const char* clear_screen_below_cursor = "\033[J"; + std::cout << clear_screen_below_cursor; + std::flush(std::cout); + } +} + + // DPkgPM::Go - Run the sequence /*{{{*/ // --------------------------------------------------------------------- /* This globs the operations and calls dpkg @@ -1430,7 +1444,9 @@ bool pkgDPkgPM::Go(int OutStatusFd) if (fcntl(STDIN_FILENO,F_SETFL,Flags & (~(long)O_NONBLOCK)) < 0) _exit(100); } + // setup terminal SetupTerminalScrollArea(d->nr_terminal_rows); + SendTerminalProgress(PackagesDone/float(PackagesTotal)*100.0); /* No Job Control Stop Env is a magic dpkg var that prevents it from using sigstop */ @@ -1525,15 +1541,6 @@ bool pkgDPkgPM::Go(int OutStatusFd) signal(SIGHUP,old_SIGHUP); - // reset scroll area - SetupTerminalScrollArea(d->nr_terminal_rows + 1); - if(d->fancy_progress_output) - { - // override the progress line (sledgehammer) - static const char* clear_screen_below_cursor = "\033[J"; - std::cout << clear_screen_below_cursor; - } - if(master >= 0) { tcsetattr(0, TCSAFLUSH, &tt); @@ -1564,6 +1571,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) if(stopOnError) { CloseLog(); + CleanupTerminal(); return false; } } @@ -1574,6 +1582,8 @@ bool pkgDPkgPM::Go(int OutStatusFd) if(_config->FindB("DPkgPM::Progress", false) == true) SendTerminalProgress(100); + CleanupTerminal(); + if (pkgPackageManager::SigINTStop) _error->Warning(_("Operation was interrupted before it could finish")); diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h index 3b8d36623..1a58e1af5 100644 --- a/apt-pkg/deb/dpkgpm.h +++ b/apt-pkg/deb/dpkgpm.h @@ -87,6 +87,7 @@ class pkgDPkgPM : public pkgPackageManager // Terminal progress void SetupTerminalScrollArea(int nr_scrolled_rows); void SendTerminalProgress(float percentage); + void CleanupTerminal(); // apport integration void WriteApportReport(const char *pkgpath, const char *errormsg); -- cgit v1.2.3-70-g09d2