+ /* Convert version string to an integer */
+ oldversion = s ? atol(s) : 1;
+ if(oldversion > config->dbversion) {
+ /* Database is from the future; we never allow this. */
+ fatal(0, "this version of DisOrder is too old for database version %ld",
+ oldversion);
+ }
+ 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();
+ }
+ }
+ if(oldversion == config->dbversion && (flags & TRACKDB_OPEN_FOR_UPGRADE)) {
+ /* This doesn't make any sense */
+ fatal(0, "database is already at current version");
+ }
+ newdb = 0;