When btrfs-image failed to create an image, the invalid output file
had better be deleted to prevent being used mistakenly in the future.
Signed-off-by: Gui Hecheng <guihc.fnst@xxxxxxxxxxxxxx>
---
btrfs-image.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/btrfs-image.c b/btrfs-image.c
index 549722c..b235b87 100644
--- a/btrfs-image.c
+++ b/btrfs-image.c
@@ -2598,8 +2598,16 @@ int main(int argc, char *argv[])
out:
if (out == stdout)
fflush(out);
- else
+ else {
fclose(out);
+ if (ret && create) {
+ ret = unlink(target);
+ if (ret)
+ fprintf(stderr,
+ "unlink output file failed : %s\n",
+ strerror(errno));
+ }
+ }
return !!ret;
}
--
1.8.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html