diff options
Diffstat (limited to '')
-rw-r--r-- | apt-pkg/acquire-item.cc | 4 | ||||
-rw-r--r-- | apt-pkg/aptconfiguration.cc | 35 | ||||
-rw-r--r-- | apt-pkg/aptconfiguration.h | 2 | ||||
-rw-r--r-- | apt-pkg/contrib/error.cc | 28 | ||||
-rw-r--r-- | apt-pkg/contrib/error.h | 23 | ||||
-rw-r--r-- | apt-pkg/contrib/progress.cc | 10 | ||||
-rw-r--r-- | apt-pkg/deb/deblistparser.cc | 2 | ||||
-rw-r--r-- | apt-pkg/deb/dpkgpm.cc | 2 | ||||
-rw-r--r-- | apt-pkg/edsp.cc | 4 | ||||
-rw-r--r-- | apt-pkg/tagfile.cc | 32 | ||||
-rw-r--r-- | apt-pkg/tagfile.h | 8 |
11 files changed, 123 insertions, 27 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 3c491ad..b534d56 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -2013,6 +2013,8 @@ void pkgAcqMetaClearSig::Failed(string const &Message,pkgAcquire::MethodConfig c return; } + _error->Audit(_("Repositories should provide a clear-signed InRelease file, but none found at %s."), Target.URI.c_str()); + // Queue the 'old' InRelease file for removal if we try Release.gpg // as otherwise the file will stay around and gives a false-auth // impression (CVE-2012-0214) @@ -3985,7 +3987,7 @@ void pkgAcqFile::Done(string const &Message,HashStringList const &CalcHashes, _error->PushToStack(); _error->Errno("pkgAcqFile::Done", "Symlinking file %s failed", DestFile.c_str()); std::stringstream msg; - _error->DumpErrors(msg, GlobalError::DEBUG, false); + _error->DumpErrors(msg, GlobalError::NOTICE, false); _error->RevertToStack(); ErrorText = msg.str(); Status = StatError; diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index 982e68b..f462b6e 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -563,4 +563,39 @@ bool Configuration::checkUsrMerged() return true; } /*}}}*/ +// isUsrMerged - whether usr is merged t /*{{{*/ +// --------------------------------------------------------------------- +/* */ +std::string Configuration::color(std::string const &colorName, std::string const &content) +{ + if (not _config->FindB("APT::Color")) + return content; + + auto colors = ::Configuration(_config->Tree("APT::Color")); + auto color = colors.Find(colorName); + + // Resolve the color recursively. A color string has the following format + // <color> := \x1B<word> ; fully resolved color + // | \\x1B<word> ; color escaped. + // | <word> ; a simple color name + // | <color> <color> ; a sequence of colors + if (color.find(" ") != color.npos) + { + std::string res; + for (auto &&colorPart : VectorizeString(color, ' ')) + res += Configuration::color(colorPart); + color = res; + } + else if (not color.empty() && color[0] != '\x1B') + { + if (APT::String::Startswith(color, "\\x1B")) + color = "\x1B" + color.substr(4); + else + color = Configuration::color(color); + } + if (content.empty()) + return color; + return color + content + Configuration::color("Neutral"); +} + /*}}}*/ } diff --git a/apt-pkg/aptconfiguration.h b/apt-pkg/aptconfiguration.h index 3e2636e..58c925b 100644 --- a/apt-pkg/aptconfiguration.h +++ b/apt-pkg/aptconfiguration.h @@ -130,7 +130,9 @@ namespace Configuration { /*{{{*/ APT_PUBLIC bool isChroot(); /** \return Check usr is merged or produce error. */ APT_PUBLIC bool checkUsrMerged(); + APT_PUBLIC std::string color(std::string const &colorName, std::string const &content = ""); #endif + /*}}}*/ } /*}}}*/ diff --git a/apt-pkg/contrib/error.cc b/apt-pkg/contrib/error.cc index c9bb622..83e90a0 100644 --- a/apt-pkg/contrib/error.cc +++ b/apt-pkg/contrib/error.cc @@ -34,6 +34,7 @@ #include <string> #include <unistd.h> +#include <apti18n.h> /*}}}*/ // Global Error Object /*{{{*/ @@ -64,6 +65,7 @@ GEMessage(FatalE, FATAL) GEMessage(Errno, ERROR) GEMessage(WarningE, WARNING) GEMessage(NoticeE, NOTICE) +GEMessage(AuditE, AUDIT) GEMessage(DebugE, DEBUG) #undef GEMessage /*}}}*/ @@ -121,6 +123,7 @@ GEMessage(Fatal, FATAL) GEMessage(Error, ERROR) GEMessage(Warning, WARNING) GEMessage(Notice, NOTICE) +GEMessage(Audit, AUDIT) GEMessage(Debug, DEBUG) #undef GEMessage /*}}}*/ @@ -252,11 +255,13 @@ void GlobalError::MergeWithStack() { APT_HIDDEN std::ostream &operator<<(std::ostream &out, GlobalError::Item i) { static constexpr auto COLOR_RESET = "\033[0m"; - static constexpr auto COLOR_NOTICE = "\033[33m"; // normal yellow + static constexpr auto COLOR_BOLD = "\033[1m"; // bold neutral + static constexpr auto COLOR_NOTICE = "\033[1m"; // bold neutral static constexpr auto COLOR_WARN = "\033[1;33m"; // bold yellow static constexpr auto COLOR_ERROR = "\033[1;31m"; // bold red bool use_color = _config->FindB("APT::Color", false); + auto out_ver = _config->FindI("APT::Output-Version"); if (use_color) { @@ -270,6 +275,7 @@ APT_HIDDEN std::ostream &operator<<(std::ostream &out, GlobalError::Item i) out << COLOR_WARN; break; case GlobalError::NOTICE: + case GlobalError::AUDIT: out << COLOR_NOTICE; break; default: @@ -281,19 +287,26 @@ APT_HIDDEN std::ostream &operator<<(std::ostream &out, GlobalError::Item i) { case GlobalError::FATAL: case GlobalError::ERROR: - out << 'E'; + // TRANSLATOR: This is a warning level displayed before the message + out << (out_ver < 30 ? "E:" : _("Error:")); break; case GlobalError::WARNING: - out << 'W'; + // TRANSLATOR: This is a warning level displayed before the message + out << (out_ver < 30 ? "W:" : _("Warning:")); break; case GlobalError::NOTICE: - out << 'N'; + // TRANSLATOR: This is a warning level displayed before the message + out << (out_ver < 30 ? "N:" : _("Notice:")); + break; + case GlobalError::AUDIT: + out << (out_ver < 30 ? "A:" : _("Audit:")); break; case GlobalError::DEBUG: - out << 'D'; + // TRANSLATOR: This is a warning level displayed before the message + out << _("Debug:"); break; } - out << ": "; + out << " "; if (use_color) { @@ -303,7 +316,10 @@ APT_HIDDEN std::ostream &operator<<(std::ostream &out, GlobalError::Item i) case GlobalError::ERROR: case GlobalError::WARNING: case GlobalError::NOTICE: + case GlobalError::AUDIT: out << COLOR_RESET; + if (out_ver >= 30) + out << COLOR_BOLD; break; default: break; diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h index 35e39ee..7922320 100644 --- a/apt-pkg/contrib/error.h +++ b/apt-pkg/contrib/error.h @@ -66,6 +66,8 @@ public: /*{{{*/ WARNING = 20, /** \brief deprecation warnings, old fallback behavior, … */ NOTICE = 10, + /** \brief future deprecation warnings, divergence from best practices */ + AUDIT = 5, /** \brief for developers only in areas it is hard to print something directly */ DEBUG = 0 }; @@ -109,6 +111,15 @@ public: /*{{{*/ */ bool NoticeE(const char *Function,const char *Description,...) APT_PRINTF(3) APT_COLD; + /** \brief add an audit message with errno to the list + * + * \param Function name of the function generating the error + * \param Description format string for the error message + * + * \return \b false + */ + bool AuditE(const char *Function,const char *Description,...) APT_PRINTF(3) APT_COLD; + /** \brief add a debug message with errno to the list * * \param Function name of the function generating the error @@ -193,6 +204,18 @@ public: /*{{{*/ */ bool Notice(const char *Description,...) APT_PRINTF(2) APT_COLD; + /** \brief add an audit message to the list + * + * An audit message highlights divergences from best practices and + * future deprecations. It my for example include additional messages + * targeted at repository owners. + * + * \param Description Format string for the message + * + * \return \b false + */ + bool Audit(const char *Description,...) APT_PRINTF(2) APT_COLD; + /** \brief add a debug message to the list * * \param Description Format string for the message diff --git a/apt-pkg/contrib/progress.cc b/apt-pkg/contrib/progress.cc index df068e4..5f440a7 100644 --- a/apt-pkg/contrib/progress.cc +++ b/apt-pkg/contrib/progress.cc @@ -156,12 +156,12 @@ void OpTextProgress::Done() char S[300] = {}; if (_error->PendingError() == true) snprintf(S,sizeof(S),_("%c%s... Error!"),'\r',OldOp.c_str()); - else if (not _config->FindB("APT::Internal::OpProgress::EraseLines", true)) + else if (not _config->FindB("APT::Internal::OpProgress::EraseLines", _config->FindI("APT::Output-Version") >= 30)) snprintf(S,sizeof(S),_("%c%s... Done"),'\r',OldOp.c_str()); Write(S); // FIXME: apt-cdrom relies on this end of line being printed - if (_error->PendingError() || not _config->FindB("APT::Internal::OpProgress::EraseLines", true)) - cout << endl; + if (_error->PendingError() || not _config->FindB("APT::Internal::OpProgress::EraseLines", _config->FindI("APT::Output-Version") >= 30)) + cout << endl; OldOp = string(); } @@ -202,8 +202,8 @@ void OpTextProgress::Update() { snprintf(S,sizeof(S),"\r%s",OldOp.c_str()); Write(S); - if (_config->FindB("APT::Internal::OpProgress::EraseLines", true)) - cout << endl; + if (_config->FindB("APT::Internal::OpProgress::EraseLines", _config->FindI("APT::Output-Version") >= 30)) + cout << endl; } // Print the spinner. Absolute progress shows us a time progress. diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 46c3629..071189b 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -608,7 +608,7 @@ const char *debListParser::ParseDepends(const char *Start, const char *Stop, { // Skip the '(' for (I++; I != Stop && isspace_ascii(*I) != 0 ; I++); - if (I + 3 >= Stop) + if (I + 3 > Stop) return 0; I = ConvertRelation(I,Op); diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 4f87cc2..82035ee 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -1301,7 +1301,7 @@ void pkgDPkgPM::StartPtyMagic() /*{{{*/ free(d->slave); d->slave = NULL; } - _error->DumpErrors(std::cerr, GlobalError::DEBUG, false); + _error->DumpErrors(std::cerr, GlobalError::NOTICE, false); } _error->RevertToStack(); } diff --git a/apt-pkg/edsp.cc b/apt-pkg/edsp.cc index b0ac4ae..a02e400 100644 --- a/apt-pkg/edsp.cc +++ b/apt-pkg/edsp.cc @@ -435,7 +435,7 @@ bool EDSP::ReadResponse(int const input, pkgDepCache &Cache, OpProgress *Progres if (Progress != nullptr) Progress->Done(); Progress = nullptr; - _error->DumpErrors(std::cerr, GlobalError::DEBUG, false); + _error->DumpErrors(std::cerr, GlobalError::NOTICE, false); } std::string msg = SubstVar(SubstVar(section.FindS("Message"), "\n .\n", "\n\n"), "\n ", "\n"); if (msg.empty() == true) { @@ -1044,7 +1044,7 @@ bool EIPP::ReadResponse(int const input, pkgPackageManager * const PM, OpProgres if (Progress != nullptr) Progress->Done(); Progress = nullptr; - _error->DumpErrors(std::cerr, GlobalError::DEBUG, false); + _error->DumpErrors(std::cerr, GlobalError::NOTICE, false); } std::string msg = SubstVar(SubstVar(section.FindS("Message"), "\n .\n", "\n\n"), "\n ", "\n"); if (msg.empty() == true) { diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc index 95ae4a4..934a89d 100644 --- a/apt-pkg/tagfile.cc +++ b/apt-pkg/tagfile.cc @@ -12,6 +12,7 @@ // Include Files /*{{{*/ #include <config.h> +#include <apt-pkg/configuration.h> #include <apt-pkg/error.h> #include <apt-pkg/fileutl.h> #include <apt-pkg/string_view.h> @@ -30,8 +31,9 @@ #include <apti18n.h> /*}}}*/ -using std::string; using APT::StringView; +using APT::Configuration::color; +using std::string; class APT_HIDDEN pkgTagFilePrivate /*{{{*/ { @@ -972,19 +974,23 @@ pkgTagSection::Tag pkgTagSection::Tag::Rewrite(std::string const &Name, std::str else return Tag(REWRITE, Name, Data); } -static bool WriteTag(FileFd &File, std::string Tag, StringView Value) +static bool WriteTag(FileFd &File, std::string Tag, StringView Value, pkgTagSection::WriteFlags flags) { if (Value.empty() || isspace_ascii(Value[0]) != 0) Tag.append(":"); else Tag.append(": "); + + if (flags & pkgTagSection::WRITE_HUMAN) + Tag = color("Show::Field", Tag); + Tag.append(Value.data(), Value.length()); Tag.append("\n"); return File.Write(Tag.c_str(), Tag.length()); } -static bool RewriteTags(FileFd &File, pkgTagSection const * const This, char const * const Tag, - std::vector<pkgTagSection::Tag>::const_iterator &R, - std::vector<pkgTagSection::Tag>::const_iterator const &REnd) +static bool RewriteTags(FileFd &File, pkgTagSection const *const This, char const *const Tag, + std::vector<pkgTagSection::Tag>::const_iterator &R, + std::vector<pkgTagSection::Tag>::const_iterator const &REnd, pkgTagSection::WriteFlags flags) { size_t const TagLen = strlen(Tag); for (; R != REnd; ++R) @@ -1002,19 +1008,23 @@ static bool RewriteTags(FileFd &File, pkgTagSection const * const This, char con else continue; - return WriteTag(File, Tag, data); + return WriteTag(File, Tag, data, flags); } return true; } bool pkgTagSection::Write(FileFd &File, char const * const * const Order, std::vector<Tag> const &Rewrite) const { + return Write(File, WRITE_DEFAULT, Order, Rewrite); +} +bool pkgTagSection::Write(FileFd &File, pkgTagSection::WriteFlags flags, char const *const *const Order, std::vector<Tag> const &Rewrite) const +{ // first pass: Write everything we have an order for if (Order != NULL) { for (unsigned int I = 0; Order[I] != 0; ++I) { std::vector<Tag>::const_iterator R = Rewrite.begin(); - if (RewriteTags(File, this, Order[I], R, Rewrite.end()) == false) + if (RewriteTags(File, this, Order[I], R, Rewrite.end(), flags) == false) return false; if (R != Rewrite.end()) continue; @@ -1022,7 +1032,7 @@ bool pkgTagSection::Write(FileFd &File, char const * const * const Order, std::v if (Exists(Order[I]) == false) continue; - if (WriteTag(File, Order[I], FindRaw(Order[I])) == false) + if (WriteTag(File, Order[I], FindRaw(Order[I]), flags) == false) return false; } } @@ -1047,12 +1057,12 @@ bool pkgTagSection::Write(FileFd &File, char const * const * const Order, std::v std::string const name(fieldname, fieldnamelen); std::vector<Tag>::const_iterator R = Rewrite.begin(); - if (RewriteTags(File, this, name.c_str(), R, Rewrite.end()) == false) + if (RewriteTags(File, this, name.c_str(), R, Rewrite.end(), flags) == false) return false; if (R != Rewrite.end()) continue; - if (WriteTag(File, name, FindRaw(name)) == false) + if (WriteTag(File, name, FindRaw(name), flags) == false) return false; } } @@ -1076,7 +1086,7 @@ bool pkgTagSection::Write(FileFd &File, char const * const * const Order, std::v continue; } - if (WriteTag(File, name, ((R->Action == Tag::RENAME) ? FindRaw(R->Name) : R->Data)) == false) + if (WriteTag(File, name, ((R->Action == Tag::RENAME) ? FindRaw(R->Name) : R->Data), flags) == false) return false; } return true; diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index 0020d28..45529c9 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -166,6 +166,14 @@ class APT_PUBLIC pkgTagSection * @return \b true if successful, otherwise \b false */ bool Write(FileFd &File, char const * const * const Order = NULL, std::vector<Tag> const &Rewrite = std::vector<Tag>()) const; +#ifdef APT_COMPILING_APT + enum WriteFlags + { + WRITE_DEFAULT = 0, + WRITE_HUMAN = (1 << 0), /* write human readable output, may include highlighting */ + }; + bool Write(FileFd &File, WriteFlags flags, char const *const *const Order = NULL, std::vector<Tag> const &Rewrite = std::vector<Tag>()) const; +#endif }; |