aboutsummaryrefslogtreecommitdiffstats
path: root/btrfs-image.c
diff options
context:
space:
mode:
authorGui Hecheng <guihc.fnst@cn.fujitsu.com>2014-06-24 11:16:45 +0800
committerDavid Sterba <dsterba@suse.cz>2014-08-22 14:43:10 +0200
commit792ef0938d2a3a504e7b98ee8118a3de09c78f28 (patch)
treef8a59be18715b7530af05d77c9364e7a1639c439 /btrfs-image.c
parent08b0fdced1af19e6c10c94a74ec8fb9e64562def (diff)
downloadbtrfs-progs-792ef0938d2a3a504e7b98ee8118a3de09c78f28.tar.gz
btrfs-progs-792ef0938d2a3a504e7b98ee8118a3de09c78f28.tar.xz
btrfs-progs-792ef0938d2a3a504e7b98ee8118a3de09c78f28.zip
btrfs-progs: delete invalid output file when btrfs-image failed
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@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'btrfs-image.c')
-rw-r--r--btrfs-image.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/btrfs-image.c b/btrfs-image.c
index 8ad488d..c03a98d 100644
--- a/btrfs-image.c
+++ b/btrfs-image.c
@@ -2607,10 +2607,20 @@ int main(int argc, char *argv[])
}
out:
- if (out == stdout)
+ if (out == stdout) {
fflush(out);
- else
+ } else {
fclose(out);
+ if (ret && create) {
+ int unlink_ret;
+
+ unlink_ret = unlink(target);
+ if (unlink_ret)
+ fprintf(stderr,
+ "unlink output file failed : %s\n",
+ strerror(errno));
+ }
+ }
return !!ret;
}