|
|
|
@ -22,6 +22,9 @@ std::string safe_get_env(const std::string &env) { |
|
|
|
return nullptr==ptr ? "" : std::string(ptr); |
|
|
|
return nullptr==ptr ? "" : std::string(ptr); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Returns home folder, empty on error |
|
|
|
|
|
|
|
*/ |
|
|
|
std::string juci::filesystem::get_home_folder() { |
|
|
|
std::string juci::filesystem::get_home_folder() { |
|
|
|
auto home=safe_get_env("HOME"); |
|
|
|
auto home=safe_get_env("HOME"); |
|
|
|
if(home.empty()) |
|
|
|
if(home.empty()) |
|
|
|
@ -30,11 +33,24 @@ std::string juci::filesystem::get_home_folder() { |
|
|
|
if((status.permissions() & 0222)>=2) { |
|
|
|
if((status.permissions() & 0222)>=2) { |
|
|
|
return home; |
|
|
|
return home; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Singleton::terminal()->print("Invalid permissions. Cannot write in " + home + "\n"); |
|
|
|
JERROR("No write permissions in home, var:"); |
|
|
|
throw new std::exception; |
|
|
|
DEBUG_VAR(home); |
|
|
|
|
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Returns tmp folder, empty on error. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
std::string juci::filesystem::get_tmp_folder() { |
|
|
|
|
|
|
|
boost::system::error_code code; |
|
|
|
|
|
|
|
auto path = boost::filesystem::temp_directory_path(code); |
|
|
|
|
|
|
|
if (code.value()!=0) { |
|
|
|
|
|
|
|
return ""; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return path.string(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int juci::filesystem::read(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { |
|
|
|
int juci::filesystem::read(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { |
|
|
|
std::ifstream input(path, std::ofstream::binary); |
|
|
|
std::ifstream input(path, std::ofstream::binary); |
|
|
|
|
|
|
|
|
|
|
|
|