Author: zooey Date: 2011-02-09 20:11:23 +0100 (Wed, 09 Feb 2011) New Revision: 40405 Changeset: http://dev.haiku-os.org/changeset/40405 Added: haiku/trunk/headers/os/package/RepositoryInfo.h haiku/trunk/src/bin/package_repo/ haiku/trunk/src/bin/package_repo/Jamfile haiku/trunk/src/bin/package_repo/command_create.cpp haiku/trunk/src/bin/package_repo/command_list.cpp haiku/trunk/src/bin/package_repo/package_repo.cpp haiku/trunk/src/bin/package_repo/package_repo.h haiku/trunk/src/kits/package/RepositoryInfo.cpp Removed: haiku/trunk/headers/os/package/RepositoryHeader.h haiku/trunk/src/kits/package/RepositoryHeader.cpp Modified: haiku/trunk/headers/os/package/PackageInfo.h haiku/trunk/headers/os/package/PackageInfoAttributes.h haiku/trunk/headers/os/package/PackageResolvable.h haiku/trunk/headers/os/package/PackageResolvableExpression.h haiku/trunk/headers/os/package/PackageVersion.h haiku/trunk/headers/os/package/RepositoryCache.h haiku/trunk/headers/os/package/hpkg/PackageContentHandler.h haiku/trunk/headers/os/package/hpkg/RepositoryWriter.h haiku/trunk/headers/private/package/ActivateRepositoryConfigJob.h haiku/trunk/headers/private/package/hpkg/RepositoryWriterImpl.h haiku/trunk/headers/private/package/hpkg/haiku_package.h haiku/trunk/src/add-ons/kernel/file_systems/packagefs/Volume.cpp haiku/trunk/src/bin/Jamfile haiku/trunk/src/bin/package/command_create.cpp haiku/trunk/src/bin/package/command_extract.cpp haiku/trunk/src/bin/package/command_list.cpp haiku/trunk/src/bin/package/package.cpp haiku/trunk/src/kits/package/ActivateRepositoryConfigJob.cpp haiku/trunk/src/kits/package/AddRepositoryRequest.cpp haiku/trunk/src/kits/package/Jamfile haiku/trunk/src/kits/package/PackageInfo.cpp haiku/trunk/src/kits/package/PackageResolvable.cpp haiku/trunk/src/kits/package/PackageResolvableExpression.cpp haiku/trunk/src/kits/package/PackageVersion.cpp haiku/trunk/src/kits/package/RepositoryCache.cpp haiku/trunk/src/kits/package/hpkg/PackageReaderImpl.cpp haiku/trunk/src/kits/package/hpkg/RepositoryWriter.cpp haiku/trunk/src/kits/package/hpkg/RepositoryWriterImpl.cpp haiku/trunk/src/tests/kits/package/make_repo.cpp Log: Implemented repository writing: * fleshed out RepositoryWriterImpl * renamed BRepositoryHeader to BRepositoryInfo (in accordance with BPackageInfo) * adjusted BRepositoryInfo to be able to parse itself from a driver_settings file * added package_repo binary (only 'create' works as of yet) Modified: haiku/trunk/headers/os/package/PackageInfo.h =================================================================== --- haiku/trunk/headers/os/package/PackageInfo.h 2011-02-09 11:28:56 UTC (rev 40404) +++ haiku/trunk/headers/os/package/PackageInfo.h 2011-02-09 19:11:23 UTC (rev 40405) @@ -55,6 +55,7 @@ const BString& Description() const; const BString& Vendor() const; const BString& Packager() const; + const BString& Checksum() const; uint32 Flags() const; @@ -81,6 +82,7 @@ void SetDescription(const BString& description); void SetVendor(const BString& vendor); void SetPackager(const BString& packager); + void SetChecksum(const BString& checksum); void SetFlags(uint32 flags); @@ -120,6 +122,9 @@ void Clear(); public: + static status_t GetArchitectureByName(const BString& name, + BPackageArchitecture& _architecture); + static const char* kElementNames[]; static const char* kArchitectureNames[]; @@ -152,6 +157,8 @@ BObjectList<BPackageResolvableExpression> fFreshensList; BObjectList<BString> fReplacesList; + + BString fChecksum; }; Modified: haiku/trunk/headers/os/package/PackageInfoAttributes.h =================================================================== --- haiku/trunk/headers/os/package/PackageInfoAttributes.h 2011-02-09 11:28:56 UTC (rev 40404) +++ haiku/trunk/headers/os/package/PackageInfoAttributes.h 2011-02-09 19:11:23 UTC (rev 40405) @@ -34,6 +34,7 @@ B_PACKAGE_INFO_REPLACES, // list of resolvables that this package // will replace (upon update) B_PACKAGE_INFO_FLAGS, + B_PACKAGE_INFO_CHECKSUM, // sha256-checksum // B_PACKAGE_INFO_ENUM_COUNT, }; Modified: haiku/trunk/headers/os/package/PackageResolvable.h =================================================================== --- haiku/trunk/headers/os/package/PackageResolvable.h 2011-02-09 11:28:56 UTC (rev 40404) +++ haiku/trunk/headers/os/package/PackageResolvable.h 2011-02-09 19:11:23 UTC (rev 40405) @@ -15,6 +15,12 @@ namespace BPackageKit { +namespace BHPKG { + class BPackageResolvableData; +} +using BHPKG::BPackageResolvableData; + + /* * Defines a resolvable (something other packages can depend upon). * Each resolvable is defined as a name (with an optional type prefix) @@ -39,6 +45,8 @@ class BPackageResolvable { public: BPackageResolvable(); + BPackageResolvable( + const BPackageResolvableData& data); BPackageResolvable(const BString& name, BPackageResolvableType type = B_PACKAGE_RESOLVABLE_TYPE_DEFAULT, Modified: haiku/trunk/headers/os/package/PackageResolvableExpression.h =================================================================== --- haiku/trunk/headers/os/package/PackageResolvableExpression.h 2011-02-09 11:28:56 UTC (rev 40404) +++ haiku/trunk/headers/os/package/PackageResolvableExpression.h 2011-02-09 19:11:23 UTC (rev 40405) @@ -15,6 +15,12 @@ namespace BPackageKit { +namespace BHPKG { + class BPackageResolvableExpressionData; +} +using BHPKG::BPackageResolvableExpressionData; + + /* * Expresses a constraint on a specific resolvable, either just a name * or a name plus a relational operator and a version. @@ -34,6 +40,9 @@ public: BPackageResolvableExpression(); BPackageResolvableExpression( + const BPackageResolvableExpressionData& data + ); + BPackageResolvableExpression( const BString& name, BPackageResolvableOperator _op = B_PACKAGE_RESOLVABLE_OP_ENUM_COUNT, Modified: haiku/trunk/headers/os/package/PackageVersion.h =================================================================== --- haiku/trunk/headers/os/package/PackageVersion.h 2011-02-09 11:28:56 UTC (rev 40404) +++ haiku/trunk/headers/os/package/PackageVersion.h 2011-02-09 19:11:23 UTC (rev 40405) @@ -12,9 +12,17 @@ namespace BPackageKit { +namespace BHPKG { + class BPackageVersionData; +} +using BHPKG::BPackageVersionData; + + class BPackageVersion { public: BPackageVersion(); + BPackageVersion( + const BPackageVersionData& data); BPackageVersion(const BString& major, const BString& minor, const BString& micro, uint8 release); Modified: haiku/trunk/headers/os/package/RepositoryCache.h =================================================================== --- haiku/trunk/headers/os/package/RepositoryCache.h 2011-02-09 11:28:56 UTC (rev 40404) +++ haiku/trunk/headers/os/package/RepositoryCache.h 2011-02-09 19:11:23 UTC (rev 40405) @@ -9,15 +9,12 @@ #include <Entry.h> #include <String.h> -#include <package/RepositoryHeader.h> +#include <package/RepositoryInfo.h> namespace BPackageKit { -//class RepositoryHeader; - - class BRepositoryCache { public: BRepositoryCache(); @@ -27,7 +24,7 @@ status_t SetTo(const BEntry& entry); status_t InitCheck() const; - const BRepositoryHeader& Header() const; + const BRepositoryInfo& Info() const; const BEntry& Entry() const; bool IsUserSpecific() const; @@ -37,7 +34,7 @@ status_t fInitStatus; BEntry fEntry; - BRepositoryHeader fHeader; + BRepositoryInfo fInfo; bool fIsUserSpecific; }; Copied: haiku/trunk/headers/os/package/RepositoryInfo.h (from rev 40387, haiku/trunk/headers/os/package/RepositoryHeader.h) =================================================================== --- haiku/trunk/headers/os/package/RepositoryInfo.h (rev 0) +++ haiku/trunk/headers/os/package/RepositoryInfo.h 2011-02-09 19:11:23 UTC (rev 40405) @@ -0,0 +1,75 @@ +/* + * Copyright 2011, Haiku, Inc. + * Distributed under the terms of the MIT License. + */ +#ifndef _PACKAGE__REPOSITORY_INFO_H_ +#define _PACKAGE__REPOSITORY_INFO_H_ + + +#include <Archivable.h> +#include <Entry.h> +#include <String.h> + +#include <package/PackageArchitecture.h> + + +namespace BPackageKit { + + +class BRepositoryInfo : public BArchivable { + typedef BArchivable inherited; + +public: + BRepositoryInfo(); + BRepositoryInfo(BMessage* data); + BRepositoryInfo(const BEntry& entry); + virtual ~BRepositoryInfo(); + + virtual status_t Archive(BMessage* data, bool deep = true) const; + + status_t SetTo(const BMessage* data); + status_t SetTo(const BEntry& entry); + status_t InitCheck() const; + + const BString& Name() const; + const BString& OriginalBaseURL() const; + const BString& Vendor() const; + const BString& Summary() const; + uint8 Priority() const; + BPackageArchitecture Architecture() const; + + void SetName(const BString& name); + void SetOriginalBaseURL(const BString& url); + void SetVendor(const BString& vendor); + void SetSummary(const BString& summary); + void SetPriority(uint8 priority); + void SetArchitecture(BPackageArchitecture arch); + +public: + static BRepositoryInfo* Instantiate(BMessage* data); + + static const uint8 kDefaultPriority; + + static const char* kNameField; + static const char* kURLField; + static const char* kVendorField; + static const char* kSummaryField; + static const char* kPriorityField; + static const char* kArchitectureField; + +private: + status_t fInitStatus; + + BString fName; + BString fOriginalBaseURL; + BString fVendor; + BString fSummary; + uint8 fPriority; + BPackageArchitecture fArchitecture; +}; + + +} // namespace BPackageKit + + +#endif // _PACKAGE__REPOSITORY_INFO_H_ Modified: haiku/trunk/headers/os/package/hpkg/PackageContentHandler.h =================================================================== --- haiku/trunk/headers/os/package/hpkg/PackageContentHandler.h 2011-02-09 11:28:56 UTC (rev 40404) +++ haiku/trunk/headers/os/package/hpkg/PackageContentHandler.h 2011-02-09 19:11:23 UTC (rev 40405) @@ -47,6 +47,7 @@ virtual status_t HandlePackageAttribute( const BPackageInfoAttributeValue& value ) = 0; + virtual status_t HandlePackageAttributesDone() = 0; virtual void HandleErrorOccurred() = 0; }; Modified: haiku/trunk/headers/os/package/hpkg/RepositoryWriter.h =================================================================== --- haiku/trunk/headers/os/package/hpkg/RepositoryWriter.h 2011-02-09 11:28:56 UTC (rev 40404) +++ haiku/trunk/headers/os/package/hpkg/RepositoryWriter.h 2011-02-09 19:11:23 UTC (rev 40405) @@ -16,6 +16,7 @@ class BPackageInfo; +class BRepositoryInfo; namespace BHPKG { @@ -38,6 +39,8 @@ virtual void OnPackageAttributesSizeInfo(uint32 stringCount, uint32 uncompressedSize) = 0; virtual void OnRepositorySizeInfo(uint32 headerSize, + uint32 repositoryInfoLength, + uint32 packageCount, uint32 packageAttributesSize, uint64 totalSize) = 0; }; @@ -47,7 +50,8 @@ public: public: BRepositoryWriter( - BRepositoryWriterListener* listener); + BRepositoryWriterListener* listener, + const BRepositoryInfo* repositoryInfo); ~BRepositoryWriter(); status_t Init(const char* fileName); Modified: haiku/trunk/headers/private/package/ActivateRepositoryConfigJob.h =================================================================== --- haiku/trunk/headers/private/package/ActivateRepositoryConfigJob.h 2011-02-09 11:28:56 UTC (rev 40404) +++ haiku/trunk/headers/private/package/ActivateRepositoryConfigJob.h 2011-02-09 19:11:23 UTC (rev 40405) @@ -25,7 +25,7 @@ ActivateRepositoryConfigJob( const BContext& context, const BString& title, - const BEntry& archivedRepoHeaderEntry, + const BEntry& archivedRepoInfoEntry, const BString& repositoryBaseURL, const BDirectory& targetDirectory); virtual ~ActivateRepositoryConfigJob(); @@ -37,7 +37,7 @@ virtual void Cleanup(status_t jobResult); private: - BEntry fArchivedRepoHeaderEntry; + BEntry fArchivedRepoInfoEntry; BString fRepositoryBaseURL; BDirectory fTargetDirectory; BEntry fTargetEntry; Modified: haiku/trunk/headers/private/package/hpkg/RepositoryWriterImpl.h =================================================================== --- haiku/trunk/headers/private/package/hpkg/RepositoryWriterImpl.h 2011-02-09 11:28:56 UTC (rev 40404) +++ haiku/trunk/headers/private/package/hpkg/RepositoryWriterImpl.h 2011-02-09 19:11:23 UTC (rev 40405) @@ -8,17 +8,21 @@ #include <Entry.h> +#include <package/hpkg/PackageContentHandler.h> #include <package/hpkg/RepositoryWriter.h> #include <package/hpkg/WriterImplBase.h> +#include <package/PackageInfo.h> namespace BPackageKit { + namespace BHPKG { -class BDataReader; -class BErrorOutput; +class BPackageEntry; +class BPackageEntryAttribute; +class BPackageInfoAttributeValue; namespace BPrivate { @@ -26,10 +30,12 @@ struct hpkg_header; -class RepositoryWriterImpl : public WriterImplBase { +class RepositoryWriterImpl + : public WriterImplBase, private BPackageContentHandler { public: RepositoryWriterImpl( - BRepositoryWriterListener* listener); + BRepositoryWriterListener* listener, + const BRepositoryInfo* repositoryInfo); ~RepositoryWriterImpl(); status_t Init(const char* fileName); @@ -37,15 +43,41 @@ status_t Finish(); private: + // BPackageContentHandler + virtual status_t HandleEntry(BPackageEntry* entry); + virtual status_t HandleEntryAttribute(BPackageEntry* entry, + BPackageEntryAttribute* attribute); + virtual status_t HandleEntryDone(BPackageEntry* entry); + + virtual status_t HandlePackageAttribute( + const BPackageInfoAttributeValue& value + ); + virtual status_t HandlePackageAttributesDone(); + + virtual void HandleErrorOccurred(); + +private: status_t _Init(const char* fileName); status_t _AddPackage(const BEntry& packageEntry); status_t _Finish(); + status_t _RegisterCurrentPackageInfo(); + status_t _WriteRepositoryInfo( + ssize_t& _repositoryInfoLength); off_t _WritePackageAttributes( - hpkg_repo_header& header); + hpkg_repo_header& header, + off_t startOffset); + struct PackageNameSet; + private: BRepositoryWriterListener* fListener; + + const BRepositoryInfo* fRepositoryInfo; + + BPackageInfo fPackageInfo; + uint32 fPackageCount; + PackageNameSet* fPackageNames; }; Modified: haiku/trunk/headers/private/package/hpkg/haiku_package.h =================================================================== --- haiku/trunk/headers/private/package/hpkg/haiku_package.h 2011-02-09 11:28:56 UTC (rev 40404) +++ haiku/trunk/headers/private/package/hpkg/haiku_package.h 2011-02-09 19:11:23 UTC (rev 40405) @@ -51,6 +51,9 @@ uint16 version; uint64 total_size; + // repository header + uint32 repository_header_length; + // package attributes section uint32 attributes_compression; uint32 attributes_length_compressed; Modified: haiku/trunk/src/add-ons/kernel/file_systems/packagefs/Volume.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/packagefs/Volume.cpp 2011-02-09 11:28:56 UTC (rev 40404) +++ haiku/trunk/src/add-ons/kernel/file_systems/packagefs/Volume.cpp 2011-02-09 19:11:23 UTC (rev 40405) @@ -264,6 +264,12 @@ return B_OK; } + virtual status_t HandlePackageAttributesDone() + { + // TODO! + return B_OK; + } + virtual void HandleErrorOccurred() { fErrorOccurred = true; Modified: haiku/trunk/src/bin/Jamfile =================================================================== --- haiku/trunk/src/bin/Jamfile 2011-02-09 11:28:56 UTC (rev 40404) +++ haiku/trunk/src/bin/Jamfile 2011-02-09 19:11:23 UTC (rev 40405) @@ -255,6 +255,7 @@ SubInclude HAIKU_TOP src bin mkfs ; SubInclude HAIKU_TOP src bin multiuser ; SubInclude HAIKU_TOP src bin package ; +SubInclude HAIKU_TOP src bin package_repo ; SubInclude HAIKU_TOP src bin patch ; SubInclude HAIKU_TOP src bin pc ; SubInclude HAIKU_TOP src bin pcmcia-cs ; Modified: haiku/trunk/src/bin/package/command_create.cpp =================================================================== --- haiku/trunk/src/bin/package/command_create.cpp 2011-02-09 11:28:56 UTC (rev 40404) +++ haiku/trunk/src/bin/package/command_create.cpp 2011-02-09 19:11:23 UTC (rev 40405) @@ -88,7 +88,7 @@ printf("TOC size: %10llu\n", tocSize); printf("package attributes size: %10lu\n", packageAttributesSize); printf("total size: %10llu\n", totalSize); - + printf("-----------------------------------\n"); } private: Modified: haiku/trunk/src/bin/package/command_extract.cpp =================================================================== --- haiku/trunk/src/bin/package/command_extract.cpp 2011-02-09 11:28:56 UTC (rev 40404) +++ haiku/trunk/src/bin/package/command_extract.cpp 2011-02-09 19:11:23 UTC (rev 40405) @@ -229,6 +229,11 @@ return B_OK; } + virtual status_t HandlePackageAttributesDone() + { + return B_OK; + } + virtual void HandleErrorOccurred() { fErrorOccurred = true; Modified: haiku/trunk/src/bin/package/command_list.cpp =================================================================== --- haiku/trunk/src/bin/package/command_list.cpp 2011-02-09 11:28:56 UTC (rev 40404) +++ haiku/trunk/src/bin/package/command_list.cpp 2011-02-09 19:11:23 UTC (rev 40405) @@ -144,7 +144,7 @@ break; case B_PACKAGE_INFO_ARCHITECTURE: - printf("\tarchitecure: %s\n", + printf("\tarchitecture: %s\n", BPackageInfo::kArchitectureNames[value.unsignedInt]); break; @@ -226,6 +226,11 @@ return B_OK; } + virtual status_t HandlePackageAttributesDone() + { + return B_OK; + } + virtual void HandleErrorOccurred() { } Modified: haiku/trunk/src/bin/package/package.cpp =================================================================== --- haiku/trunk/src/bin/package/package.cpp 2011-02-09 11:28:56 UTC (rev 40404) +++ haiku/trunk/src/bin/package/package.cpp 2011-02-09 19:11:23 UTC (rev 40405) @@ -13,9 +13,7 @@ #include <stdlib.h> #include <string.h> -#include <package/hpkg/PackageWriter.h> - extern const char* __progname; const char* kCommandName = __progname; @@ -28,7 +26,9 @@ " create [ <options> ] <package>\n" " Creates package file <package> from contents of current directory.\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" + " -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" @@ -36,7 +36,7 @@ " extract [ <options> ] <package>\n" " Extracts the contents of package file <package>.\n" "\n" - " -C <dir> - Change to directory <dir> before extracting the " + " -C <dir> - Change to directory <dir> before extracting the " "contents\n" " of the archive.\n" "\n" Added: haiku/trunk/src/bin/package_repo/Jamfile =================================================================== --- haiku/trunk/src/bin/package_repo/Jamfile (rev 0) +++ haiku/trunk/src/bin/package_repo/Jamfile 2011-02-09 19:11:23 UTC (rev 40405) @@ -0,0 +1,20 @@ +SubDir HAIKU_TOP src bin package_repo ; + +UsePrivateHeaders kernel shared ; + +DEFINES += B_ENABLE_INCOMPLETE_POSIX_AT_SUPPORT ; + # TODO: Remove when it is complete! + +SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src bin package ] ; + +BinCommand package_repo : + BlockBufferCacheNoLock.cpp + command_create.cpp + command_list.cpp + package_repo.cpp + StandardErrorOutput.cpp + : + package be + $(TARGET_LIBSUPC++) +; + Added: haiku/trunk/src/bin/package_repo/command_create.cpp =================================================================== --- haiku/trunk/src/bin/package_repo/command_create.cpp (rev 0) +++ haiku/trunk/src/bin/package_repo/command_create.cpp 2011-02-09 19:11:23 UTC (rev 40405) @@ -0,0 +1,218 @@ +/* + * Copyright 2011, Oliver Tappe <zooey@xxxxxxxxxxxxxxx> + * Distributed under the terms of the MIT License. + */ + + +#include <dirent.h> +#include <errno.h> +#include <getopt.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <Entry.h> +#include <Path.h> + +#include <package/hpkg/HPKGDefs.h> +#include <package/hpkg/RepositoryWriter.h> +#include <package/PackageInfo.h> +#include <package/RepositoryInfo.h> + +#include "package.h" +#include "StandardErrorOutput.h" + + +using BPackageKit::BHPKG::BRepositoryWriterListener; +using BPackageKit::BHPKG::BRepositoryWriter; +using namespace BPackageKit; + + +class RepositoryWriterListener : public BRepositoryWriterListener { +public: + RepositoryWriterListener(bool verbose, bool quiet) + : fVerbose(verbose), fQuiet(quiet) + { + } + + virtual void PrintErrorVarArgs(const char* format, va_list args) + { + vfprintf(stderr, format, args); + } + + virtual void OnPackageAdded(const BPackageInfo& packageInfo) + { + if (fQuiet) + return; + + printf("%s (%s)\n", packageInfo.Name().String(), + packageInfo.Version().ToString().String()); + if (fVerbose) { + printf("\tsummary: %s\n", packageInfo.Summary().String()); + printf("\tvendor: %s\n", packageInfo.Vendor().String()); + printf("\tpackager: %s\n", packageInfo.Packager().String()); + if (uint32 flags = packageInfo.Flags()) { + printf("\tflags:\n"); + if ((flags & B_PACKAGE_FLAG_APPROVE_LICENSE) != 0) + printf("\t\tapprove_license\n"); + if ((flags & B_PACKAGE_FLAG_SYSTEM_PACKAGE) != 0) + printf("\t\tsystem_package\n"); + } + } + } + + virtual void OnPackageAttributesSizeInfo(uint32 stringCount, + uint32 uncompressedSize) + { + if (fQuiet || !fVerbose) + return; + + printf("----- Package Attribute Info ---------------------\n"); + printf("string count: %10lu\n", stringCount); + printf("package attributes size: %10lu (uncompressed)\n", + uncompressedSize); + } + + virtual void OnRepositorySizeInfo(uint32 headerSize, + uint32 repositoryInfoSize, uint32 packageCount, + uint32 packageAttributesSize, uint64 totalSize) + { + if (fQuiet) + return; + + printf("----- Package Repository Info -----\n"); + printf("package count %10lu\n", packageCount); + printf("-----------------------------------\n"); + printf("header size: %10lu\n", headerSize); + printf("repository header size: %10lu\n", repositoryInfoSize); + printf("package attributes size: %10lu\n", packageAttributesSize); + printf("total size: %10llu\n", totalSize); + printf("-----------------------------------\n"); + } + +private: + bool fVerbose; + bool fQuiet; +}; + + +int +command_create(int argc, const char* const* argv) +{ + const char* changeToDirectory = NULL; + bool quiet = false; + bool verbose = false; + + while (true) { + static struct option sLongOptions[] = { + { "help", no_argument, 0, 'h' }, + { "quiet", no_argument, 0, 'q' }, + { "verbose", no_argument, 0, 'v' }, + { 0, 0, 0, 0 } + }; + + opterr = 0; // don't print errors + int c = getopt_long(argc, (char**)argv, "+C:hqv", sLongOptions, NULL); + if (c == -1) + break; + + switch (c) { + case 'C': + changeToDirectory = optarg; + break; + + case 'h': + print_usage_and_exit(false); + break; + + case 'q': + quiet = true; + break; + + case 'v': + verbose = true; + break; + + default: + print_usage_and_exit(true); + break; + } + } + + // The remaining arguments are the repository info file plus one or more + // package files, i.e. at least two more arguments. + if (optind + 2 >= argc) + print_usage_and_exit(true); + + const char* repositoryInfoFileName = argv[optind++]; + const char* const* packageFileNames = argv + optind; + + RepositoryWriterListener listener(verbose, quiet); + + BEntry repositoryInfoEntry(repositoryInfoFileName); + if (!repositoryInfoEntry.Exists()) { + listener.PrintError( + "Error: given repository-info file '%s' doesn't exist!\n", + repositoryInfoFileName); + return 1; + } + + // determine path for 'repo' file from given info file + BEntry repositoryParentEntry; + repositoryInfoEntry.GetParent(&repositoryParentEntry); + BPath repositoryPath; + if (repositoryParentEntry.GetPath(&repositoryPath) != B_OK) { + listener.PrintError( + "Error: can't determine path of given repository-info file!\n"); + return 1; + } + repositoryPath.Append("repo"); + + // create repository + BRepositoryInfo repositoryInfo(repositoryInfoEntry); + status_t result = repositoryInfo.InitCheck(); + if (result != B_OK) { + listener.PrintError( + "Error: can't parse given repository-info file : %s\n", + strerror(result)); + return 1; + } + BRepositoryWriter repositoryWriter(&listener, &repositoryInfo); + if ((result = repositoryWriter.Init(repositoryPath.Path())) != B_OK) { + listener.PrintError("Error: can't initialize repository-writer : %s\n", + strerror(result)); + return 1; + } + + // change directory, if requested + if (changeToDirectory != NULL) { + if (chdir(changeToDirectory) != 0) { + listener.PrintError( + "Error: Failed to change the current working directory to " + "\"%s\": %s\n", changeToDirectory, strerror(errno)); + return 1; + } + } + + // add all given package files + for (int i = 0; i < argc - optind; ++i) { + if (verbose) + printf("reading package '%s' ...\n", packageFileNames[i]); + BEntry entry(packageFileNames[i]); + result = repositoryWriter.AddPackage(entry); + if (result != B_OK) + return 1; + } + + // write the repository + result = repositoryWriter.Finish(); + if (result != B_OK) + return 1; + + if (verbose) { + printf("\nsuccessfully created repository '%s'\n", + repositoryPath.Path()); + } + + return 0; +} Added: haiku/trunk/src/bin/package_repo/command_list.cpp =================================================================== --- haiku/trunk/src/bin/package_repo/command_list.cpp (rev 0) +++ haiku/trunk/src/bin/package_repo/command_list.cpp 2011-02-09 19:11:23 UTC (rev 40405) @@ -0,0 +1,323 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Distributed under the terms of the MIT License. + */ + + +#include <ctype.h> +#include <errno.h> +#include <getopt.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <package/hpkg/PackageContentHandler.h> +#include <package/hpkg/PackageEntry.h> +#include <package/hpkg/PackageEntryAttribute.h> +#include <package/hpkg/PackageInfoAttributeValue.h> +#include <package/hpkg/PackageReader.h> + +#include <package/PackageInfo.h> + +#include "package.h" +#include "StandardErrorOutput.h" + + +using namespace BPackageKit::BHPKG; +using namespace BPackageKit; + + +struct PackageContentListHandler : BPackageContentHandler { + PackageContentListHandler(bool listAttributes) + : + fLevel(0), + fListAttribute(listAttributes) + { + } + + virtual status_t HandleEntry(BPackageEntry* entry) + { + fLevel++; + + int indentation = (fLevel - 1) * 2; + printf("%*s", indentation, ""); + + // name and size + printf("%-*s", indentation < 32 ? 32 - indentation : 0, entry->Name()); + printf(" %8llu", entry->Data().UncompressedSize()); + + // time + struct tm* time = localtime(&entry->ModifiedTime().tv_sec); + printf(" %04d-%02d-%02d %02d:%02d:%02d", + 1900 + time->tm_year, time->tm_mon + 1, time->tm_mday, + time->tm_hour, time->tm_min, time->tm_sec); + + // file type + mode_t mode = entry->Mode(); + if (S_ISREG(mode)) + printf(" -"); + else if (S_ISDIR(mode)) + printf(" d"); + else if (S_ISLNK(mode)) + printf(" l"); + else + printf(" ?"); + + // permissions + char buffer[4]; + printf("%s", _PermissionString(buffer, mode >> 6, + (mode & S_ISUID) != 0)); + printf("%s", _PermissionString(buffer, mode >> 3, + (mode & S_ISGID) != 0)); + printf("%s", _PermissionString(buffer, mode, false)); + + // print the symlink path + if (S_ISLNK(mode)) + printf(" -> %s", entry->SymlinkPath()); + + printf("\n"); + return B_OK; + } + + virtual status_t HandleEntryAttribute(BPackageEntry* entry, + BPackageEntryAttribute* attribute) + { + if (!fListAttribute) + return B_OK; + + int indentation = fLevel * 2; + printf("%*s<", indentation, ""); + printf("%-*s %8llu", indentation < 31 ? 31 - indentation : 0, + attribute->Name(), attribute->Data().UncompressedSize()); + + uint32 type = attribute->Type(); + if (isprint(type & 0xff) && isprint((type >> 8) & 0xff) + && isprint((type >> 16) & 0xff) && isprint(type >> 24)) { + printf(" '%c%c%c%c'", int(type >> 24), int((type >> 16) & 0xff), + int((type >> 8) & 0xff), int(type & 0xff)); + } else + printf(" %#lx", type); + + printf(">\n"); + return B_OK; + } + + virtual status_t HandleEntryDone(BPackageEntry* entry) + { + fLevel--; + return B_OK; + } + + virtual status_t HandlePackageAttribute( + const BPackageInfoAttributeValue& value) + { + switch (value.attributeIndex) { + case B_PACKAGE_INFO_NAME: + printf("package-attributes:\n"); + printf("\tname: %s\n", value.string); + break; + + case B_PACKAGE_INFO_SUMMARY: + printf("\tsummary: %s\n", value.string); + break; + + case B_PACKAGE_INFO_DESCRIPTION: + printf("\tdescription: %s\n", value.string); + break; + + case B_PACKAGE_INFO_VENDOR: + printf("\tvendor: %s\n", value.string); + break; + + case B_PACKAGE_INFO_PACKAGER: + printf("\tpackager: %s\n", value.string); + break; + + case B_PACKAGE_INFO_FLAGS: + if (value.unsignedInt == 0) + break; + printf("\tflags:\n"); + if ((value.unsignedInt & B_PACKAGE_FLAG_APPROVE_LICENSE) != 0) + printf("\t\tapprove_license\n"); + if ((value.unsignedInt & B_PACKAGE_FLAG_SYSTEM_PACKAGE) != 0) + printf("\t\tsystem_package\n"); + break; + + case B_PACKAGE_INFO_ARCHITECTURE: + printf("\tarchitecture: %s\n", + BPackageInfo::kArchitectureNames[value.unsignedInt]); + break; + + case B_PACKAGE_INFO_VERSION: + printf("\tversion: %s.%s.%s-%d\n", value.version.major, + value.version.minor, value.version.micro, + value.version.release); + break; + + case B_PACKAGE_INFO_COPYRIGHTS: + printf("\tcopyright: %s\n", value.string); + break; + + case B_PACKAGE_INFO_LICENSES: + printf("\tlicense: %s\n", value.string); + break; + + case B_PACKAGE_INFO_PROVIDES: + printf("\tprovides: %s", value.resolvable.name); + if (value.resolvable.haveVersion) { + printf(" = "); + _PrintPackageVersion(value.resolvable.version); + } + printf("\n"); + break; + + case B_PACKAGE_INFO_REQUIRES: + printf("\trequires: %s", value.resolvableExpression.name); + if (value.resolvableExpression.haveOpAndVersion) { + printf(" %s ", BPackageResolvableExpression::kOperatorNames[ + value.resolvableExpression.op]); + _PrintPackageVersion(value.resolvableExpression.version); + } + printf("\n"); + break; + + case B_PACKAGE_INFO_SUPPLEMENTS: + printf("\tsupplements: %s", value.resolvableExpression.name); + if (value.resolvableExpression.haveOpAndVersion) { + printf(" %s ", BPackageResolvableExpression::kOperatorNames[ + value.resolvableExpression.op]); + _PrintPackageVersion(value.resolvableExpression.version); + } + printf("\n"); + break; + + case B_PACKAGE_INFO_CONFLICTS: + printf("\tconflicts: %s", value.resolvableExpression.name); + if (value.resolvableExpression.haveOpAndVersion) { + printf(" %s ", BPackageResolvableExpression::kOperatorNames[ + value.resolvableExpression.op]); + _PrintPackageVersion(value.resolvableExpression.version); + } [... truncated: 1275 lines follow ...]