lib/commit: respect SOURCE_DATE_EPOCH for commit timestamp
This tweaks `ostree_repo_write_commit` so that it checks for the envinroment variable `SOURCE_DATE_EPOCH` as a way to override the current time, which is used as the commit timestamp. Ref: https://reproducible-builds.org/docs/source-date-epoch/ Ref: https://reproducible-builds.org/specs/source-date-epoch/
This commit is contained in:
3 files changed
+69
-2
No files matched your search
@@ -3020,6 +3020,10 @@ create_empty_gvariant_dict (void)
|
||||
*
|
||||
* Write a commit metadata object, referencing @root_contents_checksum
|
||||
* and @root_metadata_checksum.
|
||||
* This uses the current time as the commit timestamp, but it can be
|
||||
* overridden with an explicit timestamp via the
|
||||
* [standard](https://reproducible-builds.org/specs/source-date-epoch/)
|
||||
* `SOURCE_DATE_EPOCH` environment flag.
|
||||
*/
|
||||
gboolean
|
||||
ostree_repo_write_commit (OstreeRepo *self,
|
||||
@@ -3032,9 +3036,26 @@ ostree_repo_write_commit (OstreeRepo *self,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GDateTime) now = g_date_time_new_now_utc ();
|
||||
gint64 timestamp = 0;
|
||||
const gchar *env_timestamp = g_getenv ("SOURCE_DATE_EPOCH");
|
||||
if (env_timestamp == NULL)
|
||||
{
|
||||
g_autoptr(GDateTime) now = g_date_time_new_now_utc ();
|
||||
timestamp = g_date_time_to_unix (now);
|
||||
}
|
||||
else
|
||||
{
|
||||
gchar *ret = NULL;
|
||||
errno = 0;
|
||||
timestamp = g_ascii_strtoll (env_timestamp, &ret, 10);
|
||||
if (errno != 0)
|
||||
return glnx_throw_errno_prefix (error, "Parsing SOURCE_DATE_EPOCH");
|
||||
if (ret == env_timestamp)
|
||||
return glnx_throw (error, "Failed to convert SOURCE_DATE_EPOCH");
|
||||
}
|
||||
|
||||
return ostree_repo_write_commit_with_time (self, parent, subject, body,
|
||||
metadata, root, g_date_time_to_unix (now),
|
||||
metadata, root, timestamp,
|
||||
out_commit, cancellable, error);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user