Skip to content

Use std::filesystem::path for directories in the public API - #207

Open
sebasje wants to merge 4 commits into
xsco:mainfrom
sebasje:seabass/filesystem-path-api
Open

sebasje wants to merge 4 commits into
xsco:mainfrom
sebasje:seabass/filesystem-path-api

Conversation

@sebasje

@sebasje sebasje commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

As discussed in #205: the public API takes and returns directories as std::filesystem::path instead of std::string.

This is stacked on #205, so until that is merged the first two commits here are #205's. The change itself is the last commit, 45d618d.

What changes

  • create_database(), create_database_from_scripts(), create_or_load_database(), database_exists() and load_database() take const std::filesystem::path&.
  • database::directory() and base_engine_library::directory() return std::filesystem::path.
  • v2::engine_library and v3::engine_library: create(), exists() and load() take const std::filesystem::path&.
  • Internally, paths are built with /, and a small path_to_utf8() helper turns them into the UTF-8 strings SQLite expects. path_from_utf8() from Treat path strings as UTF-8 on Windows #205 is gone again.

Track paths stored inside the database are strings, not filesystem paths, so they stay std::string.

For downstream users

This is a clean break: there are no std::string overloads left, since they would make every call with a string literal ambiguous. Passing a std::string still compiles, through the implicit conversion to path. On Windows, though, a narrow string is read in the ANSI code page, so callers holding UTF-8 should construct the path from a std::u8string (or, with Qt, from QString::toStdU16String()). Code that used directory() as a string needs .u8string(), or .string() where the ANSI code page is fine.

The test suite passes (14/14 on Linux). The UTF-8 directory test from #205 now builds its path from a u8"" literal.

@mr-smidge

Copy link
Copy Markdown
Contributor

I haven't done a full review yet, but note that a breaking API change like this will require a version bump to 0.28.0 in CMakeLists.txt.

@mr-smidge mr-smidge left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just left a couple of questions...

Comment thread src/djinterop/util/filesystem.hpp Outdated
namespace djinterop::util
{
/// Converts a UTF-8 encoded path string into a `std::filesystem::path`.
/// Returns a path as a UTF-8 encoded string, on all platforms.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend being very explicit about the return type to avoid any confusion.

e.g. "Returns a path as UTF-8 encoded data in a std::string (note: not std::u8string), on all platforms."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Done in 65ef741, the doc now says it is a std::string (not std::u8string).

Comment on lines 36 to 37
boost::filesystem::path temp_dir{
boost::filesystem::temp_directory_path()};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering... do we actually need boost::filesystem at all now, or can it be removed as a dependency entirely?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std has evolved a lot, would be nice to get rid of boost::filesystem. IMO not in this PR, but I'll investigate and file a PR if it's straightforward enough!

Functions that create, load or test for an Engine library now take the
directory as a std::filesystem::path, and database::directory() returns one.
Callers no longer need to know which encoding a path string is in.
This is a breaking change: there are no std::string overloads left beside them.
Track paths stored inside the database are strings, not filesystem paths, and
stay std::string.
The directory arguments and return values in the public API are now
std::filesystem::path, which breaks source compatibility.
OneLibrary support landed on main with std::string paths, so its
database_impl::directory() no longer matched the base class and the
build broke once this branch was rebased.  Its functions that load,
create or test for a database now take a std::filesystem::path, and
directory() returns one, like the Engine functions.
@sebasje
sebasje force-pushed the seabass/filesystem-path-api branch from 7b82b2e to 4980e21 Compare October 28, 2026 18:57
@sebasje

sebasje commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

I've rebased onto main. OneLibrary support landed with std::string paths, so I added a commit that moves its directory functions to std::filesystem::path as well: database_exists(), load_database(), create_database_from_scripts(), the v1::library equivalents, and directory(). Without it the branch no longer builds. Tests pass with and without SQLCipher.

I've also clarified the path_to_utf8() doc as you suggested.

@sebasje

sebasje commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

✅ Bumped to 0.28.0 in 99bf25f.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants