From 5ea52968ead8b5ed573e1e7820d99bddbd9dd534 Mon Sep 17 00:00:00 2001 From: Icarus Sparry Date: Thu, 31 Aug 2017 15:50:35 -0700 Subject: [PATCH] Test a statedir is removed directly Don't use the return value from swupd_rm, which is poorly defined, but test directly that the file no longer exists. Signed-off-by: Icarus Sparry --- src/helpers.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/helpers.c b/src/helpers.c index a89ce615..c3ad0b89 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -152,12 +152,15 @@ static int ensure_root_owned_dir(const char *dirname) /* Oops, not owned by root or * not a directory or wrong perms */ - ret = swupd_rm(state_dir); - if (ret) { + swupd_rm(dirname); + errno = 0; + ret = stat(dirname, &sb); + if ((ret != -1) || (errno != ENOENT)) { fprintf(stderr, - "Error \"%s\" not owned by root" - "but couldn't be deleted\n", - state_dir); + "Error \"%s\" not owned by root, is not a directory, " + "or has the wrong permissions.\n" + "However it couldn't be deleted. stat gives error '%s'\n", + dirname, strerror(errno)); exit(100); } return true; /* doesn't exist now */