MCPcopy Create free account
hub / github.com/chipsalliance/Surelog / writeLines

Method writeLines

src/Common/FileSystem.cpp:208–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

206}
207
208bool 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
241bool FileSystem::writeLines(PathId fileId,
242 const std::vector<std::string> &lines) {

Callers 2

TESTFunction · 0.80

Calls 1

flushMethod · 0.80

Tested by 1

TESTFunction · 0.64