diff options
author | Tor Egge <Tor.Egge@online.no> | 2022-06-23 21:39:48 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2022-06-23 21:39:48 +0200 |
commit | 09d546dfdd152ce4e69971fc8ce422d998cb523a (patch) | |
tree | 18da6c3d44a2a056fcc41a213f47feec26f2e30b /searchlib | |
parent | 316b44c13d886ef9ff50b040f4a01f38dfd3f94c (diff) |
Use std::filesystem to create and remove directories.
Diffstat (limited to 'searchlib')
6 files changed, 24 insertions, 19 deletions
diff --git a/searchlib/src/apps/tests/biglogtest.cpp b/searchlib/src/apps/tests/biglogtest.cpp index d5c59bf5b29..bd8991edc4b 100644 --- a/searchlib/src/apps/tests/biglogtest.cpp +++ b/searchlib/src/apps/tests/biglogtest.cpp @@ -8,6 +8,7 @@ #include <vespa/vespalib/util/size_literals.h> #include <vespa/vespalib/util/threadstackexecutor.h> #include <vespa/vespalib/data/databuffer.h> +#include <filesystem> using namespace search; using search::index::DummyFileHeaderContext; @@ -148,9 +149,8 @@ Test::testDIO() { uint64_t serial = 0; - FastOS_File::EmptyDirectory(_dir.c_str()); - FastOS_File::RemoveDirectory(_dir.c_str()); - EXPECT_TRUE(FastOS_File::MakeDirectory(_dir.c_str())); + std::filesystem::remove_all(std::filesystem::path(_dir)); + std::filesystem::create_directory(std::filesystem::path(_dir)); Map lidToBlobMap; vespalib::DataBuffer buf; @@ -238,7 +238,6 @@ Test::testDIO() factory<DS> ds(_dir); checkBlobs(ds(), lidToBlobMap); } - FastOS_File::EmptyDirectory(_dir.c_str()); - FastOS_File::RemoveDirectory(_dir.c_str()); + std::filesystem::remove_all(std::filesystem::path(_dir)); TEST_FLUSH(); } diff --git a/searchlib/src/tests/attribute/sourceselector/sourceselector_test.cpp b/searchlib/src/tests/attribute/sourceselector/sourceselector_test.cpp index c6091604a97..4ca2802d22d 100644 --- a/searchlib/src/tests/attribute/sourceselector/sourceselector_test.cpp +++ b/searchlib/src/tests/attribute/sourceselector/sourceselector_test.cpp @@ -6,7 +6,7 @@ #include <vespa/searchcommon/common/undefinedvalues.h> #include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/util/size_literals.h> -#include <vespa/fastos/file.h> +#include <filesystem> #include <vespa/log/log.h> LOG_SETUP("sourceselector_test"); @@ -161,8 +161,8 @@ Test::requireThatSelectorCanSaveAndLoad(bool compactLidSpace) selector.compactLidSpace(maxDocId - 4); } - FastOS_FileInterface::EmptyAndRemoveDirectory(index_dir.c_str()); - FastOS_FileInterface::MakeDirIfNotPresentOrExit(index_dir.c_str()); + std::filesystem::remove_all(std::filesystem::path(index_dir)); + std::filesystem::create_directory(std::filesystem::path(index_dir)); SourceSelector::SaveInfo::UP save_info = selector.extractSaveInfo(base_file_name); @@ -177,7 +177,7 @@ Test::requireThatSelectorCanSaveAndLoad(bool compactLidSpace) EXPECT_EQUAL(maxDocId + 2, selector2->getDocIdLimit()); } - FastOS_FileInterface::EmptyAndRemoveDirectory(index_dir.c_str()); + std::filesystem::remove_all(std::filesystem::path(index_dir)); } void diff --git a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp index 0865e2c199a..418182f7bbf 100644 --- a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp +++ b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp @@ -667,13 +667,13 @@ TEST("test that the integrated visit cache works.") { } TEST("testWriteRead") { - FastOS_File::RemoveDirectory("empty"); + std::filesystem::remove_all(std::filesystem::path("empty")); const char * bufA = "aaaaaaaaaaaaaaaaaaaaa"; const char * bufB = "bbbbbbbbbbbbbbbb"; const vespalib::ConstBufferRef a[2] = { vespalib::ConstBufferRef(bufA, strlen(bufA)), vespalib::ConstBufferRef(bufB, strlen(bufB))}; LogDataStore::Config config; { - EXPECT_TRUE(FastOS_File::MakeDirectory("empty")); + std::filesystem::create_directory(std::filesystem::path("empty")); DummyFileHeaderContext fileHeaderContext; vespalib::ThreadStackExecutor executor(1, 128_Ki); MyTlSyncer tlSyncer; @@ -737,7 +737,7 @@ TEST("testWriteRead") { EXPECT_EQUAL(0ul, datastore.getDiskBloat()); EXPECT_EQUAL(0ul, datastore.getMaxSpreadAsBloat()); } - FastOS_File::EmptyAndRemoveDirectory("empty"); + std::filesystem::remove_all(std::filesystem::path("empty")); } TEST("requireThatSyncTokenIsUpdatedAfterFlush") { diff --git a/searchlib/src/vespa/searchlib/diskindex/field_merger.cpp b/searchlib/src/vespa/searchlib/diskindex/field_merger.cpp index 860903174bc..d27ab2e7787 100644 --- a/searchlib/src/vespa/searchlib/diskindex/field_merger.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/field_merger.cpp @@ -12,12 +12,12 @@ #include <vespa/searchlib/common/i_flush_token.h> #include <vespa/searchlib/index/schemautil.h> #include <vespa/searchlib/util/filekit.h> -#include <vespa/searchlib/util/dirtraverse.h> #include <vespa/searchlib/util/posting_priority_queue_merger.hpp> #include <vespa/vespalib/io/fileutil.h> #include <vespa/vespalib/stllike/asciistream.h> #include <vespa/vespalib/util/exceptions.h> #include <filesystem> +#include <system_error> #include <vespa/log/log.h> @@ -107,8 +107,9 @@ FieldMerger::clean_tmp_dirs() while (i > 0) { i--; vespalib::string tmpindexpath = createTmpPath(_field_dir, i); - search::DirectoryTraverse dt(tmpindexpath.c_str()); - if (!dt.RemoveTree()) { + std::error_code ec; + std::filesystem::remove_all(std::filesystem::path(tmpindexpath), ec); + if (ec) { LOG(error, "Failed to clean tmpdir %s", tmpindexpath.c_str()); return false; } diff --git a/searchlib/src/vespa/searchlib/diskindex/fusion.cpp b/searchlib/src/vespa/searchlib/diskindex/fusion.cpp index e142255252c..4fd9d116244 100644 --- a/searchlib/src/vespa/searchlib/diskindex/fusion.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/fusion.cpp @@ -8,13 +8,13 @@ #include <vespa/searchlib/common/documentsummary.h> #include <vespa/searchlib/common/i_flush_token.h> #include <vespa/searchlib/index/schemautil.h> -#include <vespa/searchlib/util/dirtraverse.h> #include <vespa/vespalib/io/fileutil.h> #include <vespa/vespalib/util/error.h> #include <vespa/vespalib/util/exceptions.h> #include <vespa/vespalib/util/lambdatask.h> #include <vespa/document/util/queue.h> #include <filesystem> +#include <system_error> #include <vespa/log/log.h> @@ -117,8 +117,9 @@ Fusion::merge(vespalib::Executor& shared_executor, std::shared_ptr<IFlushToken> LOG(error, "\"%s\" is not a directory", _fusion_out_index.get_path().c_str()); return false; } - search::DirectoryTraverse dt(_fusion_out_index.get_path().c_str()); - if (!dt.RemoveTree()) { + std::error_code ec; + std::filesystem::remove_all(std::filesystem::path(_fusion_out_index.get_path()), ec); + if (ec) { LOG(error, "Failed to clean directory \"%s\"", _fusion_out_index.get_path().c_str()); return false; } diff --git a/searchlib/src/vespa/searchlib/transactionlog/common.cpp b/searchlib/src/vespa/searchlib/transactionlog/common.cpp index 4130ad0bc06..d4192fe0beb 100644 --- a/searchlib/src/vespa/searchlib/transactionlog/common.cpp +++ b/searchlib/src/vespa/searchlib/transactionlog/common.cpp @@ -3,7 +3,9 @@ #include "common.h" #include <vespa/vespalib/util/stringfmt.h> #include <vespa/fastos/file.h> +#include <filesystem> #include <stdexcept> +#include <system_error> namespace search::transactionlog { @@ -32,7 +34,9 @@ makeDirectory(const char * dir) if ( FastOS_File::Stat(dir, &st) ) { retval = st._isDirectory ? 0 : -2; } else { - retval = FastOS_File::MakeDirectory(dir) ? 0 : -3; + std::error_code ec; + std::filesystem::create_directory(std::filesystem::path(dir), ec); + retval = (!ec) ? 0 : -3; } return retval; |