summaryrefslogtreecommitdiffstats
path: root/vespalib
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 /vespalib
parent00c37c3d80017f062163e512696869787d06ff71 (diff)
Use std::filesystem::is_directory and std::filesystem::exists
Diffstat (limited to 'vespalib')
-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
7 files changed, 19 insertions, 40 deletions
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);
}
}