diff options
author | Gui Hecheng <guihc.fnst@cn.fujitsu.com> | 2014-06-24 11:16:45 +0800 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2014-08-22 14:43:10 +0200 |
commit | 792ef0938d2a3a504e7b98ee8118a3de09c78f28 (patch) | |
tree | f8a59be18715b7530af05d77c9364e7a1639c439 /btrfs-image.c | |
parent | 08b0fdced1af19e6c10c94a74ec8fb9e64562def (diff) |
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.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/btrfs-image.c b/btrfs-image.c index 8ad488d5..c03a98d6 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; } |