summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2014-01-22 17:18:26 +0100
committerMichael Vogt <mvo@debian.org>2014-01-22 17:18:26 +0100
commit9e51c0b6a3a1a36336820eda11bcfd5534d9d80c (patch)
tree762c18d7ca6a62ce52fdcee00aa0958f44d6341d
parent6d73fe5be080e66a4f6ff2b250ed1957ae7ac063 (diff)
"apt show" show user friendly size info
The size/installed-size is displayed via SizeToStr() and Size is rewriten to "Download-Size" to make clear what size is refered to here.
-rw-r--r--apt-pkg/tagfile.cc84
-rw-r--r--apt-private/private-show.cc28
-rwxr-xr-xtest/integration/test-apt-cli-show3
3 files changed, 65 insertions, 50 deletions
diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc
index bef3c76ba..b92b2c15a 100644
--- a/apt-pkg/tagfile.cc
+++ b/apt-pkg/tagfile.cc
@@ -567,52 +567,54 @@ bool TFRewrite(FILE *Output,pkgTagSection const &Tags,const char *Order[],
}
// Write all all of the tags, in order.
- for (unsigned int I = 0; Order[I] != 0; I++)
+ if (Order != NULL)
{
- bool Rewritten = false;
-
- // See if this is a field that needs to be rewritten
- for (unsigned int J = 0; Rewrite != 0 && Rewrite[J].Tag != 0; J++)
+ for (unsigned int I = 0; Order[I] != 0; I++)
{
- if (strcasecmp(Rewrite[J].Tag,Order[I]) == 0)
- {
- Visited[J] |= 2;
- if (Rewrite[J].Rewrite != 0 && Rewrite[J].Rewrite[0] != 0)
- {
- if (isspace(Rewrite[J].Rewrite[0]))
- fprintf(Output,"%s:%s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite);
- else
- fprintf(Output,"%s: %s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite);
- }
-
- Rewritten = true;
- break;
- }
- }
+ bool Rewritten = false;
+
+ // See if this is a field that needs to be rewritten
+ for (unsigned int J = 0; Rewrite != 0 && Rewrite[J].Tag != 0; J++)
+ {
+ if (strcasecmp(Rewrite[J].Tag,Order[I]) == 0)
+ {
+ Visited[J] |= 2;
+ if (Rewrite[J].Rewrite != 0 && Rewrite[J].Rewrite[0] != 0)
+ {
+ if (isspace(Rewrite[J].Rewrite[0]))
+ fprintf(Output,"%s:%s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite);
+ else
+ fprintf(Output,"%s: %s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite);
+ }
+ Rewritten = true;
+ break;
+ }
+ }
- // See if it is in the fragment
- unsigned Pos;
- if (Tags.Find(Order[I],Pos) == false)
- continue;
- Visited[Pos] |= 1;
-
- if (Rewritten == true)
- continue;
+ // See if it is in the fragment
+ unsigned Pos;
+ if (Tags.Find(Order[I],Pos) == false)
+ continue;
+ Visited[Pos] |= 1;
+
+ if (Rewritten == true)
+ continue;
- /* Write out this element, taking a moment to rewrite the tag
- in case of changes of case. */
- const char *Start;
- const char *Stop;
- Tags.Get(Start,Stop,Pos);
+ /* Write out this element, taking a moment to rewrite the tag
+ in case of changes of case. */
+ const char *Start;
+ const char *Stop;
+ Tags.Get(Start,Stop,Pos);
- if (fputs(Order[I],Output) < 0)
- return _error->Errno("fputs","IO Error to output");
- Start += strlen(Order[I]);
- if (fwrite(Start,Stop - Start,1,Output) != 1)
- return _error->Errno("fwrite","IO Error to output");
- if (Stop[-1] != '\n')
- fprintf(Output,"\n");
- }
+ if (fputs(Order[I],Output) < 0)
+ return _error->Errno("fputs","IO Error to output");
+ Start += strlen(Order[I]);
+ if (fwrite(Start,Stop - Start,1,Output) != 1)
+ return _error->Errno("fwrite","IO Error to output");
+ if (Stop[-1] != '\n')
+ fprintf(Output,"\n");
+ }
+ }
// Now write all the old tags that were missed.
for (unsigned int I = 0; I != Tags.Count(); I++)
diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc
index 0aa42ecce..32a49cc5c 100644
--- a/apt-private/private-show.cc
+++ b/apt-private/private-show.cc
@@ -57,20 +57,32 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V,
return false;
pkgTagSection Tags;
pkgTagFile TagF(&PkgF);
-
+
+ if (TagF.Jump(Tags, V.FileList()->Offset) == false)
+ return _error->Error("Internal Error, Unable to parse a package record");
+
+ // make size nice
+ std::string installed_size;
+ if (Tags.FindI("Installed-Size") > 0)
+ installed_size = SizeToStr(Tags.FindI("Installed-Size")*1024);
+ else
+ installed_size = _("unknown");
+ std::string package_size;
+ if (Tags.FindI("Size") > 0)
+ package_size = SizeToStr(Tags.FindI("Size"));
+ else
+ package_size = _("unknown");
+
TFRewriteData RW[] = {
{"Conffiles",0},
{"Description",0},
{"Description-md5",0},
+ {"Installed-Size", installed_size.c_str(), 0},
+ {"Size", package_size.c_str(), "Download-Size"},
{}
};
- const char *Zero = 0;
- if (TagF.Jump(Tags, V.FileList()->Offset) == false ||
- TFRewrite(stdout,Tags,&Zero,RW) == false)
- {
- _error->Error("Internal Error, Unable to parse a package record");
- return false;
- }
+ if(TFRewrite(stdout, Tags, NULL, RW) == false)
+ return _error->Error("Internal Error, Unable to parse a package record");
// write the description
pkgRecords Recs(*Cache);
diff --git a/test/integration/test-apt-cli-show b/test/integration/test-apt-cli-show
index 0ab3d2e56..bbb2de7ef 100755
--- a/test/integration/test-apt-cli-show
+++ b/test/integration/test-apt-cli-show
@@ -19,11 +19,12 @@ APTARCHIVE=$(readlink -f ./aptarchive)
testequal "Package: foo
Priority: optional
Section: other
-Installed-Size: 42
+Installed-Size: 43.0 k
Maintainer: Joe Sixpack <joe@example.org>
Architecture: all
Version: 1.0
Filename: pool/main/foo/foo_1.0_all.deb
+Download-Size: unknown
Description: Some description
That has multiple lines
" apt show foo