Skip to content

Commit 7ee1327

Browse files
committed
refactor(common): rename ocre_is_valid_id to ocre_is_valid_name
As this will check if a user specified name is valid or not. In the future we will want the container name to be unrelated from the ID, so we take the change to rename and decouple it here, now. Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
1 parent 0aa6cca commit 7ee1327

7 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/common/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <ctype.h>
33
#include <string.h>
44

5-
int ocre_is_valid_id(const char *id)
5+
int ocre_is_valid_name(const char *id)
66
{
77
/* Cannot be NULL */
88

src/common/include/ocre/common.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
#define OCRE_COMMON_H
1010

1111
/**
12-
* @brief Check if a container or image ID is valid
12+
* @brief Check if a container or image names is valid
1313
* @memberof ocre_context
1414
*
15-
* Checks if a container or image ID is valid. A valid container or image ID must not be NULL, empty, or start with a
16-
* dot '.'. It can only contain alphanumeric characters, dots, underscores, and hyphens.
15+
* Checks if a container or image name is valid. A valid container or image name must not be NULL, empty, or start with
16+
* a dot '.'. It can only contain alphanumeric characters, dots, underscores, and hyphens.
1717
*
1818
* @param id A pointer to the container or image ID to check
1919
*
2020
* @return Zero if invalid, 1 if valid
2121
*/
22-
int ocre_is_valid_id(const char *id);
22+
int ocre_is_valid_name(const char *id);
2323

2424
#endif /* OCRE_COMMON_H */

src/ocre/context.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ struct ocre_container *ocre_context_create_container(struct ocre_context *contex
187187

188188
/* Check if the provided container ID is valid */
189189

190-
if (container_id && !ocre_is_valid_id(container_id)) {
190+
if (container_id && !ocre_is_valid_name(container_id)) {
191191
LOG_ERR("Invalid characters in container ID '%s'. Valid are [a-z0-9_-.] (lowercase alphanumeric) and "
192192
"cannot start with '.'",
193193
container_id);
@@ -196,7 +196,7 @@ struct ocre_container *ocre_context_create_container(struct ocre_context *contex
196196

197197
/* Check if the provided image ID is valid */
198198

199-
if (!image || !ocre_is_valid_id(image)) {
199+
if (!image || !ocre_is_valid_name(image)) {
200200
LOG_ERR("Invalid characters in image ID '%s'. Valid are [a-z0-9_-.] (lowercase alphanumeric) and "
201201
"cannot start with '.'",
202202
image);

src/shell/container/create.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ int cmd_container_create_run(struct ocre_context *ctx, const char *argv0, int ar
8181

8282
/* Check if the provided container ID is valid */
8383

84-
if (optarg && !ocre_is_valid_id(optarg)) {
84+
if (optarg && !ocre_is_valid_name(optarg)) {
8585
fprintf(stderr,
8686
"Invalid characters in container ID '%s'. Valid are [a-z0-9_-.] "
8787
"(lowercase alphanumeric) and cannot start with '.'\n",
@@ -200,7 +200,7 @@ int cmd_container_create_run(struct ocre_context *ctx, const char *argv0, int ar
200200

201201
/* Check if the provided image ID is valid */
202202

203-
if (argv[optind] && !ocre_is_valid_id(argv[optind])) {
203+
if (argv[optind] && !ocre_is_valid_name(argv[optind])) {
204204
fprintf(stderr,
205205
"Invalid characters in image ID '%s'. Valid are [a-z0-9_-.] (lowercase alphanumeric) and "
206206
"cannot start with '.'",

src/shell/image/ls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ int cmd_image_ls(struct ocre_context *ctx, const char *argv0, int argc, char **a
124124

125125
/* Check if the provided image ID is valid */
126126

127-
if (argv[1] && !ocre_is_valid_id(argv[1])) {
127+
if (argv[1] && !ocre_is_valid_name(argv[1])) {
128128
fprintf(stderr,
129129
"Invalid characters in image ID '%s'. Valid are [a-z0-9_-.] (lowercase "
130130
"alphanumeric) and cannot start with '.'\n",

src/shell/image/pull.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int cmd_image_pull(struct ocre_context *ctx, const char *argv0, int argc, char *
5454

5555
/* Check if the provided image ID is valid */
5656

57-
if (!ocre_is_valid_id(local_name)) {
57+
if (!ocre_is_valid_name(local_name)) {
5858
fprintf(stderr,
5959
"Invalid characters in image ID '%s'. Valid are [a-z0-9_-.] (lowercase "
6060
"alphanumeric) and cannot start with '.'\n",

src/shell/image/rm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int cmd_image_rm(struct ocre_context *ctx, const char *argv0, int argc, char **a
2626
if (argc == 2) {
2727
/* Check if the provided image ID is valid */
2828

29-
if (argv[1] && !ocre_is_valid_id(argv[1])) {
29+
if (argv[1] && !ocre_is_valid_name(argv[1])) {
3030
fprintf(stderr,
3131
"Invalid characters in image ID '%s'. Valid are [a-z0-9_-.] (lowercase "
3232
"alphanumeric) and cannot start with '.'\n",

0 commit comments

Comments
 (0)