[ostree] cmdline: Fatally error if the timestamp in a commit is invalid
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] cmdline: Fatally error if the timestamp in a commit is invalid
- Date: Fri, 4 Dec 2015 19:29:05 +0000 (UTC)
commit 8ba90a33410c9707a30a77f808a7ec712d465165
Author: Colin Walters <walters verbum org>
Date: Fri Dec 4 11:14:25 2015 -0500
cmdline: Fatally error if the timestamp in a commit is invalid
Previously we were just ignoring this, which hid a bug in
an earlier commit that generated them.
Also change the `commit` program to use both APIs - this
involves extra code, but not too much.
This way, reverting the fix with this on top caused the test suite to
fail. Adding an active test for this would need a custom test program
using the C API, or adding a cmdline flag to the client, neither of
which quite seemed worth it.
src/ostree/ot-builtin-commit.c | 17 +++++++++++------
src/ostree/ot-dump.c | 19 ++++++++++++++-----
2 files changed, 25 insertions(+), 11 deletions(-)
---
diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c
index 6afed20..72b83bf 100644
--- a/src/ostree/ot-builtin-commit.c
+++ b/src/ostree/ot-builtin-commit.c
@@ -497,6 +497,11 @@ ostree_builtin_commit (int argc, char **argv, GCancellable *cancellable, GError
GDateTime *now = g_date_time_new_now_utc ();
timestamp = g_date_time_to_unix (now);
g_date_time_unref (now);
+
+ if (!ostree_repo_write_commit (repo, parent, opt_subject, opt_body, metadata,
+ OSTREE_REPO_FILE (root),
+ &commit_checksum, cancellable, error))
+ goto out;
}
else
{
@@ -508,13 +513,13 @@ ostree_builtin_commit (int argc, char **argv, GCancellable *cancellable, GError
goto out;
}
timestamp = ts.tv_sec;
- }
- if (!ostree_repo_write_commit_with_time (repo, parent, opt_subject, opt_body, metadata,
- OSTREE_REPO_FILE (root),
- timestamp,
- &commit_checksum, cancellable, error))
- goto out;
+ if (!ostree_repo_write_commit_with_time (repo, parent, opt_subject, opt_body, metadata,
+ OSTREE_REPO_FILE (root),
+ timestamp,
+ &commit_checksum, cancellable, error))
+ goto out;
+ }
if (detached_metadata)
{
diff --git a/src/ostree/ot-dump.c b/src/ostree/ot-dump.c
index dc2b3a0..fd4c367 100644
--- a/src/ostree/ot-dump.c
+++ b/src/ostree/ot-dump.c
@@ -24,6 +24,8 @@
#include "config.h"
+#include <err.h>
+
#include "ot-dump.h"
#include "otutil.h"
#include "ot-admin-functions.h"
@@ -47,14 +49,19 @@ ot_dump_variant (GVariant *variant)
}
static gchar *
-format_timestamp (guint64 timestamp)
+format_timestamp (guint64 timestamp,
+ GError **error)
{
GDateTime *dt;
gchar *str;
dt = g_date_time_new_from_unix_utc (timestamp);
if (dt == NULL)
- return NULL;
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
+ "Invalid timestamp: %" G_GUINT64_FORMAT, timestamp);
+ return NULL;
+ }
str = g_date_time_format (dt, "%Y-%m-%d %H:%M:%S +0000");
g_date_time_unref (dt);
@@ -94,15 +101,17 @@ dump_commit (GVariant *variant,
guint64 timestamp;
g_autofree char *str = NULL;
g_autofree char *version = NULL;
+ g_autoptr(GError) local_error = NULL;
/* See OSTREE_COMMIT_GVARIANT_FORMAT */
g_variant_get (variant, "(a{sv}aya(say)&s&stayay)", NULL, NULL, NULL,
&subject, &body, ×tamp, NULL, NULL);
timestamp = GUINT64_FROM_BE (timestamp);
- str = format_timestamp (timestamp);
- if (str)
- g_print ("Date: %s\n", str);
+ str = format_timestamp (timestamp, &local_error);
+ if (!str)
+ errx (1, "Failed to read commit: %s", local_error->message);
+ g_print ("Date: %s\n", str);
if ((version = ot_admin_checksum_version (variant)))
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]