Browse Source

Always ask for confirmation before overwriting.

Make sure the decrypt task behaves as the encrypt task regarding
the overwriting of an existing file, when using the default
output filename.
master
parent
commit
4c496aea11
  1. 2
      src/Makefile.am
  2. 4
      src/decrypt.c
  3. 26
      src/encrypt.c
  4. 48
      src/util.c
  5. 33
      src/util.h

2
src/Makefile.am

@ -3,7 +3,7 @@ bin_PROGRAMS = yki
yki_SOURCES = yki.c gpgutil.c gpgutil.h error.c error.h errors.h \
encrypt.c encrypt.h yki-encrypt.ui \
decrypt.c decrypt.h yki-decrypt.ui \
resources.xml
util.c util.h resources.xml
nodist_yki_SOURCES = resources.c

4
src/decrypt.c

@ -31,6 +31,7 @@
#include "error.h"
#include "gpgutil.h"
#include "util.h"
@ -292,6 +293,9 @@ yki_decrypt(gpgme_ctx_t gpgme, const char *file, GError **error)
ret = gtk_dialog_run(dlg) == GTK_RESPONSE_OK;
}
if ( ret && g_file_test(yki.output_filename, G_FILE_TEST_EXISTS) && ! yki.output_filename_userset )
ret = yki_confirm_overwrite(yki.output_filename);
if ( ret )
ret = write_decrypted_output(&out, yki.output_filename, error);

26
src/encrypt.c

@ -29,6 +29,7 @@
#include "error.h"
#include "gpgutil.h"
#include "util.h"
@ -223,29 +224,6 @@ create_encrypt_dialog(yki_encrypt_data_t *yki)
return GTK_DIALOG(gtk_builder_get_object(builder, "dlgEncrypt"));
}
static int
confirm_overwrite(GtkWindow *parent, yki_encrypt_data_t *yki)
{
GtkWidget *dlg;
int ret;
dlg = gtk_message_dialog_new(parent, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
"A file name \"%s\" already exists. "
"Do you want to replace it?", yki->output_basename);
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dlg),
"Replacing it will overwrite its contents.");
gtk_dialog_add_buttons(GTK_DIALOG(dlg),
"Cancel", GTK_RESPONSE_CANCEL,
"Replace", GTK_RESPONSE_OK,
NULL);
ret = gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_OK;
gtk_widget_destroy(dlg);
return ret;
}
/* Dealing with public keys. */
@ -382,7 +360,7 @@ yki_encrypt(gpgme_ctx_t gpgme, const char *file, GError **error)
/* Check with user before overwriting a file with the default filename. */
if ( g_file_test(yki.output_filename, G_FILE_TEST_EXISTS) && ! yki.output_filename_userset )
ret = confirm_overwrite(GTK_WINDOW(dlg), &yki);
ret = yki_confirm_overwrite(yki.output_filename);
if ( ret )
ret = gpgutil_open_file(file, "r", &in, error);

48
src/util.c

@ -0,0 +1,48 @@
/*
* Yorkie - A task-oriented GnuPG frontend
* Copyright (C) 2020 Damien Goutte-Gattat
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "util.h"
#include <gtk/gtk.h>
int
yki_confirm_overwrite(const char *filename)
{
GtkWidget *dlg;
int ret;
dlg = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
"A file named \"%s\" already exists. "
"Do you want to replace it?", filename);
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dlg),
"Replacing it will overwrite its contents.");
gtk_dialog_add_buttons(GTK_DIALOG(dlg),
"Cancel", GTK_RESPONSE_CANCEL,
"Replace", GTK_RESPONSE_OK,
NULL);
ret = gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_OK;
gtk_widget_destroy(dlg);
return ret;
}

33
src/util.h

@ -0,0 +1,33 @@
/*
* Yorkie - A task-oriented GnuPG frontend
* Copyright (C) 2020 Damien Goutte-Gattat
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ICP20200509_UTIL_H
#define ICP20200509_UTIL_H
#ifdef __cpluscplus
extern "C" {
#endif
int
yki_confirm_overwrite(const char *);
#ifdef __cplusplus
}
#endif
#endif /* !ICP20200509_UTIL_H */
Loading…
Cancel
Save