diff options
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/algorithms.cc | 43 | ||||
-rw-r--r-- | apt-pkg/algorithms.h | 4 | ||||
-rw-r--r-- | apt-pkg/cachefilter.cc | 11 | ||||
-rw-r--r-- | apt-pkg/cachefilter.h | 84 | ||||
-rw-r--r-- | apt-pkg/cacheset.cc | 64 | ||||
-rw-r--r-- | apt-pkg/cacheset.h | 13 | ||||
-rw-r--r-- | apt-pkg/contrib/cmndline.cc | 48 | ||||
-rw-r--r-- | apt-pkg/contrib/cmndline.h | 6 | ||||
-rw-r--r-- | apt-pkg/contrib/strutl.cc | 12 | ||||
-rw-r--r-- | apt-pkg/contrib/strutl.h | 4 | ||||
-rw-r--r-- | apt-pkg/deb/deblistparser.cc | 2 | ||||
-rw-r--r-- | apt-pkg/deb/dpkgpm.cc | 20 | ||||
-rw-r--r-- | apt-pkg/indexrecords.cc | 2 | ||||
-rw-r--r-- | apt-pkg/tagfile.cc | 59 | ||||
-rw-r--r-- | apt-pkg/tagfile.h | 1 |
15 files changed, 343 insertions, 30 deletions
diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index 6296e8fe8..69d4acd83 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -459,6 +459,49 @@ bool pkgAllUpgrade(pkgDepCache &Cache) return Fix.ResolveByKeep(); } /*}}}*/ +// AllUpgradeNoDelete - Upgrade without removing packages /*{{{*/ +// --------------------------------------------------------------------- +/* Right now the system must be consistent before this can be called. + * Upgrade as much as possible without deleting anything (useful for + * stable systems) + */ +bool pkgAllUpgradeNoDelete(pkgDepCache &Cache) +{ + pkgDepCache::ActionGroup group(Cache); + + pkgProblemResolver Fix(&Cache); + + if (Cache.BrokenCount() != 0) + return false; + + // provide the initial set of stuff we want to upgrade by marking + // all upgradable packages for upgrade + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) + { + if (I->CurrentVer != 0 && Cache[I].InstallVer != 0) + { + if (_config->FindB("APT::Ignore-Hold",false) == false) + if (I->SelectedState == pkgCache::State::Hold) + continue; + + Cache.MarkInstall(I, false, 0, false); + } + } + + // then let auto-install loose + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) + if (Cache[I].Install()) + Cache.MarkInstall(I, true, 0, false); + + // ... but it may remove stuff, we we need to clean up afterwards again + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) + if (Cache[I].Delete() == true) + Cache.MarkKeep(I, false, false); + + // resolve remaining issues via keep + return Fix.ResolveByKeep(); +} + /*}}}*/ // MinimizeUpgrade - Minimizes the set of packages to be upgraded /*{{{*/ // --------------------------------------------------------------------- /* This simply goes over the entire set of packages and tries to keep diff --git a/apt-pkg/algorithms.h b/apt-pkg/algorithms.h index 7f58c8eed..a499db8ba 100644 --- a/apt-pkg/algorithms.h +++ b/apt-pkg/algorithms.h @@ -143,7 +143,11 @@ class pkgProblemResolver /*{{{*/ bool pkgDistUpgrade(pkgDepCache &Cache); bool pkgApplyStatus(pkgDepCache &Cache); bool pkgFixBroken(pkgDepCache &Cache); + bool pkgAllUpgrade(pkgDepCache &Cache); + +bool pkgAllUpgradeNoDelete(pkgDepCache &Cache); + bool pkgMinimizeUpgrade(pkgDepCache &Cache); void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List); diff --git a/apt-pkg/cachefilter.cc b/apt-pkg/cachefilter.cc index 64cde41d1..57b9af159 100644 --- a/apt-pkg/cachefilter.cc +++ b/apt-pkg/cachefilter.cc @@ -55,6 +55,17 @@ PackageNameMatchesRegEx::~PackageNameMatchesRegEx() { /*{{{*/ } /*}}}*/ +// Fnmatch support /*{{{*/ +//---------------------------------------------------------------------- +bool PackageNameMatchesFnmatch::operator() (pkgCache::PkgIterator const &Pkg) {/*{{{*/ + return fnmatch(Pattern.c_str(), Pkg.Name(), FNM_CASEFOLD) == 0; +} + /*}}}*/ +bool PackageNameMatchesFnmatch::operator() (pkgCache::GrpIterator const &Grp) {/*{{{*/ + return fnmatch(Pattern.c_str(), Grp.Name(), FNM_CASEFOLD) == 0; +} + /*}}}*/ + // CompleteArch to <kernel>-<cpu> tuple /*{{{*/ //---------------------------------------------------------------------- /* The complete architecture, consisting of <kernel>-<cpu>. */ diff --git a/apt-pkg/cachefilter.h b/apt-pkg/cachefilter.h index 25cd43f47..34b7d0b46 100644 --- a/apt-pkg/cachefilter.h +++ b/apt-pkg/cachefilter.h @@ -14,6 +14,10 @@ /*}}}*/ namespace APT { namespace CacheFilter { + +#define PACKAGE_MATCHER_ABI_COMPAT 1 +#ifdef PACKAGE_MATCHER_ABI_COMPAT + // PackageNameMatchesRegEx /*{{{*/ class PackageNameMatchesRegEx { /** \brief dpointer placeholder (for later in case we need it) */ @@ -26,6 +30,19 @@ public: ~PackageNameMatchesRegEx(); }; /*}}}*/ +// PackageNameMatchesFnmatch /*{{{*/ + class PackageNameMatchesFnmatch { + /** \brief dpointer placeholder (for later in case we need it) */ + void *d; + const std::string Pattern; +public: + PackageNameMatchesFnmatch(std::string const &Pattern) + : Pattern(Pattern) {}; + bool operator() (pkgCache::PkgIterator const &Pkg); + bool operator() (pkgCache::GrpIterator const &Grp); + ~PackageNameMatchesFnmatch() {}; +}; + /*}}}*/ // PackageArchitectureMatchesSpecification /*{{{*/ /** \class PackageArchitectureMatchesSpecification \brief matching against architecture specification strings @@ -55,6 +72,73 @@ public: bool operator() (pkgCache::VerIterator const &Ver); ~PackageArchitectureMatchesSpecification(); }; + +#else + +class PackageMatcher { + public: + virtual bool operator() (pkgCache::PkgIterator const &Pkg) { return false; }; + virtual bool operator() (pkgCache::GrpIterator const &Grp) { return false; }; + virtual bool operator() (pkgCache::VerIterator const &Ver) { return false; }; + + virtual ~PackageMatcher() {}; +}; + +// PackageNameMatchesRegEx /*{{{*/ +class PackageNameMatchesRegEx : public PackageMatcher { + /** \brief dpointer placeholder (for later in case we need it) */ + void *d; + regex_t* pattern; +public: + PackageNameMatchesRegEx(std::string const &Pattern); + virtual bool operator() (pkgCache::PkgIterator const &Pkg); + virtual bool operator() (pkgCache::GrpIterator const &Grp); + virtual ~PackageNameMatchesRegEx(); +}; + /*}}}*/ +// PackageNameMatchesFnmatch /*{{{*/ + class PackageNameMatchesFnmatch : public PackageMatcher{ + /** \brief dpointer placeholder (for later in case we need it) */ + void *d; + const std::string Pattern; +public: + PackageNameMatchesFnmatch(std::string const &Pattern) + : Pattern(Pattern) {}; + virtual bool operator() (pkgCache::PkgIterator const &Pkg); + virtual bool operator() (pkgCache::GrpIterator const &Grp); + virtual ~PackageNameMatchesFnmatch() {}; +}; + /*}}}*/ +// PackageArchitectureMatchesSpecification /*{{{*/ +/** \class PackageArchitectureMatchesSpecification + \brief matching against architecture specification strings + + The strings are of the format <kernel>-<cpu> where either component, + or the whole string, can be the wildcard "any" as defined in + debian-policy ยง11.1 "Architecture specification strings". + + Examples: i386, mipsel, linux-any, any-amd64, any */ +class PackageArchitectureMatchesSpecification : public PackageMatcher { + std::string literal; + std::string complete; + bool isPattern; + /** \brief dpointer placeholder (for later in case we need it) */ + void *d; +public: + /** \brief matching against architecture specification strings + * + * @param pattern is the architecture specification string + * @param isPattern defines if the given \b pattern is a + * architecture specification pattern to match others against + * or if it is the fixed string and matched against patterns + */ + PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern = true); + bool operator() (char const * const &arch); + virtual bool operator() (pkgCache::PkgIterator const &Pkg); + virtual bool operator() (pkgCache::VerIterator const &Ver); + virtual ~PackageArchitectureMatchesSpecification(); +}; +#endif /*}}}*/ } } diff --git a/apt-pkg/cacheset.cc b/apt-pkg/cacheset.cc index 1fea4f94a..0147f7e86 100644 --- a/apt-pkg/cacheset.cc +++ b/apt-pkg/cacheset.cc @@ -155,6 +155,69 @@ bool PackageContainerInterface::FromRegEx(PackageContainerInterface * const pci, return true; } /*}}}*/ +// FromFnmatch - Returns the package defined by this fnmatch /*{{{*/ +bool +PackageContainerInterface::FromFnmatch(PackageContainerInterface * const pci, + pkgCacheFile &Cache, + std::string pattern, + CacheSetHelper &helper) +{ + static const char * const isfnmatch = ".?*[]!"; + if (pattern.find_first_of(isfnmatch) == std::string::npos) + return false; + + bool const wasEmpty = pci->empty(); + if (wasEmpty == true) + pci->setConstructor(FNMATCH); + + size_t archfound = pattern.find_last_of(':'); + std::string arch = "native"; + if (archfound != std::string::npos) { + arch = pattern.substr(archfound+1); + if (arch.find_first_of(isfnmatch) == std::string::npos) + pattern.erase(archfound); + else + arch = "native"; + } + + if (unlikely(Cache.GetPkgCache() == 0)) + return false; + + APT::CacheFilter::PackageNameMatchesFnmatch filter(pattern); + + bool found = false; + for (pkgCache::GrpIterator Grp = Cache.GetPkgCache()->GrpBegin(); Grp.end() == false; ++Grp) { + if (filter(Grp) == false) + continue; + pkgCache::PkgIterator Pkg = Grp.FindPkg(arch); + if (Pkg.end() == true) { + if (archfound == std::string::npos) { + std::vector<std::string> archs = APT::Configuration::getArchitectures(); + for (std::vector<std::string>::const_iterator a = archs.begin(); + a != archs.end() && Pkg.end() != true; ++a) + Pkg = Grp.FindPkg(*a); + } + if (Pkg.end() == true) + continue; + } + + pci->insert(Pkg); + helper.showRegExSelection(Pkg, pattern); + found = true; + } + + if (found == false) { + helper.canNotFindRegEx(pci, Cache, pattern); + pci->setConstructor(UNKNOWN); + return false; + } + + if (wasEmpty == false && pci->getConstructor() != UNKNOWN) + pci->setConstructor(UNKNOWN); + + return true; +} + /*}}}*/ // FromName - Returns the package defined by this string /*{{{*/ pkgCache::PkgIterator PackageContainerInterface::FromName(pkgCacheFile &Cache, std::string const &str, CacheSetHelper &helper) { @@ -239,6 +302,7 @@ bool PackageContainerInterface::FromString(PackageContainerInterface * const pci if (FromGroup(pci, Cache, str, helper) == false && FromTask(pci, Cache, str, helper) == false && + FromFnmatch(pci, Cache, str, helper) == false && FromRegEx(pci, Cache, str, helper) == false) { helper.canNotFindPackage(pci, Cache, str); diff --git a/apt-pkg/cacheset.h b/apt-pkg/cacheset.h index d7328d705..29103aad9 100644 --- a/apt-pkg/cacheset.h +++ b/apt-pkg/cacheset.h @@ -131,13 +131,14 @@ public: virtual bool empty() const = 0; virtual void clear() = 0; - enum Constructor { UNKNOWN, REGEX, TASK }; + enum Constructor { UNKNOWN, REGEX, TASK, FNMATCH }; virtual void setConstructor(Constructor const &con) = 0; virtual Constructor getConstructor() const = 0; static bool FromTask(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); static bool FromRegEx(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); static pkgCache::PkgIterator FromName(pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper); + static bool FromFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); static bool FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper); static bool FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &pattern, CacheSetHelper &helper); static bool FromCommandLine(PackageContainerInterface * const pci, pkgCacheFile &Cache, const char **cmdline, CacheSetHelper &helper); @@ -259,6 +260,16 @@ public: /*{{{*/ return FromRegEx(Cache, pattern, helper); } + static PackageContainer FromFnmatch(pkgCacheFile &Cache, std::string pattern, CacheSetHelper &helper) { + PackageContainer cont(FNMATCH); + PackageContainerInterface::FromFnmatch(&cont, Cache, pattern, helper); + return cont; + } + static PackageContainer FromFnMatch(pkgCacheFile &Cache, std::string const &pattern) { + CacheSetHelper helper; + return FromFnmatch(Cache, pattern, helper); + } + /** \brief returns a package specified by a string \param Cache the package is in diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc index 75d02cad4..8cef80368 100644 --- a/apt-pkg/contrib/cmndline.cc +++ b/apt-pkg/contrib/cmndline.cc @@ -38,6 +38,42 @@ CommandLine::~CommandLine() delete [] FileList; } /*}}}*/ +// CommandLine::GetCommand - return the first non-option word /*{{{*/ +char const * CommandLine::GetCommand(Dispatch const * const Map, + unsigned int const argc, char const * const * const argv) +{ + // if there is a -- on the line there must be the word we search for around it + // as -- marks the end of the options, just not sure if the command can be + // considered an option or not, so accept both + for (size_t i = 1; i < argc; ++i) + { + if (strcmp(argv[i], "--") != 0) + continue; + ++i; + if (i < argc) + for (size_t j = 0; Map[j].Match != NULL; ++j) + if (strcmp(argv[i], Map[j].Match) == 0) + return Map[j].Match; + i -= 2; + if (i != 0) + for (size_t j = 0; Map[j].Match != NULL; ++j) + if (strcmp(argv[i], Map[j].Match) == 0) + return Map[j].Match; + return NULL; + } + // no --, so search for the first word matching a command + // FIXME: How like is it that an option parameter will be also a valid Match ? + for (size_t i = 1; i < argc; ++i) + { + if (*(argv[i]) == '-') + continue; + for (size_t j = 0; Map[j].Match != NULL; ++j) + if (strcmp(argv[i], Map[j].Match) == 0) + return Map[j].Match; + } + return NULL; +} + /*}}}*/ // CommandLine::Parse - Main action member /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -390,3 +426,15 @@ void CommandLine::SaveInConfig(unsigned int const &argc, char const * const * co _config->Set("CommandLine::AsString", cmdline); } /*}}}*/ +CommandLine::Args CommandLine::MakeArgs(char ShortOpt, char const *LongOpt, char const *ConfName, unsigned long Flags)/*{{{*/ +{ + /* In theory, this should be a constructor for CommandLine::Args instead, + but this breaks compatibility as gcc thinks this is a c++11 initializer_list */ + CommandLine::Args arg; + arg.ShortOpt = ShortOpt; + arg.LongOpt = LongOpt; + arg.ConfName = ConfName; + arg.Flags = Flags; + return arg; +} + /*}}}*/ diff --git a/apt-pkg/contrib/cmndline.h b/apt-pkg/contrib/cmndline.h index 9f505fd41..180276633 100644 --- a/apt-pkg/contrib/cmndline.h +++ b/apt-pkg/contrib/cmndline.h @@ -83,6 +83,12 @@ class CommandLine unsigned int FileSize() const; bool DispatchArg(Dispatch *List,bool NoMatch = true); + static char const * GetCommand(Dispatch const * const Map, + unsigned int const argc, char const * const * const argv); + + static CommandLine::Args MakeArgs(char ShortOpt, char const *LongOpt, + char const *ConfName, unsigned long Flags); + CommandLine(Args *AList,Configuration *Conf); ~CommandLine(); }; diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index df02c3499..d06637155 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -1291,6 +1291,18 @@ bool CheckDomainList(const string &Host,const string &List) return false; } /*}}}*/ +// strv_length - Return the length of a NULL-terminated string array /*{{{*/ +// --------------------------------------------------------------------- +/* */ +size_t strv_length(const char **str_array) +{ + size_t i; + for (i=0; str_array[i] != NULL; i++) + /* nothing */ + ; + return i; +} + // DeEscapeString - unescape (\0XX and \xXX) from a string /*{{{*/ // --------------------------------------------------------------------- /* */ diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index e92f91dc0..530896141 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -108,6 +108,10 @@ inline int stringcasecmp(std::string::const_iterator A,std::string::const_iterat APT_MKSTRCMP2(stringcmp,stringcmp); APT_MKSTRCMP2(stringcasecmp,stringcasecmp); +// Return the length of a NULL-terminated string array +size_t strv_length(const char **str_array); + + inline const char *DeNull(const char *s) {return (s == 0?"(null)":s);}; class URI diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index c2707d0a5..87aab6ee2 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -805,7 +805,7 @@ bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI, map_ptrloc const storage = WriteUniqString(component); FileI->Component = storage; - pkgTagFile TagFile(&File); + pkgTagFile TagFile(&File, File.Size()); pkgTagSection Section; if (_error->PendingError() == true || TagFile.Step(Section) == false) return false; diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 21109ed94..b069f22f7 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -382,24 +382,32 @@ bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf) OptSec = "DPkg::Tools::Options::" + string(Opts->Value.c_str(),Pos); unsigned int Version = _config->FindI(OptSec+"::Version",1); + unsigned int InfoFD = _config->FindI(OptSec + "::InfoFD", STDIN_FILENO); // Create the pipes int Pipes[2]; if (pipe(Pipes) != 0) return _error->Errno("pipe","Failed to create IPC pipe to subprocess"); - SetCloseExec(Pipes[0],true); + if (InfoFD != (unsigned)Pipes[0]) + SetCloseExec(Pipes[0],true); + else + _config->Set("APT::Keep-Fds::", Pipes[0]); SetCloseExec(Pipes[1],true); - + // Purified Fork for running the script - pid_t Process = ExecFork(); + pid_t Process = ExecFork(); if (Process == 0) { // Setup the FDs - dup2(Pipes[0],STDIN_FILENO); + dup2(Pipes[0], InfoFD); SetCloseExec(STDOUT_FILENO,false); - SetCloseExec(STDIN_FILENO,false); + SetCloseExec(STDIN_FILENO,false); SetCloseExec(STDERR_FILENO,false); + string hookfd; + strprintf(hookfd, "%d", InfoFD); + setenv("APT_HOOK_INFO_FD", hookfd.c_str(), 1); + dpkgChrootDirectory(); const char *Args[4]; Args[0] = "/bin/sh"; @@ -409,6 +417,8 @@ bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf) execv(Args[0],(char **)Args); _exit(100); } + if (InfoFD == (unsigned)Pipes[0]) + _config->Clear("APT::Keep-Fds", Pipes[0]); close(Pipes[0]); FILE *F = fdopen(Pipes[1],"w"); if (F == 0) diff --git a/apt-pkg/indexrecords.cc b/apt-pkg/indexrecords.cc index 6d89949a0..8a72ca151 100644 --- a/apt-pkg/indexrecords.cc +++ b/apt-pkg/indexrecords.cc @@ -62,7 +62,7 @@ bool indexRecords::Load(const string Filename) /*{{{*/ if (OpenMaybeClearSignedFile(Filename, Fd) == false) return false; - pkgTagFile TagFile(&Fd); + pkgTagFile TagFile(&Fd, Fd.Size()); if (_error->PendingError() == true) { strprintf(ErrorText, _("Unable to parse Release file %s"),Filename.c_str()); diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc index 1c79ee74f..10bc08d95 100644 --- a/apt-pkg/tagfile.cc +++ b/apt-pkg/tagfile.cc @@ -50,21 +50,27 @@ public: /* */ pkgTagFile::pkgTagFile(FileFd *pFd,unsigned long long Size) { + /* The size is increased by 4 because if we start with the Size of the + filename we need to try to read 1 char more to see an EOF faster, 1 + char the end-pointer can be on and maybe 2 newlines need to be added + to the end of the file -> 4 extra chars */ + Size += 4; d = new pkgTagFilePrivate(pFd, Size); if (d->Fd.IsOpen() == false) - { d->Start = d->End = d->Buffer = 0; + else + d->Buffer = (char*)malloc(sizeof(char) * Size); + + if (d->Buffer == NULL) d->Done = true; - d->iOffset = 0; - return; - } - - d->Buffer = new char[Size]; + else + d->Done = false; + d->Start = d->End = d->Buffer; - d->Done = false; d->iOffset = 0; - Fill(); + if (d->Done == false) + Fill(); } /*}}}*/ // TagFile::~pkgTagFile - Destructor /*{{{*/ @@ -72,11 +78,11 @@ pkgTagFile::pkgTagFile(FileFd *pFd,unsigned long long Size) /* */ pkgTagFile::~pkgTagFile() { - delete [] d->Buffer; + free(d->Buffer); delete d; } /*}}}*/ -// TagFile::Offset - Return the current offset in the buffer /*{{{*/ +// TagFile::Offset - Return the current offset in the buffer /*{{{*/ unsigned long pkgTagFile::Offset() { return d->iOffset; @@ -89,19 +95,22 @@ unsigned long pkgTagFile::Offset() */ bool pkgTagFile::Resize() { - char *tmp; - unsigned long long EndSize = d->End - d->Start; - // fail is the buffer grows too big if(d->Size > 1024*1024+1) return false; + return Resize(d->Size * 2); +} +bool pkgTagFile::Resize(unsigned long long const newSize) +{ + unsigned long long const EndSize = d->End - d->Start; + // get new buffer and use it - tmp = new char[2*d->Size]; - memcpy(tmp, d->Buffer, d->Size); - d->Size = d->Size*2; - delete [] d->Buffer; - d->Buffer = tmp; + char* newBuffer = (char*)realloc(d->Buffer, sizeof(char) * newSize); + if (newBuffer == NULL) + return false; + d->Buffer = newBuffer; + d->Size = newSize; // update the start/end pointers to the new buffer d->Start = d->Buffer; @@ -152,9 +161,10 @@ bool pkgTagFile::Fill() if (d->Done == false) { // See if only a bit of the file is left - if (d->Fd.Read(d->End, d->Size - (d->End - d->Buffer),&Actual) == false) + unsigned long long const dataSize = d->Size - ((d->End - d->Buffer) + 1); + if (d->Fd.Read(d->End, dataSize, &Actual) == false) return false; - if (Actual != d->Size - (d->End - d->Buffer)) + if (Actual != dataSize || d->Fd.Eof() == true) d->Done = true; d->End += Actual; } @@ -171,8 +181,13 @@ bool pkgTagFile::Fill() for (const char *E = d->End - 1; E - d->End < 6 && (*E == '\n' || *E == '\r'); E--) if (*E == '\n') LineCount++; - for (; LineCount < 2; LineCount++) - *d->End++ = '\n'; + if (LineCount < 2) + { + if ((unsigned)(d->End - d->Buffer) >= d->Size) + Resize(d->Size + 3); + for (; LineCount < 2; LineCount++) + *d->End++ = '\n'; + } return true; } diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index fedd72701..66c56799d 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -95,6 +95,7 @@ class pkgTagFile bool Fill(); bool Resize(); + bool Resize(unsigned long long const newSize); public: |