- if(oldversion < config->dbversion && !dbupgrade) {
- /* This database needs upgrading. This isn't implemented yet so we just
- * fail. */
- fatal(0, "database needs upgrading from %ld to %ld",
- oldversion, config->dbversion);
+ if(oldversion < config->dbversion) {
+ /* Database version is out of date */
+ switch(flags & TRACKDB_UPGRADE_MASK) {
+ case TRACKDB_NO_UPGRADE:
+ /* This database needs upgrading but this is not permitted */
+ fatal(0, "database needs upgrading from %ld to %ld",
+ oldversion, config->dbversion);
+ case TRACKDB_CAN_UPGRADE:
+ /* This database needs upgrading */
+ info("invoking disorder-dbupgrade to upgrade from %ld to %ld",
+ oldversion, config->dbversion);
+ pid = subprogram(0, "disorder-dbupgrade", -1);
+ while(waitpid(pid, &err, 0) == -1 && errno == EINTR)
+ ;
+ if(err)
+ fatal(0, "disorder-dbupgrade %s", wstat(err));
+ info("disorder-dbupgrade succeeded");
+ break;
+ case TRACKDB_OPEN_FOR_UPGRADE:
+ break;
+ default:
+ abort();
+ }