Message ID | 1403577513-6201-1-git-send-email-guihc.fnst@cn.fujitsu.com (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
On Tue, 2014-06-24 at 10:38 +0800, Gui Hecheng wrote: > 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> > --- > changelog > v1->v2: use a new local variable to avoid return value overwritten > --- > btrfs-image.c | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/btrfs-image.c b/btrfs-image.c > index c18dff1..321c331 100644 > --- a/btrfs-image.c > +++ b/btrfs-image.c > @@ -2604,8 +2604,18 @@ int main(int argc, char *argv[]) > out: > 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; > } Sorry, I will kick out the tailing whitespace and send a v3. Please *ignore* this. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/btrfs-image.c b/btrfs-image.c index c18dff1..321c331 100644 --- a/btrfs-image.c +++ b/btrfs-image.c @@ -2604,8 +2604,18 @@ int main(int argc, char *argv[]) out: 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; }
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> --- changelog v1->v2: use a new local variable to avoid return value overwritten --- btrfs-image.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)