Package: reprepro
Version: 5.4.2-1
Followup-For: Bug #1051537
Control: tags -1 patch

For some reason the patch was not attached. Here it is in text form:


*** 000-migrate-references.patch
--- a/database.c
+++ b/database.c
@@ -1949,6 +1949,8 @@
 
 retvalue database_openreferences(void) {
        retvalue r;
+       uint32_t flags;
+       int dbret;
 
        assert (rdb_references == NULL);
        r = database_table("references.db", "references",
@@ -1959,6 +1961,17 @@
                return r;
        } else
                rdb_references->verbose = false;
+       dbret = 
rdb_references->berkeleydb->get_flags(rdb_references->berkeleydb, &flags);
+       if (dbret != 0) {
+                       table_printerror(rdb_references, dbret, "get_flags");
+                       return RET_DBERR(dbret);
+               }
+       if (ISSET(flags, DB_DUPSORT)) {
+               fprintf(stderr,
+"Error: database uses deprecated format.\n"
+"Please run translatelegacyreferences to update to the new format first.\n");
+               return RET_ERROR;
+               }
        return RET_OK;
 }
 
@@ -2707,3 +2720,91 @@
        database_free();
        return r;
 }
+
+static retvalue table_copy_with_dup(struct table *oldtable, struct table 
*newtable) {
+       retvalue r;
+       struct cursor *cursor;
+       const char *filekey, *data;
+       size_t data_len;
+
+       r = table_newglobalcursor(oldtable, true, &cursor);
+       if (!RET_IS_OK(r))
+               return r;
+       while (cursor_nexttempdata(oldtable, cursor, &filekey,
+                               &data, &data_len)) {
+               r = table_addrecord(newtable, filekey,
+                               data, data_len, false);
+               if (RET_WAS_ERROR(r))
+                       return r;
+       }
+       return RET_OK;
+}
+
+retvalue database_translate_legacy_references(void) {
+       char *dbname, *tmpdbname;
+       struct table *oldtable, *newtable;
+       int ret;
+       retvalue r, r2;
+
+       dbname = dbfilename("references.db");
+       if (FAILEDTOALLOC(dbname))
+               return RET_ERROR_OOM;
+       tmpdbname = dbfilename("old.references.db");
+       if (FAILEDTOALLOC(tmpdbname)) {
+               free(dbname);
+               return RET_ERROR_OOM;
+       }
+       ret = rename(dbname, tmpdbname);
+       if (ret != 0) {
+               int e = errno;
+               fprintf(stderr, "Could not rename '%s' into '%s': %s(%d)\n",
+                               dbname, tmpdbname, strerror(e), e);
+               free(dbname);
+               free(tmpdbname);
+               return RET_ERRNO(e);
+       }
+       newtable = NULL;
+       r = database_table("references.db", "references",
+                       dbt_BTREEDUP, DB_CREATE, &newtable);
+       assert (r != RET_NOTHING);
+       oldtable = NULL;
+       if (RET_IS_OK(r)) {
+               r = database_table("old.references.db", "references",
+                               dbt_BTREEDUP, DB_RDONLY, &oldtable);
+               if (r == RET_NOTHING) {
+                       fprintf(stderr, "Could not find old-style database!\n");
+                       r = RET_ERROR;
+               }
+       }
+       if (RET_IS_OK(r)) {
+               r = table_copy_with_dup(oldtable, newtable);
+               r2 = table_close(oldtable);
+               RET_ENDUPDATE(r, r2);
+               if (r == RET_NOTHING) {
+                       r = RET_OK;
+               }
+       }
+       r2 = table_close(newtable);
+       RET_ENDUPDATE(r, r2);
+       if (RET_IS_OK(r))
+               (void)unlink(tmpdbname);
+
+       if (RET_WAS_ERROR(r)) {
+               ret = rename(tmpdbname, dbname);
+               if (ret != 0) {
+                       int e = errno;
+                       fprintf(stderr,
+"Could not rename '%s' back into '%s': %s(%d)\n",
+                                       dbname, tmpdbname, strerror(e), e);
+                       free(tmpdbname);
+                       free(dbname);
+                       return RET_ERRNO(e);
+               }
+               free(tmpdbname);
+               free(dbname);
+               return r;
+       }
+       free(tmpdbname);
+       free(dbname);
+       return RET_OK;
+}
\ No newline at end of file
--- a/main.c
+++ b/main.c
@@ -538,6 +538,9 @@
                        verbosedatabase || verbose > 10);
 }
 
+ACTION_T(n, n, translatelegacyreferences) {
+       return database_translate_legacy_references();
+}
 
 ACTION_F(n, n, n, n, addmd5sums) {
        char buffer[2000], *c, *m;
@@ -4135,6 +4138,8 @@
                0, 0, "translatefilelists"},
        {"translatelegacychecksums",    A_N(translatelegacychecksums),
                0, 0, "translatelegacychecksums"},
+       {"translatelegacyreferences",   A__T(translatelegacyreferences),
+               0, 0, "translatelegacyreferences"},
        {"_listconfidentifiers",        A_C(listconfidentifiers),
                0, -1, "_listconfidentifiers"},
        {"_listdbidentifiers",  A_ROB(listdbidentifiers)|MAY_UNUSED,
--- a/docs/reprepro.1
+++ b/docs/reprepro.1
@@ -1041,6 +1041,15 @@
 .IB db /contents.cache.db
 file size available in that partition.
 .TP
+.B translatelegacyreferences
+Translate the references within
+.IB db /references.db
+into the new format used since reprepro 5.4.0.
+
+Make sure you have at least the same space of the current
+.IB db /references.db
+file size available in that partition.
+.TP
 .B flood \fIdistribution\fP \fR[\fP\fIarchitecture\fP\fR]\fP
 For each architecture of \fIdistribution\fP (or for the one specified)
 add architecture \fBall\fP packages from other architectures
--- a/docs/reprepro.bash_completion
+++ b/docs/reprepro.bash_completion
@@ -338,6 +338,7 @@
                        tidytracks\
                        translatefilelists\
                        translatelegacychecksums\
+                       translatelegacyreferences\
                        unusedsources\
                        update'
                hiddencommands='__d\
--- a/docs/reprepro.zsh_completion
+++ b/docs/reprepro.zsh_completion
@@ -254,6 +254,7 @@
        tidytracks:"look for files referened by tracks but no longer needed"
        translatefilelists:"translate pre-3.0.0 contents.cache.db into new 
format"
        translatelegacychecksums:"get rid of obsolete files.db"
+       translatelegacyreferences:"translate pre-5.4.0 references.db into new 
format"
        unreferencesnapshot:"no longer mark files used by an snapshot"
        unusedsources:"list source packages with no binary packages"
        update:"update from external source"
--- a/database.h
+++ b/database.h
@@ -27,6 +27,7 @@
 retvalue database_opentracking(const char *, bool /*readonly*/, 
/*@out@*/struct table **);
 retvalue database_translate_filelists(void);
 retvalue database_translate_legacy_checksums(bool /*verbosedb*/);
+retvalue database_translate_legacy_references(void);
 
 retvalue table_close(/*@only@*/struct table *);
 

Reply via email to