Skip to content

Commit

Permalink
do rollback in lua instead of C
Browse files Browse the repository at this point in the history
  • Loading branch information
palage4a committed Aug 21, 2023
1 parent 64ca166 commit 348bf9e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
11 changes: 2 additions & 9 deletions cartridge/clusterwide-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,17 @@ static int cw_save(char* path, char* random_path, char** sections_k, char** sect
if(file_write(tmp_path, sections_v[i]) == -1) {
say_error("file_write() error: %s", strerror(errno));
sprintf(err, "%s: %s", tmp_path, strerror(errno));
goto rollback;
return -1;
}
}

if(rename(random_path, path) == -1) {
say_error("rename() error: %s", 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(remove(random_path) == -1) {
say_warn("remove error: %s, path: %s", strerror(errno), random_path);
}
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 ok, err = internal.save(path, random_path, sections_k, sections_v)
if not ok and err then
local _, rm_err = fio.rmtree(random_path)
if rm_err then
log.warn(
"Error removing %s: %s",
random_path, err
)
end
return nil, SaveConfigError:new("%s: %s", path, err)
end
return true
Expand Down

0 comments on commit 348bf9e

Please sign in to comment.