Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id CFFEF6DE025E for ; Wed, 10 Jun 2015 00:19:08 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.207 X-Spam-Level: X-Spam-Status: No, score=0.207 tagged_above=-999 required=5 tests=[AWL=0.197, T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id w8HF7pQd60sV for ; Wed, 10 Jun 2015 00:19:05 -0700 (PDT) Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net [87.98.215.224]) by arlo.cworth.org (Postfix) with ESMTPS id CC8E46DE0244 for ; Wed, 10 Jun 2015 00:19:04 -0700 (PDT) Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim 4.80) (envelope-from ) id 1Z2aGM-0007U6-6x; Wed, 10 Jun 2015 07:17:26 +0000 Received: (nullmailer pid 5324 invoked by uid 1000); Wed, 10 Jun 2015 07:17:07 -0000 From: David Bremner To: David Bremner , Morgan Veyret , notmuch@notmuchmail.org Subject: [PATCH 1/2] lib: add NOTMUCH_STATUS_PATH_ERROR Date: Wed, 10 Jun 2015 09:17:00 +0200 Message-Id: <1433920621-5279-1-git-send-email-david@tethera.net> X-Mailer: git-send-email 2.1.4 In-Reply-To: <87oakqj5rm.fsf@maritornes.cs.unb.ca> References: <87oakqj5rm.fsf@maritornes.cs.unb.ca> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Jun 2015 07:19:08 -0000 The difference with FILE_ERROR is that this is for things that are wrong with the path before looking at the disk. Add some 3 tests; two broken as a reminder to actually use this new code. --- lib/database.cc | 2 ++ lib/notmuch.h | 5 +++++ test/T070-insert.sh | 2 +- test/T560-lib-error.sh | 42 ++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index 78a24f7..e726f62 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -342,6 +342,8 @@ notmuch_status_to_string (notmuch_status_t status) return "Unsupported operation"; case NOTMUCH_STATUS_UPGRADE_REQUIRED: return "Operation requires a database upgrade"; + case NOTMUCH_STATUS_PATH_ERROR: + return "Path supplied is illegal for this function"; default: case NOTMUCH_STATUS_LAST_STATUS: return "Unknown error status value"; diff --git a/lib/notmuch.h b/lib/notmuch.h index 20c4e01..aab0151 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -164,6 +164,11 @@ typedef enum _notmuch_status { */ NOTMUCH_STATUS_UPGRADE_REQUIRED, /** + * There is a problem with the proposed path, a relative path + * passed to a function expecting an absolute path. + */ + NOTMUCH_STATUS_PATH_ERROR, + /** * Not an actual status value. Just a way to find out how many * valid status values there are. */ diff --git a/test/T070-insert.sh b/test/T070-insert.sh index 74f1955..7e71c3b 100755 --- a/test/T070-insert.sh +++ b/test/T070-insert.sh @@ -188,7 +188,7 @@ notmuch config set new.tags $OLDCONFIG # DUPLICATE_MESSAGE_ID is not tested here, because it should actually pass. for code in OUT_OF_MEMORY XAPIAN_EXCEPTION FILE_NOT_EMAIL \ - READ_ONLY_DATABASE UPGRADE_REQUIRED; do + READ_ONLY_DATABASE UPGRADE_REQUIRED PATH_ERROR; do gen_insert_msg cat < index-file-$code.gdb set breakpoint pending on diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh index c99b17e..9f5f7ae 100755 --- a/test/T560-lib-error.sh +++ b/test/T560-lib-error.sh @@ -35,7 +35,8 @@ Error: Cannot open a database for a NULL path. EOF test_expect_equal_file EXPECTED OUTPUT -test_begin_subtest "Open nonexistent database" +test_begin_subtest "Open relative path" +test_subtest_known_broken test_C <<'EOF' #include #include @@ -49,7 +50,44 @@ EOF cat <<'EOF' >EXPECTED == stdout == == stderr == -Error opening database at ./nonexistent/foo/.notmuch: No such file or directory +Error: Database path must be absolute. +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "Create database in relative path" +test_subtest_known_broken +test_C <<'EOF' +#include +#include +int main (int argc, char** argv) +{ + notmuch_database_t *db; + notmuch_status_t stat; + stat = notmuch_database_create ("./nonexistent/foo", &db); +} +EOF +cat <<'EOF' >EXPECTED +== stdout == +== stderr == +Error: Database path must be absolute. +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "Open nonexistent database" +test_C ${PWD}/nonexistent/foo <<'EOF' +#include +#include +int main (int argc, char** argv) +{ + notmuch_database_t *db; + notmuch_status_t stat; + stat = notmuch_database_open (argv[1], 0, 0); +} +EOF +cat <<'EOF' >EXPECTED +== stdout == +== stderr == +Error opening database at CWD/nonexistent/foo/.notmuch: No such file or directory EOF test_expect_equal_file EXPECTED OUTPUT -- 2.1.4