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. 23
      src/directories.cc
  2. 4
      src/window.cc

23
src/directories.cc

@ -90,9 +90,13 @@ 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.second<boost::filesystem::last_write_time(it->first)) {
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.second<last_write_time) {
update_paths.emplace_back(it->first);
}
it++;
@ -100,10 +104,6 @@ Directories::Directories() : stop_update_thread(false) {
else
it=last_write_times.erase(it);
}
catch(const std::exception &e) {
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<Gtk::TreeNodeChildren> children; //Gtk::TreeNodeChildren is missing default constructor...
if(parent)
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());
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");

Loading…
Cancel
Save