From 4028c5af901b08e608807078f648904b9aa15500 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 18 Jul 2023 08:09:22 +0000 Subject: Use std::filesystem::rename --- .../searchcorespi/index/indexwriteutilities.cpp | 27 ++++++++-------------- 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/searchcore/src/vespa/searchcorespi/index/indexwriteutilities.cpp b/searchcore/src/vespa/searchcorespi/index/indexwriteutilities.cpp index 8e1940cdc08..a5f796cf48e 100644 --- a/searchcore/src/vespa/searchcorespi/index/indexwriteutilities.cpp +++ b/searchcore/src/vespa/searchcorespi/index/indexwriteutilities.cpp @@ -25,6 +25,7 @@ using search::index::SchemaUtil; using search::SerialNum; using vespalib::IllegalStateException; using vespalib::FileHeader; +using std::filesystem::path; namespace searchcorespi::index { @@ -64,8 +65,9 @@ IndexWriteUtilities::writeSerialNum(SerialNum serialNum, vespalib::File::sync(dir); if (ok) { - FastOS_File renameFile(tmpFileName.c_str()); - ok &= renameFile.Rename(fileName.c_str()); + std::error_code ec; + std::filesystem::rename(path(tmpFileName), path(fileName), ec); + ok = !ec; } if (!ok) { std::ostringstream msg; @@ -84,26 +86,15 @@ IndexWriteUtilities::copySerialNumFile(const vespalib::string &sourceDir, vespalib::string tmpDest = dest + ".tmp"; std::error_code ec; - std::filesystem::copy_file(std::filesystem::path(source), std::filesystem::path(tmpDest), ec); + std::filesystem::copy_file(path(source), path(tmpDest), ec); if (ec) { LOG(error, "Unable to copy file '%s'", source.c_str()); return false; } - FastOS_File file(tmpDest.c_str()); - if (!file.OpenReadWrite()) { - LOG(error, "Unable to open '%s' for fsync", tmpDest.c_str()); - return false; - } - if (!file.Sync()) { - LOG(error, "Unable to fsync '%s'", tmpDest.c_str()); - return false; - } - if (!file.Close()) { - LOG(error, "Unable to close '%s'", tmpDest.c_str()); - return false; - } + vespalib::File::sync(tmpDest); vespalib::File::sync(destDir); - if (!file.Rename(dest.c_str())) { + std::filesystem::rename(path(tmpDest), path(dest), ec); + if (ec) { LOG(error, "Unable to rename file '%s' to '%s'", tmpDest.c_str(), dest.c_str()); return false; } @@ -159,7 +150,7 @@ IndexWriteUtilities::updateDiskIndexSchema(const vespalib::string &indexDir, } vespalib::string schemaTmpName = schemaName + ".tmp"; vespalib::string schemaOrigName = schemaName + ".orig"; - std::filesystem::remove(std::filesystem::path(schemaTmpName)); + std::filesystem::remove(path(schemaTmpName)); if (!newSchema->saveToFile(schemaTmpName)) { LOG(error, "Could not save schema to '%s'", schemaTmpName.c_str()); -- cgit v1.2.3