summaryrefslogtreecommitdiffstats
path: root/Source/cmArchiveWrite.h
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2010-08-06 15:38:05 (GMT)
committerBrad King <brad.king@kitware.com>2010-08-06 15:38:05 (GMT)
commitc7c90095d4759034359a747abb1cc32b97dc8363 (patch)
tree19eccd55c878f6a3d9e9bc733010aa444d30cc49 /Source/cmArchiveWrite.h
parentac267371e63806718a0905e321baa552f18a57e9 (diff)
downloadCMake-c7c90095d4759034359a747abb1cc32b97dc8363.zip
CMake-c7c90095d4759034359a747abb1cc32b97dc8363.tar.gz
CMake-c7c90095d4759034359a747abb1cc32b97dc8363.tar.bz2
Create class cmArchiveWrite to wrap libarchive (#11020)
Diffstat (limited to 'Source/cmArchiveWrite.h')
-rw-r--r--Source/cmArchiveWrite.h84
1 files changed, 84 insertions, 0 deletions
diff --git a/Source/cmArchiveWrite.h b/Source/cmArchiveWrite.h
new file mode 100644
index 0000000..92c0c73
--- /dev/null
+++ b/Source/cmArchiveWrite.h
@@ -0,0 +1,84 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2010 Kitware, Inc., Insight Software Consortium
+
+ Distributed under the OSI-approved BSD License (the "License");
+ see accompanying file Copyright.txt for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License for more information.
+============================================================================*/
+#ifndef cmArchiveWrite_h
+#define cmArchiveWrite_h
+
+#include "cmStandardIncludes.h"
+
+#if !defined(CMAKE_BUILD_WITH_CMAKE)
+# error "cmArchiveWrite not allowed during bootstrap build!"
+#endif
+
+/** \class cmArchiveWrite
+ * \brief Wrapper around libarchive for writing.
+ *
+ */
+class cmArchiveWrite
+{
+ typedef void (cmArchiveWrite::* safe_bool)();
+ void safe_bool_true() {}
+public:
+ /** Compression type. */
+ enum Compress
+ {
+ CompressNone,
+ CompressGZip,
+ CompressBZip2
+ };
+
+ /** Construct with output stream to which to write archive. */
+ cmArchiveWrite(std::ostream& os, Compress c = CompressNone);
+ ~cmArchiveWrite();
+
+ /**
+ * Add a path (file or directory) to the archive. Directories are
+ * added recursively. The "path" must be readable on disk, either
+ * full path or relative to current working directory. The "skip"
+ * value indicates how many leading bytes from the input path to
+ * skip. The remaining part of the input path is appended to the
+ * "prefix" value to construct the final name in the archive.
+ */
+ bool Add(std::string path, size_t skip = 0, const char* prefix = 0);
+
+ /** Returns true if there has been no error. */
+ operator safe_bool() const
+ { return this->Okay()? &cmArchiveWrite::safe_bool_true : 0; }
+
+ /** Returns true if there has been an error. */
+ bool operator!() const { return !this->Okay(); }
+
+ /** Return the error string; empty if none. */
+ std::string GetError() const { return this->Error; }
+
+ // TODO: More general callback instead of hard-coding calls to
+ // std::cout.
+ void SetVerbose(bool v) { this->Verbose = v; }
+
+private:
+ bool Okay() const { return this->Error.empty(); }
+ bool AddPath(const char* path, size_t skip, const char* prefix);
+ bool AddFile(const char* file, size_t skip, const char* prefix);
+ bool AddData(const char* file, size_t size);
+
+ struct Callback;
+ friend struct Callback;
+
+ class Entry;
+
+ std::ostream& Stream;
+ struct archive* Archive;
+ struct archive* Disk;
+ bool Verbose;
+ std::string Error;
+};
+
+#endif