package list: add option '-i' to list only the meta info
This commit is contained in:
@@ -78,18 +78,29 @@ struct VersionPolicyV2 {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum ListMode {
|
||||||
|
LIST_ALL,
|
||||||
|
LIST_PATHS_ONLY,
|
||||||
|
LIST_META_INFO_ONLY
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
template<typename VersionPolicy>
|
template<typename VersionPolicy>
|
||||||
struct PackageContentListHandler : VersionPolicy::PackageContentHandler {
|
struct PackageContentListHandler : VersionPolicy::PackageContentHandler {
|
||||||
PackageContentListHandler(bool listAttributes)
|
PackageContentListHandler(bool listEntries, bool listAttributes)
|
||||||
:
|
:
|
||||||
fPrinter(),
|
fPrinter(),
|
||||||
fLevel(0),
|
fLevel(0),
|
||||||
fListAttribute(listAttributes)
|
fListEntries(listEntries),
|
||||||
|
fListAttribute(listEntries && listAttributes)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual status_t HandleEntry(typename VersionPolicy::PackageEntry* entry)
|
virtual status_t HandleEntry(typename VersionPolicy::PackageEntry* entry)
|
||||||
{
|
{
|
||||||
|
if (!fListEntries)
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
fLevel++;
|
fLevel++;
|
||||||
|
|
||||||
int indentation = (fLevel - 1) * 2;
|
int indentation = (fLevel - 1) * 2;
|
||||||
@@ -162,6 +173,9 @@ struct PackageContentListHandler : VersionPolicy::PackageContentHandler {
|
|||||||
virtual status_t HandleEntryDone(
|
virtual status_t HandleEntryDone(
|
||||||
typename VersionPolicy::PackageEntry* entry)
|
typename VersionPolicy::PackageEntry* entry)
|
||||||
{
|
{
|
||||||
|
if (!fListEntries)
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
fLevel--;
|
fLevel--;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -208,6 +222,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
PackageInfoPrinter fPrinter;
|
PackageInfoPrinter fPrinter;
|
||||||
int fLevel;
|
int fLevel;
|
||||||
|
bool fListEntries;
|
||||||
bool fListAttribute;
|
bool fListAttribute;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -258,7 +273,7 @@ private:
|
|||||||
|
|
||||||
template<typename VersionPolicy>
|
template<typename VersionPolicy>
|
||||||
static void
|
static void
|
||||||
do_list(const char* packageFileName, bool listAttributes, bool filePathsOnly,
|
do_list(const char* packageFileName, bool listAttributes, ListMode listMode,
|
||||||
bool ignoreVersionError)
|
bool ignoreVersionError)
|
||||||
{
|
{
|
||||||
// open package
|
// open package
|
||||||
@@ -272,13 +287,23 @@ do_list(const char* packageFileName, bool listAttributes, bool filePathsOnly,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// list
|
// list
|
||||||
if (filePathsOnly) {
|
switch (listMode) {
|
||||||
|
case LIST_PATHS_ONLY:
|
||||||
|
{
|
||||||
PackageContentListPathsHandler<VersionPolicy> handler;
|
PackageContentListPathsHandler<VersionPolicy> handler;
|
||||||
error = packageReader.ParseContent(&handler);
|
error = packageReader.ParseContent(&handler);
|
||||||
} else {
|
break;
|
||||||
PackageContentListHandler<VersionPolicy> handler(listAttributes);
|
}
|
||||||
|
|
||||||
|
case LIST_ALL:
|
||||||
|
case LIST_META_INFO_ONLY:
|
||||||
|
{
|
||||||
|
PackageContentListHandler<VersionPolicy> handler(
|
||||||
|
listMode != LIST_META_INFO_ONLY, listAttributes);
|
||||||
error = packageReader.ParseContent(&handler);
|
error = packageReader.ParseContent(&handler);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
@@ -289,8 +314,8 @@ do_list(const char* packageFileName, bool listAttributes, bool filePathsOnly,
|
|||||||
int
|
int
|
||||||
command_list(int argc, const char* const* argv)
|
command_list(int argc, const char* const* argv)
|
||||||
{
|
{
|
||||||
|
ListMode listMode = LIST_ALL;
|
||||||
bool listAttributes = false;
|
bool listAttributes = false;
|
||||||
bool filePathsOnly = false;
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
static struct option sLongOptions[] = {
|
static struct option sLongOptions[] = {
|
||||||
@@ -299,7 +324,7 @@ command_list(int argc, const char* const* argv)
|
|||||||
};
|
};
|
||||||
|
|
||||||
opterr = 0; // don't print errors
|
opterr = 0; // don't print errors
|
||||||
int c = getopt_long(argc, (char**)argv, "+hap", sLongOptions, NULL);
|
int c = getopt_long(argc, (char**)argv, "+ahip", sLongOptions, NULL);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -308,12 +333,16 @@ command_list(int argc, const char* const* argv)
|
|||||||
listAttributes = true;
|
listAttributes = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'i':
|
||||||
|
listMode = LIST_META_INFO_ONLY;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
print_usage_and_exit(false);
|
print_usage_and_exit(false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
filePathsOnly = true;
|
listMode = LIST_PATHS_ONLY;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -331,10 +360,8 @@ command_list(int argc, const char* const* argv)
|
|||||||
BHPKG::BStandardErrorOutput errorOutput;
|
BHPKG::BStandardErrorOutput errorOutput;
|
||||||
|
|
||||||
// current package file format version
|
// current package file format version
|
||||||
do_list<VersionPolicyV2>(packageFileName, listAttributes, filePathsOnly,
|
do_list<VersionPolicyV2>(packageFileName, listAttributes, listMode, true);
|
||||||
true);
|
do_list<VersionPolicyV1>(packageFileName, listAttributes, listMode, false);
|
||||||
do_list<VersionPolicyV1>(packageFileName, listAttributes, filePathsOnly,
|
|
||||||
false);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ static const char* kUsage =
|
|||||||
" Lists the contents of package file <package>.\n"
|
" Lists the contents of package file <package>.\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -a - Also list the file attributes.\n"
|
" -a - Also list the file attributes.\n"
|
||||||
|
" -i - Only print the meta information, not the files.\n"
|
||||||
" -p - Only print a list of file paths.\n"
|
" -p - Only print a list of file paths.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Common Options:\n"
|
"Common Options:\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user