| 96 | } |
| 97 | |
| 98 | bool WriteToFile(const std::string& filePath, const char* data, std::streamsize size, |
| 99 | std::ios::openmode mode) { |
| 100 | auto path = Utf8ToPath(filePath); |
| 101 | auto parentPath = path.parent_path(); |
| 102 | if (!parentPath.empty() && !fs::exists(parentPath)) { |
| 103 | fs::create_directories(parentPath); |
| 104 | } |
| 105 | std::ofstream file(path, mode); |
| 106 | if (!file) { |
| 107 | LOGE("Failed to open file: %s", filePath.c_str()); |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | file.write(data, size); |
| 112 | |
| 113 | if (file.fail()) { |
| 114 | LOGE("Failed to write to file: %s", filePath.c_str()); |
| 115 | if (file.eof()) { |
| 116 | LOGE("eof is set: End-of-File reached on input operation."); |
| 117 | } |
| 118 | file.close(); |
| 119 | return false; |
| 120 | } |
| 121 | |
| 122 | file.close(); |
| 123 | return true; |
| 124 | } |
| 125 | |
| 126 | bool DeleteFile(const std::string& path) { |
| 127 | return fs::remove_all(path); |
no test coverage detected