mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-11-17 10:01:01 +03:00
Improve error message for zfs create with @ or # in name
Reorder the `zfs create` error messages in order to return the most specific one first. If none of them apply then an expanded version of the invalid name message is used. Reviewed by: Tom Caputi <tcaputi@datto.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed by: Matt Ahrens <mahrens@delphix.com> Signed-off-by: Damian Wojsław <damian@wojslaw.pl> Closes #8155 Closes #8352
This commit is contained in:
parent
ba7b05cb25
commit
e065034563
@ -108,6 +108,43 @@ zfs_validate_name(libzfs_handle_t *hdl, const char *path, int type,
|
|||||||
namecheck_err_t why;
|
namecheck_err_t why;
|
||||||
char what;
|
char what;
|
||||||
|
|
||||||
|
if (!(type & ZFS_TYPE_SNAPSHOT) && strchr(path, '@') != NULL) {
|
||||||
|
if (hdl != NULL)
|
||||||
|
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
|
||||||
|
"snapshot delimiter '@' is not expected here"));
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == ZFS_TYPE_SNAPSHOT && strchr(path, '@') == NULL) {
|
||||||
|
if (hdl != NULL)
|
||||||
|
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
|
||||||
|
"missing '@' delimiter in snapshot name, "
|
||||||
|
"did you mean to use -r?"));
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(type & ZFS_TYPE_BOOKMARK) && strchr(path, '#') != NULL) {
|
||||||
|
if (hdl != NULL)
|
||||||
|
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
|
||||||
|
"bookmark delimiter '#' is not expected here"));
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == ZFS_TYPE_BOOKMARK && strchr(path, '#') == NULL) {
|
||||||
|
if (hdl != NULL)
|
||||||
|
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
|
||||||
|
"missing '#' delimiter in bookmark name, "
|
||||||
|
"did you mean to use -r?"));
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modifying && strchr(path, '%') != NULL) {
|
||||||
|
if (hdl != NULL)
|
||||||
|
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
|
||||||
|
"invalid character %c in name"), '%');
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
if (entity_namecheck(path, &why, &what) != 0) {
|
if (entity_namecheck(path, &why, &what) != 0) {
|
||||||
if (hdl != NULL) {
|
if (hdl != NULL) {
|
||||||
switch (why) {
|
switch (why) {
|
||||||
@ -123,7 +160,8 @@ zfs_validate_name(libzfs_handle_t *hdl, const char *path, int type,
|
|||||||
|
|
||||||
case NAME_ERR_EMPTY_COMPONENT:
|
case NAME_ERR_EMPTY_COMPONENT:
|
||||||
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
|
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
|
||||||
"empty component in name"));
|
"empty component or misplaced '@'"
|
||||||
|
" or '#' delimiter in name"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NAME_ERR_TRAILING_SLASH:
|
case NAME_ERR_TRAILING_SLASH:
|
||||||
@ -168,43 +206,6 @@ zfs_validate_name(libzfs_handle_t *hdl, const char *path, int type,
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(type & ZFS_TYPE_SNAPSHOT) && strchr(path, '@') != NULL) {
|
|
||||||
if (hdl != NULL)
|
|
||||||
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
|
|
||||||
"snapshot delimiter '@' is not expected here"));
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == ZFS_TYPE_SNAPSHOT && strchr(path, '@') == NULL) {
|
|
||||||
if (hdl != NULL)
|
|
||||||
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
|
|
||||||
"missing '@' delimiter in snapshot name, "
|
|
||||||
"did you mean to use -r?"));
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(type & ZFS_TYPE_BOOKMARK) && strchr(path, '#') != NULL) {
|
|
||||||
if (hdl != NULL)
|
|
||||||
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
|
|
||||||
"bookmark delimiter '#' is not expected here"));
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == ZFS_TYPE_BOOKMARK && strchr(path, '#') == NULL) {
|
|
||||||
if (hdl != NULL)
|
|
||||||
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
|
|
||||||
"missing '#' delimiter in bookmark name, "
|
|
||||||
"did you mean to use -r?"));
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (modifying && strchr(path, '%') != NULL) {
|
|
||||||
if (hdl != NULL)
|
|
||||||
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
|
|
||||||
"invalid character %c in name"), '%');
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user