Add create -i option for specifying a package info

This commit is contained in:
Ingo Weinhold 2011-07-01 01:42:23 +02:00
parent 0f9a98a419
commit 7395bf8a76
2 changed files with 34 additions and 3 deletions

View File

@ -100,6 +100,7 @@ int
command_create(int argc, const char* const* argv)
{
const char* changeToDirectory = NULL;
const char* packageInfoFileName = NULL;
bool quiet = false;
bool verbose = false;
@ -112,7 +113,7 @@ command_create(int argc, const char* const* argv)
};
opterr = 0; // don't print errors
int c = getopt_long(argc, (char**)argv, "+C:hqv", sLongOptions, NULL);
int c = getopt_long(argc, (char**)argv, "+C:hi:qv", sLongOptions, NULL);
if (c == -1)
break;
@ -125,6 +126,10 @@ command_create(int argc, const char* const* argv)
print_usage_and_exit(false);
break;
case 'i':
packageInfoFileName = optarg;
break;
case 'q':
quiet = true;
break;
@ -152,6 +157,16 @@ command_create(int argc, const char* const* argv)
if (result != B_OK)
return 1;
// If a package info file has been specified explicitly, open it.
int packageInfoFD = -1;
if (packageInfoFileName != NULL) {
packageInfoFD = open(packageInfoFileName, O_RDONLY);
if (packageInfoFD < 0) {
fprintf(stderr, "Error: Failed to open package info file \"%s\": "
"%s\n", packageInfoFileName, strerror(errno));
}
}
// change directory, if requested
if (changeToDirectory != NULL) {
if (chdir(changeToDirectory) != 0) {
@ -168,16 +183,29 @@ command_create(int argc, const char* const* argv)
strerror(errno));
return 1;
}
while (dirent* entry = readdir(dir)) {
// skip "." and ".."
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
continue;
// also skip the .PackageInfo -- we'll add it later
if (strcmp(entry->d_name, B_HPKG_PACKAGE_INFO_FILE_NAME) == 0)
continue;
result = packageWriter.AddEntry(entry->d_name);
if (result != B_OK)
return 1;
}
closedir(dir);
// add the .PackageInfo
result = packageWriter.AddEntry(B_HPKG_PACKAGE_INFO_FILE_NAME,
packageInfoFD);
if (result != B_OK)
return 1;
// write the package
result = packageWriter.Finish();
if (result != B_OK)

View File

@ -27,8 +27,11 @@ static const char* kUsage =
" Creates package file <package> from contents of current directory.\n"
"\n"
" -C <dir> - Change to directory <dir> before starting.\n"
" -q - be quiet (don't show any output except for errors).\n"
" -v - be verbose (show more info about created package).\n"
" -i <info> - Use the package info file <info>. It will be added as\n"
" \".PackageInfo\", overriding a \".PackageInfo\" file,\n"
" existing.\n"
" -q - Be quiet (don't show any output except for errors).\n"
" -v - Be verbose (show more info about created package).\n"
"\n"
" dump [ <options> ] <package>\n"
" Dumps the TOC section of package file <package>. For debugging only.\n"