Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp61342ybl; Tue, 28 Jan 2020 18:33:33 -0800 (PST) X-Google-Smtp-Source: APXvYqyKvYH0JSGzQ4EvSUlJEsqNh+NoiNXLHFchitA7KftSvipDCW++sJgmpEsIuBH7bzKB7Ltk X-Received: by 2002:aca:1903:: with SMTP id l3mr5056639oii.16.1580265213446; Tue, 28 Jan 2020 18:33:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580265213; cv=none; d=google.com; s=arc-20160816; b=NYsGC6CKIwPRSIAxGoP7Hn6BG/ARqAZnSbE8OBxUr186H6Us+1z+ZOajk7qVixToRB Pcg8Tt2lqVX/CT21L4DDOdPYCypeBHe27WTz26XhAa2peVmgdQohurplndWNBtjfw9Ah t2xMmzTalG8FwUAltZbBzzIwuzc8poBjjtn6B2PlVfdskeR0rixXa6j9JlMgFT6KntlE IMxX52PbQ3cnw5hVZ4iNc/+y132uBXEfJJVC0L9GujheNk+mzD+S4PuCC4X/7SBJL4MZ B6Pi103iv2G9MdM039zYJ4NVuxMrmq7adq9mPXbPe+Z/3h4ZHJau+EuUMgr0lRl+/Gf0 19Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=zkQJMRO/hk0EVqYFEL7nsLfDnhzs7B/QZo85/gxmP3k=; b=rHzGansgKzeG9vKsC1VkS28ZVKbkNanp1qkpeeXKK0qU1zPzfppsW0pq2dWCrL9GG0 A5iToCyUkQpnEjbKoKc0r0M80j4bCvAgOnfqPAw2xDuevXgFwy69rToPeKFVmNohs3pz 1dSQs04aHbi2Tx3EconZAtQtTHMyxRYlBvC3A6akX0o6j70v+jJYkXt33pXByp4jIiYt kYGFn3DxYMXE0z8WDZFfJ7TJz3IeiesysH86FPSL9r3sFzgonV+rQhO5PISXyRcv69Sj Z0KzNjvH8hNC7JFzf/9dMX0ZyKk/TNFvyNVbNn9qiLflJWXahpx6As0U1h61gp3g9SBQ XcJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j9si329133otq.317.2020.01.28.18.33.11; Tue, 28 Jan 2020 18:33:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-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-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726556AbgA2CdJ (ORCPT + 99 others); Tue, 28 Jan 2020 21:33:09 -0500 Received: from mga05.intel.com ([192.55.52.43]:53194 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726539AbgA2CdJ (ORCPT ); Tue, 28 Jan 2020 21:33:09 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Jan 2020 18:33:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,376,1574150400"; d="scan'208";a="427831882" Received: from bgi1-mobl2.amr.corp.intel.com ([10.255.84.27]) by fmsmga005.fm.intel.com with ESMTP; 28 Jan 2020 18:33:08 -0800 From: Brian Gix To: linux-bluetooth@vger.kernel.org Cc: brian.gix@intel.com, inga.stotland@intel.com, rafal.gajda@silvair.com Subject: [PATCH BlueZ v4 1/5] mesh: Relocate tree deletion to util.c/h Date: Tue, 28 Jan 2020 18:32:54 -0800 Message-Id: <20200129023258.10004-2-brian.gix@intel.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200129023258.10004-1-brian.gix@intel.com> References: <20200129023258.10004-1-brian.gix@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org --- mesh/mesh-config-json.c | 20 +------------------- mesh/util.c | 25 +++++++++++++++++++++++++ mesh/util.h | 1 + 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c index 5855149e3..ad2d4d0f8 100644 --- a/mesh/mesh-config-json.c +++ b/mesh/mesh-config-json.c @@ -2253,24 +2253,6 @@ bool mesh_config_load_nodes(const char *cfgdir_name, mesh_config_node_func_t cb, return true; } -static int del_fobject(const char *fpath, const struct stat *sb, int typeflag, - struct FTW *ftwbuf) -{ - switch (typeflag) { - case FTW_DP: - rmdir(fpath); - l_debug("RMDIR %s", fpath); - break; - - case FTW_SL: - default: - remove(fpath); - l_debug("RM %s", fpath); - break; - } - return 0; -} - void mesh_config_destroy(struct mesh_config *cfg) { char *node_dir, *node_name; @@ -2291,7 +2273,7 @@ void mesh_config_destroy(struct mesh_config *cfg) if (strcmp(node_name, uuid)) return; - nftw(node_dir, del_fobject, 5, FTW_DEPTH | FTW_PHYS); + del_path(node_dir); /* Release node config object */ mesh_config_release(cfg); diff --git a/mesh/util.c b/mesh/util.c index 986ba4b28..43340f159 100644 --- a/mesh/util.c +++ b/mesh/util.c @@ -24,6 +24,7 @@ #define _GNU_SOURCE #include #include +#include #include #include #include @@ -129,3 +130,27 @@ int create_dir(const char *dir_name) return 0; } + +static int del_fobject(const char *fpath, const struct stat *sb, int typeflag, + struct FTW *ftwbuf) +{ + switch (typeflag) { + case FTW_DP: + rmdir(fpath); + l_debug("RMDIR %s", fpath); + break; + + case FTW_SL: + default: + remove(fpath); + l_debug("RM %s", fpath); + break; + } + return 0; +} + + +void del_path(const char *path) +{ + nftw(path, del_fobject, 5, FTW_DEPTH | FTW_PHYS); +} diff --git a/mesh/util.h b/mesh/util.h index d1e83b573..092d33041 100644 --- a/mesh/util.h +++ b/mesh/util.h @@ -23,3 +23,4 @@ bool str2hex(const char *str, uint16_t in_len, uint8_t *out, size_t hex2str(uint8_t *in, size_t in_len, char *out, size_t out_len); void print_packet(const char *label, const void *data, uint16_t size); int create_dir(const char *dir_name); +void del_path(const char *path); -- 2.21.1