27 #include <boost/iostreams/filtering_streambuf.hpp>
28 #include <boost/iostreams/filter/gzip.hpp>
29 #include <boost/locale.hpp>
42 using namespace boost::locale;
61 writerHandler(xcksWriterHandler),
62 ckProvider(checksumProvider),
63 writerOptions(options),
66 ckfConfProvider(ckftConfProvider)
87 if (checkBaseDirAndPathList(basePath, relativePaths))
88 return doWrite(os, basePath, relativePaths);
101 if (!fileFullPath.is_absolute())
108 if (checkBaseDirAndPathList(fileFullPath.parent_path(), relativePaths))
110 ofstream os(fileFullPath, ios_base::out | ios_base::binary);
118 return doWrite(os, fileFullPath.parent_path(), relativePaths);
130 const std::filesystem::path& basePath,
133 if (checkBaseDirAndPathList(basePath, relativePaths))
135 ofstream os(filePath, ios_base::out | ios_base::binary);
143 return doWrite(os, basePath, relativePaths);
157 bool XCKSWriter::checkBaseDirAndPathList(
const filesystem::path& basePath,
160 if (!basePath.is_absolute())
167 bool allRelative =
true;
168 ArrayPath::const_iterator it = relativePaths.cbegin();
169 while (allRelative && it != relativePaths.cend())
171 if (it->is_relative())
199 return writer.
write(os, relativePaths);
219 XCKSWriter(xcksWriterHandler, checksumProvider,
220 options, version, algoIds, ckftConfProvider)
241 boost::iostreams::filtering_streambuf<boost::iostreams::output> outbuf;
244 ostream outstream(&outbuf);
249 boost::iostreams::close(outbuf);
ArrayChecksumAlgoId getChecksumTypesForNewEntries() const
Returns the list of checksums algorithms to compute for new entries of this type of checksums' file.
bool write(std::ostream &os, const ArrayPath &relativePaths)
Writes the checksums in a stream.
Provides checksums values from an array of wanted algorithms of checksums for the XCKS writer.
Handler for writing XCKS files.
virtual void onFatalError(const std::string &errorMessage)=0
Called on a non-recoverable error.
Provides options for the XCKS writer.
virtual bool doWrite(std::ostream &os, const std::filesystem::path &basePath, const ArrayPath &relativePaths)
Writes an XCKS file to an output stream.
const ArrayChecksumAlgoId sumsAlgos
Type of algorithms' checksums to write for each file.
const Version version
Version of the (Z)XCKS file to write.
virtual ~XCKSWriter()
Destructor.
bool write(std::ostream &os, const std::filesystem::path &basePath, const ArrayPath &relativePaths)
Writes an XCKS file to an output stream.
XCKSWriterChecksumProvider & ckProvider
The provider of checksums values.
XCKSWriterHandler & writerHandler
The XCKS file writer handler.
const ChecksumFormatter::ConfigurationProvider & ckfConfProvider
Configuration provider for ChecksumFormatter.
const XCKSWriterOptions & writerOptions
The writer options.
Provides options for the XCKS writer.
virtual ~ZXCKSWriter()
Destructor.
ZXCKSWriter()=delete
Deleted default constructor.
bool doWrite(std::ostream &os, const std::filesystem::path &basePath, const ArrayPath &relativePaths) override
Writes a ZXCKS file to an output stream.
constexpr const char * libxcks_domain
Domain for translations (i18n).
std::filesystem::path ensureEndsWithPathSeparator(const std::filesystem::path &p)
Ensures the path ends with a path separator.
std::string from_u8string(const std::string &s)
Returns an UTF-8 encoded string in an object of type std::string (C++17).
std::vector< ChecksumAlgoId > ArrayChecksumAlgoId
Array of ids of algorithms of checksums.
std::vector< std::filesystem::path > ArrayPath
Array of paths.
Version
Known versions of XCKS file.
Classes that write a XCKS file.