Skip to content

Commit

Permalink
WIP: Some more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yunimoo committed Aug 14, 2024
1 parent 316e416 commit c43012d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 40 deletions.
32 changes: 6 additions & 26 deletions fdbmonitor/fdbmonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
#include <iterator>
#include <functional>
#include <memory>
#include <filesystem>

#include <string.h>
#include <errno.h>
Expand Down Expand Up @@ -319,32 +320,11 @@ std::string cleanPath(std::string const& path) {
}

// Removes the last component from a path string (if possible) and returns the result with one trailing separator.
std::string popPath(const std::string& path) {
int i = path.size() - 1;
// Skip over any trailing separators
while (i >= 0 && path[i] == CANONICAL_PATH_SEPARATOR) {
--i;
}
// Skip over non separators
while (i >= 0 && path[i] != CANONICAL_PATH_SEPARATOR) {
--i;
}
// Skip over trailing separators again
bool foundSeparator = false;
while (i >= 0 && path[i] == CANONICAL_PATH_SEPARATOR) {
--i;
foundSeparator = true;
}

if (foundSeparator) {
++i;
} else {
// If absolute then we popped off the only path component so return "/"
if (!path.empty() && path.front() == CANONICAL_PATH_SEPARATOR) {
return "/";
}
}
return path.substr(0, i + 1);
std::filesystem::path popPath(std::filesystem::path const& path) {
std::filesystem::path parent = path.parent_path();
std::filesystem::path filename = parent.filename();
filename /= "";
return filename;
}

std::string abspath(std::string const& path, bool resolveLinks = true) {
Expand Down
4 changes: 2 additions & 2 deletions fdbrpc/Net2FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Future<Reference<class IAsyncFile>> Net2FileSystem::open(const std::string& file

// Deletes the given file. If mustBeDurable, returns only when the file is guaranteed to be deleted even after a power
// failure.
Future<Void> Net2FileSystem::deleteFile(const std::string& filename, bool mustBeDurable) {
Future<Void> Net2FileSystem::deleteFile(const std::filesystem::path& filename, bool mustBeDurable) {
return Net2AsyncFile::deleteFile(filename, mustBeDurable);
}

Expand Down Expand Up @@ -144,7 +144,7 @@ Net2FileSystem::Net2FileSystem(double ioTimeout, const std::string& fileSystemPa
#endif
}

Future<Void> Net2FileSystem::renameFile(const std::string& from, const std::string& to) {
Future<Void> Net2FileSystem::renameFile(const std::filesystem::path& from, const std::filesystem::path& to) {
return Net2AsyncFile::renameFile(from, to);
}

Expand Down
8 changes: 4 additions & 4 deletions fdbrpc/include/fdbrpc/AsyncFileEIO.actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class AsyncFileEIO : public IAsyncFile, public ReferenceCounted<AsyncFileEIO> {

return Reference<IAsyncFile>(new AsyncFileEIO(r->result, flags, filename));
}
static Future<Void> deleteFile(std::string filename, bool mustBeDurable) {
static Future<Void> deleteFile(std::filesystem::path const& filename, bool mustBeDurable) {
::deleteFile(filename);
if (mustBeDurable) {
CODE_PROBE(true, "deleteFile and fsync parent dir", probe::decoration::rare);
Expand All @@ -124,10 +124,10 @@ class AsyncFileEIO : public IAsyncFile, public ReferenceCounted<AsyncFileEIO> {
return Void();
}

ACTOR static Future<Void> renameFile(std::string from, std::string to) {
ACTOR static Future<Void> renameFile(std::filesystem::path from, std::filesystem::path to) {
state TaskPriority taskID = g_network->getCurrentTask();
state Promise<Void> p;
state eio_req* r = eio_rename(from.c_str(), to.c_str(), 0, eio_callback, &p);
state eio_req* r = eio_rename(from.string(), to.string(), 0, eio_callback, &p);
try {
wait(p.getFuture());
} catch (...) {
Expand Down Expand Up @@ -198,7 +198,7 @@ class AsyncFileEIO : public IAsyncFile, public ReferenceCounted<AsyncFileEIO> {
}
std::string getFilename() const override { return filename; }

ACTOR static Future<Void> async_fsync_parent(std::string filename) {
ACTOR static Future<Void> async_fsync_parent(std::filesystem::path const& filename) {
std::string folder = parentDirectory(filename);
TraceEvent("FSyncParentDir").detail("Folder", folder).detail("File", filename);
state int folderFD = ::open(folder.c_str(), O_DIRECTORY | O_CLOEXEC, 0);
Expand Down
2 changes: 1 addition & 1 deletion fdbrpc/include/fdbrpc/AsyncFileWinASIO.actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class AsyncFileWinASIO final : public IAsyncFile, public ReferenceCounted<AsyncF
return result.getFuture();
}

static Future<Void> renameFile(std::string const& from, std::string const& to) {
static Future<Void> renameFile(std::filesystem::path const& from, std::filesystem::path const& to) {
::renameFile(from, to);
return Void();
}
Expand Down
6 changes: 3 additions & 3 deletions flow/IAsyncFile.actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ TEST_CASE("/fileio/incrementalDelete") {
TEST_CASE("/fileio/rename") {
// create a file
state int64_t fileSize = 100e6;
state std::string filename = "/tmp/__JUNK__." + deterministicRandom()->randomUniqueID().toString();
state std::string renamedFile = "/tmp/__RENAMED_JUNK__." + deterministicRandom()->randomUniqueID().toString();
state std::filesystem::path filename = std::filesystem::path("/tmp/__JUNK__." + deterministicRandom()->randomUniqueID().toString());
state std::filesystem::path renamedFile = std::filesystem::path("/tmp/__RENAMED_JUNK__." + deterministicRandom()->randomUniqueID().toString());
state std::unique_ptr<char[]> data(new char[4096]);
state std::unique_ptr<char[]> readData(new char[4096]);
state Reference<IAsyncFile> f = wait(IAsyncFileSystem::filesystem()->open(
Expand All @@ -161,7 +161,7 @@ TEST_CASE("/fileio/rename") {

// verify rename happened
bool renamedExists = false;
auto bName = basename(renamedFile);
auto bName = renamedFile.filename();
auto files = platform::listFiles("/tmp/");
for (const auto& file : files) {
if (file == bName) {
Expand Down
9 changes: 5 additions & 4 deletions flow/TLSConfig.actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ TLSPolicy::~TLSPolicy() {}
#include <sstream>
#include <utility>
#include <vector>
#include <filesystem>

#include <boost/asio/ssl/context.hpp>
#include <boost/lexical_cast.hpp>
Expand Down Expand Up @@ -192,8 +193,8 @@ std::string TLSConfig::getCertificatePathSync() const {
}

const char* defaultCertFileName = "cert.pem";
if (fileExists(joinPath(platform::getDefaultConfigPath(), defaultCertFileName))) {
return joinPath(platform::getDefaultConfigPath(), defaultCertFileName);
if (fileExists(platform::getDefaultConfigPath() / defaultCertFileName)) {
return platform::getDefaultConfigPath() / defaultCertFileName;
}

return std::string();
Expand All @@ -210,8 +211,8 @@ std::string TLSConfig::getKeyPathSync() const {
}

const char* defaultKeyFileName = "key.pem";
if (fileExists(joinPath(platform::getDefaultConfigPath(), defaultKeyFileName))) {
return joinPath(platform::getDefaultConfigPath(), defaultKeyFileName);
if (fileExists(platform::getDefaultConfigPath() / defaultKeyFileName)) {
return platform::getDefaultConfigPath() / defaultKeyFileName;
}

return std::string();
Expand Down

0 comments on commit c43012d

Please sign in to comment.