genimage: only delete regular files and symlinks

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
This commit is contained in:
Michael Olbrich 2018-12-17 13:46:01 +01:00
parent 8687e9c639
commit 86b76c6d43

View File

@ -20,6 +20,7 @@
#include <string.h>
#include <errno.h>
#include <libgen.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <dirent.h>
@ -231,7 +232,11 @@ static int image_generate(struct image *image)
}
if (ret) {
systemp(image, "rm -f \"%s\"", imageoutfile(image));
struct stat s;
if (lstat(imageoutfile(image), &s) != 0 ||
((s.st_mode & S_IFMT) == S_IFREG) ||
((s.st_mode & S_IFMT) == S_IFLNK))
systemp(image, "rm -f \"%s\"", imageoutfile(image));
return ret;
}