Browse Source

Fixed crashes related to boost::filesystem::exists and ::last_write_time.

merge-requests/365/head
eidheim 10 years ago
parent
commit
9d5ab766f6
  1. 29
      src/directories.cc
  2. 4
      src/window.cc

29
src/directories.cc

@ -90,19 +90,19 @@ Directories::Directories() : stop_update_thread(false) {
update_mutex.lock(); update_mutex.lock();
if(update_paths.size()==0) { if(update_paths.size()==0) {
for(auto it=last_write_times.begin();it!=last_write_times.end();) { for(auto it=last_write_times.begin();it!=last_write_times.end();) {
try { boost::system::error_code ec;
if(boost::filesystem::exists(it->first)) { //Added for older boost versions (no exception thrown) auto exists=boost::filesystem::exists(it->first, ec);
if(it->second.second<boost::filesystem::last_write_time(it->first)) { std::time_t last_write_time;
update_paths.emplace_back(it->first); if(!ec && exists)
} last_write_time=boost::filesystem::last_write_time(it->first, ec);
it++; if(!ec) {
if(it->second.second<last_write_time) {
update_paths.emplace_back(it->first);
} }
else it++;
it=last_write_times.erase(it);
} }
catch(const std::exception &e) { else
it=last_write_times.erase(it); it=last_write_times.erase(it);
}
} }
if(update_paths.size()>0) if(update_paths.size()>0)
update_dispatcher(); update_dispatcher();
@ -198,7 +198,14 @@ void Directories::select(const boost::filesystem::path &path) {
} }
void Directories::add_path(const boost::filesystem::path& dir_path, const Gtk::TreeModel::Row &parent) { void Directories::add_path(const boost::filesystem::path& dir_path, const Gtk::TreeModel::Row &parent) {
last_write_times[dir_path.string()]={parent, boost::filesystem::last_write_time(dir_path)}; boost::system::error_code ec;
auto exists=boost::filesystem::exists(dir_path, ec);
if(ec || !exists)
return;
auto last_write_time=boost::filesystem::last_write_time(dir_path, ec);
if(ec)
return;
last_write_times[dir_path.string()]={parent, last_write_time};
std::unique_ptr<Gtk::TreeNodeChildren> children; //Gtk::TreeNodeChildren is missing default constructor... std::unique_ptr<Gtk::TreeNodeChildren> children; //Gtk::TreeNodeChildren is missing default constructor...
if(parent) if(parent)
children=std::unique_ptr<Gtk::TreeNodeChildren>(new Gtk::TreeNodeChildren(parent.children())); children=std::unique_ptr<Gtk::TreeNodeChildren>(new Gtk::TreeNodeChildren(parent.children()));

4
src/window.cc

@ -172,7 +172,9 @@ void Window::set_menu_actions() {
auto time_now=std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); auto time_now=std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
boost::filesystem::path path = Dialog::new_folder(); boost::filesystem::path path = Dialog::new_folder();
if(path!="" && boost::filesystem::exists(path)) { if(path!="" && boost::filesystem::exists(path)) {
if(boost::filesystem::last_write_time(path)>=time_now) { boost::system::error_code ec;
auto last_write_time=boost::filesystem::last_write_time(path, ec);
if(!ec && last_write_time>=time_now) {
if(Singleton::directories->current_path!="") if(Singleton::directories->current_path!="")
Singleton::directories->update(); Singleton::directories->update();
Singleton::terminal->print("New folder "+path.string()+" created.\n"); Singleton::terminal->print("New folder "+path.string()+" created.\n");

Loading…
Cancel
Save