// TJP COPYRIGHT HEADER #include "writeSegmentsToFile.h" #include #include #include #include #include #include #include #include "../random/Random.h" #include namespace tjp { namespace core { namespace file { bool writeSegmentsToFile(const StringView &path_, const StackArray> &segments, const WriteOptions &options) { auto path = String(path_); auto extension = "." + core::to_string(core::StandardRandom.next()); auto temporary = path + extension; std::ofstream file(temporary, std::ios::binary); if (!file) return false; for (auto &contents: segments) file.write((char *)contents.data(), contents.size()); file.close(); remove(path.c_str()); if (rename(temporary.c_str(), path.c_str())) return false; if (options.lastModifiedTime) { setFileLastModifiedTime(path, options.lastModifiedTime); } return true; } } // namespace } // namespace } // namespace