diff options
author | Philip Withnall <withnall@endlessm.com> | 2017-06-07 15:27:10 +0100 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2017-06-26 15:56:07 +0000 |
commit | 0a20e7d43c43c9d5793f0fdb5bf8422affa5d841 (patch) | |
tree | 3d9636d1489d1f7cf4f868777a98ddf4877c23c2 /src/libostree/ostree-core.c | |
parent | bf1f8eb0fa36204377127e335b01b4bb95666cb2 (diff) | |
download | ostree-0a20e7d43c43c9d5793f0fdb5bf8422affa5d841.tar.gz |
lib/ref: Add OstreeCollectionRef type for globally unique refs
This is a type representing the tuple (collection ID, ref name), which is
guaranteed to be globally unique. It will be used in upcoming commits.
It introduces the concept of a ‘collection’ which is a unique, curated
set of refs which lie in the same trust domain (i.e. all signed by the
same key and validated by the same developer). Flathub might be a
collection, for example; or the set of OS refs coming from a particular
OS vendor.
It includes a function for validating collection IDs.
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #924
Approved by: cgwalters
Diffstat (limited to 'src/libostree/ostree-core.c')
-rw-r--r-- | src/libostree/ostree-core.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c index 32516b7c..c0b7cbe3 100644 --- a/src/libostree/ostree-core.c +++ b/src/libostree/ostree-core.c @@ -210,6 +210,38 @@ ostree_validate_remote_name (const char *remote_name, return TRUE; } +/** + * ostree_validate_collection_id: + * @rev: (nullable): A collection ID + * @error: Error + * + * Check whether the given @collection_id is valid. Return an error if it is + * invalid or %NULL. + * + * Valid collection IDs are reverse DNS names: + * * They are composed of 1 or more elements separated by a period (`.`) character. + * All elements must contain at least one character. + * * Each element must only contain the ASCII characters `[A-Z][a-z][0-9]_` and must not + * begin with a digit. + * * They must contain at least one `.` (period) character (and thus at least two elements). + * * They must not begin with a `.` (period) character. + * * They must not exceed 255 characters in length. + * + * (This makes their format identical to D-Bus interface names, for consistency.) + * + * Returns: %TRUE if @collection_id is a valid collection ID, %FALSE if it is invalid + * or %NULL + */ +gboolean +ostree_validate_collection_id (const char *collection_id, GError **error) +{ + /* Abuse g_dbus_is_interface_name(), since collection IDs have the same format. */ + if (collection_id == NULL || !g_dbus_is_interface_name (collection_id)) + return glnx_throw (error, "Invalid collection ID %s", collection_id); + + return TRUE; +} + GVariant * _ostree_file_header_new (GFileInfo *file_info, GVariant *xattrs) |