diff --git a/genimage.c b/genimage.c index 0be3f5c..6fc7efe 100644 --- a/genimage.c +++ b/genimage.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -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; }