From 390f6456f27722af2a4bf9b35e8a9a3d83f402b7 Mon Sep 17 00:00:00 2001 From: palage4a Date: Thu, 17 Aug 2023 18:18:56 +0300 Subject: [PATCH] fix rmtree --- cartridge/clusterwide-config.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cartridge/clusterwide-config.c b/cartridge/clusterwide-config.c index c74a4754e..1be64bf3d 100644 --- a/cartridge/clusterwide-config.c +++ b/cartridge/clusterwide-config.c @@ -46,20 +46,25 @@ static int rmtree(const char *path) { if(strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; + char tmp_path[512]; + sprintf(tmp_path, "%s/%s", path, ep->d_name); if(ep->d_type == DT_DIR) { - char tmp_path[512]; - sprintf(tmp_path, "%s/%s", path, ep->d_name); - if(rmtree((const char*)tmp_path) == -1) { - say_error("%s: %s", path, strerror(errno)); + int rc = rmtree((const char*)tmp_path); + if(rc == -1) { + say_error("%s: %s", tmp_path, strerror(errno)); return -1; } } else { - if(remove(path) == -1) { - say_error("%s:%s", path, strerror(errno)); + if(unlink(tmp_path) == -1) { + say_error("%s: %s", path, strerror(errno)); return -1; } } } + if(rmdir(path) == -1) { + say_error("%s: %s", path, strerror(errno)); + return -1; + } closedir(dp); } return 0;