Changeset: a26e8e9d228b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a26e8e9d228b
Modified Files:
        tools/merovingian/client/monetdb.c
        tools/merovingian/daemon/controlrunner.c
Branch: default
Log Message:

Make snapshot list proto epoch independent


diffs (70 lines):

diff --git a/tools/merovingian/client/monetdb.c 
b/tools/merovingian/client/monetdb.c
--- a/tools/merovingian/client/monetdb.c
+++ b/tools/merovingian/client/monetdb.c
@@ -1754,20 +1754,35 @@ snapshot_enumerate(struct snapshot **sna
                char *p = out + 4;
                char *end = p + strlen(p);
                while (p < end) {
+                       char datebuf[100];
+                       char *parse_result;
+                       struct tm tm = {0};
                        char *eol = strchr(p, '\n');
                        eol = (eol != NULL) ? eol : end;
-                       int64_t time;
+                       time_t timestamp, pre, post;
                        uint64_t size;
                        int len;
-                       if (sscanf(p, "%" SCNd64 " %" SCNu64 " %n", &time, 
&size, &len) != 2) {
+                       if (sscanf(p, "%99s %" SCNu64 " %n", datebuf, &size, 
&len) != 2) {
                                free(out);
                                return strdup("internal parse error");
                        }
+                       parse_result = strptime(datebuf, "%Y%m%dT%H%M%S", &tm);
+                       if (parse_result == NULL || *parse_result != '\0') {
+                               free(out);
+                               return strdup("internal timestamp parse error");
+                       }
+                       // Unfortunately mktime interprets tm as local time, we 
have
+                       // to correct for that.
+                       timestamp = mktime(&tm);
+                       pre = time(NULL);
+                       gmtime_r(&pre, &tm);
+                       post = mktime(&tm);
+                       timestamp += pre - post;
                        p += len;
                        char *dbend = strchr(p, ' ');
                        if (dbend == NULL) {
                                free(out);
-                               return strdup("internal parse error");
+                               return strdup("Internal parse error");
                        }
                        int dblen = dbend - p;
                        char *path = dbend + 1;
@@ -1776,7 +1791,7 @@ snapshot_enumerate(struct snapshot **sna
                        snap->dbname = malloc(dblen + 1);
                        memmove(snap->dbname, p, dblen);
                        snap->dbname[dblen] = '\0';
-                       snap->time = time;
+                       snap->time = timestamp;
                        snap->size = size;
                        snap->path = malloc(pathlen + 1);
                        memmove(snap->path, path, pathlen);
diff --git a/tools/merovingian/daemon/controlrunner.c 
b/tools/merovingian/daemon/controlrunner.c
--- a/tools/merovingian/daemon/controlrunner.c
+++ b/tools/merovingian/daemon/controlrunner.c
@@ -783,9 +783,13 @@ static void ctl_handle_client(
                                len = snprintf(buf2, sizeof(buf2), "OK1\n");
                                send_client("=");
                                for (int i = 0; i < nsnaps; i++) {
+                                       struct tm tm = { 0 };
+                                       char datebuf[100];
                                        struct snapshot *snap = &snaps[i];
-                                       len = snprintf(buf2, sizeof(buf2), "%" 
PRIi64 " %" PRIu64 " %s %s\n",
-                                               (int64_t)snap->time,
+                                       gmtime_r(&snap->time, &tm);
+                                       strftime(datebuf, sizeof(datebuf), 
"%Y%m%dT%H%M%S", &tm);
+                                       len = snprintf(buf2, sizeof(buf2), "%s 
%" PRIu64 " %s %s\n",
+                                               datebuf,
                                                (uint64_t)snap->size,
                                                snap->dbname,
                                                snap->path != NULL ? snap->path 
: "");
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to