1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2010 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #ifndef cmArchiveWrite_h
13 #define cmArchiveWrite_h
15 #include "cmStandardIncludes.h"
17 #if !defined(CMAKE_BUILD_WITH_CMAKE)
18 # error "cmArchiveWrite not allowed during bootstrap build!"
21 /** \class cmArchiveWrite
22 * \brief Wrapper around libarchive for writing.
27 typedef void (cmArchiveWrite::* safe_bool)();
28 void safe_bool_true() {}
30 /** Compression type. */
48 /** Construct with output stream to which to write archive. */
49 cmArchiveWrite(std::ostream& os, Compress c = CompressNone, Type = TypeTAR);
53 * Add a path (file or directory) to the archive. Directories are
54 * added recursively. The "path" must be readable on disk, either
55 * full path or relative to current working directory. The "skip"
56 * value indicates how many leading bytes from the input path to
57 * skip. The remaining part of the input path is appended to the
58 * "prefix" value to construct the final name in the archive.
60 bool Add(std::string path, size_t skip = 0, const char* prefix = 0);
62 /** Returns true if there has been no error. */
63 operator safe_bool() const
64 { return this->Okay()? &cmArchiveWrite::safe_bool_true : 0; }
66 /** Returns true if there has been an error. */
67 bool operator!() const { return !this->Okay(); }
69 /** Return the error string; empty if none. */
70 std::string GetError() const { return this->Error; }
72 // TODO: More general callback instead of hard-coding calls to
74 void SetVerbose(bool v) { this->Verbose = v; }
77 bool Okay() const { return this->Error.empty(); }
78 bool AddPath(const char* path, size_t skip, const char* prefix);
79 bool AddFile(const char* file, size_t skip, const char* prefix);
80 bool AddData(const char* file, size_t size);
83 friend struct Callback;
88 struct archive* Archive;