Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions C/c4BlobStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static optional<C4BlobKey> BlobKeyFromFilename(slice filename) {

C4BlobStore::C4BlobStore(slice dirPath, C4DatabaseFlags flags, const C4EncryptionKey& key)
: _dirPath(dirPath), _flags(flags), _encryptionKey(key) {
FilePath dir(_dirPath, "");
FilePath dir(_dirPath);
if ( dir.exists() ) {
dir.mustExistAsDir();
} else if ( !(flags & kC4DB_ReadOnly) ) {
Expand All @@ -103,9 +103,9 @@ C4BlobStore::~C4BlobStore() = default;

void C4BlobStore::deleteStore() { dir().delRecursive(); }

FilePath C4BlobStore::dir() const { return {_dirPath, ""}; }
FilePath C4BlobStore::dir() const { return filesystem::path(_dirPath); }

FilePath C4BlobStore::pathForKey(C4BlobKey key) const { return {_dirPath, BlobKeyToFilename(key)}; }
FilePath C4BlobStore::pathForKey(C4BlobKey key) const { return filesystem::path(_dirPath) / BlobKeyToFilename(key); }

alloc_slice C4BlobStore::getFilePath(C4BlobKey key) const {
FilePath path = pathForKey(key);
Expand Down
14 changes: 8 additions & 6 deletions C/c4Database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <cinttypes>
#include <optional>
#include <regex>
#include <filesystem>


// NOTE: Most of C4Database is implemented in its concrete subclass DatabaseImpl.
Expand Down Expand Up @@ -71,11 +72,12 @@ void C4Database::enableExtension(slice name, slice path) {

static FilePath dbPath(slice name, slice parentDir) {
if ( name.size == 0 || parentDir.size == 0 ) C4Error::raise(LiteCoreDomain, kC4ErrorInvalidParameter);
return FilePath(string(parentDir), string(name)).addingExtension(kC4DatabaseFilenameExtension);
return FilePath(filesystem::path(parentDir.asString()) / name.asString())
.addingExtension(kC4DatabaseFilenameExtension);
}

static void ensureConfigDirExists(const C4DatabaseConfig2& config) {
if ( !(config.flags & kC4DB_ReadOnly) ) (void)FilePath(slice(config.parentDirectory), "").mkdir();
if ( !(config.flags & kC4DB_ReadOnly) ) (void)FilePath(slice(config.parentDirectory).asString()).mkdir();
}

static C4DatabaseConfig newToOldConfig(const C4DatabaseConfig2& config2) {
Expand All @@ -99,7 +101,7 @@ static C4DatabaseConfig newToOldConfig(const C4DatabaseConfig2& config2) {

/*static*/ bool C4Database::deleteAtPath(slice dbPath) {
// Find the db file in the bundle:
FilePath bundle{dbPath, ""};
FilePath bundle(dbPath.asString());
if ( bundle.exists() ) {
try {
C4StorageEngine storageEngine = nullptr;
Expand Down Expand Up @@ -143,21 +145,21 @@ constexpr const char* kInvalidDbNameMsgTemplate =
/*static*/ Retained<C4Database> C4Database::openAtPath(slice path, C4DatabaseFlags flags, const C4EncryptionKey* key) {
C4DatabaseConfig config = {flags};
if ( key ) config.encryptionKey = *key;
return DatabaseImpl::open(FilePath(path, ""), config);
return DatabaseImpl::open(FilePath(path.asString()), config);
}

/*static*/ void C4Database::copyNamed(slice sourcePath, slice destinationName, const Config& config) {
if ( !isValidDbName(destinationName) ) { Warn(kInvalidDbNameMsgTemplate, destinationName.asString().c_str()); }

ensureConfigDirExists(config);
FilePath from(sourcePath, "");
FilePath from(sourcePath.asString());
FilePath to = dbPath(destinationName, config.parentDirectory);
C4DatabaseConfig oldConfig = newToOldConfig(config);
CopyPrebuiltDB(from, to, &oldConfig);
}

/*static*/ void C4Database::copyFileToPath(slice sourcePath, slice destinationPath, const C4DatabaseConfig& config) {
return CopyPrebuiltDB(FilePath(sourcePath), FilePath(destinationPath), &config);
return CopyPrebuiltDB(FilePath(sourcePath.asString()), FilePath(destinationPath.asString()), &config);
}

/*static*/ bool C4Database::deleteNamed(slice name, slice inDirectory) {
Expand Down
16 changes: 9 additions & 7 deletions C/tests/c4DatabaseTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <iostream>
#include <mutex>
#include <thread>
#include <filesystem>

#include "sqlite3.h"

Expand Down Expand Up @@ -183,7 +184,7 @@ N_WAY_TEST_CASE_METHOD(C4DatabaseTest, "Database OpenNamed", "[Database][C][!thr
REQUIRE(bundle);
CHECK(c4db_getName(bundle) == kTestBundleName);
C4SliceResult path = c4db_getPath(bundle);
CHECK(path == TEMPDIR("cbl_core_test_bundle.cblite2" kPathSeparator)); // note trailing '/'
CHECK(path == TEMPDIR("cbl_core_test_bundle.cblite2"));
c4slice_free(path);
REQUIRE(c4db_close(bundle, WITH_ERROR()));
c4db_release(bundle);
Expand Down Expand Up @@ -912,21 +913,22 @@ N_WAY_TEST_CASE_METHOD(C4DatabaseTest, "Database copy", "[Database][C]") {

createRev(doc1ID, kRevID, kFleeceBody);
createRev(doc2ID, kRevID, kFleeceBody);
string srcPathStr = toString(c4db_getPath(db));
string srcPathStr = toString(c4db_getPath(db)) + "/";

C4DatabaseConfig2 config = *c4db_getConfig2(db);

string nuPath = string(slice(config.parentDirectory)) + string(kNuName) + ".cblite2" + kPathSeparator;
auto nuPath = filesystem::path(string(slice(config.parentDirectory))) / (string(kNuName) + ".cblite2");
auto nuPathStr = nuPath.string() + "/";

C4Error error;

SECTION("WITH SLASH") {}
SECTION("WITHOUT SLASH") {
srcPathStr.pop_back();
nuPath.pop_back();
nuPathStr.pop_back();
}

if ( !c4db_deleteNamed(kNuName, slice(nuPath), &error) ) { REQUIRE(error.code == 0); }
if ( !c4db_deleteNamed(kNuName, slice(nuPathStr), &error) ) { REQUIRE(error.code == 0); }

{
ExpectingExceptions x;
Expand Down Expand Up @@ -1116,8 +1118,8 @@ N_WAY_TEST_CASE_METHOD(C4DatabaseTest, "Database Create Upgrade Fixture", "[.Mai

closeDB();

litecore::FilePath fixturePath(C4DatabaseTest::sFixturesDir + kVersionedFixturesSubDir + filename, "");
litecore::FilePath(string(path), "").moveToReplacingDir(fixturePath, false);
litecore::FilePath fixturePath(C4DatabaseTest::sFixturesDir + kVersionedFixturesSubDir + filename);
litecore::FilePath(string(path)).moveToReplacingDir(fixturePath, false);
C4Log("New fixture is at %s", string(fixturePath).c_str());
}

Expand Down
6 changes: 3 additions & 3 deletions C/tests/c4PerfTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PerfTest : public C4Test {
explicit PerfTest(int variation) : C4Test(variation) {
const char* showFastDir = getenv("CBL_SHOWFAST_DIR");
if ( showFastDir ) {
litecore::FilePath showFastPath(showFastDir, "");
litecore::FilePath showFastPath(showFastDir);
if ( showFastPath.exists() && showFastPath.isDir() ) { _showFastDir = showFastDir; }
}

Expand Down Expand Up @@ -251,7 +251,7 @@ class PerfTest : public C4Test {
if ( isEncrypted() ) { filename += "_encrypted"; }

filename += ".json";
litecore::FilePath sfPath(_showFastDir, filename);
litecore::FilePath sfPath(filesystem::path(string(_showFastDir)) / filename);

ofstream fout(sfPath.path(), ios::trunc | ios::out);
fout.exceptions(ostream::failbit | ostream::badbit);
Expand Down Expand Up @@ -300,7 +300,7 @@ N_WAY_TEST_CASE_METHOD(PerfTest, "Import iTunesMusicLibrary", "[Perf][C][.slow]"
st.stop();
st.printReport("******** Importing JSON w/spaces", numDocs, "doc");

litecore::FilePath path(alloc_slice(c4db_getPath(db)).asString(), "db.sqlite3");
litecore::FilePath path(filesystem::path(slice(c4db_getPath(db)).asString()) / "db.sqlite3");
fprintf(stderr, "******** DB size is %" PRIi64 "\n", path.dataSize());
reopenDB();
string sf = generateShowfast((double)numDocs / st.elapsed(), "tunes_import_json");
Expand Down
4 changes: 2 additions & 2 deletions C/tests/c4Test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ void C4Test::deleteAndRecreateDB(C4Database*& db) {
/*static*/ alloc_slice C4Test::copyFixtureDB(const string& name) { return copyFixtureDB(sFixturesDir, name); }

alloc_slice C4Test::copyFixtureDB(const string& parentDir, const string& name) {
auto srcPath = litecore::FilePath(parentDir + name, "");
litecore::FilePath destDir(TempDir(), "");
auto srcPath = litecore::FilePath(parentDir + name);
litecore::FilePath destDir(TempDir());
auto dbPath = destDir[srcPath.fileOrDirName() + "/"];
dbPath.delRecursive();
srcPath.copyTo(dbPath);
Expand Down
2 changes: 1 addition & 1 deletion C/tests/c4Test.hh
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class WITH_ERROR {


// Temporary directory to use for tests.
#define TEMPDIR(PATH) c4str((TempDir() + (PATH)).c_str())
#define TEMPDIR(PATH) c4str((TempDir() + kPathSeparator + (PATH)).c_str())

const std::string& TempDir();

Expand Down
1 change: 0 additions & 1 deletion C/tests/cmake/platform_linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ function(setup_build)
target_sources(
C4Tests PRIVATE
${TOP}Crypto/mbedUtils.cc
${TOP}LiteCore/Unix/strlcat.c
)

target_link_libraries(
Expand Down
3 changes: 0 additions & 3 deletions C/tests/cmake/platform_win.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ function(setup_build)
${TOP}LiteCore/Support/PlatformIO.cc
${TOP}MSVC/vasprintf-msvc.c
${TOP}MSVC/asprintf.c
${TOP}MSVC/mkdtemp.cc
${TOP}MSVC/mkstemp.cc
${TOP}MSVC/strlcat.c
${TOP}MSVC/asprintf.c
)

Expand Down
3 changes: 2 additions & 1 deletion LiteCore/BlobStore/BlobStreams.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "EncryptedStream.hh"
#include "Error.hh"
#include "Logging.hh"
#include <filesystem>

namespace litecore {
using namespace std;
Expand All @@ -38,7 +39,7 @@ namespace litecore {

BlobWriteStream::BlobWriteStream(const string& blobsDir, EncryptionAlgorithm algorithm, slice encryptionKey) {
FILE* file;
_tmpPath = FilePath(blobsDir, "incoming_").mkTempFile(&file);
_tmpPath = FilePath(filesystem::path(blobsDir) / "incoming_").mkTempFile(&file);
_writer = shared_ptr<WriteStream>{new FileWriteStream(file)};
if ( algorithm != EncryptionAlgorithm::kNoEncryption )
_writer = make_shared<EncryptedWriteStream>(_writer, algorithm, encryptionKey);
Expand Down
4 changes: 2 additions & 2 deletions LiteCore/Database/DatabaseImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace litecore {
// `path` is path to bundle; return value is path to db file. Updates config.storageEngine. */
/*static*/ FilePath DatabaseImpl::findOrCreateBundle(const string& path, bool canCreate,
C4StorageEngine& storageEngine) {
FilePath bundle(path, "");
FilePath bundle(path);
bool createdDir = (canCreate && bundle.mkdir());
if ( !createdDir ) bundle.mustExistAsDir();

Expand Down Expand Up @@ -118,7 +118,7 @@ namespace litecore {
if ( bundlePath.isDir() ) {
bundlePath.delRecursive();
} else {
FilePath{bundlePath.path(), ""}.delRecursive();
FilePath{bundlePath.path()}.delRecursive();
}
}
} catch ( ... ) {
Expand Down
2 changes: 1 addition & 1 deletion LiteCore/Logging/LogFiles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ namespace litecore {
}

void purgeOldLogs() {
FilePath logDir(_options.directory, "");
FilePath logDir(_options.directory);
if ( !logDir.existsAsDir() ) { return; }

multimap<time_t, FilePath> logFiles;
Expand Down
1 change: 0 additions & 1 deletion LiteCore/Storage/DataFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "Instrumentation.hh"
#include <algorithm>
#include <cerrno>
#include <dirent.h>
#include <exception>
#include <iomanip>
#include <sstream>
Expand Down
4 changes: 3 additions & 1 deletion LiteCore/Support/DatabasePool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ namespace litecore {
logInfo("...all databases closed!");
}

FilePath DatabasePool::databasePath() const { return FilePath{_dbDir, _dbName + kC4DatabaseFilenameExtension}; }
FilePath DatabasePool::databasePath() const {
return filesystem::path(_dbDir.asString()) / (_dbName + kC4DatabaseFilenameExtension);
}

unsigned DatabasePool::capacity() const noexcept {
unique_lock lock(_mutex);
Expand Down
Loading
Loading