From 7395bf8a768f1fb4467ddf88db03034bb97d7bb3 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 1 Jul 2011 01:42:23 +0200 Subject: [PATCH] Add create -i option for specifying a package info --- src/bin/package/command_create.cpp | 30 +++++++++++++++++++++++++++++- src/bin/package/package.cpp | 7 +++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/bin/package/command_create.cpp b/src/bin/package/command_create.cpp index 66fbb6c28b..5ca624de2c 100644 --- a/src/bin/package/command_create.cpp +++ b/src/bin/package/command_create.cpp @@ -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) diff --git a/src/bin/package/package.cpp b/src/bin/package/package.cpp index 7d192caff1..2d25611762 100644 --- a/src/bin/package/package.cpp +++ b/src/bin/package/package.cpp @@ -27,8 +27,11 @@ static const char* kUsage = " Creates package file from contents of current directory.\n" "\n" " -C - Change to directory 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 - Use the package info file . 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 [ ] \n" " Dumps the TOC section of package file . For debugging only.\n"