From e2c66de5c5e63d8400efb0522c31fbe1ec225f93 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 3 Jun 2010 09:22:00 +0200 Subject: * apt-pkg/pkgcache.h: - switch {,Install-}Size to unsigned long long * apt-pkg/depcache.cc: - deal with long long, not with int to remove 2GB Limit (LP: #250909) --- apt-pkg/acquire-item.h | 4 ++-- apt-pkg/deb/deblistparser.cc | 5 ++--- apt-pkg/depcache.cc | 14 +++++++------- apt-pkg/pkgcache.h | 4 ++-- apt-pkg/tagfile.cc | 24 ++++++++++++++++++++++++ apt-pkg/tagfile.h | 1 + 6 files changed, 38 insertions(+), 14 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h index b338b2a41..36fc53b92 100644 --- a/apt-pkg/acquire-item.h +++ b/apt-pkg/acquire-item.h @@ -112,10 +112,10 @@ class pkgAcquire::Item : public WeakPointable string ErrorText; /** \brief The size of the object to fetch. */ - unsigned long FileSize; + unsigned long long FileSize; /** \brief How much of the object was already fetched. */ - unsigned long PartialSize; + unsigned long long PartialSize; /** \brief If not \b NULL, contains the name of a subprocess that * is operating on this object (for instance, "gzip" or "gpgv"). diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 0551a5f7c..83c5b8d2e 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -133,10 +133,9 @@ bool debListParser::NewVersion(pkgCache::VerIterator Ver) } // Archive Size - Ver->Size = (unsigned)Section.FindI("Size"); - + Ver->Size = Section.FindULL("Size"); // Unpacked Size (in K) - Ver->InstalledSize = (unsigned)Section.FindI("Installed-Size"); + Ver->InstalledSize = Section.FindULL("Installed-Size"); Ver->InstalledSize *= 1024; // Priority diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 411ae5f62..6e0eeab5b 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -422,8 +422,8 @@ void pkgDepCache::AddSizes(const PkgIterator &Pkg,signed long Mult) // Compute the size data if (P.NewInstall() == true) { - iUsrSize += (signed)(Mult*P.InstVerIter(*this)->InstalledSize); - iDownloadSize += (signed)(Mult*P.InstVerIter(*this)->Size); + iUsrSize += (signed long long)(Mult*P.InstVerIter(*this)->InstalledSize); + iDownloadSize += (signed long long)(Mult*P.InstVerIter(*this)->Size); return; } @@ -432,9 +432,9 @@ void pkgDepCache::AddSizes(const PkgIterator &Pkg,signed long Mult) (P.InstallVer != (Version *)Pkg.CurrentVer() || (P.iFlags & ReInstall) == ReInstall) && P.InstallVer != 0) { - iUsrSize += (signed)(Mult*((signed)P.InstVerIter(*this)->InstalledSize - - (signed)Pkg.CurrentVer()->InstalledSize)); - iDownloadSize += (signed)(Mult*P.InstVerIter(*this)->Size); + iUsrSize += (signed long long)(Mult*((signed long long)P.InstVerIter(*this)->InstalledSize - + (signed long long)Pkg.CurrentVer()->InstalledSize)); + iDownloadSize += (signed long long)(Mult*P.InstVerIter(*this)->Size); return; } @@ -442,14 +442,14 @@ void pkgDepCache::AddSizes(const PkgIterator &Pkg,signed long Mult) if (Pkg.State() == pkgCache::PkgIterator::NeedsUnpack && P.Delete() == false) { - iDownloadSize += (signed)(Mult*P.InstVerIter(*this)->Size); + iDownloadSize += (signed long long)(Mult*P.InstVerIter(*this)->Size); return; } // Removing if (Pkg->CurrentVer != 0 && P.InstallVer == 0) { - iUsrSize -= (signed)(Mult*Pkg.CurrentVer()->InstalledSize); + iUsrSize -= (signed long long)(Mult*Pkg.CurrentVer()->InstalledSize); return; } } diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h index 643f240b0..426bb9f13 100644 --- a/apt-pkg/pkgcache.h +++ b/apt-pkg/pkgcache.h @@ -532,9 +532,9 @@ struct pkgCache::Version /** \brief archive size for this version For Debian this is the size of the .deb file. */ - map_ptrloc Size; // These are the .deb size + unsigned long long Size; // These are the .deb size /** \brief uncompressed size for this version */ - map_ptrloc InstalledSize; + unsigned long long InstalledSize; /** \brief characteristic value representing this version No two packages in existence should have the same VerStr diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc index 0d4999ee7..1394d7e24 100644 --- a/apt-pkg/tagfile.cc +++ b/apt-pkg/tagfile.cc @@ -365,6 +365,30 @@ signed int pkgTagSection::FindI(const char *Tag,signed long Default) const return Result; } /*}}}*/ +// TagSection::FindULL - Find an unsigned long long integer /*{{{*/ +// --------------------------------------------------------------------- +/* */ +unsigned long long pkgTagSection::FindULL(const char *Tag, unsigned long long const &Default) const +{ + const char *Start; + const char *Stop; + if (Find(Tag,Start,Stop) == false) + return Default; + + // Copy it into a temp buffer so we can use strtoull + char S[100]; + if ((unsigned)(Stop - Start) >= sizeof(S)) + return Default; + strncpy(S,Start,Stop-Start); + S[Stop - Start] = 0; + + char *End; + unsigned long long Result = strtoull(S,&End,10); + if (S == End) + return Default; + return Result; +} + /*}}}*/ // TagSection::FindFlag - Locate a yes/no type flag /*{{{*/ // --------------------------------------------------------------------- /* The bits marked in Flag are masked on/off in Flags */ diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index f63a51d07..6891c1d81 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -57,6 +57,7 @@ class pkgTagSection bool Find(const char *Tag,unsigned &Pos) const; string FindS(const char *Tag) const; signed int FindI(const char *Tag,signed long Default = 0) const ; + unsigned long long FindULL(const char *Tag, unsigned long long const &Default = 0) const; bool FindFlag(const char *Tag,unsigned long &Flags, unsigned long Flag) const; bool Scan(const char *Start,unsigned long MaxLength); -- cgit v1.2.3 From 81305a0b30cc12aa6d32081bbdcf930907ecfbbe Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 3 Jun 2010 09:50:06 +0200 Subject: deprecate AddSize with Multiplier as it is unused and switch to boolean instead to handle the sizes more gracefully. --- apt-pkg/depcache.cc | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++-- apt-pkg/depcache.h | 5 ++-- 2 files changed, 74 insertions(+), 4 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 6e0eeab5b..786b20ec0 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -407,8 +407,11 @@ bool pkgDepCache::CheckDep(DepIterator Dep,int Type,PkgIterator &Res) /*}}}*/ // DepCache::AddSizes - Add the packages sizes to the counters /*{{{*/ // --------------------------------------------------------------------- -/* Call with Mult = -1 to preform the inverse opration */ -void pkgDepCache::AddSizes(const PkgIterator &Pkg,signed long Mult) +/* Call with Mult = -1 to preform the inverse opration + The Mult increases the complexity of the calulations here and is unused - + or do we really have a usecase for removing the size of a package two + times? So let us replace it with a simple bool and be done with it… */ +__deprecated void pkgDepCache::AddSizes(const PkgIterator &Pkg,signed long Mult) { StateCache &P = PkgState[Pkg->ID]; @@ -454,6 +457,72 @@ void pkgDepCache::AddSizes(const PkgIterator &Pkg,signed long Mult) } } /*}}}*/ +// DepCache::AddSizes - Add the packages sizes to the counters /*{{{*/ +// --------------------------------------------------------------------- +/* Call with Inverse = true to preform the inverse opration */ +void pkgDepCache::AddSizes(const PkgIterator &Pkg, bool const &Inverse) +{ + StateCache &P = PkgState[Pkg->ID]; + + if (Pkg->VersionList == 0) + return; + + if (Pkg.State() == pkgCache::PkgIterator::NeedsConfigure && + P.Keep() == true) + return; + + // Compute the size data + if (P.NewInstall() == true) + { + if (Inverse == false) { + iUsrSize += P.InstVerIter(*this)->InstalledSize; + iDownloadSize += P.InstVerIter(*this)->Size; + } else { + iUsrSize -= P.InstVerIter(*this)->InstalledSize; + iDownloadSize -= P.InstVerIter(*this)->Size; + } + return; + } + + // Upgrading + if (Pkg->CurrentVer != 0 && + (P.InstallVer != (Version *)Pkg.CurrentVer() || + (P.iFlags & ReInstall) == ReInstall) && P.InstallVer != 0) + { + if (Inverse == false) { + iUsrSize -= Pkg.CurrentVer()->InstalledSize; + iUsrSize += P.InstVerIter(*this)->InstalledSize; + iDownloadSize += P.InstVerIter(*this)->Size; + } else { + iUsrSize -= P.InstVerIter(*this)->InstalledSize; + iUsrSize += Pkg.CurrentVer()->InstalledSize; + iDownloadSize -= P.InstVerIter(*this)->Size; + } + return; + } + + // Reinstall + if (Pkg.State() == pkgCache::PkgIterator::NeedsUnpack && + P.Delete() == false) + { + if (Inverse == false) + iDownloadSize += P.InstVerIter(*this)->Size; + else + iDownloadSize -= P.InstVerIter(*this)->Size; + return; + } + + // Removing + if (Pkg->CurrentVer != 0 && P.InstallVer == 0) + { + if (Inverse == false) + iUsrSize -= Pkg.CurrentVer()->InstalledSize; + else + iUsrSize += Pkg.CurrentVer()->InstalledSize; + return; + } +} + /*}}}*/ // DepCache::AddStates - Add the package to the state counter /*{{{*/ // --------------------------------------------------------------------- /* This routine is tricky to use, you must make sure that it is never diff --git a/apt-pkg/depcache.h b/apt-pkg/depcache.h index 3decc7a5f..d4258438f 100644 --- a/apt-pkg/depcache.h +++ b/apt-pkg/depcache.h @@ -321,8 +321,9 @@ class pkgDepCache : protected pkgCache::Namespace void Update(PkgIterator const &P); // Count manipulators - void AddSizes(const PkgIterator &Pkg,signed long Mult = 1); - inline void RemoveSizes(const PkgIterator &Pkg) {AddSizes(Pkg,-1);}; + void AddSizes(const PkgIterator &Pkg, bool const &Invert = false); + inline void RemoveSizes(const PkgIterator &Pkg) {AddSizes(Pkg, true);}; + void AddSizes(const PkgIterator &Pkg,signed long Mult) __deprecated; void AddStates(const PkgIterator &Pkg,int Add = 1); inline void RemoveStates(const PkgIterator &Pkg) {AddStates(Pkg,-1);}; -- cgit v1.2.3 From a3c4c81afe25377020470ff71c1362136437397c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 3 Jun 2010 10:45:58 +0200 Subject: * apt-pkg/depcache.cc: - switch i{Download,Usr}Size from double to (un)signed long long The biggest reason is that this saves a lot of float point operations we do in AddSizes() on integers. The only reason i see that this was a double is that it was 64bit long and can therefore store bigger values than int/long, but with the availablity of (un)signed long long we are now also at 64bit and can store sizes more than 8 Exabytes big - by the time this will be a limit the C/C++ Standard will have bigger types, hopefully. --- apt-pkg/acquire.cc | 12 ++++++------ apt-pkg/acquire.h | 6 +++--- apt-pkg/depcache.h | 12 +++++++----- 3 files changed, 16 insertions(+), 14 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 832eaa02c..63825da93 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -506,9 +506,9 @@ bool pkgAcquire::Clean(string Dir) // Acquire::TotalNeeded - Number of bytes to fetch /*{{{*/ // --------------------------------------------------------------------- /* This is the total number of bytes needed */ -double pkgAcquire::TotalNeeded() +unsigned long long pkgAcquire::TotalNeeded() { - double Total = 0; + unsigned long long Total = 0; for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); I++) Total += (*I)->FileSize; return Total; @@ -517,9 +517,9 @@ double pkgAcquire::TotalNeeded() // Acquire::FetchNeeded - Number of bytes needed to get /*{{{*/ // --------------------------------------------------------------------- /* This is the number of bytes that is not local */ -double pkgAcquire::FetchNeeded() +unsigned long long pkgAcquire::FetchNeeded() { - double Total = 0; + unsigned long long Total = 0; for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); I++) if ((*I)->Local == false) Total += (*I)->FileSize; @@ -529,9 +529,9 @@ double pkgAcquire::FetchNeeded() // Acquire::PartialPresent - Number of partial bytes we already have /*{{{*/ // --------------------------------------------------------------------- /* This is the number of bytes that is not local */ -double pkgAcquire::PartialPresent() +unsigned long long pkgAcquire::PartialPresent() { - double Total = 0; + unsigned long long Total = 0; for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); I++) if ((*I)->Local == false) Total += (*I)->PartialSize; diff --git a/apt-pkg/acquire.h b/apt-pkg/acquire.h index 8e2c21151..82be8b843 100644 --- a/apt-pkg/acquire.h +++ b/apt-pkg/acquire.h @@ -323,17 +323,17 @@ class pkgAcquire /** \return the total size in bytes of all the items included in * this download. */ - double TotalNeeded(); + unsigned long long TotalNeeded(); /** \return the size in bytes of all non-local items included in * this download. */ - double FetchNeeded(); + unsigned long long FetchNeeded(); /** \return the amount of data to be fetched that is already * present on the filesystem. */ - double PartialPresent(); + unsigned long long PartialPresent(); /** \brief Delayed constructor * diff --git a/apt-pkg/depcache.h b/apt-pkg/depcache.h index d4258438f..c6f245a80 100644 --- a/apt-pkg/depcache.h +++ b/apt-pkg/depcache.h @@ -286,9 +286,11 @@ class pkgDepCache : protected pkgCache::Namespace pkgCache *Cache; StateCache *PkgState; unsigned char *DepState; - - double iUsrSize; - double iDownloadSize; + + /** Stores the space changes after installation */ + signed long long iUsrSize; + /** Stores how much we need to download to get the packages */ + unsigned long long iDownloadSize; unsigned long iInstCount; unsigned long iDelCount; unsigned long iKeepCount; @@ -452,8 +454,8 @@ class pkgDepCache : protected pkgCache::Namespace bool writeStateFile(OpProgress *prog, bool InstalledOnly=true); // Size queries - inline double UsrSize() {return iUsrSize;}; - inline double DebSize() {return iDownloadSize;}; + inline signed long long UsrSize() {return iUsrSize;}; + inline unsigned long long DebSize() {return iDownloadSize;}; inline unsigned long DelCount() {return iDelCount;}; inline unsigned long KeepCount() {return iKeepCount;}; inline unsigned long InstCount() {return iInstCount;}; -- cgit v1.2.3