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>
This commit is contained in:
Gui Hecheng 2014-06-24 11:16:45 +08:00 committed by David Sterba
parent 08b0fdced1
commit 792ef0938d

View File

@ -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;
}