From 9d5ab766f6e222526eb5e86bb2cbf2ecc20afd2a Mon Sep 17 00:00:00 2001 From: eidheim Date: Wed, 18 Nov 2015 18:33:39 +0100 Subject: [PATCH] Fixed crashes related to boost::filesystem::exists and ::last_write_time. --- src/directories.cc | 29 ++++++++++++++++++----------- src/window.cc | 4 +++- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/directories.cc b/src/directories.cc index b7e5c7e..1f70846 100644 --- a/src/directories.cc +++ b/src/directories.cc @@ -90,19 +90,19 @@ Directories::Directories() : stop_update_thread(false) { update_mutex.lock(); if(update_paths.size()==0) { for(auto it=last_write_times.begin();it!=last_write_times.end();) { - try { - if(boost::filesystem::exists(it->first)) { //Added for older boost versions (no exception thrown) - if(it->second.secondfirst)) { - update_paths.emplace_back(it->first); - } - it++; + boost::system::error_code ec; + auto exists=boost::filesystem::exists(it->first, ec); + std::time_t last_write_time; + if(!ec && exists) + last_write_time=boost::filesystem::last_write_time(it->first, ec); + if(!ec) { + if(it->second.secondfirst); } - else - it=last_write_times.erase(it); + it++; } - catch(const std::exception &e) { + else it=last_write_times.erase(it); - } } if(update_paths.size()>0) 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) { - 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 children; //Gtk::TreeNodeChildren is missing default constructor... if(parent) children=std::unique_ptr(new Gtk::TreeNodeChildren(parent.children())); diff --git a/src/window.cc b/src/window.cc index b157296..3d8576d 100644 --- a/src/window.cc +++ b/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()); boost::filesystem::path path = Dialog::new_folder(); 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!="") Singleton::directories->update(); Singleton::terminal->print("New folder "+path.string()+" created.\n");