Skip to content

Commit 91c743e

Browse files
author
Dexter Le
committed
Refactor to use std::filesystem
1 parent 7b19172 commit 91c743e

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

flow/FileTraceLogWriter.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,17 @@ void FileTraceLogWriter::cleanupTraceFiles() {
234234
// Rename/finalize any stray files ending in tracePartialFileSuffix for this process.
235235
if (!tracePartialFileSuffix.empty()) {
236236
for (const auto& f : platform::listFiles(directory, tracePartialFileSuffix)) {
237-
if (f.substr(0, processName.length()) == processName) {
238-
renameFile(f, f.substr(0, f.size() - tracePartialFileSuffix.size()));
237+
if (f.parent_path() == processName) {
238+
renameFile(f, f.stem());
239239
}
240240
}
241241
}
242242

243-
std::vector<std::string> existingFiles = platform::listFiles(directory, extension);
244-
std::vector<std::string> existingTraceFiles;
243+
std::vector<std::filesystem::path> existingFiles = platform::listFiles(directory, extension);
244+
std::vector<std::filesystem::path> existingTraceFiles;
245245

246246
for (auto f = existingFiles.begin(); f != existingFiles.end(); ++f) {
247-
if (f->substr(0, processName.length()) == processName) {
247+
if (f->parent_path() == processName) {
248248
existingTraceFiles.push_back(*f);
249249
}
250250
}
@@ -253,15 +253,15 @@ void FileTraceLogWriter::cleanupTraceFiles() {
253253
std::sort(existingTraceFiles.begin(), existingTraceFiles.end(), std::greater<std::string>());
254254

255255
uint64_t runningTotal = 0;
256-
std::vector<std::string>::iterator fileListIterator = existingTraceFiles.begin();
256+
std::vector<std::filesystem::path>::iterator fileListIterator = existingTraceFiles.begin();
257257

258258
while (runningTotal < maxLogsSize && fileListIterator != existingTraceFiles.end()) {
259-
runningTotal += (fileSize(joinPath(directory, *fileListIterator)) + FLOW_KNOBS->ZERO_LENGTH_FILE_PAD);
259+
runningTotal += (fileSize(directory / *fileListIterator) + FLOW_KNOBS->ZERO_LENGTH_FILE_PAD);
260260
++fileListIterator;
261261
}
262262

263263
while (fileListIterator != existingTraceFiles.end()) {
264-
deleteFile(joinPath(directory, *fileListIterator));
264+
deleteFile(directory / *fileListIterator);
265265
++fileListIterator;
266266
}
267267
} catch (Error&) {

0 commit comments

Comments
 (0)