Crash when launching RT after last directory selected has been deleted. Issue #131

For some strange reason Gio exceptions are not catched well: inserted a test to verify file existence before accessing it.
This commit is contained in:
ffsup2
2010-07-06 21:37:52 +02:00
parent 6885b6f76a
commit c6a774f821
4 changed files with 16 additions and 9 deletions

View File

@@ -214,7 +214,7 @@ void CacheManager::deleteDir (const Glib::ustring& dirName) {
std::string CacheManager::getMD5 (const Glib::ustring& fname) {
Glib::RefPtr<Gio::File> file = Gio::File::create_for_path (fname);
if (file) {
if (file && file->query_exists()) {
Glib::RefPtr<Gio::FileInfo> info = safe_query_file_info (file);
if (info)
return Glib::Checksum::compute_checksum (Glib::Checksum::CHECKSUM_MD5, Glib::ustring::compose ("%1%2", fname, info->get_size()));

View File

@@ -265,7 +265,6 @@ void DirBrowser::addDir (const Gtk::TreeModel::iterator& iter, const Glib::ustri
child->set_value (1, closedfolder);
Glib::ustring fullname = Glib::build_filename (iter->get_value (dtColumns.dirname), dirname);
child->set_value (dtColumns.dirname, fullname);
Glib::RefPtr<Gio::File> f = Gio::File::create_for_path (fullname);
Gtk::TreeModel::iterator fooRow = dirTreeModel->append(child->children());
fooRow->set_value (dtColumns.filename, Glib::ustring("foo"));
}
@@ -339,7 +338,11 @@ void DirBrowser::open (const Glib::ustring& dirname, const Glib::ustring& fileNa
dirtree->collapse_all ();
Glib::ustring absDirPath = Gio::File::create_for_path(dirname)->get_parse_name ();
Glib::RefPtr<Gio::File> dir = Gio::File::create_for_path(dirname);
if( !dir->query_exists())
return;
Glib::ustring absDirPath = dir->get_parse_name ();
Gtk::TreePath path = expandToDir (absDirPath);
dirtree->scroll_to_row (path);
dirtree->get_selection()->select (path);

View File

@@ -792,8 +792,10 @@ void FileCatalog::on_dir_changed (const Glib::RefPtr<Gio::File>& file, const Gli
void FileCatalog::checkAndAddFile (Glib::RefPtr<Gio::File> file) {
if (!file)
if (!file )
return;
if( !file->query_exists())
return;
Glib::RefPtr<Gio::FileInfo> info = safe_query_file_info(file);
if (info && info->get_file_type() != Gio::FILE_TYPE_DIRECTORY && (!info->is_hidden() || !options.fbShowHidden)) {
int lastdot = info->get_name().find_last_of ('.');
@@ -807,8 +809,10 @@ void FileCatalog::checkAndAddFile (Glib::RefPtr<Gio::File> file) {
void FileCatalog::addAndOpenFile (const Glib::ustring& fname) {
Glib::RefPtr<Gio::File> file = Gio::File::create_for_path (fname);
if (!file)
if (!file )
return;
if( !file->query_exists())
return;
Glib::RefPtr<Gio::FileInfo> info = safe_query_file_info(file);
if( !info )
return;

View File

@@ -81,7 +81,7 @@ void PlacesBrowser::refreshPlacesList () {
// append home directory
Glib::RefPtr<Gio::File> hfile = Gio::File::create_for_path (Glib::get_home_dir ());
if (hfile) {
if (hfile && hfile->query_exists()) {
try {
Glib::RefPtr<Gio::FileInfo> info = safe_query_file_info (hfile);
if (info) {
@@ -97,7 +97,7 @@ void PlacesBrowser::refreshPlacesList () {
// append pictures directory
hfile = Gio::File::create_for_path (Glib::get_user_special_dir (G_USER_DIRECTORY_PICTURES));
if (hfile) {
if (hfile && hfile->query_exists()) {
try {
Glib::RefPtr<Gio::FileInfo> info = safe_query_file_info (hfile);
if (info) {
@@ -191,7 +191,7 @@ void PlacesBrowser::refreshPlacesList () {
}
for (int i=0; i<options.favoriteDirs.size(); i++) {
Glib::RefPtr<Gio::File> hfile = Gio::File::create_for_path (options.favoriteDirs[i]);
if (hfile) {
if (hfile && hfile->query_exists()) {
Glib::RefPtr<Gio::FileInfo> info = safe_query_file_info (hfile);
if (info) {
Gtk::TreeModel::Row newrow = *(placesModel->append());
@@ -274,7 +274,7 @@ void PlacesBrowser::addPressed () {
// append
Glib::RefPtr<Gio::File> hfile = Gio::File::create_for_path (lastSelectedDir);
if (hfile) {
if (hfile && hfile->query_exists()) {
Glib::RefPtr<Gio::FileInfo> info = safe_query_file_info (hfile);
if (info) {
options.favoriteDirs.push_back (hfile->get_parse_name ());