summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2023-07-20 15:46:58 +0200
committerTor Egge <Tor.Egge@online.no>2023-07-20 15:46:58 +0200
commit8299e786be93e412360bcc3b44ab73a322a6a4da (patch)
treeee97df8abea0dababc4475d80184e94162178488
parent00c37c3d80017f062163e512696869787d06ff71 (diff)
Use std::filesystem::is_directory and std::filesystem::exists
-rw-r--r--document/src/tests/documenttestcase.cpp4
-rw-r--r--documentapi/src/tests/messages/testbase.cpp4
-rw-r--r--searchcore/src/tests/proton/proton_disk_layout/proton_disk_layout_test.cpp2
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/proton_disk_layout.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/load_utils.cpp3
-rw-r--r--vespalib/src/tests/io/fileutil/fileutiltest.cpp10
-rw-r--r--vespalib/src/tests/net/tls/auto_reloading_tls_crypto_engine/auto_reloading_tls_crypto_engine_test.cpp2
-rw-r--r--vespalib/src/tests/util/mmap_file_allocator_factory/mmap_file_allocator_factory_test.cpp8
-rw-r--r--vespalib/src/vespa/vespalib/io/fileutil.cpp12
-rw-r--r--vespalib/src/vespa/vespalib/io/fileutil.h16
-rw-r--r--vespalib/src/vespa/vespalib/net/tls/transport_security_options_reading.cpp3
-rw-r--r--vespalib/src/vespa/vespalib/util/cgroup_resource_limits.cpp8
12 files changed, 27 insertions, 47 deletions
diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp
index 2e9e783470c..d290371953f 100644
--- a/document/src/tests/documenttestcase.cpp
+++ b/document/src/tests/documenttestcase.cpp
@@ -23,7 +23,6 @@
#include <vespa/document/serialization/vespadocumentdeserializer.h>
#include <vespa/document/serialization/vespadocumentserializer.h>
#include <vespa/vespalib/objects/nbostream.h>
-#include <vespa/vespalib/io/fileutil.h>
#include <vespa/vespalib/util/growablebytebuffer.h>
#include <vespa/vespalib/testkit/test_kit.h>
@@ -32,6 +31,7 @@
#include <fcntl.h>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
+#include <filesystem>
using vespalib::nbostream;
using namespace ::testing;
@@ -748,7 +748,7 @@ TEST(DocumentTest,testReadSerializedAllVersions)
int version = tests[i]._createdVersion;
std::string name = tests[i]._dataFile;
std::cerr << name << std::endl;
- if (!vespalib::fileExists(name)) {
+ if (!std::filesystem::exists(std::filesystem::path(name))) {
FAIL() << "File " << name << " does not exist.";
}
int fd = open(tests[i]._dataFile.c_str(), O_RDONLY);
diff --git a/documentapi/src/tests/messages/testbase.cpp b/documentapi/src/tests/messages/testbase.cpp
index ddce9f82a5d..9135d6d1c2e 100644
--- a/documentapi/src/tests/messages/testbase.cpp
+++ b/documentapi/src/tests/messages/testbase.cpp
@@ -5,10 +5,10 @@
#include <vespa/document/base/testdocrepo.h>
#include <vespa/document/config/documenttypes_config_fwd.h>
#include <vespa/vespalib/util/exception.h>
-#include <vespa/vespalib/io/fileutil.h>
#include <fcntl.h>
#include <unistd.h>
#include <algorithm>
+#include <filesystem>
#include <vespa/log/log.h>
LOG_SETUP(".testbase");
@@ -128,7 +128,7 @@ TestBase::testCoverage(const std::vector<uint32_t> &expected, const std::vector<
}
bool TestBase::file_content_is_unchanged(const string& filename, const mbus::Blob& data_to_write) const {
- if (!vespalib::fileExists(filename)) {
+ if (!std::filesystem::exists(std::filesystem::path(filename))) {
return false;
}
mbus::Blob existing = readFile(filename);
diff --git a/searchcore/src/tests/proton/proton_disk_layout/proton_disk_layout_test.cpp b/searchcore/src/tests/proton/proton_disk_layout/proton_disk_layout_test.cpp
index 3d087808e44..436719c12fc 100644
--- a/searchcore/src/tests/proton/proton_disk_layout/proton_disk_layout_test.cpp
+++ b/searchcore/src/tests/proton/proton_disk_layout/proton_disk_layout_test.cpp
@@ -67,7 +67,7 @@ struct DiskLayoutFixture {
std::set<vespalib::string> dirs;
auto names = vespalib::listDirectory(documentsDir);
for (const auto &name : names) {
- if (vespalib::isDirectory(documentsDir + "/" + name)) {
+ if (std::filesystem::is_directory(std::filesystem::path(documentsDir + "/" + name))) {
dirs.emplace(name);
}
}
diff --git a/searchcore/src/vespa/searchcore/proton/server/proton_disk_layout.cpp b/searchcore/src/vespa/searchcore/proton/server/proton_disk_layout.cpp
index aecb1eec262..6e876888c50 100644
--- a/searchcore/src/vespa/searchcore/proton/server/proton_disk_layout.cpp
+++ b/searchcore/src/vespa/searchcore/proton/server/proton_disk_layout.cpp
@@ -54,7 +54,7 @@ void scanDir(const vespalib::string documentsDir, DocumentDBDirScan &dirs)
{
auto names = vespalib::listDirectory(documentsDir);
for (const auto &name : names) {
- if (vespalib::isDirectory(documentsDir + "/" + name)) {
+ if (std::filesystem::is_directory(std::filesystem::path(documentsDir + "/" + name))) {
if (isRemovedName(name)) {
dirs[DocTypeName(getNormalName(name))].removed = true;
} else {
diff --git a/searchlib/src/vespa/searchlib/attribute/load_utils.cpp b/searchlib/src/vespa/searchlib/attribute/load_utils.cpp
index 5f17689d605..7d7837c8881 100644
--- a/searchlib/src/vespa/searchlib/attribute/load_utils.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/load_utils.cpp
@@ -9,6 +9,7 @@
#include <vespa/searchlib/util/fileutil.h>
#include <vespa/vespalib/io/fileutil.h>
#include <vespa/vespalib/util/array.hpp>
+#include <filesystem>
using search::multivalue::WeightedValue;
using vespalib::datastore::AtomicEntryRef;
@@ -45,7 +46,7 @@ LoadUtils::openWeight(const AttributeVector& attr)
bool
LoadUtils::file_exists(const AttributeVector& attr, const vespalib::string& suffix)
{
- return vespalib::fileExists(attr.getBaseFileName() + "." + suffix);
+ return std::filesystem::exists(std::filesystem::path(attr.getBaseFileName() + "." + suffix));
}
LoadedBufferUP
diff --git a/vespalib/src/tests/io/fileutil/fileutiltest.cpp b/vespalib/src/tests/io/fileutil/fileutiltest.cpp
index f98ddd80de4..5e64bfa7192 100644
--- a/vespalib/src/tests/io/fileutil/fileutiltest.cpp
+++ b/vespalib/src/tests/io/fileutil/fileutiltest.cpp
@@ -11,6 +11,14 @@
namespace vespalib {
+namespace {
+
+bool fileExists(const vespalib::string& name) {
+ return std::filesystem::exists(std::filesystem::path(name));
+}
+
+}
+
vespalib::string normalizeOpenError(const vespalib::string str)
{
std::regex modeex(" mode=[0-7]+");
@@ -178,8 +186,6 @@ TEST("require that vespalib::File::stat works")
f.close();
EXPECT_EQUAL(6, getFileSize("myfile"));
- EXPECT_EQUAL(true, isDirectory("mydir"));
- EXPECT_EQUAL(false, isDirectory("myfile"));
EXPECT_EQUAL(true, fileExists("myfile"));
EXPECT_EQUAL(true, fileExists("mydir"));
}
diff --git a/vespalib/src/tests/net/tls/auto_reloading_tls_crypto_engine/auto_reloading_tls_crypto_engine_test.cpp b/vespalib/src/tests/net/tls/auto_reloading_tls_crypto_engine/auto_reloading_tls_crypto_engine_test.cpp
index 62614f5d811..8c17d366940 100644
--- a/vespalib/src/tests/net/tls/auto_reloading_tls_crypto_engine/auto_reloading_tls_crypto_engine_test.cpp
+++ b/vespalib/src/tests/net/tls/auto_reloading_tls_crypto_engine/auto_reloading_tls_crypto_engine_test.cpp
@@ -100,7 +100,7 @@ struct Fixture {
~Fixture() {
engine.reset();
- if (fileExists("test_cert.pem")) {
+ if (std::filesystem::exists(std::filesystem::path("test_cert.pem"))) {
unlink("test_cert.pem"); // just crash the test if this throws
}
}
diff --git a/vespalib/src/tests/util/mmap_file_allocator_factory/mmap_file_allocator_factory_test.cpp b/vespalib/src/tests/util/mmap_file_allocator_factory/mmap_file_allocator_factory_test.cpp
index b9c8a9f82c9..346c415ff9b 100644
--- a/vespalib/src/tests/util/mmap_file_allocator_factory/mmap_file_allocator_factory_test.cpp
+++ b/vespalib/src/tests/util/mmap_file_allocator_factory/mmap_file_allocator_factory_test.cpp
@@ -37,12 +37,12 @@ TEST(MmapFileAllocatorFactoryTest, nonempty_dir_gives_allocator)
EXPECT_TRUE(is_mmap_file_allocator(allocator1.get()));
vespalib::string allocator0_dir(basedir + "/0.foo");
vespalib::string allocator1_dir(basedir + "/1.bar");
- EXPECT_TRUE(isDirectory(allocator0_dir));
- EXPECT_TRUE(isDirectory(allocator1_dir));
+ EXPECT_TRUE(std::filesystem::is_directory(std::filesystem::path(allocator0_dir)));
+ EXPECT_TRUE(std::filesystem::is_directory(std::filesystem::path(allocator1_dir)));
allocator0.reset();
- EXPECT_FALSE(isDirectory(allocator0_dir));
+ EXPECT_FALSE(std::filesystem::is_directory(std::filesystem::path(allocator0_dir)));
allocator1.reset();
- EXPECT_FALSE(isDirectory(allocator1_dir));
+ EXPECT_FALSE(std::filesystem::is_directory(std::filesystem::path(allocator1_dir)));
MmapFileAllocatorFactory::instance().setup("");
std::filesystem::remove_all(std::filesystem::path(basedir));
}
diff --git a/vespalib/src/vespa/vespalib/io/fileutil.cpp b/vespalib/src/vespa/vespalib/io/fileutil.cpp
index 1ff2d3434f7..1b63a5b0910 100644
--- a/vespalib/src/vespa/vespalib/io/fileutil.cpp
+++ b/vespalib/src/vespa/vespalib/io/fileutil.cpp
@@ -467,18 +467,6 @@ stat(const string & path)
return processStat(filestats, ::stat(path.c_str(), &filestats) == 0, path);
}
-FileInfo::UP
-lstat(const string & path)
-{
- struct ::stat filestats;
- return processStat(filestats, ::lstat(path.c_str(), &filestats) == 0, path);
-}
-
-bool
-fileExists(const string & path) {
- return (stat(path).get() != 0);
-}
-
namespace {
uint32_t diskAlignmentSize = 4_Ki;
diff --git a/vespalib/src/vespa/vespalib/io/fileutil.h b/vespalib/src/vespa/vespalib/io/fileutil.h
index 20711d10201..9a55edb88d7 100644
--- a/vespalib/src/vespa/vespalib/io/fileutil.h
+++ b/vespalib/src/vespa/vespalib/io/fileutil.h
@@ -233,22 +233,6 @@ extern void chdir(const vespalib::string & directory);
extern FileInfo::UP stat(const vespalib::string & path);
/**
- * Stat a file. Give info on symlink rather than on file pointed to.
- *
- * @throw IoException If we failed to stat the file.
- * @return A file info object if everything went well, a null pointer if the
- * file was not found.
- */
-extern FileInfo::UP lstat(const vespalib::string & path);
-
-/**
- * Check if a file exists or not. See also pathExists.
- *
- * @throw IoException If we failed to stat the file.
- */
-extern bool fileExists(const vespalib::string & path);
-
-/**
* Get the filesize of the given file. Ignoring if it exists or not.
* (None-existing files will be reported to have size zero)
*/
diff --git a/vespalib/src/vespa/vespalib/net/tls/transport_security_options_reading.cpp b/vespalib/src/vespa/vespalib/net/tls/transport_security_options_reading.cpp
index 94281d3ef41..383d088ed20 100644
--- a/vespalib/src/vespa/vespalib/net/tls/transport_security_options_reading.cpp
+++ b/vespalib/src/vespa/vespalib/net/tls/transport_security_options_reading.cpp
@@ -7,6 +7,7 @@
#include <vespa/vespalib/data/memory_input.h>
#include <vespa/vespalib/net/tls/capability_set.h>
#include <vespa/vespalib/stllike/hash_set.h>
+#include <filesystem>
namespace vespalib::net::tls {
@@ -39,7 +40,7 @@ using namespace slime::convenience;
namespace {
void verify_referenced_file_exists(const vespalib::string& file_path) {
- if (!fileExists(file_path)) {
+ if (!std::filesystem::exists(std::filesystem::path(file_path))) {
throw IllegalArgumentException(make_string("File '%s' referenced by TLS config does not exist", file_path.c_str()));
}
}
diff --git a/vespalib/src/vespa/vespalib/util/cgroup_resource_limits.cpp b/vespalib/src/vespa/vespalib/util/cgroup_resource_limits.cpp
index 35094c8aeaa..1ff30af23cc 100644
--- a/vespalib/src/vespa/vespalib/util/cgroup_resource_limits.cpp
+++ b/vespalib/src/vespa/vespalib/util/cgroup_resource_limits.cpp
@@ -2,9 +2,9 @@
#include "cgroup_resource_limits.h"
#include "round_up_to_page_size.h"
-#include <vespa/vespalib/io/fileutil.h>
#include <algorithm>
#include <cmath>
+#include <filesystem>
#include <fstream>
#include <limits>
#include <sstream>
@@ -111,7 +111,7 @@ void
CGroupResourceLimits::foreach_cgroup_level(const std::string& controller, const std::string& cgroup_path, const std::function<void(const std::string&)>& callback)
{
auto dir = combine_paths(_base_path, controller, empty_std_string);
- if (!isDirectory(dir)) {
+ if (!std::filesystem::is_directory(std::filesystem::path(dir))) {
return;
}
callback(dir);
@@ -121,14 +121,14 @@ CGroupResourceLimits::foreach_cgroup_level(const std::string& controller, const
auto slash_pos = cgroup_path.find('/', 1);
while (slash_pos != std::string::npos) {
dir = combine_paths(_base_path, controller, cgroup_path.substr(0, slash_pos));
- if (!isDirectory(dir)) {
+ if (!std::filesystem::is_directory(std::filesystem::path(dir))) {
return;
}
callback(dir);
slash_pos = cgroup_path.find('/', slash_pos + 1);
}
dir = combine_paths(_base_path, controller, cgroup_path);
- if (isDirectory(dir)) {
+ if (std::filesystem::is_directory(std::filesystem::path(dir))) {
callback(dir);
}
}