Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp2883229ima; Sun, 3 Feb 2019 08:42:19 -0800 (PST) X-Google-Smtp-Source: AHgI3IbktpxTNX77ajeQW8raKv4Jm/vGsHCxOZhBGLu+U/EhCBjt53VaO0i6FfMYFV+s4x+SPzfq X-Received: by 2002:aa7:80c8:: with SMTP id a8mr4215679pfn.27.1549212139488; Sun, 03 Feb 2019 08:42:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549212139; cv=none; d=google.com; s=arc-20160816; b=ibDdAgFdtGHwKz4uEHc8pQTiMZiiQRmpXc2wqLK3pUAqBFO/ZJrf5itzqZvn4VSYv3 qr5oVDrDeXA/B3w7zN+fKCxauvBl4ItBgd8+Lp5Y5K92ym3hELIby0uyzIU1kVFankNJ MejStPjgYOwn8sI9CCw7TQh5OWTbouIFT9dpcoICTxds1O7LvcFSCd3/HMYugfELntzf 9WtkJZSyc0xG80j1VoyML2gyZiF3VcxpkDLTktG/sUnsvRl9OpURAZitJiRM+xMZk2NH aztqcvqsV/53HU9HA7LqbgEJbYI9zxkaXFEwWM9mLZght9Pu24/xIyTKHTAUUSgN5Kxh MgFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=HGDNF24R/hQZyBSu/hpyKWlmRl98WMEv0vk6Eq/r9MM=; b=QGY6iQFK9m8K3hVLn4+f9uM2jXEOPtVlXXYyi9XUY7A3HGWmWTaq8bKbF/AibqoOG1 W/mKX2X8l9p1Fcqq3wcDKAKjvdHnHBi3xrW5TN8+5irhl8ymCxRs3XdoFV97LpPYve8t FELTzSZA0gNyyShGDBDVbGUtXObW8fzk31nkLybOBtYRuqlzkrefZS7x3qsyXfuqzYEP rAVJ0PZysXt5j5WdTvcnzxAmJBH9sEKnWxYVUtPAIdFBBZeqNGRh9/ykHemPY4Worm5o uGXorjTiFpmM3i69TKC2BK/Gz7I6RwWlS80uDBsxHk9boy5tEBK7pgOSwEuW2eBECo8p PDsA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 6si12341132plc.241.2019.02.03.08.42.02; Sun, 03 Feb 2019 08:42:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728436AbfBCPal (ORCPT + 99 others); Sun, 3 Feb 2019 10:30:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44516 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728376AbfBCPai (ORCPT ); Sun, 3 Feb 2019 10:30:38 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4FBCC05E753; Sun, 3 Feb 2019 15:30:37 +0000 (UTC) Received: from krava.redhat.com (ovpn-204-46.brq.redhat.com [10.40.204.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3CBF75C238; Sun, 3 Feb 2019 15:30:35 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Adrian Hunter , Andi Kleen , Stephane Eranian , Alexey Budankov Subject: [PATCH 05/14] perf data: Make check_backup work over directories Date: Sun, 3 Feb 2019 16:30:09 +0100 Message-Id: <20190203153018.9650-6-jolsa@kernel.org> In-Reply-To: <20190203153018.9650-1-jolsa@kernel.org> References: <20190203153018.9650-1-jolsa@kernel.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sun, 03 Feb 2019 15:30:38 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Changing check_backup to work also over directory path. Also moving the call earlier in the path, so it can rename also directory data. Link: http://lkml.kernel.org/n/tip-j4lwm20en1yk1hsaqb8zpxkr@git.kernel.org Signed-off-by: Jiri Olsa --- tools/perf/util/data.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c index e16d06ed1100..0a3051cc0ea0 100644 --- a/tools/perf/util/data.c +++ b/tools/perf/util/data.c @@ -37,12 +37,15 @@ static int check_backup(struct perf_data *data) { struct stat st; + if (perf_data__is_read(data)) + return 0; + if (!stat(data->path, &st) && st.st_size) { /* TODO check errors properly */ char oldname[PATH_MAX]; snprintf(oldname, sizeof(oldname), "%s.old", data->path); - unlink(oldname); + rm_rf(oldname); rename(data->path, oldname); } @@ -95,9 +98,6 @@ static int open_file_write(struct perf_data *data) int fd; char sbuf[STRERR_BUFSIZE]; - if (check_backup(data)) - return -1; - fd = open(data->file.path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC, S_IRUSR|S_IWUSR); @@ -141,6 +141,9 @@ int perf_data__open(struct perf_data *data) if (!data->path) data->path = "perf.data"; + if (check_backup(data)) + return -1; + return open_file_dup(data); } -- 2.17.2