| 160 | } |
| 161 | |
| 162 | bool FileSystem::writeContent(PathId fileId, std::string_view content, |
| 163 | bool onlyIfModified) { |
| 164 | if (!fileId) return false; |
| 165 | |
| 166 | if (onlyIfModified && exists(fileId)) { |
| 167 | std::string currentContent; |
| 168 | if (readContent(fileId, currentContent) && (currentContent == content)) { |
| 169 | return true; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | bool result = false; |
| 174 | std::ostream &strm = openForWrite(fileId); |
| 175 | if (strm.good()) { |
| 176 | strm << content; |
| 177 | strm.flush(); |
| 178 | result = strm.good(); |
| 179 | } |
| 180 | close(strm); |
| 181 | return result; |
| 182 | } |
| 183 | |
| 184 | bool FileSystem::writeContent(PathId fileId, std::string_view content) { |
| 185 | return writeContent(fileId, content, true); |