summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2025-01-30 18:03:26 +0000
committerDavid Kalnischkies <david@kalnischkies.de>2025-01-30 19:10:50 +0000
commit1bc8dab8df60c5da7cc817bec5f53e60f7eb9817 (patch)
tree2d67b584affdebb7726c98072462901763bc90c5
parent1bc221a9dd22baa6e2e516d45dc858774cafddd0 (diff)
Drop unused version stanza size info from binary cache
Same reason as with the description size before, but this one had actually one extremely dated user in src:apt left with dumpavail, which is changed to an implementation that is (in comparison) a bit slower, but should be good enough for a command that is ideally not used anymore (even if codesearch suggests otherwise). After all, what makes this a bit slower is not that we don't know the size, but that this one does additional work preparing for accessing the fields which we don't do. In exchange pkgTagFile has a better implementation for "Jitter" than the old code that we would "just" need to copy here if speed were really an issue.
-rw-r--r--apt-pkg/pkgcache.h5
-rw-r--r--apt-pkg/pkgcachegen.cc11
-rw-r--r--cmdline/apt-cache.cc50
3 files changed, 30 insertions, 36 deletions
diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h
index d5d8fcad3..0b61b0048 100644
--- a/apt-pkg/pkgcache.h
+++ b/apt-pkg/pkgcache.h
@@ -604,8 +604,9 @@ struct pkgCache::VerFile
map_pointer<VerFile> NextFile;
/** \brief position in the package file */
map_filesize_t Offset; // File offset
- /** @TODO document pkgCache::VerFile::Size */
- map_filesize_t Size;
+#if APT_PKG_ABI <= 600
+ [[deprecated("No usage in src:apt, try MaxVerFileSize instead")]] map_filesize_t Size;
+#endif
};
/*}}}*/
// DescFile structure /*{{{*/
diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc
index 76dea6266..055b2e08e 100644
--- a/apt-pkg/pkgcachegen.cc
+++ b/apt-pkg/pkgcachegen.cc
@@ -854,9 +854,14 @@ bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator &Ver,
*Last = VF.MapPointer();
VF->Offset = List.Offset();
- VF->Size = List.Size();
- if (Cache.HeaderP->MaxVerFileSize < VF->Size)
- Cache.HeaderP->MaxVerFileSize = VF->Size;
+ auto const Size = List.Size();
+ if (Cache.HeaderP->MaxVerFileSize < Size)
+ Cache.HeaderP->MaxVerFileSize = Size;
+#if APT_PKG_ABI <= 600
+ APT_IGNORE_DEPRECATED_PUSH
+ VF->Size = Size;
+ APT_IGNORE_DEPRECATED_POP
+#endif
Cache.HeaderP->VerFileCount++;
return true;
diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc
index 7fdd4dff2..4ad0b0099 100644
--- a/cmdline/apt-cache.cc
+++ b/cmdline/apt-cache.cc
@@ -464,7 +464,6 @@ static bool DumpAvail(CommandLine &)
stdoutfd.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly, false);
// Iterate over all the package files and write them out.
- char *Buffer = new char[Cache->HeaderP->MaxVerFileSize+10];
for (pkgCache::VerFile **J = VFList; *J != 0;)
{
pkgCache::PkgFileIterator File(*Cache, Cache->PkgFileP + (*J)->File);
@@ -472,40 +471,23 @@ static bool DumpAvail(CommandLine &)
FileFd PkgF(File.FileName(),FileFd::ReadOnly, FileFd::Extension);
if (_error->PendingError() == true)
break;
-
- /* Write all of the records from this package file, since we
- already did locality sorting we can now just seek through the
- file in read order. We apply 1 more optimization here, since often
- there will be < 1 byte gaps between records (for the \n) we read that
- into the next buffer and offset a bit.. */
- unsigned long Pos = 0;
+
+ pkgTagFile tagsfile(&PkgF, Cache->HeaderP->MaxVerFileSize);
+ pkgTagSection Tags;
+
for (; *J != 0; J++)
{
if (Cache->PkgFileP + (*J)->File != File)
break;
-
- const pkgCache::VerFile &VF = **J;
- // Read the record and then write it out again.
- unsigned long Jitter = VF.Offset - Pos;
- if (Jitter > 8)
- {
- if (PkgF.Seek(VF.Offset) == false)
- break;
- Jitter = 0;
- }
-
- if (PkgF.Read(Buffer,VF.Size + Jitter) == false)
+ const pkgCache::VerFile &VF = **J;
+ if (not tagsfile.Jump(Tags, VF.Offset))
break;
- Buffer[VF.Size + Jitter] = '\n';
- // See above..
if ((File->Flags & pkgCache::Flag::NotSource) == pkgCache::Flag::NotSource)
{
- pkgTagSection Tags;
- if (Tags.Scan(Buffer+Jitter,VF.Size+1) == false ||
- Tags.Write(stdoutfd, NULL, RW) == false ||
- stdoutfd.Write("\n", 1) == false)
+ if (not Tags.Write(stdoutfd, NULL, RW) ||
+ not stdoutfd.Write("\n", 1))
{
_error->Error("Internal Error, Unable to parse a package record");
break;
@@ -513,18 +495,24 @@ static bool DumpAvail(CommandLine &)
}
else
{
- if (stdoutfd.Write(Buffer + Jitter, VF.Size + 1) == false)
+ char const *Start, *Stop;
+ Tags.GetSection(Start, Stop);
+ for (; Start < Stop; --Stop)
+ if (std::string_view{"\n\r"}.find(*(Stop - 1)) == std::string_view::npos)
+ break;
+ if (not stdoutfd.Write(Start, Stop - Start) ||
+ not stdoutfd.Write("\n\n", 2))
+ {
+ _error->Error("Internal Error, Unable to parse a package record");
break;
+ }
}
-
- Pos = VF.Offset + VF.Size;
}
- if (_error->PendingError() == true)
+ if (_error->PendingError())
break;
}
- delete [] Buffer;
delete [] VFList;
return !_error->PendingError();
}