Search code examples
c++c++11boostboost-filesystem

boost::filesystem::create_directory threw a boost::filesystem::filesystem_error: Bad address


The TL;DR of my code is the following:

server::server(boost::filesystem::path mappath) : mappath(mappath) {
    if(boost::filesystem::is_directory(mappath) && boost::filesystem::exists(mappath)) {
        // Do some stuff here
    } else {
        boost::filesystem::create_directory(mappath);
    }
}

The code works when mappath exists (barely, as I find Boost to be segfaulting in almost every function).
However, when it doesn't, it throws an exception with the message "Bad address".
When I print mappath via std::cout, it returns:

"/home/myusername/.testfolder/huni/ENTER YOUR TEXT HERE"

Which is correct.

Note that, when I try printing mappath inside the else statement, it segfaults.
I've deduced that something messes with mappath in either is_directory or exists, as there were no errors when printing before the if statement.


Solution

  • Turned out Bad address is a POSIX-specific error.

    Also the reason I couldn't print mappath in the else clause of my if statement, was that is_directory was messing with the reference.
    What it was actually doing I couldn't figure out.

    So, I've switched from Boost to something that actually works.