summaryrefslogtreecommitdiff
path: root/cmdline
diff options
context:
space:
mode:
authorDavid Kalnischkies <kalnischkies@gmail.com>2013-06-16 15:42:31 +0200
committerDavid Kalnischkies <kalnischkies@gmail.com>2013-06-20 10:46:14 +0200
commit99359751efb1ad84e877219639030feb47fb28f7 (patch)
treea3993ffc03d0cae502ad2e81d25dd5ad7982dfe0 /cmdline
parent00612a8c55aab3560966533fe77e4940f902b3b6 (diff)
handle missing "Description" in apt-cache show
do not blindly assume that all packages stanzas have a "Description:" field in 'apt-cache show' as well as in the cache creation itself. We instead assume now that if the stanza has a Description, it will not be the first field as we look out for "\nDescription" to take care of MD5sum as well as (maybe ignored) translated Descriptions embedded in the package stanza. Closes: #712435
Diffstat (limited to 'cmdline')
-rw-r--r--cmdline/apt-cache.cc47
1 files changed, 32 insertions, 15 deletions
diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc
index bda09a5a1..fb4467c2c 100644
--- a/cmdline/apt-cache.cc
+++ b/cmdline/apt-cache.cc
@@ -1161,7 +1161,11 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V)
}
// Get a pointer to start of Description field
- const unsigned char *DescP = (unsigned char*)strstr((char*)Buffer, "Description:");
+ const unsigned char *DescP = (unsigned char*)strstr((char*)Buffer, "\nDescription");
+ if (DescP != NULL)
+ ++DescP;
+ else
+ DescP = Buffer + V.FileList()->Size;
// Write all but Description
if (fwrite(Buffer,1,DescP - Buffer,stdout) < (size_t)(DescP - Buffer))
@@ -1173,25 +1177,38 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V)
// Show the right description
pkgRecords Recs(*Cache);
pkgCache::DescIterator Desc = V.TranslatedDescription();
- pkgRecords::Parser &P = Recs.Lookup(Desc.FileList());
- cout << "Description" << ( (strcmp(Desc.LanguageCode(),"") != 0) ? "-" : "" ) << Desc.LanguageCode() << ": " << P.LongDesc();
-
- // Find the first field after the description (if there is any)
- for(DescP++;DescP != &Buffer[V.FileList()->Size];DescP++)
+ if (Desc.end() == false)
{
- if(*DescP == '\n' && *(DescP+1) != ' ')
+ pkgRecords::Parser &P = Recs.Lookup(Desc.FileList());
+ cout << "Description" << ( (strcmp(Desc.LanguageCode(),"") != 0) ? "-" : "" ) << Desc.LanguageCode() << ": " << P.LongDesc();
+ cout << std::endl << "Description-md5: " << Desc.md5() << std::endl;
+
+ // Find the first field after the description (if there is any)
+ while ((DescP = (unsigned char*)strchr((char*)DescP, '\n')) != NULL)
{
- // write the rest of the buffer
- const unsigned char *end=&Buffer[V.FileList()->Size];
- if (fwrite(DescP,1,end-DescP,stdout) < (size_t)(end-DescP))
- {
- delete [] Buffer;
- return false;
- }
+ if (DescP[1] == ' ')
+ DescP += 2;
+ else if (strncmp((char*)DescP, "\nDescription", strlen("\nDescription")) == 0)
+ DescP += strlen("\nDescription");
+ else
+ break;
+ }
+ if (DescP != NULL)
+ ++DescP;
+ }
+ // if we have no translation, we found a lonely Description-md5, so don't skip it
- break;
+ if (DescP != NULL)
+ {
+ // write the rest of the buffer
+ const unsigned char *end=&Buffer[V.FileList()->Size];
+ if (fwrite(DescP,1,end-DescP,stdout) < (size_t)(end-DescP))
+ {
+ delete [] Buffer;
+ return false;
}
}
+
// write a final newline (after the description)
cout<<endl;
delete [] Buffer;