lib: use the compaction backup path provided by the caller

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.
This commit is contained in:
Jani Nikula 2013-11-03 14:24:47 +02:00 committed by David Bremner
parent 20abbe89a3
commit 00d2ac2b41
2 changed files with 11 additions and 13 deletions

View file

@ -868,7 +868,6 @@ notmuch_database_compact (const char* path,
{ {
void *local; void *local;
char *notmuch_path, *xapian_path, *compact_xapian_path; char *notmuch_path, *xapian_path, *compact_xapian_path;
char *old_xapian_path = NULL;
notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS; notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
notmuch_database_t *notmuch = NULL; notmuch_database_t *notmuch = NULL;
struct stat statbuf; struct stat statbuf;
@ -898,13 +897,8 @@ notmuch_database_compact (const char* path,
} }
if (backup_path != NULL) { if (backup_path != NULL) {
if (! (old_xapian_path = talloc_asprintf (local, "%s/xapian.old", backup_path))) { if (stat(backup_path, &statbuf) != -1) {
ret = NOTMUCH_STATUS_OUT_OF_MEMORY; fprintf (stderr, "Backup path already exists: %s\n", backup_path);
goto DONE;
}
if (stat(old_xapian_path, &statbuf) != -1) {
fprintf (stderr, "Backup path already exists: %s\n", old_xapian_path);
ret = NOTMUCH_STATUS_FILE_ERROR; ret = NOTMUCH_STATUS_FILE_ERROR;
goto DONE; goto DONE;
} }
@ -928,8 +922,8 @@ notmuch_database_compact (const char* path,
goto DONE; goto DONE;
} }
if (old_xapian_path != NULL) { if (backup_path) {
if (rename(xapian_path, old_xapian_path)) { if (rename(xapian_path, backup_path)) {
fprintf (stderr, "Error moving old database out of the way\n"); fprintf (stderr, "Error moving old database out of the way\n");
ret = NOTMUCH_STATUS_FILE_ERROR; ret = NOTMUCH_STATUS_FILE_ERROR;
goto DONE; goto DONE;

View file

@ -32,9 +32,13 @@ notmuch_compact_command (notmuch_config_t *config,
unused (char *argv[])) unused (char *argv[]))
{ {
const char *path = notmuch_config_get_database_path (config); const char *path = notmuch_config_get_database_path (config);
const char *backup_path = path; const char *backup_path;
notmuch_status_t ret; notmuch_status_t ret;
backup_path = talloc_asprintf (config, "%s/xapian.old", path);
if (! backup_path)
return 1;
printf ("Compacting database...\n"); printf ("Compacting database...\n");
ret = notmuch_database_compact (path, backup_path, status_update_cb, NULL); ret = notmuch_database_compact (path, backup_path, status_update_cb, NULL);
if (ret) { if (ret) {
@ -42,11 +46,11 @@ notmuch_compact_command (notmuch_config_t *config,
} else { } else {
printf ("\n"); printf ("\n");
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 ("\n");
printf ("To delete run,\n"); printf ("To delete run,\n");
printf ("\n"); printf ("\n");
printf (" rm -R %s/xapian.old\n", backup_path); printf (" rm -R %s\n", backup_path);
printf ("\n"); printf ("\n");
} }