summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2018-12-17 13:46:01 +0100
committerMichael Olbrich <m.olbrich@pengutronix.de>2019-03-01 16:38:16 +0100
commit86b76c6d43a3ea87c00235f2961d71002d4c4792 (patch)
treed3bd847e213ea1beb01fb3d56269bff8c880eafd
parent8687e9c639621e1de65297cb7d56335b2add7701 (diff)
downloadgenimage-86b76c6d43a3ea87c00235f2961d71002d4c4792.tar.gz
genimage-86b76c6d43a3ea87c00235f2961d71002d4c4792.tar.xz
genimage: only delete regular files and symlinks
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rw-r--r--genimage.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/genimage.c b/genimage.c
index 0be3f5c..6fc7efe 100644
--- a/genimage.c
+++ b/genimage.c
@@ -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;
}