From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id IAK5BpfQ42K6ZwAAbAwnHQ (envelope-from ) for ; Fri, 29 Jul 2022 14:20:39 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id WA/eBZfQ42KpPwAAG6o9tA (envelope-from ) for ; Fri, 29 Jul 2022 14:20:39 +0200 Received: from mail.notmuchmail.org (yantan.tethera.net [IPv6:2a01:4f9:c011:7a79::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D38712C7DB for ; Fri, 29 Jul 2022 14:20:38 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id D5A4A5F383; Fri, 29 Jul 2022 12:20:19 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 811D55F377 for ; Fri, 29 Jul 2022 12:20:16 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 948675FBD0; Fri, 29 Jul 2022 08:20:15 -0400 (EDT) Received: (nullmailer pid 1557189 invoked by uid 1000); Fri, 29 Jul 2022 12:20:10 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 4/6] lib/open: refactor call to mkdir into function Date: Fri, 29 Jul 2022 09:19:59 -0300 Message-Id: <20220729122001.1556787-5-david@tethera.net> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220729122001.1556787-1-david@tethera.net> References: <20220729122001.1556787-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: KWEB4V5LA4GL6NU64XB2BMP4VOG7TKPN X-Message-ID-Hash: KWEB4V5LA4GL6NU64XB2BMP4VOG7TKPN X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: spwhitton@spwhitton.name X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1659097238; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=1l0HCw1+8phAClREESJmYYa9RW8WkMfk3qhx5LUh1TM=; b=lkZ8SmFFd3xvzlGZNmGK2mRmJG/DYTWCIETNSVrDeSk8xw7bjLipDVFSwLgHTWZrUAuGvI wpes5bKAjsqqhE/IPc9NLEAtK1pwX3NJYLcGFLl9SbdNMo2jhVSij5egl+OtCLZzsdFwWb 1ofFGAJx+yF4tARFIZJmLqG6Kx4itlH1yh50P23rYZoN3tfESEyQ1+fC/6DY6UDpsp4wLi LLLzfs+ab2BhyAHLjThws2m1unLcSNfw96SX97o4aJ7q4whr4eJuA2xoVdr9yPwUq90cek WzAADwLi5NNG+BWm/E3fuBPCB6yPOAt6Wv41SGN6U93hQitnwhdqNzky2CQw/w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1659097238; a=rsa-sha256; cv=none; b=VvlXVMntEk4CcNR59XtGplIwR9cu0vADP5KS5nhRnMtj8PgIQ8OHKpZCCgMvnKiiH/A8EB iWTKCLailHd7djZSPA/dP/b40epqktn50GSA4uoTyx3XIgsjKMBbXDwkWL9UKAhgsXwCYc KAmyF67Hm202zsYaCiXoCxWV0MeitmjATOv9sSbVuoJWYZh7kYL0lhMKpFrSIegzypddFf mnB9Y/h6sP1pqSGj2tVi8uEjJH0y8lTkHg/7aR6AxyuQA7VW+qiCW+JI9sxQcYCBxGZTpH FfdQQybcvxp7pQMiDpldvxTAg/Yrfq0vu5YhalSyRBD9vXzGA+j0KGJRTcz9wA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.60 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: D38712C7DB X-Spam-Score: -1.60 X-Migadu-Scanner: scn0.migadu.com X-TUID: 3EPWqZrr4FI5 This makes the error handling available for re-use. Using g_mkdir_with_parents also handles the case of a pre-existing directory. This introduces new functionality, namely creating the parent directories, which will be useful for creating directories like '.local/share/notmuch/default'. --- lib/open.cc | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/open.cc b/lib/open.cc index 30cfcf9e..85e46dc7 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -244,6 +244,18 @@ _choose_database_path (notmuch_database_t *notmuch, return NOTMUCH_STATUS_SUCCESS; } +static notmuch_status_t +_mkdir (const char *path, char **message) +{ + if (g_mkdir_with_parents (path, 0755)) { + IGNORE_RESULT (asprintf (message, "Error: Cannot create directory %s: %s.\n", + path, strerror (errno))); + return NOTMUCH_STATUS_FILE_ERROR; + } + return NOTMUCH_STATUS_SUCCESS; +} + + static notmuch_database_t * _alloc_notmuch (const char *database_path, const char *config_path, const char *profile) { @@ -607,7 +619,6 @@ notmuch_database_create_with_config (const char *database_path, const char *notmuch_path = NULL; char *message = NULL; GKeyFile *key_file = NULL; - int err; _notmuch_init (); @@ -653,15 +664,9 @@ notmuch_database_create_with_config (const char *database_path, goto DONE; } - err = mkdir (notmuch_path, 0755); - if (err) { - if (errno != EEXIST) { - IGNORE_RESULT (asprintf (&message, "Error: Cannot create directory %s: %s.\n", - notmuch_path, strerror (errno))); - status = NOTMUCH_STATUS_FILE_ERROR; - goto DONE; - } - } + status = _mkdir (notmuch_path, &message); + if (status) + goto DONE; } if (! (notmuch->xapian_path = talloc_asprintf (notmuch, "%s/%s", notmuch_path, "xapian"))) { -- 2.35.2