From 74b3eb1db015fce921e0d450a66e13af2edec99f Mon Sep 17 00:00:00 2001 From: Peter Schiffer Date: Thu, 16 May 2013 17:10:32 +0200 Subject: [PATCH] Make cg_mkdir_p() function compatible with read-only fs mkdir(2) function returns EROFS error even when the path already exists on the read only file system, so it is impossible to determine whether the path already exists on this kind of fs only be return code from the mkdir(2). To make cg_mkdir_p() compatible with the ro fs, the function checks whether the path exists with stat(2) before trying to create it. Signed-off-by: Peter Schiffer Acked-By: Jan Safranek --- src/api.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/api.c b/src/api.c index ee18797b..c4204750 100644 --- a/src/api.c +++ b/src/api.c @@ -1292,7 +1292,8 @@ int cg_mkdir_p(const char *path) char *real_path = NULL; int i = 0; char pos; - int ret = 0; + int ret = 0, stat_ret; + struct stat st; real_path = strdup(path); if (!real_path) { @@ -1320,6 +1321,14 @@ int cg_mkdir_p(const char *path) ret = ECGROUPNOTOWNER; goto done; default: + /* Check if path exists */ + real_path[i] = '\0'; + stat_ret = stat(real_path, &st); + real_path[i] = pos; + if (stat_ret == 0) { + ret = 0; /* Path exists */ + break; + } ret = ECGROUPNOTALLOWED; goto done; } -- 2.47.2