From c9c41ddfa90dffffbba8b043b6f4ce7971b87fc3 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Fri, 29 May 2015 14:45:00 +0300 Subject: [PATCH] img: Remove empty lazy images after dump If dump doesn't generate data into some image file the respective file is not created at all as it used to be in 1.5. This brings potential problem -- if the file with the image name exists during dump (e.g. a dump file left from previous, maybe unsuccessful, dump) then restore would pick this file and read bad/wrong/fake data from it. To return the proper behavior back the file with the name of empty image should be removed. Signed-off-by: Pavel Emelyanov --- image.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/image.c b/image.c index bb0edaa04..dc9d6a189 100644 --- a/image.c +++ b/image.c @@ -369,9 +369,15 @@ int open_image_lazy(struct cr_img *img) void close_image(struct cr_img *img) { - if (lazy_image(img)) + if (lazy_image(img)) { + /* + * Remove the image file if it's there so that + * subsequent restore doesn't read wrong or fake + * data from it. + */ + unlinkat(get_service_fd(IMG_FD_OFF), img->path, 0); xfree(img->path); - else if (!empty_image(img)) + } else if (!empty_image(img)) bclose(&img->_x); xfree(img);