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-rename-file-popover-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-rename-file-popover-controller.c')
-rw-r--r-- | src/nautilus-rename-file-popover-controller.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/nautilus-rename-file-popover-controller.c b/src/nautilus-rename-file-popover-controller.c index f93421c51..e4fd9aa17 100644 --- a/src/nautilus-rename-file-popover-controller.c +++ b/src/nautilus-rename-file-popover-controller.c @@ -106,19 +106,21 @@ nautilus_rename_file_popover_controller_name_is_valid (NautilusFileNameWidgetCon NautilusDirectory *directory; glong max_name_length; size_t name_length; + gboolean is_valid; self = NAUTILUS_RENAME_FILE_POPOVER_CONTROLLER (controller); directory = nautilus_file_get_directory (self->target_file); name_length = strlen (name); max_name_length = nautilus_directory_get_max_child_name_length (directory); + is_valid = TRUE; if (name_length == 0) { - return FALSE; + is_valid = FALSE; } - - if (strstr (name, "/") != NULL) + else if (strstr (name, "/") != NULL) { + is_valid = FALSE; if (self->target_is_folder) { *error_message = _("Folder names cannot contain “/”."); @@ -130,6 +132,7 @@ nautilus_rename_file_popover_controller_name_is_valid (NautilusFileNameWidgetCon } else if (strcmp (name, ".") == 0) { + is_valid = FALSE; if (self->target_is_folder) { *error_message = _("A folder cannot be called “.”."); @@ -141,6 +144,7 @@ nautilus_rename_file_popover_controller_name_is_valid (NautilusFileNameWidgetCon } else if (strcmp (name, "..") == 0) { + is_valid = FALSE; if (self->target_is_folder) { *error_message = _("A folder cannot be called “..”."); @@ -152,6 +156,7 @@ nautilus_rename_file_popover_controller_name_is_valid (NautilusFileNameWidgetCon } else if (name_length > max_name_length + 1 && max_name_length != -1) { + is_valid = FALSE; if (self->target_is_folder) { *error_message = _("Folder name is too long."); @@ -161,8 +166,10 @@ nautilus_rename_file_popover_controller_name_is_valid (NautilusFileNameWidgetCon *error_message = _("File name is too long."); } } - else if (g_str_has_prefix (name, ".")) + + if (is_valid && g_str_has_prefix (name, ".")) { + /* We must warn about the side effect */ if (self->target_is_folder) { *error_message = _("Folders with “.” at the beginning of their name are hidden."); @@ -171,10 +178,9 @@ nautilus_rename_file_popover_controller_name_is_valid (NautilusFileNameWidgetCon { *error_message = _("Files with “.” at the beginning of their name are hidden."); } - return TRUE; } - return *error_message == NULL; + return is_valid; } static gboolean |