lundi 3 septembre 2018

boost::filesystem::current_path() returns empty path

I have a C++ program where I need the current path to later create a folder. The location of my executable is, let's say /home/me/foo/bin. This is what I run:

//Here I expect '/home/me/foo/bin', but get ''
auto currentPath = boost::filesystem::current_path(); 

//Here I expect '/home/me/foo', but get ''
auto parentPath = currentPath.parent_path();

//Here I expect '/home/me/foo/foo2/', but get 'foo2/'
string subFolder    = "foo2";
string folderPath   = parentPath.string() + "/" + subFolder + "/";

//Here I expect to create '/home/me/foo/foo2/', but get a core dump
boost::filesystem::path boostPath{ folderPath};
boost::filesystem::create_directories( boostPath); 

I am running on Ubuntu 16.04, using Boost 1.66 installed with the package manager Conan.

I used to run this successfully with a previous version of Boost (1.45 I believe) without using Conan. Boost was just normally installed on my machine. I now get a core dump when running create_directories( boostPath);.

Two questions:

  1. Why isn't current_path() providing me with the actual path, and returns and empty path instead?
  2. Even if current_path() returned nothing why would I still have a core dump even if I run it with sudo? Wouldn't I simply create the folder(s) at root?

Aucun commentaire:

Enregistrer un commentaire