- /* Make state.directory a complete path without ..s (where possible)
- (Code swiped from Adam Bowen on stackoverflow)
- XXX: couldn't/shouldn't this just be boost::filesystem::canonical?
- */
-
- boost::filesystem::path p (boost::filesystem::system_complete (dir.get()));
- boost::filesystem::path result;
- for (auto i: p) {
- if (i == "..") {
- boost::system::error_code ec;
- if (boost::filesystem::is_symlink(result, ec) || result.filename() == "..") {
- result /= i;
- } else {
- result = result.parent_path ();
- }
- } else if (i != ".") {
- result /= i;
- }
- }
-
- set_directory (result.make_preferred ());