summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-07-18 08:09:22 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-07-18 08:09:22 +0000
commit4028c5af901b08e608807078f648904b9aa15500 (patch)
tree95ef84db19e4a74401e1fcfa570060132d86d1c2
parente7e320d7e40f6a2dff5d10b5e0034c3c8a310d07 (diff)
Use std::filesystem::rename
-rw-r--r--searchcore/src/vespa/searchcorespi/index/indexwriteutilities.cpp27
1 files 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());