diff options
author | António Fernandes <antoniof@gnome.org> | 2018-07-31 18:27:28 +0100 |
---|---|---|
committer | Ernestas Kulik <ernestas.kulik@gmail.com> | 2018-08-02 11:40:32 +0000 |
commit | 5198b5e2104f7f7a538c6bd03a50f17561ec2ef7 (patch) | |
tree | 52fdb65044f2be092d34c7f002b5b7a57b43029b /src/nautilus-new-folder-dialog-controller.c | |
parent | 1f77023b5769c773dd9261e5294c0738bf6a3115 (diff) | |
download | nautilus-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-new-folder-dialog-controller.c')
-rw-r--r-- | src/nautilus-new-folder-dialog-controller.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/nautilus-new-folder-dialog-controller.c b/src/nautilus-new-folder-dialog-controller.c index 14d46a5ec..52b6e217b 100644 --- a/src/nautilus-new-folder-dialog-controller.c +++ b/src/nautilus-new-folder-dialog-controller.c @@ -42,30 +42,37 @@ nautilus_new_folder_dialog_controller_name_is_valid (NautilusFileNameWidgetContr 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 = _("Folder names cannot contain “/”."); } else if (strcmp (name, ".") == 0) { + is_valid = FALSE; *error_message = _("A folder cannot be called “.”."); } else if (strcmp (name, "..") == 0) { + is_valid = FALSE; *error_message = _("A folder 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 = _("Folders with “.” at the beginning of their name are hidden."); return TRUE; } - return *error_message == NULL; + return is_valid; } static void |