summaryrefslogtreecommitdiff
path: root/src/nautilus-compress-dialog-controller.c
diff options
context:
space:
mode:
authorAntónio Fernandes <antoniof@gnome.org>2018-07-31 18:27:28 +0100
committerErnestas Kulik <ernestas.kulik@gmail.com>2018-08-02 11:40:32 +0000
commit5198b5e2104f7f7a538c6bd03a50f17561ec2ef7 (patch)
tree52fdb65044f2be092d34c7f002b5b7a57b43029b /src/nautilus-compress-dialog-controller.c
parent1f77023b5769c773dd9261e5294c0738bf6a3115 (diff)
downloadnautilus-5198b5e2104f7f7a538c6bd03a50f17561ec2ef7.tar.gz
file-name-widget: Clarify logic in name_is_valid()
We rely on the presence of an error_message to decide whether the name is valid. However, this is misleading, because we can have an invalid name with no error_message (the empty name case), and we can have a valid name with an error_message (the dotfile case), requiring 2 early returns. Instead, use an explicit return variable.
Diffstat (limited to 'src/nautilus-compress-dialog-controller.c')
-rw-r--r--src/nautilus-compress-dialog-controller.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/nautilus-compress-dialog-controller.c b/src/nautilus-compress-dialog-controller.c
index fc8264d26..d551c37bc 100644
--- a/src/nautilus-compress-dialog-controller.c
+++ b/src/nautilus-compress-dialog-controller.c
@@ -49,29 +49,36 @@ nautilus_compress_dialog_controller_name_is_valid (NautilusFileNameWidgetControl
gchar *name,
gchar **error_message)
{
+ gboolean is_valid;
+
+ is_valid = TRUE;
if (strlen (name) == 0)
{
- return FALSE;
+ is_valid = FALSE;
}
-
- if (strstr (name, "/") != NULL)
+ else if (strstr (name, "/") != NULL)
{
+ is_valid = FALSE;
*error_message = _("Archive names cannot contain “/”.");
}
else if (strcmp (name, ".") == 0)
{
+ is_valid = FALSE;
*error_message = _("An archive cannot be called “.”.");
}
else if (strcmp (name, "..") == 0)
{
+ is_valid = FALSE;
*error_message = _("An archive cannot be called “..”.");
}
- else if (g_str_has_prefix (name, "."))
+
+ if (is_valid && g_str_has_prefix (name, "."))
{
+ /* We must warn about the side effect */
*error_message = _("Archives with “.” at the beginning of their name are hidden.");
- return TRUE;
}
- return *error_message == NULL;
+
+ return is_valid;
}
static gchar *