summaryrefslogtreecommitdiff
path: root/src/libostree/ostree-core.c
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2017-05-18 18:12:33 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2017-08-21 18:24:07 +0000
commit618617d68b6ea82a71b3394ccd726e6b4b3e156e (patch)
tree44c73d98da2a73593bbf8a894ce49a3977c6fc3e /src/libostree/ostree-core.c
parentca61a2bd9d5002ac6cdf2371077e15b0c25da2bc (diff)
downloadostree-618617d68b6ea82a71b3394ccd726e6b4b3e156e.tar.gz
lib/pull: Add support for timestamp-check option, use in upgrader
For both flatpak and ostree-as-host, we really want to verify up front during pulls that we're not being downgraded. Currently both flatpak and `OstreeSysrootUpgrader` do this before deployments, but at that point we've already downloaded all the data, which is annoying. Closes: https://github.com/ostreedev/ostree/issues/687 Closes: #1055 Approved by: jlebon
Diffstat (limited to 'src/libostree/ostree-core.c')
-rw-r--r--src/libostree/ostree-core.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index c13d2f2e..4118cf7e 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -2086,6 +2086,38 @@ ostree_commit_get_timestamp (GVariant *commit_variant)
return GUINT64_FROM_BE (ret);
}
+/* Used in pull/deploy to validate we're not being downgraded */
+gboolean
+_ostree_compare_timestamps (const char *current_rev,
+ guint64 current_ts,
+ const char *new_rev,
+ guint64 new_ts,
+ GError **error)
+{
+ /* Newer timestamp is OK */
+ if (new_ts > current_ts)
+ return TRUE;
+ /* If they're equal, ensure they're the same rev */
+ if (new_ts == current_ts || strcmp (current_rev, new_rev) == 0)
+ return TRUE;
+
+ /* Looks like a downgrade, format an error message */
+ g_autoptr(GDateTime) current_dt = g_date_time_new_from_unix_utc (current_ts);
+ g_autoptr(GDateTime) new_dt = g_date_time_new_from_unix_utc (new_ts);
+
+ if (current_dt == NULL || new_dt == NULL)
+ return glnx_throw (error, "Upgrade target revision '%s' timestamp (%" G_GINT64_FORMAT ") or current revision '%s' timestamp (%" G_GINT64_FORMAT ") is invalid",
+ new_rev, new_ts,
+ current_rev, current_ts);
+
+ g_autofree char *current_ts_str = g_date_time_format (current_dt, "%c");
+ g_autofree char *new_ts_str = g_date_time_format (new_dt, "%c");
+
+ return glnx_throw (error, "Upgrade target revision '%s' with timestamp '%s' is chronologically older than current revision '%s' with timestamp '%s'",
+ new_rev, new_ts_str, current_rev, current_ts_str);
+}
+
+
GVariant *
_ostree_detached_metadata_append_gpg_sig (GVariant *existing_metadata,
GBytes *signature_bytes)