From patchwork Tue Jun 24 02:38:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gui Hecheng X-Patchwork-Id: 4406181 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9BECA9F37C for ; Tue, 24 Jun 2014 02:43:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9D1EE20303 for ; Tue, 24 Jun 2014 02:43:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C4DAE202FE for ; Tue, 24 Jun 2014 02:43:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751126AbaFXCny (ORCPT ); Mon, 23 Jun 2014 22:43:54 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:55171 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751000AbaFXCny (ORCPT ); Mon, 23 Jun 2014 22:43:54 -0400 X-IronPort-AV: E=Sophos;i="5.00,765,1396972800"; d="scan'208";a="32327439" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 24 Jun 2014 10:41:12 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s5O2hpoj016955; Tue, 24 Jun 2014 10:43:51 +0800 Received: from localhost.localdomain (10.167.226.111) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 24 Jun 2014 10:43:56 +0800 From: Gui Hecheng To: CC: , Gui Hecheng Subject: [PATCH v2 3/4] btrfs-progs: delete invalid output file when btrfs-image failed Date: Tue, 24 Jun 2014 10:38:33 +0800 Message-ID: <1403577513-6201-1-git-send-email-guihc.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <20140623141557.GG1553@twin.jikos.cz> References: <20140623141557.GG1553@twin.jikos.cz> MIME-Version: 1.0 X-Originating-IP: [10.167.226.111] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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; }