FilePath FilePath::safeCurrentPath(const FilePath& revertToPath) { try { #ifdef _WIN32 return FilePath(boost::filesystem::current_path().wstring()) ; #elif defined(BOOST_FILESYSTEM_VERSION) && BOOST_FILESYSTEM_VERSION != 2 return FilePath(boost::filesystem::current_path().string()) ; #else return FilePath(boost::filesystem::current_path<path_t>().string()) ; #endif } catch(const boost::filesystem::filesystem_error& e) { if (e.code() != boost::system::errc::no_such_file_or_directory) LOG_ERROR(Error(e.code(), ERROR_LOCATION)); } CATCH_UNEXPECTED_EXCEPTION // revert to the specified path if it exists, otherwise // take the user home path from the system FilePath safePath = revertToPath; if (!safePath.exists()) safePath = core::system::userHomePath(); Error error = safePath.makeCurrentPath(); if (error) LOG_ERROR(error); return safePath; }
Error setWorkingDirectory(const json::JsonRpcRequest& request, json::JsonRpcResponse*) { // get the path std::string path; Error error = json::readParam(request.params, 0, &path); if (error) return error; // set current path FilePath filePath = module_context::resolveAliasedPath(path); return filePath.makeCurrentPath(); }
Error restoreWorkingDirectory(const FilePath& userHomePath, const std::string& workingDirectory) { // resolve working dir FilePath workingDirPath = FilePath::resolveAliasedPath(workingDirectory, userHomePath); // restore working path if it exists (else revert to home) if (workingDirPath.exists()) return workingDirPath.makeCurrentPath() ; else return utils::userHomePath().makeCurrentPath(); }