| 206 | } |
| 207 | |
| 208 | bool FileSystem::writeLines(PathId fileId, |
| 209 | const std::vector<std::string> &lines, |
| 210 | bool onlyIfModified /* = true */) { |
| 211 | if (!fileId) return false; |
| 212 | |
| 213 | if (onlyIfModified && exists(fileId)) { |
| 214 | std::vector<std::string> currentLines; |
| 215 | if ((readLines(fileId, currentLines)) && |
| 216 | (lines.size() == currentLines.size())) { |
| 217 | bool diffs = false; |
| 218 | for (size_t i = 0, n = lines.size(); i < n; ++i) { |
| 219 | if (lines[i] != currentLines[i]) { |
| 220 | diffs = true; |
| 221 | break; |
| 222 | } |
| 223 | } |
| 224 | if (!diffs) return true; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | bool result = false; |
| 229 | std::ostream &strm = openForWrite(fileId); |
| 230 | if (strm.good()) { |
| 231 | for (const std::string &line : lines) { |
| 232 | strm << line << std::endl; |
| 233 | } |
| 234 | strm.flush(); |
| 235 | result = strm.good(); |
| 236 | } |
| 237 | close(strm); |
| 238 | return result; |
| 239 | } |
| 240 | |
| 241 | bool FileSystem::writeLines(PathId fileId, |
| 242 | const std::vector<std::string> &lines) { |