From 04dda49f3af8f874920195a93d88d51dd47d4549 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Fri, 29 Jul 2011 00:47:39 +0000 Subject: [PATCH] Stricter error handling --- po/de.po | 32 ++++++++++++++++---------------- po/es.po | 32 ++++++++++++++++---------------- po/fr.po | 32 ++++++++++++++++---------------- po/it.po | 32 ++++++++++++++++---------------- src/browser.c | 28 +++++++++++++--------------- src/callbacks.c | 40 +++++++++++++++++++++------------------- src/plugins/cvs.c | 3 ++- 7 files changed, 100 insertions(+), 99 deletions(-) diff --git a/po/de.po b/po/de.po index 24a3f9f..ec9c98f 100644 --- a/po/de.po +++ b/po/de.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Browser 0.1.4\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-07-29 02:45+0200\n" +"POT-Creation-Date: 2011-07-29 02:47+0200\n" "PO-Revision-Date: 2010-03-29 23:28+0200\n" "Last-Translator: Pierre Pronchery \n" "Language-Team: English\n" @@ -702,64 +702,64 @@ msgstr "" msgid "Usage: view file...\n" msgstr "" -#: ../src/plugins/cvs.c:119 ../src/plugins/cvs.c:505 +#: ../src/plugins/cvs.c:120 ../src/plugins/cvs.c:506 msgid "CVS" msgstr "CVS" -#: ../src/plugins/cvs.c:166 +#: ../src/plugins/cvs.c:167 msgid "Root:" msgstr "" -#: ../src/plugins/cvs.c:168 +#: ../src/plugins/cvs.c:169 msgid "Repository:" msgstr "Repository:" -#: ../src/plugins/cvs.c:170 +#: ../src/plugins/cvs.c:171 msgid "Tag:" msgstr "" -#: ../src/plugins/cvs.c:172 ../src/plugins/cvs.c:189 +#: ../src/plugins/cvs.c:173 ../src/plugins/cvs.c:190 msgid "Request diff" msgstr "" -#: ../src/plugins/cvs.c:175 ../src/plugins/cvs.c:192 +#: ../src/plugins/cvs.c:176 ../src/plugins/cvs.c:193 msgid "Update" msgstr "" -#: ../src/plugins/cvs.c:178 ../src/plugins/cvs.c:195 +#: ../src/plugins/cvs.c:179 ../src/plugins/cvs.c:196 msgid "Commit" msgstr "" -#: ../src/plugins/cvs.c:187 +#: ../src/plugins/cvs.c:188 msgid "Revision:" msgstr "" -#: ../src/plugins/cvs.c:202 +#: ../src/plugins/cvs.c:203 msgid "Add to CVS" msgstr "" -#: ../src/plugins/cvs.c:205 +#: ../src/plugins/cvs.c:206 msgid "Run make" msgstr "" -#: ../src/plugins/cvs.c:335 ../src/plugins/cvs.c:404 +#: ../src/plugins/cvs.c:336 ../src/plugins/cvs.c:405 msgid "Not a CVS repository" msgstr "Kein CVS Inhalt" -#: ../src/plugins/cvs.c:427 +#: ../src/plugins/cvs.c:428 msgid "Not managed by CVS" msgstr "" -#: ../src/plugins/cvs.c:549 +#: ../src/plugins/cvs.c:550 msgid "Running command..." msgstr "" -#: ../src/plugins/cvs.c:742 +#: ../src/plugins/cvs.c:743 #, c-format msgid "Command exited with error code %d" msgstr "" -#: ../src/plugins/cvs.c:748 +#: ../src/plugins/cvs.c:749 #, c-format msgid "Command exited with signal %d" msgstr "" diff --git a/po/es.po b/po/es.po index 09c0693..ac5afcf 100644 --- a/po/es.po +++ b/po/es.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Browser 0.1.4\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-07-29 02:45+0200\n" +"POT-Creation-Date: 2011-07-29 02:47+0200\n" "PO-Revision-Date: 2010-03-30 01:04+0200\n" "Last-Translator: Pierre Pronchery \n" "Language-Team: Spanish\n" @@ -702,64 +702,64 @@ msgstr "" msgid "Usage: view file...\n" msgstr "" -#: ../src/plugins/cvs.c:119 ../src/plugins/cvs.c:505 +#: ../src/plugins/cvs.c:120 ../src/plugins/cvs.c:506 msgid "CVS" msgstr "CVS" -#: ../src/plugins/cvs.c:166 +#: ../src/plugins/cvs.c:167 msgid "Root:" msgstr "" -#: ../src/plugins/cvs.c:168 +#: ../src/plugins/cvs.c:169 msgid "Repository:" msgstr "" -#: ../src/plugins/cvs.c:170 +#: ../src/plugins/cvs.c:171 msgid "Tag:" msgstr "" -#: ../src/plugins/cvs.c:172 ../src/plugins/cvs.c:189 +#: ../src/plugins/cvs.c:173 ../src/plugins/cvs.c:190 msgid "Request diff" msgstr "" -#: ../src/plugins/cvs.c:175 ../src/plugins/cvs.c:192 +#: ../src/plugins/cvs.c:176 ../src/plugins/cvs.c:193 msgid "Update" msgstr "" -#: ../src/plugins/cvs.c:178 ../src/plugins/cvs.c:195 +#: ../src/plugins/cvs.c:179 ../src/plugins/cvs.c:196 msgid "Commit" msgstr "" -#: ../src/plugins/cvs.c:187 +#: ../src/plugins/cvs.c:188 msgid "Revision:" msgstr "" -#: ../src/plugins/cvs.c:202 +#: ../src/plugins/cvs.c:203 msgid "Add to CVS" msgstr "" -#: ../src/plugins/cvs.c:205 +#: ../src/plugins/cvs.c:206 msgid "Run make" msgstr "" -#: ../src/plugins/cvs.c:335 ../src/plugins/cvs.c:404 +#: ../src/plugins/cvs.c:336 ../src/plugins/cvs.c:405 msgid "Not a CVS repository" msgstr "" -#: ../src/plugins/cvs.c:427 +#: ../src/plugins/cvs.c:428 msgid "Not managed by CVS" msgstr "" -#: ../src/plugins/cvs.c:549 +#: ../src/plugins/cvs.c:550 msgid "Running command..." msgstr "" -#: ../src/plugins/cvs.c:742 +#: ../src/plugins/cvs.c:743 #, c-format msgid "Command exited with error code %d" msgstr "" -#: ../src/plugins/cvs.c:748 +#: ../src/plugins/cvs.c:749 #, c-format msgid "Command exited with signal %d" msgstr "" diff --git a/po/fr.po b/po/fr.po index d2936a2..5c2bdac 100644 --- a/po/fr.po +++ b/po/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Browser 0.1.4\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-07-29 02:45+0200\n" +"POT-Creation-Date: 2011-07-29 02:47+0200\n" "PO-Revision-Date: 2010-03-29 23:28+0200\n" "Last-Translator: Pierre Pronchery \n" "Language-Team: French\n" @@ -736,64 +736,64 @@ msgstr "Impossible d'éditer le fichier" msgid "Usage: view file...\n" msgstr "Usage: view fichier...\n" -#: ../src/plugins/cvs.c:119 ../src/plugins/cvs.c:505 +#: ../src/plugins/cvs.c:120 ../src/plugins/cvs.c:506 msgid "CVS" msgstr "CVS" -#: ../src/plugins/cvs.c:166 +#: ../src/plugins/cvs.c:167 msgid "Root:" msgstr "Racine :" -#: ../src/plugins/cvs.c:168 +#: ../src/plugins/cvs.c:169 msgid "Repository:" msgstr "Dépôt :" -#: ../src/plugins/cvs.c:170 +#: ../src/plugins/cvs.c:171 msgid "Tag:" msgstr "Tag :" -#: ../src/plugins/cvs.c:172 ../src/plugins/cvs.c:189 +#: ../src/plugins/cvs.c:173 ../src/plugins/cvs.c:190 msgid "Request diff" msgstr "Différences" -#: ../src/plugins/cvs.c:175 ../src/plugins/cvs.c:192 +#: ../src/plugins/cvs.c:176 ../src/plugins/cvs.c:193 msgid "Update" msgstr "Actualiser" -#: ../src/plugins/cvs.c:178 ../src/plugins/cvs.c:195 +#: ../src/plugins/cvs.c:179 ../src/plugins/cvs.c:196 msgid "Commit" msgstr "Soumettre" -#: ../src/plugins/cvs.c:187 +#: ../src/plugins/cvs.c:188 msgid "Revision:" msgstr "Révision :" -#: ../src/plugins/cvs.c:202 +#: ../src/plugins/cvs.c:203 msgid "Add to CVS" msgstr "Ajouter à CVS" -#: ../src/plugins/cvs.c:205 +#: ../src/plugins/cvs.c:206 msgid "Run make" msgstr "Exécuter make" -#: ../src/plugins/cvs.c:335 ../src/plugins/cvs.c:404 +#: ../src/plugins/cvs.c:336 ../src/plugins/cvs.c:405 msgid "Not a CVS repository" msgstr "Pas un dépôt CVS" -#: ../src/plugins/cvs.c:427 +#: ../src/plugins/cvs.c:428 msgid "Not managed by CVS" msgstr "Pas maintenu par CVS" -#: ../src/plugins/cvs.c:549 +#: ../src/plugins/cvs.c:550 msgid "Running command..." msgstr "Exécution en cours..." -#: ../src/plugins/cvs.c:742 +#: ../src/plugins/cvs.c:743 #, c-format msgid "Command exited with error code %d" msgstr "La commande a terminé avec le code d'erreur %d" -#: ../src/plugins/cvs.c:748 +#: ../src/plugins/cvs.c:749 #, c-format msgid "Command exited with signal %d" msgstr "La commande a été terminée par le signal %d" diff --git a/po/it.po b/po/it.po index ccbcf32..2cd447c 100644 --- a/po/it.po +++ b/po/it.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Browser 0.1.4\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-07-29 02:45+0200\n" +"POT-Creation-Date: 2011-07-29 02:47+0200\n" "PO-Revision-Date: 2010-04-07 23:18+0200\n" "Last-Translator: Pierre Pronchery \n" "Language-Team: Italian\n" @@ -702,64 +702,64 @@ msgstr "" msgid "Usage: view file...\n" msgstr "" -#: ../src/plugins/cvs.c:119 ../src/plugins/cvs.c:505 +#: ../src/plugins/cvs.c:120 ../src/plugins/cvs.c:506 msgid "CVS" msgstr "CVS" -#: ../src/plugins/cvs.c:166 +#: ../src/plugins/cvs.c:167 msgid "Root:" msgstr "" -#: ../src/plugins/cvs.c:168 +#: ../src/plugins/cvs.c:169 msgid "Repository:" msgstr "" -#: ../src/plugins/cvs.c:170 +#: ../src/plugins/cvs.c:171 msgid "Tag:" msgstr "" -#: ../src/plugins/cvs.c:172 ../src/plugins/cvs.c:189 +#: ../src/plugins/cvs.c:173 ../src/plugins/cvs.c:190 msgid "Request diff" msgstr "" -#: ../src/plugins/cvs.c:175 ../src/plugins/cvs.c:192 +#: ../src/plugins/cvs.c:176 ../src/plugins/cvs.c:193 msgid "Update" msgstr "" -#: ../src/plugins/cvs.c:178 ../src/plugins/cvs.c:195 +#: ../src/plugins/cvs.c:179 ../src/plugins/cvs.c:196 msgid "Commit" msgstr "" -#: ../src/plugins/cvs.c:187 +#: ../src/plugins/cvs.c:188 msgid "Revision:" msgstr "" -#: ../src/plugins/cvs.c:202 +#: ../src/plugins/cvs.c:203 msgid "Add to CVS" msgstr "" -#: ../src/plugins/cvs.c:205 +#: ../src/plugins/cvs.c:206 msgid "Run make" msgstr "" -#: ../src/plugins/cvs.c:335 ../src/plugins/cvs.c:404 +#: ../src/plugins/cvs.c:336 ../src/plugins/cvs.c:405 msgid "Not a CVS repository" msgstr "" -#: ../src/plugins/cvs.c:427 +#: ../src/plugins/cvs.c:428 msgid "Not managed by CVS" msgstr "" -#: ../src/plugins/cvs.c:549 +#: ../src/plugins/cvs.c:550 msgid "Running command..." msgstr "" -#: ../src/plugins/cvs.c:742 +#: ../src/plugins/cvs.c:743 #, c-format msgid "Command exited with error code %d" msgstr "" -#: ../src/plugins/cvs.c:748 +#: ../src/plugins/cvs.c:749 #, c-format msgid "Command exited with signal %d" msgstr "" diff --git a/src/browser.c b/src/browser.c index e1403ab..aa80781 100644 --- a/src/browser.c +++ b/src/browser.c @@ -261,7 +261,7 @@ Browser * browser_new(char const * directory) if((browser = malloc(sizeof(*browser))) == NULL) { - browser_error(NULL, directory != NULL ? directory : ".", 0); + browser_error(NULL, directory != NULL ? directory : ".", 1); return NULL; } browser->window = NULL; @@ -281,7 +281,7 @@ Browser * browser_new(char const * directory) if((browser->config = config_new()) == NULL || browser_config_load(browser) != 0) browser_error(browser, _("Error while loading configuration"), - 0); + 1); /* mime */ browser->mime = mime_new(NULL); /* FIXME share MIME instances */ @@ -702,7 +702,6 @@ static void _error_response(gpointer data); int browser_error(Browser * browser, char const * message, int ret) { GtkWidget * dialog; - char const * error; #ifdef DEBUG fprintf(stderr, "DEBUG: %s(\"%s\", %d) errno=%d\n", __func__, message, @@ -710,7 +709,6 @@ int browser_error(Browser * browser, char const * message, int ret) #endif if(browser == NULL) return _browser_error(message, ret); - error = strerror(errno); dialog = gtk_message_dialog_new(GTK_WINDOW(browser->window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, @@ -718,7 +716,7 @@ int browser_error(Browser * browser, char const * message, int ret) "%s", _("Error")); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), #endif - "%s: %s", message, error); + "%s", message); gtk_window_set_title(GTK_WINDOW(dialog), _("Error")); if(ret < 0) { @@ -735,8 +733,7 @@ int browser_error(Browser * browser, char const * message, int ret) static int _browser_error(char const * message, int ret) { - fputs("browser: ", stderr); - perror(message); + fprintf(stderr, "%s: %s", "browser", message); return ret; } @@ -944,13 +941,13 @@ void browser_open_with(Browser * browser, char const * path) if(filename == NULL) return; if((pid = fork()) == -1) - browser_error(browser, "fork", 0); + browser_error(browser, strerror(errno), 1); else if(pid == 0) { if(close(0) != 0) - browser_error(NULL, "stdin", 0); + browser_error(NULL, strerror(errno), 0); execlp(filename, filename, path, NULL); - browser_error(NULL, filename, 0); + browser_error(NULL, strerror(errno), 0); exit(2); } g_free(filename); @@ -970,7 +967,7 @@ void browser_refresh(Browser * browser) if(browser->current == NULL) return; if((dir = _browser_opendir(browser->current->data, &st)) == NULL) - browser_error(browser, browser->current->data, 0); + browser_error(browser, strerror(errno), 1); else _browser_refresh_do(browser, dir, &st); } @@ -1028,7 +1025,7 @@ static int _refresh_new_loop(Browser * browser) if((path = g_build_filename(browser->current->data, de->d_name, NULL)) == NULL || lstat(path, &lst) != 0) { - browser_error(NULL, de->d_name, 0); + browser_error(NULL, strerror(errno), 1); if(path != NULL) g_free(path); return 0; @@ -1341,7 +1338,8 @@ static gboolean _done_timeout(gpointer data) if(stat(browser->current->data, &st) != 0) { browser->refresh_id = 0; - return browser_error(NULL, browser->current->data, FALSE); + browser_error(NULL, strerror(errno), 1); + return FALSE; } if(st.st_mtime == browser->refresh_mti) return TRUE; @@ -1402,7 +1400,7 @@ static int _current_loop(Browser * browser) if((path = g_build_filename(browser->current->data, de->d_name, NULL)) == NULL || lstat(path, &lst) != 0) { - browser_error(NULL, de->d_name, 0); + browser_error(NULL, strerror(errno), 1); if(path != NULL) g_free(path); return 0; @@ -1553,7 +1551,7 @@ void browser_set_location(Browser * browser, char const * path) } else /* XXX errno may not be set */ - browser_error(browser, realpath, 0); + browser_error(browser, strerror(errno), 1); free(realpath); } diff --git a/src/callbacks.c b/src/callbacks.c index 1ed1334..c1d8a00 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -122,12 +122,12 @@ void on_file_new_folder(gpointer data) len = strlen(cur) + strlen(newfolder) + 2; if((path = malloc(len)) == NULL) { - browser_error(browser, "malloc", 0); + browser_error(browser, strerror(errno), 1); return; } snprintf(path, len, "%s/%s", cur, newfolder); if(mkdir(path, 0777) != 0) - browser_error(browser, path, 0); + browser_error(browser, strerror(errno), 1); free(path); } @@ -138,7 +138,7 @@ void on_file_new_symlink(gpointer data) char const * cur = browser->current->data; if(_common_symlink(browser->window, cur) != 0) - browser_error(browser, "symlink", 0); + browser_error(browser, strerror(errno), 1); } @@ -205,7 +205,7 @@ void on_edit_delete(gpointer data) } if(res == GTK_RESPONSE_YES && _common_exec("delete", "-ir", selection) != 0) - browser_error(browser, "fork", 0); + browser_error(browser, strerror(errno), 1); g_list_foreach(selection, (GFunc)free, NULL); g_list_free(selection); } @@ -405,7 +405,7 @@ void on_properties(gpointer data) if((selection = _copy_selection(browser)) == NULL) selection = g_list_append(NULL, strdup(browser->current->data)); if(_common_exec("properties", NULL, selection) != 0) - browser_error(browser, "fork", 0); + browser_error(browser, strerror(errno), 1); g_list_foreach(selection, (GFunc)free, NULL); g_list_free(selection); } @@ -544,7 +544,7 @@ void on_filename_edited(GtkCellRendererText * renderer, gchar * arg1, { q = g_filename_from_utf8(p, -1, NULL, NULL, NULL); if(rename(path, (q != NULL) ? q : p) != 0) - browser_error(browser, path, 0); + browser_error(browser, strerror(errno), 1); else gtk_list_store_set(browser->store, &iter, BR_COL_PATH, p, BR_COL_DISPLAY_NAME, arg2, -1); @@ -553,11 +553,11 @@ void on_filename_edited(GtkCellRendererText * renderer, gchar * arg1, else if(lstat(path, &st) == 0 && S_ISLNK(st.st_mode)) { if(rename(path, p) != 0) - browser_error(browser, path, 0); + browser_error(browser, strerror(errno), 1); } /* FIXME implement workaround for FAT */ else if(link(path, p) != 0 || unlink(path) != 0) - browser_error(browser, path, 0); + browser_error(browser, strerror(errno), 1); free(p); free(path); } @@ -618,7 +618,7 @@ void on_view_drag_data_received(GtkWidget * widget, GdkDragContext * context, BR_COL_PATH, &dest, -1); } if(_common_drag_data_received(context, seldata, dest) != 0) - browser_error(browser, "fork", 0); + browser_error(browser, strerror(errno), 1); } #endif /* GTK_CHECK_VERSION(2, 8, 0) */ @@ -831,12 +831,12 @@ static void _on_popup_new_text_file(gpointer data) len = strlen(cur) + strlen(newtext) + 2; if((path = malloc(len)) == NULL) { - browser_error(browser, "malloc", 0); + browser_error(browser, strerror(errno), 1); return; } snprintf(path, len, "%s/%s", cur, newtext); if((fd = creat(path, 0666)) < 0) - browser_error(browser, path, 0); + browser_error(browser, strerror(errno), 1); else close(fd); free(path); @@ -1034,13 +1034,12 @@ static void _on_icon_run(gpointer data) dialog = gtk_message_dialog_new(GTK_WINDOW(cb->browser->window), GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, - GTK_BUTTONS_YES_NO, "%s", + GTK_BUTTONS_YES_NO, #if GTK_CHECK_VERSION(2, 6, 0) - _("Warning")); + "%s", _("Warning")); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), - "%s", #endif - _("Are you sure you want to execute this file?")); + "%s", _("Are you sure you want to execute this file?")); gtk_window_set_title(GTK_WINDOW(dialog), _("Warning")); res = gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); @@ -1048,7 +1047,10 @@ static void _on_icon_run(gpointer data) return; argv[0] = cb->path; if(g_spawn_async(NULL, argv, NULL, 0, NULL, NULL, NULL, &error) != TRUE) - browser_error(cb->browser, cb->path, 1); + { + browser_error(cb->browser, error->message, 1); + g_error_free(error); + } } static void _on_icon_open_with(gpointer data) @@ -1080,7 +1082,7 @@ static void _on_icon_unmount(gpointer data) #else if(unmount(cb->path, 0) != 0) #endif - browser_error(cb->browser, cb->path, 0); + browser_error(cb->browser, strerror(errno), 1); } @@ -1132,12 +1134,12 @@ static void _paste_selection(Browser * browser) if(browser->selection_cut != 1) { if(_common_exec("copy", "-ir", browser->selection) != 0) - browser_error(browser, "fork", 0); + browser_error(browser, strerror(errno), 1); browser->selection = g_list_remove(browser->selection, p); return; } if(_common_exec("move", "-i", browser->selection) != 0) - browser_error(browser, "fork", 0); + browser_error(browser, strerror(errno), 1); browser->selection = g_list_remove(browser->selection, p); g_list_foreach(browser->selection, (GFunc)free, NULL); g_list_free(browser->selection); diff --git a/src/plugins/cvs.c b/src/plugins/cvs.c index 0911d47..b794335 100644 --- a/src/plugins/cvs.c +++ b/src/plugins/cvs.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "Browser.h" #define _(string) gettext(string) @@ -479,7 +480,7 @@ static int _cvs_add_task(BrowserPlugin * plugin, char const * title, GtkWidget * widget; if((p = realloc(cvs->tasks, sizeof(*p) * (cvs->tasks_cnt + 1))) == NULL) - return -helper->error(helper->browser, "malloc", 1); + return -helper->error(helper->browser, strerror(errno), 1); cvs->tasks = p; if((task = object_new(sizeof(*task))) == NULL) return -helper->error(helper->browser, error_get(), 1);