summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2014-01-04 11:15:28 +0100
committerMichael Vogt <mvo@debian.org>2014-01-04 11:15:28 +0100
commitc93d14fc05b50a8ee8bb7804579c2912f34c676b (patch)
tree1f45c51bd8d3ab33de2610f1663b3ec8e5f49c02 /apt-pkg
parente2fa0aa64d2249129543f82a213043d96469be1c (diff)
parent23bd09778261c945b460b46d855b1a6ef998cfd8 (diff)
Merge branch 'debian/sid' into feature/source-deb822
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/contrib/fileutl.cc17
-rw-r--r--apt-pkg/contrib/fileutl.h2
-rw-r--r--apt-pkg/contrib/gpgv.cc12
-rw-r--r--apt-pkg/deb/dpkgpm.cc12
-rw-r--r--apt-pkg/install-progress.cc61
-rw-r--r--apt-pkg/install-progress.h17
-rw-r--r--apt-pkg/policy.cc4
-rw-r--r--apt-pkg/tagfile.cc11
8 files changed, 98 insertions, 38 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 7fbe4d604..efbf7aaf4 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -1827,3 +1827,20 @@ std::vector<std::string> Glob(std::string const &pattern, int flags)
return result;
}
/*}}}*/
+
+std::string GetTempDir()
+{
+ const char *tmpdir = getenv("TMPDIR");
+
+#ifdef P_tmpdir
+ if (!tmpdir)
+ tmpdir = P_tmpdir;
+#endif
+
+ // check that tmpdir is set and exists
+ struct stat st;
+ if (!tmpdir || strlen(tmpdir) == 0 || stat(tmpdir, &st) != 0)
+ tmpdir = "/tmp";
+
+ return string(tmpdir);
+}
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index e9a9aab28..e752e9621 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -165,6 +165,8 @@ bool DirectoryExists(std::string const &Path) __attrib_const;
bool CreateDirectory(std::string const &Parent, std::string const &Path);
time_t GetModificationTime(std::string const &Path);
+std::string GetTempDir();
+
/** \brief Ensure the existence of the given Path
*
* \param Parent directory of the Path directory - a trailing
diff --git a/apt-pkg/contrib/gpgv.cc b/apt-pkg/contrib/gpgv.cc
index f47e7ea48..f57a72d86 100644
--- a/apt-pkg/contrib/gpgv.cc
+++ b/apt-pkg/contrib/gpgv.cc
@@ -10,6 +10,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <unistd.h>
#include<apt-pkg/configuration.h>
#include<apt-pkg/error.h>
@@ -21,16 +22,9 @@
/*}}}*/
static char * GenerateTemporaryFileTemplate(const char *basename) /*{{{*/
{
- const char *tmpdir = getenv("TMPDIR");
-#ifdef P_tmpdir
- if (!tmpdir)
- tmpdir = P_tmpdir;
-#endif
- if (!tmpdir)
- tmpdir = "/tmp";
-
std::string out;
- strprintf(out, "%s/%s.XXXXXX", tmpdir, basename);
+ std::string tmpdir = GetTempDir();
+ strprintf(out, "%s/%s.XXXXXX", tmpdir.c_str(), basename);
return strdup(out.c_str());
}
/*}}}*/
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc
index b4bfd1400..14ce133cf 100644
--- a/apt-pkg/deb/dpkgpm.cc
+++ b/apt-pkg/deb/dpkgpm.cc
@@ -44,6 +44,7 @@
#include <unistd.h>
#include <sys/ioctl.h>
#include <pty.h>
+#include <stdio.h>
#include <apti18n.h>
/*}}}*/
@@ -596,7 +597,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(char *line)
errors look like this:
'status: /var/cache/apt/archives/krecipes_0.8.1-0ubuntu1_i386.deb : error : trying to overwrite `/usr/share/doc/kde/HTML/en/krecipes/krectip.png', which is also in package krecipes-data
and conffile-prompt like this
- 'status: conffile-prompt: conffile : 'current-conffile' 'new-conffile' useredited distedited
+ 'status:/etc/compiz.conf/compiz.conf : conffile-prompt: 'current-conffile' 'new-conffile' useredited distedited
*/
if (prefix == "status")
{
@@ -608,7 +609,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(char *line)
WriteApportReport(list[1].c_str(), list[3].c_str());
return;
}
- else if(action == "conffile")
+ else if(action == "conffile-prompt")
{
d->progress->ConffilePrompt(list[1], PackagesDone, PackagesTotal,
list[3]);
@@ -1036,7 +1037,10 @@ void pkgDPkgPM::StartPtyMagic()
if (tcgetattr(STDOUT_FILENO, &d->tt) == 0)
{
ioctl(1, TIOCGWINSZ, (char *)&win);
- if (openpty(&d->master, &d->slave, NULL, &d->tt, &win) < 0)
+ if (_config->FindB("Dpkg::Use-Pty", true) == false)
+ {
+ d->master = d->slave = -1;
+ } else if (openpty(&d->master, &d->slave, NULL, &d->tt, &win) < 0)
{
_error->Errno("openpty", _("Can not write log (%s)"), _("Is /dev/pts mounted?"));
d->master = d->slave = -1;
@@ -1182,7 +1186,7 @@ bool pkgDPkgPM::GoNoABIBreak(APT::Progress::PackageManager *progress)
StartPtyMagic();
// Tell the progress that its starting and fork dpkg
- d->progress->Start();
+ d->progress->Start(d->master);
// this loop is runs once per dpkg operation
vector<Item>::const_iterator I = List.begin();
diff --git a/apt-pkg/install-progress.cc b/apt-pkg/install-progress.cc
index b82b7efde..fe065da4f 100644
--- a/apt-pkg/install-progress.cc
+++ b/apt-pkg/install-progress.cc
@@ -9,7 +9,8 @@
#include <sys/ioctl.h>
#include <sstream>
#include <fcntl.h>
-
+#include <algorithm>
+#include <stdio.h>
namespace APT {
namespace Progress {
@@ -222,17 +223,47 @@ bool PackageManagerProgressDeb822Fd::StatusChanged(std::string PackageName,
return true;
}
+
+PackageManagerFancy::PackageManagerFancy()
+ : child_pty(-1)
+{
+ // setup terminal size
+ old_SIGWINCH = signal(SIGWINCH, PackageManagerFancy::staticSIGWINCH);
+ instances.push_back(this);
+}
+std::vector<PackageManagerFancy*> PackageManagerFancy::instances;
+
+PackageManagerFancy::~PackageManagerFancy()
+{
+ instances.erase(find(instances.begin(), instances.end(), this));
+ signal(SIGWINCH, old_SIGWINCH);
+}
+
+void PackageManagerFancy::staticSIGWINCH(int signum)
+{
+ std::vector<PackageManagerFancy *>::const_iterator I;
+ for(I = instances.begin(); I != instances.end(); I++)
+ (*I)->HandleSIGWINCH(signum);
+}
+
int PackageManagerFancy::GetNumberTerminalRows()
{
struct winsize win;
+ // FIXME: get from "child_pty" instead?
if(ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&win) != 0)
return -1;
+
+ if(_config->FindB("Debug::InstallProgress::Fancy", false) == true)
+ std::cerr << "GetNumberTerminalRows: " << win.ws_row << std::endl;
return win.ws_row;
}
void PackageManagerFancy::SetupTerminalScrollArea(int nr_rows)
{
+ if(_config->FindB("Debug::InstallProgress::Fancy", false) == true)
+ std::cerr << "SetupTerminalScrollArea: " << nr_rows << std::endl;
+
// scroll down a bit to avoid visual glitch when the screen
// area shrinks by one row
std::cout << "\n";
@@ -241,30 +272,22 @@ void PackageManagerFancy::SetupTerminalScrollArea(int nr_rows)
std::cout << "\033[s";
// set scroll region (this will place the cursor in the top left)
- std::cout << "\033[1;" << nr_rows - 1 << "r";
+ std::cout << "\033[0;" << nr_rows - 1 << "r";
// restore cursor but ensure its inside the scrolling area
std::cout << "\033[u";
static const char *move_cursor_up = "\033[1A";
std::cout << move_cursor_up;
- // setup env for (hopefully!) ncurses
- string s;
- strprintf(s, "%i", nr_rows);
- setenv("LINES", s.c_str(), 1);
-
+ // ensure its flushed
std::flush(std::cout);
-}
-PackageManagerFancy::PackageManagerFancy()
-{
- // setup terminal size
- old_SIGWINCH = signal(SIGWINCH, HandleSIGWINCH);
-}
-
-PackageManagerFancy::~PackageManagerFancy()
-{
- signal(SIGWINCH, old_SIGWINCH);
+ // setup tty size to ensure xterm/linux console are working properly too
+ // see bug #731738
+ struct winsize win;
+ ioctl(child_pty, TIOCGWINSZ, (char *)&win);
+ win.ws_row = nr_rows - 1;
+ ioctl(child_pty, TIOCSWINSZ, (char *)&win);
}
void PackageManagerFancy::HandleSIGWINCH(int)
@@ -273,8 +296,9 @@ void PackageManagerFancy::HandleSIGWINCH(int)
SetupTerminalScrollArea(nr_terminal_rows);
}
-void PackageManagerFancy::Start()
+void PackageManagerFancy::Start(int a_child_pty)
{
+ child_pty = a_child_pty;
int nr_terminal_rows = GetNumberTerminalRows();
if (nr_terminal_rows > 0)
SetupTerminalScrollArea(nr_terminal_rows);
@@ -291,6 +315,7 @@ void PackageManagerFancy::Stop()
static const char* clear_screen_below_cursor = "\033[J";
std::cout << clear_screen_below_cursor;
}
+ child_pty = -1;
}
bool PackageManagerFancy::StatusChanged(std::string PackageName,
diff --git a/apt-pkg/install-progress.h b/apt-pkg/install-progress.h
index 4b7590983..8a5b68a8f 100644
--- a/apt-pkg/install-progress.h
+++ b/apt-pkg/install-progress.h
@@ -4,6 +4,7 @@
#include <string>
#include <unistd.h>
#include <signal.h>
+#include <vector>
namespace APT {
namespace Progress {
@@ -28,7 +29,7 @@ namespace Progress {
virtual ~PackageManager() {};
/* Global Start/Stop */
- virtual void Start() {};
+ virtual void Start(int child_pty=-1) {};
virtual void Stop() {};
/* When dpkg is invoked (may happen multiple times for each
@@ -116,16 +117,22 @@ namespace Progress {
class PackageManagerFancy : public PackageManager
{
+ private:
+ static void staticSIGWINCH(int);
+ static std::vector<PackageManagerFancy*> instances;
+
protected:
- static void SetupTerminalScrollArea(int nr_rows);
- static int GetNumberTerminalRows();
- static void HandleSIGWINCH(int);
+ void SetupTerminalScrollArea(int nr_rows);
+ void HandleSIGWINCH(int);
+
+ int GetNumberTerminalRows();
sighandler_t old_SIGWINCH;
+ int child_pty;
public:
PackageManagerFancy();
~PackageManagerFancy();
- virtual void Start();
+ virtual void Start(int child_pty=-1);
virtual void Stop();
virtual bool StatusChanged(std::string PackageName,
unsigned int StepsDone,
diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc
index 0a06cc6e3..d0f97441d 100644
--- a/apt-pkg/policy.cc
+++ b/apt-pkg/policy.cc
@@ -405,6 +405,10 @@ bool ReadPinFile(pkgPolicy &Plcy,string File)
PreferenceSection Tags;
while (TF.Step(Tags) == true)
{
+ // can happen when there are only comments in a record
+ if (Tags.Count() == 0)
+ continue;
+
string Name = Tags.FindS("Package");
if (Name.empty() == true)
return _error->Error(_("Invalid record in the preferences file %s, no Package header"), File.c_str());
diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc
index e0802e3d5..bef3c76ba 100644
--- a/apt-pkg/tagfile.cc
+++ b/apt-pkg/tagfile.cc
@@ -259,7 +259,12 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength)
TagCount = 0;
while (TagCount+1 < sizeof(Indexes)/sizeof(Indexes[0]) && Stop < End)
{
- TrimRecord(true,End);
+ TrimRecord(true,End);
+
+ // this can happen when TrimRecord trims away the entire Record
+ // (e.g. because it just contains comments)
+ if(Stop == End)
+ return true;
// Start a new index and add it to the hash
if (isspace(Stop[0]) == 0)
@@ -273,7 +278,9 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength)
if (Stop == 0)
return false;
- for (; Stop+1 < End && Stop[1] == '\r'; Stop++);
+ for (; Stop+1 < End && Stop[1] == '\r'; Stop++)
+ /* nothing */
+ ;
// Double newline marks the end of the record
if (Stop+1 < End && Stop[1] == '\n')