Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 200A8431FCB for ; Sun, 3 Nov 2013 04:25:43 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PLP5jADX9ZJm for ; Sun, 3 Nov 2013 04:25:37 -0800 (PST) Received: from mail-ee0-f49.google.com (mail-ee0-f49.google.com [74.125.83.49]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 8E2D9429E25 for ; Sun, 3 Nov 2013 04:25:13 -0800 (PST) Received: by mail-ee0-f49.google.com with SMTP id e52so580835eek.36 for ; Sun, 03 Nov 2013 04:25:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=hsWsMcdXmJOySzux5u60RChOOl+XhERARCk5b5+VOzU=; b=MAUAhEpwbW3QzY6XQV+1iYZHiOUt5gNx8gOJniDhqVW4OINgokuKcFRVD9Hp/C8jot PGFITn73nNUvlxzI0EUBNZm95FHwDmwfDU3rY+vqqmqI9zeUBp18qw7qo+sYd3FbKjrq GF5+vU1nEb6Rnois3vJe6lpKcB6rDV8byg15CShLcCF3zmt7IvpBCMVmV4qqMEZ5L6VY W9JQ4IRNcOr1vP5+VEbl79NjDfib2+jG9jhpXn2wfxftD2IafdK9Ur2j7RGyIWZ/O+jt DdwwxsJU9RiO6ycBdKfAc19/LJFBs/Un2qkf8t5RtB+lCmFOv5pgzwb5szxooq1SReEi tfKw== X-Gm-Message-State: ALoCoQnphsxQPLcyzjyYZ0eDQuWtuLLM4OqkKRHGv13zuNELDTUe7BLoFJ+ZT4DYpzMjbSSqNl7o X-Received: by 10.15.10.6 with SMTP id f6mr1614135eet.57.1383481512392; Sun, 03 Nov 2013 04:25:12 -0800 (PST) Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi. [88.195.111.91]) by mx.google.com with ESMTPSA id u46sm32772104eep.17.2013.11.03.04.25.10 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 03 Nov 2013 04:25:11 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH v2 07/11] lib: use the compaction backup path provided by the caller Date: Sun, 3 Nov 2013 14:24:47 +0200 Message-Id: <6e8053834c8ab856c2ebab881069f18b2badcf71.1383481295.git.jani@nikula.org> X-Mailer: git-send-email 1.8.4.rc3 In-Reply-To: References: In-Reply-To: References: X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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: Sun, 03 Nov 2013 12:25:43 -0000 The extra path component added by the lib is a magic value that the caller just has to know. This is demonstrated by the current code, which indeed has "xapian.old" both sides of the interface. Use the backup path provided by the lib caller verbatim, without adding anything to it. --- v2: add xapian.old in cli --- lib/database.cc | 14 ++++---------- notmuch-compact.c | 10 +++++++--- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index 5a01703..a021bf1 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -868,7 +868,6 @@ notmuch_database_compact (const char* path, { void *local; char *notmuch_path, *xapian_path, *compact_xapian_path; - char *old_xapian_path = NULL; notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS; notmuch_database_t *notmuch = NULL; struct stat statbuf; @@ -898,13 +897,8 @@ notmuch_database_compact (const char* path, } if (backup_path != NULL) { - if (! (old_xapian_path = talloc_asprintf (local, "%s/xapian.old", backup_path))) { - ret = NOTMUCH_STATUS_OUT_OF_MEMORY; - goto DONE; - } - - if (stat(old_xapian_path, &statbuf) != -1) { - fprintf (stderr, "Backup path already exists: %s\n", old_xapian_path); + if (stat(backup_path, &statbuf) != -1) { + fprintf (stderr, "Backup path already exists: %s\n", backup_path); ret = NOTMUCH_STATUS_FILE_ERROR; goto DONE; } @@ -928,8 +922,8 @@ notmuch_database_compact (const char* path, goto DONE; } - if (old_xapian_path != NULL) { - if (rename(xapian_path, old_xapian_path)) { + if (backup_path) { + if (rename(xapian_path, backup_path)) { fprintf (stderr, "Error moving old database out of the way\n"); ret = NOTMUCH_STATUS_FILE_ERROR; goto DONE; diff --git a/notmuch-compact.c b/notmuch-compact.c index ee7afcf..55dc731 100644 --- a/notmuch-compact.c +++ b/notmuch-compact.c @@ -32,9 +32,13 @@ notmuch_compact_command (notmuch_config_t *config, unused (char *argv[])) { const char *path = notmuch_config_get_database_path (config); - const char *backup_path = path; + const char *backup_path; notmuch_status_t ret; + backup_path = talloc_asprintf (config, "%s/xapian.old", path); + if (! backup_path) + return 1; + printf ("Compacting database...\n"); ret = notmuch_database_compact (path, backup_path, status_update_cb, NULL); if (ret) { @@ -42,11 +46,11 @@ notmuch_compact_command (notmuch_config_t *config, } else { printf ("\n"); printf ("\n"); - printf ("The old database has been moved to %s/xapian.old", backup_path); + printf ("The old database has been moved to %s", backup_path); printf ("\n"); printf ("To delete run,\n"); printf ("\n"); - printf (" rm -R %s/xapian.old\n", backup_path); + printf (" rm -R %s\n", backup_path); printf ("\n"); } -- 1.8.4.rc3