summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/tests/io/fileutil/fileutiltest.cpp19
-rw-r--r--vespalib/src/vespa/vespalib/datastore/datastore.h5
-rw-r--r--vespalib/src/vespa/vespalib/datastore/datastore.hpp9
-rw-r--r--vespalib/src/vespa/vespalib/io/fileutil.cpp49
-rw-r--r--vespalib/src/vespa/vespalib/io/fileutil.h5
-rw-r--r--vespalib/src/vespa/vespalib/net/tls/crypto_codec.h2
-rw-r--r--vespalib/src/vespa/vespalib/util/alloc.cpp28
-rw-r--r--vespalib/src/vespa/vespalib/util/memory_allocator.h3
-rw-r--r--vespalib/src/vespa/vespalib/util/runnable_pair.cpp2
-rw-r--r--vespalib/src/vespa/vespalib/util/runnable_pair.h2
-rw-r--r--vespalib/src/vespa/vespalib/util/shared_string_repo.h1
-rw-r--r--vespalib/src/vespa/vespalib/util/typify.h2
12 files changed, 42 insertions, 85 deletions
diff --git a/vespalib/src/tests/io/fileutil/fileutiltest.cpp b/vespalib/src/tests/io/fileutil/fileutiltest.cpp
index 189bfef349b..51cf2055d33 100644
--- a/vespalib/src/tests/io/fileutil/fileutiltest.cpp
+++ b/vespalib/src/tests/io/fileutil/fileutiltest.cpp
@@ -1,9 +1,11 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/io/fileutil.h>
#include <vespa/vespalib/testkit/test_kit.h>
+#include <filesystem>
#include <iostream>
#include <vector>
#include <regex>
+#include <system_error>
#include <vespa/vespalib/util/exceptions.h>
#include <vespa/vespalib/util/size_literals.h>
@@ -237,9 +239,9 @@ TEST("require that vespalib::mkdir and vespalib::rmdir works")
ASSERT_TRUE(mkdir("mydir/otherdir/evenmorestuff"));
rmdir("mydir");
TEST_FATAL("Should not work without recursive option set");
- } catch (IoException& e) {
+ } catch (std::filesystem::filesystem_error& e) {
//std::cerr << e.what() << "\n";
- EXPECT_EQUAL(IoException::DIRECTORY_HAVE_CONTENT, e.getType());
+ EXPECT_EQUAL(make_error_code(std::errc::directory_not_empty), e.code());
}
// Works with recursive option
{
@@ -247,19 +249,6 @@ TEST("require that vespalib::mkdir and vespalib::rmdir works")
ASSERT_TRUE(!fileExists("mydir"));
ASSERT_TRUE(!rmdir("mydir", true));
}
- // Doesn't work on file
- try{
- {
- File f("myfile");
- f.open(File::CREATE);
- f.write("foo", 3, 0);
- }
- rmdir("myfile");
- TEST_FATAL("Should have failed to run rmdir on file.");
- } catch (IoException& e) {
- //std::cerr << e.what() << "\n";
- EXPECT_EQUAL(IoException::ILLEGAL_PATH, e.getType());
- }
// mkdir works when a path component is a symlink which points to
// another directory and the final path component does not exist.
diff --git a/vespalib/src/vespa/vespalib/datastore/datastore.h b/vespalib/src/vespa/vespalib/datastore/datastore.h
index be74c2a60d5..3ede2ada953 100644
--- a/vespalib/src/vespa/vespalib/datastore/datastore.h
+++ b/vespalib/src/vespa/vespalib/datastore/datastore.h
@@ -118,7 +118,10 @@ public:
~DataStore();
EntryRef addEntry(const EntryType &e);
- const EntryType &getEntry(EntryRef ref) const;
+
+ const EntryType &getEntry(EntryRef ref) const {
+ return *this->template getEntry<EntryType>(RefType(ref));
+ }
};
extern template class DataStoreT<EntryRefT<22> >;
diff --git a/vespalib/src/vespa/vespalib/datastore/datastore.hpp b/vespalib/src/vespa/vespalib/datastore/datastore.hpp
index 23dcb9222a1..e46b6cf111e 100644
--- a/vespalib/src/vespa/vespalib/datastore/datastore.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/datastore.hpp
@@ -164,15 +164,6 @@ DataStore<EntryType, RefT>::addEntry(const EntryType &e)
return FreeListAllocator<EntryType, RefT, NoOpReclaimer>(*this, 0).alloc(e).ref;
}
-template <typename EntryType, typename RefT>
-const EntryType &
-DataStore<EntryType, RefT>::getEntry(EntryRef ref) const
-{
- RefType intRef(ref);
- const EntryType *be = this->template getEntry<EntryType>(intRef);
- return *be;
-}
-
extern template class DataStoreT<EntryRefT<22> >;
}
diff --git a/vespalib/src/vespa/vespalib/io/fileutil.cpp b/vespalib/src/vespa/vespalib/io/fileutil.cpp
index 9994e0d0d6f..2d28f07e600 100644
--- a/vespalib/src/vespa/vespalib/io/fileutil.cpp
+++ b/vespalib/src/vespa/vespalib/io/fileutil.cpp
@@ -5,9 +5,10 @@
#include <vespa/vespalib/stllike/asciistream.h>
#include <vespa/vespalib/util/size_literals.h>
#include <vespa/vespalib/util/stringfmt.h>
-#include <vespa/fastos/file.h>
#include <ostream>
#include <cassert>
+#include <filesystem>
+#include <dirent.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
@@ -534,50 +535,12 @@ chdir(const string & directory)
bool
rmdir(const string & directory, bool recursive)
{
- string dirname(directory);
- if (!dirname.empty() && *dirname.rbegin() == '/') {
- dirname.resize(dirname.size() - 1);
- }
- if (dirname.empty()) {
- LOG(debug, "rmdir(%s): Not allowing deletion of '/'.", directory.c_str());
- return false;
- }
+ std::filesystem::path path(directory);
if (recursive) {
- FastOS_DirectoryScan dir(dirname.c_str());
- while (dir.ReadNext()) {
- if (strcmp(dir.GetName(), "..") != 0 &&
- strcmp(dir.GetName(), ".") != 0)
- {
- string fullpath(dirname + "/" + dir.GetName());
- if (dir.IsDirectory()) {
- rmdir(fullpath, true);
- } else {
- if (::unlink(fullpath.c_str()) != 0) {
- asciistream ost;
- ost << "rmdir(" << fullpath
- << (recursive ? ", recursive" : "")
- << "): Failed, errno(" << errno << "): "
- << safeStrerror(errno);
- throw IoException(ost.str(),
- IoException::getErrorType(errno),
- VESPA_STRLOC);
- }
- }
- }
- }
- }
- if (::rmdir(dirname.c_str()) == 0) {
- LOG(debug, "rmdir(%s): Directory deleted.", directory.c_str());
- return true;
- }
- if (errno == ENOENT) {
- LOG(debug, "rmdir(%s): No directory to delete.", directory.c_str());
- return false;
+ return std::filesystem::remove_all(path) > 0;
+ } else {
+ return std::filesystem::remove(path);
}
- asciistream ost;
- ost << "rmdir(" << dirname << (recursive ? ", recursive" : "")
- << "): Failed, errno(" << errno << "): " << safeStrerror(errno);
- throw IoException(ost.str(), IoException::getErrorType(errno), VESPA_STRLOC);
}
FileInfo::UP
diff --git a/vespalib/src/vespa/vespalib/io/fileutil.h b/vespalib/src/vespa/vespalib/io/fileutil.h
index d9e1a00345f..4d2ce45358a 100644
--- a/vespalib/src/vespa/vespalib/io/fileutil.h
+++ b/vespalib/src/vespa/vespalib/io/fileutil.h
@@ -240,9 +240,12 @@ extern void chdir(const vespalib::string & directory);
* @param directory The directory name.
* @param recursive If set, remove all content of the directory to. If not
* set, fail if the directory is not empty.
- * @throw IoException If we failed to remove the directory.
+ * @throw std::filesystem::filesystem_error If we failed to remove the directory.
*
* @return True if directory existed, false if not.
+ *
+ * This function is deprecated. Use std::filesystem::remove or std::filesystem::remove_all
+ * instead.
*/
extern bool rmdir(const vespalib::string & directory, bool recursive = false);
diff --git a/vespalib/src/vespa/vespalib/net/tls/crypto_codec.h b/vespalib/src/vespa/vespalib/net/tls/crypto_codec.h
index 86ccaf3eb64..fc729d7dd6a 100644
--- a/vespalib/src/vespa/vespalib/net/tls/crypto_codec.h
+++ b/vespalib/src/vespa/vespalib/net/tls/crypto_codec.h
@@ -53,7 +53,7 @@ struct DecodeResult {
};
struct TlsContext;
-class PeerCredentials;
+struct PeerCredentials;
class AssumedRoles;
// TODO move to different namespace, not dependent on TLS?
diff --git a/vespalib/src/vespa/vespalib/util/alloc.cpp b/vespalib/src/vespa/vespalib/util/alloc.cpp
index d7e134cbb5a..8240fa2d8e6 100644
--- a/vespalib/src/vespa/vespalib/util/alloc.cpp
+++ b/vespalib/src/vespa/vespalib/util/alloc.cpp
@@ -228,6 +228,9 @@ getDefaultAutoAllocator(AutoAllocatorsMap & map) {
}
AutoAllocatorsMapWithDefault
+createAutoAllocatorsWithDefault() __attribute__((noinline));
+
+AutoAllocatorsMapWithDefault
createAutoAllocatorsWithDefault() {
AutoAllocatorsMapWithDefault tmp(createAutoAllocators(), nullptr);
tmp.second = &getDefaultAutoAllocator(tmp.first);
@@ -454,33 +457,33 @@ AutoAllocator::resize_inplace(PtrAndSize current, size_t newSize) const {
MMapAllocator::PtrAndSize
AutoAllocator::alloc(size_t sz) const {
- if (useMMap(sz)) {
- sz = roundUpToHugePages(sz);
- return MMapAllocator::salloc(sz, nullptr);
- } else {
+ if ( ! useMMap(sz)) {
if (_alignment == 0) {
return HeapAllocator::salloc(sz);
} else {
return AlignedHeapAllocator(_alignment).alloc(sz);
}
+ } else {
+ sz = roundUpToHugePages(sz);
+ return MMapAllocator::salloc(sz, nullptr);
}
}
void
AutoAllocator::free(PtrAndSize alloc) const {
- if (isMMapped(alloc.second)) {
- return MMapAllocator::sfree(alloc);
- } else {
+ if ( ! isMMapped(alloc.second)) {
return HeapAllocator::sfree(alloc);
+ } else {
+ return MMapAllocator::sfree(alloc);
}
}
void
AutoAllocator::free(void * ptr, size_t sz) const {
- if (useMMap(sz)) {
- return MMapAllocator::sfree(PtrAndSize(ptr, roundUpToHugePages(sz)));
- } else {
+ if ( ! useMMap(sz)) {
return HeapAllocator::sfree(PtrAndSize(ptr, sz));
+ } else {
+ return MMapAllocator::sfree(PtrAndSize(ptr, roundUpToHugePages(sz)));
}
}
@@ -491,6 +494,11 @@ MemoryAllocator::select_allocator(size_t mmapLimit, size_t alignment) {
return & AutoAllocator::getAllocator(mmapLimit, alignment);
}
+const MemoryAllocator *
+MemoryAllocator::select_allocator() {
+ return & AutoAllocator::getDefault();
+}
+
Alloc
Alloc::allocHeap(size_t sz)
{
diff --git a/vespalib/src/vespa/vespalib/util/memory_allocator.h b/vespalib/src/vespa/vespalib/util/memory_allocator.h
index d7a000e75b4..4f5374b0f11 100644
--- a/vespalib/src/vespa/vespalib/util/memory_allocator.h
+++ b/vespalib/src/vespa/vespalib/util/memory_allocator.h
@@ -37,7 +37,8 @@ public:
static size_t roundUpToHugePages(size_t sz) {
return (sz+(HUGEPAGE_SIZE-1)) & ~(HUGEPAGE_SIZE-1);
}
- static const MemoryAllocator * select_allocator(size_t mmapLimit = MemoryAllocator::HUGEPAGE_SIZE, size_t alignment=0);
+ static const MemoryAllocator * select_allocator();
+ static const MemoryAllocator * select_allocator(size_t mmapLimit, size_t alignment);
};
}
diff --git a/vespalib/src/vespa/vespalib/util/runnable_pair.cpp b/vespalib/src/vespa/vespalib/util/runnable_pair.cpp
index d0574b53d76..d947e05e7de 100644
--- a/vespalib/src/vespa/vespalib/util/runnable_pair.cpp
+++ b/vespalib/src/vespa/vespalib/util/runnable_pair.cpp
@@ -17,4 +17,4 @@ RunnablePair::run()
_second.run();
}
-} // namespace vesaplib
+} // namespace vespalib
diff --git a/vespalib/src/vespa/vespalib/util/runnable_pair.h b/vespalib/src/vespa/vespalib/util/runnable_pair.h
index ee3afe797bb..97417728b0f 100644
--- a/vespalib/src/vespa/vespalib/util/runnable_pair.h
+++ b/vespalib/src/vespa/vespalib/util/runnable_pair.h
@@ -20,5 +20,5 @@ public:
void run() override;
};
-} // namespace vesaplib
+} // namespace vespalib
diff --git a/vespalib/src/vespa/vespalib/util/shared_string_repo.h b/vespalib/src/vespa/vespalib/util/shared_string_repo.h
index 7ba59937c7c..99a120d1cc5 100644
--- a/vespalib/src/vespa/vespalib/util/shared_string_repo.h
+++ b/vespalib/src/vespa/vespalib/util/shared_string_repo.h
@@ -6,7 +6,6 @@
#include "string_id.h"
#include "spin_lock.h"
#include <vespa/vespalib/stllike/string.h>
-#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/stllike/identity.h>
#include <vespa/vespalib/stllike/allocator.h>
#include <vespa/vespalib/stllike/hashtable.hpp>
diff --git a/vespalib/src/vespa/vespalib/util/typify.h b/vespalib/src/vespa/vespalib/util/typify.h
index 4d97c1a458c..906c0c85710 100644
--- a/vespalib/src/vespa/vespalib/util/typify.h
+++ b/vespalib/src/vespa/vespalib/util/typify.h
@@ -3,7 +3,7 @@
#pragma once
#include "traits.h"
-#include <stddef.h>
+#include <cstddef>
#include <utility>
namespace vespalib {