Add create -i option for specifying a package info
This commit is contained in:
@@ -100,6 +100,7 @@ int
|
|||||||
command_create(int argc, const char* const* argv)
|
command_create(int argc, const char* const* argv)
|
||||||
{
|
{
|
||||||
const char* changeToDirectory = NULL;
|
const char* changeToDirectory = NULL;
|
||||||
|
const char* packageInfoFileName = NULL;
|
||||||
bool quiet = false;
|
bool quiet = false;
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
|
|
||||||
@@ -112,7 +113,7 @@ command_create(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, "+C:hqv", sLongOptions, NULL);
|
int c = getopt_long(argc, (char**)argv, "+C:hi:qv", sLongOptions, NULL);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -125,6 +126,10 @@ command_create(int argc, const char* const* argv)
|
|||||||
print_usage_and_exit(false);
|
print_usage_and_exit(false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'i':
|
||||||
|
packageInfoFileName = optarg;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'q':
|
case 'q':
|
||||||
quiet = true;
|
quiet = true;
|
||||||
break;
|
break;
|
||||||
@@ -152,6 +157,16 @@ command_create(int argc, const char* const* argv)
|
|||||||
if (result != B_OK)
|
if (result != B_OK)
|
||||||
return 1;
|
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
|
// change directory, if requested
|
||||||
if (changeToDirectory != NULL) {
|
if (changeToDirectory != NULL) {
|
||||||
if (chdir(changeToDirectory) != 0) {
|
if (chdir(changeToDirectory) != 0) {
|
||||||
@@ -168,16 +183,29 @@ command_create(int argc, const char* const* argv)
|
|||||||
strerror(errno));
|
strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (dirent* entry = readdir(dir)) {
|
while (dirent* entry = readdir(dir)) {
|
||||||
|
// skip "." and ".."
|
||||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||||
continue;
|
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);
|
result = packageWriter.AddEntry(entry->d_name);
|
||||||
if (result != B_OK)
|
if (result != B_OK)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
|
// add the .PackageInfo
|
||||||
|
result = packageWriter.AddEntry(B_HPKG_PACKAGE_INFO_FILE_NAME,
|
||||||
|
packageInfoFD);
|
||||||
|
if (result != B_OK)
|
||||||
|
return 1;
|
||||||
|
|
||||||
// write the package
|
// write the package
|
||||||
result = packageWriter.Finish();
|
result = packageWriter.Finish();
|
||||||
if (result != B_OK)
|
if (result != B_OK)
|
||||||
|
|||||||
@@ -27,8 +27,11 @@ static const char* kUsage =
|
|||||||
" Creates package file <package> from contents of current directory.\n"
|
" Creates package file <package> from contents of current directory.\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -C <dir> - Change to directory <dir> before starting.\n"
|
" -C <dir> - Change to directory <dir> before starting.\n"
|
||||||
" -q - be quiet (don't show any output except for errors).\n"
|
" -i <info> - Use the package info file <info>. It will be added as\n"
|
||||||
" -v - be verbose (show more info about created package).\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"
|
"\n"
|
||||||
" dump [ <options> ] <package>\n"
|
" dump [ <options> ] <package>\n"
|
||||||
" Dumps the TOC section of package file <package>. For debugging only.\n"
|
" Dumps the TOC section of package file <package>. For debugging only.\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user