Skip to content

Commit

Permalink
rmtree in lua
Browse files Browse the repository at this point in the history
  • Loading branch information
palage4a committed Aug 18, 2023
1 parent 05fabef commit 5566f19
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
14 changes: 3 additions & 11 deletions cartridge/clusterwide-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,29 +110,21 @@ static int cw_save(char* path, char* random_path, char** sections_k, char** sect
if(mktree(_dirname) == -1) {
say_error("mktree() error: %s: %s", _dirname, strerror(errno));
sprintf(err, "%s: %s", _dirname, strerror(errno));
goto rollback;
return -1;
}
if(file_write(abspath, sections_v[i]) == -1) {
say_error("file_write() error: %s: %s", abspath, strerror(errno));
sprintf(err, "%s: %s", abspath, strerror(errno));
goto rollback;
return -1;
}
}

if(rename(random_path, path) == -1) {
say_error("rename() error: %s: %s", path, strerror(errno));
sprintf(err, "%s: %s", path, strerror(errno));
goto rollback;
return -1;
}

say_verbose("%s has renamed to %s", random_path, path);
goto exit;
rollback:
if(rmtree(random_path) == -1) {
say_warn("remove() error: %s: %s", path, strerror(errno));
}
return -1;
exit:
return 0;
}

Expand Down
7 changes: 7 additions & 0 deletions cartridge/clusterwide-config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,13 @@ local function save(clusterwide_config, path)
end
local rc, err = internal.save(path, random_path, sections_k, sections_v)
if not rc and err then
local ok, rm_err = fio.rmtree(random_path)
if not ok then
log.warn(
"Error removing %s: %s",
random_path, rm_err
)
end
return nil, SaveConfigError:new(err)
end
return true
Expand Down

0 comments on commit 5566f19

Please sign in to comment.