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 | |
parent | 316b44c13d886ef9ff50b040f4a01f38dfd3f94c (diff) |
Use std::filesystem to create and remove directories.
17 files changed, 53 insertions, 52 deletions
diff --git a/config/src/tests/misc/configsystem.cpp b/config/src/tests/misc/configsystem.cpp index db3d0a80706..db6764e6b17 100644 --- a/config/src/tests/misc/configsystem.cpp +++ b/config/src/tests/misc/configsystem.cpp @@ -5,6 +5,7 @@ #include <vespa/defaults.h> #include <vespa/fastos/file.h> #include <unistd.h> +#include <filesystem> using namespace config; @@ -25,23 +26,20 @@ TEST("require that bad home directory fails") { TEST("require that incorrect pid file type fails") { ASSERT_TRUE(nullptr != getcwd(cwd, sizeof(cwd))); - FastOS_File::EmptyAndRemoveDirectory("var"); - FastOS_File::MakeDirIfNotPresentOrExit("var"); - FastOS_File::MakeDirIfNotPresentOrExit("var/run"); - FastOS_File::MakeDirIfNotPresentOrExit("var/run/configproxy.pid"); + std::filesystem::remove_all(std::filesystem::path("var")); + std::filesystem::create_directories(std::filesystem::path("var/run/configproxy.pid")); ASSERT_EQUAL(0, setenv(VESPA_HOME, cwd, 1)); vespa::Defaults::bootstrap(cwd); ConfigSystem configSystem; ASSERT_FALSE(configSystem.isUp()); - FastOS_File::EmptyAndRemoveDirectory("var"); + std::filesystem::remove_all(std::filesystem::path("var")); } TEST("require that correct pid file succeeds") { ASSERT_TRUE(nullptr != getcwd(cwd, sizeof(cwd))); - FastOS_File::EmptyAndRemoveDirectory("var"); - FastOS_File::MakeDirIfNotPresentOrExit("var"); - FastOS_File::MakeDirIfNotPresentOrExit("var/run"); + std::filesystem::remove_all(std::filesystem::path("var")); + std::filesystem::create_directories(std::filesystem::path("var/run")); FastOS_File pid_file("var/run/configproxy.pid"); pid_file.OpenWriteOnlyTruncate(); ASSERT_TRUE(pid_file.Close()); @@ -50,7 +48,7 @@ TEST("require that correct pid file succeeds") { vespa::Defaults::bootstrap(cwd); ConfigSystem configSystem; ASSERT_TRUE(configSystem.isUp()); - FastOS_File::EmptyAndRemoveDirectory("var"); + std::filesystem::remove_all(std::filesystem::path("var")); } TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/searchcore/src/apps/tests/persistenceconformance_test.cpp b/searchcore/src/apps/tests/persistenceconformance_test.cpp index b489a07bba2..a9c18d4b8a9 100644 --- a/searchcore/src/apps/tests/persistenceconformance_test.cpp +++ b/searchcore/src/apps/tests/persistenceconformance_test.cpp @@ -379,7 +379,7 @@ public: } void clear() override { - FastOS_FileInterface::EmptyAndRemoveDirectory(_baseDir.c_str()); + std::filesystem::remove_all(std::filesystem::path(_baseDir)); } bool hasPersistence() const override { return true; } diff --git a/searchcore/src/tests/proton/docsummary/docsummary.cpp b/searchcore/src/tests/proton/docsummary/docsummary.cpp index a0400661b4e..49fd82c3a36 100644 --- a/searchcore/src/tests/proton/docsummary/docsummary.cpp +++ b/searchcore/src/tests/proton/docsummary/docsummary.cpp @@ -42,6 +42,7 @@ #include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/util/destructor_callbacks.h> #include <vespa/vespalib/util/size_literals.h> +#include <filesystem> #include <regex> #include <vespa/log/log.h> @@ -82,11 +83,11 @@ public: DirMaker(const vespalib::string & dir) : _dir(dir) { - FastOS_File::MakeDirectory(dir.c_str()); + std::filesystem::create_directory(std::filesystem::path(dir)); } ~DirMaker() { - FastOS_File::EmptyAndRemoveDirectory(_dir.c_str()); + std::filesystem::remove_all(std::filesystem::path(_dir)); } private: vespalib::string _dir; @@ -180,7 +181,7 @@ public: vespalib::ThreadStackExecutor _summaryExecutor; MockSharedThreadingService _shared_service; TransLogServer _tls; - bool _mkdirOk; + bool _made_dir; matching::QueryLimiter _queryLimiter; DummyWireService _dummy; ::config::DirSpec _spec; @@ -199,7 +200,7 @@ public: _summaryExecutor(8, 128_Ki), _shared_service(_summaryExecutor, _summaryExecutor), _tls(_shared_service.transport(), "tmp", 9013, ".", _fileHeaderContext), - _mkdirOk(FastOS_File::MakeDirectory("tmpdb")), + _made_dir(std::filesystem::create_directory(std::filesystem::path("tmpdb"))), _queryLimiter(), _dummy(), _spec(TEST_PATH("")), @@ -212,7 +213,7 @@ public: _aw(), _sa() { - assert(_mkdirOk); + (void) _made_dir; auto b = std::make_shared<BootstrapConfig>(1, _documenttypesConfig, _repo, std::make_shared<ProtonConfig>(), std::make_shared<FiledistributorrpcConfig>(), @@ -220,9 +221,7 @@ public: _tuneFileDocumentDB, _hwInfo); _configMgr.forwardConfig(b); _configMgr.nextGeneration(_shared_service.transport(), 0ms); - if (! FastOS_File::MakeDirectory((std::string("tmpdb/") + docTypeName).c_str())) { - LOG_ABORT("should not be reached"); - } + std::filesystem::create_directory(std::filesystem::path(std::string("tmpdb/") + docTypeName)); _ddb = DocumentDB::create("tmpdb", _configMgr.getConfig(), "tcp/localhost:9013", _queryLimiter, DocTypeName(docTypeName), makeBucketSpace(), *b->getProtonConfigSP(), *this, _shared_service, _tls, _dummy, _fileHeaderContext, @@ -239,8 +238,8 @@ public: _sa.reset(); _aw.reset(); _ddb.reset(); - FastOS_File::EmptyAndRemoveDirectory("tmp"); - FastOS_File::EmptyAndRemoveDirectory("tmpdb"); + std::filesystem::remove_all(std::filesystem::path("tmp")); + std::filesystem::remove_all(std::filesystem::path("tmpdb")); } void diff --git a/searchcore/src/tests/proton/index/diskindexcleaner_test.cpp b/searchcore/src/tests/proton/index/diskindexcleaner_test.cpp index c814bdf3f37..35583ea46da 100644 --- a/searchcore/src/tests/proton/index/diskindexcleaner_test.cpp +++ b/searchcore/src/tests/proton/index/diskindexcleaner_test.cpp @@ -6,6 +6,7 @@ #include <vespa/vespalib/testkit/testapp.h> #include <vespa/fastos/file.h> #include <algorithm> +#include <filesystem> #include <vespa/log/log.h> LOG_SETUP("diskindexcleaner_test"); @@ -30,7 +31,7 @@ public: const string index_dir = "diskindexcleaner_test_data"; void removeTestData() { - FastOS_FileInterface::EmptyAndRemoveDirectory(index_dir.c_str()); + std::filesystem::remove_all(std::filesystem::path(index_dir)); } int @@ -52,9 +53,9 @@ Test::Main() } void createIndex(const string &name) { - FastOS_FileInterface::MakeDirIfNotPresentOrExit(index_dir.c_str()); + std::filesystem::create_directory(std::filesystem::path(index_dir)); const string dir_name = index_dir + "/" + name; - FastOS_FileInterface::MakeDirIfNotPresentOrExit(dir_name.c_str()); + std::filesystem::create_directory(std::filesystem::path(dir_name)); const string serial_file = dir_name + "/serial.dat"; FastOS_File file(serial_file.c_str()); file.OpenWriteOnlyTruncate(); diff --git a/searchcore/src/tests/proton/index/fusionrunner_test.cpp b/searchcore/src/tests/proton/index/fusionrunner_test.cpp index 4a84e3972ad..850f8a8f0d1 100644 --- a/searchcore/src/tests/proton/index/fusionrunner_test.cpp +++ b/searchcore/src/tests/proton/index/fusionrunner_test.cpp @@ -20,6 +20,7 @@ #include <vespa/vespalib/util/size_literals.h> #include <vespa/vespalib/stllike/asciistream.h> #include <vespa/fastos/file.h> +#include <filesystem> #include <set> using document::Document; @@ -134,7 +135,7 @@ Schema getSchema() { } void Test::setUp() { - FastOS_FileInterface::EmptyAndRemoveDirectory(base_dir.c_str()); + std::filesystem::remove_all(std::filesystem::path(base_dir)); _fusion_runner.reset(new FusionRunner(base_dir, getSchema(), TuneFileAttributes(), _fileHeaderContext)); @@ -144,7 +145,7 @@ void Test::setUp() { } void Test::tearDown() { - FastOS_FileInterface::EmptyAndRemoveDirectory(base_dir.c_str()); + std::filesystem::remove_all(std::filesystem::path(base_dir)); _selector.reset(0); } @@ -167,7 +168,7 @@ void addDocument(DocBuilder & doc_builder, MemoryIndex &index, ISourceSelector & } void Test::createIndex(const string &dir, uint32_t id, bool fusion) { - FastOS_FileInterface::MakeDirIfNotPresentOrExit(dir.c_str()); + std::filesystem::create_directory(std::filesystem::path(dir)); vespalib::asciistream ost; if (fusion) { ost << dir << "/index.fusion." << id; diff --git a/searchcore/src/tests/proton/index/indexmanager_test.cpp b/searchcore/src/tests/proton/index/indexmanager_test.cpp index 0bc11e64df8..b427daa4ad1 100644 --- a/searchcore/src/tests/proton/index/indexmanager_test.cpp +++ b/searchcore/src/tests/proton/index/indexmanager_test.cpp @@ -85,7 +85,7 @@ Schema getSchema() { } void removeTestData() { - FastOS_FileInterface::EmptyAndRemoveDirectory(index_dir.c_str()); + std::filesystem::remove_all(std::filesystem::path(index_dir)); } Document::UP buildDocument(DocBuilder &doc_builder, int id, diff --git a/searchcore/src/vespa/searchcore/proton/attribute/flushableattribute.cpp b/searchcore/src/vespa/searchcore/proton/attribute/flushableattribute.cpp index f0e7cad5758..25d6e3c36a7 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/flushableattribute.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/flushableattribute.cpp @@ -5,7 +5,6 @@ #include "attribute_directory.h" #include <vespa/searchlib/attribute/attributefilesavetarget.h> #include <vespa/searchlib/attribute/attributesaver.h> -#include <vespa/searchlib/util/dirtraverse.h> #include <vespa/searchlib/util/filekit.h> #include <vespa/vespalib/io/fileutil.h> #include <vespa/searchlib/common/serialnumfileheadercontext.h> diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreflushtarget.cpp b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreflushtarget.cpp index 53535cddcdf..7786ead49b2 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreflushtarget.cpp +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreflushtarget.cpp @@ -8,7 +8,6 @@ #include <vespa/searchlib/attribute/attributefilesavetarget.h> #include <vespa/searchlib/attribute/attributememorysavetarget.h> #include <vespa/searchlib/attribute/attributesaver.h> -#include <vespa/searchlib/util/dirtraverse.h> #include <vespa/searchlib/common/serialnumfileheadercontext.h> #include <vespa/searchlib/util/filekit.h> #include <filesystem> diff --git a/searchcore/src/vespa/searchcore/proton/server/fileconfigmanager.cpp b/searchcore/src/vespa/searchcore/proton/server/fileconfigmanager.cpp index 2c758ee712f..820e61bc7a7 100644 --- a/searchcore/src/vespa/searchcore/proton/server/fileconfigmanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/fileconfigmanager.cpp @@ -389,7 +389,7 @@ FileConfigManager::removeInvalid() vespalib::string snapDirBaseName(makeSnapDirBaseName(serial)); vespalib::string snapDir(_baseDir + "/" + snapDirBaseName); try { - FastOS_FileInterface::EmptyAndRemoveDirectory(snapDir.c_str()); + std::filesystem::remove_all(std::filesystem::path(snapDir)); } catch (const std::exception &e) { LOG(warning, "Removing obsolete config directory '%s' failed due to %s", snapDir.c_str(), e.what()); } diff --git a/searchcore/src/vespa/searchcorespi/index/fusionrunner.cpp b/searchcore/src/vespa/searchcorespi/index/fusionrunner.cpp index 1675b6091cf..1d63e883245 100644 --- a/searchcore/src/vespa/searchcorespi/index/fusionrunner.cpp +++ b/searchcore/src/vespa/searchcorespi/index/fusionrunner.cpp @@ -6,7 +6,6 @@ #include <vespa/searchlib/common/serialnumfileheadercontext.h> #include <vespa/searchlib/attribute/fixedsourceselector.h> #include <vespa/searchlib/queryeval/isourceselector.h> -#include <vespa/searchlib/util/dirtraverse.h> #include <vespa/log/log.h> LOG_SETUP(".searchcorespi.index.fusionrunner"); diff --git a/searchcore/src/vespa/searchcorespi/index/indexmaintainer.cpp b/searchcore/src/vespa/searchcorespi/index/indexmaintainer.cpp index af273bc5e45..1f022b1215b 100644 --- a/searchcore/src/vespa/searchcorespi/index/indexmaintainer.cpp +++ b/searchcore/src/vespa/searchcorespi/index/indexmaintainer.cpp @@ -13,7 +13,6 @@ #include <vespa/searchcorespi/flush/lambdaflushtask.h> #include <vespa/searchlib/common/i_flush_token.h> #include <vespa/searchlib/index/schemautil.h> -#include <vespa/searchlib/util/dirtraverse.h> #include <vespa/searchlib/util/filekit.h> #include <vespa/vespalib/io/fileutil.h> #include <vespa/vespalib/util/array.hpp> @@ -23,6 +22,7 @@ #include <vespa/vespalib/util/destructor_callbacks.h> #include <vespa/vespalib/util/time.h> #include <vespa/fastos/file.h> +#include <filesystem> #include <sstream> #include <vespa/log/log.h> @@ -1103,7 +1103,7 @@ IndexMaintainer::runFusion(const FusionSpec &fusion_spec, std::shared_ptr<search } else { LOG(error, "Fusion failed, fusion dir \"%s\".", fail_dir.c_str()); } - FastOS_FileInterface::EmptyAndRemoveDirectory(fail_dir.c_str()); + std::filesystem::remove_all(std::filesystem::path(fail_dir)); { LockGuard slock(_state_lock); LockGuard ilock(_index_update_lock); 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; |