Skip to content

Commit

Permalink
libsemanage: simplify file deletion
Browse files Browse the repository at this point in the history
Instead of checking if a file to be deleted exists, just try to delete
it and ignore any error for it not existing in the first place.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
  • Loading branch information
cgzones authored and bachradsusi committed Nov 27, 2024
1 parent 2cc2d1e commit d3a5ae3
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions libsemanage/src/direct_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2762,7 +2762,6 @@ static int semanage_direct_install_info(semanage_handle_t *sh,
int status = 0;
int ret = 0;
int type;
struct stat sb;

char path[PATH_MAX];
mode_t mask = umask(0077);
Expand Down Expand Up @@ -2863,13 +2862,11 @@ static int semanage_direct_install_info(semanage_handle_t *sh,
goto cleanup;
}

if (stat(path, &sb) == 0) {
ret = unlink(path);
if (ret != 0) {
ERR(sh, "Error while removing cached CIL file %s.", path);
status = -3;
goto cleanup;
}
ret = unlink(path);
if (ret != 0 && errno != ENOENT) {
ERR(sh, "Error while removing cached CIL file %s.", path);
status = -3;
goto cleanup;
}
}

Expand Down Expand Up @@ -2966,13 +2963,10 @@ static int semanage_direct_remove_key(semanage_handle_t *sh,
goto cleanup;
}

struct stat sb;
if (stat(path, &sb) == 0) {
ret = unlink(path);
if (ret != 0) {
status = -1;
goto cleanup;
}
ret = unlink(path);
if (ret != 0 && errno != ENOENT) {
status = -1;
goto cleanup;
}
}
else {
Expand Down

0 comments on commit d3a5ae3

Please sign in to comment.