mirror of
https://github.com/ostreedev/ostree.git
synced 2025-03-11 20:58:45 +03:00
Merge pull request #2565 from cgwalters/clang-format
Add .clang-format file + tree-wide: Run `clang-format`
This commit is contained in:
commit
8a2993a9d0
@ -2,3 +2,4 @@ Language: Cpp
|
||||
BasedOnStyle: GNU
|
||||
ColumnLimit: 100
|
||||
ForEachMacros: ['GLNX_HASH_TABLE_FOREACH', 'GLNX_HASH_TABLE_FOREACH_V', 'GLNX_HASH_TABLE_FOREACH_KV', 'GLNX_HASH_TABLE_FOREACH_IT']
|
||||
AlignEscapedNewlines: DontAlign
|
||||
|
@ -15,12 +15,23 @@ done
|
||||
echo "ok"
|
||||
fi
|
||||
|
||||
# Will uncomment this once we reformat
|
||||
#if command -v clang-format; then
|
||||
# echo -n "checking clang-format... "
|
||||
# git ls-files '**.c' '**.cxx' '**.h' '**.hpp' | xargs clang-format --Werror --dry-run
|
||||
# echo "ok"
|
||||
#fi
|
||||
if command -v clang-format; then
|
||||
clang_ver=$(clang-format --version)
|
||||
clang_min_ver=15
|
||||
version_re=" version ([0-9]+)."
|
||||
if [[ $clang_ver =~ $version_re ]]; then
|
||||
if test "${BASH_REMATCH[1]}" -ge "${clang_min_ver}"; then
|
||||
echo -n "checking clang-format... "
|
||||
git ls-files '**.c' '**.cxx' '**.h' '**.hpp' | xargs clang-format --Werror --dry-run
|
||||
echo "ok"
|
||||
else
|
||||
echo "notice: clang-format ${clang_ver}" is too old
|
||||
fi
|
||||
else
|
||||
echo "failed to parse clang-format version ${clang_ver}" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -n 'grep-based static analysis... '
|
||||
patterns=(glnx_fd_close)
|
||||
|
@ -6,172 +6,174 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define PRINT_CONSTANT(CONSTANT_NAME) \
|
||||
printf("%s;", #CONSTANT_NAME); \
|
||||
printf(_Generic((CONSTANT_NAME), \
|
||||
char *: "%s", \
|
||||
const char *: "%s", \
|
||||
char: "%c", \
|
||||
signed char: "%hhd", \
|
||||
unsigned char: "%hhu", \
|
||||
short int: "%hd", \
|
||||
unsigned short int: "%hu", \
|
||||
int: "%d", \
|
||||
unsigned int: "%u", \
|
||||
long: "%ld", \
|
||||
unsigned long: "%lu", \
|
||||
long long: "%lld", \
|
||||
unsigned long long: "%llu", \
|
||||
float: "%f", \
|
||||
double: "%f", \
|
||||
long double: "%ld"), \
|
||||
CONSTANT_NAME); \
|
||||
printf("\n");
|
||||
printf ("%s;", #CONSTANT_NAME); \
|
||||
printf (_Generic ((CONSTANT_NAME), \
|
||||
char *: "%s", \
|
||||
const char *: "%s", \
|
||||
char: "%c", \
|
||||
signed char: "%hhd", \
|
||||
unsigned char: "%hhu", \
|
||||
short int: "%hd", \
|
||||
unsigned short int: "%hu", \
|
||||
int: "%d", \
|
||||
unsigned int: "%u", \
|
||||
long: "%ld", \
|
||||
unsigned long: "%lu", \
|
||||
long long: "%lld", \
|
||||
unsigned long long: "%llu", \
|
||||
float: "%f", \
|
||||
double: "%f", \
|
||||
long double: "%ld"), \
|
||||
CONSTANT_NAME); \
|
||||
printf ("\n");
|
||||
|
||||
int main() {
|
||||
PRINT_CONSTANT((guint) OSTREE_CHECKSUM_FLAGS_CANONICAL_PERMISSIONS);
|
||||
PRINT_CONSTANT((guint) OSTREE_CHECKSUM_FLAGS_IGNORE_XATTRS);
|
||||
PRINT_CONSTANT((guint) OSTREE_CHECKSUM_FLAGS_NONE);
|
||||
PRINT_CONSTANT(OSTREE_COMMIT_GVARIANT_STRING);
|
||||
PRINT_CONSTANT(OSTREE_COMMIT_META_KEY_ARCHITECTURE);
|
||||
PRINT_CONSTANT(OSTREE_COMMIT_META_KEY_COLLECTION_BINDING);
|
||||
PRINT_CONSTANT(OSTREE_COMMIT_META_KEY_ENDOFLIFE);
|
||||
PRINT_CONSTANT(OSTREE_COMMIT_META_KEY_ENDOFLIFE_REBASE);
|
||||
PRINT_CONSTANT(OSTREE_COMMIT_META_KEY_REF_BINDING);
|
||||
PRINT_CONSTANT(OSTREE_COMMIT_META_KEY_SOURCE_TITLE);
|
||||
PRINT_CONSTANT(OSTREE_COMMIT_META_KEY_VERSION);
|
||||
PRINT_CONSTANT((gint) OSTREE_DEPLOYMENT_UNLOCKED_DEVELOPMENT);
|
||||
PRINT_CONSTANT((gint) OSTREE_DEPLOYMENT_UNLOCKED_HOTFIX);
|
||||
PRINT_CONSTANT((gint) OSTREE_DEPLOYMENT_UNLOCKED_NONE);
|
||||
PRINT_CONSTANT((gint) OSTREE_DEPLOYMENT_UNLOCKED_TRANSIENT);
|
||||
PRINT_CONSTANT((guint) OSTREE_DIFF_FLAGS_IGNORE_XATTRS);
|
||||
PRINT_CONSTANT((guint) OSTREE_DIFF_FLAGS_NONE);
|
||||
PRINT_CONSTANT(OSTREE_DIRMETA_GVARIANT_STRING);
|
||||
PRINT_CONSTANT(OSTREE_FILEMETA_GVARIANT_STRING);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_ERROR_EXPIRED_KEY);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_ERROR_EXPIRED_SIGNATURE);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_ERROR_INVALID_SIGNATURE);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_ERROR_MISSING_KEY);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_ERROR_NO_SIGNATURE);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_ERROR_REVOKED_KEY);
|
||||
PRINT_CONSTANT(OSTREE_GPG_KEY_GVARIANT_STRING);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_SIGNATURE_ATTR_EXP_TIMESTAMP);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_SIGNATURE_ATTR_FINGERPRINT);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_SIGNATURE_ATTR_FINGERPRINT_PRIMARY);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_SIGNATURE_ATTR_HASH_ALGO_NAME);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_SIGNATURE_ATTR_KEY_EXPIRED);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_SIGNATURE_ATTR_KEY_EXP_TIMESTAMP);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_SIGNATURE_ATTR_KEY_EXP_TIMESTAMP_PRIMARY);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_SIGNATURE_ATTR_KEY_MISSING);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_SIGNATURE_ATTR_KEY_REVOKED);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_SIGNATURE_ATTR_PUBKEY_ALGO_NAME);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_SIGNATURE_ATTR_SIG_EXPIRED);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_SIGNATURE_ATTR_TIMESTAMP);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_SIGNATURE_ATTR_USER_EMAIL);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_SIGNATURE_ATTR_USER_NAME);
|
||||
PRINT_CONSTANT((gint) OSTREE_GPG_SIGNATURE_ATTR_VALID);
|
||||
PRINT_CONSTANT((guint) OSTREE_GPG_SIGNATURE_FORMAT_DEFAULT);
|
||||
PRINT_CONSTANT(OSTREE_MAX_METADATA_SIZE);
|
||||
PRINT_CONSTANT(OSTREE_MAX_METADATA_WARN_SIZE);
|
||||
PRINT_CONSTANT(OSTREE_METADATA_KEY_BOOTABLE);
|
||||
PRINT_CONSTANT(OSTREE_METADATA_KEY_LINUX);
|
||||
PRINT_CONSTANT(OSTREE_META_KEY_DEPLOY_COLLECTION_ID);
|
||||
PRINT_CONSTANT((gint) OSTREE_OBJECT_TYPE_COMMIT);
|
||||
PRINT_CONSTANT((gint) OSTREE_OBJECT_TYPE_COMMIT_META);
|
||||
PRINT_CONSTANT((gint) OSTREE_OBJECT_TYPE_DIR_META);
|
||||
PRINT_CONSTANT((gint) OSTREE_OBJECT_TYPE_DIR_TREE);
|
||||
PRINT_CONSTANT((gint) OSTREE_OBJECT_TYPE_FILE);
|
||||
PRINT_CONSTANT((gint) OSTREE_OBJECT_TYPE_FILE_XATTRS);
|
||||
PRINT_CONSTANT((gint) OSTREE_OBJECT_TYPE_FILE_XATTRS_LINK);
|
||||
PRINT_CONSTANT((gint) OSTREE_OBJECT_TYPE_PAYLOAD_LINK);
|
||||
PRINT_CONSTANT((gint) OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT);
|
||||
PRINT_CONSTANT(OSTREE_ORIGIN_TRANSIENT_GROUP);
|
||||
PRINT_CONSTANT(OSTREE_PATH_BOOTED);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_CHECKOUT_FILTER_ALLOW);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_CHECKOUT_FILTER_SKIP);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_CHECKOUT_MODE_NONE);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_CHECKOUT_MODE_USER);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_CHECKOUT_OVERWRITE_ADD_FILES);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_CHECKOUT_OVERWRITE_NONE);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_FILES);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_IDENTICAL);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_COMMIT_FILTER_ALLOW);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_COMMIT_FILTER_SKIP);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_COMMIT_ITER_RESULT_DIR);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_COMMIT_ITER_RESULT_END);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_COMMIT_ITER_RESULT_ERROR);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_COMMIT_ITER_RESULT_FILE);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CONSUME);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_COMMIT_MODIFIER_FLAGS_DEVINO_CANONICAL);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_COMMIT_MODIFIER_FLAGS_ERROR_ON_UNLABELED);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_COMMIT_MODIFIER_FLAGS_NONE);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_COMMIT_STATE_FSCK_PARTIAL);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_COMMIT_STATE_NORMAL);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_COMMIT_STATE_PARTIAL);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_COMMIT_TRAVERSE_FLAG_COMMIT_ONLY);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_LIST_OBJECTS_ALL);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_LIST_OBJECTS_LOOSE);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_LIST_OBJECTS_NO_PARENTS);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_LIST_OBJECTS_PACKED);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_LIST_REFS_EXT_ALIASES);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_MIRRORS);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_LIST_REFS_EXT_NONE);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_LOCK_EXCLUSIVE);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_LOCK_SHARED);
|
||||
PRINT_CONSTANT(OSTREE_REPO_METADATA_REF);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_MODE_ARCHIVE);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_MODE_ARCHIVE_Z2);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_MODE_BARE);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_MODE_BARE_SPLIT_XATTRS);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_MODE_BARE_USER);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_MODE_BARE_USER_ONLY);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_PRUNE_FLAGS_COMMIT_ONLY);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_PRUNE_FLAGS_NONE);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_PRUNE_FLAGS_NO_PRUNE);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_PULL_FLAGS_BAREUSERONLY_FILES);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_PULL_FLAGS_COMMIT_ONLY);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_PULL_FLAGS_MIRROR);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_PULL_FLAGS_NONE);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_PULL_FLAGS_TRUSTED_HTTP);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_PULL_FLAGS_UNTRUSTED);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_REMOTE_CHANGE_ADD);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_REMOTE_CHANGE_ADD_IF_NOT_EXISTS);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_REMOTE_CHANGE_DELETE);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_REMOTE_CHANGE_DELETE_IF_EXISTS);
|
||||
PRINT_CONSTANT((gint) OSTREE_REPO_REMOTE_CHANGE_REPLACE);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_RESOLVE_REV_EXT_NONE);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_VERIFY_FLAGS_NONE);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_VERIFY_FLAGS_NO_GPG);
|
||||
PRINT_CONSTANT((guint) OSTREE_REPO_VERIFY_FLAGS_NO_SIGNAPI);
|
||||
PRINT_CONSTANT((guint) OSTREE_SEPOLICY_RESTORECON_FLAGS_ALLOW_NOLABEL);
|
||||
PRINT_CONSTANT((guint) OSTREE_SEPOLICY_RESTORECON_FLAGS_KEEP_EXISTING);
|
||||
PRINT_CONSTANT((guint) OSTREE_SEPOLICY_RESTORECON_FLAGS_NONE);
|
||||
PRINT_CONSTANT(OSTREE_SHA256_DIGEST_LEN);
|
||||
PRINT_CONSTANT(OSTREE_SHA256_STRING_LEN);
|
||||
PRINT_CONSTANT(OSTREE_SIGN_NAME_ED25519);
|
||||
PRINT_CONSTANT((gint) OSTREE_STATIC_DELTA_GENERATE_OPT_LOWLATENCY);
|
||||
PRINT_CONSTANT((gint) OSTREE_STATIC_DELTA_GENERATE_OPT_MAJOR);
|
||||
PRINT_CONSTANT((gint) OSTREE_STATIC_DELTA_INDEX_FLAGS_NONE);
|
||||
PRINT_CONSTANT(OSTREE_SUMMARY_GVARIANT_STRING);
|
||||
PRINT_CONSTANT(OSTREE_SUMMARY_SIG_GVARIANT_STRING);
|
||||
PRINT_CONSTANT((guint) OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NONE);
|
||||
PRINT_CONSTANT((guint) OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NOT_DEFAULT);
|
||||
PRINT_CONSTANT((guint) OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NO_CLEAN);
|
||||
PRINT_CONSTANT((guint) OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN);
|
||||
PRINT_CONSTANT((guint) OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN_PENDING);
|
||||
PRINT_CONSTANT((guint) OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN_ROLLBACK);
|
||||
PRINT_CONSTANT((guint) OSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED);
|
||||
PRINT_CONSTANT((guint) OSTREE_SYSROOT_UPGRADER_FLAGS_STAGE);
|
||||
PRINT_CONSTANT((guint) OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_ALLOW_OLDER);
|
||||
PRINT_CONSTANT((guint) OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_NONE);
|
||||
PRINT_CONSTANT((guint) OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_SYNTHETIC);
|
||||
PRINT_CONSTANT(OSTREE_TIMESTAMP);
|
||||
PRINT_CONSTANT(OSTREE_TREE_GVARIANT_STRING);
|
||||
return 0;
|
||||
int
|
||||
main ()
|
||||
{
|
||||
PRINT_CONSTANT ((guint)OSTREE_CHECKSUM_FLAGS_CANONICAL_PERMISSIONS);
|
||||
PRINT_CONSTANT ((guint)OSTREE_CHECKSUM_FLAGS_IGNORE_XATTRS);
|
||||
PRINT_CONSTANT ((guint)OSTREE_CHECKSUM_FLAGS_NONE);
|
||||
PRINT_CONSTANT (OSTREE_COMMIT_GVARIANT_STRING);
|
||||
PRINT_CONSTANT (OSTREE_COMMIT_META_KEY_ARCHITECTURE);
|
||||
PRINT_CONSTANT (OSTREE_COMMIT_META_KEY_COLLECTION_BINDING);
|
||||
PRINT_CONSTANT (OSTREE_COMMIT_META_KEY_ENDOFLIFE);
|
||||
PRINT_CONSTANT (OSTREE_COMMIT_META_KEY_ENDOFLIFE_REBASE);
|
||||
PRINT_CONSTANT (OSTREE_COMMIT_META_KEY_REF_BINDING);
|
||||
PRINT_CONSTANT (OSTREE_COMMIT_META_KEY_SOURCE_TITLE);
|
||||
PRINT_CONSTANT (OSTREE_COMMIT_META_KEY_VERSION);
|
||||
PRINT_CONSTANT ((gint)OSTREE_DEPLOYMENT_UNLOCKED_DEVELOPMENT);
|
||||
PRINT_CONSTANT ((gint)OSTREE_DEPLOYMENT_UNLOCKED_HOTFIX);
|
||||
PRINT_CONSTANT ((gint)OSTREE_DEPLOYMENT_UNLOCKED_NONE);
|
||||
PRINT_CONSTANT ((gint)OSTREE_DEPLOYMENT_UNLOCKED_TRANSIENT);
|
||||
PRINT_CONSTANT ((guint)OSTREE_DIFF_FLAGS_IGNORE_XATTRS);
|
||||
PRINT_CONSTANT ((guint)OSTREE_DIFF_FLAGS_NONE);
|
||||
PRINT_CONSTANT (OSTREE_DIRMETA_GVARIANT_STRING);
|
||||
PRINT_CONSTANT (OSTREE_FILEMETA_GVARIANT_STRING);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_ERROR_EXPIRED_KEY);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_ERROR_EXPIRED_SIGNATURE);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_ERROR_INVALID_SIGNATURE);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_ERROR_MISSING_KEY);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_ERROR_NO_SIGNATURE);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_ERROR_REVOKED_KEY);
|
||||
PRINT_CONSTANT (OSTREE_GPG_KEY_GVARIANT_STRING);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_SIGNATURE_ATTR_EXP_TIMESTAMP);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_SIGNATURE_ATTR_FINGERPRINT);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_SIGNATURE_ATTR_FINGERPRINT_PRIMARY);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_SIGNATURE_ATTR_HASH_ALGO_NAME);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_SIGNATURE_ATTR_KEY_EXPIRED);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_SIGNATURE_ATTR_KEY_EXP_TIMESTAMP);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_SIGNATURE_ATTR_KEY_EXP_TIMESTAMP_PRIMARY);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_SIGNATURE_ATTR_KEY_MISSING);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_SIGNATURE_ATTR_KEY_REVOKED);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_SIGNATURE_ATTR_PUBKEY_ALGO_NAME);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_SIGNATURE_ATTR_SIG_EXPIRED);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_SIGNATURE_ATTR_TIMESTAMP);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_SIGNATURE_ATTR_USER_EMAIL);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_SIGNATURE_ATTR_USER_NAME);
|
||||
PRINT_CONSTANT ((gint)OSTREE_GPG_SIGNATURE_ATTR_VALID);
|
||||
PRINT_CONSTANT ((guint)OSTREE_GPG_SIGNATURE_FORMAT_DEFAULT);
|
||||
PRINT_CONSTANT (OSTREE_MAX_METADATA_SIZE);
|
||||
PRINT_CONSTANT (OSTREE_MAX_METADATA_WARN_SIZE);
|
||||
PRINT_CONSTANT (OSTREE_METADATA_KEY_BOOTABLE);
|
||||
PRINT_CONSTANT (OSTREE_METADATA_KEY_LINUX);
|
||||
PRINT_CONSTANT (OSTREE_META_KEY_DEPLOY_COLLECTION_ID);
|
||||
PRINT_CONSTANT ((gint)OSTREE_OBJECT_TYPE_COMMIT);
|
||||
PRINT_CONSTANT ((gint)OSTREE_OBJECT_TYPE_COMMIT_META);
|
||||
PRINT_CONSTANT ((gint)OSTREE_OBJECT_TYPE_DIR_META);
|
||||
PRINT_CONSTANT ((gint)OSTREE_OBJECT_TYPE_DIR_TREE);
|
||||
PRINT_CONSTANT ((gint)OSTREE_OBJECT_TYPE_FILE);
|
||||
PRINT_CONSTANT ((gint)OSTREE_OBJECT_TYPE_FILE_XATTRS);
|
||||
PRINT_CONSTANT ((gint)OSTREE_OBJECT_TYPE_FILE_XATTRS_LINK);
|
||||
PRINT_CONSTANT ((gint)OSTREE_OBJECT_TYPE_PAYLOAD_LINK);
|
||||
PRINT_CONSTANT ((gint)OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT);
|
||||
PRINT_CONSTANT (OSTREE_ORIGIN_TRANSIENT_GROUP);
|
||||
PRINT_CONSTANT (OSTREE_PATH_BOOTED);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_CHECKOUT_FILTER_ALLOW);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_CHECKOUT_FILTER_SKIP);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_CHECKOUT_MODE_NONE);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_CHECKOUT_MODE_USER);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_CHECKOUT_OVERWRITE_ADD_FILES);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_CHECKOUT_OVERWRITE_NONE);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_FILES);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_IDENTICAL);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_COMMIT_FILTER_ALLOW);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_COMMIT_FILTER_SKIP);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_COMMIT_ITER_RESULT_DIR);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_COMMIT_ITER_RESULT_END);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_COMMIT_ITER_RESULT_ERROR);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_COMMIT_ITER_RESULT_FILE);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CONSUME);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_COMMIT_MODIFIER_FLAGS_DEVINO_CANONICAL);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_COMMIT_MODIFIER_FLAGS_ERROR_ON_UNLABELED);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_COMMIT_MODIFIER_FLAGS_NONE);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_COMMIT_STATE_FSCK_PARTIAL);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_COMMIT_STATE_NORMAL);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_COMMIT_STATE_PARTIAL);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_COMMIT_TRAVERSE_FLAG_COMMIT_ONLY);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_LIST_OBJECTS_ALL);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_LIST_OBJECTS_LOOSE);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_LIST_OBJECTS_NO_PARENTS);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_LIST_OBJECTS_PACKED);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_LIST_REFS_EXT_ALIASES);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_MIRRORS);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_LIST_REFS_EXT_NONE);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_LOCK_EXCLUSIVE);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_LOCK_SHARED);
|
||||
PRINT_CONSTANT (OSTREE_REPO_METADATA_REF);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_MODE_ARCHIVE);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_MODE_ARCHIVE_Z2);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_MODE_BARE);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_MODE_BARE_SPLIT_XATTRS);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_MODE_BARE_USER);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_MODE_BARE_USER_ONLY);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_PRUNE_FLAGS_COMMIT_ONLY);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_PRUNE_FLAGS_NONE);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_PRUNE_FLAGS_NO_PRUNE);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_PULL_FLAGS_BAREUSERONLY_FILES);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_PULL_FLAGS_COMMIT_ONLY);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_PULL_FLAGS_MIRROR);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_PULL_FLAGS_NONE);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_PULL_FLAGS_TRUSTED_HTTP);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_PULL_FLAGS_UNTRUSTED);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_REMOTE_CHANGE_ADD);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_REMOTE_CHANGE_ADD_IF_NOT_EXISTS);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_REMOTE_CHANGE_DELETE);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_REMOTE_CHANGE_DELETE_IF_EXISTS);
|
||||
PRINT_CONSTANT ((gint)OSTREE_REPO_REMOTE_CHANGE_REPLACE);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_RESOLVE_REV_EXT_NONE);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_VERIFY_FLAGS_NONE);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_VERIFY_FLAGS_NO_GPG);
|
||||
PRINT_CONSTANT ((guint)OSTREE_REPO_VERIFY_FLAGS_NO_SIGNAPI);
|
||||
PRINT_CONSTANT ((guint)OSTREE_SEPOLICY_RESTORECON_FLAGS_ALLOW_NOLABEL);
|
||||
PRINT_CONSTANT ((guint)OSTREE_SEPOLICY_RESTORECON_FLAGS_KEEP_EXISTING);
|
||||
PRINT_CONSTANT ((guint)OSTREE_SEPOLICY_RESTORECON_FLAGS_NONE);
|
||||
PRINT_CONSTANT (OSTREE_SHA256_DIGEST_LEN);
|
||||
PRINT_CONSTANT (OSTREE_SHA256_STRING_LEN);
|
||||
PRINT_CONSTANT (OSTREE_SIGN_NAME_ED25519);
|
||||
PRINT_CONSTANT ((gint)OSTREE_STATIC_DELTA_GENERATE_OPT_LOWLATENCY);
|
||||
PRINT_CONSTANT ((gint)OSTREE_STATIC_DELTA_GENERATE_OPT_MAJOR);
|
||||
PRINT_CONSTANT ((gint)OSTREE_STATIC_DELTA_INDEX_FLAGS_NONE);
|
||||
PRINT_CONSTANT (OSTREE_SUMMARY_GVARIANT_STRING);
|
||||
PRINT_CONSTANT (OSTREE_SUMMARY_SIG_GVARIANT_STRING);
|
||||
PRINT_CONSTANT ((guint)OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NONE);
|
||||
PRINT_CONSTANT ((guint)OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NOT_DEFAULT);
|
||||
PRINT_CONSTANT ((guint)OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NO_CLEAN);
|
||||
PRINT_CONSTANT ((guint)OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN);
|
||||
PRINT_CONSTANT ((guint)OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN_PENDING);
|
||||
PRINT_CONSTANT ((guint)OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN_ROLLBACK);
|
||||
PRINT_CONSTANT ((guint)OSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED);
|
||||
PRINT_CONSTANT ((guint)OSTREE_SYSROOT_UPGRADER_FLAGS_STAGE);
|
||||
PRINT_CONSTANT ((guint)OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_ALLOW_OLDER);
|
||||
PRINT_CONSTANT ((guint)OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_NONE);
|
||||
PRINT_CONSTANT ((guint)OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_SYNTHETIC);
|
||||
PRINT_CONSTANT (OSTREE_TIMESTAMP);
|
||||
PRINT_CONSTANT (OSTREE_TREE_GVARIANT_STRING);
|
||||
return 0;
|
||||
}
|
||||
|
@ -6,60 +6,113 @@
|
||||
#include <stdalign.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("%s;%zu;%zu\n", "OstreeAsyncProgressClass", sizeof(OstreeAsyncProgressClass), alignof(OstreeAsyncProgressClass));
|
||||
printf("%s;%zu;%zu\n", "OstreeChecksumFlags", sizeof(OstreeChecksumFlags), alignof(OstreeChecksumFlags));
|
||||
printf("%s;%zu;%zu\n", "OstreeCollectionRef", sizeof(OstreeCollectionRef), alignof(OstreeCollectionRef));
|
||||
printf("%s;%zu;%zu\n", "OstreeCollectionRefv", sizeof(OstreeCollectionRefv), alignof(OstreeCollectionRefv));
|
||||
printf("%s;%zu;%zu\n", "OstreeCommitSizesEntry", sizeof(OstreeCommitSizesEntry), alignof(OstreeCommitSizesEntry));
|
||||
printf("%s;%zu;%zu\n", "OstreeContentWriterClass", sizeof(OstreeContentWriterClass), alignof(OstreeContentWriterClass));
|
||||
printf("%s;%zu;%zu\n", "OstreeDeploymentUnlockedState", sizeof(OstreeDeploymentUnlockedState), alignof(OstreeDeploymentUnlockedState));
|
||||
printf("%s;%zu;%zu\n", "OstreeDiffDirsOptions", sizeof(OstreeDiffDirsOptions), alignof(OstreeDiffDirsOptions));
|
||||
printf("%s;%zu;%zu\n", "OstreeDiffFlags", sizeof(OstreeDiffFlags), alignof(OstreeDiffFlags));
|
||||
printf("%s;%zu;%zu\n", "OstreeDiffItem", sizeof(OstreeDiffItem), alignof(OstreeDiffItem));
|
||||
printf("%s;%zu;%zu\n", "OstreeGpgError", sizeof(OstreeGpgError), alignof(OstreeGpgError));
|
||||
printf("%s;%zu;%zu\n", "OstreeGpgSignatureAttr", sizeof(OstreeGpgSignatureAttr), alignof(OstreeGpgSignatureAttr));
|
||||
printf("%s;%zu;%zu\n", "OstreeGpgSignatureFormatFlags", sizeof(OstreeGpgSignatureFormatFlags), alignof(OstreeGpgSignatureFormatFlags));
|
||||
printf("%s;%zu;%zu\n", "OstreeMutableTreeClass", sizeof(OstreeMutableTreeClass), alignof(OstreeMutableTreeClass));
|
||||
printf("%s;%zu;%zu\n", "OstreeMutableTreeIter", sizeof(OstreeMutableTreeIter), alignof(OstreeMutableTreeIter));
|
||||
printf("%s;%zu;%zu\n", "OstreeObjectType", sizeof(OstreeObjectType), alignof(OstreeObjectType));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoCheckoutAtOptions", sizeof(OstreeRepoCheckoutAtOptions), alignof(OstreeRepoCheckoutAtOptions));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoCheckoutFilterResult", sizeof(OstreeRepoCheckoutFilterResult), alignof(OstreeRepoCheckoutFilterResult));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoCheckoutMode", sizeof(OstreeRepoCheckoutMode), alignof(OstreeRepoCheckoutMode));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoCheckoutOverwriteMode", sizeof(OstreeRepoCheckoutOverwriteMode), alignof(OstreeRepoCheckoutOverwriteMode));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoCommitFilterResult", sizeof(OstreeRepoCommitFilterResult), alignof(OstreeRepoCommitFilterResult));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoCommitIterResult", sizeof(OstreeRepoCommitIterResult), alignof(OstreeRepoCommitIterResult));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoCommitModifierFlags", sizeof(OstreeRepoCommitModifierFlags), alignof(OstreeRepoCommitModifierFlags));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoCommitState", sizeof(OstreeRepoCommitState), alignof(OstreeRepoCommitState));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoCommitTraverseFlags", sizeof(OstreeRepoCommitTraverseFlags), alignof(OstreeRepoCommitTraverseFlags));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoCommitTraverseIter", sizeof(OstreeRepoCommitTraverseIter), alignof(OstreeRepoCommitTraverseIter));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoFileClass", sizeof(OstreeRepoFileClass), alignof(OstreeRepoFileClass));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoFinderAvahiClass", sizeof(OstreeRepoFinderAvahiClass), alignof(OstreeRepoFinderAvahiClass));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoFinderConfigClass", sizeof(OstreeRepoFinderConfigClass), alignof(OstreeRepoFinderConfigClass));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoFinderInterface", sizeof(OstreeRepoFinderInterface), alignof(OstreeRepoFinderInterface));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoFinderMountClass", sizeof(OstreeRepoFinderMountClass), alignof(OstreeRepoFinderMountClass));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoFinderOverrideClass", sizeof(OstreeRepoFinderOverrideClass), alignof(OstreeRepoFinderOverrideClass));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoFinderResult", sizeof(OstreeRepoFinderResult), alignof(OstreeRepoFinderResult));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoFinderResultv", sizeof(OstreeRepoFinderResultv), alignof(OstreeRepoFinderResultv));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoListObjectsFlags", sizeof(OstreeRepoListObjectsFlags), alignof(OstreeRepoListObjectsFlags));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoListRefsExtFlags", sizeof(OstreeRepoListRefsExtFlags), alignof(OstreeRepoListRefsExtFlags));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoLockType", sizeof(OstreeRepoLockType), alignof(OstreeRepoLockType));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoMode", sizeof(OstreeRepoMode), alignof(OstreeRepoMode));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoPruneFlags", sizeof(OstreeRepoPruneFlags), alignof(OstreeRepoPruneFlags));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoPruneOptions", sizeof(OstreeRepoPruneOptions), alignof(OstreeRepoPruneOptions));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoPullFlags", sizeof(OstreeRepoPullFlags), alignof(OstreeRepoPullFlags));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoRemoteChange", sizeof(OstreeRepoRemoteChange), alignof(OstreeRepoRemoteChange));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoResolveRevExtFlags", sizeof(OstreeRepoResolveRevExtFlags), alignof(OstreeRepoResolveRevExtFlags));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoTransactionStats", sizeof(OstreeRepoTransactionStats), alignof(OstreeRepoTransactionStats));
|
||||
printf("%s;%zu;%zu\n", "OstreeRepoVerifyFlags", sizeof(OstreeRepoVerifyFlags), alignof(OstreeRepoVerifyFlags));
|
||||
printf("%s;%zu;%zu\n", "OstreeSePolicyRestoreconFlags", sizeof(OstreeSePolicyRestoreconFlags), alignof(OstreeSePolicyRestoreconFlags));
|
||||
printf("%s;%zu;%zu\n", "OstreeSignInterface", sizeof(OstreeSignInterface), alignof(OstreeSignInterface));
|
||||
printf("%s;%zu;%zu\n", "OstreeStaticDeltaGenerateOpt", sizeof(OstreeStaticDeltaGenerateOpt), alignof(OstreeStaticDeltaGenerateOpt));
|
||||
printf("%s;%zu;%zu\n", "OstreeStaticDeltaIndexFlags", sizeof(OstreeStaticDeltaIndexFlags), alignof(OstreeStaticDeltaIndexFlags));
|
||||
printf("%s;%zu;%zu\n", "OstreeSysrootDeployTreeOpts", sizeof(OstreeSysrootDeployTreeOpts), alignof(OstreeSysrootDeployTreeOpts));
|
||||
printf("%s;%zu;%zu\n", "OstreeSysrootSimpleWriteDeploymentFlags", sizeof(OstreeSysrootSimpleWriteDeploymentFlags), alignof(OstreeSysrootSimpleWriteDeploymentFlags));
|
||||
printf("%s;%zu;%zu\n", "OstreeSysrootUpgraderFlags", sizeof(OstreeSysrootUpgraderFlags), alignof(OstreeSysrootUpgraderFlags));
|
||||
printf("%s;%zu;%zu\n", "OstreeSysrootUpgraderPullFlags", sizeof(OstreeSysrootUpgraderPullFlags), alignof(OstreeSysrootUpgraderPullFlags));
|
||||
printf("%s;%zu;%zu\n", "OstreeSysrootWriteDeploymentsOpts", sizeof(OstreeSysrootWriteDeploymentsOpts), alignof(OstreeSysrootWriteDeploymentsOpts));
|
||||
return 0;
|
||||
int
|
||||
main ()
|
||||
{
|
||||
printf ("%s;%zu;%zu\n", "OstreeAsyncProgressClass", sizeof (OstreeAsyncProgressClass),
|
||||
alignof (OstreeAsyncProgressClass));
|
||||
printf ("%s;%zu;%zu\n", "OstreeChecksumFlags", sizeof (OstreeChecksumFlags),
|
||||
alignof (OstreeChecksumFlags));
|
||||
printf ("%s;%zu;%zu\n", "OstreeCollectionRef", sizeof (OstreeCollectionRef),
|
||||
alignof (OstreeCollectionRef));
|
||||
printf ("%s;%zu;%zu\n", "OstreeCollectionRefv", sizeof (OstreeCollectionRefv),
|
||||
alignof (OstreeCollectionRefv));
|
||||
printf ("%s;%zu;%zu\n", "OstreeCommitSizesEntry", sizeof (OstreeCommitSizesEntry),
|
||||
alignof (OstreeCommitSizesEntry));
|
||||
printf ("%s;%zu;%zu\n", "OstreeContentWriterClass", sizeof (OstreeContentWriterClass),
|
||||
alignof (OstreeContentWriterClass));
|
||||
printf ("%s;%zu;%zu\n", "OstreeDeploymentUnlockedState", sizeof (OstreeDeploymentUnlockedState),
|
||||
alignof (OstreeDeploymentUnlockedState));
|
||||
printf ("%s;%zu;%zu\n", "OstreeDiffDirsOptions", sizeof (OstreeDiffDirsOptions),
|
||||
alignof (OstreeDiffDirsOptions));
|
||||
printf ("%s;%zu;%zu\n", "OstreeDiffFlags", sizeof (OstreeDiffFlags), alignof (OstreeDiffFlags));
|
||||
printf ("%s;%zu;%zu\n", "OstreeDiffItem", sizeof (OstreeDiffItem), alignof (OstreeDiffItem));
|
||||
printf ("%s;%zu;%zu\n", "OstreeGpgError", sizeof (OstreeGpgError), alignof (OstreeGpgError));
|
||||
printf ("%s;%zu;%zu\n", "OstreeGpgSignatureAttr", sizeof (OstreeGpgSignatureAttr),
|
||||
alignof (OstreeGpgSignatureAttr));
|
||||
printf ("%s;%zu;%zu\n", "OstreeGpgSignatureFormatFlags", sizeof (OstreeGpgSignatureFormatFlags),
|
||||
alignof (OstreeGpgSignatureFormatFlags));
|
||||
printf ("%s;%zu;%zu\n", "OstreeMutableTreeClass", sizeof (OstreeMutableTreeClass),
|
||||
alignof (OstreeMutableTreeClass));
|
||||
printf ("%s;%zu;%zu\n", "OstreeMutableTreeIter", sizeof (OstreeMutableTreeIter),
|
||||
alignof (OstreeMutableTreeIter));
|
||||
printf ("%s;%zu;%zu\n", "OstreeObjectType", sizeof (OstreeObjectType),
|
||||
alignof (OstreeObjectType));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoCheckoutAtOptions", sizeof (OstreeRepoCheckoutAtOptions),
|
||||
alignof (OstreeRepoCheckoutAtOptions));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoCheckoutFilterResult", sizeof (OstreeRepoCheckoutFilterResult),
|
||||
alignof (OstreeRepoCheckoutFilterResult));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoCheckoutMode", sizeof (OstreeRepoCheckoutMode),
|
||||
alignof (OstreeRepoCheckoutMode));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoCheckoutOverwriteMode",
|
||||
sizeof (OstreeRepoCheckoutOverwriteMode), alignof (OstreeRepoCheckoutOverwriteMode));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoCommitFilterResult", sizeof (OstreeRepoCommitFilterResult),
|
||||
alignof (OstreeRepoCommitFilterResult));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoCommitIterResult", sizeof (OstreeRepoCommitIterResult),
|
||||
alignof (OstreeRepoCommitIterResult));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoCommitModifierFlags", sizeof (OstreeRepoCommitModifierFlags),
|
||||
alignof (OstreeRepoCommitModifierFlags));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoCommitState", sizeof (OstreeRepoCommitState),
|
||||
alignof (OstreeRepoCommitState));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoCommitTraverseFlags", sizeof (OstreeRepoCommitTraverseFlags),
|
||||
alignof (OstreeRepoCommitTraverseFlags));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoCommitTraverseIter", sizeof (OstreeRepoCommitTraverseIter),
|
||||
alignof (OstreeRepoCommitTraverseIter));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoFileClass", sizeof (OstreeRepoFileClass),
|
||||
alignof (OstreeRepoFileClass));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoFinderAvahiClass", sizeof (OstreeRepoFinderAvahiClass),
|
||||
alignof (OstreeRepoFinderAvahiClass));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoFinderConfigClass", sizeof (OstreeRepoFinderConfigClass),
|
||||
alignof (OstreeRepoFinderConfigClass));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoFinderInterface", sizeof (OstreeRepoFinderInterface),
|
||||
alignof (OstreeRepoFinderInterface));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoFinderMountClass", sizeof (OstreeRepoFinderMountClass),
|
||||
alignof (OstreeRepoFinderMountClass));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoFinderOverrideClass", sizeof (OstreeRepoFinderOverrideClass),
|
||||
alignof (OstreeRepoFinderOverrideClass));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoFinderResult", sizeof (OstreeRepoFinderResult),
|
||||
alignof (OstreeRepoFinderResult));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoFinderResultv", sizeof (OstreeRepoFinderResultv),
|
||||
alignof (OstreeRepoFinderResultv));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoListObjectsFlags", sizeof (OstreeRepoListObjectsFlags),
|
||||
alignof (OstreeRepoListObjectsFlags));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoListRefsExtFlags", sizeof (OstreeRepoListRefsExtFlags),
|
||||
alignof (OstreeRepoListRefsExtFlags));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoLockType", sizeof (OstreeRepoLockType),
|
||||
alignof (OstreeRepoLockType));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoMode", sizeof (OstreeRepoMode), alignof (OstreeRepoMode));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoPruneFlags", sizeof (OstreeRepoPruneFlags),
|
||||
alignof (OstreeRepoPruneFlags));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoPruneOptions", sizeof (OstreeRepoPruneOptions),
|
||||
alignof (OstreeRepoPruneOptions));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoPullFlags", sizeof (OstreeRepoPullFlags),
|
||||
alignof (OstreeRepoPullFlags));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoRemoteChange", sizeof (OstreeRepoRemoteChange),
|
||||
alignof (OstreeRepoRemoteChange));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoResolveRevExtFlags", sizeof (OstreeRepoResolveRevExtFlags),
|
||||
alignof (OstreeRepoResolveRevExtFlags));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoTransactionStats", sizeof (OstreeRepoTransactionStats),
|
||||
alignof (OstreeRepoTransactionStats));
|
||||
printf ("%s;%zu;%zu\n", "OstreeRepoVerifyFlags", sizeof (OstreeRepoVerifyFlags),
|
||||
alignof (OstreeRepoVerifyFlags));
|
||||
printf ("%s;%zu;%zu\n", "OstreeSePolicyRestoreconFlags", sizeof (OstreeSePolicyRestoreconFlags),
|
||||
alignof (OstreeSePolicyRestoreconFlags));
|
||||
printf ("%s;%zu;%zu\n", "OstreeSignInterface", sizeof (OstreeSignInterface),
|
||||
alignof (OstreeSignInterface));
|
||||
printf ("%s;%zu;%zu\n", "OstreeStaticDeltaGenerateOpt", sizeof (OstreeStaticDeltaGenerateOpt),
|
||||
alignof (OstreeStaticDeltaGenerateOpt));
|
||||
printf ("%s;%zu;%zu\n", "OstreeStaticDeltaIndexFlags", sizeof (OstreeStaticDeltaIndexFlags),
|
||||
alignof (OstreeStaticDeltaIndexFlags));
|
||||
printf ("%s;%zu;%zu\n", "OstreeSysrootDeployTreeOpts", sizeof (OstreeSysrootDeployTreeOpts),
|
||||
alignof (OstreeSysrootDeployTreeOpts));
|
||||
printf ("%s;%zu;%zu\n", "OstreeSysrootSimpleWriteDeploymentFlags",
|
||||
sizeof (OstreeSysrootSimpleWriteDeploymentFlags),
|
||||
alignof (OstreeSysrootSimpleWriteDeploymentFlags));
|
||||
printf ("%s;%zu;%zu\n", "OstreeSysrootUpgraderFlags", sizeof (OstreeSysrootUpgraderFlags),
|
||||
alignof (OstreeSysrootUpgraderFlags));
|
||||
printf ("%s;%zu;%zu\n", "OstreeSysrootUpgraderPullFlags", sizeof (OstreeSysrootUpgraderPullFlags),
|
||||
alignof (OstreeSysrootUpgraderPullFlags));
|
||||
printf ("%s;%zu;%zu\n", "OstreeSysrootWriteDeploymentsOpts",
|
||||
sizeof (OstreeSysrootWriteDeploymentsOpts), alignof (OstreeSysrootWriteDeploymentsOpts));
|
||||
return 0;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
// hack to build and test on versions of libostree < 2019.2
|
||||
#if !OSTREE_CHECK_VERSION(2019, 2)
|
||||
# define OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_MIRRORS 4
|
||||
# define OSTREE_REPO_REMOTE_CHANGE_REPLACE 4
|
||||
# define OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY 1
|
||||
#define OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_MIRRORS 4
|
||||
#define OSTREE_REPO_REMOTE_CHANGE_REPLACE 4
|
||||
#define OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY 1
|
||||
#endif
|
||||
|
@ -28,10 +28,10 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "bupsplit.h"
|
||||
#include <stdint.h>
|
||||
#include <memory.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// According to librsync/rollsum.h:
|
||||
// "We should make this something other than zero to improve the
|
||||
@ -40,79 +40,81 @@
|
||||
// slightly worse than the librsync value of 31 for my arbitrary test data.
|
||||
#define ROLLSUM_CHAR_OFFSET 31
|
||||
|
||||
typedef struct {
|
||||
unsigned s1, s2;
|
||||
uint8_t window[BUP_WINDOWSIZE];
|
||||
int wofs;
|
||||
typedef struct
|
||||
{
|
||||
unsigned s1, s2;
|
||||
uint8_t window[BUP_WINDOWSIZE];
|
||||
int wofs;
|
||||
} Rollsum;
|
||||
|
||||
|
||||
// These formulas are based on rollsum.h in the librsync project.
|
||||
static void rollsum_add(Rollsum *r, uint8_t drop, uint8_t add)
|
||||
static void
|
||||
rollsum_add (Rollsum *r, uint8_t drop, uint8_t add)
|
||||
{
|
||||
r->s1 += add - drop;
|
||||
r->s2 += r->s1 - (BUP_WINDOWSIZE * (drop + ROLLSUM_CHAR_OFFSET));
|
||||
r->s1 += add - drop;
|
||||
r->s2 += r->s1 - (BUP_WINDOWSIZE * (drop + ROLLSUM_CHAR_OFFSET));
|
||||
}
|
||||
|
||||
|
||||
static void rollsum_init(Rollsum *r)
|
||||
static void
|
||||
rollsum_init (Rollsum *r)
|
||||
{
|
||||
r->s1 = BUP_WINDOWSIZE * ROLLSUM_CHAR_OFFSET;
|
||||
r->s2 = BUP_WINDOWSIZE * (BUP_WINDOWSIZE-1) * ROLLSUM_CHAR_OFFSET;
|
||||
r->wofs = 0;
|
||||
memset(r->window, 0, BUP_WINDOWSIZE);
|
||||
r->s1 = BUP_WINDOWSIZE * ROLLSUM_CHAR_OFFSET;
|
||||
r->s2 = BUP_WINDOWSIZE * (BUP_WINDOWSIZE - 1) * ROLLSUM_CHAR_OFFSET;
|
||||
r->wofs = 0;
|
||||
memset (r->window, 0, BUP_WINDOWSIZE);
|
||||
}
|
||||
|
||||
|
||||
// For some reason, gcc 4.3 (at least) optimizes badly if find_ofs()
|
||||
// is static and rollsum_roll is an inline function. Let's use a macro
|
||||
// here instead to help out the optimizer.
|
||||
#define rollsum_roll(r, ch) do { \
|
||||
rollsum_add((r), (r)->window[(r)->wofs], (ch)); \
|
||||
(r)->window[(r)->wofs] = (ch); \
|
||||
(r)->wofs = ((r)->wofs + 1) % BUP_WINDOWSIZE; \
|
||||
} while (0)
|
||||
#define rollsum_roll(r, ch) \
|
||||
do \
|
||||
{ \
|
||||
rollsum_add ((r), (r)->window[(r)->wofs], (ch)); \
|
||||
(r)->window[(r)->wofs] = (ch); \
|
||||
(r)->wofs = ((r)->wofs + 1) % BUP_WINDOWSIZE; \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
|
||||
static uint32_t rollsum_digest(Rollsum *r)
|
||||
static uint32_t
|
||||
rollsum_digest (Rollsum *r)
|
||||
{
|
||||
return (r->s1 << 16) | (r->s2 & 0xffff);
|
||||
return (r->s1 << 16) | (r->s2 & 0xffff);
|
||||
}
|
||||
|
||||
|
||||
uint32_t
|
||||
bupsplit_sum(uint8_t *buf, size_t ofs, size_t len)
|
||||
bupsplit_sum (uint8_t *buf, size_t ofs, size_t len)
|
||||
{
|
||||
size_t count;
|
||||
Rollsum r;
|
||||
rollsum_init(&r);
|
||||
for (count = ofs; count < len; count++)
|
||||
rollsum_roll(&r, buf[count]);
|
||||
return rollsum_digest(&r);
|
||||
size_t count;
|
||||
Rollsum r;
|
||||
rollsum_init (&r);
|
||||
for (count = ofs; count < len; count++)
|
||||
rollsum_roll (&r, buf[count]);
|
||||
return rollsum_digest (&r);
|
||||
}
|
||||
|
||||
|
||||
int bupsplit_find_ofs(const unsigned char *buf, int len, int *bits)
|
||||
int
|
||||
bupsplit_find_ofs (const unsigned char *buf, int len, int *bits)
|
||||
{
|
||||
Rollsum r;
|
||||
int count;
|
||||
Rollsum r;
|
||||
int count;
|
||||
|
||||
rollsum_init(&r);
|
||||
for (count = 0; count < len; count++)
|
||||
rollsum_init (&r);
|
||||
for (count = 0; count < len; count++)
|
||||
{
|
||||
rollsum_roll(&r, buf[count]);
|
||||
if ((r.s2 & (BUP_BLOBSIZE-1)) == ((~0) & (BUP_BLOBSIZE-1)))
|
||||
{
|
||||
if (bits)
|
||||
{
|
||||
unsigned rsum = rollsum_digest(&r);
|
||||
*bits = BUP_BLOBBITS;
|
||||
rsum >>= BUP_BLOBBITS;
|
||||
for (*bits = BUP_BLOBBITS; (rsum >>= 1) & 1; (*bits)++)
|
||||
;
|
||||
}
|
||||
return count+1;
|
||||
}
|
||||
rollsum_roll (&r, buf[count]);
|
||||
if ((r.s2 & (BUP_BLOBSIZE - 1)) == ((~0) & (BUP_BLOBSIZE - 1)))
|
||||
{
|
||||
if (bits)
|
||||
{
|
||||
unsigned rsum = rollsum_digest (&r);
|
||||
*bits = BUP_BLOBBITS;
|
||||
rsum >>= BUP_BLOBBITS;
|
||||
for (*bits = BUP_BLOBBITS; (rsum >>= 1) & 1; (*bits)++)
|
||||
;
|
||||
}
|
||||
return count + 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -34,16 +34,17 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#define BUP_BLOBBITS (13)
|
||||
#define BUP_BLOBSIZE (1<<BUP_BLOBBITS)
|
||||
#define BUP_BLOBSIZE (1 << BUP_BLOBBITS)
|
||||
#define BUP_WINDOWBITS (7)
|
||||
#define BUP_WINDOWSIZE (1<<(BUP_WINDOWBITS-1))
|
||||
#define BUP_WINDOWSIZE (1 << (BUP_WINDOWBITS - 1))
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
uint32_t bupsplit_sum(uint8_t *buf, size_t ofs, size_t len);
|
||||
int bupsplit_find_ofs(const unsigned char *buf, int len, int *bits);
|
||||
uint32_t bupsplit_sum (uint8_t *buf, size_t ofs, size_t len);
|
||||
int bupsplit_find_ofs (const unsigned char *buf, int len, int *bits);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -45,7 +45,8 @@
|
||||
* must always have the correct type.
|
||||
*/
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
CHANGED,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
@ -59,7 +60,7 @@ struct OstreeAsyncProgress
|
||||
GMutex lock;
|
||||
GMainContext *maincontext;
|
||||
GSource *idle_source;
|
||||
GHashTable *values; /* (element-type uint GVariant) */
|
||||
GHashTable *values; /* (element-type uint GVariant) */
|
||||
|
||||
gboolean dead;
|
||||
};
|
||||
@ -94,14 +95,9 @@ ostree_async_progress_class_init (OstreeAsyncProgressClass *klass)
|
||||
*
|
||||
* Emitted when @self has been changed.
|
||||
**/
|
||||
signals[CHANGED] =
|
||||
g_signal_new ("changed",
|
||||
OSTREE_TYPE_ASYNC_PROGRESS,
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (OstreeAsyncProgressClass, changed),
|
||||
NULL, NULL,
|
||||
NULL,
|
||||
G_TYPE_NONE, 0);
|
||||
signals[CHANGED] = g_signal_new ("changed", OSTREE_TYPE_ASYNC_PROGRESS, G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (OstreeAsyncProgressClass, changed), NULL, NULL,
|
||||
NULL, G_TYPE_NONE, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -109,7 +105,7 @@ ostree_async_progress_init (OstreeAsyncProgress *self)
|
||||
{
|
||||
g_mutex_init (&self->lock);
|
||||
self->maincontext = g_main_context_ref_thread_default ();
|
||||
self->values = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_variant_unref);
|
||||
self->values = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)g_variant_unref);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,8 +121,7 @@ ostree_async_progress_init (OstreeAsyncProgress *self)
|
||||
* Since: 2017.6
|
||||
*/
|
||||
GVariant *
|
||||
ostree_async_progress_get_variant (OstreeAsyncProgress *self,
|
||||
const char *key)
|
||||
ostree_async_progress_get_variant (OstreeAsyncProgress *self, const char *key)
|
||||
{
|
||||
g_assert (OSTREE_IS_ASYNC_PROGRESS (self));
|
||||
|
||||
@ -145,18 +140,16 @@ ostree_async_progress_get_variant (OstreeAsyncProgress *self,
|
||||
}
|
||||
|
||||
guint
|
||||
ostree_async_progress_get_uint (OstreeAsyncProgress *self,
|
||||
const char *key)
|
||||
ostree_async_progress_get_uint (OstreeAsyncProgress *self, const char *key)
|
||||
{
|
||||
g_autoptr(GVariant) rval = ostree_async_progress_get_variant (self, key);
|
||||
g_autoptr (GVariant) rval = ostree_async_progress_get_variant (self, key);
|
||||
return (rval != NULL) ? g_variant_get_uint32 (rval) : 0;
|
||||
}
|
||||
|
||||
guint64
|
||||
ostree_async_progress_get_uint64 (OstreeAsyncProgress *self,
|
||||
const char *key)
|
||||
ostree_async_progress_get_uint64 (OstreeAsyncProgress *self, const char *key)
|
||||
{
|
||||
g_autoptr(GVariant) rval = ostree_async_progress_get_variant (self, key);
|
||||
g_autoptr (GVariant) rval = ostree_async_progress_get_variant (self, key);
|
||||
return (rval != NULL) ? g_variant_get_uint64 (rval) : 0;
|
||||
}
|
||||
|
||||
@ -194,8 +187,7 @@ ostree_async_progress_get_uint64 (OstreeAsyncProgress *self,
|
||||
* Since: 2017.6
|
||||
*/
|
||||
void
|
||||
ostree_async_progress_get (OstreeAsyncProgress *self,
|
||||
...)
|
||||
ostree_async_progress_get (OstreeAsyncProgress *self, ...)
|
||||
{
|
||||
va_list ap;
|
||||
const char *key, *format_string;
|
||||
@ -203,8 +195,7 @@ ostree_async_progress_get (OstreeAsyncProgress *self,
|
||||
g_mutex_lock (&self->lock);
|
||||
va_start (ap, self);
|
||||
|
||||
for (key = va_arg (ap, const char *), format_string = va_arg (ap, const char *);
|
||||
key != NULL;
|
||||
for (key = va_arg (ap, const char *), format_string = va_arg (ap, const char *); key != NULL;
|
||||
key = va_arg (ap, const char *), format_string = va_arg (ap, const char *))
|
||||
{
|
||||
GVariant *variant;
|
||||
@ -259,8 +250,7 @@ ensure_callback_locked (OstreeAsyncProgress *self)
|
||||
* Since: 2017.6
|
||||
*/
|
||||
void
|
||||
ostree_async_progress_set_status (OstreeAsyncProgress *self,
|
||||
const char *status)
|
||||
ostree_async_progress_set_status (OstreeAsyncProgress *self, const char *status)
|
||||
{
|
||||
ostree_async_progress_set_variant (self, "status",
|
||||
g_variant_new_string ((status != NULL) ? status : ""));
|
||||
@ -280,9 +270,9 @@ ostree_async_progress_set_status (OstreeAsyncProgress *self,
|
||||
* Since: 2017.6
|
||||
*/
|
||||
char *
|
||||
ostree_async_progress_get_status (OstreeAsyncProgress *self)
|
||||
ostree_async_progress_get_status (OstreeAsyncProgress *self)
|
||||
{
|
||||
g_autoptr(GVariant) rval = ostree_async_progress_get_variant (self, "status");
|
||||
g_autoptr (GVariant) rval = ostree_async_progress_get_variant (self, "status");
|
||||
const gchar *status = (rval != NULL) ? g_variant_get_string (rval, NULL) : NULL;
|
||||
if (status != NULL && *status == '\0')
|
||||
status = NULL;
|
||||
@ -320,8 +310,7 @@ ostree_async_progress_get_status (OstreeAsyncProgress *self)
|
||||
* Since: 2017.6
|
||||
*/
|
||||
void
|
||||
ostree_async_progress_set (OstreeAsyncProgress *self,
|
||||
...)
|
||||
ostree_async_progress_set (OstreeAsyncProgress *self, ...)
|
||||
{
|
||||
va_list ap;
|
||||
const char *key, *format_string;
|
||||
@ -336,18 +325,17 @@ ostree_async_progress_set (OstreeAsyncProgress *self,
|
||||
|
||||
va_start (ap, self);
|
||||
|
||||
for (key = va_arg (ap, const char *), format_string = va_arg (ap, const char *);
|
||||
key != NULL;
|
||||
for (key = va_arg (ap, const char *), format_string = va_arg (ap, const char *); key != NULL;
|
||||
key = va_arg (ap, const char *), format_string = va_arg (ap, const char *))
|
||||
{
|
||||
GVariant *orig_value;
|
||||
g_autoptr(GVariant) new_value = NULL;
|
||||
g_autoptr (GVariant) new_value = NULL;
|
||||
gpointer qkey = GUINT_TO_POINTER (g_quark_from_string (key));
|
||||
|
||||
new_value = g_variant_ref_sink (g_variant_new_va (format_string, NULL, &ap));
|
||||
|
||||
if (g_hash_table_lookup_extended (self->values, qkey, NULL, (gpointer *) &orig_value) &&
|
||||
g_variant_equal (orig_value, new_value))
|
||||
if (g_hash_table_lookup_extended (self->values, qkey, NULL, (gpointer *)&orig_value)
|
||||
&& g_variant_equal (orig_value, new_value))
|
||||
continue;
|
||||
|
||||
g_hash_table_replace (self->values, qkey, g_steal_pointer (&new_value));
|
||||
@ -379,12 +367,10 @@ out:
|
||||
* Since: 2017.6
|
||||
*/
|
||||
void
|
||||
ostree_async_progress_set_variant (OstreeAsyncProgress *self,
|
||||
const char *key,
|
||||
GVariant *value)
|
||||
ostree_async_progress_set_variant (OstreeAsyncProgress *self, const char *key, GVariant *value)
|
||||
{
|
||||
GVariant *orig_value;
|
||||
g_autoptr(GVariant) new_value = g_variant_ref_sink (value);
|
||||
g_autoptr (GVariant) new_value = g_variant_ref_sink (value);
|
||||
gpointer qkey = GUINT_TO_POINTER (g_quark_from_string (key));
|
||||
|
||||
g_return_if_fail (OSTREE_IS_ASYNC_PROGRESS (self));
|
||||
@ -396,7 +382,7 @@ ostree_async_progress_set_variant (OstreeAsyncProgress *self,
|
||||
if (self->dead)
|
||||
goto out;
|
||||
|
||||
if (g_hash_table_lookup_extended (self->values, qkey, NULL, (gpointer *) &orig_value))
|
||||
if (g_hash_table_lookup_extended (self->values, qkey, NULL, (gpointer *)&orig_value))
|
||||
{
|
||||
if (g_variant_equal (orig_value, new_value))
|
||||
goto out;
|
||||
@ -404,22 +390,18 @@ ostree_async_progress_set_variant (OstreeAsyncProgress *self,
|
||||
g_hash_table_replace (self->values, qkey, g_steal_pointer (&new_value));
|
||||
ensure_callback_locked (self);
|
||||
|
||||
out:
|
||||
out:
|
||||
g_mutex_unlock (&self->lock);
|
||||
}
|
||||
|
||||
void
|
||||
ostree_async_progress_set_uint (OstreeAsyncProgress *self,
|
||||
const char *key,
|
||||
guint value)
|
||||
ostree_async_progress_set_uint (OstreeAsyncProgress *self, const char *key, guint value)
|
||||
{
|
||||
ostree_async_progress_set_variant (self, key, g_variant_new_uint32 (value));
|
||||
}
|
||||
|
||||
void
|
||||
ostree_async_progress_set_uint64 (OstreeAsyncProgress *self,
|
||||
const char *key,
|
||||
guint64 value)
|
||||
ostree_async_progress_set_uint64 (OstreeAsyncProgress *self, const char *key, guint64 value)
|
||||
{
|
||||
ostree_async_progress_set_variant (self, key, g_variant_new_uint64 (value));
|
||||
}
|
||||
@ -436,8 +418,7 @@ ostree_async_progress_set_uint64 (OstreeAsyncProgress *self,
|
||||
* Since: 2019.6
|
||||
*/
|
||||
void
|
||||
ostree_async_progress_copy_state (OstreeAsyncProgress *self,
|
||||
OstreeAsyncProgress *dest)
|
||||
ostree_async_progress_copy_state (OstreeAsyncProgress *self, OstreeAsyncProgress *dest)
|
||||
{
|
||||
g_assert (OSTREE_IS_ASYNC_PROGRESS (self));
|
||||
g_assert (OSTREE_IS_ASYNC_PROGRESS (dest));
|
||||
@ -454,7 +435,7 @@ ostree_async_progress_copy_state (OstreeAsyncProgress *self,
|
||||
g_hash_table_replace (dest->values, key, value);
|
||||
}
|
||||
|
||||
out:
|
||||
out:
|
||||
g_mutex_unlock (&self->lock);
|
||||
}
|
||||
|
||||
@ -466,7 +447,7 @@ ostree_async_progress_copy_state (OstreeAsyncProgress *self,
|
||||
OstreeAsyncProgress *
|
||||
ostree_async_progress_new (void)
|
||||
{
|
||||
return (OstreeAsyncProgress*)g_object_new (OSTREE_TYPE_ASYNC_PROGRESS, NULL);
|
||||
return (OstreeAsyncProgress *)g_object_new (OSTREE_TYPE_ASYNC_PROGRESS, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -477,7 +458,8 @@ ostree_async_progress_new (void)
|
||||
* Returns: (transfer full): A new progress object
|
||||
*/
|
||||
OstreeAsyncProgress *
|
||||
ostree_async_progress_new_and_connect (void (*changed) (OstreeAsyncProgress *self, gpointer user_data),
|
||||
ostree_async_progress_new_and_connect (void (*changed) (OstreeAsyncProgress *self,
|
||||
gpointer user_data),
|
||||
gpointer user_data)
|
||||
{
|
||||
OstreeAsyncProgress *ret = ostree_async_progress_new ();
|
||||
|
@ -23,15 +23,19 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_ASYNC_PROGRESS (ostree_async_progress_get_type ())
|
||||
#define OSTREE_ASYNC_PROGRESS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_ASYNC_PROGRESS, OstreeAsyncProgress))
|
||||
#define OSTREE_ASYNC_PROGRESS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), OSTREE_TYPE_ASYNC_PROGRESS, OstreeAsyncProgressClass))
|
||||
#define OSTREE_IS_ASYNC_PROGRESS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_ASYNC_PROGRESS))
|
||||
#define OSTREE_IS_ASYNC_PROGRESS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_ASYNC_PROGRESS))
|
||||
#define OSTREE_ASYNC_PROGRESS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_ASYNC_PROGRESS, OstreeAsyncProgressClass))
|
||||
#define OSTREE_TYPE_ASYNC_PROGRESS (ostree_async_progress_get_type ())
|
||||
#define OSTREE_ASYNC_PROGRESS(o) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_ASYNC_PROGRESS, OstreeAsyncProgress))
|
||||
#define OSTREE_ASYNC_PROGRESS_CLASS(k) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((k), OSTREE_TYPE_ASYNC_PROGRESS, OstreeAsyncProgressClass))
|
||||
#define OSTREE_IS_ASYNC_PROGRESS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_ASYNC_PROGRESS))
|
||||
#define OSTREE_IS_ASYNC_PROGRESS_CLASS(k) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_ASYNC_PROGRESS))
|
||||
#define OSTREE_ASYNC_PROGRESS_GET_CLASS(o) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_ASYNC_PROGRESS, OstreeAsyncProgressClass))
|
||||
|
||||
typedef struct OstreeAsyncProgress OstreeAsyncProgress;
|
||||
typedef struct OstreeAsyncProgressClass OstreeAsyncProgressClass;
|
||||
typedef struct OstreeAsyncProgress OstreeAsyncProgress;
|
||||
typedef struct OstreeAsyncProgressClass OstreeAsyncProgressClass;
|
||||
|
||||
struct OstreeAsyncProgressClass
|
||||
{
|
||||
@ -41,57 +45,46 @@ struct OstreeAsyncProgressClass
|
||||
};
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
GType ostree_async_progress_get_type (void) G_GNUC_CONST;
|
||||
GType ostree_async_progress_get_type (void) G_GNUC_CONST;
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeAsyncProgress *ostree_async_progress_new (void);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeAsyncProgress *ostree_async_progress_new_and_connect (void (*changed) (OstreeAsyncProgress *self, gpointer user_data), gpointer user_data);
|
||||
OstreeAsyncProgress *ostree_async_progress_new_and_connect (
|
||||
void (*changed) (OstreeAsyncProgress *self, gpointer user_data), gpointer user_data);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
char *ostree_async_progress_get_status (OstreeAsyncProgress *self);
|
||||
char *ostree_async_progress_get_status (OstreeAsyncProgress *self);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_async_progress_get (OstreeAsyncProgress *self,
|
||||
...) G_GNUC_NULL_TERMINATED;
|
||||
void ostree_async_progress_get (OstreeAsyncProgress *self, ...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
guint ostree_async_progress_get_uint (OstreeAsyncProgress *self,
|
||||
const char *key);
|
||||
guint ostree_async_progress_get_uint (OstreeAsyncProgress *self, const char *key);
|
||||
_OSTREE_PUBLIC
|
||||
guint64 ostree_async_progress_get_uint64 (OstreeAsyncProgress *self,
|
||||
const char *key);
|
||||
guint64 ostree_async_progress_get_uint64 (OstreeAsyncProgress *self, const char *key);
|
||||
_OSTREE_PUBLIC
|
||||
GVariant *ostree_async_progress_get_variant (OstreeAsyncProgress *self,
|
||||
const char *key);
|
||||
GVariant *ostree_async_progress_get_variant (OstreeAsyncProgress *self, const char *key);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_async_progress_set_status (OstreeAsyncProgress *self,
|
||||
const char *status);
|
||||
void ostree_async_progress_set_status (OstreeAsyncProgress *self, const char *status);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_async_progress_set (OstreeAsyncProgress *self,
|
||||
...) G_GNUC_NULL_TERMINATED;
|
||||
void ostree_async_progress_set (OstreeAsyncProgress *self, ...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_async_progress_set_uint (OstreeAsyncProgress *self,
|
||||
const char *key,
|
||||
guint value);
|
||||
void ostree_async_progress_set_uint (OstreeAsyncProgress *self, const char *key, guint value);
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_async_progress_set_uint64 (OstreeAsyncProgress *self,
|
||||
const char *key,
|
||||
guint64 value);
|
||||
void ostree_async_progress_set_uint64 (OstreeAsyncProgress *self, const char *key, guint64 value);
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_async_progress_set_variant (OstreeAsyncProgress *self,
|
||||
const char *key,
|
||||
GVariant *value);
|
||||
void ostree_async_progress_set_variant (OstreeAsyncProgress *self, const char *key,
|
||||
GVariant *value);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_async_progress_finish (OstreeAsyncProgress *self);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_async_progress_copy_state (OstreeAsyncProgress *self,
|
||||
OstreeAsyncProgress *dest);
|
||||
void ostree_async_progress_copy_state (OstreeAsyncProgress *self, OstreeAsyncProgress *dest);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -58,7 +58,8 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeSePolicy, g_object_unref)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeSysroot, g_object_unref)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeSysrootUpgrader, g_object_unref)
|
||||
|
||||
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (OstreeRepoCommitTraverseIter, ostree_repo_commit_traverse_iter_clear)
|
||||
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (OstreeRepoCommitTraverseIter,
|
||||
ostree_repo_commit_traverse_iter_clear)
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeCollectionRef, ostree_collection_ref_free)
|
||||
G_DEFINE_AUTO_CLEANUP_FREE_FUNC (OstreeCollectionRefv, ostree_collection_ref_freev, NULL)
|
||||
|
@ -23,8 +23,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "libglnx.h"
|
||||
|
||||
@ -55,8 +55,7 @@ typedef struct _OstreeBloom OstreeBloom;
|
||||
*
|
||||
* Since: 2017.8
|
||||
*/
|
||||
typedef guint64 (*OstreeBloomHashFunc) (gconstpointer element,
|
||||
guint8 k);
|
||||
typedef guint64 (*OstreeBloomHashFunc) (gconstpointer element, guint8 k);
|
||||
|
||||
#define OSTREE_TYPE_BLOOM (ostree_bloom_get_type ())
|
||||
|
||||
@ -64,14 +63,10 @@ G_GNUC_INTERNAL
|
||||
GType ostree_bloom_get_type (void);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
OstreeBloom *ostree_bloom_new (gsize n_bytes,
|
||||
guint8 k,
|
||||
OstreeBloomHashFunc hash_func);
|
||||
OstreeBloom *ostree_bloom_new (gsize n_bytes, guint8 k, OstreeBloomHashFunc hash_func);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
OstreeBloom *ostree_bloom_new_from_bytes (GBytes *bytes,
|
||||
guint8 k,
|
||||
OstreeBloomHashFunc hash_func);
|
||||
OstreeBloom *ostree_bloom_new_from_bytes (GBytes *bytes, guint8 k, OstreeBloomHashFunc hash_func);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
OstreeBloom *ostree_bloom_ref (OstreeBloom *bloom);
|
||||
@ -81,15 +76,13 @@ void ostree_bloom_unref (OstreeBloom *bloom);
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeBloom, ostree_bloom_unref)
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
gboolean ostree_bloom_maybe_contains (OstreeBloom *bloom,
|
||||
gconstpointer element);
|
||||
gboolean ostree_bloom_maybe_contains (OstreeBloom *bloom, gconstpointer element);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
GBytes *ostree_bloom_seal (OstreeBloom *bloom);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
void ostree_bloom_add_element (OstreeBloom *bloom,
|
||||
gconstpointer element);
|
||||
void ostree_bloom_add_element (OstreeBloom *bloom, gconstpointer element);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
gsize ostree_bloom_get_size (OstreeBloom *bloom);
|
||||
@ -99,7 +92,6 @@ G_GNUC_INTERNAL
|
||||
OstreeBloomHashFunc ostree_bloom_get_hash_func (OstreeBloom *bloom);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
guint64 ostree_str_bloom_hash (gconstpointer element,
|
||||
guint8 k);
|
||||
guint64 ostree_str_bloom_hash (gconstpointer element, guint8 k);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -24,8 +24,8 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -76,13 +76,13 @@
|
||||
struct _OstreeBloom
|
||||
{
|
||||
guint ref_count;
|
||||
gsize n_bytes; /* 0 < n_bytes <= G_MAXSIZE / 8 */
|
||||
gboolean is_mutable; /* determines which of [im]mutable_bytes is accessed */
|
||||
gsize n_bytes; /* 0 < n_bytes <= G_MAXSIZE / 8 */
|
||||
gboolean is_mutable; /* determines which of [im]mutable_bytes is accessed */
|
||||
union
|
||||
{
|
||||
guint8 *mutable_bytes; /* owned; mutually exclusive */
|
||||
GBytes *immutable_bytes; /* owned; mutually exclusive */
|
||||
};
|
||||
{
|
||||
guint8 *mutable_bytes; /* owned; mutually exclusive */
|
||||
GBytes *immutable_bytes; /* owned; mutually exclusive */
|
||||
};
|
||||
guint8 k;
|
||||
OstreeBloomHashFunc hash_func;
|
||||
};
|
||||
@ -110,11 +110,9 @@ G_DEFINE_BOXED_TYPE (OstreeBloom, ostree_bloom, ostree_bloom_ref, ostree_bloom_u
|
||||
* Since: 2017.8
|
||||
*/
|
||||
OstreeBloom *
|
||||
ostree_bloom_new (gsize n_bytes,
|
||||
guint8 k,
|
||||
OstreeBloomHashFunc hash_func)
|
||||
ostree_bloom_new (gsize n_bytes, guint8 k, OstreeBloomHashFunc hash_func)
|
||||
{
|
||||
g_autoptr(OstreeBloom) bloom = NULL;
|
||||
g_autoptr (OstreeBloom) bloom = NULL;
|
||||
|
||||
g_return_val_if_fail (n_bytes > 0, NULL);
|
||||
g_return_val_if_fail (n_bytes <= G_MAXSIZE / 8, NULL);
|
||||
@ -152,11 +150,9 @@ ostree_bloom_new (gsize n_bytes,
|
||||
* Since: 2017.8
|
||||
*/
|
||||
OstreeBloom *
|
||||
ostree_bloom_new_from_bytes (GBytes *bytes,
|
||||
guint8 k,
|
||||
OstreeBloomHashFunc hash_func)
|
||||
ostree_bloom_new_from_bytes (GBytes *bytes, guint8 k, OstreeBloomHashFunc hash_func)
|
||||
{
|
||||
g_autoptr(OstreeBloom) bloom = NULL;
|
||||
g_autoptr (OstreeBloom) bloom = NULL;
|
||||
|
||||
g_return_val_if_fail (bytes != NULL, NULL);
|
||||
g_return_val_if_fail (g_bytes_get_size (bytes) > 0, NULL);
|
||||
@ -227,8 +223,7 @@ ostree_bloom_unref (OstreeBloom *bloom)
|
||||
|
||||
/* @idx is in bits, not bytes. */
|
||||
static inline gboolean
|
||||
ostree_bloom_get_bit (OstreeBloom *bloom,
|
||||
gsize idx)
|
||||
ostree_bloom_get_bit (OstreeBloom *bloom, gsize idx)
|
||||
{
|
||||
const guint8 *bytes;
|
||||
|
||||
@ -243,12 +238,11 @@ ostree_bloom_get_bit (OstreeBloom *bloom,
|
||||
|
||||
/* @idx is in bits, not bytes. */
|
||||
static inline void
|
||||
ostree_bloom_set_bit (OstreeBloom *bloom,
|
||||
gsize idx)
|
||||
ostree_bloom_set_bit (OstreeBloom *bloom, gsize idx)
|
||||
{
|
||||
g_assert (bloom->is_mutable);
|
||||
g_assert (idx / 8 < bloom->n_bytes);
|
||||
bloom->mutable_bytes[idx / 8] |= (guint8) (1 << (idx % 8));
|
||||
bloom->mutable_bytes[idx / 8] |= (guint8)(1 << (idx % 8));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -265,8 +259,7 @@ ostree_bloom_set_bit (OstreeBloom *bloom,
|
||||
* Since: 2017.8
|
||||
*/
|
||||
gboolean
|
||||
ostree_bloom_maybe_contains (OstreeBloom *bloom,
|
||||
gconstpointer element)
|
||||
ostree_bloom_maybe_contains (OstreeBloom *bloom, gconstpointer element)
|
||||
{
|
||||
guint8 i;
|
||||
|
||||
@ -279,11 +272,11 @@ ostree_bloom_maybe_contains (OstreeBloom *bloom,
|
||||
|
||||
idx = bloom->hash_func (element, i);
|
||||
|
||||
if (!ostree_bloom_get_bit (bloom, (gsize) (idx % (bloom->n_bytes * 8))))
|
||||
return FALSE; /* definitely not in the set */
|
||||
if (!ostree_bloom_get_bit (bloom, (gsize)(idx % (bloom->n_bytes * 8))))
|
||||
return FALSE; /* definitely not in the set */
|
||||
}
|
||||
|
||||
return TRUE; /* possibly in the set */
|
||||
return TRUE; /* possibly in the set */
|
||||
}
|
||||
|
||||
/**
|
||||
@ -310,7 +303,8 @@ ostree_bloom_seal (OstreeBloom *bloom)
|
||||
if (bloom->is_mutable)
|
||||
{
|
||||
bloom->is_mutable = FALSE;
|
||||
bloom->immutable_bytes = g_bytes_new_take (g_steal_pointer (&bloom->mutable_bytes), bloom->n_bytes);
|
||||
bloom->immutable_bytes
|
||||
= g_bytes_new_take (g_steal_pointer (&bloom->mutable_bytes), bloom->n_bytes);
|
||||
}
|
||||
|
||||
return g_bytes_ref (bloom->immutable_bytes);
|
||||
@ -328,8 +322,7 @@ ostree_bloom_seal (OstreeBloom *bloom)
|
||||
* Since: 2017.8
|
||||
*/
|
||||
void
|
||||
ostree_bloom_add_element (OstreeBloom *bloom,
|
||||
gconstpointer element)
|
||||
ostree_bloom_add_element (OstreeBloom *bloom, gconstpointer element)
|
||||
{
|
||||
guint8 i;
|
||||
|
||||
@ -340,7 +333,7 @@ ostree_bloom_add_element (OstreeBloom *bloom,
|
||||
for (i = 0; i < bloom->k; i++)
|
||||
{
|
||||
guint64 idx = bloom->hash_func (element, i);
|
||||
ostree_bloom_set_bit (bloom, (gsize) (idx % (bloom->n_bytes * 8)));
|
||||
ostree_bloom_set_bit (bloom, (gsize)(idx % (bloom->n_bytes * 8)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -418,145 +411,147 @@ ostree_bloom_get_hash_func (OstreeBloom *bloom)
|
||||
#define cROUNDS 2
|
||||
#define dROUNDS 4
|
||||
|
||||
#define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b))))
|
||||
#define ROTL(x, b) (uint64_t) (((x) << (b)) | ((x) >> (64 - (b))))
|
||||
|
||||
#define U32TO8_LE(p, v) \
|
||||
(p)[0] = (uint8_t)((v)); \
|
||||
(p)[1] = (uint8_t)((v) >> 8); \
|
||||
(p)[2] = (uint8_t)((v) >> 16); \
|
||||
(p)[3] = (uint8_t)((v) >> 24);
|
||||
#define U32TO8_LE(p, v) \
|
||||
(p)[0] = (uint8_t)((v)); \
|
||||
(p)[1] = (uint8_t)((v) >> 8); \
|
||||
(p)[2] = (uint8_t)((v) >> 16); \
|
||||
(p)[3] = (uint8_t)((v) >> 24);
|
||||
|
||||
#define U64TO8_LE(p, v) \
|
||||
U32TO8_LE((p), (uint32_t)((v))); \
|
||||
U32TO8_LE((p) + 4, (uint32_t)((v) >> 32));
|
||||
#define U64TO8_LE(p, v) \
|
||||
U32TO8_LE ((p), (uint32_t)((v))); \
|
||||
U32TO8_LE ((p) + 4, (uint32_t)((v) >> 32));
|
||||
|
||||
#define U8TO64_LE(p) \
|
||||
(((uint64_t)((p)[0])) | ((uint64_t)((p)[1]) << 8) | \
|
||||
((uint64_t)((p)[2]) << 16) | ((uint64_t)((p)[3]) << 24) | \
|
||||
((uint64_t)((p)[4]) << 32) | ((uint64_t)((p)[5]) << 40) | \
|
||||
((uint64_t)((p)[6]) << 48) | ((uint64_t)((p)[7]) << 56))
|
||||
#define U8TO64_LE(p) \
|
||||
(((uint64_t)((p)[0])) | ((uint64_t)((p)[1]) << 8) | ((uint64_t)((p)[2]) << 16) \
|
||||
| ((uint64_t)((p)[3]) << 24) | ((uint64_t)((p)[4]) << 32) | ((uint64_t)((p)[5]) << 40) \
|
||||
| ((uint64_t)((p)[6]) << 48) | ((uint64_t)((p)[7]) << 56))
|
||||
|
||||
#define SIPROUND \
|
||||
do { \
|
||||
v0 += v1; \
|
||||
v1 = ROTL(v1, 13); \
|
||||
v1 ^= v0; \
|
||||
v0 = ROTL(v0, 32); \
|
||||
v2 += v3; \
|
||||
v3 = ROTL(v3, 16); \
|
||||
v3 ^= v2; \
|
||||
v0 += v3; \
|
||||
v3 = ROTL(v3, 21); \
|
||||
v3 ^= v0; \
|
||||
v2 += v1; \
|
||||
v1 = ROTL(v1, 17); \
|
||||
v1 ^= v2; \
|
||||
v2 = ROTL(v2, 32); \
|
||||
} while (0)
|
||||
#define SIPROUND \
|
||||
do \
|
||||
{ \
|
||||
v0 += v1; \
|
||||
v1 = ROTL (v1, 13); \
|
||||
v1 ^= v0; \
|
||||
v0 = ROTL (v0, 32); \
|
||||
v2 += v3; \
|
||||
v3 = ROTL (v3, 16); \
|
||||
v3 ^= v2; \
|
||||
v0 += v3; \
|
||||
v3 = ROTL (v3, 21); \
|
||||
v3 ^= v0; \
|
||||
v2 += v1; \
|
||||
v1 = ROTL (v1, 17); \
|
||||
v1 ^= v2; \
|
||||
v2 = ROTL (v2, 32); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#ifdef DEBUG
|
||||
#define TRACE \
|
||||
do { \
|
||||
printf("(%3d) v0 %08x %08x\n", (int)inlen, (uint32_t)(v0 >> 32), \
|
||||
(uint32_t)v0); \
|
||||
printf("(%3d) v1 %08x %08x\n", (int)inlen, (uint32_t)(v1 >> 32), \
|
||||
(uint32_t)v1); \
|
||||
printf("(%3d) v2 %08x %08x\n", (int)inlen, (uint32_t)(v2 >> 32), \
|
||||
(uint32_t)v2); \
|
||||
printf("(%3d) v3 %08x %08x\n", (int)inlen, (uint32_t)(v3 >> 32), \
|
||||
(uint32_t)v3); \
|
||||
} while (0)
|
||||
#define TRACE \
|
||||
do \
|
||||
{ \
|
||||
printf ("(%3d) v0 %08x %08x\n", (int)inlen, (uint32_t)(v0 >> 32), (uint32_t)v0); \
|
||||
printf ("(%3d) v1 %08x %08x\n", (int)inlen, (uint32_t)(v1 >> 32), (uint32_t)v1); \
|
||||
printf ("(%3d) v2 %08x %08x\n", (int)inlen, (uint32_t)(v2 >> 32), (uint32_t)v2); \
|
||||
printf ("(%3d) v3 %08x %08x\n", (int)inlen, (uint32_t)(v3 >> 32), (uint32_t)v3); \
|
||||
} \
|
||||
while (0)
|
||||
#else
|
||||
#define TRACE
|
||||
#endif
|
||||
|
||||
static int siphash(const uint8_t *in, const size_t inlen, const uint8_t *k,
|
||||
uint8_t *out, const size_t outlen) {
|
||||
static int
|
||||
siphash (const uint8_t *in, const size_t inlen, const uint8_t *k, uint8_t *out, const size_t outlen)
|
||||
{
|
||||
|
||||
assert((outlen == 8) || (outlen == 16));
|
||||
uint64_t v0 = 0x736f6d6570736575ULL;
|
||||
uint64_t v1 = 0x646f72616e646f6dULL;
|
||||
uint64_t v2 = 0x6c7967656e657261ULL;
|
||||
uint64_t v3 = 0x7465646279746573ULL;
|
||||
uint64_t k0 = U8TO64_LE(k);
|
||||
uint64_t k1 = U8TO64_LE(k + 8);
|
||||
uint64_t m;
|
||||
int i;
|
||||
const uint8_t *end = in + inlen - (inlen % sizeof(uint64_t));
|
||||
const int left = inlen & 7;
|
||||
uint64_t b = ((uint64_t)inlen) << 56;
|
||||
v3 ^= k1;
|
||||
v2 ^= k0;
|
||||
v1 ^= k1;
|
||||
v0 ^= k0;
|
||||
assert ((outlen == 8) || (outlen == 16));
|
||||
uint64_t v0 = 0x736f6d6570736575ULL;
|
||||
uint64_t v1 = 0x646f72616e646f6dULL;
|
||||
uint64_t v2 = 0x6c7967656e657261ULL;
|
||||
uint64_t v3 = 0x7465646279746573ULL;
|
||||
uint64_t k0 = U8TO64_LE (k);
|
||||
uint64_t k1 = U8TO64_LE (k + 8);
|
||||
uint64_t m;
|
||||
int i;
|
||||
const uint8_t *end = in + inlen - (inlen % sizeof (uint64_t));
|
||||
const int left = inlen & 7;
|
||||
uint64_t b = ((uint64_t)inlen) << 56;
|
||||
v3 ^= k1;
|
||||
v2 ^= k0;
|
||||
v1 ^= k1;
|
||||
v0 ^= k0;
|
||||
|
||||
if (outlen == 16)
|
||||
v1 ^= 0xee;
|
||||
if (outlen == 16)
|
||||
v1 ^= 0xee;
|
||||
|
||||
for (; in != end; in += 8) {
|
||||
m = U8TO64_LE(in);
|
||||
v3 ^= m;
|
||||
for (; in != end; in += 8)
|
||||
{
|
||||
m = U8TO64_LE (in);
|
||||
v3 ^= m;
|
||||
|
||||
TRACE;
|
||||
for (i = 0; i < cROUNDS; ++i)
|
||||
SIPROUND;
|
||||
TRACE;
|
||||
for (i = 0; i < cROUNDS; ++i)
|
||||
SIPROUND;
|
||||
|
||||
v0 ^= m;
|
||||
v0 ^= m;
|
||||
}
|
||||
|
||||
switch (left) {
|
||||
switch (left)
|
||||
{
|
||||
case 7:
|
||||
b |= ((uint64_t)in[6]) << 48;
|
||||
b |= ((uint64_t)in[6]) << 48;
|
||||
case 6:
|
||||
b |= ((uint64_t)in[5]) << 40;
|
||||
b |= ((uint64_t)in[5]) << 40;
|
||||
case 5:
|
||||
b |= ((uint64_t)in[4]) << 32;
|
||||
b |= ((uint64_t)in[4]) << 32;
|
||||
case 4:
|
||||
b |= ((uint64_t)in[3]) << 24;
|
||||
b |= ((uint64_t)in[3]) << 24;
|
||||
case 3:
|
||||
b |= ((uint64_t)in[2]) << 16;
|
||||
b |= ((uint64_t)in[2]) << 16;
|
||||
case 2:
|
||||
b |= ((uint64_t)in[1]) << 8;
|
||||
b |= ((uint64_t)in[1]) << 8;
|
||||
case 1:
|
||||
b |= ((uint64_t)in[0]);
|
||||
break;
|
||||
b |= ((uint64_t)in[0]);
|
||||
break;
|
||||
case 0:
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
v3 ^= b;
|
||||
v3 ^= b;
|
||||
|
||||
TRACE;
|
||||
for (i = 0; i < cROUNDS; ++i)
|
||||
SIPROUND;
|
||||
TRACE;
|
||||
for (i = 0; i < cROUNDS; ++i)
|
||||
SIPROUND;
|
||||
|
||||
v0 ^= b;
|
||||
v0 ^= b;
|
||||
|
||||
if (outlen == 16)
|
||||
v2 ^= 0xee;
|
||||
else
|
||||
v2 ^= 0xff;
|
||||
if (outlen == 16)
|
||||
v2 ^= 0xee;
|
||||
else
|
||||
v2 ^= 0xff;
|
||||
|
||||
TRACE;
|
||||
for (i = 0; i < dROUNDS; ++i)
|
||||
SIPROUND;
|
||||
TRACE;
|
||||
for (i = 0; i < dROUNDS; ++i)
|
||||
SIPROUND;
|
||||
|
||||
b = v0 ^ v1 ^ v2 ^ v3;
|
||||
U64TO8_LE(out, b);
|
||||
|
||||
if (outlen == 8)
|
||||
return 0;
|
||||
|
||||
v1 ^= 0xdd;
|
||||
|
||||
TRACE;
|
||||
for (i = 0; i < dROUNDS; ++i)
|
||||
SIPROUND;
|
||||
|
||||
b = v0 ^ v1 ^ v2 ^ v3;
|
||||
U64TO8_LE(out + 8, b);
|
||||
b = v0 ^ v1 ^ v2 ^ v3;
|
||||
U64TO8_LE (out, b);
|
||||
|
||||
if (outlen == 8)
|
||||
return 0;
|
||||
|
||||
v1 ^= 0xdd;
|
||||
|
||||
TRACE;
|
||||
for (i = 0; i < dROUNDS; ++i)
|
||||
SIPROUND;
|
||||
|
||||
b = v0 ^ v1 ^ v2 ^ v3;
|
||||
U64TO8_LE (out + 8, b);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* End SipHash copied code. */
|
||||
@ -581,16 +576,15 @@ static int siphash(const uint8_t *in, const size_t inlen, const uint8_t *k,
|
||||
* Since: 2017.8
|
||||
*/
|
||||
guint64
|
||||
ostree_str_bloom_hash (gconstpointer element,
|
||||
guint8 k)
|
||||
ostree_str_bloom_hash (gconstpointer element, guint8 k)
|
||||
{
|
||||
const gchar *str = element;
|
||||
gsize str_len;
|
||||
union
|
||||
{
|
||||
guint64 u64;
|
||||
guint8 u8[8];
|
||||
} out_le;
|
||||
{
|
||||
guint64 u64;
|
||||
guint8 u8[8];
|
||||
} out_le;
|
||||
guint8 k_array[16];
|
||||
gsize i;
|
||||
|
||||
@ -598,7 +592,7 @@ ostree_str_bloom_hash (gconstpointer element,
|
||||
for (i = 0; i < G_N_ELEMENTS (k_array); i++)
|
||||
k_array[i] = k;
|
||||
|
||||
siphash ((const guint8 *) str, str_len, k_array, out_le.u8, sizeof (out_le));
|
||||
siphash ((const guint8 *)str, str_len, k_array, out_le.u8, sizeof (out_le));
|
||||
|
||||
return le64toh (out_le.u64);
|
||||
}
|
||||
|
@ -22,15 +22,15 @@
|
||||
|
||||
struct _OstreeBootconfigParser
|
||||
{
|
||||
GObject parent_instance;
|
||||
GObject parent_instance;
|
||||
|
||||
gboolean parsed;
|
||||
const char *separators;
|
||||
gboolean parsed;
|
||||
const char *separators;
|
||||
|
||||
GHashTable *options;
|
||||
GHashTable *options;
|
||||
|
||||
/* Additional initrds; the primary initrd is in options. */
|
||||
char **overlay_initrds;
|
||||
char **overlay_initrds;
|
||||
};
|
||||
|
||||
typedef GObjectClass OstreeBootconfigParserClass;
|
||||
@ -48,7 +48,7 @@ ostree_bootconfig_parser_clone (OstreeBootconfigParser *self)
|
||||
{
|
||||
OstreeBootconfigParser *parser = ostree_bootconfig_parser_new ();
|
||||
|
||||
GLNX_HASH_TABLE_FOREACH_KV (self->options, const char*, k, const char*, v)
|
||||
GLNX_HASH_TABLE_FOREACH_KV (self->options, const char *, k, const char *, v)
|
||||
g_hash_table_replace (parser->options, g_strdup (k), g_strdup (v));
|
||||
|
||||
parser->overlay_initrds = g_strdupv (self->overlay_initrds);
|
||||
@ -67,11 +67,8 @@ ostree_bootconfig_parser_clone (OstreeBootconfigParser *self)
|
||||
* Initialize a bootconfig from the given file.
|
||||
*/
|
||||
gboolean
|
||||
ostree_bootconfig_parser_parse_at (OstreeBootconfigParser *self,
|
||||
int dfd,
|
||||
const char *path,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_bootconfig_parser_parse_at (OstreeBootconfigParser *self, int dfd, const char *path,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
g_assert (!self->parsed);
|
||||
|
||||
@ -79,9 +76,9 @@ ostree_bootconfig_parser_parse_at (OstreeBootconfigParser *self,
|
||||
if (!contents)
|
||||
return FALSE;
|
||||
|
||||
g_autoptr(GPtrArray) overlay_initrds = NULL;
|
||||
g_autoptr (GPtrArray) overlay_initrds = NULL;
|
||||
|
||||
g_auto(GStrv) lines = g_strsplit (contents, "\n", -1);
|
||||
g_auto (GStrv) lines = g_strsplit (contents, "\n", -1);
|
||||
for (char **iter = lines; *iter; iter++)
|
||||
{
|
||||
const char *line = *iter;
|
||||
@ -92,8 +89,8 @@ ostree_bootconfig_parser_parse_at (OstreeBootconfigParser *self,
|
||||
items = g_strsplit_set (line, self->separators, 2);
|
||||
if (g_strv_length (items) == 2 && items[0][0] != '\0')
|
||||
{
|
||||
if (g_str_equal (items[0], "initrd") &&
|
||||
g_hash_table_contains (self->options, "initrd"))
|
||||
if (g_str_equal (items[0], "initrd")
|
||||
&& g_hash_table_contains (self->options, "initrd"))
|
||||
{
|
||||
if (!overlay_initrds)
|
||||
overlay_initrds = g_ptr_array_new_with_free_func (g_free);
|
||||
@ -116,7 +113,7 @@ ostree_bootconfig_parser_parse_at (OstreeBootconfigParser *self,
|
||||
if (overlay_initrds)
|
||||
{
|
||||
g_ptr_array_add (overlay_initrds, NULL);
|
||||
self->overlay_initrds = (char**)g_ptr_array_free (g_steal_pointer (&overlay_initrds), FALSE);
|
||||
self->overlay_initrds = (char **)g_ptr_array_free (g_steal_pointer (&overlay_initrds), FALSE);
|
||||
}
|
||||
|
||||
self->parsed = TRUE;
|
||||
@ -125,10 +122,8 @@ ostree_bootconfig_parser_parse_at (OstreeBootconfigParser *self,
|
||||
}
|
||||
|
||||
gboolean
|
||||
ostree_bootconfig_parser_parse (OstreeBootconfigParser *self,
|
||||
GFile *path,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_bootconfig_parser_parse (OstreeBootconfigParser *self, GFile *path,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
return ostree_bootconfig_parser_parse_at (self, AT_FDCWD, gs_file_get_path_cached (path),
|
||||
cancellable, error);
|
||||
@ -143,9 +138,7 @@ ostree_bootconfig_parser_parse (OstreeBootconfigParser *self,
|
||||
* Set the @key/@value pair to the boot configuration dictionary.
|
||||
*/
|
||||
void
|
||||
ostree_bootconfig_parser_set (OstreeBootconfigParser *self,
|
||||
const char *key,
|
||||
const char *value)
|
||||
ostree_bootconfig_parser_set (OstreeBootconfigParser *self, const char *key, const char *value)
|
||||
{
|
||||
g_hash_table_replace (self->options, g_strdup (key), g_strdup (value));
|
||||
}
|
||||
@ -161,8 +154,7 @@ ostree_bootconfig_parser_set (OstreeBootconfigParser *self,
|
||||
* found.
|
||||
*/
|
||||
const char *
|
||||
ostree_bootconfig_parser_get (OstreeBootconfigParser *self,
|
||||
const char *key)
|
||||
ostree_bootconfig_parser_get (OstreeBootconfigParser *self, const char *key)
|
||||
{
|
||||
return g_hash_table_lookup (self->options, key);
|
||||
}
|
||||
@ -179,8 +171,7 @@ ostree_bootconfig_parser_get (OstreeBootconfigParser *self,
|
||||
* Since: 2020.7
|
||||
*/
|
||||
void
|
||||
ostree_bootconfig_parser_set_overlay_initrds (OstreeBootconfigParser *self,
|
||||
char **initrds)
|
||||
ostree_bootconfig_parser_set_overlay_initrds (OstreeBootconfigParser *self, char **initrds)
|
||||
{
|
||||
g_assert (g_hash_table_contains (self->options, "initrd"));
|
||||
g_strfreev (self->overlay_initrds);
|
||||
@ -196,17 +187,14 @@ ostree_bootconfig_parser_set_overlay_initrds (OstreeBootconfigParser *self,
|
||||
*
|
||||
* Since: 2020.7
|
||||
*/
|
||||
char**
|
||||
ostree_bootconfig_parser_get_overlay_initrds (OstreeBootconfigParser *self)
|
||||
char **
|
||||
ostree_bootconfig_parser_get_overlay_initrds (OstreeBootconfigParser *self)
|
||||
{
|
||||
return self->overlay_initrds;
|
||||
}
|
||||
|
||||
static void
|
||||
write_key (OstreeBootconfigParser *self,
|
||||
GString *buf,
|
||||
const char *key,
|
||||
const char *value)
|
||||
write_key (OstreeBootconfigParser *self, GString *buf, const char *key, const char *value)
|
||||
{
|
||||
g_string_append (buf, key);
|
||||
g_string_append_c (buf, self->separators[0]);
|
||||
@ -215,19 +203,16 @@ write_key (OstreeBootconfigParser *self,
|
||||
}
|
||||
|
||||
gboolean
|
||||
ostree_bootconfig_parser_write_at (OstreeBootconfigParser *self,
|
||||
int dfd,
|
||||
const char *path,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_bootconfig_parser_write_at (OstreeBootconfigParser *self, int dfd, const char *path,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
/* Write the fields in a deterministic order, following what is used
|
||||
* in the bootconfig example of the BootLoaderspec document:
|
||||
* https://systemd.io/BOOT_LOADER_SPECIFICATION
|
||||
*/
|
||||
const char *fields[] = { "title", "version", "options", "devicetree", "linux", "initrd" };
|
||||
g_autoptr(GHashTable) keys_written = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
g_autoptr(GString) buf = g_string_new ("");
|
||||
g_autoptr (GHashTable) keys_written = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
g_autoptr (GString) buf = g_string_new ("");
|
||||
|
||||
for (guint i = 0; i < G_N_ELEMENTS (fields); i++)
|
||||
{
|
||||
@ -250,29 +235,25 @@ ostree_bootconfig_parser_write_at (OstreeBootconfigParser *self,
|
||||
}
|
||||
|
||||
/* Write unknown fields */
|
||||
GLNX_HASH_TABLE_FOREACH_KV (self->options, const char*, k, const char*, v)
|
||||
GLNX_HASH_TABLE_FOREACH_KV (self->options, const char *, k, const char *, v)
|
||||
{
|
||||
if (g_hash_table_lookup (keys_written, k))
|
||||
continue;
|
||||
write_key (self, buf, k, v);
|
||||
}
|
||||
|
||||
if (!glnx_file_replace_contents_at (dfd, path, (guint8*)buf->str, buf->len,
|
||||
GLNX_FILE_REPLACE_NODATASYNC,
|
||||
cancellable, error))
|
||||
if (!glnx_file_replace_contents_at (dfd, path, (guint8 *)buf->str, buf->len,
|
||||
GLNX_FILE_REPLACE_NODATASYNC, cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
ostree_bootconfig_parser_write (OstreeBootconfigParser *self,
|
||||
GFile *output,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_bootconfig_parser_write (OstreeBootconfigParser *self, GFile *output,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
return ostree_bootconfig_parser_write_at (self,
|
||||
AT_FDCWD, gs_file_get_path_cached (output),
|
||||
return ostree_bootconfig_parser_write_at (self, AT_FDCWD, gs_file_get_path_cached (output),
|
||||
cancellable, error);
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,10 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_BOOTCONFIG_PARSER (ostree_bootconfig_parser_get_type ())
|
||||
#define OSTREE_BOOTCONFIG_PARSER(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_BOOTCONFIG_PARSER, OstreeBootconfigParser))
|
||||
#define OSTREE_IS_BOOTCONFIG_PARSER(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), OSTREE_TYPE_BOOTCONFIG_PARSER))
|
||||
#define OSTREE_BOOTCONFIG_PARSER(inst) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_BOOTCONFIG_PARSER, OstreeBootconfigParser))
|
||||
#define OSTREE_IS_BOOTCONFIG_PARSER(inst) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((inst), OSTREE_TYPE_BOOTCONFIG_PARSER))
|
||||
|
||||
typedef struct _OstreeBootconfigParser OstreeBootconfigParser;
|
||||
|
||||
@ -31,51 +33,38 @@ _OSTREE_PUBLIC
|
||||
GType ostree_bootconfig_parser_get_type (void) G_GNUC_CONST;
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeBootconfigParser * ostree_bootconfig_parser_new (void);
|
||||
OstreeBootconfigParser *ostree_bootconfig_parser_new (void);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeBootconfigParser * ostree_bootconfig_parser_clone (OstreeBootconfigParser *self);
|
||||
OstreeBootconfigParser *ostree_bootconfig_parser_clone (OstreeBootconfigParser *self);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_bootconfig_parser_parse (OstreeBootconfigParser *self,
|
||||
GFile *path,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_bootconfig_parser_parse (OstreeBootconfigParser *self, GFile *path,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_bootconfig_parser_parse_at (OstreeBootconfigParser *self,
|
||||
int dfd,
|
||||
const char *path,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_bootconfig_parser_parse_at (OstreeBootconfigParser *self, int dfd, const char *path,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_bootconfig_parser_write (OstreeBootconfigParser *self,
|
||||
GFile *output,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_bootconfig_parser_write (OstreeBootconfigParser *self, GFile *output,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_bootconfig_parser_write_at (OstreeBootconfigParser *self,
|
||||
int dfd,
|
||||
const char *path,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_bootconfig_parser_write_at (OstreeBootconfigParser *self, int dfd, const char *path,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_bootconfig_parser_set (OstreeBootconfigParser *self,
|
||||
const char *key,
|
||||
const char *value);
|
||||
void ostree_bootconfig_parser_set (OstreeBootconfigParser *self, const char *key,
|
||||
const char *value);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
const char *ostree_bootconfig_parser_get (OstreeBootconfigParser *self,
|
||||
const char *key);
|
||||
const char *ostree_bootconfig_parser_get (OstreeBootconfigParser *self, const char *key);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_bootconfig_parser_set_overlay_initrds (OstreeBootconfigParser *self,
|
||||
char **initrds);
|
||||
void ostree_bootconfig_parser_set_overlay_initrds (OstreeBootconfigParser *self, char **initrds);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
char** ostree_bootconfig_parser_get_overlay_initrds (OstreeBootconfigParser *self);
|
||||
char **ostree_bootconfig_parser_get_overlay_initrds (OstreeBootconfigParser *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -17,10 +17,10 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ostree-sysroot-private.h"
|
||||
#include "ostree-bootloader-aboot.h"
|
||||
#include "ostree-deployment-private.h"
|
||||
#include "ostree-libarchive-private.h"
|
||||
#include "ostree-sysroot-private.h"
|
||||
#include "otutil.h"
|
||||
#include <sys/mount.h>
|
||||
|
||||
@ -33,21 +33,20 @@ static const char aboot_requires_execute_path[] = "boot/ostree-bootloader-update
|
||||
|
||||
struct _OstreeBootloaderAboot
|
||||
{
|
||||
GObject parent_instance;
|
||||
GObject parent_instance;
|
||||
|
||||
OstreeSysroot *sysroot;
|
||||
OstreeSysroot *sysroot;
|
||||
};
|
||||
|
||||
typedef GObjectClass OstreeBootloaderAbootClass;
|
||||
static void _ostree_bootloader_aboot_bootloader_iface_init (OstreeBootloaderInterface *iface);
|
||||
G_DEFINE_TYPE_WITH_CODE (OstreeBootloaderAboot, _ostree_bootloader_aboot, G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_BOOTLOADER, _ostree_bootloader_aboot_bootloader_iface_init));
|
||||
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_BOOTLOADER,
|
||||
_ostree_bootloader_aboot_bootloader_iface_init));
|
||||
|
||||
static gboolean
|
||||
_ostree_bootloader_aboot_query (OstreeBootloader *bootloader,
|
||||
gboolean *out_is_active,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_bootloader_aboot_query (OstreeBootloader *bootloader, gboolean *out_is_active,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
/* We don't auto-detect this one; should be explicitly chosen right now.
|
||||
* see also https://github.com/coreos/coreos-assembler/pull/849
|
||||
@ -63,61 +62,55 @@ _ostree_bootloader_aboot_get_name (OstreeBootloader *bootloader)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_ostree_bootloader_aboot_write_config (OstreeBootloader *bootloader,
|
||||
int bootversion,
|
||||
GPtrArray *new_deployments,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_bootloader_aboot_write_config (OstreeBootloader *bootloader, int bootversion,
|
||||
GPtrArray *new_deployments, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
OstreeBootloaderAboot *self = OSTREE_BOOTLOADER_ABOOT (bootloader);
|
||||
|
||||
/* Write our stamp file */
|
||||
if (!glnx_file_replace_contents_at (self->sysroot->sysroot_fd, aboot_requires_execute_path,
|
||||
(guint8*)"", 0, GLNX_FILE_REPLACE_NODATASYNC,
|
||||
cancellable, error))
|
||||
(guint8 *)"", 0, GLNX_FILE_REPLACE_NODATASYNC, cancellable,
|
||||
error))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_ostree_aboot_get_bls_config (OstreeBootloaderAboot *self,
|
||||
int bootversion,
|
||||
gchar **aboot,
|
||||
gchar **abootcfg,
|
||||
gchar **version,
|
||||
gchar **vmlinuz,
|
||||
gchar **initramfs,
|
||||
gchar **options,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_aboot_get_bls_config (OstreeBootloaderAboot *self, int bootversion, gchar **aboot,
|
||||
gchar **abootcfg, gchar **version, gchar **vmlinuz, gchar **initramfs,
|
||||
gchar **options, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
g_autoptr (GPtrArray) configs = NULL;
|
||||
if ( !_ostree_sysroot_read_boot_loader_configs (self->sysroot, bootversion, &configs, cancellable, error))
|
||||
if (!_ostree_sysroot_read_boot_loader_configs (self->sysroot, bootversion, &configs, cancellable,
|
||||
error))
|
||||
return glnx_prefix_error (error, "aboot: loading bls configs");
|
||||
|
||||
if (!configs || configs->len == 0)
|
||||
return glnx_throw (error, "aboot: no bls config");
|
||||
|
||||
OstreeBootconfigParser *parser = (OstreeBootconfigParser *) g_ptr_array_index (configs, 0);
|
||||
OstreeBootconfigParser *parser = (OstreeBootconfigParser *)g_ptr_array_index (configs, 0);
|
||||
const gchar *val = NULL;
|
||||
|
||||
val = ostree_bootconfig_parser_get (parser, "aboot");
|
||||
if (!val) {
|
||||
return glnx_throw (error, "aboot: no \"aboot\" key in bootloader config");
|
||||
}
|
||||
*aboot = g_strdup(val);
|
||||
if (!val)
|
||||
{
|
||||
return glnx_throw (error, "aboot: no \"aboot\" key in bootloader config");
|
||||
}
|
||||
*aboot = g_strdup (val);
|
||||
|
||||
val = ostree_bootconfig_parser_get (parser, "abootcfg");
|
||||
if (!val) {
|
||||
return glnx_throw (error, "aboot: no \"abootcfg\" key in bootloader config");
|
||||
}
|
||||
*abootcfg = g_strdup(val);
|
||||
if (!val)
|
||||
{
|
||||
return glnx_throw (error, "aboot: no \"abootcfg\" key in bootloader config");
|
||||
}
|
||||
*abootcfg = g_strdup (val);
|
||||
|
||||
val = ostree_bootconfig_parser_get (parser, "version");
|
||||
if (!val)
|
||||
return glnx_throw (error, "aboot: no \"version\" key in bootloader config");
|
||||
*version = g_strdup(val);
|
||||
*version = g_strdup (val);
|
||||
|
||||
val = ostree_bootconfig_parser_get (parser, "linux");
|
||||
if (!val)
|
||||
@ -132,16 +125,14 @@ _ostree_aboot_get_bls_config (OstreeBootloaderAboot *self,
|
||||
val = ostree_bootconfig_parser_get (parser, "options");
|
||||
if (!val)
|
||||
return glnx_throw (error, "aboot: no \"options\" key in bootloader config");
|
||||
*options = g_strdup(val);
|
||||
*options = g_strdup (val);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_ostree_bootloader_aboot_post_bls_sync (OstreeBootloader *bootloader,
|
||||
int bootversion,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_bootloader_aboot_post_bls_sync (OstreeBootloader *bootloader, int bootversion,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
OstreeBootloaderAboot *self = OSTREE_BOOTLOADER_ABOOT (bootloader);
|
||||
|
||||
@ -150,38 +141,43 @@ _ostree_bootloader_aboot_post_bls_sync (OstreeBootloader *bootloader,
|
||||
*/
|
||||
// g_assert (self->sysroot->booted_deployment);
|
||||
|
||||
if (!glnx_fstatat_allow_noent (self->sysroot->sysroot_fd, aboot_requires_execute_path, NULL, 0, error))
|
||||
if (!glnx_fstatat_allow_noent (self->sysroot->sysroot_fd, aboot_requires_execute_path, NULL, 0,
|
||||
error))
|
||||
return FALSE;
|
||||
|
||||
/* If there's no stamp file, nothing to do */
|
||||
if (errno == ENOENT)
|
||||
return TRUE;
|
||||
|
||||
g_autofree gchar* aboot = NULL;
|
||||
g_autofree gchar* abootcfg = NULL;
|
||||
g_autofree gchar* version = NULL;
|
||||
g_autofree gchar* vmlinuz = NULL;
|
||||
g_autofree gchar* initramfs = NULL;
|
||||
g_autofree gchar* options = NULL;
|
||||
if (!_ostree_aboot_get_bls_config (self, bootversion, &aboot, &abootcfg, &version, &vmlinuz, &initramfs, &options, cancellable, error))
|
||||
g_autofree gchar *aboot = NULL;
|
||||
g_autofree gchar *abootcfg = NULL;
|
||||
g_autofree gchar *version = NULL;
|
||||
g_autofree gchar *vmlinuz = NULL;
|
||||
g_autofree gchar *initramfs = NULL;
|
||||
g_autofree gchar *options = NULL;
|
||||
if (!_ostree_aboot_get_bls_config (self, bootversion, &aboot, &abootcfg, &version, &vmlinuz,
|
||||
&initramfs, &options, cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
g_autofree char *path_str = g_file_get_path(self->sysroot->path);
|
||||
g_autofree char *path_str = g_file_get_path (self->sysroot->path);
|
||||
|
||||
const char *const aboot_argv[] = {"aboot-deploy", "-r", path_str, "-c", abootcfg, aboot, NULL};
|
||||
const char *const aboot_argv[] = { "aboot-deploy", "-r", path_str, "-c", abootcfg, aboot, NULL };
|
||||
int estatus;
|
||||
if (!g_spawn_sync (NULL, (char**)aboot_argv, NULL, G_SPAWN_SEARCH_PATH,
|
||||
NULL, NULL, NULL, NULL, &estatus, error)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (!g_spawn_sync (NULL, (char **)aboot_argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL,
|
||||
&estatus, error))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!g_spawn_check_exit_status (estatus, error)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (!g_spawn_check_exit_status (estatus, error))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!glnx_unlinkat (self->sysroot->sysroot_fd, aboot_requires_execute_path, 0, error)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (!glnx_unlinkat (self->sysroot->sysroot_fd, aboot_requires_execute_path, 0, error))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -22,12 +22,14 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_BOOTLOADER_ABOOT (_ostree_bootloader_aboot_get_type ())
|
||||
#define OSTREE_BOOTLOADER_ABOOT(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_BOOTLOADER_ABOOT, OstreeBootloaderAboot))
|
||||
#define OSTREE_IS_BOOTLOADER_ABOOT(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), OSTREE_TYPE_BOOTLOADER_ABOOT))
|
||||
#define OSTREE_BOOTLOADER_ABOOT(inst) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_BOOTLOADER_ABOOT, OstreeBootloaderAboot))
|
||||
#define OSTREE_IS_BOOTLOADER_ABOOT(inst) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((inst), OSTREE_TYPE_BOOTLOADER_ABOOT))
|
||||
|
||||
typedef struct _OstreeBootloaderAboot OstreeBootloaderAboot;
|
||||
|
||||
GType _ostree_bootloader_aboot_get_type (void) G_GNUC_CONST;
|
||||
|
||||
OstreeBootloaderAboot * _ostree_bootloader_aboot_new (OstreeSysroot *sysroot);
|
||||
OstreeBootloaderAboot *_ostree_bootloader_aboot_new (OstreeSysroot *sysroot);
|
||||
G_END_DECLS
|
||||
|
@ -17,8 +17,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ostree-sysroot-private.h"
|
||||
#include "ostree-bootloader-grub2.h"
|
||||
#include "ostree-sysroot-private.h"
|
||||
#include "otutil.h"
|
||||
#include <gio/gfiledescriptorbased.h>
|
||||
#include <gio/gunixoutputstream.h>
|
||||
@ -32,7 +32,7 @@
|
||||
* Allow us to override this at build time if we're
|
||||
* using a modern GRUB installation.
|
||||
*/
|
||||
#if !defined(WITH_MODERN_GRUB) && ( defined(__i386__) || defined(__x86_64__) )
|
||||
#if !defined(WITH_MODERN_GRUB) && (defined(__i386__) || defined(__x86_64__))
|
||||
#define GRUB2_SUFFIX "16"
|
||||
#else
|
||||
#define GRUB2_SUFFIX ""
|
||||
@ -53,49 +53,48 @@
|
||||
|
||||
struct _OstreeBootloaderGrub2
|
||||
{
|
||||
GObject parent_instance;
|
||||
GObject parent_instance;
|
||||
|
||||
OstreeSysroot *sysroot;
|
||||
GFile *config_path_bios_1;
|
||||
GFile *config_path_bios_2;
|
||||
GFile *config_path_efi;
|
||||
gboolean is_efi;
|
||||
OstreeSysroot *sysroot;
|
||||
GFile *config_path_bios_1;
|
||||
GFile *config_path_bios_2;
|
||||
GFile *config_path_efi;
|
||||
gboolean is_efi;
|
||||
};
|
||||
|
||||
typedef GObjectClass OstreeBootloaderGrub2Class;
|
||||
|
||||
static void _ostree_bootloader_grub2_bootloader_iface_init (OstreeBootloaderInterface *iface);
|
||||
G_DEFINE_TYPE_WITH_CODE (OstreeBootloaderGrub2, _ostree_bootloader_grub2, G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_BOOTLOADER, _ostree_bootloader_grub2_bootloader_iface_init));
|
||||
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_BOOTLOADER,
|
||||
_ostree_bootloader_grub2_bootloader_iface_init));
|
||||
|
||||
static gboolean
|
||||
_ostree_bootloader_grub2_query (OstreeBootloader *bootloader,
|
||||
gboolean *out_is_active,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_bootloader_grub2_query (OstreeBootloader *bootloader, gboolean *out_is_active,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
OstreeBootloaderGrub2 *self = OSTREE_BOOTLOADER_GRUB2 (bootloader);
|
||||
|
||||
/* Look for the BIOS path first */
|
||||
if (g_file_query_exists (self->config_path_bios_1, NULL) ||
|
||||
g_file_query_exists (self->config_path_bios_2, NULL))
|
||||
if (g_file_query_exists (self->config_path_bios_1, NULL)
|
||||
|| g_file_query_exists (self->config_path_bios_2, NULL))
|
||||
{
|
||||
/* If we found it, we're done */
|
||||
*out_is_active = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
g_autoptr(GFile) efi_basedir = g_file_resolve_relative_path (self->sysroot->path, "boot/efi/EFI");
|
||||
g_autoptr (GFile) efi_basedir
|
||||
= g_file_resolve_relative_path (self->sysroot->path, "boot/efi/EFI");
|
||||
|
||||
g_clear_object (&self->config_path_efi);
|
||||
|
||||
if (g_file_query_exists (efi_basedir, NULL))
|
||||
{
|
||||
g_autoptr(GFileEnumerator) direnum = NULL;
|
||||
g_autoptr (GFileEnumerator) direnum = NULL;
|
||||
|
||||
direnum = g_file_enumerate_children (efi_basedir, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
cancellable, error);
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error);
|
||||
if (!direnum)
|
||||
return FALSE;
|
||||
|
||||
@ -104,8 +103,7 @@ _ostree_bootloader_grub2_query (OstreeBootloader *bootloader,
|
||||
GFileInfo *file_info;
|
||||
const char *fname;
|
||||
|
||||
if (!g_file_enumerator_iterate (direnum, &file_info, NULL,
|
||||
cancellable, error))
|
||||
if (!g_file_enumerator_iterate (direnum, &file_info, NULL, cancellable, error))
|
||||
return FALSE;
|
||||
if (file_info == NULL)
|
||||
break;
|
||||
@ -117,8 +115,8 @@ _ostree_bootloader_grub2_query (OstreeBootloader *bootloader,
|
||||
if (g_file_info_get_file_type (file_info) != G_FILE_TYPE_DIRECTORY)
|
||||
continue;
|
||||
|
||||
g_autofree char *subdir_grub_cfg =
|
||||
g_build_filename (gs_file_get_path_cached (efi_basedir), fname, "grub.cfg", NULL);
|
||||
g_autofree char *subdir_grub_cfg
|
||||
= g_build_filename (gs_file_get_path_cached (efi_basedir), fname, "grub.cfg", NULL);
|
||||
|
||||
if (g_file_test (subdir_grub_cfg, G_FILE_TEST_EXISTS))
|
||||
{
|
||||
@ -152,20 +150,15 @@ _ostree_bootloader_grub2_get_name (OstreeBootloader *bootloader)
|
||||
* https://github.com/ostreedev/ostree/issues/717
|
||||
*/
|
||||
gboolean
|
||||
_ostree_bootloader_grub2_generate_config (OstreeSysroot *sysroot,
|
||||
int bootversion,
|
||||
int target_fd,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_bootloader_grub2_generate_config (OstreeSysroot *sysroot, int bootversion, int target_fd,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
/* So... yeah. Just going to hardcode these. */
|
||||
static const char hardcoded_video[] = "load_video\n"
|
||||
"set gfxpayload=keep\n";
|
||||
"set gfxpayload=keep\n";
|
||||
static const char hardcoded_insmods[] = "insmod gzio\n";
|
||||
const char *grub2_boot_device_id =
|
||||
g_getenv ("GRUB2_BOOT_DEVICE_ID");
|
||||
const char *grub2_prepare_root_cache =
|
||||
g_getenv ("GRUB2_PREPARE_ROOT_CACHE");
|
||||
const char *grub2_boot_device_id = g_getenv ("GRUB2_BOOT_DEVICE_ID");
|
||||
const char *grub2_prepare_root_cache = g_getenv ("GRUB2_PREPARE_ROOT_CACHE");
|
||||
|
||||
/* We must have been called via the wrapper script */
|
||||
g_assert (grub2_boot_device_id != NULL);
|
||||
@ -174,15 +167,14 @@ _ostree_bootloader_grub2_generate_config (OstreeSysroot *sysroot
|
||||
/* Passed from the parent */
|
||||
gboolean is_efi = g_getenv ("_OSTREE_GRUB2_IS_EFI") != NULL;
|
||||
|
||||
g_autoptr(GOutputStream) out_stream = g_unix_output_stream_new (target_fd, FALSE);
|
||||
g_autoptr (GOutputStream) out_stream = g_unix_output_stream_new (target_fd, FALSE);
|
||||
|
||||
g_autoptr(GPtrArray) loader_configs = NULL;
|
||||
if (!_ostree_sysroot_read_boot_loader_configs (sysroot, bootversion,
|
||||
&loader_configs,
|
||||
cancellable, error))
|
||||
g_autoptr (GPtrArray) loader_configs = NULL;
|
||||
if (!_ostree_sysroot_read_boot_loader_configs (sysroot, bootversion, &loader_configs, cancellable,
|
||||
error))
|
||||
return FALSE;
|
||||
|
||||
g_autoptr(GString) output = g_string_new ("");
|
||||
g_autoptr (GString) output = g_string_new ("");
|
||||
for (guint i = 0; i < loader_configs->len; i++)
|
||||
{
|
||||
OstreeBootconfigParser *config = loader_configs->pdata[i];
|
||||
@ -204,7 +196,9 @@ _ostree_bootloader_grub2_generate_config (OstreeSysroot *sysroot
|
||||
quoted_title = g_shell_quote (title);
|
||||
uuid = g_strdup_printf ("ostree-%u-%s", (guint)i, grub2_boot_device_id);
|
||||
quoted_uuid = g_shell_quote (uuid);
|
||||
g_string_append_printf (output, "menuentry %s --class gnu-linux --class gnu --class os --unrestricted %s {\n", quoted_title, quoted_uuid);
|
||||
g_string_append_printf (
|
||||
output, "menuentry %s --class gnu-linux --class gnu --class os --unrestricted %s {\n",
|
||||
quoted_title, quoted_uuid);
|
||||
g_free (uuid);
|
||||
g_free (quoted_title);
|
||||
g_free (quoted_uuid);
|
||||
@ -259,14 +253,15 @@ _ostree_bootloader_grub2_generate_config (OstreeSysroot *sysroot
|
||||
}
|
||||
|
||||
gsize bytes_written;
|
||||
if (!g_output_stream_write_all (out_stream, output->str, output->len,
|
||||
&bytes_written, cancellable, error))
|
||||
if (!g_output_stream_write_all (out_stream, output->str, output->len, &bytes_written, cancellable,
|
||||
error))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
const char *root;
|
||||
const char *bootversion_str;
|
||||
gboolean is_efi;
|
||||
@ -302,7 +297,7 @@ grub2_child_setup (gpointer user_data)
|
||||
_exit (1);
|
||||
}
|
||||
|
||||
if (mount (NULL, "/", "none", MS_REC|MS_PRIVATE, NULL) < 0)
|
||||
if (mount (NULL, "/", "none", MS_REC | MS_PRIVATE, NULL) < 0)
|
||||
{
|
||||
perror ("Failed to make / a private mount");
|
||||
_exit (1);
|
||||
@ -329,15 +324,14 @@ grub2_child_setup (gpointer user_data)
|
||||
|
||||
/* Main entrypoint for writing GRUB configuration. */
|
||||
static gboolean
|
||||
_ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader,
|
||||
int bootversion,
|
||||
GPtrArray *new_deployments,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader, int bootversion,
|
||||
GPtrArray *new_deployments, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
OstreeBootloaderGrub2 *self = OSTREE_BOOTLOADER_GRUB2 (bootloader);
|
||||
|
||||
/* Autotests can set this envvar to select which code path to test, useful for OS installers as well */
|
||||
/* Autotests can set this envvar to select which code path to test, useful for OS installers as
|
||||
* well */
|
||||
gboolean use_system_grub2_mkconfig = TRUE;
|
||||
#ifdef USE_BUILTIN_GRUB2_MKCONFIG
|
||||
use_system_grub2_mkconfig = FALSE;
|
||||
@ -351,14 +345,15 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader,
|
||||
use_system_grub2_mkconfig = FALSE;
|
||||
}
|
||||
else
|
||||
grub_exec = use_system_grub2_mkconfig ? GRUB2_MKCONFIG_PATH : TARGET_PREFIX "/lib/ostree/ostree-grub-generator";
|
||||
grub_exec = use_system_grub2_mkconfig ? GRUB2_MKCONFIG_PATH
|
||||
: TARGET_PREFIX "/lib/ostree/ostree-grub-generator";
|
||||
|
||||
g_autofree char *grub2_mkconfig_chroot = NULL;
|
||||
if (use_system_grub2_mkconfig && ostree_sysroot_get_booted_deployment (self->sysroot) == NULL
|
||||
&& g_file_has_parent (self->sysroot->path, NULL))
|
||||
{
|
||||
OstreeDeployment *tool_deployment;
|
||||
g_autoptr(GFile) tool_deployment_root = NULL;
|
||||
g_autoptr (GFile) tool_deployment_root = NULL;
|
||||
|
||||
g_assert_cmpint (new_deployments->len, >, 0);
|
||||
tool_deployment = new_deployments->pdata[0];
|
||||
@ -372,14 +367,15 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader,
|
||||
* This all only applies if we're not using the builtin
|
||||
* generator, which handles being run outside of the root.
|
||||
*/
|
||||
tool_deployment_root = ostree_sysroot_get_deployment_directory (self->sysroot, tool_deployment);
|
||||
tool_deployment_root
|
||||
= ostree_sysroot_get_deployment_directory (self->sysroot, tool_deployment);
|
||||
grub2_mkconfig_chroot = g_file_get_path (tool_deployment_root);
|
||||
}
|
||||
|
||||
g_debug ("Using grub2-mkconfig chroot: %s\n", grub2_mkconfig_chroot);
|
||||
|
||||
g_autoptr(GFile) new_config_path = NULL;
|
||||
g_autoptr(GFile) config_path_efi_dir = NULL;
|
||||
g_autoptr (GFile) new_config_path = NULL;
|
||||
g_autoptr (GFile) config_path_efi_dir = NULL;
|
||||
if (self->is_efi)
|
||||
{
|
||||
config_path_efi_dir = g_file_get_parent (self->config_path_efi);
|
||||
@ -390,12 +386,14 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader,
|
||||
}
|
||||
else
|
||||
{
|
||||
new_config_path = ot_gfile_resolve_path_printf (self->sysroot->path, "boot/loader.%d/grub.cfg",
|
||||
bootversion);
|
||||
new_config_path = ot_gfile_resolve_path_printf (self->sysroot->path,
|
||||
"boot/loader.%d/grub.cfg", bootversion);
|
||||
}
|
||||
|
||||
const char *grub_argv[4] = { NULL, "-o", NULL, NULL};
|
||||
Grub2ChildSetupData cdata = { NULL, };
|
||||
const char *grub_argv[4] = { NULL, "-o", NULL, NULL };
|
||||
Grub2ChildSetupData cdata = {
|
||||
NULL,
|
||||
};
|
||||
grub_argv[0] = grub_exec;
|
||||
grub_argv[2] = gs_file_get_path_cached (new_config_path);
|
||||
|
||||
@ -415,9 +413,8 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader,
|
||||
Upstream is fixed though.
|
||||
*/
|
||||
int grub2_estatus;
|
||||
if (!g_spawn_sync (NULL, (char**)grub_argv, NULL, grub_spawnflags,
|
||||
grub2_child_setup, &cdata, NULL, NULL,
|
||||
&grub2_estatus, error))
|
||||
if (!g_spawn_sync (NULL, (char **)grub_argv, NULL, grub_spawnflags, grub2_child_setup, &cdata,
|
||||
NULL, NULL, &grub2_estatus, error))
|
||||
return FALSE;
|
||||
if (!g_spawn_check_exit_status (grub2_estatus, error))
|
||||
{
|
||||
@ -426,8 +423,10 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader,
|
||||
}
|
||||
|
||||
/* Now let's fdatasync() for the new file */
|
||||
{ glnx_autofd int new_config_fd = -1;
|
||||
if (!glnx_openat_rdonly (AT_FDCWD, gs_file_get_path_cached (new_config_path), TRUE, &new_config_fd, error))
|
||||
{
|
||||
glnx_autofd int new_config_fd = -1;
|
||||
if (!glnx_openat_rdonly (AT_FDCWD, gs_file_get_path_cached (new_config_path), TRUE,
|
||||
&new_config_fd, error))
|
||||
return FALSE;
|
||||
|
||||
if (fdatasync (new_config_fd) < 0)
|
||||
@ -436,13 +435,14 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader,
|
||||
|
||||
if (self->is_efi)
|
||||
{
|
||||
g_autoptr(GFile) config_path_efi_old = g_file_get_child (config_path_efi_dir, "grub.cfg.old");
|
||||
g_autoptr (GFile) config_path_efi_old
|
||||
= g_file_get_child (config_path_efi_dir, "grub.cfg.old");
|
||||
|
||||
/* copy current to old */
|
||||
if (!ot_gfile_ensure_unlinked (config_path_efi_old, cancellable, error))
|
||||
return FALSE;
|
||||
if (!g_file_copy (self->config_path_efi, config_path_efi_old,
|
||||
G_FILE_COPY_OVERWRITE, cancellable, NULL, NULL, error))
|
||||
if (!g_file_copy (self->config_path_efi, config_path_efi_old, G_FILE_COPY_OVERWRITE,
|
||||
cancellable, NULL, NULL, error))
|
||||
return FALSE;
|
||||
|
||||
/* NOTE: NON-ATOMIC REPLACEMENT; WE can't do anything else on FAT;
|
||||
@ -450,7 +450,9 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader,
|
||||
*/
|
||||
if (!ot_gfile_ensure_unlinked (self->config_path_efi, cancellable, error))
|
||||
return FALSE;
|
||||
if (rename (gs_file_get_path_cached (new_config_path), gs_file_get_path_cached (self->config_path_efi)) < 0)
|
||||
if (rename (gs_file_get_path_cached (new_config_path),
|
||||
gs_file_get_path_cached (self->config_path_efi))
|
||||
< 0)
|
||||
return glnx_throw_errno_prefix (error, "rename");
|
||||
}
|
||||
|
||||
@ -458,7 +460,7 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_ostree_bootloader_grub2_is_atomic (OstreeBootloader *bootloader)
|
||||
_ostree_bootloader_grub2_is_atomic (OstreeBootloader *bootloader)
|
||||
{
|
||||
OstreeBootloaderGrub2 *self = OSTREE_BOOTLOADER_GRUB2 (bootloader);
|
||||
return !self->is_efi;
|
||||
@ -505,8 +507,10 @@ _ostree_bootloader_grub2_new (OstreeSysroot *sysroot)
|
||||
OstreeBootloaderGrub2 *self = g_object_new (OSTREE_TYPE_BOOTLOADER_GRUB2, NULL);
|
||||
self->sysroot = g_object_ref (sysroot);
|
||||
/* Used by (at least) Debian */
|
||||
self->config_path_bios_1 = g_file_resolve_relative_path (self->sysroot->path, "boot/grub/grub.cfg");
|
||||
self->config_path_bios_1
|
||||
= g_file_resolve_relative_path (self->sysroot->path, "boot/grub/grub.cfg");
|
||||
/* Used by (at least) Fedora */
|
||||
self->config_path_bios_2 = g_file_resolve_relative_path (self->sysroot->path, "boot/grub2/grub.cfg");
|
||||
self->config_path_bios_2
|
||||
= g_file_resolve_relative_path (self->sysroot->path, "boot/grub2/grub.cfg");
|
||||
return self;
|
||||
}
|
||||
|
@ -22,15 +22,19 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_BOOTLOADER_GRUB2 (_ostree_bootloader_grub2_get_type ())
|
||||
#define OSTREE_BOOTLOADER_GRUB2(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_BOOTLOADER_GRUB2, OstreeBootloaderGrub2))
|
||||
#define OSTREE_IS_BOOTLOADER_GRUB2(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), OSTREE_TYPE_BOOTLOADER_GRUB2))
|
||||
#define OSTREE_BOOTLOADER_GRUB2(inst) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_BOOTLOADER_GRUB2, OstreeBootloaderGrub2))
|
||||
#define OSTREE_IS_BOOTLOADER_GRUB2(inst) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((inst), OSTREE_TYPE_BOOTLOADER_GRUB2))
|
||||
|
||||
typedef struct _OstreeBootloaderGrub2 OstreeBootloaderGrub2;
|
||||
|
||||
GType _ostree_bootloader_grub2_get_type (void) G_GNUC_CONST;
|
||||
|
||||
OstreeBootloaderGrub2 * _ostree_bootloader_grub2_new (OstreeSysroot *sysroot);
|
||||
OstreeBootloaderGrub2 *_ostree_bootloader_grub2_new (OstreeSysroot *sysroot);
|
||||
|
||||
gboolean _ostree_bootloader_grub2_generate_config (OstreeSysroot *sysroot, int bootversion, int target_fd, GCancellable *cancellable, GError **error);
|
||||
gboolean _ostree_bootloader_grub2_generate_config (OstreeSysroot *sysroot, int bootversion,
|
||||
int target_fd, GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -17,8 +17,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ostree-sysroot-private.h"
|
||||
#include "ostree-bootloader-syslinux.h"
|
||||
#include "ostree-sysroot-private.h"
|
||||
#include "otutil.h"
|
||||
|
||||
#include <string.h>
|
||||
@ -27,27 +27,27 @@ static const char syslinux_config_path[] = "boot/syslinux/syslinux.cfg";
|
||||
|
||||
struct _OstreeBootloaderSyslinux
|
||||
{
|
||||
GObject parent_instance;
|
||||
GObject parent_instance;
|
||||
|
||||
OstreeSysroot *sysroot;
|
||||
OstreeSysroot *sysroot;
|
||||
};
|
||||
|
||||
typedef GObjectClass OstreeBootloaderSyslinuxClass;
|
||||
|
||||
static void _ostree_bootloader_syslinux_bootloader_iface_init (OstreeBootloaderInterface *iface);
|
||||
G_DEFINE_TYPE_WITH_CODE (OstreeBootloaderSyslinux, _ostree_bootloader_syslinux, G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_BOOTLOADER, _ostree_bootloader_syslinux_bootloader_iface_init));
|
||||
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_BOOTLOADER,
|
||||
_ostree_bootloader_syslinux_bootloader_iface_init));
|
||||
|
||||
static gboolean
|
||||
_ostree_bootloader_syslinux_query (OstreeBootloader *bootloader,
|
||||
gboolean *out_is_active,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_bootloader_syslinux_query (OstreeBootloader *bootloader, gboolean *out_is_active,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
OstreeBootloaderSyslinux *self = OSTREE_BOOTLOADER_SYSLINUX (bootloader);
|
||||
struct stat stbuf;
|
||||
|
||||
if (!glnx_fstatat_allow_noent (self->sysroot->sysroot_fd, syslinux_config_path, &stbuf, AT_SYMLINK_NOFOLLOW, error))
|
||||
if (!glnx_fstatat_allow_noent (self->sysroot->sysroot_fd, syslinux_config_path, &stbuf,
|
||||
AT_SYMLINK_NOFOLLOW, error))
|
||||
return FALSE;
|
||||
*out_is_active = (errno == 0);
|
||||
return TRUE;
|
||||
@ -60,14 +60,11 @@ _ostree_bootloader_syslinux_get_name (OstreeBootloader *bootloader)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
append_config_from_loader_entries (OstreeBootloaderSyslinux *self,
|
||||
gboolean regenerate_default,
|
||||
int bootversion,
|
||||
GPtrArray *new_lines,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
append_config_from_loader_entries (OstreeBootloaderSyslinux *self, gboolean regenerate_default,
|
||||
int bootversion, GPtrArray *new_lines, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GPtrArray) loader_configs = NULL;
|
||||
g_autoptr (GPtrArray) loader_configs = NULL;
|
||||
if (!_ostree_sysroot_read_boot_loader_configs (self->sysroot, bootversion, &loader_configs,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
@ -106,27 +103,23 @@ append_config_from_loader_entries (OstreeBootloaderSyslinux *self,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader,
|
||||
int bootversion,
|
||||
GPtrArray *new_deployments,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader, int bootversion,
|
||||
GPtrArray *new_deployments, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
OstreeBootloaderSyslinux *self = OSTREE_BOOTLOADER_SYSLINUX (bootloader);
|
||||
|
||||
g_autofree char *new_config_path =
|
||||
g_strdup_printf ("boot/loader.%d/syslinux.cfg", bootversion);
|
||||
g_autofree char *new_config_path = g_strdup_printf ("boot/loader.%d/syslinux.cfg", bootversion);
|
||||
|
||||
/* This should follow the symbolic link to the current bootversion. */
|
||||
g_autofree char *config_contents =
|
||||
glnx_file_get_contents_utf8_at (self->sysroot->sysroot_fd, syslinux_config_path, NULL,
|
||||
cancellable, error);
|
||||
g_autofree char *config_contents = glnx_file_get_contents_utf8_at (
|
||||
self->sysroot->sysroot_fd, syslinux_config_path, NULL, cancellable, error);
|
||||
if (!config_contents)
|
||||
return FALSE;
|
||||
|
||||
g_auto(GStrv) lines = g_strsplit (config_contents, "\n", -1);
|
||||
g_autoptr(GPtrArray) new_lines = g_ptr_array_new_with_free_func (g_free);
|
||||
g_autoptr(GPtrArray) tmp_lines = g_ptr_array_new_with_free_func (g_free);
|
||||
g_auto (GStrv) lines = g_strsplit (config_contents, "\n", -1);
|
||||
g_autoptr (GPtrArray) new_lines = g_ptr_array_new_with_free_func (g_free);
|
||||
g_autoptr (GPtrArray) tmp_lines = g_ptr_array_new_with_free_func (g_free);
|
||||
|
||||
g_autofree char *kernel_arg = NULL;
|
||||
gboolean saw_default = FALSE;
|
||||
@ -141,8 +134,7 @@ _ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader,
|
||||
const char *line = *iter;
|
||||
gboolean skip = FALSE;
|
||||
|
||||
if (parsing_label &&
|
||||
(line == NULL || !g_str_has_prefix (line, "\t")))
|
||||
if (parsing_label && (line == NULL || !g_str_has_prefix (line, "\t")))
|
||||
{
|
||||
parsing_label = FALSE;
|
||||
if (kernel_arg == NULL)
|
||||
@ -153,8 +145,8 @@ _ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader,
|
||||
* We check for /ostree (without /boot prefix) as well to support
|
||||
* upgrading ostree from <v2020.4.
|
||||
*/
|
||||
if (!g_str_has_prefix (kernel_arg, "/ostree/") &&
|
||||
!g_str_has_prefix (kernel_arg, "/boot/ostree/"))
|
||||
if (!g_str_has_prefix (kernel_arg, "/ostree/")
|
||||
&& !g_str_has_prefix (kernel_arg, "/boot/ostree/"))
|
||||
{
|
||||
for (guint i = 0; i < tmp_lines->len; i++)
|
||||
{
|
||||
@ -174,8 +166,7 @@ _ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader,
|
||||
if (line == NULL)
|
||||
break;
|
||||
|
||||
if (!parsing_label &&
|
||||
(g_str_has_prefix (line, "LABEL ")))
|
||||
if (!parsing_label && (g_str_has_prefix (line, "LABEL ")))
|
||||
{
|
||||
parsing_label = TRUE;
|
||||
g_ptr_array_set_size (tmp_lines, 0);
|
||||
@ -185,15 +176,14 @@ _ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader,
|
||||
g_free (kernel_arg);
|
||||
kernel_arg = g_strdup (line + strlen ("\tKERNEL "));
|
||||
}
|
||||
else if (!parsing_label &&
|
||||
(g_str_has_prefix (line, "DEFAULT ")))
|
||||
else if (!parsing_label && (g_str_has_prefix (line, "DEFAULT ")))
|
||||
{
|
||||
saw_default = TRUE;
|
||||
/* XXX Searching for patterns in the title is rather brittle,
|
||||
* but this hack is at least noted in the code that builds
|
||||
* the title to hopefully avoid regressions. */
|
||||
if (g_str_has_prefix (line, "DEFAULT ostree:") || /* old format */
|
||||
strstr (line, "(ostree") != NULL) /* new format */
|
||||
if (g_str_has_prefix (line, "DEFAULT ostree:") || /* old format */
|
||||
strstr (line, "(ostree") != NULL) /* new format */
|
||||
regenerate_default = TRUE;
|
||||
skip = TRUE;
|
||||
}
|
||||
@ -210,16 +200,14 @@ _ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader,
|
||||
if (!saw_default)
|
||||
regenerate_default = TRUE;
|
||||
|
||||
if (!append_config_from_loader_entries (self, regenerate_default,
|
||||
bootversion, new_lines,
|
||||
if (!append_config_from_loader_entries (self, regenerate_default, bootversion, new_lines,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
g_autofree char *new_config_contents = _ostree_sysroot_join_lines (new_lines);
|
||||
if (!glnx_file_replace_contents_at (self->sysroot->sysroot_fd, new_config_path,
|
||||
(guint8*)new_config_contents, strlen (new_config_contents),
|
||||
GLNX_FILE_REPLACE_DATASYNC_NEW,
|
||||
cancellable, error))
|
||||
(guint8 *)new_config_contents, strlen (new_config_contents),
|
||||
GLNX_FILE_REPLACE_DATASYNC_NEW, cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
|
@ -22,13 +22,15 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_BOOTLOADER_SYSLINUX (_ostree_bootloader_syslinux_get_type ())
|
||||
#define OSTREE_BOOTLOADER_SYSLINUX(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_BOOTLOADER_SYSLINUX, OstreeBootloaderSyslinux))
|
||||
#define OSTREE_IS_BOOTLOADER_SYSLINUX(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), OSTREE_TYPE_BOOTLOADER_SYSLINUX))
|
||||
#define OSTREE_BOOTLOADER_SYSLINUX(inst) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_BOOTLOADER_SYSLINUX, OstreeBootloaderSyslinux))
|
||||
#define OSTREE_IS_BOOTLOADER_SYSLINUX(inst) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((inst), OSTREE_TYPE_BOOTLOADER_SYSLINUX))
|
||||
|
||||
typedef struct _OstreeBootloaderSyslinux OstreeBootloaderSyslinux;
|
||||
|
||||
GType _ostree_bootloader_syslinux_get_type (void) G_GNUC_CONST;
|
||||
|
||||
OstreeBootloaderSyslinux * _ostree_bootloader_syslinux_new (OstreeSysroot *sysroot);
|
||||
OstreeBootloaderSyslinux *_ostree_bootloader_syslinux_new (OstreeSysroot *sysroot);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -21,8 +21,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ostree-sysroot-private.h"
|
||||
#include "ostree-bootloader-uboot.h"
|
||||
#include "ostree-sysroot-private.h"
|
||||
#include "otutil.h"
|
||||
|
||||
#include <string.h>
|
||||
@ -31,27 +31,27 @@ static const char uboot_config_path[] = "boot/loader/uEnv.txt";
|
||||
|
||||
struct _OstreeBootloaderUboot
|
||||
{
|
||||
GObject parent_instance;
|
||||
GObject parent_instance;
|
||||
|
||||
OstreeSysroot *sysroot;
|
||||
OstreeSysroot *sysroot;
|
||||
};
|
||||
|
||||
typedef GObjectClass OstreeBootloaderUbootClass;
|
||||
|
||||
static void _ostree_bootloader_uboot_bootloader_iface_init (OstreeBootloaderInterface *iface);
|
||||
G_DEFINE_TYPE_WITH_CODE (OstreeBootloaderUboot, _ostree_bootloader_uboot, G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_BOOTLOADER, _ostree_bootloader_uboot_bootloader_iface_init));
|
||||
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_BOOTLOADER,
|
||||
_ostree_bootloader_uboot_bootloader_iface_init));
|
||||
|
||||
static gboolean
|
||||
_ostree_bootloader_uboot_query (OstreeBootloader *bootloader,
|
||||
gboolean *out_is_active,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_bootloader_uboot_query (OstreeBootloader *bootloader, gboolean *out_is_active,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
OstreeBootloaderUboot *self = OSTREE_BOOTLOADER_UBOOT (bootloader);
|
||||
struct stat stbuf;
|
||||
|
||||
if (!glnx_fstatat_allow_noent (self->sysroot->sysroot_fd, uboot_config_path, &stbuf, AT_SYMLINK_NOFOLLOW, error))
|
||||
if (!glnx_fstatat_allow_noent (self->sysroot->sysroot_fd, uboot_config_path, &stbuf,
|
||||
AT_SYMLINK_NOFOLLOW, error))
|
||||
return FALSE;
|
||||
*out_is_active = (errno == 0);
|
||||
return TRUE;
|
||||
@ -65,14 +65,11 @@ _ostree_bootloader_uboot_get_name (OstreeBootloader *bootloader)
|
||||
|
||||
/* Append system's uEnv.txt, if it exists in $deployment/usr/lib/ostree-boot/ */
|
||||
static gboolean
|
||||
append_system_uenv (OstreeBootloaderUboot *self,
|
||||
const char *bootargs,
|
||||
GPtrArray *new_lines,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
append_system_uenv (OstreeBootloaderUboot *self, const char *bootargs, GPtrArray *new_lines,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
glnx_autofd int uenv_fd = -1;
|
||||
g_autoptr(OstreeKernelArgs) kargs = NULL;
|
||||
g_autoptr (OstreeKernelArgs) kargs = NULL;
|
||||
const char *uenv_path = NULL;
|
||||
const char *ostree_arg = NULL;
|
||||
|
||||
@ -102,13 +99,11 @@ append_system_uenv (OstreeBootloaderUboot *self,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
create_config_from_boot_loader_entries (OstreeBootloaderUboot *self,
|
||||
int bootversion,
|
||||
GPtrArray *new_lines,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
create_config_from_boot_loader_entries (OstreeBootloaderUboot *self, int bootversion,
|
||||
GPtrArray *new_lines, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GPtrArray) boot_loader_configs = NULL;
|
||||
g_autoptr (GPtrArray) boot_loader_configs = NULL;
|
||||
OstreeBootconfigParser *config;
|
||||
const char *val;
|
||||
|
||||
@ -122,7 +117,7 @@ create_config_from_boot_loader_entries (OstreeBootloaderUboot *self,
|
||||
if (i == 0)
|
||||
index_suffix = g_strdup ("");
|
||||
else
|
||||
index_suffix = g_strdup_printf ("%d", i+1);
|
||||
index_suffix = g_strdup_printf ("%d", i + 1);
|
||||
config = boot_loader_configs->pdata[i];
|
||||
|
||||
val = ostree_bootconfig_parser_get (config, "linux");
|
||||
@ -160,32 +155,27 @@ create_config_from_boot_loader_entries (OstreeBootloaderUboot *self,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_ostree_bootloader_uboot_write_config (OstreeBootloader *bootloader,
|
||||
int bootversion,
|
||||
GPtrArray *new_deployments,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_bootloader_uboot_write_config (OstreeBootloader *bootloader, int bootversion,
|
||||
GPtrArray *new_deployments, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
OstreeBootloaderUboot *self = OSTREE_BOOTLOADER_UBOOT (bootloader);
|
||||
|
||||
/* This should follow the symbolic link to the current bootversion. */
|
||||
g_autofree char *config_contents =
|
||||
glnx_file_get_contents_utf8_at (self->sysroot->sysroot_fd, uboot_config_path, NULL,
|
||||
cancellable, error);
|
||||
g_autofree char *config_contents = glnx_file_get_contents_utf8_at (
|
||||
self->sysroot->sysroot_fd, uboot_config_path, NULL, cancellable, error);
|
||||
if (!config_contents)
|
||||
return FALSE;
|
||||
|
||||
g_autoptr(GPtrArray) new_lines = g_ptr_array_new_with_free_func (g_free);
|
||||
if (!create_config_from_boot_loader_entries (self, bootversion, new_lines,
|
||||
cancellable, error))
|
||||
g_autoptr (GPtrArray) new_lines = g_ptr_array_new_with_free_func (g_free);
|
||||
if (!create_config_from_boot_loader_entries (self, bootversion, new_lines, cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
g_autofree char *new_config_path = g_strdup_printf ("boot/loader.%d/uEnv.txt", bootversion);
|
||||
g_autofree char *new_config_contents = _ostree_sysroot_join_lines (new_lines);
|
||||
if (!glnx_file_replace_contents_at (self->sysroot->sysroot_fd, new_config_path,
|
||||
(guint8*)new_config_contents, strlen (new_config_contents),
|
||||
GLNX_FILE_REPLACE_DATASYNC_NEW,
|
||||
cancellable, error))
|
||||
(guint8 *)new_config_contents, strlen (new_config_contents),
|
||||
GLNX_FILE_REPLACE_DATASYNC_NEW, cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
|
@ -26,13 +26,15 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_BOOTLOADER_UBOOT (_ostree_bootloader_uboot_get_type ())
|
||||
#define OSTREE_BOOTLOADER_UBOOT(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_BOOTLOADER_UBOOT, OstreeBootloaderUboot))
|
||||
#define OSTREE_IS_BOOTLOADER_UBOOT(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), OSTREE_TYPE_BOOTLOADER_UBOOT))
|
||||
#define OSTREE_BOOTLOADER_UBOOT(inst) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_BOOTLOADER_UBOOT, OstreeBootloaderUboot))
|
||||
#define OSTREE_IS_BOOTLOADER_UBOOT(inst) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((inst), OSTREE_TYPE_BOOTLOADER_UBOOT))
|
||||
|
||||
typedef struct _OstreeBootloaderUboot OstreeBootloaderUboot;
|
||||
|
||||
GType _ostree_bootloader_uboot_get_type (void) G_GNUC_CONST;
|
||||
|
||||
OstreeBootloaderUboot * _ostree_bootloader_uboot_new (OstreeSysroot *sysroot);
|
||||
OstreeBootloaderUboot *_ostree_bootloader_uboot_new (OstreeSysroot *sysroot);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -17,24 +17,24 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ostree-sysroot-private.h"
|
||||
#include "ostree-bootloader-zipl.h"
|
||||
#include "ostree-deployment-private.h"
|
||||
#include "ostree-libarchive-private.h"
|
||||
#include "ostree-sysroot-private.h"
|
||||
#include "otutil.h"
|
||||
#include <string.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
|
||||
#define SECURE_EXECUTION_SYSFS_FLAG "/sys/firmware/uv/prot_virt_guest"
|
||||
#define SECURE_EXECUTION_PARTITION "/dev/disk/by-label/se"
|
||||
#define SECURE_EXECUTION_MOUNTPOINT "/sysroot/se"
|
||||
#define SECURE_EXECUTION_BOOT_IMAGE SECURE_EXECUTION_MOUNTPOINT "/sdboot"
|
||||
#define SECURE_EXECUTION_HOSTKEY_PATH "/etc/se-hostkeys/"
|
||||
#define SECURE_EXECUTION_SYSFS_FLAG "/sys/firmware/uv/prot_virt_guest"
|
||||
#define SECURE_EXECUTION_PARTITION "/dev/disk/by-label/se"
|
||||
#define SECURE_EXECUTION_MOUNTPOINT "/sysroot/se"
|
||||
#define SECURE_EXECUTION_BOOT_IMAGE SECURE_EXECUTION_MOUNTPOINT "/sdboot"
|
||||
#define SECURE_EXECUTION_HOSTKEY_PATH "/etc/se-hostkeys/"
|
||||
#define SECURE_EXECUTION_HOSTKEY_PREFIX "ibm-z-hostkey"
|
||||
#define SECURE_EXECUTION_LUKS_ROOT_KEY "/etc/luks/root"
|
||||
#define SECURE_EXECUTION_LUKS_BOOT_KEY "/etc/luks/boot"
|
||||
#define SECURE_EXECUTION_LUKS_CONFIG "/etc/crypttab"
|
||||
#define SECURE_EXECUTION_LUKS_ROOT_KEY "/etc/luks/root"
|
||||
#define SECURE_EXECUTION_LUKS_BOOT_KEY "/etc/luks/boot"
|
||||
#define SECURE_EXECUTION_LUKS_CONFIG "/etc/crypttab"
|
||||
|
||||
#if !(defined HAVE_LIBARCHIVE) && defined(__s390x__)
|
||||
#error libarchive is required for s390x
|
||||
@ -47,22 +47,21 @@ static const char zipl_requires_execute_path[] = "boot/ostree-bootloader-update.
|
||||
|
||||
struct _OstreeBootloaderZipl
|
||||
{
|
||||
GObject parent_instance;
|
||||
GObject parent_instance;
|
||||
|
||||
OstreeSysroot *sysroot;
|
||||
OstreeSysroot *sysroot;
|
||||
};
|
||||
|
||||
typedef GObjectClass OstreeBootloaderZiplClass;
|
||||
|
||||
static void _ostree_bootloader_zipl_bootloader_iface_init (OstreeBootloaderInterface *iface);
|
||||
G_DEFINE_TYPE_WITH_CODE (OstreeBootloaderZipl, _ostree_bootloader_zipl, G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_BOOTLOADER, _ostree_bootloader_zipl_bootloader_iface_init));
|
||||
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_BOOTLOADER,
|
||||
_ostree_bootloader_zipl_bootloader_iface_init));
|
||||
|
||||
static gboolean
|
||||
_ostree_bootloader_zipl_query (OstreeBootloader *bootloader,
|
||||
gboolean *out_is_active,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_bootloader_zipl_query (OstreeBootloader *bootloader, gboolean *out_is_active,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
/* We don't auto-detect this one; should be explicitly chosen right now.
|
||||
* see also https://github.com/coreos/coreos-assembler/pull/849
|
||||
@ -78,18 +77,18 @@ _ostree_bootloader_zipl_get_name (OstreeBootloader *bootloader)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_ostree_secure_execution_mount(GError **error)
|
||||
_ostree_secure_execution_mount (GError **error)
|
||||
{
|
||||
const char *device = realpath (SECURE_EXECUTION_PARTITION, NULL);
|
||||
if (device == NULL)
|
||||
return glnx_throw_errno_prefix(error, "s390x SE: resolving %s", SECURE_EXECUTION_PARTITION);
|
||||
return glnx_throw_errno_prefix (error, "s390x SE: resolving %s", SECURE_EXECUTION_PARTITION);
|
||||
if (mount (device, SECURE_EXECUTION_MOUNTPOINT, "ext4", 0, NULL) < 0)
|
||||
return glnx_throw_errno_prefix (error, "s390x SE: Mounting %s", device);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_ostree_secure_execution_umount(GError **error)
|
||||
_ostree_secure_execution_umount (GError **error)
|
||||
{
|
||||
if (umount (SECURE_EXECUTION_MOUNTPOINT) < 0)
|
||||
return glnx_throw_errno_prefix (error, "s390x SE: Unmounting %s", SECURE_EXECUTION_MOUNTPOINT);
|
||||
@ -97,33 +96,31 @@ _ostree_secure_execution_umount(GError **error)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_ostree_bootloader_zipl_write_config (OstreeBootloader *bootloader,
|
||||
int bootversion,
|
||||
GPtrArray *new_deployments,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_bootloader_zipl_write_config (OstreeBootloader *bootloader, int bootversion,
|
||||
GPtrArray *new_deployments, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
OstreeBootloaderZipl *self = OSTREE_BOOTLOADER_ZIPL (bootloader);
|
||||
|
||||
/* Write our stamp file */
|
||||
if (!glnx_file_replace_contents_at (self->sysroot->sysroot_fd, zipl_requires_execute_path,
|
||||
(guint8*)"", 0, GLNX_FILE_REPLACE_NODATASYNC,
|
||||
cancellable, error))
|
||||
(guint8 *)"", 0, GLNX_FILE_REPLACE_NODATASYNC, cancellable,
|
||||
error))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean _ostree_secure_execution_is_enabled (gboolean *out_enabled,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
static gboolean
|
||||
_ostree_secure_execution_is_enabled (gboolean *out_enabled, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
*out_enabled = FALSE;
|
||||
glnx_autofd int fd = -1;
|
||||
if (!ot_openat_ignore_enoent (AT_FDCWD, SECURE_EXECUTION_SYSFS_FLAG, &fd, error))
|
||||
return FALSE;
|
||||
if (fd == -1)
|
||||
return TRUE; //ENOENT --> SecureExecution is disabled
|
||||
return TRUE; // ENOENT --> SecureExecution is disabled
|
||||
g_autofree char *data = glnx_fd_readall_utf8 (fd, NULL, cancellable, error);
|
||||
if (!data)
|
||||
return FALSE;
|
||||
@ -132,15 +129,15 @@ static gboolean _ostree_secure_execution_is_enabled (gboolean *out_enabled,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_ostree_secure_execution_get_keys (GPtrArray **keys,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_secure_execution_get_keys (GPtrArray **keys, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
g_auto (GLnxDirFdIterator) it = { 0,};
|
||||
if ( !glnx_dirfd_iterator_init_at (-1, SECURE_EXECUTION_HOSTKEY_PATH, TRUE, &it, error))
|
||||
g_auto (GLnxDirFdIterator) it = {
|
||||
0,
|
||||
};
|
||||
if (!glnx_dirfd_iterator_init_at (-1, SECURE_EXECUTION_HOSTKEY_PATH, TRUE, &it, error))
|
||||
return glnx_prefix_error (error, "s390x SE: looking for SE keys");
|
||||
|
||||
g_autoptr(GPtrArray) ret_keys = g_ptr_array_new_with_free_func (g_free);
|
||||
g_autoptr (GPtrArray) ret_keys = g_ptr_array_new_with_free_func (g_free);
|
||||
while (TRUE)
|
||||
{
|
||||
struct dirent *dent = NULL;
|
||||
@ -151,7 +148,8 @@ _ostree_secure_execution_get_keys (GPtrArray **keys,
|
||||
break;
|
||||
|
||||
if (g_str_has_prefix (dent->d_name, SECURE_EXECUTION_HOSTKEY_PREFIX))
|
||||
g_ptr_array_add (ret_keys, g_build_filename (SECURE_EXECUTION_HOSTKEY_PATH, dent->d_name, NULL));
|
||||
g_ptr_array_add (ret_keys,
|
||||
g_build_filename (SECURE_EXECUTION_HOSTKEY_PATH, dent->d_name, NULL));
|
||||
}
|
||||
|
||||
*keys = g_steal_pointer (&ret_keys);
|
||||
@ -159,22 +157,19 @@ _ostree_secure_execution_get_keys (GPtrArray **keys,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_ostree_secure_execution_get_bls_config (OstreeBootloaderZipl *self,
|
||||
int bootversion,
|
||||
gchar **vmlinuz,
|
||||
gchar **initramfs,
|
||||
gchar **options,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_secure_execution_get_bls_config (OstreeBootloaderZipl *self, int bootversion,
|
||||
gchar **vmlinuz, gchar **initramfs, gchar **options,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
g_autoptr (GPtrArray) configs = NULL;
|
||||
if ( !_ostree_sysroot_read_boot_loader_configs (self->sysroot, bootversion, &configs, cancellable, error))
|
||||
if (!_ostree_sysroot_read_boot_loader_configs (self->sysroot, bootversion, &configs, cancellable,
|
||||
error))
|
||||
return glnx_prefix_error (error, "s390x SE: loading bls configs");
|
||||
|
||||
if (!configs || configs->len == 0)
|
||||
return glnx_throw (error, "s390x SE: no bls config");
|
||||
|
||||
OstreeBootconfigParser *parser = (OstreeBootconfigParser *) g_ptr_array_index (configs, 0);
|
||||
OstreeBootconfigParser *parser = (OstreeBootconfigParser *)g_ptr_array_index (configs, 0);
|
||||
const gchar *val = NULL;
|
||||
|
||||
val = ostree_bootconfig_parser_get (parser, "linux");
|
||||
@ -190,7 +185,7 @@ _ostree_secure_execution_get_bls_config (OstreeBootloaderZipl *self,
|
||||
val = ostree_bootconfig_parser_get (parser, "options");
|
||||
if (!val)
|
||||
return glnx_throw (error, "s390x SE: no \"options\" key in bootloader config");
|
||||
*options = g_strdup(val);
|
||||
*options = g_strdup (val);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -198,73 +193,71 @@ _ostree_secure_execution_get_bls_config (OstreeBootloaderZipl *self,
|
||||
static gboolean
|
||||
_ostree_secure_execution_luks_key_exists (void)
|
||||
{
|
||||
return (access(SECURE_EXECUTION_LUKS_CONFIG, F_OK) == 0 &&
|
||||
access(SECURE_EXECUTION_LUKS_ROOT_KEY, F_OK) == 0 &&
|
||||
access(SECURE_EXECUTION_LUKS_BOOT_KEY, F_OK) == 0);
|
||||
return (access (SECURE_EXECUTION_LUKS_CONFIG, F_OK) == 0
|
||||
&& access (SECURE_EXECUTION_LUKS_ROOT_KEY, F_OK) == 0
|
||||
&& access (SECURE_EXECUTION_LUKS_BOOT_KEY, F_OK) == 0);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_ostree_secure_execution_append_luks_keys (int initrd_fd,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_secure_execution_append_luks_keys (int initrd_fd, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
#ifdef HAVE_LIBARCHIVE
|
||||
// appending cpio gzip archive with LUKS keys
|
||||
g_autoptr(OtAutoArchiveWrite) a = archive_write_new ();
|
||||
g_autoptr (OtAutoArchiveWrite) a = archive_write_new ();
|
||||
g_assert (a != NULL);
|
||||
|
||||
if (archive_write_set_format_cpio_newc (a) != 0 ||
|
||||
archive_write_add_filter_gzip (a) != 0 ||
|
||||
archive_write_open_fd(a, initrd_fd) != 0)
|
||||
if (archive_write_set_format_cpio_newc (a) != 0 || archive_write_add_filter_gzip (a) != 0
|
||||
|| archive_write_open_fd (a, initrd_fd) != 0)
|
||||
return glnx_prefix_error (error, "s390x SE: initing cpio: %s", archive_error_string (a));
|
||||
|
||||
const char *files[] = {"/etc", "/etc/luks", SECURE_EXECUTION_LUKS_CONFIG, SECURE_EXECUTION_LUKS_BOOT_KEY, SECURE_EXECUTION_LUKS_ROOT_KEY};
|
||||
const char *files[] = { "/etc", "/etc/luks", SECURE_EXECUTION_LUKS_CONFIG,
|
||||
SECURE_EXECUTION_LUKS_BOOT_KEY, SECURE_EXECUTION_LUKS_ROOT_KEY };
|
||||
for (uint i = 0; i != G_N_ELEMENTS (files); ++i)
|
||||
{
|
||||
const char *path = files[i];
|
||||
struct stat st;
|
||||
if (stat(path, &st) != 0)
|
||||
if (stat (path, &st) != 0)
|
||||
glnx_throw_errno_prefix (error, "s390x SE: stat(%s) failed", path);
|
||||
|
||||
g_autoptr(OtArchiveEntry) ae = archive_entry_new ();
|
||||
g_autoptr (OtArchiveEntry) ae = archive_entry_new ();
|
||||
g_assert (ae != NULL);
|
||||
|
||||
archive_entry_copy_stat (ae, &st);
|
||||
archive_entry_set_pathname (ae, path);
|
||||
if (archive_write_header (a, ae) != 0)
|
||||
glnx_prefix_error (error, "s390x SE: writing cpio header: %s", archive_error_string (a));
|
||||
glnx_prefix_error (error, "s390x SE: writing cpio header: %s", archive_error_string (a));
|
||||
|
||||
if (S_ISREG (st.st_mode))
|
||||
{
|
||||
ot_journal_print(LOG_INFO, "s390x SE: appending %s to initrd", path);
|
||||
ot_journal_print (LOG_INFO, "s390x SE: appending %s to initrd", path);
|
||||
glnx_autofd int fd = -1;
|
||||
if (!glnx_openat_rdonly (AT_FDCWD, path, TRUE, &fd, error))
|
||||
return glnx_prefix_error (error, "s390x SE: opening %s", path);
|
||||
g_autoptr(GBytes) data = glnx_fd_readall_bytes (fd, cancellable, error);
|
||||
g_autoptr (GBytes) data = glnx_fd_readall_bytes (fd, cancellable, error);
|
||||
if (!data)
|
||||
return glnx_prefix_error (error, "s390x SE: reading %s", path);
|
||||
|
||||
gsize size = 0;
|
||||
const char *ptr = (const char *) g_bytes_get_data (data, &size);
|
||||
const char *ptr = (const char *)g_bytes_get_data (data, &size);
|
||||
ssize_t written = archive_write_data (a, ptr, size);
|
||||
if (written == -1)
|
||||
return glnx_prefix_error (error, "s390x SE: writing cpio entry: %s", archive_error_string (a));
|
||||
return glnx_prefix_error (error, "s390x SE: writing cpio entry: %s",
|
||||
archive_error_string (a));
|
||||
if (written != size)
|
||||
return glnx_prefix_error (error, "s390x SE: writing cpio entry %zd != %zu", written, size);
|
||||
return glnx_prefix_error (error, "s390x SE: writing cpio entry %zd != %zu", written,
|
||||
size);
|
||||
}
|
||||
}
|
||||
ot_journal_print(LOG_INFO, "s390x SE: luks keys added to initrd");
|
||||
ot_journal_print (LOG_INFO, "s390x SE: luks keys added to initrd");
|
||||
return TRUE;
|
||||
#else
|
||||
#else
|
||||
return glnx_throw (error, "'libarchive' is required for s390x");
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_ostree_secure_execution_generate_initrd (const gchar *initrd,
|
||||
GLnxTmpfile *out_initrd,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_secure_execution_generate_initrd (const gchar *initrd, GLnxTmpfile *out_initrd,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
if (!_ostree_secure_execution_luks_key_exists ())
|
||||
return glnx_throw (error, "s390x SE: missing luks keys and config");
|
||||
@ -275,7 +268,7 @@ _ostree_secure_execution_generate_initrd (const gchar *initrd,
|
||||
glnx_autofd int fd = -1;
|
||||
if (!glnx_openat_rdonly (AT_FDCWD, initrd, TRUE, &fd, error))
|
||||
return glnx_prefix_error (error, "s390x SE: opening initrd");
|
||||
if (glnx_regfile_copy_bytes (fd, out_initrd->fd, (off_t) -1) < 0)
|
||||
if (glnx_regfile_copy_bytes (fd, out_initrd->fd, (off_t)-1) < 0)
|
||||
return glnx_throw_errno_prefix (error, "s390x SE: copying ramdisk");
|
||||
}
|
||||
|
||||
@ -283,22 +276,21 @@ _ostree_secure_execution_generate_initrd (const gchar *initrd,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_ostree_secure_execution_generate_sdboot (gchar *vmlinuz,
|
||||
gchar *initramfs,
|
||||
gchar *options,
|
||||
GPtrArray *keys,
|
||||
GCancellable *cancellable,
|
||||
_ostree_secure_execution_generate_sdboot (gchar *vmlinuz, gchar *initramfs, gchar *options,
|
||||
GPtrArray *keys, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
g_assert (vmlinuz && initramfs && options && keys && keys->len);
|
||||
ot_journal_print(LOG_INFO, "s390x SE: kernel: %s", vmlinuz);
|
||||
ot_journal_print(LOG_INFO, "s390x SE: initrd: %s", initramfs);
|
||||
ot_journal_print(LOG_INFO, "s390x SE: kargs: %s", options);
|
||||
ot_journal_print (LOG_INFO, "s390x SE: kernel: %s", vmlinuz);
|
||||
ot_journal_print (LOG_INFO, "s390x SE: initrd: %s", initramfs);
|
||||
ot_journal_print (LOG_INFO, "s390x SE: kargs: %s", options);
|
||||
|
||||
pid_t self = getpid ();
|
||||
|
||||
// Store kernel options to temp file, so `genprotimg` can later embed it
|
||||
g_auto(GLnxTmpfile) cmdline = { 0, };
|
||||
g_auto (GLnxTmpfile) cmdline = {
|
||||
0,
|
||||
};
|
||||
if (!glnx_open_anonymous_tmpfile (O_RDWR | O_CLOEXEC, &cmdline, error))
|
||||
return glnx_prefix_error (error, "s390x SE: opening cmdline file");
|
||||
if (glnx_loop_write (cmdline.fd, options, strlen (options)) < 0)
|
||||
@ -306,12 +298,14 @@ _ostree_secure_execution_generate_sdboot (gchar *vmlinuz,
|
||||
g_autofree gchar *cmdline_filename = g_strdup_printf ("/proc/%d/fd/%d", self, cmdline.fd);
|
||||
|
||||
// Copy initramfs to temp file and embed LUKS keys & config into it
|
||||
g_auto(GLnxTmpfile) ramdisk = { 0, };
|
||||
g_auto (GLnxTmpfile) ramdisk = {
|
||||
0,
|
||||
};
|
||||
if (!_ostree_secure_execution_generate_initrd (initramfs, &ramdisk, cancellable, error))
|
||||
return FALSE;
|
||||
g_autofree gchar *ramdisk_filename = g_strdup_printf ("/proc/%d/fd/%d", self, ramdisk.fd);
|
||||
|
||||
g_autoptr(GPtrArray) argv = g_ptr_array_new ();
|
||||
g_autoptr (GPtrArray) argv = g_ptr_array_new ();
|
||||
g_ptr_array_add (argv, "genprotimg");
|
||||
g_ptr_array_add (argv, "-i");
|
||||
g_ptr_array_add (argv, vmlinuz);
|
||||
@ -324,7 +318,7 @@ _ostree_secure_execution_generate_sdboot (gchar *vmlinuz,
|
||||
gchar *key = g_ptr_array_index (keys, i);
|
||||
g_ptr_array_add (argv, "-k");
|
||||
g_ptr_array_add (argv, key);
|
||||
ot_journal_print(LOG_INFO, "s390x SE: key[%d]: %s", i + 1, key);
|
||||
ot_journal_print (LOG_INFO, "s390x SE: key[%d]: %s", i + 1, key);
|
||||
}
|
||||
g_ptr_array_add (argv, "--no-verify");
|
||||
g_ptr_array_add (argv, "-o");
|
||||
@ -332,14 +326,14 @@ _ostree_secure_execution_generate_sdboot (gchar *vmlinuz,
|
||||
g_ptr_array_add (argv, NULL);
|
||||
|
||||
gint status = 0;
|
||||
if (!g_spawn_sync (NULL, (char**)argv->pdata, NULL, G_SPAWN_SEARCH_PATH,
|
||||
NULL, NULL, NULL, NULL, &status, error))
|
||||
return glnx_prefix_error(error, "s390x SE: spawning genprotimg");
|
||||
if (!g_spawn_sync (NULL, (char **)argv->pdata, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL,
|
||||
&status, error))
|
||||
return glnx_prefix_error (error, "s390x SE: spawning genprotimg");
|
||||
|
||||
if (!g_spawn_check_exit_status (status, error))
|
||||
return glnx_prefix_error(error, "s390x SE: `genprotimg` failed");
|
||||
return glnx_prefix_error (error, "s390x SE: `genprotimg` failed");
|
||||
|
||||
ot_journal_print(LOG_INFO, "s390x SE: `%s` generated", SECURE_EXECUTION_BOOT_IMAGE);
|
||||
ot_journal_print (LOG_INFO, "s390x SE: `%s` generated", SECURE_EXECUTION_BOOT_IMAGE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -347,45 +341,42 @@ static gboolean
|
||||
_ostree_secure_execution_call_zipl (GError **error)
|
||||
{
|
||||
int status = 0;
|
||||
const char *const zipl_argv[] = {"zipl", "-V", "-t", SECURE_EXECUTION_MOUNTPOINT, "-i", SECURE_EXECUTION_BOOT_IMAGE, NULL};
|
||||
if (!g_spawn_sync (NULL, (char**)zipl_argv, NULL, G_SPAWN_SEARCH_PATH,
|
||||
NULL, NULL, NULL, NULL, &status, error))
|
||||
return glnx_prefix_error(error, "s390x SE: spawning zipl");
|
||||
const char *const zipl_argv[] = {
|
||||
"zipl", "-V", "-t", SECURE_EXECUTION_MOUNTPOINT, "-i", SECURE_EXECUTION_BOOT_IMAGE, NULL
|
||||
};
|
||||
if (!g_spawn_sync (NULL, (char **)zipl_argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL,
|
||||
&status, error))
|
||||
return glnx_prefix_error (error, "s390x SE: spawning zipl");
|
||||
|
||||
if (!g_spawn_check_exit_status (status, error))
|
||||
return glnx_prefix_error(error, "s390x SE: `zipl` failed");
|
||||
return glnx_prefix_error (error, "s390x SE: `zipl` failed");
|
||||
|
||||
ot_journal_print(LOG_INFO, "s390x SE: `sdboot` zipled");
|
||||
ot_journal_print (LOG_INFO, "s390x SE: `sdboot` zipled");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_ostree_secure_execution_enable (OstreeBootloaderZipl *self,
|
||||
int bootversion,
|
||||
GPtrArray *keys,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_secure_execution_enable (OstreeBootloaderZipl *self, int bootversion, GPtrArray *keys,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
g_autofree gchar* vmlinuz = NULL;
|
||||
g_autofree gchar* initramfs = NULL;
|
||||
g_autofree gchar* options = NULL;
|
||||
g_autofree gchar *vmlinuz = NULL;
|
||||
g_autofree gchar *initramfs = NULL;
|
||||
g_autofree gchar *options = NULL;
|
||||
|
||||
gboolean rc =
|
||||
_ostree_secure_execution_mount (error) &&
|
||||
_ostree_secure_execution_get_bls_config (self, bootversion, &vmlinuz, &initramfs, &options, cancellable, error) &&
|
||||
_ostree_secure_execution_generate_sdboot (vmlinuz, initramfs, options, keys, cancellable, error) &&
|
||||
_ostree_secure_execution_call_zipl (error) &&
|
||||
_ostree_secure_execution_umount (error);
|
||||
gboolean rc = _ostree_secure_execution_mount (error)
|
||||
&& _ostree_secure_execution_get_bls_config (self, bootversion, &vmlinuz, &initramfs,
|
||||
&options, cancellable, error)
|
||||
&& _ostree_secure_execution_generate_sdboot (vmlinuz, initramfs, options, keys,
|
||||
cancellable, error)
|
||||
&& _ostree_secure_execution_call_zipl (error)
|
||||
&& _ostree_secure_execution_umount (error);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
_ostree_bootloader_zipl_post_bls_sync (OstreeBootloader *bootloader,
|
||||
int bootversion,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_bootloader_zipl_post_bls_sync (OstreeBootloader *bootloader, int bootversion,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
OstreeBootloaderZipl *self = OSTREE_BOOTLOADER_ZIPL (bootloader);
|
||||
|
||||
@ -394,7 +385,8 @@ _ostree_bootloader_zipl_post_bls_sync (OstreeBootloader *bootloader,
|
||||
*/
|
||||
g_assert (self->sysroot->booted_deployment);
|
||||
|
||||
if (!glnx_fstatat_allow_noent (self->sysroot->sysroot_fd, zipl_requires_execute_path, NULL, 0, error))
|
||||
if (!glnx_fstatat_allow_noent (self->sysroot->sysroot_fd, zipl_requires_execute_path, NULL, 0,
|
||||
error))
|
||||
return FALSE;
|
||||
|
||||
/* If there's no stamp file, nothing to do */
|
||||
@ -403,11 +395,11 @@ _ostree_bootloader_zipl_post_bls_sync (OstreeBootloader *bootloader,
|
||||
|
||||
/* Try with Secure Execution */
|
||||
gboolean se_enabled = FALSE;
|
||||
if ( !_ostree_secure_execution_is_enabled (&se_enabled, cancellable, error))
|
||||
if (!_ostree_secure_execution_is_enabled (&se_enabled, cancellable, error))
|
||||
return FALSE;
|
||||
if (se_enabled)
|
||||
{
|
||||
g_autoptr(GPtrArray) keys = NULL;
|
||||
g_autoptr (GPtrArray) keys = NULL;
|
||||
if (!_ostree_secure_execution_get_keys (&keys, cancellable, error))
|
||||
return FALSE;
|
||||
if (!keys || keys->len == 0)
|
||||
@ -415,10 +407,10 @@ _ostree_bootloader_zipl_post_bls_sync (OstreeBootloader *bootloader,
|
||||
return _ostree_secure_execution_enable (self, bootversion, keys, cancellable, error);
|
||||
}
|
||||
/* Fallback to non-SE setup */
|
||||
const char *const zipl_argv[] = {"zipl", NULL};
|
||||
const char *const zipl_argv[] = { "zipl", NULL };
|
||||
int estatus;
|
||||
if (!g_spawn_sync (NULL, (char**)zipl_argv, NULL, G_SPAWN_SEARCH_PATH,
|
||||
NULL, NULL, NULL, NULL, &estatus, error))
|
||||
if (!g_spawn_sync (NULL, (char **)zipl_argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL,
|
||||
&estatus, error))
|
||||
return FALSE;
|
||||
if (!g_spawn_check_exit_status (estatus, error))
|
||||
return FALSE;
|
||||
|
@ -22,12 +22,14 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_BOOTLOADER_ZIPL (_ostree_bootloader_zipl_get_type ())
|
||||
#define OSTREE_BOOTLOADER_ZIPL(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_BOOTLOADER_ZIPL, OstreeBootloaderZipl))
|
||||
#define OSTREE_IS_BOOTLOADER_ZIPL(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), OSTREE_TYPE_BOOTLOADER_ZIPL))
|
||||
#define OSTREE_BOOTLOADER_ZIPL(inst) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_BOOTLOADER_ZIPL, OstreeBootloaderZipl))
|
||||
#define OSTREE_IS_BOOTLOADER_ZIPL(inst) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((inst), OSTREE_TYPE_BOOTLOADER_ZIPL))
|
||||
|
||||
typedef struct _OstreeBootloaderZipl OstreeBootloaderZipl;
|
||||
|
||||
GType _ostree_bootloader_zipl_get_type (void) G_GNUC_CONST;
|
||||
|
||||
OstreeBootloaderZipl * _ostree_bootloader_zipl_new (OstreeSysroot *sysroot);
|
||||
OstreeBootloaderZipl *_ostree_bootloader_zipl_new (OstreeSysroot *sysroot);
|
||||
G_END_DECLS
|
||||
|
@ -27,10 +27,8 @@ _ostree_bootloader_default_init (OstreeBootloaderInterface *iface)
|
||||
}
|
||||
|
||||
gboolean
|
||||
_ostree_bootloader_query (OstreeBootloader *self,
|
||||
gboolean *out_is_active,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_bootloader_query (OstreeBootloader *self, gboolean *out_is_active,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
g_assert (OSTREE_IS_BOOTLOADER (self));
|
||||
|
||||
@ -43,7 +41,7 @@ _ostree_bootloader_query (OstreeBootloader *self,
|
||||
* Returns: (transfer none): Name of this bootloader
|
||||
*/
|
||||
const char *
|
||||
_ostree_bootloader_get_name (OstreeBootloader *self)
|
||||
_ostree_bootloader_get_name (OstreeBootloader *self)
|
||||
{
|
||||
g_assert (OSTREE_IS_BOOTLOADER (self));
|
||||
|
||||
@ -51,35 +49,31 @@ _ostree_bootloader_get_name (OstreeBootloader *self)
|
||||
}
|
||||
|
||||
gboolean
|
||||
_ostree_bootloader_write_config (OstreeBootloader *self,
|
||||
int bootversion,
|
||||
GPtrArray *new_deployments,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_bootloader_write_config (OstreeBootloader *self, int bootversion,
|
||||
GPtrArray *new_deployments, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
g_assert (OSTREE_IS_BOOTLOADER (self));
|
||||
|
||||
return OSTREE_BOOTLOADER_GET_IFACE (self)->write_config (self, bootversion,
|
||||
new_deployments,
|
||||
return OSTREE_BOOTLOADER_GET_IFACE (self)->write_config (self, bootversion, new_deployments,
|
||||
cancellable, error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
_ostree_bootloader_post_bls_sync (OstreeBootloader *self,
|
||||
int bootversion,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_bootloader_post_bls_sync (OstreeBootloader *self, int bootversion,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
g_assert (OSTREE_IS_BOOTLOADER (self));
|
||||
|
||||
if (OSTREE_BOOTLOADER_GET_IFACE (self)->post_bls_sync)
|
||||
return OSTREE_BOOTLOADER_GET_IFACE (self)->post_bls_sync (self, bootversion, cancellable, error);
|
||||
return OSTREE_BOOTLOADER_GET_IFACE (self)->post_bls_sync (self, bootversion, cancellable,
|
||||
error);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_ostree_bootloader_is_atomic (OstreeBootloader *self)
|
||||
_ostree_bootloader_is_atomic (OstreeBootloader *self)
|
||||
{
|
||||
g_assert (OSTREE_IS_BOOTLOADER (self));
|
||||
|
||||
|
@ -24,56 +24,45 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_BOOTLOADER (_ostree_bootloader_get_type ())
|
||||
#define OSTREE_BOOTLOADER(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_BOOTLOADER, OstreeBootloader))
|
||||
#define OSTREE_BOOTLOADER(inst) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_BOOTLOADER, OstreeBootloader))
|
||||
#define OSTREE_IS_BOOTLOADER(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), OSTREE_TYPE_BOOTLOADER))
|
||||
#define OSTREE_BOOTLOADER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), OSTREE_TYPE_BOOTLOADER, OstreeBootloaderInterface))
|
||||
#define OSTREE_BOOTLOADER_GET_IFACE(inst) \
|
||||
(G_TYPE_INSTANCE_GET_INTERFACE ((inst), OSTREE_TYPE_BOOTLOADER, OstreeBootloaderInterface))
|
||||
|
||||
typedef struct _OstreeBootloader OstreeBootloader;
|
||||
typedef struct _OstreeBootloaderInterface OstreeBootloaderInterface;
|
||||
typedef struct _OstreeBootloaderInterface OstreeBootloaderInterface;
|
||||
|
||||
struct _OstreeBootloaderInterface
|
||||
{
|
||||
GTypeInterface g_iface;
|
||||
|
||||
/* virtual functions */
|
||||
gboolean (* query) (OstreeBootloader *bootloader,
|
||||
gboolean *out_is_active,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
const char * (* get_name) (OstreeBootloader *self);
|
||||
gboolean (* write_config) (OstreeBootloader *self,
|
||||
int bootversion,
|
||||
GPtrArray *new_deployments,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean (* post_bls_sync) (OstreeBootloader *self,
|
||||
int bootversion,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean (* is_atomic) (OstreeBootloader *self);
|
||||
gboolean (*query) (OstreeBootloader *bootloader, gboolean *out_is_active,
|
||||
GCancellable *cancellable, GError **error);
|
||||
const char *(*get_name) (OstreeBootloader *self);
|
||||
gboolean (*write_config) (OstreeBootloader *self, int bootversion, GPtrArray *new_deployments,
|
||||
GCancellable *cancellable, GError **error);
|
||||
gboolean (*post_bls_sync) (OstreeBootloader *self, int bootversion, GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean (*is_atomic) (OstreeBootloader *self);
|
||||
};
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeBootloader, g_object_unref)
|
||||
|
||||
GType _ostree_bootloader_get_type (void) G_GNUC_CONST;
|
||||
|
||||
gboolean _ostree_bootloader_query (OstreeBootloader *bootloader,
|
||||
gboolean *out_is_active,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean _ostree_bootloader_query (OstreeBootloader *bootloader, gboolean *out_is_active,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
const char *_ostree_bootloader_get_name (OstreeBootloader *self);
|
||||
const char *_ostree_bootloader_get_name (OstreeBootloader *self);
|
||||
|
||||
gboolean _ostree_bootloader_write_config (OstreeBootloader *self,
|
||||
int bootversion,
|
||||
GPtrArray *new_deployments,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean _ostree_bootloader_write_config (OstreeBootloader *self, int bootversion,
|
||||
GPtrArray *new_deployments, GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
gboolean _ostree_bootloader_post_bls_sync (OstreeBootloader *self,
|
||||
int bootversion,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean _ostree_bootloader_post_bls_sync (OstreeBootloader *self, int bootversion,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
gboolean _ostree_bootloader_is_atomic (OstreeBootloader *self);
|
||||
gboolean _ostree_bootloader_is_atomic (OstreeBootloader *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -22,35 +22,29 @@
|
||||
|
||||
#include "ostree-chain-input-stream.h"
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_STREAMS
|
||||
};
|
||||
|
||||
struct _OstreeChainInputStreamPrivate {
|
||||
struct _OstreeChainInputStreamPrivate
|
||||
{
|
||||
GPtrArray *streams;
|
||||
guint index;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (OstreeChainInputStream, ostree_chain_input_stream, G_TYPE_INPUT_STREAM)
|
||||
|
||||
static void ostree_chain_input_stream_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void ostree_chain_input_stream_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void ostree_chain_input_stream_finalize (GObject *object);
|
||||
static gssize ostree_chain_input_stream_read (GInputStream *stream,
|
||||
void *buffer,
|
||||
gsize count,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
static gboolean ostree_chain_input_stream_close (GInputStream *stream,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
static void ostree_chain_input_stream_set_property (GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec);
|
||||
static void ostree_chain_input_stream_get_property (GObject *object, guint prop_id, GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void ostree_chain_input_stream_finalize (GObject *object);
|
||||
static gssize ostree_chain_input_stream_read (GInputStream *stream, void *buffer, gsize count,
|
||||
GCancellable *cancellable, GError **error);
|
||||
static gboolean ostree_chain_input_stream_close (GInputStream *stream, GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
static void
|
||||
ostree_chain_input_stream_class_init (OstreeChainInputStreamClass *klass)
|
||||
@ -60,7 +54,7 @@ ostree_chain_input_stream_class_init (OstreeChainInputStreamClass *klass)
|
||||
|
||||
gobject_class->get_property = ostree_chain_input_stream_get_property;
|
||||
gobject_class->set_property = ostree_chain_input_stream_set_property;
|
||||
gobject_class->finalize = ostree_chain_input_stream_finalize;
|
||||
gobject_class->finalize = ostree_chain_input_stream_finalize;
|
||||
|
||||
stream_class->read_fn = ostree_chain_input_stream_read;
|
||||
stream_class->close_fn = ostree_chain_input_stream_close;
|
||||
@ -70,21 +64,15 @@ ostree_chain_input_stream_class_init (OstreeChainInputStreamClass *klass)
|
||||
*
|
||||
* Chain of input streams read in order.
|
||||
*/
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_STREAMS,
|
||||
g_param_spec_pointer ("streams",
|
||||
"", "",
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (
|
||||
gobject_class, PROP_STREAMS,
|
||||
g_param_spec_pointer ("streams", "", "",
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
static void
|
||||
ostree_chain_input_stream_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
ostree_chain_input_stream_set_property (GObject *object, guint prop_id, const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
OstreeChainInputStream *self;
|
||||
|
||||
@ -102,10 +90,8 @@ ostree_chain_input_stream_set_property (GObject *object,
|
||||
}
|
||||
|
||||
static void
|
||||
ostree_chain_input_stream_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
ostree_chain_input_stream_get_property (GObject *object, guint prop_id, GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
OstreeChainInputStream *self;
|
||||
|
||||
@ -126,7 +112,7 @@ ostree_chain_input_stream_finalize (GObject *object)
|
||||
{
|
||||
OstreeChainInputStream *stream;
|
||||
|
||||
stream = (OstreeChainInputStream*)(object);
|
||||
stream = (OstreeChainInputStream *)(object);
|
||||
|
||||
g_ptr_array_unref (stream->priv->streams);
|
||||
|
||||
@ -137,29 +123,23 @@ static void
|
||||
ostree_chain_input_stream_init (OstreeChainInputStream *self)
|
||||
{
|
||||
self->priv = ostree_chain_input_stream_get_instance_private (self);
|
||||
|
||||
}
|
||||
|
||||
OstreeChainInputStream *
|
||||
ostree_chain_input_stream_new (GPtrArray *streams)
|
||||
ostree_chain_input_stream_new (GPtrArray *streams)
|
||||
{
|
||||
OstreeChainInputStream *stream;
|
||||
|
||||
stream = g_object_new (OSTREE_TYPE_CHAIN_INPUT_STREAM,
|
||||
"streams", streams,
|
||||
NULL);
|
||||
stream = g_object_new (OSTREE_TYPE_CHAIN_INPUT_STREAM, "streams", streams, NULL);
|
||||
|
||||
return (OstreeChainInputStream*) (stream);
|
||||
return (OstreeChainInputStream *)(stream);
|
||||
}
|
||||
|
||||
static gssize
|
||||
ostree_chain_input_stream_read (GInputStream *stream,
|
||||
void *buffer,
|
||||
gsize count,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_chain_input_stream_read (GInputStream *stream, void *buffer, gsize count,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
OstreeChainInputStream *self = (OstreeChainInputStream*) stream;
|
||||
OstreeChainInputStream *self = (OstreeChainInputStream *)stream;
|
||||
GInputStream *child;
|
||||
gssize res = -1;
|
||||
|
||||
@ -173,11 +153,7 @@ ostree_chain_input_stream_read (GInputStream *stream,
|
||||
while (res == 0 && self->priv->index < self->priv->streams->len)
|
||||
{
|
||||
child = self->priv->streams->pdata[self->priv->index];
|
||||
res = g_input_stream_read (child,
|
||||
buffer,
|
||||
count,
|
||||
cancellable,
|
||||
error);
|
||||
res = g_input_stream_read (child, buffer, count, cancellable, error);
|
||||
if (res == 0)
|
||||
self->priv->index++;
|
||||
}
|
||||
@ -186,9 +162,7 @@ ostree_chain_input_stream_read (GInputStream *stream,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ostree_chain_input_stream_close (GInputStream *stream,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_chain_input_stream_close (GInputStream *stream, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
OstreeChainInputStream *self = (gpointer)stream;
|
||||
@ -202,6 +176,6 @@ ostree_chain_input_stream_close (GInputStream *stream,
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
@ -22,20 +22,25 @@
|
||||
|
||||
#ifndef __GI_SCANNER__
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <ostree.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_CHAIN_INPUT_STREAM (ostree_chain_input_stream_get_type ())
|
||||
#define OSTREE_CHAIN_INPUT_STREAM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_CHAIN_INPUT_STREAM, OstreeChainInputStream))
|
||||
#define OSTREE_CHAIN_INPUT_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), OSTREE_TYPE_CHAIN_INPUT_STREAM, OstreeChainInputStreamClass))
|
||||
#define OSTREE_IS_CHAIN_INPUT_STREAM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_CHAIN_INPUT_STREAM))
|
||||
#define OSTREE_IS_CHAIN_INPUT_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_CHAIN_INPUT_STREAM))
|
||||
#define OSTREE_CHAIN_INPUT_STREAM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_CHAIN_INPUT_STREAM, OstreeChainInputStreamClass))
|
||||
#define OSTREE_TYPE_CHAIN_INPUT_STREAM (ostree_chain_input_stream_get_type ())
|
||||
#define OSTREE_CHAIN_INPUT_STREAM(o) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_CHAIN_INPUT_STREAM, OstreeChainInputStream))
|
||||
#define OSTREE_CHAIN_INPUT_STREAM_CLASS(k) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((k), OSTREE_TYPE_CHAIN_INPUT_STREAM, OstreeChainInputStreamClass))
|
||||
#define OSTREE_IS_CHAIN_INPUT_STREAM(o) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_CHAIN_INPUT_STREAM))
|
||||
#define OSTREE_IS_CHAIN_INPUT_STREAM_CLASS(k) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_CHAIN_INPUT_STREAM))
|
||||
#define OSTREE_CHAIN_INPUT_STREAM_GET_CLASS(o) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_CHAIN_INPUT_STREAM, OstreeChainInputStreamClass))
|
||||
|
||||
typedef struct _OstreeChainInputStream OstreeChainInputStream;
|
||||
typedef struct _OstreeChainInputStreamClass OstreeChainInputStreamClass;
|
||||
typedef struct _OstreeChainInputStreamPrivate OstreeChainInputStreamPrivate;
|
||||
typedef struct _OstreeChainInputStream OstreeChainInputStream;
|
||||
typedef struct _OstreeChainInputStreamClass OstreeChainInputStreamClass;
|
||||
typedef struct _OstreeChainInputStreamPrivate OstreeChainInputStreamPrivate;
|
||||
|
||||
struct _OstreeChainInputStream
|
||||
{
|
||||
@ -59,10 +64,10 @@ struct _OstreeChainInputStreamClass
|
||||
};
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
GType ostree_chain_input_stream_get_type (void) G_GNUC_CONST;
|
||||
GType ostree_chain_input_stream_get_type (void) G_GNUC_CONST;
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeChainInputStream * ostree_chain_input_stream_new (GPtrArray *streams);
|
||||
OstreeChainInputStream *ostree_chain_input_stream_new (GPtrArray *streams);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -22,30 +22,26 @@
|
||||
|
||||
#include "ostree-checksum-input-stream.h"
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_CHECKSUM
|
||||
};
|
||||
|
||||
struct _OstreeChecksumInputStreamPrivate {
|
||||
struct _OstreeChecksumInputStreamPrivate
|
||||
{
|
||||
GChecksum *checksum;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (OstreeChecksumInputStream, ostree_checksum_input_stream, G_TYPE_FILTER_INPUT_STREAM)
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (OstreeChecksumInputStream, ostree_checksum_input_stream,
|
||||
G_TYPE_FILTER_INPUT_STREAM)
|
||||
|
||||
static void ostree_checksum_input_stream_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void ostree_checksum_input_stream_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static gssize ostree_checksum_input_stream_read (GInputStream *stream,
|
||||
void *buffer,
|
||||
gsize count,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
static void ostree_checksum_input_stream_set_property (GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec);
|
||||
static void ostree_checksum_input_stream_get_property (GObject *object, guint prop_id,
|
||||
GValue *value, GParamSpec *pspec);
|
||||
static gssize ostree_checksum_input_stream_read (GInputStream *stream, void *buffer, gsize count,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
static void
|
||||
ostree_checksum_input_stream_class_init (OstreeChecksumInputStreamClass *klass)
|
||||
@ -63,21 +59,15 @@ ostree_checksum_input_stream_class_init (OstreeChecksumInputStreamClass *klass)
|
||||
*
|
||||
* The checksum that the stream updates.
|
||||
*/
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_CHECKSUM,
|
||||
g_param_spec_pointer ("checksum",
|
||||
"", "",
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (
|
||||
gobject_class, PROP_CHECKSUM,
|
||||
g_param_spec_pointer ("checksum", "", "",
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
static void
|
||||
ostree_checksum_input_stream_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
ostree_checksum_input_stream_set_property (GObject *object, guint prop_id, const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
OstreeChecksumInputStream *self;
|
||||
|
||||
@ -95,10 +85,8 @@ ostree_checksum_input_stream_set_property (GObject *object,
|
||||
}
|
||||
|
||||
static void
|
||||
ostree_checksum_input_stream_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
ostree_checksum_input_stream_get_property (GObject *object, guint prop_id, GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
OstreeChecksumInputStream *self;
|
||||
|
||||
@ -121,39 +109,28 @@ ostree_checksum_input_stream_init (OstreeChecksumInputStream *self)
|
||||
}
|
||||
|
||||
OstreeChecksumInputStream *
|
||||
ostree_checksum_input_stream_new (GInputStream *base,
|
||||
GChecksum *checksum)
|
||||
ostree_checksum_input_stream_new (GInputStream *base, GChecksum *checksum)
|
||||
{
|
||||
g_assert (G_IS_INPUT_STREAM (base));
|
||||
|
||||
OstreeChecksumInputStream *stream = g_object_new (
|
||||
OSTREE_TYPE_CHECKSUM_INPUT_STREAM,
|
||||
"base-stream", base,
|
||||
"checksum", checksum,
|
||||
NULL);
|
||||
OSTREE_TYPE_CHECKSUM_INPUT_STREAM, "base-stream", base, "checksum", checksum, NULL);
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
static gssize
|
||||
ostree_checksum_input_stream_read (GInputStream *stream,
|
||||
void *buffer,
|
||||
gsize count,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_checksum_input_stream_read (GInputStream *stream, void *buffer, gsize count,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
OstreeChecksumInputStream *self = (OstreeChecksumInputStream*) stream;
|
||||
GFilterInputStream *fself = (GFilterInputStream*) self;
|
||||
OstreeChecksumInputStream *self = (OstreeChecksumInputStream *)stream;
|
||||
GFilterInputStream *fself = (GFilterInputStream *)self;
|
||||
gssize res = -1;
|
||||
|
||||
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
||||
return -1;
|
||||
|
||||
res = g_input_stream_read (fself->base_stream,
|
||||
buffer,
|
||||
count,
|
||||
cancellable,
|
||||
error);
|
||||
res = g_input_stream_read (fself->base_stream, buffer, count, cancellable, error);
|
||||
if (res > 0)
|
||||
g_checksum_update (self->priv->checksum, buffer, res);
|
||||
|
||||
|
@ -24,16 +24,22 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_CHECKSUM_INPUT_STREAM (ostree_checksum_input_stream_get_type ())
|
||||
#define OSTREE_CHECKSUM_INPUT_STREAM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_CHECKSUM_INPUT_STREAM, OstreeChecksumInputStream))
|
||||
#define OSTREE_CHECKSUM_INPUT_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), OSTREE_TYPE_CHECKSUM_INPUT_STREAM, OstreeChecksumInputStreamClass))
|
||||
#define OSTREE_IS_CHECKSUM_INPUT_STREAM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_CHECKSUM_INPUT_STREAM))
|
||||
#define OSTREE_IS_CHECKSUM_INPUT_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_CHECKSUM_INPUT_STREAM))
|
||||
#define OSTREE_CHECKSUM_INPUT_STREAM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_CHECKSUM_INPUT_STREAM, OstreeChecksumInputStreamClass))
|
||||
#define OSTREE_TYPE_CHECKSUM_INPUT_STREAM (ostree_checksum_input_stream_get_type ())
|
||||
#define OSTREE_CHECKSUM_INPUT_STREAM(o) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_CHECKSUM_INPUT_STREAM, OstreeChecksumInputStream))
|
||||
#define OSTREE_CHECKSUM_INPUT_STREAM_CLASS(k) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((k), OSTREE_TYPE_CHECKSUM_INPUT_STREAM, OstreeChecksumInputStreamClass))
|
||||
#define OSTREE_IS_CHECKSUM_INPUT_STREAM(o) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_CHECKSUM_INPUT_STREAM))
|
||||
#define OSTREE_IS_CHECKSUM_INPUT_STREAM_CLASS(k) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_CHECKSUM_INPUT_STREAM))
|
||||
#define OSTREE_CHECKSUM_INPUT_STREAM_GET_CLASS(o) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_CHECKSUM_INPUT_STREAM, \
|
||||
OstreeChecksumInputStreamClass))
|
||||
|
||||
typedef struct _OstreeChecksumInputStream OstreeChecksumInputStream;
|
||||
typedef struct _OstreeChecksumInputStreamClass OstreeChecksumInputStreamClass;
|
||||
typedef struct _OstreeChecksumInputStreamPrivate OstreeChecksumInputStreamPrivate;
|
||||
typedef struct _OstreeChecksumInputStream OstreeChecksumInputStream;
|
||||
typedef struct _OstreeChecksumInputStreamClass OstreeChecksumInputStreamClass;
|
||||
typedef struct _OstreeChecksumInputStreamPrivate OstreeChecksumInputStreamPrivate;
|
||||
|
||||
struct _OstreeChecksumInputStream
|
||||
{
|
||||
@ -57,10 +63,10 @@ struct _OstreeChecksumInputStreamClass
|
||||
};
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
GType ostree_checksum_input_stream_get_type (void) G_GNUC_CONST;
|
||||
GType ostree_checksum_input_stream_get_type (void) G_GNUC_CONST;
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeChecksumInputStream * ostree_checksum_input_stream_new (GInputStream *stream,
|
||||
GChecksum *checksum);
|
||||
OstreeChecksumInputStream *ostree_checksum_input_stream_new (GInputStream *stream,
|
||||
GChecksum *checksum);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -19,19 +19,21 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ostree-bootloader-grub2.h"
|
||||
#include "ostree-cmd-private.h"
|
||||
#include "ostree-repo-private.h"
|
||||
#include "ostree-core-private.h"
|
||||
#include "ostree-repo-private.h"
|
||||
#include "ostree-repo-static-delta-private.h"
|
||||
#include "ostree-sysroot-private.h"
|
||||
#include "ostree-bootloader-grub2.h"
|
||||
|
||||
#include "otutil.h"
|
||||
|
||||
static gboolean
|
||||
impl_ostree_generate_grub2_config (OstreeSysroot *sysroot, int bootversion, int target_fd, GCancellable *cancellable, GError **error)
|
||||
impl_ostree_generate_grub2_config (OstreeSysroot *sysroot, int bootversion, int target_fd,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
return _ostree_bootloader_grub2_generate_config (sysroot, bootversion, target_fd, cancellable, error);
|
||||
return _ostree_bootloader_grub2_generate_config (sysroot, bootversion, target_fd, cancellable,
|
||||
error);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,14 +46,10 @@ const OstreeCmdPrivateVTable *
|
||||
ostree_cmd__private__ (void)
|
||||
{
|
||||
static OstreeCmdPrivateVTable table = {
|
||||
_ostree_impl_system_generator,
|
||||
impl_ostree_generate_grub2_config,
|
||||
_ostree_repo_static_delta_dump,
|
||||
_ostree_repo_static_delta_query_exists,
|
||||
_ostree_repo_static_delta_delete,
|
||||
_ostree_repo_verify_bindings,
|
||||
_ostree_sysroot_finalize_staged,
|
||||
_ostree_sysroot_boot_complete,
|
||||
_ostree_impl_system_generator, impl_ostree_generate_grub2_config,
|
||||
_ostree_repo_static_delta_dump, _ostree_repo_static_delta_query_exists,
|
||||
_ostree_repo_static_delta_delete, _ostree_repo_verify_bindings,
|
||||
_ostree_sysroot_finalize_staged, _ostree_sysroot_boot_complete,
|
||||
};
|
||||
|
||||
return &table;
|
||||
|
@ -23,21 +23,32 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
gboolean _ostree_impl_system_generator (const char *ostree_cmdline, const char *normal_dir, const char *early_dir, const char *late_dir, GError **error);
|
||||
gboolean _ostree_impl_system_generator (const char *ostree_cmdline, const char *normal_dir,
|
||||
const char *early_dir, const char *late_dir,
|
||||
GError **error);
|
||||
|
||||
typedef struct {
|
||||
gboolean (* ostree_system_generator) (const char *ostree_cmdline, const char *normal_dir, const char *early_dir, const char *late_dir, GError **error);
|
||||
gboolean (* ostree_generate_grub2_config) (OstreeSysroot *sysroot, int bootversion, int target_fd, GCancellable *cancellable, GError **error);
|
||||
gboolean (* ostree_static_delta_dump) (OstreeRepo *repo, const char *delta_id, GCancellable *cancellable, GError **error);
|
||||
gboolean (* ostree_static_delta_query_exists) (OstreeRepo *repo, const char *delta_id, gboolean *out_exists, GCancellable *cancellable, GError **error);
|
||||
gboolean (* ostree_static_delta_delete) (OstreeRepo *repo, const char *delta_id, GCancellable *cancellable, GError **error);
|
||||
gboolean (* ostree_repo_verify_bindings) (const char *collection_id, const char *ref_name, GVariant *commit, GError **error);
|
||||
gboolean (* ostree_finalize_staged) (OstreeSysroot *sysroot, GCancellable *cancellable, GError **error);
|
||||
gboolean (* ostree_boot_complete) (OstreeSysroot *sysroot, GCancellable *cancellable, GError **error);
|
||||
typedef struct
|
||||
{
|
||||
gboolean (*ostree_system_generator) (const char *ostree_cmdline, const char *normal_dir,
|
||||
const char *early_dir, const char *late_dir, GError **error);
|
||||
gboolean (*ostree_generate_grub2_config) (OstreeSysroot *sysroot, int bootversion, int target_fd,
|
||||
GCancellable *cancellable, GError **error);
|
||||
gboolean (*ostree_static_delta_dump) (OstreeRepo *repo, const char *delta_id,
|
||||
GCancellable *cancellable, GError **error);
|
||||
gboolean (*ostree_static_delta_query_exists) (OstreeRepo *repo, const char *delta_id,
|
||||
gboolean *out_exists, GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean (*ostree_static_delta_delete) (OstreeRepo *repo, const char *delta_id,
|
||||
GCancellable *cancellable, GError **error);
|
||||
gboolean (*ostree_repo_verify_bindings) (const char *collection_id, const char *ref_name,
|
||||
GVariant *commit, GError **error);
|
||||
gboolean (*ostree_finalize_staged) (OstreeSysroot *sysroot, GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean (*ostree_boot_complete) (OstreeSysroot *sysroot, GCancellable *cancellable,
|
||||
GError **error);
|
||||
} OstreeCmdPrivateVTable;
|
||||
|
||||
/* Note this not really "public", we just export the symbol, but not the header */
|
||||
_OSTREE_PUBLIC const OstreeCmdPrivateVTable *
|
||||
ostree_cmd__private__ (void);
|
||||
_OSTREE_PUBLIC const OstreeCmdPrivateVTable *ostree_cmd__private__ (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -17,9 +17,9 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ostree-autocleanups.h"
|
||||
#include "ostree-content-writer.h"
|
||||
#include "ostree-repo-private.h"
|
||||
#include "ostree-autocleanups.h"
|
||||
|
||||
struct _OstreeContentWriter
|
||||
{
|
||||
@ -31,15 +31,11 @@ struct _OstreeContentWriter
|
||||
|
||||
G_DEFINE_TYPE (OstreeContentWriter, ostree_content_writer, G_TYPE_OUTPUT_STREAM)
|
||||
|
||||
static void ostree_content_writer_finalize (GObject *object);
|
||||
static gssize ostree_content_writer_write (GOutputStream *stream,
|
||||
const void *buffer,
|
||||
gsize count,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
static gboolean ostree_content_writer_close (GOutputStream *stream,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
static void ostree_content_writer_finalize (GObject *object);
|
||||
static gssize ostree_content_writer_write (GOutputStream *stream, const void *buffer, gsize count,
|
||||
GCancellable *cancellable, GError **error);
|
||||
static gboolean ostree_content_writer_close (GOutputStream *stream, GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
static void
|
||||
ostree_content_writer_class_init (OstreeContentWriterClass *klass)
|
||||
@ -47,7 +43,7 @@ ostree_content_writer_class_init (OstreeContentWriterClass *klass)
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GOutputStreamClass *stream_class = G_OUTPUT_STREAM_CLASS (klass);
|
||||
|
||||
gobject_class->finalize = ostree_content_writer_finalize;
|
||||
gobject_class->finalize = ostree_content_writer_finalize;
|
||||
|
||||
stream_class->write_fn = ostree_content_writer_write;
|
||||
stream_class->close_fn = ostree_content_writer_close;
|
||||
@ -58,7 +54,7 @@ ostree_content_writer_finalize (GObject *object)
|
||||
{
|
||||
OstreeContentWriter *stream;
|
||||
|
||||
stream = (OstreeContentWriter*)(object);
|
||||
stream = (OstreeContentWriter *)(object);
|
||||
|
||||
g_clear_object (&stream->repo);
|
||||
_ostree_repo_bare_content_cleanup (&stream->output);
|
||||
@ -70,19 +66,13 @@ static void
|
||||
ostree_content_writer_init (OstreeContentWriter *self)
|
||||
{
|
||||
self->output.initialized = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
OstreeContentWriter *
|
||||
_ostree_content_writer_new (OstreeRepo *repo,
|
||||
const char *checksum,
|
||||
guint uid,
|
||||
guint gid,
|
||||
guint mode,
|
||||
guint64 content_len,
|
||||
GVariant *xattrs,
|
||||
GError **error)
|
||||
_ostree_content_writer_new (OstreeRepo *repo, const char *checksum, guint uid, guint gid,
|
||||
guint mode, guint64 content_len, GVariant *xattrs, GError **error)
|
||||
{
|
||||
g_autoptr(OstreeContentWriter) stream = g_object_new (OSTREE_TYPE_CONTENT_WRITER, NULL);
|
||||
g_autoptr (OstreeContentWriter) stream = g_object_new (OSTREE_TYPE_CONTENT_WRITER, NULL);
|
||||
stream->repo = g_object_ref (repo);
|
||||
if (!_ostree_repo_bare_content_open (stream->repo, checksum, content_len, uid, gid, mode, xattrs,
|
||||
&stream->output, NULL, error))
|
||||
@ -91,27 +81,22 @@ _ostree_content_writer_new (OstreeRepo *repo,
|
||||
}
|
||||
|
||||
static gssize
|
||||
ostree_content_writer_write (GOutputStream *stream,
|
||||
const void *buffer,
|
||||
gsize count,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_content_writer_write (GOutputStream *stream, const void *buffer, gsize count,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
OstreeContentWriter *self = (OstreeContentWriter*) stream;
|
||||
OstreeContentWriter *self = (OstreeContentWriter *)stream;
|
||||
|
||||
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
||||
return -1;
|
||||
|
||||
if (!_ostree_repo_bare_content_write (self->repo, &self->output,
|
||||
buffer, count, cancellable, error))
|
||||
if (!_ostree_repo_bare_content_write (self->repo, &self->output, buffer, count, cancellable,
|
||||
error))
|
||||
return -1;
|
||||
return count;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ostree_content_writer_close (GOutputStream *stream,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_content_writer_close (GOutputStream *stream, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
/* We don't expect people to invoke close() - they need to call finish()
|
||||
* to get the checksum. We'll clean up in finalize anyways if need be.
|
||||
@ -129,11 +114,9 @@ ostree_content_writer_close (GOutputStream *stream,
|
||||
* Returns: (transfer full): Checksum, or %NULL on error
|
||||
*/
|
||||
char *
|
||||
ostree_content_writer_finish (OstreeContentWriter *self,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_content_writer_finish (OstreeContentWriter *self, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
char actual_checksum[OSTREE_SHA256_STRING_LEN+1];
|
||||
char actual_checksum[OSTREE_SHA256_STRING_LEN + 1];
|
||||
if (!_ostree_repo_bare_content_commit (self->repo, &self->output, actual_checksum,
|
||||
sizeof (actual_checksum), cancellable, error))
|
||||
return NULL;
|
||||
|
@ -24,11 +24,12 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_CONTENT_WRITER (ostree_content_writer_get_type ())
|
||||
_OSTREE_PUBLIC G_DECLARE_FINAL_TYPE (OstreeContentWriter, ostree_content_writer, OSTREE, CONTENT_WRITER, GOutputStream)
|
||||
_OSTREE_PUBLIC
|
||||
G_DECLARE_FINAL_TYPE (OstreeContentWriter, ostree_content_writer, OSTREE, CONTENT_WRITER,
|
||||
GOutputStream)
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
char * ostree_content_writer_finish (OstreeContentWriter *self,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
char *ostree_content_writer_finish (OstreeContentWriter *self, GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -36,7 +36,7 @@ G_BEGIN_DECLS
|
||||
|
||||
/* This exists in glibc's sys/stat.h, but not on musl */
|
||||
#ifndef ALLPERMS
|
||||
#define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)
|
||||
#define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
|
||||
#endif
|
||||
|
||||
/* This file contains private implementation data format definitions
|
||||
@ -78,30 +78,23 @@ G_BEGIN_DECLS
|
||||
*/
|
||||
#define _OSTREE_ZLIB_FILE_HEADER_GVARIANT_FORMAT G_VARIANT_TYPE ("(tuuuusa(ayay))")
|
||||
|
||||
GBytes *_ostree_file_header_new (GFileInfo *file_info, GVariant *xattrs);
|
||||
|
||||
GBytes *_ostree_file_header_new (GFileInfo *file_info,
|
||||
GVariant *xattrs);
|
||||
GBytes *_ostree_zlib_file_header_new (GFileInfo *file_info, GVariant *xattrs);
|
||||
|
||||
GBytes *_ostree_zlib_file_header_new (GFileInfo *file_info,
|
||||
GVariant *xattrs);
|
||||
gboolean _ostree_make_temporary_symlink_at (int tmp_dirfd, const char *target, char **out_name,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
gboolean
|
||||
_ostree_make_temporary_symlink_at (int tmp_dirfd,
|
||||
const char *target,
|
||||
char **out_name,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
GFileInfo * _ostree_stbuf_to_gfileinfo (const struct stat *stbuf);
|
||||
void _ostree_gfileinfo_to_stbuf (GFileInfo *file_info, struct stat *out_stbuf);
|
||||
GFileInfo *_ostree_stbuf_to_gfileinfo (const struct stat *stbuf);
|
||||
void _ostree_gfileinfo_to_stbuf (GFileInfo *file_info, struct stat *out_stbuf);
|
||||
gboolean _ostree_gfileinfo_equal (GFileInfo *a, GFileInfo *b);
|
||||
gboolean _ostree_stbuf_equal (struct stat *stbuf_a, struct stat *stbuf_b);
|
||||
GFileInfo * _ostree_mode_uidgid_to_gfileinfo (mode_t mode, uid_t uid, gid_t gid);
|
||||
GFileInfo *_ostree_mode_uidgid_to_gfileinfo (mode_t mode, uid_t uid, gid_t gid);
|
||||
|
||||
static inline void
|
||||
_ostree_checksum_inplace_from_bytes_v (GVariant *csum_v, char *buf)
|
||||
{
|
||||
const guint8*csum = ostree_checksum_bytes_peek (csum_v);
|
||||
const guint8 *csum = ostree_checksum_bytes_peek (csum_v);
|
||||
g_assert (csum);
|
||||
ostree_checksum_inplace_from_bytes (csum, buf);
|
||||
}
|
||||
@ -114,84 +107,49 @@ _ostree_checksum_inplace_from_bytes_v (GVariant *csum_v, char *buf)
|
||||
/* GVariant format for ostree.sizes metadata entries. */
|
||||
#define _OSTREE_OBJECT_SIZES_ENTRY_SIGNATURE "ay"
|
||||
|
||||
char *
|
||||
_ostree_get_relative_object_path (const char *checksum,
|
||||
OstreeObjectType type,
|
||||
gboolean compressed);
|
||||
char *_ostree_get_relative_object_path (const char *checksum, OstreeObjectType type,
|
||||
gboolean compressed);
|
||||
|
||||
char *_ostree_get_relative_static_delta_path (const char *from, const char *to, const char *target);
|
||||
|
||||
char *
|
||||
_ostree_get_relative_static_delta_path (const char *from,
|
||||
const char *to,
|
||||
const char *target);
|
||||
char *_ostree_get_relative_static_delta_superblock_path (const char *from, const char *to);
|
||||
|
||||
char *
|
||||
_ostree_get_relative_static_delta_superblock_path (const char *from,
|
||||
const char *to);
|
||||
char *_ostree_get_relative_static_delta_detachedmeta_path (const char *from, const char *to);
|
||||
|
||||
char *
|
||||
_ostree_get_relative_static_delta_detachedmeta_path (const char *from,
|
||||
const char *to);
|
||||
char *_ostree_get_relative_static_delta_part_path (const char *from, const char *to, guint i);
|
||||
|
||||
char *
|
||||
_ostree_get_relative_static_delta_part_path (const char *from,
|
||||
const char *to,
|
||||
guint i);
|
||||
char *_ostree_get_relative_static_delta_index_path (const char *to);
|
||||
|
||||
char *
|
||||
_ostree_get_relative_static_delta_index_path (const char *to);
|
||||
|
||||
static inline char * _ostree_get_commitpartial_path (const char *checksum)
|
||||
static inline char *
|
||||
_ostree_get_commitpartial_path (const char *checksum)
|
||||
{
|
||||
return g_strconcat ("state/", checksum, ".commitpartial", NULL);
|
||||
}
|
||||
|
||||
gboolean
|
||||
_ostree_validate_ref_fragment (const char *fragment,
|
||||
GError **error);
|
||||
gboolean _ostree_validate_ref_fragment (const char *fragment, GError **error);
|
||||
|
||||
|
||||
gboolean
|
||||
_ostree_validate_bareuseronly_mode (guint32 mode,
|
||||
const char *checksum,
|
||||
GError **error);
|
||||
gboolean _ostree_validate_bareuseronly_mode (guint32 mode, const char *checksum, GError **error);
|
||||
static inline gboolean
|
||||
_ostree_validate_bareuseronly_mode_finfo (GFileInfo *finfo,
|
||||
const char *checksum,
|
||||
GError **error)
|
||||
_ostree_validate_bareuseronly_mode_finfo (GFileInfo *finfo, const char *checksum, GError **error)
|
||||
{
|
||||
const guint32 content_mode = g_file_info_get_attribute_uint32 (finfo, "unix::mode");
|
||||
return _ostree_validate_bareuseronly_mode (content_mode, checksum, error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
_ostree_compare_object_checksum (OstreeObjectType objtype,
|
||||
const char *expected,
|
||||
const char *actual,
|
||||
GError **error);
|
||||
gboolean _ostree_compare_object_checksum (OstreeObjectType objtype, const char *expected,
|
||||
const char *actual, GError **error);
|
||||
|
||||
gboolean
|
||||
_ostree_parse_delta_name (const char *delta_name,
|
||||
char **out_from,
|
||||
char **out_to,
|
||||
GError **error);
|
||||
gboolean _ostree_parse_delta_name (const char *delta_name, char **out_from, char **out_to,
|
||||
GError **error);
|
||||
|
||||
void
|
||||
_ostree_loose_path (char *buf,
|
||||
const char *checksum,
|
||||
OstreeObjectType objtype,
|
||||
OstreeRepoMode repo_mode);
|
||||
void _ostree_loose_path (char *buf, const char *checksum, OstreeObjectType objtype,
|
||||
OstreeRepoMode repo_mode);
|
||||
|
||||
gboolean _ostree_validate_structureof_metadata (OstreeObjectType objtype,
|
||||
GVariant *commit,
|
||||
GError **error);
|
||||
|
||||
gboolean
|
||||
_ostree_verify_metadata_object (OstreeObjectType objtype,
|
||||
const char *expected_checksum,
|
||||
GVariant *metadata,
|
||||
GError **error);
|
||||
gboolean _ostree_validate_structureof_metadata (OstreeObjectType objtype, GVariant *commit,
|
||||
GError **error);
|
||||
|
||||
gboolean _ostree_verify_metadata_object (OstreeObjectType objtype, const char *expected_checksum,
|
||||
GVariant *metadata, GError **error);
|
||||
|
||||
#define _OSTREE_METADATA_GPGSIGS_NAME "ostree.gpgsigs"
|
||||
#define _OSTREE_METADATA_GPGSIGS_TYPE G_VARIANT_TYPE ("aay")
|
||||
@ -199,37 +157,24 @@ _ostree_verify_metadata_object (OstreeObjectType objtype,
|
||||
static inline gboolean
|
||||
_ostree_repo_mode_is_bare (OstreeRepoMode mode)
|
||||
{
|
||||
return
|
||||
mode == OSTREE_REPO_MODE_BARE ||
|
||||
mode == OSTREE_REPO_MODE_BARE_USER ||
|
||||
mode == OSTREE_REPO_MODE_BARE_USER_ONLY ||
|
||||
mode == OSTREE_REPO_MODE_BARE_SPLIT_XATTRS;
|
||||
return mode == OSTREE_REPO_MODE_BARE || mode == OSTREE_REPO_MODE_BARE_USER
|
||||
|| mode == OSTREE_REPO_MODE_BARE_USER_ONLY || mode == OSTREE_REPO_MODE_BARE_SPLIT_XATTRS;
|
||||
}
|
||||
|
||||
#ifndef OSTREE_DISABLE_GPGME
|
||||
GVariant *
|
||||
_ostree_detached_metadata_append_gpg_sig (GVariant *existing_metadata,
|
||||
GBytes *signature_bytes);
|
||||
GVariant *_ostree_detached_metadata_append_gpg_sig (GVariant *existing_metadata,
|
||||
GBytes *signature_bytes);
|
||||
#endif
|
||||
|
||||
GFile *
|
||||
_ostree_get_default_sysroot_path (void);
|
||||
GFile *_ostree_get_default_sysroot_path (void);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean
|
||||
_ostree_raw_file_to_archive_stream (GInputStream *input,
|
||||
GFileInfo *file_info,
|
||||
GVariant *xattrs,
|
||||
guint compression_level,
|
||||
GInputStream **out_input,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean _ostree_raw_file_to_archive_stream (GInputStream *input, GFileInfo *file_info,
|
||||
GVariant *xattrs, guint compression_level,
|
||||
GInputStream **out_input, GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
gboolean
|
||||
_ostree_compare_timestamps (const char *current_rev,
|
||||
guint64 current_ts,
|
||||
const char *new_rev,
|
||||
guint64 new_ts,
|
||||
GError **error);
|
||||
gboolean _ostree_compare_timestamps (const char *current_rev, guint64 current_ts,
|
||||
const char *new_rev, guint64 new_ts, GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -21,9 +21,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <gio/gio.h>
|
||||
#include <ostree-types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -68,21 +68,23 @@ G_BEGIN_DECLS
|
||||
* @OSTREE_OBJECT_TYPE_COMMIT_META: Detached metadata for a commit
|
||||
* @OSTREE_OBJECT_TYPE_PAYLOAD_LINK: Symlink to a .file given its checksum on the payload only.
|
||||
* @OSTREE_OBJECT_TYPE_FILE_XATTRS: Detached xattrs content, for 'bare-split-xattrs' mode.
|
||||
* @OSTREE_OBJECT_TYPE_FILE_XATTRS_LINK: Hardlink to a .file-xattrs given the checksum of its .file object.
|
||||
* @OSTREE_OBJECT_TYPE_FILE_XATTRS_LINK: Hardlink to a .file-xattrs given the checksum of its .file
|
||||
* object.
|
||||
*
|
||||
* Enumeration for core object types; %OSTREE_OBJECT_TYPE_FILE is for
|
||||
* content, the other types are metadata.
|
||||
*/
|
||||
typedef enum {
|
||||
OSTREE_OBJECT_TYPE_FILE = 1, /* .file */
|
||||
OSTREE_OBJECT_TYPE_DIR_TREE = 2, /* .dirtree */
|
||||
OSTREE_OBJECT_TYPE_DIR_META = 3, /* .dirmeta */
|
||||
OSTREE_OBJECT_TYPE_COMMIT = 4, /* .commit */
|
||||
OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT = 5, /* .commit-tombstone */
|
||||
OSTREE_OBJECT_TYPE_COMMIT_META = 6, /* .commitmeta */
|
||||
OSTREE_OBJECT_TYPE_PAYLOAD_LINK = 7, /* .payload-link */
|
||||
OSTREE_OBJECT_TYPE_FILE_XATTRS = 8, /* .file-xattrs */
|
||||
OSTREE_OBJECT_TYPE_FILE_XATTRS_LINK = 9, /* .file-xattrs-link */
|
||||
typedef enum
|
||||
{
|
||||
OSTREE_OBJECT_TYPE_FILE = 1, /* .file */
|
||||
OSTREE_OBJECT_TYPE_DIR_TREE = 2, /* .dirtree */
|
||||
OSTREE_OBJECT_TYPE_DIR_META = 3, /* .dirmeta */
|
||||
OSTREE_OBJECT_TYPE_COMMIT = 4, /* .commit */
|
||||
OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT = 5, /* .commit-tombstone */
|
||||
OSTREE_OBJECT_TYPE_COMMIT_META = 6, /* .commitmeta */
|
||||
OSTREE_OBJECT_TYPE_PAYLOAD_LINK = 7, /* .payload-link */
|
||||
OSTREE_OBJECT_TYPE_FILE_XATTRS = 8, /* .file-xattrs */
|
||||
OSTREE_OBJECT_TYPE_FILE_XATTRS_LINK = 9, /* .file-xattrs-link */
|
||||
} OstreeObjectType;
|
||||
|
||||
/**
|
||||
@ -154,7 +156,8 @@ typedef enum {
|
||||
/**
|
||||
* OSTREE_SUMMARY_GVARIANT_FORMAT:
|
||||
*
|
||||
* - a(s(taya{sv})) - Map of ref name -> (latest commit size, latest commit checksum, additional metadata), sorted by ref name
|
||||
* - a(s(taya{sv})) - Map of ref name -> (latest commit size, latest commit checksum, additional
|
||||
* metadata), sorted by ref name
|
||||
* - a{sv} - Additional metadata, at the current time the following are defined:
|
||||
* - key: "ostree.static-deltas", value: a{sv}, static delta name -> 32 bytes of checksum
|
||||
* - key: "ostree.summary.last-modified", value: t, timestamp (seconds since
|
||||
@ -188,17 +191,23 @@ typedef enum {
|
||||
|
||||
/**
|
||||
* OstreeRepoMode:
|
||||
* @OSTREE_REPO_MODE_BARE: Files are stored as themselves; checkouts are hardlinks; can only be written as root
|
||||
* @OSTREE_REPO_MODE_ARCHIVE: Files are compressed, should be owned by non-root. Can be served via HTTP. Since: 2017.12
|
||||
* @OSTREE_REPO_MODE_BARE: Files are stored as themselves; checkouts are hardlinks; can only be
|
||||
* written as root
|
||||
* @OSTREE_REPO_MODE_ARCHIVE: Files are compressed, should be owned by non-root. Can be served via
|
||||
* HTTP. Since: 2017.12
|
||||
* @OSTREE_REPO_MODE_ARCHIVE_Z2: Legacy alias for `OSTREE_REPO_MODE_ARCHIVE`
|
||||
* @OSTREE_REPO_MODE_BARE_USER: Files are stored as themselves, except ownership; can be written by user. Hardlinks work only in user checkouts.
|
||||
* @OSTREE_REPO_MODE_BARE_USER_ONLY: Same as BARE_USER, but all metadata is not stored, so it can only be used for user checkouts. Does not need xattrs.
|
||||
* @OSTREE_REPO_MODE_BARE_SPLIT_XATTRS: Same as BARE_USER, but xattrs are stored separately from file content, with dedicated object types.
|
||||
* @OSTREE_REPO_MODE_BARE_USER: Files are stored as themselves, except ownership; can be written by
|
||||
* user. Hardlinks work only in user checkouts.
|
||||
* @OSTREE_REPO_MODE_BARE_USER_ONLY: Same as BARE_USER, but all metadata is not stored, so it can
|
||||
* only be used for user checkouts. Does not need xattrs.
|
||||
* @OSTREE_REPO_MODE_BARE_SPLIT_XATTRS: Same as BARE_USER, but xattrs are stored separately from
|
||||
* file content, with dedicated object types.
|
||||
*
|
||||
* See the documentation of #OstreeRepo for more information about the
|
||||
* possible modes.
|
||||
*/
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
OSTREE_REPO_MODE_BARE,
|
||||
OSTREE_REPO_MODE_ARCHIVE,
|
||||
OSTREE_REPO_MODE_ARCHIVE_Z2 = OSTREE_REPO_MODE_ARCHIVE,
|
||||
@ -222,10 +231,10 @@ typedef enum {
|
||||
/**
|
||||
* OSTREE_COMMIT_META_KEY_ARCHITECTURE:
|
||||
*
|
||||
* GVariant type `s`. Intended to describe the CPU architecture. This is a freeform string, and some distributions
|
||||
* which have existing package managers might want to match that schema. If you
|
||||
* don't have a prior schema, it's recommended to use `uname -m` by default (i.e. the Linux kernel schema). In the future
|
||||
* ostree might include a builtin function to compare architectures.
|
||||
* GVariant type `s`. Intended to describe the CPU architecture. This is a freeform string, and
|
||||
* some distributions which have existing package managers might want to match that schema. If you
|
||||
* don't have a prior schema, it's recommended to use `uname -m` by default (i.e. the Linux kernel
|
||||
* schema). In the future ostree might include a builtin function to compare architectures.
|
||||
*
|
||||
* Since: 2020.4
|
||||
*/
|
||||
@ -298,8 +307,7 @@ _OSTREE_PUBLIC
|
||||
const GVariantType *ostree_metadata_variant_type (OstreeObjectType objtype);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_validate_checksum_string (const char *sha256,
|
||||
GError **error);
|
||||
gboolean ostree_validate_checksum_string (const char *sha256, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
guchar *ostree_checksum_to_bytes (const char *checksum);
|
||||
@ -308,26 +316,22 @@ GVariant *ostree_checksum_to_bytes_v (const char *checksum);
|
||||
_OSTREE_PUBLIC
|
||||
guchar *ostree_checksum_b64_to_bytes (const char *checksum);
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_checksum_b64_inplace_to_bytes (const char *checksum,
|
||||
guint8 *buf);
|
||||
void ostree_checksum_b64_inplace_to_bytes (const char *checksum, guint8 *buf);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
char * ostree_checksum_from_bytes (const guchar *csum);
|
||||
char *ostree_checksum_from_bytes (const guchar *csum);
|
||||
_OSTREE_PUBLIC
|
||||
char * ostree_checksum_from_bytes_v (GVariant *csum_v);
|
||||
char *ostree_checksum_from_bytes_v (GVariant *csum_v);
|
||||
_OSTREE_PUBLIC
|
||||
char * ostree_checksum_b64_from_bytes (const guchar *csum);
|
||||
char *ostree_checksum_b64_from_bytes (const guchar *csum);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_checksum_inplace_from_bytes (const guchar *csum,
|
||||
char *buf);
|
||||
void ostree_checksum_inplace_from_bytes (const guchar *csum, char *buf);
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_checksum_b64_inplace_from_bytes (const guchar *csum,
|
||||
char *buf);
|
||||
void ostree_checksum_b64_inplace_from_bytes (const guchar *csum, char *buf);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_checksum_inplace_to_bytes (const char *checksum,
|
||||
guchar *buf);
|
||||
void ostree_checksum_inplace_to_bytes (const char *checksum, guchar *buf);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
const guchar *ostree_checksum_bytes_peek (GVariant *bytes);
|
||||
@ -348,13 +352,11 @@ _OSTREE_PUBLIC
|
||||
gboolean ostree_validate_remote_name (const char *remote_name, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_parse_refspec (const char *refspec,
|
||||
char **out_remote,
|
||||
char **out_ref,
|
||||
GError **error);
|
||||
gboolean ostree_parse_refspec (const char *refspec, char **out_remote, char **out_ref,
|
||||
GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
const char * ostree_object_type_to_string (OstreeObjectType objtype);
|
||||
const char *ostree_object_type_to_string (OstreeObjectType objtype);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeObjectType ostree_object_type_from_string (const char *str);
|
||||
@ -363,112 +365,73 @@ _OSTREE_PUBLIC
|
||||
guint ostree_hash_object_name (gconstpointer a);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
GVariant *ostree_object_name_serialize (const char *checksum,
|
||||
OstreeObjectType objtype);
|
||||
GVariant *ostree_object_name_serialize (const char *checksum, OstreeObjectType objtype);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_object_name_deserialize (GVariant *variant,
|
||||
const char **out_checksum,
|
||||
void ostree_object_name_deserialize (GVariant *variant, const char **out_checksum,
|
||||
OstreeObjectType *out_objtype);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
char * ostree_object_to_string (const char *checksum,
|
||||
OstreeObjectType objtype);
|
||||
char *ostree_object_to_string (const char *checksum, OstreeObjectType objtype);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_object_from_string (const char *str,
|
||||
gchar **out_checksum,
|
||||
void ostree_object_from_string (const char *str, gchar **out_checksum,
|
||||
OstreeObjectType *out_objtype);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean
|
||||
ostree_content_stream_parse (gboolean compressed,
|
||||
GInputStream *input,
|
||||
guint64 input_length,
|
||||
gboolean trusted,
|
||||
GInputStream **out_input,
|
||||
GFileInfo **out_file_info,
|
||||
GVariant **out_xattrs,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_content_stream_parse (gboolean compressed, GInputStream *input,
|
||||
guint64 input_length, gboolean trusted,
|
||||
GInputStream **out_input, GFileInfo **out_file_info,
|
||||
GVariant **out_xattrs, GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_content_file_parse (gboolean compressed,
|
||||
GFile *content_path,
|
||||
gboolean trusted,
|
||||
GInputStream **out_input,
|
||||
GFileInfo **out_file_info,
|
||||
GVariant **out_xattrs,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_content_file_parse (gboolean compressed, GFile *content_path, gboolean trusted,
|
||||
GInputStream **out_input, GFileInfo **out_file_info,
|
||||
GVariant **out_xattrs, GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_content_file_parse_at (gboolean compressed,
|
||||
int parent_dfd,
|
||||
const char *path,
|
||||
gboolean trusted,
|
||||
GInputStream **out_input,
|
||||
GFileInfo **out_file_info,
|
||||
GVariant **out_xattrs,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_content_file_parse_at (gboolean compressed, int parent_dfd, const char *path,
|
||||
gboolean trusted, GInputStream **out_input,
|
||||
GFileInfo **out_file_info, GVariant **out_xattrs,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean
|
||||
ostree_raw_file_to_archive_z2_stream (GInputStream *input,
|
||||
GFileInfo *file_info,
|
||||
GVariant *xattrs,
|
||||
GInputStream **out_input,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_raw_file_to_archive_z2_stream (GInputStream *input, GFileInfo *file_info,
|
||||
GVariant *xattrs, GInputStream **out_input,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean
|
||||
ostree_raw_file_to_archive_z2_stream_with_options (GInputStream *input,
|
||||
GFileInfo *file_info,
|
||||
GVariant *xattrs,
|
||||
GVariant *options,
|
||||
GInputStream **out_input,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_raw_file_to_archive_z2_stream_with_options (
|
||||
GInputStream *input, GFileInfo *file_info, GVariant *xattrs, GVariant *options,
|
||||
GInputStream **out_input, GCancellable *cancellable, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_raw_file_to_content_stream (GInputStream *input,
|
||||
GFileInfo *file_info,
|
||||
GVariant *xattrs,
|
||||
GInputStream **out_input,
|
||||
guint64 *out_length,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_raw_file_to_content_stream (GInputStream *input, GFileInfo *file_info,
|
||||
GVariant *xattrs, GInputStream **out_input,
|
||||
guint64 *out_length, GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_checksum_file_from_input (GFileInfo *file_info,
|
||||
GVariant *xattrs,
|
||||
GInputStream *in,
|
||||
OstreeObjectType objtype,
|
||||
guchar **out_csum,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_checksum_file_from_input (GFileInfo *file_info, GVariant *xattrs, GInputStream *in,
|
||||
OstreeObjectType objtype, guchar **out_csum,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_checksum_file (GFile *f,
|
||||
OstreeObjectType objtype,
|
||||
guchar **out_csum,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_checksum_file (GFile *f, OstreeObjectType objtype, guchar **out_csum,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_break_hardlink (int dfd,
|
||||
const char *path,
|
||||
gboolean skip_xattrs,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_break_hardlink (int dfd, const char *path, gboolean skip_xattrs,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
GVariant *ostree_fs_get_all_xattrs (int fd, GCancellable *cancellable, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
GVariant *ostree_fs_get_all_xattrs_at (int dfd, const char *path, GCancellable *cancellable, GError **error);
|
||||
GVariant *ostree_fs_get_all_xattrs_at (int dfd, const char *path, GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
/**
|
||||
* OstreeChecksumFlags:
|
||||
@ -483,77 +446,60 @@ GVariant *ostree_fs_get_all_xattrs_at (int dfd, const char *path, GCancellable *
|
||||
*
|
||||
* Since: 2017.13
|
||||
*/
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
OSTREE_CHECKSUM_FLAGS_NONE = 0,
|
||||
OSTREE_CHECKSUM_FLAGS_IGNORE_XATTRS = (1 << 0),
|
||||
OSTREE_CHECKSUM_FLAGS_CANONICAL_PERMISSIONS = (1 << 1),
|
||||
} OstreeChecksumFlags;
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_checksum_file_at (int dfd,
|
||||
const char *path,
|
||||
struct stat *stbuf,
|
||||
OstreeObjectType objtype,
|
||||
OstreeChecksumFlags flags,
|
||||
char **out_checksum,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_checksum_file_at (int dfd, const char *path, struct stat *stbuf,
|
||||
OstreeObjectType objtype, OstreeChecksumFlags flags,
|
||||
char **out_checksum, GCancellable *cancellable, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_checksum_file_async (GFile *f,
|
||||
OstreeObjectType objtype,
|
||||
int io_priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
void ostree_checksum_file_async (GFile *f, OstreeObjectType objtype, int io_priority,
|
||||
GCancellable *cancellable, GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_checksum_file_async_finish (GFile *f,
|
||||
GAsyncResult *result,
|
||||
guchar **out_csum,
|
||||
GError **error);
|
||||
gboolean ostree_checksum_file_async_finish (GFile *f, GAsyncResult *result, guchar **out_csum,
|
||||
GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
GVariant *ostree_create_directory_metadata (GFileInfo *dir_info,
|
||||
GVariant *xattrs);
|
||||
GVariant *ostree_create_directory_metadata (GFileInfo *dir_info, GVariant *xattrs);
|
||||
|
||||
/* VALIDATION */
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_validate_structureof_objtype (guchar objtype,
|
||||
GError **error);
|
||||
gboolean ostree_validate_structureof_objtype (guchar objtype, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_validate_structureof_csum_v (GVariant *checksum,
|
||||
GError **error);
|
||||
gboolean ostree_validate_structureof_csum_v (GVariant *checksum, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_validate_structureof_checksum_string (const char *checksum,
|
||||
GError **error);
|
||||
gboolean ostree_validate_structureof_checksum_string (const char *checksum, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_validate_structureof_file_mode (guint32 mode,
|
||||
GError **error);
|
||||
gboolean ostree_validate_structureof_file_mode (guint32 mode, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_validate_structureof_commit (GVariant *commit,
|
||||
GError **error);
|
||||
gboolean ostree_validate_structureof_commit (GVariant *commit, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_validate_structureof_dirtree (GVariant *dirtree,
|
||||
GError **error);
|
||||
gboolean ostree_validate_structureof_dirtree (GVariant *dirtree, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_validate_structureof_dirmeta (GVariant *dirmeta,
|
||||
GError **error);
|
||||
gboolean ostree_validate_structureof_dirmeta (GVariant *dirmeta, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gchar * ostree_commit_get_parent (GVariant *commit_variant);
|
||||
gchar *ostree_commit_get_parent (GVariant *commit_variant);
|
||||
_OSTREE_PUBLIC
|
||||
guint64 ostree_commit_get_timestamp (GVariant *commit_variant);
|
||||
guint64 ostree_commit_get_timestamp (GVariant *commit_variant);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gchar * ostree_commit_get_content_checksum (GVariant *commit_variant);
|
||||
gchar *ostree_commit_get_content_checksum (GVariant *commit_variant);
|
||||
|
||||
/**
|
||||
* OstreeCommitSizesEntry:
|
||||
@ -567,7 +513,8 @@ gchar * ostree_commit_get_content_checksum (GVariant *commit_variant);
|
||||
*
|
||||
* Since: 2020.1
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
gchar *checksum;
|
||||
OstreeObjectType objtype;
|
||||
guint64 unpacked;
|
||||
@ -578,19 +525,17 @@ _OSTREE_PUBLIC
|
||||
GType ostree_commit_sizes_entry_get_type (void);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeCommitSizesEntry *ostree_commit_sizes_entry_new (const gchar *checksum,
|
||||
OstreeObjectType objtype,
|
||||
guint64 unpacked,
|
||||
guint64 archived);
|
||||
OstreeCommitSizesEntry *ostree_commit_sizes_entry_new (const gchar *checksum,
|
||||
OstreeObjectType objtype, guint64 unpacked,
|
||||
guint64 archived);
|
||||
_OSTREE_PUBLIC
|
||||
OstreeCommitSizesEntry *ostree_commit_sizes_entry_copy (const OstreeCommitSizesEntry *entry);
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_commit_sizes_entry_free (OstreeCommitSizesEntry *entry);
|
||||
void ostree_commit_sizes_entry_free (OstreeCommitSizesEntry *entry);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_commit_get_object_sizes (GVariant *commit_variant,
|
||||
GPtrArray **out_sizes_entries,
|
||||
GError **error);
|
||||
gboolean ostree_commit_get_object_sizes (GVariant *commit_variant, GPtrArray **out_sizes_entries,
|
||||
GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_check_version (guint required_year, guint required_release);
|
||||
|
@ -28,8 +28,7 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
GDateTime *_ostree_parse_rfc2616_date_time (const char *buf,
|
||||
size_t len);
|
||||
GDateTime *_ostree_parse_rfc2616_date_time (const char *buf, size_t len);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -30,11 +30,7 @@
|
||||
|
||||
/* @buf must already be known to be long enough */
|
||||
static gboolean
|
||||
parse_uint (const char *buf,
|
||||
guint n_digits,
|
||||
guint min,
|
||||
guint max,
|
||||
guint *out)
|
||||
parse_uint (const char *buf, guint n_digits, guint min, guint max, guint *out)
|
||||
{
|
||||
guint64 number;
|
||||
const char *end_ptr = NULL;
|
||||
@ -42,19 +38,15 @@ parse_uint (const char *buf,
|
||||
|
||||
g_assert (out != NULL);
|
||||
|
||||
if(!(n_digits == 2 || n_digits == 4))
|
||||
if (!(n_digits == 2 || n_digits == 4))
|
||||
return FALSE;
|
||||
|
||||
errno = 0;
|
||||
number = g_ascii_strtoull (buf, (gchar **)&end_ptr, 10);
|
||||
saved_errno = errno;
|
||||
|
||||
if (!g_ascii_isdigit (buf[0]) ||
|
||||
saved_errno != 0 ||
|
||||
end_ptr == NULL ||
|
||||
end_ptr != buf + n_digits ||
|
||||
number < min ||
|
||||
number > max)
|
||||
if (!g_ascii_isdigit (buf[0]) || saved_errno != 0 || end_ptr == NULL || end_ptr != buf + n_digits
|
||||
|| number < min || number > max)
|
||||
return FALSE;
|
||||
|
||||
*out = number;
|
||||
@ -75,36 +67,16 @@ parse_uint (const char *buf,
|
||||
* Wed, 21 Oct 2015 07:28:00 GMT
|
||||
*/
|
||||
GDateTime *
|
||||
_ostree_parse_rfc2616_date_time (const char *buf,
|
||||
size_t len)
|
||||
_ostree_parse_rfc2616_date_time (const char *buf, size_t len)
|
||||
{
|
||||
guint day_int, year_int, hour_int, minute_int, second_int;
|
||||
const char *day_names[] =
|
||||
{
|
||||
"Mon",
|
||||
"Tue",
|
||||
"Wed",
|
||||
"Thu",
|
||||
"Fri",
|
||||
"Sat",
|
||||
"Sun",
|
||||
};
|
||||
const char *day_names[] = {
|
||||
"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
|
||||
};
|
||||
size_t day_name_index;
|
||||
const char *month_names[] =
|
||||
{
|
||||
"Jan",
|
||||
"Feb",
|
||||
"Mar",
|
||||
"Apr",
|
||||
"May",
|
||||
"Jun",
|
||||
"Jul",
|
||||
"Aug",
|
||||
"Sep",
|
||||
"Oct",
|
||||
"Nov",
|
||||
"Dec",
|
||||
};
|
||||
const char *month_names[] = {
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
|
||||
};
|
||||
size_t month_name_index;
|
||||
|
||||
if (len != 29)
|
||||
@ -154,13 +126,13 @@ _ostree_parse_rfc2616_date_time (const char *buf,
|
||||
return NULL;
|
||||
if (*(minute + 2) != ':')
|
||||
return NULL;
|
||||
if (!parse_uint (second, 2, 0, 60, &second_int)) /* allow leap seconds */
|
||||
if (!parse_uint (second, 2, 0, 60, &second_int)) /* allow leap seconds */
|
||||
return NULL;
|
||||
if (*(second + 2) != ' ')
|
||||
return NULL;
|
||||
if (strncmp (tz, "GMT", 3) != 0)
|
||||
return NULL;
|
||||
|
||||
return g_date_time_new_utc (year_int, month_name_index + 1, day_int,
|
||||
hour_int, minute_int, second_int);
|
||||
return g_date_time_new_utc (year_int, month_name_index + 1, day_int, hour_int, minute_int,
|
||||
second_int);
|
||||
}
|
||||
|
@ -21,7 +21,6 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
/**
|
||||
* OstreeDeployment:
|
||||
* @parent_instance:
|
||||
@ -40,7 +39,7 @@ G_BEGIN_DECLS
|
||||
*/
|
||||
struct _OstreeDeployment
|
||||
{
|
||||
GObject parent_instance;
|
||||
GObject parent_instance;
|
||||
|
||||
int index;
|
||||
char *osname;
|
||||
@ -58,9 +57,8 @@ struct _OstreeDeployment
|
||||
|
||||
void _ostree_deployment_set_bootcsum (OstreeDeployment *self, const char *bootcsum);
|
||||
|
||||
void _ostree_deployment_set_overlay_initrds (OstreeDeployment *self,
|
||||
char **overlay_initrds);
|
||||
void _ostree_deployment_set_overlay_initrds (OstreeDeployment *self, char **overlay_initrds);
|
||||
|
||||
char** _ostree_deployment_get_overlay_initrds (OstreeDeployment *self);
|
||||
char **_ostree_deployment_get_overlay_initrds (OstreeDeployment *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -17,9 +17,9 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "otutil.h"
|
||||
#include "ostree.h"
|
||||
#include "ostree-deployment-private.h"
|
||||
#include "ostree.h"
|
||||
#include "otutil.h"
|
||||
|
||||
typedef GObjectClass OstreeDeploymentClass;
|
||||
|
||||
@ -209,16 +209,14 @@ ostree_deployment_origin_remove_transient_state (GKeyFile *origin)
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_deployment_set_bootcsum (OstreeDeployment *self,
|
||||
const char *bootcsum)
|
||||
_ostree_deployment_set_bootcsum (OstreeDeployment *self, const char *bootcsum)
|
||||
{
|
||||
g_free (self->bootcsum);
|
||||
self->bootcsum = g_strdup (bootcsum);
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_deployment_set_overlay_initrds (OstreeDeployment *self,
|
||||
char **overlay_initrds)
|
||||
_ostree_deployment_set_overlay_initrds (OstreeDeployment *self, char **overlay_initrds)
|
||||
{
|
||||
g_clear_pointer (&self->overlay_initrds, g_strfreev);
|
||||
g_clear_pointer (&self->overlay_initrds_id, g_free);
|
||||
@ -230,7 +228,7 @@ _ostree_deployment_set_overlay_initrds (OstreeDeployment *self,
|
||||
* ostree_sysroot_write_deployments_with_options() can easily compare initrds when
|
||||
* comparing deployments for whether a bootswap is necessary. We could be fancier here but
|
||||
* meh... this works. */
|
||||
g_autoptr(GString) id = g_string_new (NULL);
|
||||
g_autoptr (GString) id = g_string_new (NULL);
|
||||
for (char **it = overlay_initrds; it && *it; it++)
|
||||
g_string_append (id, *it);
|
||||
|
||||
@ -238,7 +236,7 @@ _ostree_deployment_set_overlay_initrds (OstreeDeployment *self,
|
||||
self->overlay_initrds_id = g_string_free (g_steal_pointer (&id), FALSE);
|
||||
}
|
||||
|
||||
char**
|
||||
char **
|
||||
_ostree_deployment_get_overlay_initrds (OstreeDeployment *self)
|
||||
{
|
||||
return self->overlay_initrds;
|
||||
@ -253,10 +251,9 @@ _ostree_deployment_get_overlay_initrds (OstreeDeployment *self)
|
||||
OstreeDeployment *
|
||||
ostree_deployment_clone (OstreeDeployment *self)
|
||||
{
|
||||
g_autoptr(OstreeBootconfigParser) new_bootconfig = NULL;
|
||||
OstreeDeployment *ret = ostree_deployment_new (self->index, self->osname, self->csum,
|
||||
self->deployserial,
|
||||
self->bootcsum, self->bootserial);
|
||||
g_autoptr (OstreeBootconfigParser) new_bootconfig = NULL;
|
||||
OstreeDeployment *ret = ostree_deployment_new (
|
||||
self->index, self->osname, self->csum, self->deployserial, self->bootcsum, self->bootserial);
|
||||
|
||||
new_bootconfig = ostree_bootconfig_parser_clone (self->bootconfig);
|
||||
ostree_deployment_set_bootconfig (ret, new_bootconfig);
|
||||
@ -265,7 +262,7 @@ ostree_deployment_clone (OstreeDeployment *self)
|
||||
|
||||
if (self->origin)
|
||||
{
|
||||
g_autoptr(GKeyFile) new_origin = NULL;
|
||||
g_autoptr (GKeyFile) new_origin = NULL;
|
||||
g_autofree char *data = NULL;
|
||||
gsize len;
|
||||
gboolean success;
|
||||
@ -291,10 +288,9 @@ ostree_deployment_clone (OstreeDeployment *self)
|
||||
guint
|
||||
ostree_deployment_hash (gconstpointer v)
|
||||
{
|
||||
OstreeDeployment *d = (OstreeDeployment*)v;
|
||||
return g_str_hash (ostree_deployment_get_osname (d)) +
|
||||
g_str_hash (ostree_deployment_get_csum (d)) +
|
||||
ostree_deployment_get_deployserial (d);
|
||||
OstreeDeployment *d = (OstreeDeployment *)v;
|
||||
return g_str_hash (ostree_deployment_get_osname (d)) + g_str_hash (ostree_deployment_get_csum (d))
|
||||
+ ostree_deployment_get_deployserial (d);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -307,17 +303,15 @@ ostree_deployment_hash (gconstpointer v)
|
||||
gboolean
|
||||
ostree_deployment_equal (gconstpointer ap, gconstpointer bp)
|
||||
{
|
||||
OstreeDeployment *a = (OstreeDeployment*)ap;
|
||||
OstreeDeployment *b = (OstreeDeployment*)bp;
|
||||
OstreeDeployment *a = (OstreeDeployment *)ap;
|
||||
OstreeDeployment *b = (OstreeDeployment *)bp;
|
||||
|
||||
if (a == b)
|
||||
return TRUE;
|
||||
else if (a != NULL && b != NULL)
|
||||
return g_str_equal (ostree_deployment_get_osname (a),
|
||||
ostree_deployment_get_osname (b)) &&
|
||||
g_str_equal (ostree_deployment_get_csum (a),
|
||||
ostree_deployment_get_csum (b)) &&
|
||||
ostree_deployment_get_deployserial (a) == ostree_deployment_get_deployserial (b);
|
||||
return g_str_equal (ostree_deployment_get_osname (a), ostree_deployment_get_osname (b))
|
||||
&& g_str_equal (ostree_deployment_get_csum (a), ostree_deployment_get_csum (b))
|
||||
&& ostree_deployment_get_deployserial (a) == ostree_deployment_get_deployserial (b);
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
@ -363,12 +357,8 @@ ostree_deployment_class_init (OstreeDeploymentClass *class)
|
||||
* Returns: (transfer full) (not nullable): New deployment
|
||||
*/
|
||||
OstreeDeployment *
|
||||
ostree_deployment_new (int index,
|
||||
const char *osname,
|
||||
const char *csum,
|
||||
int deployserial,
|
||||
const char *bootcsum,
|
||||
int bootserial)
|
||||
ostree_deployment_new (int index, const char *osname, const char *csum, int deployserial,
|
||||
const char *bootcsum, int bootserial)
|
||||
{
|
||||
OstreeDeployment *self;
|
||||
|
||||
@ -404,8 +394,7 @@ char *
|
||||
ostree_deployment_get_origin_relpath (OstreeDeployment *self)
|
||||
{
|
||||
return g_strdup_printf ("ostree/deploy/%s/deploy/%s.%d.origin",
|
||||
ostree_deployment_get_osname (self),
|
||||
ostree_deployment_get_csum (self),
|
||||
ostree_deployment_get_osname (self), ostree_deployment_get_csum (self),
|
||||
ostree_deployment_get_deployserial (self));
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,8 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_DEPLOYMENT (ostree_deployment_get_type ())
|
||||
#define OSTREE_DEPLOYMENT(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_DEPLOYMENT, OstreeDeployment))
|
||||
#define OSTREE_DEPLOYMENT(inst) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_DEPLOYMENT, OstreeDeployment))
|
||||
#define OSTREE_IS_DEPLOYMENT(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), OSTREE_TYPE_DEPLOYMENT))
|
||||
|
||||
/**
|
||||
@ -47,12 +48,8 @@ _OSTREE_PUBLIC
|
||||
gboolean ostree_deployment_equal (gconstpointer ap, gconstpointer bp);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeDeployment * ostree_deployment_new (int index,
|
||||
const char *osname,
|
||||
const char *csum,
|
||||
int deployserial,
|
||||
const char *bootcsum,
|
||||
int bootserial);
|
||||
OstreeDeployment *ostree_deployment_new (int index, const char *osname, const char *csum,
|
||||
int deployserial, const char *bootcsum, int bootserial);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
int ostree_deployment_get_index (OstreeDeployment *self);
|
||||
@ -94,7 +91,8 @@ OstreeDeployment *ostree_deployment_clone (OstreeDeployment *self);
|
||||
_OSTREE_PUBLIC
|
||||
char *ostree_deployment_get_origin_relpath (OstreeDeployment *self);
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
OSTREE_DEPLOYMENT_UNLOCKED_NONE,
|
||||
OSTREE_DEPLOYMENT_UNLOCKED_DEVELOPMENT,
|
||||
OSTREE_DEPLOYMENT_UNLOCKED_HOTFIX,
|
||||
|
@ -22,62 +22,55 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "libglnx.h"
|
||||
#include "ostree.h"
|
||||
#include "ostree-repo-private.h"
|
||||
#include "ostree.h"
|
||||
#include "otutil.h"
|
||||
|
||||
/* See ostree-repo.c for a bit more info about these ABI checks */
|
||||
#if __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 8 && __SIZEOF_INT__ == 4
|
||||
G_STATIC_ASSERT(sizeof(OstreeDiffDirsOptions) ==
|
||||
sizeof(int) * 2 +
|
||||
sizeof(gpointer) +
|
||||
sizeof(int) * (7+6) +
|
||||
sizeof(int) + /* hole */
|
||||
sizeof(gpointer) * 7);
|
||||
G_STATIC_ASSERT (sizeof (OstreeDiffDirsOptions)
|
||||
== sizeof (int) * 2 + sizeof (gpointer) + sizeof (int) * (7 + 6) + sizeof (int)
|
||||
+ /* hole */
|
||||
sizeof (gpointer) * 7);
|
||||
#endif
|
||||
|
||||
static gboolean
|
||||
get_file_checksum (OstreeDiffFlags flags,
|
||||
GFile *f,
|
||||
GFileInfo *f_info,
|
||||
char **out_checksum,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
get_file_checksum (OstreeDiffFlags flags, GFile *f, GFileInfo *f_info, char **out_checksum,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
g_autofree char *ret_checksum = NULL;
|
||||
|
||||
if (OSTREE_IS_REPO_FILE (f))
|
||||
{
|
||||
ret_checksum = g_strdup (ostree_repo_file_get_checksum ((OstreeRepoFile*)f));
|
||||
ret_checksum = g_strdup (ostree_repo_file_get_checksum ((OstreeRepoFile *)f));
|
||||
}
|
||||
else
|
||||
{
|
||||
g_autoptr(GVariant) xattrs = NULL;
|
||||
g_autoptr(GInputStream) in = NULL;
|
||||
g_autoptr (GVariant) xattrs = NULL;
|
||||
g_autoptr (GInputStream) in = NULL;
|
||||
|
||||
if (!(flags & OSTREE_DIFF_FLAGS_IGNORE_XATTRS))
|
||||
{
|
||||
if (!glnx_dfd_name_get_all_xattrs (AT_FDCWD, gs_file_get_path_cached (f),
|
||||
&xattrs, cancellable, error))
|
||||
if (!glnx_dfd_name_get_all_xattrs (AT_FDCWD, gs_file_get_path_cached (f), &xattrs,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (g_file_info_get_file_type (f_info) == G_FILE_TYPE_REGULAR)
|
||||
{
|
||||
in = (GInputStream*)g_file_read (f, cancellable, error);
|
||||
in = (GInputStream *)g_file_read (f, cancellable, error);
|
||||
if (!in)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_autofree guchar *csum = NULL;
|
||||
if (!ostree_checksum_file_from_input (f_info, xattrs, in,
|
||||
OSTREE_OBJECT_TYPE_FILE,
|
||||
&csum, cancellable, error))
|
||||
if (!ostree_checksum_file_from_input (f_info, xattrs, in, OSTREE_OBJECT_TYPE_FILE, &csum,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
ret_checksum = ostree_checksum_from_bytes (csum);
|
||||
}
|
||||
|
||||
ot_transfer_out_value(out_checksum, &ret_checksum);
|
||||
ot_transfer_out_value (out_checksum, &ret_checksum);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -103,17 +96,12 @@ ostree_diff_item_unref (OstreeDiffItem *diffitem)
|
||||
g_free (diffitem);
|
||||
}
|
||||
|
||||
G_DEFINE_BOXED_TYPE(OstreeDiffItem, ostree_diff_item,
|
||||
ostree_diff_item_ref,
|
||||
ostree_diff_item_unref);
|
||||
G_DEFINE_BOXED_TYPE (OstreeDiffItem, ostree_diff_item, ostree_diff_item_ref,
|
||||
ostree_diff_item_unref);
|
||||
|
||||
static OstreeDiffItem *
|
||||
diff_item_new (GFile *a,
|
||||
GFileInfo *a_info,
|
||||
GFile *b,
|
||||
GFileInfo *b_info,
|
||||
char *checksum_a,
|
||||
char *checksum_b)
|
||||
diff_item_new (GFile *a, GFileInfo *a_info, GFile *b, GFileInfo *b_info, char *checksum_a,
|
||||
char *checksum_b)
|
||||
{
|
||||
OstreeDiffItem *ret = g_new0 (OstreeDiffItem, 1);
|
||||
ret->refcount = 1;
|
||||
@ -127,14 +115,8 @@ diff_item_new (GFile *a,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
diff_files (OstreeDiffFlags flags,
|
||||
GFile *a,
|
||||
GFileInfo *a_info,
|
||||
GFile *b,
|
||||
GFileInfo *b_info,
|
||||
OstreeDiffItem **out_item,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
diff_files (OstreeDiffFlags flags, GFile *a, GFileInfo *a_info, GFile *b, GFileInfo *b_info,
|
||||
OstreeDiffItem **out_item, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
g_autofree char *checksum_a = NULL;
|
||||
g_autofree char *checksum_b = NULL;
|
||||
@ -143,28 +125,21 @@ diff_files (OstreeDiffFlags flags,
|
||||
if (!get_file_checksum (flags, b, b_info, &checksum_b, cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
g_autoptr(OstreeDiffItem) ret_item = NULL;
|
||||
g_autoptr (OstreeDiffItem) ret_item = NULL;
|
||||
if (strcmp (checksum_a, checksum_b) != 0)
|
||||
{
|
||||
ret_item = diff_item_new (a, a_info, b, b_info,
|
||||
checksum_a, checksum_b);
|
||||
ret_item = diff_item_new (a, a_info, b, b_info, checksum_a, checksum_b);
|
||||
}
|
||||
|
||||
ot_transfer_out_value(out_item, &ret_item);
|
||||
ot_transfer_out_value (out_item, &ret_item);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
diff_add_dir_recurse (GFile *d,
|
||||
GPtrArray *added,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
diff_add_dir_recurse (GFile *d, GPtrArray *added, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
g_autoptr(GFileEnumerator) dir_enum =
|
||||
g_file_enumerate_children (d, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
cancellable,
|
||||
error);
|
||||
g_autoptr (GFileEnumerator) dir_enum = g_file_enumerate_children (
|
||||
d, OSTREE_GIO_FAST_QUERYINFO, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error);
|
||||
if (!dir_enum)
|
||||
return FALSE;
|
||||
|
||||
@ -173,15 +148,14 @@ diff_add_dir_recurse (GFile *d,
|
||||
GFileInfo *child_info;
|
||||
const char *name;
|
||||
|
||||
if (!g_file_enumerator_iterate (dir_enum, &child_info, NULL,
|
||||
cancellable, error))
|
||||
if (!g_file_enumerator_iterate (dir_enum, &child_info, NULL, cancellable, error))
|
||||
return FALSE;
|
||||
if (child_info == NULL)
|
||||
break;
|
||||
|
||||
name = g_file_info_get_name (child_info);
|
||||
|
||||
g_autoptr(GFile) child = g_file_get_child (d, name);
|
||||
g_autoptr (GFile) child = g_file_get_child (d, name);
|
||||
g_ptr_array_add (added, g_object_ref (child));
|
||||
|
||||
if (g_file_info_get_file_type (child_info) == G_FILE_TYPE_DIRECTORY)
|
||||
@ -209,18 +183,11 @@ diff_add_dir_recurse (GFile *d,
|
||||
* sets of #OstreeDiffItem in @modified, @removed, and @added.
|
||||
*/
|
||||
gboolean
|
||||
ostree_diff_dirs (OstreeDiffFlags flags,
|
||||
GFile *a,
|
||||
GFile *b,
|
||||
GPtrArray *modified,
|
||||
GPtrArray *removed,
|
||||
GPtrArray *added,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_diff_dirs (OstreeDiffFlags flags, GFile *a, GFile *b, GPtrArray *modified,
|
||||
GPtrArray *removed, GPtrArray *added, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
return ostree_diff_dirs_with_options (flags, a, b, modified,
|
||||
removed, added, NULL,
|
||||
cancellable, error);
|
||||
return ostree_diff_dirs_with_options (flags, a, b, modified, removed, added, NULL, cancellable,
|
||||
error);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -241,23 +208,17 @@ ostree_diff_dirs (OstreeDiffFlags flags,
|
||||
* Since: 2017.4
|
||||
*/
|
||||
gboolean
|
||||
ostree_diff_dirs_with_options (OstreeDiffFlags flags,
|
||||
GFile *a,
|
||||
GFile *b,
|
||||
GPtrArray *modified,
|
||||
GPtrArray *removed,
|
||||
GPtrArray *added,
|
||||
OstreeDiffDirsOptions *options,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_diff_dirs_with_options (OstreeDiffFlags flags, GFile *a, GFile *b, GPtrArray *modified,
|
||||
GPtrArray *removed, GPtrArray *added, OstreeDiffDirsOptions *options,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
GError *temp_error = NULL;
|
||||
g_autoptr(GFileEnumerator) dir_enum = NULL;
|
||||
g_autoptr(GFile) child_a = NULL;
|
||||
g_autoptr(GFile) child_b = NULL;
|
||||
g_autoptr(GFileInfo) child_a_info = NULL;
|
||||
g_autoptr(GFileInfo) child_b_info = NULL;
|
||||
g_autoptr (GFileEnumerator) dir_enum = NULL;
|
||||
g_autoptr (GFile) child_a = NULL;
|
||||
g_autoptr (GFile) child_b = NULL;
|
||||
g_autoptr (GFileInfo) child_a_info = NULL;
|
||||
g_autoptr (GFileInfo) child_b_info = NULL;
|
||||
OstreeDiffDirsOptions default_opts = OSTREE_DIFF_DIRS_OPTIONS_INIT;
|
||||
|
||||
if (!options)
|
||||
@ -268,13 +229,13 @@ ostree_diff_dirs_with_options (OstreeDiffFlags flags,
|
||||
*/
|
||||
if (OSTREE_IS_REPO_FILE (a))
|
||||
{
|
||||
OstreeRepo *repo = ostree_repo_file_get_repo ((OstreeRepoFile*)a);
|
||||
OstreeRepo *repo = ostree_repo_file_get_repo ((OstreeRepoFile *)a);
|
||||
if (repo->disable_xattrs || repo->mode == OSTREE_REPO_MODE_BARE_USER_ONLY)
|
||||
flags |= OSTREE_DIFF_FLAGS_IGNORE_XATTRS;
|
||||
}
|
||||
if (OSTREE_IS_REPO_FILE (b))
|
||||
{
|
||||
OstreeRepo *repo = ostree_repo_file_get_repo ((OstreeRepoFile*)b);
|
||||
OstreeRepo *repo = ostree_repo_file_get_repo ((OstreeRepoFile *)b);
|
||||
if (repo->disable_xattrs || repo->mode == OSTREE_REPO_MODE_BARE_USER_ONLY)
|
||||
flags |= OSTREE_DIFF_FLAGS_IGNORE_XATTRS;
|
||||
}
|
||||
@ -289,28 +250,26 @@ ostree_diff_dirs_with_options (OstreeDiffFlags flags,
|
||||
}
|
||||
|
||||
child_a_info = g_file_query_info (a, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
cancellable, error);
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error);
|
||||
if (!child_a_info)
|
||||
goto out;
|
||||
|
||||
child_b_info = g_file_query_info (b, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
cancellable, error);
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error);
|
||||
if (!child_b_info)
|
||||
goto out;
|
||||
|
||||
/* Fast path test for unmodified directories */
|
||||
if (g_file_info_get_file_type (child_a_info) == G_FILE_TYPE_DIRECTORY
|
||||
&& g_file_info_get_file_type (child_b_info) == G_FILE_TYPE_DIRECTORY
|
||||
&& OSTREE_IS_REPO_FILE (a)
|
||||
&& OSTREE_IS_REPO_FILE (b))
|
||||
&& OSTREE_IS_REPO_FILE (a) && OSTREE_IS_REPO_FILE (b))
|
||||
{
|
||||
OstreeRepoFile *a_repof = (OstreeRepoFile*) a;
|
||||
OstreeRepoFile *b_repof = (OstreeRepoFile*) b;
|
||||
OstreeRepoFile *a_repof = (OstreeRepoFile *)a;
|
||||
OstreeRepoFile *b_repof = (OstreeRepoFile *)b;
|
||||
|
||||
if (strcmp (ostree_repo_file_tree_get_contents_checksum (a_repof),
|
||||
ostree_repo_file_tree_get_contents_checksum (b_repof)) == 0)
|
||||
ostree_repo_file_tree_get_contents_checksum (b_repof))
|
||||
== 0)
|
||||
{
|
||||
ret = TRUE;
|
||||
goto out;
|
||||
@ -321,8 +280,7 @@ ostree_diff_dirs_with_options (OstreeDiffFlags flags,
|
||||
g_clear_object (&child_b_info);
|
||||
|
||||
dir_enum = g_file_enumerate_children (a, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
cancellable, error);
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error);
|
||||
if (!dir_enum)
|
||||
goto out;
|
||||
|
||||
@ -342,10 +300,9 @@ ostree_diff_dirs_with_options (OstreeDiffFlags flags,
|
||||
child_b = g_file_get_child (b, name);
|
||||
|
||||
g_clear_object (&child_b_info);
|
||||
child_b_info = g_file_query_info (child_b, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
cancellable,
|
||||
&temp_error);
|
||||
child_b_info
|
||||
= g_file_query_info (child_b, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, &temp_error);
|
||||
if (!child_b_info)
|
||||
{
|
||||
if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
|
||||
@ -369,8 +326,8 @@ ostree_diff_dirs_with_options (OstreeDiffFlags flags,
|
||||
child_b_type = g_file_info_get_file_type (child_b_info);
|
||||
if (child_a_type != child_b_type)
|
||||
{
|
||||
OstreeDiffItem *diff_item = diff_item_new (child_a, child_a_info,
|
||||
child_b, child_b_info, NULL, NULL);
|
||||
OstreeDiffItem *diff_item
|
||||
= diff_item_new (child_a, child_a_info, child_b, child_b_info, NULL, NULL);
|
||||
|
||||
g_ptr_array_add (modified, diff_item);
|
||||
}
|
||||
@ -387,9 +344,8 @@ ostree_diff_dirs_with_options (OstreeDiffFlags flags,
|
||||
|
||||
if (child_a_type == G_FILE_TYPE_DIRECTORY)
|
||||
{
|
||||
if (!ostree_diff_dirs_with_options (flags, child_a, child_b, modified,
|
||||
removed, added, options,
|
||||
cancellable, error))
|
||||
if (!ostree_diff_dirs_with_options (flags, child_a, child_b, modified, removed,
|
||||
added, options, cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
@ -405,8 +361,7 @@ ostree_diff_dirs_with_options (OstreeDiffFlags flags,
|
||||
|
||||
g_clear_object (&dir_enum);
|
||||
dir_enum = g_file_enumerate_children (b, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
cancellable, error);
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error);
|
||||
if (!dir_enum)
|
||||
goto out;
|
||||
|
||||
@ -424,10 +379,9 @@ ostree_diff_dirs_with_options (OstreeDiffFlags flags,
|
||||
child_b = g_file_get_child (b, name);
|
||||
|
||||
g_clear_object (&child_a_info);
|
||||
child_a_info = g_file_query_info (child_a, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
cancellable,
|
||||
&temp_error);
|
||||
child_a_info
|
||||
= g_file_query_info (child_a, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, &temp_error);
|
||||
if (!child_a_info)
|
||||
{
|
||||
if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
|
||||
@ -455,14 +409,12 @@ ostree_diff_dirs_with_options (OstreeDiffFlags flags,
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
print_diff_item (char prefix,
|
||||
GFile *base,
|
||||
GFile *file)
|
||||
print_diff_item (char prefix, GFile *base, GFile *file)
|
||||
{
|
||||
if (g_file_is_native (file))
|
||||
{
|
||||
@ -486,11 +438,7 @@ print_diff_item (char prefix,
|
||||
* Print the contents of a diff to stdout.
|
||||
*/
|
||||
void
|
||||
ostree_diff_print (GFile *a,
|
||||
GFile *b,
|
||||
GPtrArray *modified,
|
||||
GPtrArray *removed,
|
||||
GPtrArray *added)
|
||||
ostree_diff_print (GFile *a, GFile *b, GPtrArray *modified, GPtrArray *removed, GPtrArray *added)
|
||||
{
|
||||
guint i;
|
||||
|
||||
|
@ -29,7 +29,8 @@ G_BEGIN_DECLS
|
||||
/**
|
||||
* OstreeDiffFlags:
|
||||
*/
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
OSTREE_DIFF_FLAGS_NONE = 0,
|
||||
OSTREE_DIFF_FLAGS_IGNORE_XATTRS = (1 << 0)
|
||||
} OstreeDiffFlags;
|
||||
@ -40,7 +41,7 @@ typedef enum {
|
||||
typedef struct _OstreeDiffItem OstreeDiffItem;
|
||||
struct _OstreeDiffItem
|
||||
{
|
||||
gint refcount; /* atomic */
|
||||
gint refcount; /* atomic */
|
||||
|
||||
GFile *src;
|
||||
GFile *target;
|
||||
@ -61,14 +62,9 @@ _OSTREE_PUBLIC
|
||||
GType ostree_diff_item_get_type (void);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_diff_dirs (OstreeDiffFlags flags,
|
||||
GFile *a,
|
||||
GFile *b,
|
||||
GPtrArray *modified,
|
||||
GPtrArray *removed,
|
||||
GPtrArray *added,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_diff_dirs (OstreeDiffFlags flags, GFile *a, GFile *b, GPtrArray *modified,
|
||||
GPtrArray *removed, GPtrArray *added, GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
/**
|
||||
* OstreeDiffDirsOptions:
|
||||
@ -77,7 +73,8 @@ gboolean ostree_diff_dirs (OstreeDiffFlags flags,
|
||||
* that owner_uid/gid is set to -1 when not used. This is used by
|
||||
* ostree_diff_dirs_with_options().
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
gint owner_uid;
|
||||
gint owner_gid;
|
||||
|
||||
@ -94,24 +91,19 @@ typedef struct {
|
||||
*
|
||||
* Use this to initialize an `OstreeDiffDirsOptions` structure.
|
||||
*/
|
||||
#define OSTREE_DIFF_DIRS_OPTIONS_INIT { .owner_uid = -1, .owner_gid = -1, }
|
||||
#define OSTREE_DIFF_DIRS_OPTIONS_INIT \
|
||||
{ \
|
||||
.owner_uid = -1, .owner_gid = -1, \
|
||||
}
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_diff_dirs_with_options (OstreeDiffFlags flags,
|
||||
GFile *a,
|
||||
GFile *b,
|
||||
GPtrArray *modified,
|
||||
GPtrArray *removed,
|
||||
GPtrArray *added,
|
||||
OstreeDiffDirsOptions *options,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_diff_dirs_with_options (OstreeDiffFlags flags, GFile *a, GFile *b,
|
||||
GPtrArray *modified, GPtrArray *removed, GPtrArray *added,
|
||||
OstreeDiffDirsOptions *options, GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_diff_print (GFile *a,
|
||||
GFile *b,
|
||||
GPtrArray *modified,
|
||||
GPtrArray *removed,
|
||||
GPtrArray *added);
|
||||
void ostree_diff_print (GFile *a, GFile *b, GPtrArray *modified, GPtrArray *removed,
|
||||
GPtrArray *added);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -24,6 +24,5 @@
|
||||
#include <glib-object.h>
|
||||
|
||||
#ifndef __GI_SCANNER__
|
||||
_OSTREE_PUBLIC GType
|
||||
ostree_fetcher_config_flags_get_type (void);
|
||||
_OSTREE_PUBLIC GType ostree_fetcher_config_flags_get_type (void);
|
||||
#endif
|
||||
|
@ -20,23 +20,24 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <gio/gfiledescriptorbased.h>
|
||||
#include <gio/gunixoutputstream.h>
|
||||
#include <glib-unix.h>
|
||||
#include <curl/curl.h>
|
||||
|
||||
/* These macros came from 7.43.0, but we want to check
|
||||
* for versions a bit earlier than that (to work on CentOS 7),
|
||||
* so define them here if we're using an older version.
|
||||
*/
|
||||
#ifndef CURL_VERSION_BITS
|
||||
#define CURL_VERSION_BITS(x,y,z) ((x)<<16|(y)<<8|z)
|
||||
#define CURL_VERSION_BITS(x, y, z) ((x) << 16 | (y) << 8 | z)
|
||||
#endif
|
||||
#ifndef CURL_AT_LEAST_VERSION
|
||||
#define CURL_AT_LEAST_VERSION(x,y,z) (LIBCURL_VERSION_NUM >= CURL_VERSION_BITS(x, y, z))
|
||||
#define CURL_AT_LEAST_VERSION(x, y, z) (LIBCURL_VERSION_NUM >= CURL_VERSION_BITS (x, y, z))
|
||||
#endif
|
||||
|
||||
/* Cargo culted from https://github.com/curl/curl/blob/curl-7_53_0/docs/examples/http2-download.c */
|
||||
/* Cargo culted from https://github.com/curl/curl/blob/curl-7_53_0/docs/examples/http2-download.c
|
||||
*/
|
||||
#ifndef CURLPIPE_MULTIPLEX
|
||||
/* This little trick will just make sure that we don't enable pipelining for
|
||||
libcurls old enough to not have this symbol. It is _not_ defined to zero in
|
||||
@ -45,9 +46,9 @@
|
||||
#endif
|
||||
|
||||
#include "ostree-date-utils-private.h"
|
||||
#include "ostree-fetcher.h"
|
||||
#include "ostree-fetcher-util.h"
|
||||
#include "ostree-enumtypes.h"
|
||||
#include "ostree-fetcher-util.h"
|
||||
#include "ostree-fetcher.h"
|
||||
#include "ostree-repo-private.h"
|
||||
#include "otutil.h"
|
||||
|
||||
@ -82,13 +83,14 @@ struct OstreeFetcher
|
||||
GSource *timer_event;
|
||||
int curl_running;
|
||||
GHashTable *outstanding_requests; /* Set<GTask> */
|
||||
GHashTable *sockets; /* Set<SockInfo> */
|
||||
GHashTable *sockets; /* Set<SockInfo> */
|
||||
|
||||
guint64 bytes_transferred;
|
||||
};
|
||||
|
||||
/* Information associated with a request */
|
||||
struct FetcherRequest {
|
||||
struct FetcherRequest
|
||||
{
|
||||
guint refcount;
|
||||
GPtrArray *mirrorlist;
|
||||
guint idx;
|
||||
@ -98,15 +100,16 @@ struct FetcherRequest {
|
||||
guint64 max_size;
|
||||
OstreeFetcherRequestFlags flags;
|
||||
struct curl_slist *req_headers;
|
||||
char *if_none_match; /* request ETag */
|
||||
guint64 if_modified_since; /* seconds since the epoch */
|
||||
char *if_none_match; /* request ETag */
|
||||
guint64 if_modified_since; /* seconds since the epoch */
|
||||
gboolean is_membuf;
|
||||
GError *caught_write_error;
|
||||
GLnxTmpfile tmpf;
|
||||
GString *output_buf;
|
||||
gboolean out_not_modified; /* TRUE if the server gave a HTTP 304 Not Modified response, which we don’t propagate as an error */
|
||||
char *out_etag; /* response ETag */
|
||||
guint64 out_last_modified; /* response Last-Modified, seconds since the epoch */
|
||||
gboolean out_not_modified; /* TRUE if the server gave a HTTP 304 Not Modified response, which we
|
||||
don’t propagate as an error */
|
||||
char *out_etag; /* response ETag */
|
||||
guint64 out_last_modified; /* response Last-Modified, seconds since the epoch */
|
||||
|
||||
CURL *easy;
|
||||
char error[CURL_ERROR_SIZE];
|
||||
@ -115,7 +118,8 @@ struct FetcherRequest {
|
||||
};
|
||||
|
||||
/* Information associated with a specific socket */
|
||||
struct SockInfo {
|
||||
struct SockInfo
|
||||
{
|
||||
guint refcount;
|
||||
curl_socket_t sockfd;
|
||||
int action;
|
||||
@ -124,7 +128,8 @@ struct SockInfo {
|
||||
OstreeFetcher *fetcher;
|
||||
};
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_CONFIG_FLAGS
|
||||
};
|
||||
@ -132,40 +137,35 @@ enum {
|
||||
G_DEFINE_TYPE (OstreeFetcher, _ostree_fetcher, G_TYPE_OBJECT)
|
||||
|
||||
static void
|
||||
_ostree_fetcher_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
OstreeFetcher *self = OSTREE_FETCHER (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONFIG_FLAGS:
|
||||
self->config_flags = g_value_get_flags (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_ostree_fetcher_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
_ostree_fetcher_set_property (GObject *object, guint prop_id, const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
OstreeFetcher *self = OSTREE_FETCHER (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONFIG_FLAGS:
|
||||
g_value_set_flags (value, self->config_flags);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
case PROP_CONFIG_FLAGS:
|
||||
self->config_flags = g_value_get_flags (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_ostree_fetcher_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
OstreeFetcher *self = OSTREE_FETCHER (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONFIG_FLAGS:
|
||||
g_value_set_flags (value, self->config_flags);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -211,23 +211,19 @@ _ostree_fetcher_class_init (OstreeFetcherClass *klass)
|
||||
gobject_class->finalize = _ostree_fetcher_finalize;
|
||||
gobject_class->constructed = _ostree_fetcher_constructed;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_CONFIG_FLAGS,
|
||||
g_param_spec_flags ("config-flags",
|
||||
"",
|
||||
"",
|
||||
OSTREE_TYPE_FETCHER_CONFIG_FLAGS,
|
||||
OSTREE_FETCHER_FLAGS_NONE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property (
|
||||
gobject_class, PROP_CONFIG_FLAGS,
|
||||
g_param_spec_flags ("config-flags", "", "", OSTREE_TYPE_FETCHER_CONFIG_FLAGS,
|
||||
OSTREE_FETCHER_FLAGS_NONE,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
static void
|
||||
_ostree_fetcher_init (OstreeFetcher *self)
|
||||
{
|
||||
self->multi = curl_multi_init();
|
||||
self->outstanding_requests = g_hash_table_new_full (NULL, NULL, (GDestroyNotify)g_object_unref, NULL);
|
||||
self->multi = curl_multi_init ();
|
||||
self->outstanding_requests
|
||||
= g_hash_table_new_full (NULL, NULL, (GDestroyNotify)g_object_unref, NULL);
|
||||
self->sockets = g_hash_table_new_full (NULL, NULL, (GDestroyNotify)sock_unref, NULL);
|
||||
curl_multi_setopt (self->multi, CURLMOPT_SOCKETFUNCTION, sock_cb);
|
||||
curl_multi_setopt (self->multi, CURLMOPT_SOCKETDATA, self);
|
||||
@ -245,11 +241,8 @@ _ostree_fetcher_init (OstreeFetcher *self)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
OstreeFetcher *
|
||||
_ostree_fetcher_new (int tmpdir_dfd,
|
||||
const char *remote_name,
|
||||
OstreeFetcherConfigFlags flags)
|
||||
_ostree_fetcher_new (int tmpdir_dfd, const char *remote_name, OstreeFetcherConfigFlags flags)
|
||||
{
|
||||
OstreeFetcher *fetcher = g_object_new (OSTREE_TYPE_FETCHER, "config-flags", flags, NULL);
|
||||
fetcher->remote_name = g_strdup (remote_name);
|
||||
@ -269,7 +262,8 @@ request_get_uri (FetcherRequest *req, GUri *baseuri)
|
||||
{
|
||||
if (!req->filename)
|
||||
return g_uri_to_string_partial (baseuri, G_URI_HIDE_PASSWORD);
|
||||
{ g_autofree char *uristr = g_uri_to_string_partial (baseuri, G_URI_HIDE_PASSWORD);
|
||||
{
|
||||
g_autofree char *uristr = g_uri_to_string_partial (baseuri, G_URI_HIDE_PASSWORD);
|
||||
return g_build_filename (uristr, req->filename, NULL);
|
||||
}
|
||||
}
|
||||
@ -279,8 +273,8 @@ ensure_tmpfile (FetcherRequest *req, GError **error)
|
||||
{
|
||||
if (!req->tmpf.initialized)
|
||||
{
|
||||
if (!_ostree_fetcher_tmpf_from_flags (req->flags, req->fetcher->tmpdir_dfd,
|
||||
&req->tmpf, error))
|
||||
if (!_ostree_fetcher_tmpf_from_flags (req->flags, req->fetcher->tmpdir_dfd, &req->tmpf,
|
||||
error))
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
@ -324,24 +318,24 @@ check_multi_info (OstreeFetcher *fetcher)
|
||||
if (is_file && curlres == CURLE_FILE_COULDNT_READ_FILE)
|
||||
{
|
||||
/* Handle file not found */
|
||||
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
||||
"%s", curl_easy_strerror (curlres));
|
||||
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "%s",
|
||||
curl_easy_strerror (curlres));
|
||||
}
|
||||
else
|
||||
{
|
||||
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"While fetching %s: [%u] %s", eff_url, curlres,
|
||||
curl_easy_strerror (curlres));
|
||||
_ostree_fetcher_journal_failure (req->fetcher->remote_name,
|
||||
eff_url, curl_easy_strerror (curlres));
|
||||
_ostree_fetcher_journal_failure (req->fetcher->remote_name, eff_url,
|
||||
curl_easy_strerror (curlres));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
curl_easy_getinfo (easy, CURLINFO_RESPONSE_CODE, &response);
|
||||
|
||||
if (!is_file && response == 304 &&
|
||||
(req->if_none_match != NULL || req->if_modified_since > 0))
|
||||
if (!is_file && response == 304
|
||||
&& (req->if_none_match != NULL || req->if_modified_since > 0))
|
||||
{
|
||||
/* Version on the server is unchanged from the version we have
|
||||
* cached locally; report this as an out-argument, a zero-length
|
||||
@ -355,15 +349,14 @@ check_multi_info (OstreeFetcher *fetcher)
|
||||
|
||||
if (req->idx + 1 == req->mirrorlist->len)
|
||||
{
|
||||
g_autofree char *response_msg = g_strdup_printf ("Server returned HTTP %lu", response);
|
||||
g_task_return_new_error (task, G_IO_ERROR, giocode,
|
||||
"%s", response_msg);
|
||||
if (req->fetcher->remote_name &&
|
||||
!((req->flags & OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT) > 0 &&
|
||||
giocode == G_IO_ERROR_NOT_FOUND))
|
||||
_ostree_fetcher_journal_failure (req->fetcher->remote_name,
|
||||
eff_url, response_msg);
|
||||
|
||||
g_autofree char *response_msg
|
||||
= g_strdup_printf ("Server returned HTTP %lu", response);
|
||||
g_task_return_new_error (task, G_IO_ERROR, giocode, "%s", response_msg);
|
||||
if (req->fetcher->remote_name
|
||||
&& !((req->flags & OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT) > 0
|
||||
&& giocode == G_IO_ERROR_NOT_FOUND))
|
||||
_ostree_fetcher_journal_failure (req->fetcher->remote_name, eff_url,
|
||||
response_msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -381,7 +374,7 @@ check_multi_info (OstreeFetcher *fetcher)
|
||||
}
|
||||
else
|
||||
{
|
||||
g_autoptr(GError) local_error = NULL;
|
||||
g_autoptr (GError) local_error = NULL;
|
||||
GError **error = &local_error;
|
||||
|
||||
if (!ensure_tmpfile (req, error))
|
||||
@ -454,9 +447,8 @@ event_cb (int fd, GIOCondition condition, gpointer data)
|
||||
{
|
||||
OstreeFetcher *fetcher = data;
|
||||
|
||||
int action =
|
||||
(condition & G_IO_IN ? CURL_CSELECT_IN : 0) |
|
||||
(condition & G_IO_OUT ? CURL_CSELECT_OUT : 0);
|
||||
int action
|
||||
= (condition & G_IO_IN ? CURL_CSELECT_IN : 0) | (condition & G_IO_OUT ? CURL_CSELECT_OUT : 0);
|
||||
|
||||
(void)curl_multi_socket_action (fetcher->multi, fd, action, &fetcher->curl_running);
|
||||
check_multi_info (fetcher);
|
||||
@ -484,10 +476,9 @@ sock_unref (SockInfo *f)
|
||||
|
||||
/* Assign information to a SockInfo structure */
|
||||
static void
|
||||
setsock (SockInfo*f, curl_socket_t s, int act, OstreeFetcher *fetcher)
|
||||
setsock (SockInfo *f, curl_socket_t s, int act, OstreeFetcher *fetcher)
|
||||
{
|
||||
GIOCondition kind =
|
||||
(act&CURL_POLL_IN?G_IO_IN:0)|(act&CURL_POLL_OUT?G_IO_OUT:0);
|
||||
GIOCondition kind = (act & CURL_POLL_IN ? G_IO_IN : 0) | (act & CURL_POLL_OUT ? G_IO_OUT : 0);
|
||||
|
||||
f->sockfd = s;
|
||||
f->action = act;
|
||||
@ -496,7 +487,7 @@ setsock (SockInfo*f, curl_socket_t s, int act, OstreeFetcher *fetcher)
|
||||
* flags involves less allocation.
|
||||
*/
|
||||
f->ch = g_unix_fd_source_new (f->sockfd, kind);
|
||||
g_source_set_callback (f->ch, (GSourceFunc) event_cb, fetcher, NULL);
|
||||
g_source_set_callback (f->ch, (GSourceFunc)event_cb, fetcher, NULL);
|
||||
g_source_attach (f->ch, fetcher->mainctx);
|
||||
}
|
||||
|
||||
@ -518,7 +509,7 @@ static int
|
||||
sock_cb (CURL *easy, curl_socket_t s, int what, void *cbp, void *sockp)
|
||||
{
|
||||
OstreeFetcher *fetcher = cbp;
|
||||
SockInfo *fdp = (SockInfo*) sockp;
|
||||
SockInfo *fdp = (SockInfo *)sockp;
|
||||
|
||||
if (what == CURL_POLL_REMOVE)
|
||||
{
|
||||
@ -554,14 +545,14 @@ write_cb (void *ptr, size_t size, size_t nmemb, void *data)
|
||||
|
||||
if (req->max_size > 0)
|
||||
{
|
||||
if (realsize > req->max_size ||
|
||||
(realsize + req->current_size) > req->max_size)
|
||||
if (realsize > req->max_size || (realsize + req->current_size) > req->max_size)
|
||||
{
|
||||
const char *eff_url;
|
||||
curl_easy_getinfo (req->easy, CURLINFO_EFFECTIVE_URL, &eff_url);
|
||||
req->caught_write_error = g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"URI %s exceeded maximum size of %" G_GUINT64_FORMAT " bytes",
|
||||
eff_url, req->max_size);
|
||||
req->caught_write_error
|
||||
= g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"URI %s exceeded maximum size of %" G_GUINT64_FORMAT " bytes", eff_url,
|
||||
req->max_size);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -603,17 +594,17 @@ response_header_cb (const char *buffer, size_t size, size_t n_items, void *user_
|
||||
const char *etag_header = "ETag: ";
|
||||
const char *last_modified_header = "Last-Modified: ";
|
||||
|
||||
if (real_size > strlen (etag_header) &&
|
||||
strncasecmp (buffer, etag_header, strlen (etag_header)) == 0)
|
||||
if (real_size > strlen (etag_header)
|
||||
&& strncasecmp (buffer, etag_header, strlen (etag_header)) == 0)
|
||||
{
|
||||
g_clear_pointer (&req->out_etag, g_free);
|
||||
req->out_etag = g_strstrip (g_strdup (buffer + strlen (etag_header)));
|
||||
}
|
||||
else if (real_size > strlen (last_modified_header) &&
|
||||
strncasecmp (buffer, last_modified_header, strlen (last_modified_header)) == 0)
|
||||
else if (real_size > strlen (last_modified_header)
|
||||
&& strncasecmp (buffer, last_modified_header, strlen (last_modified_header)) == 0)
|
||||
{
|
||||
g_autofree char *lm_buf = g_strstrip (g_strdup (buffer + strlen (last_modified_header)));
|
||||
g_autoptr(GDateTime) dt = _ostree_parse_rfc2616_date_time (lm_buf, strlen (lm_buf));
|
||||
g_autoptr (GDateTime) dt = _ostree_parse_rfc2616_date_time (lm_buf, strlen (lm_buf));
|
||||
req->out_last_modified = (dt != NULL) ? g_date_time_to_unix (dt) : 0;
|
||||
}
|
||||
|
||||
@ -660,28 +651,23 @@ _ostree_fetcher_get_dfd (OstreeFetcher *fetcher)
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_fetcher_set_proxy (OstreeFetcher *self,
|
||||
const char *http_proxy)
|
||||
_ostree_fetcher_set_proxy (OstreeFetcher *self, const char *http_proxy)
|
||||
{
|
||||
g_free (self->proxy);
|
||||
self->proxy = g_strdup (http_proxy);
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_fetcher_set_cookie_jar (OstreeFetcher *self,
|
||||
const char *jar_path)
|
||||
_ostree_fetcher_set_cookie_jar (OstreeFetcher *self, const char *jar_path)
|
||||
{
|
||||
g_free (self->cookie_jar_path);
|
||||
self->cookie_jar_path = g_strdup (jar_path);
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_fetcher_set_client_cert (OstreeFetcher *self,
|
||||
const char *cert_path,
|
||||
const char *key_path)
|
||||
_ostree_fetcher_set_client_cert (OstreeFetcher *self, const char *cert_path, const char *key_path)
|
||||
{
|
||||
g_assert ((cert_path == NULL && key_path == NULL)
|
||||
|| (cert_path != NULL && key_path != NULL));
|
||||
g_assert ((cert_path == NULL && key_path == NULL) || (cert_path != NULL && key_path != NULL));
|
||||
g_free (self->tls_client_cert_path);
|
||||
self->tls_client_cert_path = g_strdup (cert_path);
|
||||
g_free (self->tls_client_key_path);
|
||||
@ -689,16 +675,14 @@ _ostree_fetcher_set_client_cert (OstreeFetcher *self,
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_fetcher_set_tls_database (OstreeFetcher *self,
|
||||
const char *dbpath)
|
||||
_ostree_fetcher_set_tls_database (OstreeFetcher *self, const char *dbpath)
|
||||
{
|
||||
g_free (self->tls_ca_db_path);
|
||||
self->tls_ca_db_path = g_strdup (dbpath);
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_fetcher_set_extra_headers (OstreeFetcher *self,
|
||||
GVariant *extra_headers)
|
||||
_ostree_fetcher_set_extra_headers (OstreeFetcher *self, GVariant *extra_headers)
|
||||
{
|
||||
GVariantIter viter;
|
||||
const char *key;
|
||||
@ -715,21 +699,19 @@ _ostree_fetcher_set_extra_headers (OstreeFetcher *self,
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_fetcher_set_extra_user_agent (OstreeFetcher *self,
|
||||
const char *extra_user_agent)
|
||||
_ostree_fetcher_set_extra_user_agent (OstreeFetcher *self, const char *extra_user_agent)
|
||||
{
|
||||
g_clear_pointer (&self->custom_user_agent, g_free);
|
||||
if (extra_user_agent)
|
||||
{
|
||||
self->custom_user_agent =
|
||||
g_strdup_printf ("%s %s", OSTREE_FETCHER_USERAGENT_STRING, extra_user_agent);
|
||||
self->custom_user_agent
|
||||
= g_strdup_printf ("%s %s", OSTREE_FETCHER_USERAGENT_STRING, extra_user_agent);
|
||||
}
|
||||
}
|
||||
|
||||
/* Re-bind all of the outstanding curl items to our new main context */
|
||||
static void
|
||||
adopt_steal_mainctx (OstreeFetcher *self,
|
||||
GMainContext *mainctx)
|
||||
adopt_steal_mainctx (OstreeFetcher *self, GMainContext *mainctx)
|
||||
{
|
||||
g_assert (self->mainctx == NULL);
|
||||
self->mainctx = mainctx; /* Transfer */
|
||||
@ -744,13 +726,12 @@ adopt_steal_mainctx (OstreeFetcher *self,
|
||||
update_timeout_cb (self->multi, timeout_micros / 1000, self);
|
||||
}
|
||||
|
||||
GLNX_HASH_TABLE_FOREACH (self->sockets, SockInfo*, fdp)
|
||||
GLNX_HASH_TABLE_FOREACH (self->sockets, SockInfo *, fdp)
|
||||
setsock (fdp, fdp->sockfd, fdp->action, self);
|
||||
}
|
||||
|
||||
static void
|
||||
initiate_next_curl_request (FetcherRequest *req,
|
||||
GTask *task)
|
||||
initiate_next_curl_request (FetcherRequest *req, GTask *task)
|
||||
{
|
||||
CURLcode rc;
|
||||
OstreeFetcher *self = req->fetcher;
|
||||
@ -763,13 +744,14 @@ initiate_next_curl_request (FetcherRequest *req,
|
||||
g_assert_cmpint (req->idx, <, req->mirrorlist->len);
|
||||
|
||||
GUri *baseuri = req->mirrorlist->pdata[req->idx];
|
||||
{ g_autofree char *uri = request_get_uri (req, baseuri);
|
||||
{
|
||||
g_autofree char *uri = request_get_uri (req, baseuri);
|
||||
rc = curl_easy_setopt (req->easy, CURLOPT_URL, uri);
|
||||
g_assert_cmpint (rc, ==, CURLM_OK);
|
||||
}
|
||||
|
||||
rc = curl_easy_setopt (req->easy, CURLOPT_USERAGENT,
|
||||
self->custom_user_agent ?: OSTREE_FETCHER_USERAGENT_STRING);
|
||||
self->custom_user_agent ?: OSTREE_FETCHER_USERAGENT_STRING);
|
||||
g_assert_cmpint (rc, ==, CURLM_OK);
|
||||
|
||||
/* Set caching request headers */
|
||||
@ -781,8 +763,9 @@ initiate_next_curl_request (FetcherRequest *req,
|
||||
|
||||
if (req->if_modified_since > 0)
|
||||
{
|
||||
g_autoptr(GDateTime) date_time = g_date_time_new_from_unix_utc (req->if_modified_since);
|
||||
g_autofree char *mod_date = g_date_time_format (date_time, "If-Modified-Since: %a, %d %b %Y %H:%M:%S %Z");
|
||||
g_autoptr (GDateTime) date_time = g_date_time_new_from_unix_utc (req->if_modified_since);
|
||||
g_autofree char *mod_date
|
||||
= g_date_time_format (date_time, "If-Modified-Since: %a, %d %b %Y %H:%M:%S %Z");
|
||||
|
||||
req->req_headers = curl_slist_append (req->req_headers, mod_date);
|
||||
}
|
||||
@ -818,7 +801,6 @@ initiate_next_curl_request (FetcherRequest *req,
|
||||
g_assert_cmpint (rc, ==, CURLM_OK);
|
||||
}
|
||||
|
||||
|
||||
if ((self->config_flags & OSTREE_FETCHER_FLAGS_TLS_PERMISSIVE) > 0)
|
||||
{
|
||||
rc = curl_easy_setopt (req->easy, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
@ -873,7 +855,8 @@ initiate_next_curl_request (FetcherRequest *req,
|
||||
g_assert_cmpint (rc, ==, CURLM_OK);
|
||||
|
||||
/* We should only speak HTTP; TODO: only enable file if specified */
|
||||
rc = curl_easy_setopt (req->easy, CURLOPT_PROTOCOLS, (long)(CURLPROTO_HTTP | CURLPROTO_HTTPS | CURLPROTO_FILE));
|
||||
rc = curl_easy_setopt (req->easy, CURLOPT_PROTOCOLS,
|
||||
(long)(CURLPROTO_HTTP | CURLPROTO_HTTPS | CURLPROTO_FILE));
|
||||
g_assert_cmpint (rc, ==, CURLM_OK);
|
||||
/* Picked the current version in F25 as of 20170127, since
|
||||
* there are numerous HTTP/2 fixes since the original version in
|
||||
@ -882,12 +865,13 @@ initiate_next_curl_request (FetcherRequest *req,
|
||||
if (!(self->config_flags & OSTREE_FETCHER_FLAGS_DISABLE_HTTP2))
|
||||
{
|
||||
#if CURL_AT_LEAST_VERSION(7, 51, 0)
|
||||
if ((curl_version_info (CURLVERSION_NOW))->features & CURL_VERSION_HTTP2) {
|
||||
rc = curl_easy_setopt (req->easy, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
|
||||
g_assert_cmpint (rc, ==, CURLM_OK);
|
||||
}
|
||||
if ((curl_version_info (CURLVERSION_NOW))->features & CURL_VERSION_HTTP2)
|
||||
{
|
||||
rc = curl_easy_setopt (req->easy, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
|
||||
g_assert_cmpint (rc, ==, CURLM_OK);
|
||||
}
|
||||
#endif
|
||||
/* https://github.com/curl/curl/blob/curl-7_53_0/docs/examples/http2-download.c */
|
||||
/* https://github.com/curl/curl/blob/curl-7_53_0/docs/examples/http2-download.c */
|
||||
#if (CURLPIPE_MULTIPLEX > 0)
|
||||
/* wait for pipe connection to confirm */
|
||||
rc = curl_easy_setopt (req->easy, CURLOPT_PIPEWAIT, 1L);
|
||||
@ -938,29 +922,21 @@ initiate_next_curl_request (FetcherRequest *req,
|
||||
}
|
||||
|
||||
static void
|
||||
_ostree_fetcher_request_async (OstreeFetcher *self,
|
||||
GPtrArray *mirrorlist,
|
||||
const char *filename,
|
||||
OstreeFetcherRequestFlags flags,
|
||||
const char *if_none_match,
|
||||
guint64 if_modified_since,
|
||||
gboolean is_membuf,
|
||||
guint64 max_size,
|
||||
int priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
_ostree_fetcher_request_async (OstreeFetcher *self, GPtrArray *mirrorlist, const char *filename,
|
||||
OstreeFetcherRequestFlags flags, const char *if_none_match,
|
||||
guint64 if_modified_since, gboolean is_membuf, guint64 max_size,
|
||||
int priority, GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback, gpointer user_data)
|
||||
{
|
||||
g_autoptr(GTask) task = NULL;
|
||||
g_autoptr (GTask) task = NULL;
|
||||
FetcherRequest *req;
|
||||
g_autoptr(GMainContext) mainctx = g_main_context_ref_thread_default ();
|
||||
g_autoptr (GMainContext) mainctx = g_main_context_ref_thread_default ();
|
||||
|
||||
/* We don't support multiple concurrent main contexts; take
|
||||
* a ref to the first one, and require that later invocations
|
||||
* share it.
|
||||
*/
|
||||
if (g_hash_table_size (self->outstanding_requests) == 0
|
||||
&& mainctx != self->mainctx)
|
||||
if (g_hash_table_size (self->outstanding_requests) == 0 && mainctx != self->mainctx)
|
||||
{
|
||||
adopt_steal_mainctx (self, g_steal_pointer (&mainctx));
|
||||
}
|
||||
@ -971,7 +947,7 @@ _ostree_fetcher_request_async (OstreeFetcher *self,
|
||||
|
||||
req = g_new0 (FetcherRequest, 1);
|
||||
req->refcount = 1;
|
||||
req->error[0]='\0';
|
||||
req->error[0] = '\0';
|
||||
req->fetcher = self;
|
||||
req->mirrorlist = g_ptr_array_ref (mirrorlist);
|
||||
req->filename = g_strdup (filename);
|
||||
@ -990,7 +966,7 @@ _ostree_fetcher_request_async (OstreeFetcher *self,
|
||||
/* We'll use the GTask priority for our own priority queue. */
|
||||
g_task_set_priority (task, priority);
|
||||
g_task_set_source_tag (task, _ostree_fetcher_request_async);
|
||||
g_task_set_task_data (task, req, (GDestroyNotify) request_unref);
|
||||
g_task_set_task_data (task, req, (GDestroyNotify)request_unref);
|
||||
|
||||
initiate_next_curl_request (req, task);
|
||||
|
||||
@ -998,37 +974,27 @@ _ostree_fetcher_request_async (OstreeFetcher *self,
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_fetcher_request_to_tmpfile (OstreeFetcher *self,
|
||||
GPtrArray *mirrorlist,
|
||||
const char *filename,
|
||||
OstreeFetcherRequestFlags flags,
|
||||
const char *if_none_match,
|
||||
guint64 if_modified_since,
|
||||
guint64 max_size,
|
||||
int priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
_ostree_fetcher_request_to_tmpfile (OstreeFetcher *self, GPtrArray *mirrorlist,
|
||||
const char *filename, OstreeFetcherRequestFlags flags,
|
||||
const char *if_none_match, guint64 if_modified_since,
|
||||
guint64 max_size, int priority, GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback, gpointer user_data)
|
||||
{
|
||||
_ostree_fetcher_request_async (self, mirrorlist, filename, flags,
|
||||
if_none_match, if_modified_since, FALSE,
|
||||
max_size, priority, cancellable,
|
||||
_ostree_fetcher_request_async (self, mirrorlist, filename, flags, if_none_match,
|
||||
if_modified_since, FALSE, max_size, priority, cancellable,
|
||||
callback, user_data);
|
||||
}
|
||||
|
||||
gboolean
|
||||
_ostree_fetcher_request_to_tmpfile_finish (OstreeFetcher *self,
|
||||
GAsyncResult *result,
|
||||
GLnxTmpfile *out_tmpf,
|
||||
gboolean *out_not_modified,
|
||||
char **out_etag,
|
||||
guint64 *out_last_modified,
|
||||
GError **error)
|
||||
_ostree_fetcher_request_to_tmpfile_finish (OstreeFetcher *self, GAsyncResult *result,
|
||||
GLnxTmpfile *out_tmpf, gboolean *out_not_modified,
|
||||
char **out_etag, guint64 *out_last_modified,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (g_task_is_valid (result, self), FALSE);
|
||||
g_return_val_if_fail (g_async_result_is_tagged (result, _ostree_fetcher_request_async), FALSE);
|
||||
|
||||
GTask *task = (GTask*)result;
|
||||
GTask *task = (GTask *)result;
|
||||
FetcherRequest *req = g_task_get_task_data (task);
|
||||
|
||||
if (!g_task_propagate_boolean (task, error))
|
||||
@ -1049,32 +1015,22 @@ _ostree_fetcher_request_to_tmpfile_finish (OstreeFetcher *self,
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_fetcher_request_to_membuf (OstreeFetcher *self,
|
||||
GPtrArray *mirrorlist,
|
||||
const char *filename,
|
||||
OstreeFetcherRequestFlags flags,
|
||||
const char *if_none_match,
|
||||
guint64 if_modified_since,
|
||||
guint64 max_size,
|
||||
int priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
_ostree_fetcher_request_to_membuf (OstreeFetcher *self, GPtrArray *mirrorlist, const char *filename,
|
||||
OstreeFetcherRequestFlags flags, const char *if_none_match,
|
||||
guint64 if_modified_since, guint64 max_size, int priority,
|
||||
GCancellable *cancellable, GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
_ostree_fetcher_request_async (self, mirrorlist, filename, flags,
|
||||
if_none_match, if_modified_since, TRUE,
|
||||
max_size, priority, cancellable,
|
||||
callback, user_data);
|
||||
_ostree_fetcher_request_async (self, mirrorlist, filename, flags, if_none_match,
|
||||
if_modified_since, TRUE, max_size, priority, cancellable, callback,
|
||||
user_data);
|
||||
}
|
||||
|
||||
gboolean
|
||||
_ostree_fetcher_request_to_membuf_finish (OstreeFetcher *self,
|
||||
GAsyncResult *result,
|
||||
GBytes **out_buf,
|
||||
gboolean *out_not_modified,
|
||||
char **out_etag,
|
||||
guint64 *out_last_modified,
|
||||
GError **error)
|
||||
_ostree_fetcher_request_to_membuf_finish (OstreeFetcher *self, GAsyncResult *result,
|
||||
GBytes **out_buf, gboolean *out_not_modified,
|
||||
char **out_etag, guint64 *out_last_modified,
|
||||
GError **error)
|
||||
{
|
||||
GTask *task;
|
||||
FetcherRequest *req;
|
||||
@ -1083,7 +1039,7 @@ _ostree_fetcher_request_to_membuf_finish (OstreeFetcher *self,
|
||||
g_return_val_if_fail (g_task_is_valid (result, self), FALSE);
|
||||
g_return_val_if_fail (g_async_result_is_tagged (result, _ostree_fetcher_request_async), FALSE);
|
||||
|
||||
task = (GTask*)result;
|
||||
task = (GTask *)result;
|
||||
req = g_task_get_task_data (task);
|
||||
|
||||
ret = g_task_propagate_pointer (task, error);
|
||||
@ -1105,7 +1061,7 @@ _ostree_fetcher_request_to_membuf_finish (OstreeFetcher *self,
|
||||
}
|
||||
|
||||
guint64
|
||||
_ostree_fetcher_bytes_transferred (OstreeFetcher *self)
|
||||
_ostree_fetcher_bytes_transferred (OstreeFetcher *self)
|
||||
{
|
||||
return self->bytes_transferred;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -30,15 +30,16 @@
|
||||
#include <libsoup/soup.h>
|
||||
|
||||
#include "libglnx.h"
|
||||
#include "ostree-fetcher.h"
|
||||
#include "ostree-fetcher-util.h"
|
||||
#include "ostree-tls-cert-interaction-private.h"
|
||||
#include "ostree-enumtypes.h"
|
||||
#include "ostree-fetcher-util.h"
|
||||
#include "ostree-fetcher.h"
|
||||
#include "ostree-repo-private.h"
|
||||
#include "ostree-tls-cert-interaction-private.h"
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
GPtrArray *mirrorlist; /* list of base URIs */
|
||||
char *filename; /* relative name to fetch or NULL */
|
||||
char *filename; /* relative name to fetch or NULL */
|
||||
guint mirrorlist_idx;
|
||||
|
||||
SoupMessage *message;
|
||||
@ -49,14 +50,15 @@ typedef struct {
|
||||
|
||||
gboolean is_membuf;
|
||||
OstreeFetcherRequestFlags flags;
|
||||
char *if_none_match; /* request ETag */
|
||||
guint64 if_modified_since; /* seconds since the epoch */
|
||||
char *if_none_match; /* request ETag */
|
||||
guint64 if_modified_since; /* seconds since the epoch */
|
||||
GInputStream *response_body;
|
||||
GLnxTmpfile tmpf;
|
||||
GOutputStream *out_stream;
|
||||
gboolean out_not_modified; /* TRUE if the server gave a HTTP 304 Not Modified response, which we don’t propagate as an error */
|
||||
char *out_etag; /* response ETag */
|
||||
guint64 out_last_modified; /* response Last-Modified, seconds since the epoch */
|
||||
gboolean out_not_modified; /* TRUE if the server gave a HTTP 304 Not Modified response, which we
|
||||
don’t propagate as an error */
|
||||
char *out_etag; /* response ETag */
|
||||
guint64 out_last_modified; /* response Last-Modified, seconds since the epoch */
|
||||
|
||||
guint64 max_size;
|
||||
guint64 current_size;
|
||||
@ -82,7 +84,8 @@ struct OstreeFetcher
|
||||
guint64 bytes_transferred;
|
||||
};
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_CONFIG_FLAGS
|
||||
};
|
||||
@ -107,16 +110,11 @@ fetcher_request_free (FetcherRequest *request)
|
||||
g_free (request);
|
||||
}
|
||||
|
||||
static void
|
||||
on_request_sent (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data);
|
||||
static void on_request_sent (GObject *object, GAsyncResult *result, gpointer user_data);
|
||||
|
||||
static gboolean
|
||||
_message_accept_cert_loose (SoupMessage *msg,
|
||||
GTlsCertificate *tls_peer_certificate,
|
||||
GTlsCertificateFlags tls_peer_errors,
|
||||
gpointer data)
|
||||
_message_accept_cert_loose (SoupMessage *msg, GTlsCertificate *tls_peer_certificate,
|
||||
GTlsCertificateFlags tls_peer_errors, gpointer data)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
@ -128,17 +126,17 @@ create_request_message (FetcherRequest *request)
|
||||
g_assert (request->mirrorlist_idx < request->mirrorlist->len);
|
||||
|
||||
OstreeFetcherURI *next_mirror = g_ptr_array_index (request->mirrorlist, request->mirrorlist_idx);
|
||||
g_autoptr(OstreeFetcherURI) uri = NULL;
|
||||
g_autoptr (OstreeFetcherURI) uri = NULL;
|
||||
if (request->filename)
|
||||
uri = _ostree_fetcher_uri_new_subpath (next_mirror, request->filename);
|
||||
if (!uri)
|
||||
uri = (OstreeFetcherURI *) g_uri_ref ((GUri *) next_mirror);
|
||||
uri = (OstreeFetcherURI *)g_uri_ref ((GUri *)next_mirror);
|
||||
|
||||
g_clear_object (&request->message);
|
||||
g_clear_object (&request->file);
|
||||
g_clear_object (&request->response_body);
|
||||
|
||||
GUri *guri = (GUri *) uri;
|
||||
GUri *guri = (GUri *)uri;
|
||||
|
||||
/* file:// URI is handle via GFile */
|
||||
if (!strcmp (g_uri_get_scheme (guri), "file"))
|
||||
@ -156,7 +154,7 @@ create_request_message (FetcherRequest *request)
|
||||
|
||||
if (request->if_modified_since > 0)
|
||||
{
|
||||
g_autoptr(GDateTime) date_time = g_date_time_new_from_unix_utc (request->if_modified_since);
|
||||
g_autoptr (GDateTime) date_time = g_date_time_new_from_unix_utc (request->if_modified_since);
|
||||
g_autofree char *mod_date = g_date_time_format (date_time, "%a, %d %b %Y %H:%M:%S %Z");
|
||||
soup_message_headers_append (soup_message_get_request_headers (request->message),
|
||||
"If-Modified-Since", mod_date);
|
||||
@ -168,12 +166,13 @@ create_request_message (FetcherRequest *request)
|
||||
|
||||
if (request->fetcher->extra_headers)
|
||||
{
|
||||
g_autoptr(GVariantIter) viter = g_variant_iter_new (request->fetcher->extra_headers);
|
||||
g_autoptr (GVariantIter) viter = g_variant_iter_new (request->fetcher->extra_headers);
|
||||
const char *key;
|
||||
const char *value;
|
||||
|
||||
while (g_variant_iter_next (viter, "(&s&s)", &key, &value))
|
||||
soup_message_headers_append (soup_message_get_request_headers (request->message), key, value);
|
||||
soup_message_headers_append (soup_message_get_request_headers (request->message), key,
|
||||
value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,48 +190,43 @@ initiate_task_request (GTask *task)
|
||||
{
|
||||
g_autofree char *uri = g_uri_to_string (soup_message_get_uri (request->message));
|
||||
const char *dest = request->is_membuf ? "memory" : "tmpfile";
|
||||
g_debug ("Requesting %s to %s for session %p in main context %p",
|
||||
uri, dest, request->session, request->mainctx);
|
||||
soup_session_send_async (request->session, request->message,
|
||||
priority, cancellable, on_request_sent, task);
|
||||
g_debug ("Requesting %s to %s for session %p in main context %p", uri, dest, request->session,
|
||||
request->mainctx);
|
||||
soup_session_send_async (request->session, request->message, priority, cancellable,
|
||||
on_request_sent, task);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_ostree_fetcher_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
OstreeFetcher *self = OSTREE_FETCHER (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONFIG_FLAGS:
|
||||
self->config_flags = g_value_get_flags (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_ostree_fetcher_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
_ostree_fetcher_set_property (GObject *object, guint prop_id, const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
OstreeFetcher *self = OSTREE_FETCHER (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONFIG_FLAGS:
|
||||
g_value_set_flags (value, self->config_flags);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
case PROP_CONFIG_FLAGS:
|
||||
self->config_flags = g_value_get_flags (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_ostree_fetcher_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
OstreeFetcher *self = OSTREE_FETCHER (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONFIG_FLAGS:
|
||||
g_value_set_flags (value, self->config_flags);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -275,16 +269,11 @@ _ostree_fetcher_class_init (OstreeFetcherClass *klass)
|
||||
gobject_class->finalize = _ostree_fetcher_finalize;
|
||||
gobject_class->constructed = _ostree_fetcher_constructed;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_CONFIG_FLAGS,
|
||||
g_param_spec_flags ("config-flags",
|
||||
"",
|
||||
"",
|
||||
OSTREE_TYPE_FETCHER_CONFIG_FLAGS,
|
||||
OSTREE_FETCHER_FLAGS_NONE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property (
|
||||
gobject_class, PROP_CONFIG_FLAGS,
|
||||
g_param_spec_flags ("config-flags", "", "", OSTREE_TYPE_FETCHER_CONFIG_FLAGS,
|
||||
OSTREE_FETCHER_FLAGS_NONE,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -294,9 +283,7 @@ _ostree_fetcher_init (OstreeFetcher *self)
|
||||
}
|
||||
|
||||
OstreeFetcher *
|
||||
_ostree_fetcher_new (int tmpdir_dfd,
|
||||
const char *remote_name,
|
||||
OstreeFetcherConfigFlags flags)
|
||||
_ostree_fetcher_new (int tmpdir_dfd, const char *remote_name, OstreeFetcherConfigFlags flags)
|
||||
{
|
||||
OstreeFetcher *self = g_object_new (OSTREE_TYPE_FETCHER, "config-flags", flags, NULL);
|
||||
self->remote_name = g_strdup (remote_name);
|
||||
@ -312,15 +299,14 @@ _ostree_fetcher_get_dfd (OstreeFetcher *self)
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_fetcher_set_proxy (OstreeFetcher *self,
|
||||
const char *http_proxy)
|
||||
_ostree_fetcher_set_proxy (OstreeFetcher *self, const char *http_proxy)
|
||||
{
|
||||
g_return_if_fail (OSTREE_IS_FETCHER (self));
|
||||
g_return_if_fail (http_proxy != NULL && http_proxy[0] != '\0');
|
||||
|
||||
/* validate first */
|
||||
g_autoptr(GError) local_error = NULL;
|
||||
g_autoptr(GUri) guri = g_uri_parse (http_proxy, G_URI_FLAGS_NONE, &local_error);
|
||||
g_autoptr (GError) local_error = NULL;
|
||||
g_autoptr (GUri) guri = g_uri_parse (http_proxy, G_URI_FLAGS_NONE, &local_error);
|
||||
if (guri == NULL)
|
||||
{
|
||||
g_warning ("Invalid proxy URI '%s': %s", http_proxy, local_error->message);
|
||||
@ -332,8 +318,7 @@ _ostree_fetcher_set_proxy (OstreeFetcher *self,
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_fetcher_set_cookie_jar (OstreeFetcher *self,
|
||||
const char *jar_path)
|
||||
_ostree_fetcher_set_cookie_jar (OstreeFetcher *self, const char *jar_path)
|
||||
{
|
||||
g_return_if_fail (OSTREE_IS_FETCHER (self));
|
||||
g_return_if_fail (jar_path != NULL);
|
||||
@ -343,9 +328,7 @@ _ostree_fetcher_set_cookie_jar (OstreeFetcher *self,
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_fetcher_set_client_cert (OstreeFetcher *self,
|
||||
const char *cert_path,
|
||||
const char *key_path)
|
||||
_ostree_fetcher_set_client_cert (OstreeFetcher *self, const char *cert_path, const char *key_path)
|
||||
{
|
||||
g_return_if_fail (OSTREE_IS_FETCHER (self));
|
||||
|
||||
@ -354,12 +337,11 @@ _ostree_fetcher_set_client_cert (OstreeFetcher *self,
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_fetcher_set_tls_database (OstreeFetcher *self,
|
||||
const char *tlsdb_path)
|
||||
_ostree_fetcher_set_tls_database (OstreeFetcher *self, const char *tlsdb_path)
|
||||
{
|
||||
g_return_if_fail (OSTREE_IS_FETCHER (self));
|
||||
|
||||
g_autoptr(GError) local_error = NULL;
|
||||
g_autoptr (GError) local_error = NULL;
|
||||
GTlsDatabase *tlsdb = g_tls_file_database_new (tlsdb_path, &local_error);
|
||||
if (tlsdb == NULL)
|
||||
{
|
||||
@ -372,8 +354,7 @@ _ostree_fetcher_set_tls_database (OstreeFetcher *self,
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_fetcher_set_extra_headers (OstreeFetcher *self,
|
||||
GVariant *extra_headers)
|
||||
_ostree_fetcher_set_extra_headers (OstreeFetcher *self, GVariant *extra_headers)
|
||||
{
|
||||
g_return_if_fail (OSTREE_IS_FETCHER (self));
|
||||
|
||||
@ -382,22 +363,17 @@ _ostree_fetcher_set_extra_headers (OstreeFetcher *self,
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_fetcher_set_extra_user_agent (OstreeFetcher *self,
|
||||
const char *extra_user_agent)
|
||||
_ostree_fetcher_set_extra_user_agent (OstreeFetcher *self, const char *extra_user_agent)
|
||||
{
|
||||
g_return_if_fail (OSTREE_IS_FETCHER (self));
|
||||
|
||||
g_clear_pointer (&self->user_agent, g_free);
|
||||
if (extra_user_agent != NULL)
|
||||
self->user_agent = g_strdup_printf ("%s %s",
|
||||
OSTREE_FETCHER_USERAGENT_STRING,
|
||||
extra_user_agent);
|
||||
self->user_agent = g_strdup_printf ("%s %s", OSTREE_FETCHER_USERAGENT_STRING, extra_user_agent);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
finish_stream (FetcherRequest *request,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
finish_stream (FetcherRequest *request, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
/* Close it here since we do an async fstat(), where we don't want
|
||||
* to hit a bad fd.
|
||||
@ -408,8 +384,8 @@ finish_stream (FetcherRequest *request,
|
||||
{
|
||||
const guint8 nulchar = 0;
|
||||
|
||||
if (!g_output_stream_write_all (request->out_stream, &nulchar, 1, NULL,
|
||||
cancellable, error))
|
||||
if (!g_output_stream_write_all (request->out_stream, &nulchar, 1, NULL, cancellable,
|
||||
error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -434,20 +410,16 @@ finish_stream (FetcherRequest *request,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
on_stream_read (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data);
|
||||
static void on_stream_read (GObject *object, GAsyncResult *result, gpointer user_data);
|
||||
|
||||
static void
|
||||
on_out_splice_complete (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
on_out_splice_complete (GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
g_autoptr(GTask) task = G_TASK (user_data);
|
||||
g_autoptr (GTask) task = G_TASK (user_data);
|
||||
GError *local_error = NULL;
|
||||
|
||||
gssize bytes_written = g_output_stream_splice_finish ((GOutputStream *) object, result, &local_error);
|
||||
gssize bytes_written
|
||||
= g_output_stream_splice_finish ((GOutputStream *)object, result, &local_error);
|
||||
if (bytes_written < 0)
|
||||
{
|
||||
g_task_return_error (task, local_error);
|
||||
@ -458,19 +430,14 @@ on_out_splice_complete (GObject *object,
|
||||
request->fetcher->bytes_transferred += bytes_written;
|
||||
|
||||
GCancellable *cancellable = g_task_get_cancellable (task);
|
||||
g_input_stream_read_bytes_async (request->response_body,
|
||||
8192, G_PRIORITY_DEFAULT,
|
||||
cancellable,
|
||||
on_stream_read,
|
||||
g_object_ref (task));
|
||||
g_input_stream_read_bytes_async (request->response_body, 8192, G_PRIORITY_DEFAULT, cancellable,
|
||||
on_stream_read, g_object_ref (task));
|
||||
}
|
||||
|
||||
static void
|
||||
on_stream_read (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
on_stream_read (GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
g_autoptr(GTask) task = G_TASK (user_data);
|
||||
g_autoptr (GTask) task = G_TASK (user_data);
|
||||
FetcherRequest *request = g_task_get_task_data (task);
|
||||
GError *local_error = NULL;
|
||||
|
||||
@ -496,7 +463,8 @@ on_stream_read (GObject *object,
|
||||
}
|
||||
|
||||
/* Get a GBytes buffer */
|
||||
g_autoptr(GBytes) bytes = g_input_stream_read_bytes_finish ((GInputStream *) object, result, &local_error);
|
||||
g_autoptr (GBytes) bytes
|
||||
= g_input_stream_read_bytes_finish ((GInputStream *)object, result, &local_error);
|
||||
if (!bytes)
|
||||
{
|
||||
g_task_return_error (task, local_error);
|
||||
@ -515,8 +483,9 @@ on_stream_read (GObject *object,
|
||||
}
|
||||
if (request->is_membuf)
|
||||
{
|
||||
GBytes *mem_bytes = g_memory_output_stream_steal_as_bytes ((GMemoryOutputStream *) request->out_stream);
|
||||
g_task_return_pointer (task, mem_bytes, (GDestroyNotify) g_bytes_unref);
|
||||
GBytes *mem_bytes
|
||||
= g_memory_output_stream_steal_as_bytes ((GMemoryOutputStream *)request->out_stream);
|
||||
g_task_return_pointer (task, mem_bytes, (GDestroyNotify)g_bytes_unref);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -535,8 +504,8 @@ on_stream_read (GObject *object,
|
||||
/* Verify max size */
|
||||
if (request->max_size > 0)
|
||||
{
|
||||
if (bytes_read > request->max_size ||
|
||||
(bytes_read + request->current_size) > request->max_size)
|
||||
if (bytes_read > request->max_size
|
||||
|| (bytes_read + request->current_size) > request->max_size)
|
||||
{
|
||||
g_autofree char *uristr = NULL;
|
||||
|
||||
@ -545,9 +514,10 @@ on_stream_read (GObject *object,
|
||||
else
|
||||
uristr = g_uri_to_string (soup_message_get_uri (request->message));
|
||||
|
||||
local_error = g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"URI %s exceeded maximum size of %" G_GUINT64_FORMAT " bytes",
|
||||
uristr, request->max_size);
|
||||
local_error
|
||||
= g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"URI %s exceeded maximum size of %" G_GUINT64_FORMAT " bytes",
|
||||
uristr, request->max_size);
|
||||
g_task_return_error (task, local_error);
|
||||
return;
|
||||
}
|
||||
@ -559,34 +529,26 @@ on_stream_read (GObject *object,
|
||||
* guaranteed to do a complete write.
|
||||
*/
|
||||
{
|
||||
g_autoptr(GInputStream) membuf =
|
||||
g_memory_input_stream_new_from_bytes (bytes);
|
||||
g_autoptr (GInputStream) membuf = g_memory_input_stream_new_from_bytes (bytes);
|
||||
g_output_stream_splice_async (request->out_stream, membuf,
|
||||
G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE,
|
||||
G_PRIORITY_DEFAULT,
|
||||
cancellable,
|
||||
on_out_splice_complete,
|
||||
g_object_ref (task));
|
||||
G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE, G_PRIORITY_DEFAULT,
|
||||
cancellable, on_out_splice_complete, g_object_ref (task));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_request_sent (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
on_request_sent (GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
g_autoptr(GTask) task = G_TASK (user_data);
|
||||
g_autoptr (GTask) task = G_TASK (user_data);
|
||||
FetcherRequest *request = g_task_get_task_data (task);
|
||||
GError *local_error = NULL;
|
||||
|
||||
if (request->file)
|
||||
request->response_body = (GInputStream *) g_file_read_finish ((GFile *) object,
|
||||
result,
|
||||
&local_error);
|
||||
request->response_body
|
||||
= (GInputStream *)g_file_read_finish ((GFile *)object, result, &local_error);
|
||||
else
|
||||
request->response_body = soup_session_send_finish ((SoupSession *) object,
|
||||
result, &local_error);
|
||||
request->response_body = soup_session_send_finish ((SoupSession *)object, result, &local_error);
|
||||
|
||||
if (!request->response_body)
|
||||
{
|
||||
@ -597,8 +559,8 @@ on_request_sent (GObject *object,
|
||||
if (request->message)
|
||||
{
|
||||
SoupStatus status = soup_message_get_status (request->message);
|
||||
if (status == SOUP_STATUS_NOT_MODIFIED &&
|
||||
(request->if_none_match != NULL || request->if_modified_since > 0))
|
||||
if (status == SOUP_STATUS_NOT_MODIFIED
|
||||
&& (request->if_none_match != NULL || request->if_modified_since > 0))
|
||||
{
|
||||
/* Version on the server is unchanged from the version we have cached locally;
|
||||
* report this as an out-argument, a zero-length response buffer, and no error */
|
||||
@ -615,25 +577,23 @@ on_request_sent (GObject *object,
|
||||
}
|
||||
else
|
||||
{
|
||||
g_autofree char *uristring = g_uri_to_string (soup_message_get_uri (request->message));
|
||||
g_autofree char *uristring
|
||||
= g_uri_to_string (soup_message_get_uri (request->message));
|
||||
GIOErrorEnum code = _ostree_fetcher_http_status_code_to_io_error (status);
|
||||
{
|
||||
g_autofree char *errmsg =
|
||||
g_strdup_printf ("Server returned status %u: %s",
|
||||
status,
|
||||
soup_status_get_phrase (status));
|
||||
g_autofree char *errmsg = g_strdup_printf ("Server returned status %u: %s", status,
|
||||
soup_status_get_phrase (status));
|
||||
local_error = g_error_new_literal (G_IO_ERROR, code, errmsg);
|
||||
}
|
||||
|
||||
if (request->mirrorlist->len > 1)
|
||||
g_prefix_error (&local_error,
|
||||
"All %u mirrors failed. Last error was: ",
|
||||
g_prefix_error (&local_error, "All %u mirrors failed. Last error was: ",
|
||||
request->mirrorlist->len);
|
||||
if (request->fetcher->remote_name &&
|
||||
!((request->flags & OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT) > 0 &&
|
||||
code == G_IO_ERROR_NOT_FOUND))
|
||||
_ostree_fetcher_journal_failure (request->fetcher->remote_name,
|
||||
uristring, local_error->message);
|
||||
if (request->fetcher->remote_name
|
||||
&& !((request->flags & OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT) > 0
|
||||
&& code == G_IO_ERROR_NOT_FOUND))
|
||||
_ostree_fetcher_journal_failure (request->fetcher->remote_name, uristring,
|
||||
local_error->message);
|
||||
|
||||
g_task_return_error (task, local_error);
|
||||
return;
|
||||
@ -641,10 +601,12 @@ on_request_sent (GObject *object,
|
||||
}
|
||||
|
||||
/* Grab cache properties from the response */
|
||||
request->out_etag = g_strdup (soup_message_headers_get_one (soup_message_get_response_headers (request->message), "ETag"));
|
||||
request->out_etag = g_strdup (soup_message_headers_get_one (
|
||||
soup_message_get_response_headers (request->message), "ETag"));
|
||||
request->out_last_modified = 0;
|
||||
|
||||
const char *last_modified_str = soup_message_headers_get_one (soup_message_get_response_headers (request->message), "Last-Modified");
|
||||
const char *last_modified_str = soup_message_headers_get_one (
|
||||
soup_message_get_response_headers (request->message), "Last-Modified");
|
||||
if (last_modified_str != NULL)
|
||||
{
|
||||
GDateTime *soup_date = soup_date_time_new_from_http_string (last_modified_str);
|
||||
@ -658,10 +620,9 @@ on_request_sent (GObject *object,
|
||||
|
||||
if (request->file)
|
||||
{
|
||||
GFileInfo *info = g_file_query_info (request->file,
|
||||
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
|
||||
G_FILE_ATTRIBUTE_STANDARD_SIZE,
|
||||
0, NULL, NULL);
|
||||
GFileInfo *info = g_file_query_info (
|
||||
request->file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," G_FILE_ATTRIBUTE_STANDARD_SIZE,
|
||||
0, NULL, NULL);
|
||||
if (info)
|
||||
{
|
||||
request->content_length = g_file_info_get_size (info);
|
||||
@ -680,23 +641,17 @@ on_request_sent (GObject *object,
|
||||
}
|
||||
|
||||
GCancellable *cancellable = g_task_get_cancellable (task);
|
||||
g_input_stream_read_bytes_async (request->response_body,
|
||||
8192, G_PRIORITY_DEFAULT,
|
||||
cancellable,
|
||||
on_stream_read,
|
||||
g_object_ref (task));
|
||||
g_input_stream_read_bytes_async (request->response_body, 8192, G_PRIORITY_DEFAULT, cancellable,
|
||||
on_stream_read, g_object_ref (task));
|
||||
}
|
||||
|
||||
static SoupSession *
|
||||
create_soup_session (OstreeFetcher *self)
|
||||
{
|
||||
const char *user_agent = self->user_agent ?: OSTREE_FETCHER_USERAGENT_STRING;
|
||||
SoupSession *session =
|
||||
soup_session_new_with_options ("user-agent", user_agent,
|
||||
"timeout", 60,
|
||||
"idle-timeout", 60,
|
||||
"max-conns-per-host", _OSTREE_MAX_OUTSTANDING_FETCHER_REQUESTS,
|
||||
NULL);
|
||||
SoupSession *session = soup_session_new_with_options (
|
||||
"user-agent", user_agent, "timeout", 60, "idle-timeout", 60, "max-conns-per-host",
|
||||
_OSTREE_MAX_OUTSTANDING_FETCHER_REQUESTS, NULL);
|
||||
|
||||
/* SoupContentDecoder is included in the session by default. Remove it
|
||||
* if gzip compression isn't in use.
|
||||
@ -715,7 +670,7 @@ create_soup_session (OstreeFetcher *self)
|
||||
if (self->cookie_jar != NULL)
|
||||
soup_session_add_feature (session, SOUP_SESSION_FEATURE (self->cookie_jar));
|
||||
if (self->client_cert != NULL)
|
||||
soup_session_set_tls_interaction (session, (GTlsInteraction *) self->client_cert);
|
||||
soup_session_set_tls_interaction (session, (GTlsInteraction *)self->client_cert);
|
||||
if (self->tls_database != NULL)
|
||||
soup_session_set_tls_database (session, self->tls_database);
|
||||
|
||||
@ -723,35 +678,25 @@ create_soup_session (OstreeFetcher *self)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
match_value (gpointer key,
|
||||
gpointer value,
|
||||
gpointer user_data)
|
||||
match_value (gpointer key, gpointer value, gpointer user_data)
|
||||
{
|
||||
return value == user_data;
|
||||
}
|
||||
|
||||
static void
|
||||
on_session_finalized (gpointer data,
|
||||
GObject *object)
|
||||
on_session_finalized (gpointer data, GObject *object)
|
||||
{
|
||||
GHashTable *sessions = data;
|
||||
g_debug ("Removing session %p from sessions hash table", object);
|
||||
(void) g_hash_table_foreach_remove (sessions, match_value, object);
|
||||
(void)g_hash_table_foreach_remove (sessions, match_value, object);
|
||||
}
|
||||
|
||||
static void
|
||||
_ostree_fetcher_request_async (OstreeFetcher *self,
|
||||
GPtrArray *mirrorlist,
|
||||
const char *filename,
|
||||
OstreeFetcherRequestFlags flags,
|
||||
const char *if_none_match,
|
||||
guint64 if_modified_since,
|
||||
gboolean is_membuf,
|
||||
guint64 max_size,
|
||||
int priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
_ostree_fetcher_request_async (OstreeFetcher *self, GPtrArray *mirrorlist, const char *filename,
|
||||
OstreeFetcherRequestFlags flags, const char *if_none_match,
|
||||
guint64 if_modified_since, gboolean is_membuf, guint64 max_size,
|
||||
int priority, GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback, gpointer user_data)
|
||||
{
|
||||
g_return_if_fail (OSTREE_IS_FETCHER (self));
|
||||
g_return_if_fail (mirrorlist != NULL);
|
||||
@ -774,7 +719,7 @@ _ostree_fetcher_request_async (OstreeFetcher *self,
|
||||
* session is kept in the fetcher.
|
||||
*/
|
||||
g_debug ("Looking up session for main context %p", request->mainctx);
|
||||
request->session = (SoupSession *) g_hash_table_lookup (self->sessions, request->mainctx);
|
||||
request->session = (SoupSession *)g_hash_table_lookup (self->sessions, request->mainctx);
|
||||
if (request->session != NULL)
|
||||
{
|
||||
g_debug ("Using existing session %p", request->session);
|
||||
@ -792,9 +737,9 @@ _ostree_fetcher_request_async (OstreeFetcher *self,
|
||||
g_object_weak_ref (G_OBJECT (request->session), on_session_finalized, self->sessions);
|
||||
}
|
||||
|
||||
g_autoptr(GTask) task = g_task_new (self, cancellable, callback, user_data);
|
||||
g_autoptr (GTask) task = g_task_new (self, cancellable, callback, user_data);
|
||||
g_task_set_source_tag (task, _ostree_fetcher_request_async);
|
||||
g_task_set_task_data (task, request, (GDestroyNotify) fetcher_request_free);
|
||||
g_task_set_task_data (task, request, (GDestroyNotify)fetcher_request_free);
|
||||
|
||||
/* We'll use the GTask priority for our own priority queue. */
|
||||
g_task_set_priority (task, priority);
|
||||
@ -803,37 +748,27 @@ _ostree_fetcher_request_async (OstreeFetcher *self,
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_fetcher_request_to_tmpfile (OstreeFetcher *self,
|
||||
GPtrArray *mirrorlist,
|
||||
const char *filename,
|
||||
OstreeFetcherRequestFlags flags,
|
||||
const char *if_none_match,
|
||||
guint64 if_modified_since,
|
||||
guint64 max_size,
|
||||
int priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
_ostree_fetcher_request_to_tmpfile (OstreeFetcher *self, GPtrArray *mirrorlist,
|
||||
const char *filename, OstreeFetcherRequestFlags flags,
|
||||
const char *if_none_match, guint64 if_modified_since,
|
||||
guint64 max_size, int priority, GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback, gpointer user_data)
|
||||
{
|
||||
_ostree_fetcher_request_async (self, mirrorlist, filename, flags,
|
||||
if_none_match, if_modified_since, FALSE,
|
||||
max_size, priority, cancellable,
|
||||
_ostree_fetcher_request_async (self, mirrorlist, filename, flags, if_none_match,
|
||||
if_modified_since, FALSE, max_size, priority, cancellable,
|
||||
callback, user_data);
|
||||
}
|
||||
|
||||
gboolean
|
||||
_ostree_fetcher_request_to_tmpfile_finish (OstreeFetcher *self,
|
||||
GAsyncResult *result,
|
||||
GLnxTmpfile *out_tmpf,
|
||||
gboolean *out_not_modified,
|
||||
char **out_etag,
|
||||
guint64 *out_last_modified,
|
||||
GError **error)
|
||||
_ostree_fetcher_request_to_tmpfile_finish (OstreeFetcher *self, GAsyncResult *result,
|
||||
GLnxTmpfile *out_tmpf, gboolean *out_not_modified,
|
||||
char **out_etag, guint64 *out_last_modified,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (g_task_is_valid (result, self), FALSE);
|
||||
g_return_val_if_fail (g_async_result_is_tagged (result, _ostree_fetcher_request_async), FALSE);
|
||||
|
||||
GTask *task = (GTask *) result;
|
||||
GTask *task = (GTask *)result;
|
||||
gpointer ret = g_task_propagate_pointer (task, error);
|
||||
if (!ret)
|
||||
return FALSE;
|
||||
@ -854,37 +789,27 @@ _ostree_fetcher_request_to_tmpfile_finish (OstreeFetcher *self,
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_fetcher_request_to_membuf (OstreeFetcher *self,
|
||||
GPtrArray *mirrorlist,
|
||||
const char *filename,
|
||||
OstreeFetcherRequestFlags flags,
|
||||
const char *if_none_match,
|
||||
guint64 if_modified_since,
|
||||
guint64 max_size,
|
||||
int priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
_ostree_fetcher_request_to_membuf (OstreeFetcher *self, GPtrArray *mirrorlist, const char *filename,
|
||||
OstreeFetcherRequestFlags flags, const char *if_none_match,
|
||||
guint64 if_modified_since, guint64 max_size, int priority,
|
||||
GCancellable *cancellable, GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
_ostree_fetcher_request_async (self, mirrorlist, filename, flags,
|
||||
if_none_match, if_modified_since, TRUE,
|
||||
max_size, priority, cancellable,
|
||||
callback, user_data);
|
||||
_ostree_fetcher_request_async (self, mirrorlist, filename, flags, if_none_match,
|
||||
if_modified_since, TRUE, max_size, priority, cancellable, callback,
|
||||
user_data);
|
||||
}
|
||||
|
||||
gboolean
|
||||
_ostree_fetcher_request_to_membuf_finish (OstreeFetcher *self,
|
||||
GAsyncResult *result,
|
||||
GBytes **out_buf,
|
||||
gboolean *out_not_modified,
|
||||
char **out_etag,
|
||||
guint64 *out_last_modified,
|
||||
GError **error)
|
||||
_ostree_fetcher_request_to_membuf_finish (OstreeFetcher *self, GAsyncResult *result,
|
||||
GBytes **out_buf, gboolean *out_not_modified,
|
||||
char **out_etag, guint64 *out_last_modified,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (g_task_is_valid (result, self), FALSE);
|
||||
g_return_val_if_fail (g_async_result_is_tagged (result, _ostree_fetcher_request_async), FALSE);
|
||||
|
||||
GTask *task = (GTask *) result;
|
||||
GTask *task = (GTask *)result;
|
||||
gpointer ret = g_task_propagate_pointer (task, error);
|
||||
if (!ret)
|
||||
return FALSE;
|
||||
@ -904,7 +829,6 @@ _ostree_fetcher_request_to_membuf_finish (OstreeFetcher *self,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
guint64
|
||||
_ostree_fetcher_bytes_transferred (OstreeFetcher *self)
|
||||
{
|
||||
|
@ -32,16 +32,16 @@ void
|
||||
_ostree_fetcher_uri_free (OstreeFetcherURI *uri)
|
||||
{
|
||||
if (uri)
|
||||
g_uri_unref ((GUri*)uri);
|
||||
g_uri_unref ((GUri *)uri);
|
||||
}
|
||||
|
||||
OstreeFetcherURI *
|
||||
_ostree_fetcher_uri_parse (const char *str,
|
||||
GError **error)
|
||||
_ostree_fetcher_uri_parse (const char *str, GError **error)
|
||||
{
|
||||
GUri *uri = NULL;
|
||||
#if GLIB_CHECK_VERSION(2, 68, 0)
|
||||
uri = g_uri_parse (str, G_URI_FLAGS_HAS_PASSWORD | G_URI_FLAGS_ENCODED | G_URI_FLAGS_SCHEME_NORMALIZE, error);
|
||||
uri = g_uri_parse (
|
||||
str, G_URI_FLAGS_HAS_PASSWORD | G_URI_FLAGS_ENCODED | G_URI_FLAGS_SCHEME_NORMALIZE, error);
|
||||
#else
|
||||
/* perform manual scheme normalization for older glib */
|
||||
uri = g_uri_parse (str, G_URI_FLAGS_HAS_PASSWORD | G_URI_FLAGS_ENCODED, error);
|
||||
@ -50,42 +50,36 @@ _ostree_fetcher_uri_parse (const char *str,
|
||||
GUri *nuri = NULL;
|
||||
switch (g_uri_get_port (uri))
|
||||
{
|
||||
case 21:
|
||||
if (!strcmp (g_uri_get_scheme (uri), "ftp"))
|
||||
break;
|
||||
return (OstreeFetcherURI*)uri;
|
||||
case 80:
|
||||
if (!strcmp (g_uri_get_scheme (uri), "http"))
|
||||
break;
|
||||
return (OstreeFetcherURI*)uri;
|
||||
case 443:
|
||||
if (!strcmp (g_uri_get_scheme (uri), "https"))
|
||||
break;
|
||||
return (OstreeFetcherURI*)uri;
|
||||
default:
|
||||
return (OstreeFetcherURI*)uri;
|
||||
case 21:
|
||||
if (!strcmp (g_uri_get_scheme (uri), "ftp"))
|
||||
break;
|
||||
return (OstreeFetcherURI *)uri;
|
||||
case 80:
|
||||
if (!strcmp (g_uri_get_scheme (uri), "http"))
|
||||
break;
|
||||
return (OstreeFetcherURI *)uri;
|
||||
case 443:
|
||||
if (!strcmp (g_uri_get_scheme (uri), "https"))
|
||||
break;
|
||||
return (OstreeFetcherURI *)uri;
|
||||
default:
|
||||
return (OstreeFetcherURI *)uri;
|
||||
}
|
||||
nuri = g_uri_build_with_user (g_uri_get_flags (uri), "http",
|
||||
g_uri_get_user (uri),
|
||||
g_uri_get_password (uri),
|
||||
NULL,
|
||||
g_uri_get_host (uri), -1,
|
||||
g_uri_get_path (uri),
|
||||
g_uri_get_query (uri),
|
||||
nuri = g_uri_build_with_user (g_uri_get_flags (uri), "http", g_uri_get_user (uri),
|
||||
g_uri_get_password (uri), NULL, g_uri_get_host (uri), -1,
|
||||
g_uri_get_path (uri), g_uri_get_query (uri),
|
||||
g_uri_get_fragment (uri));
|
||||
g_uri_unref (uri);
|
||||
uri = nuri;
|
||||
}
|
||||
#endif
|
||||
return (OstreeFetcherURI*)uri;
|
||||
return (OstreeFetcherURI *)uri;
|
||||
}
|
||||
|
||||
static OstreeFetcherURI *
|
||||
_ostree_fetcher_uri_new_path_internal (OstreeFetcherURI *uri,
|
||||
gboolean extend,
|
||||
const char *path)
|
||||
_ostree_fetcher_uri_new_path_internal (OstreeFetcherURI *uri, gboolean extend, const char *path)
|
||||
{
|
||||
GUri *guri = (GUri*)uri;
|
||||
GUri *guri = (GUri *)uri;
|
||||
const char *opath = g_uri_get_path (guri);
|
||||
g_autofree char *newpath = NULL;
|
||||
if (path)
|
||||
@ -100,28 +94,20 @@ _ostree_fetcher_uri_new_path_internal (OstreeFetcherURI *uri,
|
||||
opath = path;
|
||||
}
|
||||
}
|
||||
return (OstreeFetcherURI*)g_uri_build_with_user (g_uri_get_flags (guri),
|
||||
g_uri_get_scheme (guri),
|
||||
g_uri_get_user (guri),
|
||||
g_uri_get_password (guri),
|
||||
NULL,
|
||||
g_uri_get_host (guri),
|
||||
g_uri_get_port (guri),
|
||||
opath,
|
||||
g_uri_get_query (guri),
|
||||
g_uri_get_fragment (guri));
|
||||
return (OstreeFetcherURI *)g_uri_build_with_user (
|
||||
g_uri_get_flags (guri), g_uri_get_scheme (guri), g_uri_get_user (guri),
|
||||
g_uri_get_password (guri), NULL, g_uri_get_host (guri), g_uri_get_port (guri), opath,
|
||||
g_uri_get_query (guri), g_uri_get_fragment (guri));
|
||||
}
|
||||
|
||||
OstreeFetcherURI *
|
||||
_ostree_fetcher_uri_new_path (OstreeFetcherURI *uri,
|
||||
const char *path)
|
||||
_ostree_fetcher_uri_new_path (OstreeFetcherURI *uri, const char *path)
|
||||
{
|
||||
return _ostree_fetcher_uri_new_path_internal (uri, FALSE, path);
|
||||
}
|
||||
|
||||
OstreeFetcherURI *
|
||||
_ostree_fetcher_uri_new_subpath (OstreeFetcherURI *uri,
|
||||
const char *subpath)
|
||||
_ostree_fetcher_uri_new_subpath (OstreeFetcherURI *uri, const char *subpath)
|
||||
{
|
||||
return _ostree_fetcher_uri_new_path_internal (uri, TRUE, subpath);
|
||||
}
|
||||
@ -135,22 +121,21 @@ _ostree_fetcher_uri_clone (OstreeFetcherURI *uri)
|
||||
char *
|
||||
_ostree_fetcher_uri_get_scheme (OstreeFetcherURI *uri)
|
||||
{
|
||||
return g_strdup (g_uri_get_scheme ((GUri*)uri));
|
||||
return g_strdup (g_uri_get_scheme ((GUri *)uri));
|
||||
}
|
||||
|
||||
char *
|
||||
_ostree_fetcher_uri_get_path (OstreeFetcherURI *uri)
|
||||
{
|
||||
return g_strdup (g_uri_get_path ((GUri*)uri));
|
||||
return g_strdup (g_uri_get_path ((GUri *)uri));
|
||||
}
|
||||
|
||||
char *
|
||||
_ostree_fetcher_uri_to_string (OstreeFetcherURI *uri)
|
||||
{
|
||||
return g_uri_to_string_partial ((GUri*)uri, G_URI_HIDE_PASSWORD);
|
||||
return g_uri_to_string_partial ((GUri *)uri, G_URI_HIDE_PASSWORD);
|
||||
}
|
||||
|
||||
|
||||
/* Only accept http, https, and file; particularly curl has a ton of other
|
||||
* backends like sftp that we don't want, and this also gracefully filters
|
||||
* out invalid input.
|
||||
@ -158,9 +143,10 @@ _ostree_fetcher_uri_to_string (OstreeFetcherURI *uri)
|
||||
gboolean
|
||||
_ostree_fetcher_uri_validate (OstreeFetcherURI *uri, GError **error)
|
||||
{
|
||||
const char *scheme = g_uri_get_scheme ((GUri*)uri);
|
||||
const char *scheme = g_uri_get_scheme ((GUri *)uri);
|
||||
// TODO only allow file if explicitly requested by a higher level
|
||||
if (!(g_str_equal (scheme, "http") || g_str_equal (scheme, "https") || g_str_equal (scheme, "file")))
|
||||
if (!(g_str_equal (scheme, "http") || g_str_equal (scheme, "https")
|
||||
|| g_str_equal (scheme, "file")))
|
||||
{
|
||||
g_autofree char *s = _ostree_fetcher_uri_to_string (uri);
|
||||
return glnx_throw (error, "Invalid URI scheme in %s", s);
|
||||
|
@ -32,49 +32,36 @@
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GBytes *result_buf;
|
||||
gboolean result_not_modified;
|
||||
char *result_etag;
|
||||
guint64 result_last_modified; /* second since the epoch */
|
||||
gboolean done;
|
||||
GMainContext *main_context; /* (owned) */
|
||||
GError **error;
|
||||
}
|
||||
FetchUriSyncData;
|
||||
GBytes *result_buf;
|
||||
gboolean result_not_modified;
|
||||
char *result_etag;
|
||||
guint64 result_last_modified; /* second since the epoch */
|
||||
gboolean done;
|
||||
GMainContext *main_context; /* (owned) */
|
||||
GError **error;
|
||||
} FetchUriSyncData;
|
||||
|
||||
static void
|
||||
fetch_uri_sync_on_complete (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
fetch_uri_sync_on_complete (GObject *object, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
FetchUriSyncData *data = user_data;
|
||||
|
||||
(void)_ostree_fetcher_request_to_membuf_finish ((OstreeFetcher*)object,
|
||||
result, &data->result_buf,
|
||||
&data->result_not_modified,
|
||||
&data->result_etag, &data->result_last_modified,
|
||||
data->error);
|
||||
(void)_ostree_fetcher_request_to_membuf_finish (
|
||||
(OstreeFetcher *)object, result, &data->result_buf, &data->result_not_modified,
|
||||
&data->result_etag, &data->result_last_modified, data->error);
|
||||
data->done = TRUE;
|
||||
g_main_context_wakeup (data->main_context);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_ostree_fetcher_mirrored_request_to_membuf_once (OstreeFetcher *fetcher,
|
||||
GPtrArray *mirrorlist,
|
||||
const char *filename,
|
||||
OstreeFetcherRequestFlags flags,
|
||||
const char *if_none_match,
|
||||
guint64 if_modified_since,
|
||||
GBytes **out_contents,
|
||||
gboolean *out_not_modified,
|
||||
char **out_etag,
|
||||
guint64 *out_last_modified,
|
||||
guint64 max_size,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_fetcher_mirrored_request_to_membuf_once (
|
||||
OstreeFetcher *fetcher, GPtrArray *mirrorlist, const char *filename,
|
||||
OstreeFetcherRequestFlags flags, const char *if_none_match, guint64 if_modified_since,
|
||||
GBytes **out_contents, gboolean *out_not_modified, char **out_etag, guint64 *out_last_modified,
|
||||
guint64 max_size, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
g_autoptr(GMainContext) mainctx = NULL;
|
||||
g_autoptr (GMainContext) mainctx = NULL;
|
||||
FetchUriSyncData data;
|
||||
g_assert (error != NULL);
|
||||
|
||||
@ -90,9 +77,8 @@ _ostree_fetcher_mirrored_request_to_membuf_once (OstreeFetcher *fe
|
||||
data.done = FALSE;
|
||||
data.error = error;
|
||||
|
||||
_ostree_fetcher_request_to_membuf (fetcher, mirrorlist, filename,
|
||||
flags, if_none_match, if_modified_since,
|
||||
max_size, OSTREE_FETCHER_DEFAULT_PRIORITY,
|
||||
_ostree_fetcher_request_to_membuf (fetcher, mirrorlist, filename, flags, if_none_match,
|
||||
if_modified_since, max_size, OSTREE_FETCHER_DEFAULT_PRIORITY,
|
||||
cancellable, fetch_uri_sync_on_complete, &data);
|
||||
while (!data.done)
|
||||
g_main_context_iteration (mainctx, TRUE);
|
||||
@ -125,7 +111,7 @@ _ostree_fetcher_mirrored_request_to_membuf_once (OstreeFetcher *fe
|
||||
*out_etag = g_steal_pointer (&data.result_etag);
|
||||
if (out_last_modified != NULL)
|
||||
*out_last_modified = data.result_last_modified;
|
||||
out:
|
||||
out:
|
||||
if (mainctx)
|
||||
g_main_context_pop_thread_default (mainctx);
|
||||
g_clear_pointer (&data.result_buf, g_bytes_unref);
|
||||
@ -135,33 +121,23 @@ _ostree_fetcher_mirrored_request_to_membuf_once (OstreeFetcher *fe
|
||||
}
|
||||
|
||||
gboolean
|
||||
_ostree_fetcher_mirrored_request_to_membuf (OstreeFetcher *fetcher,
|
||||
GPtrArray *mirrorlist,
|
||||
const char *filename,
|
||||
OstreeFetcherRequestFlags flags,
|
||||
const char *if_none_match,
|
||||
guint64 if_modified_since,
|
||||
guint n_network_retries,
|
||||
GBytes **out_contents,
|
||||
gboolean *out_not_modified,
|
||||
char **out_etag,
|
||||
guint64 *out_last_modified,
|
||||
guint64 max_size,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_fetcher_mirrored_request_to_membuf (OstreeFetcher *fetcher, GPtrArray *mirrorlist,
|
||||
const char *filename, OstreeFetcherRequestFlags flags,
|
||||
const char *if_none_match, guint64 if_modified_since,
|
||||
guint n_network_retries, GBytes **out_contents,
|
||||
gboolean *out_not_modified, char **out_etag,
|
||||
guint64 *out_last_modified, guint64 max_size,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
g_autoptr(GError) local_error = NULL;
|
||||
g_autoptr (GError) local_error = NULL;
|
||||
guint n_retries_remaining = n_network_retries;
|
||||
|
||||
do
|
||||
{
|
||||
g_clear_error (&local_error);
|
||||
if (_ostree_fetcher_mirrored_request_to_membuf_once (fetcher, mirrorlist,
|
||||
filename, flags,
|
||||
if_none_match, if_modified_since,
|
||||
out_contents, out_not_modified, out_etag,
|
||||
out_last_modified, max_size,
|
||||
cancellable, &local_error))
|
||||
if (_ostree_fetcher_mirrored_request_to_membuf_once (
|
||||
fetcher, mirrorlist, filename, flags, if_none_match, if_modified_since, out_contents,
|
||||
out_not_modified, out_etag, out_last_modified, max_size, cancellable, &local_error))
|
||||
return TRUE;
|
||||
}
|
||||
while (_ostree_fetcher_should_retry_request (local_error, n_retries_remaining--));
|
||||
@ -173,46 +149,33 @@ _ostree_fetcher_mirrored_request_to_membuf (OstreeFetcher *fetcher
|
||||
|
||||
/* Helper for callers who just want to fetch single one-off URIs */
|
||||
gboolean
|
||||
_ostree_fetcher_request_uri_to_membuf (OstreeFetcher *fetcher,
|
||||
OstreeFetcherURI *uri,
|
||||
OstreeFetcherRequestFlags flags,
|
||||
const char *if_none_match,
|
||||
guint64 if_modified_since,
|
||||
guint n_network_retries,
|
||||
GBytes **out_contents,
|
||||
gboolean *out_not_modified,
|
||||
char **out_etag,
|
||||
guint64 *out_last_modified,
|
||||
guint64 max_size,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_fetcher_request_uri_to_membuf (OstreeFetcher *fetcher, OstreeFetcherURI *uri,
|
||||
OstreeFetcherRequestFlags flags, const char *if_none_match,
|
||||
guint64 if_modified_since, guint n_network_retries,
|
||||
GBytes **out_contents, gboolean *out_not_modified,
|
||||
char **out_etag, guint64 *out_last_modified,
|
||||
guint64 max_size, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
g_autoptr(GPtrArray) mirrorlist = g_ptr_array_new ();
|
||||
g_autoptr (GPtrArray) mirrorlist = g_ptr_array_new ();
|
||||
g_ptr_array_add (mirrorlist, uri); /* no transfer */
|
||||
return _ostree_fetcher_mirrored_request_to_membuf (fetcher, mirrorlist, NULL, flags,
|
||||
if_none_match, if_modified_since,
|
||||
n_network_retries, out_contents,
|
||||
out_not_modified, out_etag, out_last_modified, max_size,
|
||||
cancellable, error);
|
||||
return _ostree_fetcher_mirrored_request_to_membuf (
|
||||
fetcher, mirrorlist, NULL, flags, if_none_match, if_modified_since, n_network_retries,
|
||||
out_contents, out_not_modified, out_etag, out_last_modified, max_size, cancellable, error);
|
||||
}
|
||||
|
||||
#define OSTREE_HTTP_FAILURE_ID SD_ID128_MAKE(f0,2b,ce,89,a5,4e,4e,fa,b3,a9,4a,79,7d,26,20,4a)
|
||||
#define OSTREE_HTTP_FAILURE_ID \
|
||||
SD_ID128_MAKE (f0, 2b, ce, 89, a5, 4e, 4e, fa, b3, a9, 4a, 79, 7d, 26, 20, 4a)
|
||||
|
||||
void
|
||||
_ostree_fetcher_journal_failure (const char *remote_name,
|
||||
const char *url,
|
||||
const char *msg)
|
||||
_ostree_fetcher_journal_failure (const char *remote_name, const char *url, const char *msg)
|
||||
{
|
||||
/* Sanity - we don't want to log this when doing local/file pulls */
|
||||
if (!remote_name)
|
||||
return;
|
||||
ot_journal_send ("MESSAGE=libostree HTTP error from remote %s for <%s>: %s",
|
||||
remote_name, url, msg,
|
||||
"MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(OSTREE_HTTP_FAILURE_ID),
|
||||
"OSTREE_REMOTE=%s", remote_name,
|
||||
"OSTREE_URL=%s", url,
|
||||
"PRIORITY=%i", LOG_ERR,
|
||||
NULL);
|
||||
ot_journal_send ("MESSAGE=libostree HTTP error from remote %s for <%s>: %s", remote_name, url,
|
||||
msg, "MESSAGE_ID=" SD_ID128_FORMAT_STR,
|
||||
SD_ID128_FORMAT_VAL (OSTREE_HTTP_FAILURE_ID), "OSTREE_REMOTE=%s", remote_name,
|
||||
"OSTREE_URL=%s", url, "PRIORITY=%i", LOG_ERR, NULL);
|
||||
}
|
||||
|
||||
/* Check whether a particular operation should be retried. This is entirely
|
||||
@ -224,33 +187,30 @@ _ostree_fetcher_journal_failure (const char *remote_name,
|
||||
* FIXME: In future, we may decide to use transient failures like this as a hint
|
||||
* to prioritise other mirrors for a particular pull operation (for example). */
|
||||
gboolean
|
||||
_ostree_fetcher_should_retry_request (const GError *error,
|
||||
guint n_retries_remaining)
|
||||
_ostree_fetcher_should_retry_request (const GError *error, guint n_retries_remaining)
|
||||
{
|
||||
if (error == NULL)
|
||||
g_debug ("%s: error: unset, n_retries_remaining: %u",
|
||||
G_STRFUNC, n_retries_remaining);
|
||||
g_debug ("%s: error: unset, n_retries_remaining: %u", G_STRFUNC, n_retries_remaining);
|
||||
else
|
||||
g_debug ("%s: error: %u:%u %s, n_retries_remaining: %u",
|
||||
G_STRFUNC, error->domain, error->code, error->message,
|
||||
n_retries_remaining);
|
||||
g_debug ("%s: error: %u:%u %s, n_retries_remaining: %u", G_STRFUNC, error->domain, error->code,
|
||||
error->message, n_retries_remaining);
|
||||
|
||||
if (error == NULL || n_retries_remaining == 0)
|
||||
return FALSE;
|
||||
|
||||
/* Return TRUE for transient errors. */
|
||||
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT) ||
|
||||
g_error_matches (error, G_IO_ERROR, G_IO_ERROR_HOST_NOT_FOUND) ||
|
||||
g_error_matches (error, G_IO_ERROR, G_IO_ERROR_HOST_UNREACHABLE) ||
|
||||
g_error_matches (error, G_IO_ERROR, G_IO_ERROR_PARTIAL_INPUT) ||
|
||||
g_error_matches (error, G_IO_ERROR, G_IO_ERROR_BUSY) ||
|
||||
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT)
|
||||
|| g_error_matches (error, G_IO_ERROR, G_IO_ERROR_HOST_NOT_FOUND)
|
||||
|| g_error_matches (error, G_IO_ERROR, G_IO_ERROR_HOST_UNREACHABLE)
|
||||
|| g_error_matches (error, G_IO_ERROR, G_IO_ERROR_PARTIAL_INPUT)
|
||||
|| g_error_matches (error, G_IO_ERROR, G_IO_ERROR_BUSY) ||
|
||||
#if !GLIB_CHECK_VERSION(2, 44, 0)
|
||||
g_error_matches (error, G_IO_ERROR, G_IO_ERROR_BROKEN_PIPE) ||
|
||||
#else
|
||||
g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CONNECTION_CLOSED) ||
|
||||
#endif
|
||||
g_error_matches (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_NOT_FOUND) ||
|
||||
g_error_matches (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_TEMPORARY_FAILURE))
|
||||
g_error_matches (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_NOT_FOUND)
|
||||
|| g_error_matches (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_TEMPORARY_FAILURE))
|
||||
{
|
||||
g_debug ("Should retry request (remaining: %u retries), due to transient error: %s",
|
||||
n_retries_remaining, error->message);
|
||||
@ -268,13 +228,13 @@ _ostree_fetcher_http_status_code_to_io_error (guint status_code)
|
||||
{
|
||||
switch (status_code)
|
||||
{
|
||||
case 403: /* SOUP_STATUS_FORBIDDEN */
|
||||
case 404: /* SOUP_STATUS_NOT_FOUND */
|
||||
case 410: /* SOUP_STATUS_GONE */
|
||||
case 403: /* SOUP_STATUS_FORBIDDEN */
|
||||
case 404: /* SOUP_STATUS_NOT_FOUND */
|
||||
case 410: /* SOUP_STATUS_GONE */
|
||||
return G_IO_ERROR_NOT_FOUND;
|
||||
case 408: /* SOUP_STATUS_REQUEST_TIMEOUT */
|
||||
case 408: /* SOUP_STATUS_REQUEST_TIMEOUT */
|
||||
return G_IO_ERROR_TIMED_OUT;
|
||||
case 500: /* SOUP_STATUS_INTERNAL_SERVER_ERROR */
|
||||
case 500: /* SOUP_STATUS_INTERNAL_SERVER_ERROR */
|
||||
return G_IO_ERROR_BUSY;
|
||||
default:
|
||||
return G_IO_ERROR_FAILED;
|
||||
|
@ -32,10 +32,8 @@ G_BEGIN_DECLS
|
||||
#define OSTREE_FETCHER_USERAGENT_STRING (PACKAGE_NAME "/" PACKAGE_VERSION)
|
||||
|
||||
static inline gboolean
|
||||
_ostree_fetcher_tmpf_from_flags (OstreeFetcherRequestFlags flags,
|
||||
int dfd,
|
||||
GLnxTmpfile *tmpf,
|
||||
GError **error)
|
||||
_ostree_fetcher_tmpf_from_flags (OstreeFetcherRequestFlags flags, int dfd, GLnxTmpfile *tmpf,
|
||||
GError **error)
|
||||
{
|
||||
if ((flags & OSTREE_FETCHER_REQUEST_LINKABLE) > 0)
|
||||
{
|
||||
@ -50,41 +48,21 @@ _ostree_fetcher_tmpf_from_flags (OstreeFetcherRequestFlags flags,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean _ostree_fetcher_mirrored_request_to_membuf (OstreeFetcher *fetcher,
|
||||
GPtrArray *mirrorlist,
|
||||
const char *filename,
|
||||
OstreeFetcherRequestFlags flags,
|
||||
const char *if_none_match,
|
||||
guint64 if_modified_since,
|
||||
guint n_network_retries,
|
||||
GBytes **out_contents,
|
||||
gboolean *out_not_modified,
|
||||
char **out_etag,
|
||||
guint64 *out_last_modified,
|
||||
guint64 max_size,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean _ostree_fetcher_mirrored_request_to_membuf (
|
||||
OstreeFetcher *fetcher, GPtrArray *mirrorlist, const char *filename,
|
||||
OstreeFetcherRequestFlags flags, const char *if_none_match, guint64 if_modified_since,
|
||||
guint n_network_retries, GBytes **out_contents, gboolean *out_not_modified, char **out_etag,
|
||||
guint64 *out_last_modified, guint64 max_size, GCancellable *cancellable, GError **error);
|
||||
|
||||
gboolean _ostree_fetcher_request_uri_to_membuf (OstreeFetcher *fetcher,
|
||||
OstreeFetcherURI *uri,
|
||||
OstreeFetcherRequestFlags flags,
|
||||
const char *if_none_match,
|
||||
guint64 if_modified_since,
|
||||
guint n_network_retries,
|
||||
GBytes **out_contents,
|
||||
gboolean *out_not_modified,
|
||||
char **out_etag,
|
||||
guint64 *out_last_modified,
|
||||
guint64 max_size,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean _ostree_fetcher_request_uri_to_membuf (
|
||||
OstreeFetcher *fetcher, OstreeFetcherURI *uri, OstreeFetcherRequestFlags flags,
|
||||
const char *if_none_match, guint64 if_modified_since, guint n_network_retries,
|
||||
GBytes **out_contents, gboolean *out_not_modified, char **out_etag, guint64 *out_last_modified,
|
||||
guint64 max_size, GCancellable *cancellable, GError **error);
|
||||
|
||||
void _ostree_fetcher_journal_failure (const char *remote_name,
|
||||
const char *url,
|
||||
const char *msg);
|
||||
void _ostree_fetcher_journal_failure (const char *remote_name, const char *url, const char *msg);
|
||||
|
||||
gboolean _ostree_fetcher_should_retry_request (const GError *error,
|
||||
guint n_retries_remaining);
|
||||
gboolean _ostree_fetcher_should_retry_request (const GError *error, guint n_retries_remaining);
|
||||
|
||||
GIOErrorEnum _ostree_fetcher_http_status_code_to_io_error (guint status_code);
|
||||
|
||||
|
@ -25,141 +25,107 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_FETCHER (_ostree_fetcher_get_type ())
|
||||
#define OSTREE_FETCHER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_FETCHER, OstreeFetcher))
|
||||
#define OSTREE_FETCHER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), OSTREE_TYPE_FETCHER, OstreeFetcherClass))
|
||||
#define OSTREE_IS_FETCHER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_FETCHER))
|
||||
#define OSTREE_IS_FETCHER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_FETCHER))
|
||||
#define OSTREE_FETCHER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_FETCHER, OstreeFetcherClass))
|
||||
#define OSTREE_TYPE_FETCHER (_ostree_fetcher_get_type ())
|
||||
#define OSTREE_FETCHER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_FETCHER, OstreeFetcher))
|
||||
#define OSTREE_FETCHER_CLASS(k) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((k), OSTREE_TYPE_FETCHER, OstreeFetcherClass))
|
||||
#define OSTREE_IS_FETCHER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_FETCHER))
|
||||
#define OSTREE_IS_FETCHER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_FETCHER))
|
||||
#define OSTREE_FETCHER_GET_CLASS(o) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_FETCHER, OstreeFetcherClass))
|
||||
|
||||
/* Lower values have higher priority */
|
||||
#define OSTREE_FETCHER_DEFAULT_PRIORITY 0
|
||||
|
||||
typedef struct OstreeFetcherURI OstreeFetcherURI;
|
||||
|
||||
typedef struct OstreeFetcherClass OstreeFetcherClass;
|
||||
typedef struct OstreeFetcher OstreeFetcher;
|
||||
typedef struct OstreeFetcherClass OstreeFetcherClass;
|
||||
typedef struct OstreeFetcher OstreeFetcher;
|
||||
|
||||
struct OstreeFetcherClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(OstreeFetcher, g_object_unref)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeFetcher, g_object_unref)
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
OSTREE_FETCHER_FLAGS_NONE = 0,
|
||||
OSTREE_FETCHER_FLAGS_TLS_PERMISSIVE = (1 << 0),
|
||||
OSTREE_FETCHER_FLAGS_TRANSFER_GZIP = (1 << 1),
|
||||
OSTREE_FETCHER_FLAGS_DISABLE_HTTP2 = (1 << 2),
|
||||
} OstreeFetcherConfigFlags;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
OSTREE_FETCHER_REQUEST_NUL_TERMINATION = (1 << 0),
|
||||
OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT = (1 << 1),
|
||||
OSTREE_FETCHER_REQUEST_LINKABLE = (1 << 2),
|
||||
} OstreeFetcherRequestFlags;
|
||||
|
||||
void
|
||||
_ostree_fetcher_uri_free (OstreeFetcherURI *uri);
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(OstreeFetcherURI, _ostree_fetcher_uri_free)
|
||||
void _ostree_fetcher_uri_free (OstreeFetcherURI *uri);
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeFetcherURI, _ostree_fetcher_uri_free)
|
||||
|
||||
OstreeFetcherURI *
|
||||
_ostree_fetcher_uri_parse (const char *str,
|
||||
GError **error);
|
||||
OstreeFetcherURI *_ostree_fetcher_uri_parse (const char *str, GError **error);
|
||||
|
||||
OstreeFetcherURI *
|
||||
_ostree_fetcher_uri_clone (OstreeFetcherURI *uri);
|
||||
OstreeFetcherURI *_ostree_fetcher_uri_clone (OstreeFetcherURI *uri);
|
||||
|
||||
OstreeFetcherURI *
|
||||
_ostree_fetcher_uri_new_path (OstreeFetcherURI *uri,
|
||||
const char *subpath);
|
||||
OstreeFetcherURI *_ostree_fetcher_uri_new_path (OstreeFetcherURI *uri, const char *subpath);
|
||||
|
||||
OstreeFetcherURI *
|
||||
_ostree_fetcher_uri_new_subpath (OstreeFetcherURI *uri,
|
||||
const char *subpath);
|
||||
OstreeFetcherURI *_ostree_fetcher_uri_new_subpath (OstreeFetcherURI *uri, const char *subpath);
|
||||
|
||||
char *
|
||||
_ostree_fetcher_uri_get_scheme (OstreeFetcherURI *uri);
|
||||
char *_ostree_fetcher_uri_get_scheme (OstreeFetcherURI *uri);
|
||||
|
||||
char *
|
||||
_ostree_fetcher_uri_get_path (OstreeFetcherURI *uri);
|
||||
char *_ostree_fetcher_uri_get_path (OstreeFetcherURI *uri);
|
||||
|
||||
char *
|
||||
_ostree_fetcher_uri_to_string (OstreeFetcherURI *uri);
|
||||
char *_ostree_fetcher_uri_to_string (OstreeFetcherURI *uri);
|
||||
|
||||
gboolean
|
||||
_ostree_fetcher_uri_validate (OstreeFetcherURI *uri, GError **error);
|
||||
gboolean _ostree_fetcher_uri_validate (OstreeFetcherURI *uri, GError **error);
|
||||
|
||||
GType _ostree_fetcher_get_type (void) G_GNUC_CONST;
|
||||
GType _ostree_fetcher_get_type (void) G_GNUC_CONST;
|
||||
|
||||
OstreeFetcher *_ostree_fetcher_new (int tmpdir_dfd,
|
||||
const char *remote_name,
|
||||
OstreeFetcher *_ostree_fetcher_new (int tmpdir_dfd, const char *remote_name,
|
||||
OstreeFetcherConfigFlags flags);
|
||||
|
||||
int _ostree_fetcher_get_dfd (OstreeFetcher *fetcher);
|
||||
int _ostree_fetcher_get_dfd (OstreeFetcher *fetcher);
|
||||
|
||||
void _ostree_fetcher_set_cookie_jar (OstreeFetcher *self,
|
||||
const char *jar_path);
|
||||
void _ostree_fetcher_set_cookie_jar (OstreeFetcher *self, const char *jar_path);
|
||||
|
||||
void _ostree_fetcher_set_proxy (OstreeFetcher *fetcher,
|
||||
const char *proxy);
|
||||
void _ostree_fetcher_set_proxy (OstreeFetcher *fetcher, const char *proxy);
|
||||
|
||||
void _ostree_fetcher_set_client_cert (OstreeFetcher *fetcher,
|
||||
const char *cert_path,
|
||||
const char *key_path);
|
||||
void _ostree_fetcher_set_client_cert (OstreeFetcher *fetcher, const char *cert_path,
|
||||
const char *key_path);
|
||||
|
||||
void _ostree_fetcher_set_tls_database (OstreeFetcher *self,
|
||||
const char *tlsdb_path);
|
||||
void _ostree_fetcher_set_tls_database (OstreeFetcher *self, const char *tlsdb_path);
|
||||
|
||||
void _ostree_fetcher_set_extra_headers (OstreeFetcher *self,
|
||||
GVariant *extra_headers);
|
||||
void _ostree_fetcher_set_extra_headers (OstreeFetcher *self, GVariant *extra_headers);
|
||||
|
||||
void _ostree_fetcher_set_extra_user_agent (OstreeFetcher *self,
|
||||
const char *extra_user_agent);
|
||||
void _ostree_fetcher_set_extra_user_agent (OstreeFetcher *self, const char *extra_user_agent);
|
||||
|
||||
guint64 _ostree_fetcher_bytes_transferred (OstreeFetcher *self);
|
||||
guint64 _ostree_fetcher_bytes_transferred (OstreeFetcher *self);
|
||||
|
||||
void _ostree_fetcher_request_to_tmpfile (OstreeFetcher *self,
|
||||
GPtrArray *mirrorlist,
|
||||
const char *filename,
|
||||
OstreeFetcherRequestFlags flags,
|
||||
const char *if_none_match,
|
||||
guint64 if_modified_since,
|
||||
guint64 max_size,
|
||||
int priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
void _ostree_fetcher_request_to_tmpfile (OstreeFetcher *self, GPtrArray *mirrorlist,
|
||||
const char *filename, OstreeFetcherRequestFlags flags,
|
||||
const char *if_none_match, guint64 if_modified_since,
|
||||
guint64 max_size, int priority, GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback, gpointer user_data);
|
||||
|
||||
gboolean _ostree_fetcher_request_to_tmpfile_finish (OstreeFetcher *self,
|
||||
GAsyncResult *result,
|
||||
GLnxTmpfile *out_tmpf,
|
||||
gboolean *out_not_modified,
|
||||
char **out_etag,
|
||||
guint64 *out_last_modified,
|
||||
GError **error);
|
||||
gboolean _ostree_fetcher_request_to_tmpfile_finish (OstreeFetcher *self, GAsyncResult *result,
|
||||
GLnxTmpfile *out_tmpf,
|
||||
gboolean *out_not_modified, char **out_etag,
|
||||
guint64 *out_last_modified, GError **error);
|
||||
|
||||
void _ostree_fetcher_request_to_membuf (OstreeFetcher *self,
|
||||
GPtrArray *mirrorlist,
|
||||
const char *filename,
|
||||
OstreeFetcherRequestFlags flags,
|
||||
const char *if_none_match,
|
||||
guint64 if_modified_since,
|
||||
guint64 max_size,
|
||||
int priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
gboolean _ostree_fetcher_request_to_membuf_finish (OstreeFetcher *self,
|
||||
GAsyncResult *result,
|
||||
GBytes **out_buf,
|
||||
gboolean *out_not_modified,
|
||||
char **out_etag,
|
||||
guint64 *out_last_modified,
|
||||
GError **error);
|
||||
void _ostree_fetcher_request_to_membuf (OstreeFetcher *self, GPtrArray *mirrorlist,
|
||||
const char *filename, OstreeFetcherRequestFlags flags,
|
||||
const char *if_none_match, guint64 if_modified_since,
|
||||
guint64 max_size, int priority, GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback, gpointer user_data);
|
||||
|
||||
gboolean _ostree_fetcher_request_to_membuf_finish (OstreeFetcher *self, GAsyncResult *result,
|
||||
GBytes **out_buf, gboolean *out_not_modified,
|
||||
char **out_etag, guint64 *out_last_modified,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -25,18 +25,20 @@
|
||||
|
||||
#include "libglnx.h"
|
||||
#include "ostree-gpg-verifier.h"
|
||||
#include "ot-gpg-utils.h"
|
||||
#include "ostree-gpg-verify-result-private.h"
|
||||
#include "ot-gpg-utils.h"
|
||||
#include "otutil.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
} OstreeGpgVerifierClass;
|
||||
|
||||
struct OstreeGpgVerifier {
|
||||
struct OstreeGpgVerifier
|
||||
{
|
||||
GObject parent;
|
||||
|
||||
GList *keyrings;
|
||||
@ -77,31 +79,28 @@ _ostree_gpg_verifier_init (OstreeGpgVerifier *self)
|
||||
}
|
||||
|
||||
static void
|
||||
verify_result_finalized_cb (gpointer data,
|
||||
GObject *finalized_verify_result)
|
||||
verify_result_finalized_cb (gpointer data, GObject *finalized_verify_result)
|
||||
{
|
||||
g_autofree gchar *tmp_dir = data; /* assume ownership */
|
||||
g_autofree gchar *tmp_dir = data; /* assume ownership */
|
||||
|
||||
/* XXX OstreeGpgVerifyResult could do this cleanup in its own
|
||||
* finalize() method, but I didn't want this keyring hack
|
||||
* bleeding into multiple classes. */
|
||||
|
||||
ot_gpgme_kill_agent (tmp_dir);
|
||||
(void) glnx_shutil_rm_rf_at (AT_FDCWD, tmp_dir, NULL, NULL);
|
||||
(void)glnx_shutil_rm_rf_at (AT_FDCWD, tmp_dir, NULL, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_ostree_gpg_verifier_import_keys (OstreeGpgVerifier *self,
|
||||
gpgme_ctx_t gpgme_ctx,
|
||||
GOutputStream *pubring_stream,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_gpg_verifier_import_keys (OstreeGpgVerifier *self, gpgme_ctx_t gpgme_ctx,
|
||||
GOutputStream *pubring_stream, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
GLNX_AUTO_PREFIX_ERROR("GPG", error);
|
||||
GLNX_AUTO_PREFIX_ERROR ("GPG", error);
|
||||
|
||||
for (GList *link = self->keyrings; link != NULL; link = link->next)
|
||||
{
|
||||
g_autoptr(GFileInputStream) source_stream = NULL;
|
||||
g_autoptr (GFileInputStream) source_stream = NULL;
|
||||
GFile *keyring_file = link->data;
|
||||
gssize bytes_written;
|
||||
GError *local_error = NULL;
|
||||
@ -120,10 +119,9 @@ _ostree_gpg_verifier_import_keys (OstreeGpgVerifier *self,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bytes_written = g_output_stream_splice (pubring_stream,
|
||||
G_INPUT_STREAM (source_stream),
|
||||
G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE,
|
||||
cancellable, error);
|
||||
bytes_written
|
||||
= g_output_stream_splice (pubring_stream, G_INPUT_STREAM (source_stream),
|
||||
G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE, cancellable, error);
|
||||
if (bytes_written < 0)
|
||||
return FALSE;
|
||||
}
|
||||
@ -134,8 +132,7 @@ _ostree_gpg_verifier_import_keys (OstreeGpgVerifier *self,
|
||||
gsize len;
|
||||
gsize bytes_written;
|
||||
const guint8 *buf = g_bytes_get_data (keyringd, &len);
|
||||
if (!g_output_stream_write_all (pubring_stream, buf, len, &bytes_written,
|
||||
cancellable, error))
|
||||
if (!g_output_stream_write_all (pubring_stream, buf, len, &bytes_written, cancellable, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -155,7 +152,7 @@ _ostree_gpg_verifier_import_keys (OstreeGpgVerifier *self,
|
||||
gpgme_error_t gpg_error;
|
||||
const char *path = self->key_ascii_files->pdata[i];
|
||||
glnx_autofd int fd = -1;
|
||||
g_auto(gpgme_data_t) kdata = NULL;
|
||||
g_auto (gpgme_data_t) kdata = NULL;
|
||||
|
||||
if (!glnx_openat_rdonly (AT_FDCWD, path, TRUE, &fd, error))
|
||||
goto out;
|
||||
@ -178,24 +175,21 @@ _ostree_gpg_verifier_import_keys (OstreeGpgVerifier *self,
|
||||
|
||||
ret = TRUE;
|
||||
|
||||
out:
|
||||
out:
|
||||
gpgme_set_armor (gpgme_ctx, armor);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_ostree_gpg_verifier_list_keys (OstreeGpgVerifier *self,
|
||||
const char * const *key_ids,
|
||||
GPtrArray **out_keys,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_gpg_verifier_list_keys (OstreeGpgVerifier *self, const char *const *key_ids,
|
||||
GPtrArray **out_keys, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
GLNX_AUTO_PREFIX_ERROR("GPG", error);
|
||||
g_auto(gpgme_ctx_t) context = NULL;
|
||||
g_autoptr(GOutputStream) pubring_stream = NULL;
|
||||
GLNX_AUTO_PREFIX_ERROR ("GPG", error);
|
||||
g_auto (gpgme_ctx_t) context = NULL;
|
||||
g_autoptr (GOutputStream) pubring_stream = NULL;
|
||||
g_autofree char *tmp_dir = NULL;
|
||||
g_autoptr(GPtrArray) keys = NULL;
|
||||
g_autoptr (GPtrArray) keys = NULL;
|
||||
gpgme_error_t gpg_error = 0;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
@ -206,15 +200,13 @@ _ostree_gpg_verifier_list_keys (OstreeGpgVerifier *self,
|
||||
if (context == NULL)
|
||||
goto out;
|
||||
|
||||
if (!ot_gpgme_ctx_tmp_home_dir (context, &tmp_dir, &pubring_stream,
|
||||
cancellable, error))
|
||||
if (!ot_gpgme_ctx_tmp_home_dir (context, &tmp_dir, &pubring_stream, cancellable, error))
|
||||
goto out;
|
||||
|
||||
if (!_ostree_gpg_verifier_import_keys (self, context, pubring_stream,
|
||||
cancellable, error))
|
||||
if (!_ostree_gpg_verifier_import_keys (self, context, pubring_stream, cancellable, error))
|
||||
goto out;
|
||||
|
||||
keys = g_ptr_array_new_with_free_func ((GDestroyNotify) gpgme_key_unref);
|
||||
keys = g_ptr_array_new_with_free_func ((GDestroyNotify)gpgme_key_unref);
|
||||
if (key_ids != NULL)
|
||||
{
|
||||
for (guint i = 0; key_ids[i] != NULL; i++)
|
||||
@ -224,8 +216,7 @@ _ostree_gpg_verifier_list_keys (OstreeGpgVerifier *self,
|
||||
gpg_error = gpgme_get_key (context, key_ids[i], &key, 0);
|
||||
if (gpg_error != GPG_ERR_NO_ERROR)
|
||||
{
|
||||
ot_gpgme_throw (gpg_error, error, "Unable to find key \"%s\"",
|
||||
key_ids[i]);
|
||||
ot_gpgme_throw (gpg_error, error, "Unable to find key \"%s\"", key_ids[i]);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -260,28 +251,26 @@ _ostree_gpg_verifier_list_keys (OstreeGpgVerifier *self,
|
||||
|
||||
ret = TRUE;
|
||||
|
||||
out:
|
||||
if (tmp_dir != NULL) {
|
||||
ot_gpgme_kill_agent (tmp_dir);
|
||||
(void) glnx_shutil_rm_rf_at (AT_FDCWD, tmp_dir, NULL, NULL);
|
||||
}
|
||||
out:
|
||||
if (tmp_dir != NULL)
|
||||
{
|
||||
ot_gpgme_kill_agent (tmp_dir);
|
||||
(void)glnx_shutil_rm_rf_at (AT_FDCWD, tmp_dir, NULL, NULL);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
OstreeGpgVerifyResult *
|
||||
_ostree_gpg_verifier_check_signature (OstreeGpgVerifier *self,
|
||||
GBytes *signed_data,
|
||||
GBytes *signatures,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_gpg_verifier_check_signature (OstreeGpgVerifier *self, GBytes *signed_data,
|
||||
GBytes *signatures, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
GLNX_AUTO_PREFIX_ERROR("GPG", error);
|
||||
GLNX_AUTO_PREFIX_ERROR ("GPG", error);
|
||||
gpgme_error_t gpg_error = 0;
|
||||
g_auto(gpgme_data_t) data_buffer = NULL;
|
||||
g_auto(gpgme_data_t) signature_buffer = NULL;
|
||||
g_auto (gpgme_data_t) data_buffer = NULL;
|
||||
g_auto (gpgme_data_t) signature_buffer = NULL;
|
||||
g_autofree char *tmp_dir = NULL;
|
||||
g_autoptr(GOutputStream) target_stream = NULL;
|
||||
g_autoptr (GOutputStream) target_stream = NULL;
|
||||
OstreeGpgVerifyResult *result = NULL;
|
||||
gboolean success = FALSE;
|
||||
|
||||
@ -293,38 +282,30 @@ _ostree_gpg_verifier_check_signature (OstreeGpgVerifier *self,
|
||||
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
||||
goto out;
|
||||
|
||||
result = g_initable_new (OSTREE_TYPE_GPG_VERIFY_RESULT,
|
||||
cancellable, error, NULL);
|
||||
result = g_initable_new (OSTREE_TYPE_GPG_VERIFY_RESULT, cancellable, error, NULL);
|
||||
if (result == NULL)
|
||||
goto out;
|
||||
|
||||
if (!ot_gpgme_ctx_tmp_home_dir (result->context,
|
||||
&tmp_dir, &target_stream,
|
||||
cancellable, error))
|
||||
if (!ot_gpgme_ctx_tmp_home_dir (result->context, &tmp_dir, &target_stream, cancellable, error))
|
||||
goto out;
|
||||
|
||||
if (!_ostree_gpg_verifier_import_keys (self, result->context, target_stream,
|
||||
cancellable, error))
|
||||
if (!_ostree_gpg_verifier_import_keys (self, result->context, target_stream, cancellable, error))
|
||||
goto out;
|
||||
|
||||
/* Both the signed data and signature GBytes instances will outlive the
|
||||
* gpgme_data_t structs, so we can safely reuse the GBytes memory buffer
|
||||
* directly and avoid a copy. */
|
||||
|
||||
gpg_error = gpgme_data_new_from_mem (&data_buffer,
|
||||
g_bytes_get_data (signed_data, NULL),
|
||||
g_bytes_get_size (signed_data),
|
||||
0 /* do not copy */);
|
||||
gpg_error = gpgme_data_new_from_mem (&data_buffer, g_bytes_get_data (signed_data, NULL),
|
||||
g_bytes_get_size (signed_data), 0 /* do not copy */);
|
||||
if (gpg_error != GPG_ERR_NO_ERROR)
|
||||
{
|
||||
ot_gpgme_throw (gpg_error, error, "Unable to read signed data");
|
||||
goto out;
|
||||
}
|
||||
|
||||
gpg_error = gpgme_data_new_from_mem (&signature_buffer,
|
||||
g_bytes_get_data (signatures, NULL),
|
||||
g_bytes_get_size (signatures),
|
||||
0 /* do not copy */);
|
||||
gpg_error = gpgme_data_new_from_mem (&signature_buffer, g_bytes_get_data (signatures, NULL),
|
||||
g_bytes_get_size (signatures), 0 /* do not copy */);
|
||||
if (gpg_error != GPG_ERR_NO_ERROR)
|
||||
{
|
||||
ot_gpgme_throw (gpg_error, error, "Unable to read signature");
|
||||
@ -352,9 +333,7 @@ out:
|
||||
* object so its GPGME context remains valid. It may yet have to
|
||||
* extract user details from signing keys and will need to access
|
||||
* the fabricated pubring.gpg keyring. */
|
||||
g_object_weak_ref (G_OBJECT (result),
|
||||
verify_result_finalized_cb,
|
||||
g_strdup (tmp_dir));
|
||||
g_object_weak_ref (G_OBJECT (result), verify_result_finalized_cb, g_strdup (tmp_dir));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -363,7 +342,7 @@ out:
|
||||
|
||||
/* Try to clean up the temporary directory. */
|
||||
if (tmp_dir != NULL)
|
||||
(void) glnx_shutil_rm_rf_at (AT_FDCWD, tmp_dir, NULL, NULL);
|
||||
(void)glnx_shutil_rm_rf_at (AT_FDCWD, tmp_dir, NULL, NULL);
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -373,8 +352,7 @@ out:
|
||||
* to the list of trusted keys.
|
||||
*/
|
||||
void
|
||||
_ostree_gpg_verifier_add_keyring_file (OstreeGpgVerifier *self,
|
||||
GFile *path)
|
||||
_ostree_gpg_verifier_add_keyring_file (OstreeGpgVerifier *self, GFile *path)
|
||||
{
|
||||
g_return_if_fail (G_IS_FILE (path));
|
||||
|
||||
@ -388,9 +366,8 @@ _ostree_gpg_verifier_add_keyring_file (OstreeGpgVerifier *self,
|
||||
* the list of trusted keys.
|
||||
*/
|
||||
void
|
||||
_ostree_gpg_verifier_add_keyring_data (OstreeGpgVerifier *self,
|
||||
GBytes *keyring,
|
||||
const char *data_source)
|
||||
_ostree_gpg_verifier_add_keyring_data (OstreeGpgVerifier *self, GBytes *keyring,
|
||||
const char *data_source)
|
||||
{
|
||||
g_debug ("Adding GPG keyring data from %s to verifier", data_source);
|
||||
|
||||
@ -398,8 +375,7 @@ _ostree_gpg_verifier_add_keyring_data (OstreeGpgVerifier *self,
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_gpg_verifier_add_key_ascii_file (OstreeGpgVerifier *self,
|
||||
const char *path)
|
||||
_ostree_gpg_verifier_add_key_ascii_file (OstreeGpgVerifier *self, const char *path)
|
||||
{
|
||||
g_debug ("Adding GPG key ASCII file %s to verifier", path);
|
||||
|
||||
@ -409,14 +385,11 @@ _ostree_gpg_verifier_add_key_ascii_file (OstreeGpgVerifier *self,
|
||||
}
|
||||
|
||||
gboolean
|
||||
_ostree_gpg_verifier_add_keyfile_path (OstreeGpgVerifier *self,
|
||||
const char *path,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_gpg_verifier_add_keyfile_path (OstreeGpgVerifier *self, const char *path,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
g_autoptr(GError) temp_error = NULL;
|
||||
if (!_ostree_gpg_verifier_add_keyfile_dir_at (self, AT_FDCWD, path,
|
||||
cancellable, &temp_error))
|
||||
g_autoptr (GError) temp_error = NULL;
|
||||
if (!_ostree_gpg_verifier_add_keyfile_dir_at (self, AT_FDCWD, path, cancellable, &temp_error))
|
||||
{
|
||||
g_assert (temp_error);
|
||||
|
||||
@ -442,16 +415,14 @@ _ostree_gpg_verifier_add_keyfile_path (OstreeGpgVerifier *self,
|
||||
* an error is returned.
|
||||
*/
|
||||
gboolean
|
||||
_ostree_gpg_verifier_add_keyfile_dir_at (OstreeGpgVerifier *self,
|
||||
int dfd,
|
||||
const char *path,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_gpg_verifier_add_keyfile_dir_at (OstreeGpgVerifier *self, int dfd, const char *path,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
g_auto(GLnxDirFdIterator) dfd_iter = { 0, };
|
||||
g_auto (GLnxDirFdIterator) dfd_iter = {
|
||||
0,
|
||||
};
|
||||
|
||||
if (!glnx_dirfd_iterator_init_at (dfd, path, FALSE,
|
||||
&dfd_iter, error))
|
||||
if (!glnx_dirfd_iterator_init_at (dfd, path, FALSE, &dfd_iter, error))
|
||||
return FALSE;
|
||||
|
||||
g_debug ("Adding GPG keyfile dir %s to verifier", path);
|
||||
@ -460,8 +431,7 @@ _ostree_gpg_verifier_add_keyfile_dir_at (OstreeGpgVerifier *self,
|
||||
{
|
||||
struct dirent *dent;
|
||||
|
||||
if (!glnx_dirfd_iterator_next_dent_ensure_dtype (&dfd_iter, &dent,
|
||||
cancellable, error))
|
||||
if (!glnx_dirfd_iterator_next_dent_ensure_dtype (&dfd_iter, &dent, cancellable, error))
|
||||
return FALSE;
|
||||
if (dent == NULL)
|
||||
break;
|
||||
@ -480,26 +450,21 @@ _ostree_gpg_verifier_add_keyfile_dir_at (OstreeGpgVerifier *self,
|
||||
}
|
||||
|
||||
gboolean
|
||||
_ostree_gpg_verifier_add_keyring_dir (OstreeGpgVerifier *self,
|
||||
GFile *path,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_gpg_verifier_add_keyring_dir (OstreeGpgVerifier *self, GFile *path,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
return _ostree_gpg_verifier_add_keyring_dir_at (self, AT_FDCWD,
|
||||
gs_file_get_path_cached (path),
|
||||
return _ostree_gpg_verifier_add_keyring_dir_at (self, AT_FDCWD, gs_file_get_path_cached (path),
|
||||
cancellable, error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
_ostree_gpg_verifier_add_keyring_dir_at (OstreeGpgVerifier *self,
|
||||
int dfd,
|
||||
const char *path,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_gpg_verifier_add_keyring_dir_at (OstreeGpgVerifier *self, int dfd, const char *path,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
g_auto(GLnxDirFdIterator) dfd_iter = { 0, };
|
||||
if (!glnx_dirfd_iterator_init_at (dfd, path, FALSE,
|
||||
&dfd_iter, error))
|
||||
g_auto (GLnxDirFdIterator) dfd_iter = {
|
||||
0,
|
||||
};
|
||||
if (!glnx_dirfd_iterator_init_at (dfd, path, FALSE, &dfd_iter, error))
|
||||
return FALSE;
|
||||
|
||||
g_debug ("Adding GPG keyring dir %s to verifier", path);
|
||||
@ -534,7 +499,7 @@ _ostree_gpg_verifier_add_keyring_dir_at (OstreeGpgVerifier *self,
|
||||
if (!glnx_openat_rdonly (dfd_iter.fd, dent->d_name, TRUE, &fd, error))
|
||||
return FALSE;
|
||||
|
||||
g_autoptr(GBytes) data = glnx_fd_readall_bytes (fd, cancellable, error);
|
||||
g_autoptr (GBytes) data = glnx_fd_readall_bytes (fd, cancellable, error);
|
||||
if (!data)
|
||||
return FALSE;
|
||||
|
||||
@ -545,9 +510,8 @@ _ostree_gpg_verifier_add_keyring_dir_at (OstreeGpgVerifier *self,
|
||||
}
|
||||
|
||||
gboolean
|
||||
_ostree_gpg_verifier_add_global_keyring_dir (OstreeGpgVerifier *self,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_gpg_verifier_add_global_keyring_dir (OstreeGpgVerifier *self, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
g_assert (OSTREE_IS_GPG_VERIFIER (self));
|
||||
|
||||
@ -557,9 +521,8 @@ _ostree_gpg_verifier_add_global_keyring_dir (OstreeGpgVerifier *self,
|
||||
|
||||
if (g_file_test (global_keyring_path, G_FILE_TEST_IS_DIR))
|
||||
{
|
||||
g_autoptr(GFile) global_keyring_dir = g_file_new_for_path (global_keyring_path);
|
||||
if (!_ostree_gpg_verifier_add_keyring_dir (self, global_keyring_dir,
|
||||
cancellable, error))
|
||||
g_autoptr (GFile) global_keyring_dir = g_file_new_for_path (global_keyring_path);
|
||||
if (!_ostree_gpg_verifier_add_keyring_dir (self, global_keyring_dir, cancellable, error))
|
||||
return glnx_prefix_error (error, "Reading keyring directory '%s'",
|
||||
gs_file_get_path_cached (global_keyring_dir));
|
||||
}
|
||||
@ -567,7 +530,7 @@ _ostree_gpg_verifier_add_global_keyring_dir (OstreeGpgVerifier *self,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
OstreeGpgVerifier*
|
||||
OstreeGpgVerifier *
|
||||
_ostree_gpg_verifier_new (void)
|
||||
{
|
||||
return g_object_new (OSTREE_TYPE_GPG_VERIFIER, NULL);
|
||||
|
@ -20,17 +20,16 @@
|
||||
* Author: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
|
||||
*/
|
||||
|
||||
//#pragma once
|
||||
// #pragma once
|
||||
|
||||
#include "ostree-gpg-verify-result.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_GPG_VERIFIER _ostree_gpg_verifier_get_type()
|
||||
#define OSTREE_TYPE_GPG_VERIFIER _ostree_gpg_verifier_get_type ()
|
||||
#define OSTREE_GPG_VERIFIER(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), OSTREE_TYPE_GPG_VERIFIER, OstreeGpgVerifier))
|
||||
#define OSTREE_IS_GPG_VERIFIER(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSTREE_TYPE_GPG_VERIFIER))
|
||||
#define OSTREE_IS_GPG_VERIFIER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSTREE_TYPE_GPG_VERIFIER))
|
||||
|
||||
typedef struct OstreeGpgVerifier OstreeGpgVerifier;
|
||||
|
||||
@ -44,52 +43,36 @@ GType _ostree_gpg_verifier_get_type (void);
|
||||
OstreeGpgVerifier *_ostree_gpg_verifier_new (void);
|
||||
|
||||
OstreeGpgVerifyResult *_ostree_gpg_verifier_check_signature (OstreeGpgVerifier *self,
|
||||
GBytes *signed_data,
|
||||
GBytes *signatures,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
GBytes *signed_data,
|
||||
GBytes *signatures,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
gboolean _ostree_gpg_verifier_list_keys (OstreeGpgVerifier *self,
|
||||
const char * const *key_ids,
|
||||
GPtrArray **out_keys,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean _ostree_gpg_verifier_list_keys (OstreeGpgVerifier *self, const char *const *key_ids,
|
||||
GPtrArray **out_keys, GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
gboolean _ostree_gpg_verifier_add_keyring_dir (OstreeGpgVerifier *self,
|
||||
GFile *path,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean _ostree_gpg_verifier_add_keyring_dir (OstreeGpgVerifier *self, GFile *path,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
gboolean _ostree_gpg_verifier_add_keyring_dir_at (OstreeGpgVerifier *self,
|
||||
int dfd,
|
||||
const char *path,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean _ostree_gpg_verifier_add_keyring_dir_at (OstreeGpgVerifier *self, int dfd,
|
||||
const char *path, GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
gboolean _ostree_gpg_verifier_add_global_keyring_dir (OstreeGpgVerifier *self,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean _ostree_gpg_verifier_add_global_keyring_dir (OstreeGpgVerifier *self,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
void _ostree_gpg_verifier_add_keyring_data (OstreeGpgVerifier *self,
|
||||
GBytes *data,
|
||||
const char *data_source);
|
||||
void _ostree_gpg_verifier_add_keyring_file (OstreeGpgVerifier *self,
|
||||
GFile *path);
|
||||
void _ostree_gpg_verifier_add_keyring_data (OstreeGpgVerifier *self, GBytes *data,
|
||||
const char *data_source);
|
||||
void _ostree_gpg_verifier_add_keyring_file (OstreeGpgVerifier *self, GFile *path);
|
||||
|
||||
void _ostree_gpg_verifier_add_key_ascii_file (OstreeGpgVerifier *self,
|
||||
const char *path);
|
||||
void _ostree_gpg_verifier_add_key_ascii_file (OstreeGpgVerifier *self, const char *path);
|
||||
|
||||
gboolean
|
||||
_ostree_gpg_verifier_add_keyfile_path (OstreeGpgVerifier *self,
|
||||
const char *path,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean _ostree_gpg_verifier_add_keyfile_path (OstreeGpgVerifier *self, const char *path,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
gboolean
|
||||
_ostree_gpg_verifier_add_keyfile_dir_at (OstreeGpgVerifier *self,
|
||||
int dfd,
|
||||
const char *path,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean _ostree_gpg_verifier_add_keyfile_dir_at (OstreeGpgVerifier *self, int dfd,
|
||||
const char *path, GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -42,20 +42,19 @@
|
||||
*
|
||||
* Private instance structure.
|
||||
*/
|
||||
struct OstreeGpgVerifyResult {
|
||||
struct OstreeGpgVerifyResult
|
||||
{
|
||||
GObject parent;
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
} OstreeGpgVerifyResultClass;
|
||||
|
||||
static void ostree_gpg_verify_result_initable_iface_init (GInitableIface *iface);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (OstreeGpgVerifyResult,
|
||||
ostree_gpg_verify_result,
|
||||
G_TYPE_OBJECT,
|
||||
G_DEFINE_TYPE_WITH_CODE (OstreeGpgVerifyResult, ostree_gpg_verify_result, G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
|
||||
ostree_gpg_verify_result_initable_iface_init))
|
||||
|
||||
@ -120,8 +119,7 @@ ostree_gpg_verify_result_count_valid (OstreeGpgVerifyResult *result)
|
||||
* Returns: %TRUE on success, %FALSE on failure
|
||||
**/
|
||||
gboolean
|
||||
ostree_gpg_verify_result_lookup (OstreeGpgVerifyResult *result,
|
||||
const gchar *key_id,
|
||||
ostree_gpg_verify_result_lookup (OstreeGpgVerifyResult *result, const gchar *key_id,
|
||||
guint *out_signature_index)
|
||||
{
|
||||
g_critical ("%s: GPG feature is disabled in a build time", __FUNCTION__);
|
||||
@ -146,10 +144,8 @@ ostree_gpg_verify_result_lookup (OstreeGpgVerifyResult *result,
|
||||
* Returns: (transfer floating): a new, floating, #GVariant tuple
|
||||
**/
|
||||
GVariant *
|
||||
ostree_gpg_verify_result_get (OstreeGpgVerifyResult *result,
|
||||
guint signature_index,
|
||||
OstreeGpgSignatureAttr *attrs,
|
||||
guint n_attrs)
|
||||
ostree_gpg_verify_result_get (OstreeGpgVerifyResult *result, guint signature_index,
|
||||
OstreeGpgSignatureAttr *attrs, guint n_attrs)
|
||||
{
|
||||
g_critical ("%s: GPG feature is disabled in a build time", __FUNCTION__);
|
||||
return NULL;
|
||||
@ -187,8 +183,7 @@ ostree_gpg_verify_result_get (OstreeGpgVerifyResult *result,
|
||||
* Returns: (transfer floating): a new, floating, #GVariant tuple
|
||||
**/
|
||||
GVariant *
|
||||
ostree_gpg_verify_result_get_all (OstreeGpgVerifyResult *result,
|
||||
guint signature_index)
|
||||
ostree_gpg_verify_result_get_all (OstreeGpgVerifyResult *result, guint signature_index)
|
||||
{
|
||||
g_return_val_if_fail (OSTREE_IS_GPG_VERIFY_RESULT (result), NULL);
|
||||
|
||||
@ -217,13 +212,11 @@ ostree_gpg_verify_result_get_all (OstreeGpgVerifyResult *result,
|
||||
* @result.
|
||||
*/
|
||||
void
|
||||
ostree_gpg_verify_result_describe (OstreeGpgVerifyResult *result,
|
||||
guint signature_index,
|
||||
GString *output_buffer,
|
||||
const gchar *line_prefix,
|
||||
ostree_gpg_verify_result_describe (OstreeGpgVerifyResult *result, guint signature_index,
|
||||
GString *output_buffer, const gchar *line_prefix,
|
||||
OstreeGpgSignatureFormatFlags flags)
|
||||
{
|
||||
g_autoptr(GVariant) variant = NULL;
|
||||
g_autoptr (GVariant) variant = NULL;
|
||||
|
||||
g_return_if_fail (OSTREE_IS_GPG_VERIFY_RESULT (result));
|
||||
|
||||
@ -249,8 +242,7 @@ ostree_gpg_verify_result_describe (OstreeGpgVerifyResult *result,
|
||||
* ostree_gpg_verify_result_get_all().
|
||||
*/
|
||||
void
|
||||
ostree_gpg_verify_result_describe_variant (GVariant *variant,
|
||||
GString *output_buffer,
|
||||
ostree_gpg_verify_result_describe_variant (GVariant *variant, GString *output_buffer,
|
||||
const gchar *line_prefix,
|
||||
OstreeGpgSignatureFormatFlags flags)
|
||||
{
|
||||
@ -264,8 +256,7 @@ ostree_gpg_verify_result_describe_variant (GVariant *variant,
|
||||
type_string = g_variant_get_type_string (variant);
|
||||
g_return_if_fail (strcmp (type_string, "(bbbbbsxxsssssxx)") == 0);
|
||||
|
||||
g_string_append (output_buffer,
|
||||
"GPG feature is disabled in a build time\n");
|
||||
g_string_append (output_buffer, "GPG feature is disabled in a build time\n");
|
||||
|
||||
g_critical ("%s: GPG feature is disabled in a build time", __FUNCTION__);
|
||||
}
|
||||
@ -286,15 +277,13 @@ ostree_gpg_verify_result_describe_variant (GVariant *variant,
|
||||
* Since: 2016.6
|
||||
*/
|
||||
gboolean
|
||||
ostree_gpg_verify_result_require_valid_signature (OstreeGpgVerifyResult *result,
|
||||
GError **error)
|
||||
ostree_gpg_verify_result_require_valid_signature (OstreeGpgVerifyResult *result, GError **error)
|
||||
{
|
||||
if (result == NULL)
|
||||
return FALSE;
|
||||
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||
"'%s': GPG feature is disabled in a build time",
|
||||
__FUNCTION__);
|
||||
"'%s': GPG feature is disabled in a build time", __FUNCTION__);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,8 @@
|
||||
*
|
||||
* Private instance structure.
|
||||
*/
|
||||
struct OstreeGpgVerifyResult {
|
||||
struct OstreeGpgVerifyResult
|
||||
{
|
||||
GObject parent;
|
||||
|
||||
gpgme_ctx_t context;
|
||||
|
@ -45,7 +45,8 @@
|
||||
* or get all signature details with ostree_gpg_verify_result_get_all().
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
} OstreeGpgVerifyResultClass;
|
||||
|
||||
@ -70,9 +71,7 @@ static OstreeGpgSignatureAttr all_signature_attrs[] = {
|
||||
|
||||
static void ostree_gpg_verify_result_initable_iface_init (GInitableIface *iface);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (OstreeGpgVerifyResult,
|
||||
ostree_gpg_verify_result,
|
||||
G_TYPE_OBJECT,
|
||||
G_DEFINE_TYPE_WITH_CODE (OstreeGpgVerifyResult, ostree_gpg_verify_result, G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
|
||||
ostree_gpg_verify_result_initable_iface_init))
|
||||
|
||||
@ -87,9 +86,8 @@ signature_is_valid (gpgme_signature_t signature)
|
||||
* - No summary but also no error means the signature is valid but
|
||||
* the signing key is not certified with a trusted signature.
|
||||
*/
|
||||
return (signature->summary & GPGME_SIGSUM_VALID) ||
|
||||
(signature->summary & GPGME_SIGSUM_GREEN) ||
|
||||
(signature->summary == 0 && signature->status == GPG_ERR_NO_ERROR);
|
||||
return (signature->summary & GPGME_SIGSUM_VALID) || (signature->summary & GPGME_SIGSUM_GREEN)
|
||||
|| (signature->summary == 0 && signature->status == GPG_ERR_NO_ERROR);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -104,9 +102,9 @@ signing_key_is_revoked (gpgme_signature_t signature)
|
||||
* Reported to GPGME: https://bugs.g10code.com/gnupg/issue1929
|
||||
*/
|
||||
|
||||
return (signature->summary & GPGME_SIGSUM_KEY_REVOKED) ||
|
||||
((signature->summary & GPGME_SIGSUM_SYS_ERROR) &&
|
||||
gpgme_err_code (signature->status) == GPG_ERR_CERT_REVOKED);
|
||||
return (signature->summary & GPGME_SIGSUM_KEY_REVOKED)
|
||||
|| ((signature->summary & GPGME_SIGSUM_SYS_ERROR)
|
||||
&& gpgme_err_code (signature->status) == GPG_ERR_CERT_REVOKED);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -124,9 +122,8 @@ ostree_gpg_verify_result_finalize (GObject *object)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ostree_gpg_verify_result_initable_init (GInitable *initable,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_gpg_verify_result_initable_init (GInitable *initable, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
OstreeGpgVerifyResult *result = OSTREE_GPG_VERIFY_RESULT (initable);
|
||||
gpgme_error_t gpg_error;
|
||||
@ -181,9 +178,7 @@ ostree_gpg_verify_result_count_all (OstreeGpgVerifyResult *result)
|
||||
|
||||
g_return_val_if_fail (OSTREE_IS_GPG_VERIFY_RESULT (result), 0);
|
||||
|
||||
for (signature = result->details->signatures;
|
||||
signature != NULL;
|
||||
signature = signature->next)
|
||||
for (signature = result->details->signatures; signature != NULL; signature = signature->next)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
@ -207,9 +202,7 @@ ostree_gpg_verify_result_count_valid (OstreeGpgVerifyResult *result)
|
||||
|
||||
g_return_val_if_fail (OSTREE_IS_GPG_VERIFY_RESULT (result), 0);
|
||||
|
||||
for (signature = result->details->signatures;
|
||||
signature != NULL;
|
||||
signature = signature->next)
|
||||
for (signature = result->details->signatures; signature != NULL; signature = signature->next)
|
||||
{
|
||||
if (signature_is_valid (signature))
|
||||
count++;
|
||||
@ -234,11 +227,10 @@ ostree_gpg_verify_result_count_valid (OstreeGpgVerifyResult *result)
|
||||
* Returns: %TRUE on success, %FALSE on failure
|
||||
**/
|
||||
gboolean
|
||||
ostree_gpg_verify_result_lookup (OstreeGpgVerifyResult *result,
|
||||
const gchar *key_id,
|
||||
ostree_gpg_verify_result_lookup (OstreeGpgVerifyResult *result, const gchar *key_id,
|
||||
guint *out_signature_index)
|
||||
{
|
||||
g_auto(gpgme_key_t) lookup_key = NULL;
|
||||
g_auto (gpgme_key_t) lookup_key = NULL;
|
||||
gpgme_signature_t signature;
|
||||
guint signature_index;
|
||||
|
||||
@ -246,7 +238,7 @@ ostree_gpg_verify_result_lookup (OstreeGpgVerifyResult *result,
|
||||
g_return_val_if_fail (key_id != NULL, FALSE);
|
||||
|
||||
/* fetch requested key_id from keyring to canonicalise ID */
|
||||
(void) gpgme_get_key (result->context, key_id, &lookup_key, 0);
|
||||
(void)gpgme_get_key (result->context, key_id, &lookup_key, 0);
|
||||
|
||||
if (lookup_key == NULL)
|
||||
{
|
||||
@ -254,13 +246,12 @@ ostree_gpg_verify_result_lookup (OstreeGpgVerifyResult *result,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (signature = result->details->signatures, signature_index = 0;
|
||||
signature != NULL;
|
||||
for (signature = result->details->signatures, signature_index = 0; signature != NULL;
|
||||
signature = signature->next, signature_index++)
|
||||
{
|
||||
g_auto(gpgme_key_t) signature_key = NULL;
|
||||
g_auto (gpgme_key_t) signature_key = NULL;
|
||||
|
||||
(void) gpgme_get_key (result->context, signature->fpr, &signature_key, 0);
|
||||
(void)gpgme_get_key (result->context, signature->fpr, &signature_key, 0);
|
||||
|
||||
if (signature_key == NULL)
|
||||
{
|
||||
@ -269,15 +260,13 @@ ostree_gpg_verify_result_lookup (OstreeGpgVerifyResult *result,
|
||||
}
|
||||
|
||||
/* the first subkey in the list is the primary key */
|
||||
if (!g_strcmp0 (lookup_key->subkeys->fpr,
|
||||
signature_key->subkeys->fpr))
|
||||
if (!g_strcmp0 (lookup_key->subkeys->fpr, signature_key->subkeys->fpr))
|
||||
{
|
||||
if (out_signature_index != NULL)
|
||||
*out_signature_index = signature_index;
|
||||
/* Note early return */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
@ -301,13 +290,11 @@ ostree_gpg_verify_result_lookup (OstreeGpgVerifyResult *result,
|
||||
* Returns: (transfer floating): a new, floating, #GVariant tuple
|
||||
**/
|
||||
GVariant *
|
||||
ostree_gpg_verify_result_get (OstreeGpgVerifyResult *result,
|
||||
guint signature_index,
|
||||
OstreeGpgSignatureAttr *attrs,
|
||||
guint n_attrs)
|
||||
ostree_gpg_verify_result_get (OstreeGpgVerifyResult *result, guint signature_index,
|
||||
OstreeGpgSignatureAttr *attrs, guint n_attrs)
|
||||
{
|
||||
GVariantBuilder builder;
|
||||
g_auto(gpgme_key_t) key = NULL;
|
||||
g_auto (gpgme_key_t) key = NULL;
|
||||
gpgme_signature_t signature;
|
||||
guint ii;
|
||||
|
||||
@ -329,13 +316,13 @@ ostree_gpg_verify_result_get (OstreeGpgVerifyResult *result,
|
||||
* (OSTREE_GPG_SIGNATURE_ATTR_KEY_MISSING). */
|
||||
for (ii = 0; ii < n_attrs; ii++)
|
||||
{
|
||||
if (attrs[ii] == OSTREE_GPG_SIGNATURE_ATTR_USER_NAME ||
|
||||
attrs[ii] == OSTREE_GPG_SIGNATURE_ATTR_USER_EMAIL ||
|
||||
attrs[ii] == OSTREE_GPG_SIGNATURE_ATTR_FINGERPRINT_PRIMARY ||
|
||||
attrs[ii] == OSTREE_GPG_SIGNATURE_ATTR_KEY_EXP_TIMESTAMP ||
|
||||
attrs[ii] == OSTREE_GPG_SIGNATURE_ATTR_KEY_EXP_TIMESTAMP_PRIMARY)
|
||||
if (attrs[ii] == OSTREE_GPG_SIGNATURE_ATTR_USER_NAME
|
||||
|| attrs[ii] == OSTREE_GPG_SIGNATURE_ATTR_USER_EMAIL
|
||||
|| attrs[ii] == OSTREE_GPG_SIGNATURE_ATTR_FINGERPRINT_PRIMARY
|
||||
|| attrs[ii] == OSTREE_GPG_SIGNATURE_ATTR_KEY_EXP_TIMESTAMP
|
||||
|| attrs[ii] == OSTREE_GPG_SIGNATURE_ATTR_KEY_EXP_TIMESTAMP_PRIMARY)
|
||||
{
|
||||
(void) gpgme_get_key (result->context, signature->fpr, &key, 0);
|
||||
(void)gpgme_get_key (result->context, signature->fpr, &key, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -351,108 +338,108 @@ ostree_gpg_verify_result_get (OstreeGpgVerifyResult *result,
|
||||
|
||||
switch (attrs[ii])
|
||||
{
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_VALID:
|
||||
v_boolean = signature_is_valid (signature);
|
||||
child = g_variant_new_boolean (v_boolean);
|
||||
break;
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_VALID:
|
||||
v_boolean = signature_is_valid (signature);
|
||||
child = g_variant_new_boolean (v_boolean);
|
||||
break;
|
||||
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_SIG_EXPIRED:
|
||||
v_boolean = ((signature->summary & GPGME_SIGSUM_SIG_EXPIRED) != 0);
|
||||
child = g_variant_new_boolean (v_boolean);
|
||||
break;
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_SIG_EXPIRED:
|
||||
v_boolean = ((signature->summary & GPGME_SIGSUM_SIG_EXPIRED) != 0);
|
||||
child = g_variant_new_boolean (v_boolean);
|
||||
break;
|
||||
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_KEY_EXPIRED:
|
||||
v_boolean = ((signature->summary & GPGME_SIGSUM_KEY_EXPIRED) != 0);
|
||||
child = g_variant_new_boolean (v_boolean);
|
||||
break;
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_KEY_EXPIRED:
|
||||
v_boolean = ((signature->summary & GPGME_SIGSUM_KEY_EXPIRED) != 0);
|
||||
child = g_variant_new_boolean (v_boolean);
|
||||
break;
|
||||
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_KEY_REVOKED:
|
||||
v_boolean = signing_key_is_revoked (signature);
|
||||
child = g_variant_new_boolean (v_boolean);
|
||||
break;
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_KEY_REVOKED:
|
||||
v_boolean = signing_key_is_revoked (signature);
|
||||
child = g_variant_new_boolean (v_boolean);
|
||||
break;
|
||||
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_KEY_MISSING:
|
||||
v_boolean = ((signature->summary & GPGME_SIGSUM_KEY_MISSING) != 0);
|
||||
child = g_variant_new_boolean (v_boolean);
|
||||
break;
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_KEY_MISSING:
|
||||
v_boolean = ((signature->summary & GPGME_SIGSUM_KEY_MISSING) != 0);
|
||||
child = g_variant_new_boolean (v_boolean);
|
||||
break;
|
||||
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_FINGERPRINT:
|
||||
child = g_variant_new_string (signature->fpr);
|
||||
break;
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_FINGERPRINT:
|
||||
child = g_variant_new_string (signature->fpr);
|
||||
break;
|
||||
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_TIMESTAMP:
|
||||
child = g_variant_new_int64 ((gint64) signature->timestamp);
|
||||
break;
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_TIMESTAMP:
|
||||
child = g_variant_new_int64 ((gint64)signature->timestamp);
|
||||
break;
|
||||
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_EXP_TIMESTAMP:
|
||||
child = g_variant_new_int64 ((gint64) signature->exp_timestamp);
|
||||
break;
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_EXP_TIMESTAMP:
|
||||
child = g_variant_new_int64 ((gint64)signature->exp_timestamp);
|
||||
break;
|
||||
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_PUBKEY_ALGO_NAME:
|
||||
v_string = gpgme_pubkey_algo_name (signature->pubkey_algo);
|
||||
if (v_string == NULL)
|
||||
v_string = "[unknown name]";
|
||||
child = g_variant_new_string (v_string);
|
||||
break;
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_PUBKEY_ALGO_NAME:
|
||||
v_string = gpgme_pubkey_algo_name (signature->pubkey_algo);
|
||||
if (v_string == NULL)
|
||||
v_string = "[unknown name]";
|
||||
child = g_variant_new_string (v_string);
|
||||
break;
|
||||
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_HASH_ALGO_NAME:
|
||||
v_string = gpgme_hash_algo_name (signature->hash_algo);
|
||||
if (v_string == NULL)
|
||||
v_string = "[unknown name]";
|
||||
child = g_variant_new_string (v_string);
|
||||
break;
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_HASH_ALGO_NAME:
|
||||
v_string = gpgme_hash_algo_name (signature->hash_algo);
|
||||
if (v_string == NULL)
|
||||
v_string = "[unknown name]";
|
||||
child = g_variant_new_string (v_string);
|
||||
break;
|
||||
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_USER_NAME:
|
||||
if (key != NULL && key->uids != NULL)
|
||||
v_string = key->uids->name;
|
||||
if (v_string == NULL)
|
||||
v_string = "[unknown name]";
|
||||
child = g_variant_new_string (v_string);
|
||||
break;
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_USER_NAME:
|
||||
if (key != NULL && key->uids != NULL)
|
||||
v_string = key->uids->name;
|
||||
if (v_string == NULL)
|
||||
v_string = "[unknown name]";
|
||||
child = g_variant_new_string (v_string);
|
||||
break;
|
||||
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_USER_EMAIL:
|
||||
if (key != NULL && key->uids != NULL)
|
||||
v_string = key->uids->email;
|
||||
if (v_string == NULL)
|
||||
v_string = "[unknown email]";
|
||||
child = g_variant_new_string (v_string);
|
||||
break;
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_USER_EMAIL:
|
||||
if (key != NULL && key->uids != NULL)
|
||||
v_string = key->uids->email;
|
||||
if (v_string == NULL)
|
||||
v_string = "[unknown email]";
|
||||
child = g_variant_new_string (v_string);
|
||||
break;
|
||||
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_FINGERPRINT_PRIMARY:
|
||||
if (key != NULL && key->subkeys != NULL)
|
||||
v_string = key->subkeys->fpr;
|
||||
if (v_string == NULL)
|
||||
v_string = "";
|
||||
child = g_variant_new_string (v_string);
|
||||
break;
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_FINGERPRINT_PRIMARY:
|
||||
if (key != NULL && key->subkeys != NULL)
|
||||
v_string = key->subkeys->fpr;
|
||||
if (v_string == NULL)
|
||||
v_string = "";
|
||||
child = g_variant_new_string (v_string);
|
||||
break;
|
||||
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_KEY_EXP_TIMESTAMP:
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_KEY_EXP_TIMESTAMP:
|
||||
v_int64 = 0;
|
||||
if (key != NULL)
|
||||
{
|
||||
gpgme_subkey_t subkey = key->subkeys;
|
||||
|
||||
while (subkey != NULL && (g_strcmp0 (subkey->fpr, signature->fpr) != 0))
|
||||
subkey = subkey->next;
|
||||
|
||||
if (subkey != NULL)
|
||||
v_int64 = subkey->expires;
|
||||
}
|
||||
child = g_variant_new_int64 (v_int64);
|
||||
break;
|
||||
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_KEY_EXP_TIMESTAMP_PRIMARY:
|
||||
if (key != NULL && key->subkeys != NULL)
|
||||
v_int64 = key->subkeys->expires;
|
||||
else
|
||||
v_int64 = 0;
|
||||
if (key != NULL)
|
||||
{
|
||||
gpgme_subkey_t subkey = key->subkeys;
|
||||
child = g_variant_new_int64 (v_int64);
|
||||
break;
|
||||
|
||||
while (subkey != NULL && (g_strcmp0 (subkey->fpr, signature->fpr) != 0))
|
||||
subkey = subkey->next;
|
||||
|
||||
if (subkey != NULL)
|
||||
v_int64 = subkey->expires;
|
||||
}
|
||||
child = g_variant_new_int64 (v_int64);
|
||||
break;
|
||||
|
||||
case OSTREE_GPG_SIGNATURE_ATTR_KEY_EXP_TIMESTAMP_PRIMARY:
|
||||
if (key != NULL && key->subkeys != NULL)
|
||||
v_int64 = key->subkeys->expires;
|
||||
else
|
||||
v_int64 = 0;
|
||||
child = g_variant_new_int64 (v_int64);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_critical ("Invalid signature attribute (%d)", attrs[ii]);
|
||||
g_variant_builder_clear (&builder);
|
||||
return NULL;
|
||||
default:
|
||||
g_critical ("Invalid signature attribute (%d)", attrs[ii]);
|
||||
g_variant_builder_clear (&builder);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_variant_builder_add_value (&builder, child);
|
||||
@ -493,13 +480,11 @@ ostree_gpg_verify_result_get (OstreeGpgVerifyResult *result,
|
||||
* Returns: (transfer floating): a new, floating, #GVariant tuple
|
||||
**/
|
||||
GVariant *
|
||||
ostree_gpg_verify_result_get_all (OstreeGpgVerifyResult *result,
|
||||
guint signature_index)
|
||||
ostree_gpg_verify_result_get_all (OstreeGpgVerifyResult *result, guint signature_index)
|
||||
{
|
||||
g_return_val_if_fail (OSTREE_IS_GPG_VERIFY_RESULT (result), NULL);
|
||||
|
||||
return ostree_gpg_verify_result_get (result, signature_index,
|
||||
all_signature_attrs,
|
||||
return ostree_gpg_verify_result_get (result, signature_index, all_signature_attrs,
|
||||
G_N_ELEMENTS (all_signature_attrs));
|
||||
}
|
||||
|
||||
@ -524,13 +509,11 @@ ostree_gpg_verify_result_get_all (OstreeGpgVerifyResult *result,
|
||||
* @result.
|
||||
*/
|
||||
void
|
||||
ostree_gpg_verify_result_describe (OstreeGpgVerifyResult *result,
|
||||
guint signature_index,
|
||||
GString *output_buffer,
|
||||
const gchar *line_prefix,
|
||||
ostree_gpg_verify_result_describe (OstreeGpgVerifyResult *result, guint signature_index,
|
||||
GString *output_buffer, const gchar *line_prefix,
|
||||
OstreeGpgSignatureFormatFlags flags)
|
||||
{
|
||||
g_autoptr(GVariant) variant = NULL;
|
||||
g_autoptr (GVariant) variant = NULL;
|
||||
|
||||
g_return_if_fail (OSTREE_IS_GPG_VERIFY_RESULT (result));
|
||||
|
||||
@ -540,41 +523,31 @@ ostree_gpg_verify_result_describe (OstreeGpgVerifyResult *result,
|
||||
}
|
||||
|
||||
static void
|
||||
append_expire_info (GString *output_buffer,
|
||||
const gchar *line_prefix,
|
||||
const gchar *exp_type,
|
||||
gint64 exp_timestamp,
|
||||
gboolean expired)
|
||||
append_expire_info (GString *output_buffer, const gchar *line_prefix, const gchar *exp_type,
|
||||
gint64 exp_timestamp, gboolean expired)
|
||||
{
|
||||
if (line_prefix != NULL)
|
||||
g_string_append (output_buffer, line_prefix);
|
||||
|
||||
g_autoptr(GDateTime) date_time_utc = g_date_time_new_from_unix_utc (exp_timestamp);
|
||||
g_autoptr (GDateTime) date_time_utc = g_date_time_new_from_unix_utc (exp_timestamp);
|
||||
if (date_time_utc == NULL)
|
||||
{
|
||||
g_string_append_printf (output_buffer,
|
||||
"%s expiry timestamp (%" G_GINT64_FORMAT ") is invalid\n",
|
||||
exp_type,
|
||||
"%s expiry timestamp (%" G_GINT64_FORMAT ") is invalid\n", exp_type,
|
||||
exp_timestamp);
|
||||
return;
|
||||
}
|
||||
|
||||
g_autoptr(GDateTime) date_time_local = g_date_time_to_local (date_time_utc);
|
||||
g_autoptr (GDateTime) date_time_local = g_date_time_to_local (date_time_utc);
|
||||
g_autofree char *formatted_date_time = g_date_time_format (date_time_local, "%c");
|
||||
|
||||
if (expired)
|
||||
{
|
||||
g_string_append_printf (output_buffer,
|
||||
"%s expired %s\n",
|
||||
exp_type,
|
||||
formatted_date_time);
|
||||
g_string_append_printf (output_buffer, "%s expired %s\n", exp_type, formatted_date_time);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_string_append_printf (output_buffer,
|
||||
"%s expires %s\n",
|
||||
exp_type,
|
||||
formatted_date_time);
|
||||
g_string_append_printf (output_buffer, "%s expires %s\n", exp_type, formatted_date_time);
|
||||
}
|
||||
}
|
||||
|
||||
@ -593,13 +566,12 @@ append_expire_info (GString *output_buffer,
|
||||
* ostree_gpg_verify_result_get_all().
|
||||
*/
|
||||
void
|
||||
ostree_gpg_verify_result_describe_variant (GVariant *variant,
|
||||
GString *output_buffer,
|
||||
ostree_gpg_verify_result_describe_variant (GVariant *variant, GString *output_buffer,
|
||||
const gchar *line_prefix,
|
||||
OstreeGpgSignatureFormatFlags flags)
|
||||
{
|
||||
g_autoptr(GDateTime) date_time_utc = NULL;
|
||||
g_autoptr(GDateTime) date_time_local = NULL;
|
||||
g_autoptr (GDateTime) date_time_utc = NULL;
|
||||
g_autoptr (GDateTime) date_time_local = NULL;
|
||||
g_autofree char *formatted_date_time = NULL;
|
||||
gint64 timestamp;
|
||||
gint64 exp_timestamp;
|
||||
@ -631,34 +603,23 @@ ostree_gpg_verify_result_describe_variant (GVariant *variant,
|
||||
* check_sig_and_print() in gnupg/g10/mainproc.c, though obviously
|
||||
* greatly simplified. */
|
||||
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_VALID,
|
||||
"b", &valid);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_SIG_EXPIRED,
|
||||
"b", &sig_expired);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_KEY_EXPIRED,
|
||||
"b", &key_expired);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_KEY_REVOKED,
|
||||
"b", &key_revoked);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_KEY_MISSING,
|
||||
"b", &key_missing);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_FINGERPRINT,
|
||||
"&s", &fingerprint);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_FINGERPRINT_PRIMARY,
|
||||
"&s", &fingerprint_primary);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_TIMESTAMP,
|
||||
"x", ×tamp);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_EXP_TIMESTAMP,
|
||||
"x", &exp_timestamp);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_PUBKEY_ALGO_NAME,
|
||||
"&s", &pubkey_algo);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_USER_NAME,
|
||||
"&s", &user_name);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_USER_EMAIL,
|
||||
"&s", &user_email);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_KEY_EXP_TIMESTAMP,
|
||||
"x", &key_exp_timestamp);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_KEY_EXP_TIMESTAMP_PRIMARY,
|
||||
"x", &key_exp_timestamp_primary);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_VALID, "b", &valid);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_SIG_EXPIRED, "b", &sig_expired);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_KEY_EXPIRED, "b", &key_expired);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_KEY_REVOKED, "b", &key_revoked);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_KEY_MISSING, "b", &key_missing);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_FINGERPRINT, "&s", &fingerprint);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_FINGERPRINT_PRIMARY, "&s",
|
||||
&fingerprint_primary);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_TIMESTAMP, "x", ×tamp);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_EXP_TIMESTAMP, "x", &exp_timestamp);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_PUBKEY_ALGO_NAME, "&s", &pubkey_algo);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_USER_NAME, "&s", &user_name);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_USER_EMAIL, "&s", &user_email);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_KEY_EXP_TIMESTAMP, "x",
|
||||
&key_exp_timestamp);
|
||||
g_variant_get_child (variant, OSTREE_GPG_SIGNATURE_ATTR_KEY_EXP_TIMESTAMP_PRIMARY, "x",
|
||||
&key_exp_timestamp_primary);
|
||||
|
||||
len = strlen (fingerprint);
|
||||
key_id = (len > 16) ? fingerprint + len - 16 : fingerprint;
|
||||
@ -678,8 +639,7 @@ ostree_gpg_verify_result_describe_variant (GVariant *variant,
|
||||
if (line_prefix != NULL)
|
||||
g_string_append (output_buffer, line_prefix);
|
||||
|
||||
g_string_append_printf (output_buffer,
|
||||
"Signature made %s using %s key ID %s\n",
|
||||
g_string_append_printf (output_buffer, "Signature made %s using %s key ID %s\n",
|
||||
formatted_date_time, pubkey_algo, key_id);
|
||||
|
||||
g_clear_pointer (&date_time_utc, g_date_time_unref);
|
||||
@ -691,14 +651,12 @@ ostree_gpg_verify_result_describe_variant (GVariant *variant,
|
||||
|
||||
if (key_missing)
|
||||
{
|
||||
g_string_append (output_buffer,
|
||||
"Can't check signature: public key not found\n");
|
||||
g_string_append (output_buffer, "Can't check signature: public key not found\n");
|
||||
}
|
||||
else if (valid)
|
||||
{
|
||||
g_string_append_printf (output_buffer,
|
||||
"Good signature from \"%s <%s>\"\n",
|
||||
user_name, user_email);
|
||||
g_string_append_printf (output_buffer, "Good signature from \"%s <%s>\"\n", user_name,
|
||||
user_email);
|
||||
}
|
||||
else if (key_revoked)
|
||||
{
|
||||
@ -706,15 +664,13 @@ ostree_gpg_verify_result_describe_variant (GVariant *variant,
|
||||
}
|
||||
else if (sig_expired)
|
||||
{
|
||||
g_string_append_printf (output_buffer,
|
||||
"Expired signature from \"%s <%s>\"\n",
|
||||
user_name, user_email);
|
||||
g_string_append_printf (output_buffer, "Expired signature from \"%s <%s>\"\n", user_name,
|
||||
user_email);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_string_append_printf (output_buffer,
|
||||
"BAD signature from \"%s <%s>\"\n",
|
||||
user_name, user_email);
|
||||
g_string_append_printf (output_buffer, "BAD signature from \"%s <%s>\"\n", user_name,
|
||||
user_email);
|
||||
}
|
||||
|
||||
if (!key_missing && (g_strcmp0 (fingerprint, fingerprint_primary) != 0))
|
||||
@ -722,25 +678,21 @@ ostree_gpg_verify_result_describe_variant (GVariant *variant,
|
||||
const char *key_id_primary;
|
||||
|
||||
len = strlen (fingerprint_primary);
|
||||
key_id_primary = (len > 16) ? fingerprint_primary + len - 16 :
|
||||
fingerprint_primary;
|
||||
key_id_primary = (len > 16) ? fingerprint_primary + len - 16 : fingerprint_primary;
|
||||
|
||||
if (line_prefix != NULL)
|
||||
g_string_append (output_buffer, line_prefix);
|
||||
|
||||
g_string_append_printf (output_buffer,
|
||||
"Primary key ID %s\n", key_id_primary);
|
||||
g_string_append_printf (output_buffer, "Primary key ID %s\n", key_id_primary);
|
||||
}
|
||||
|
||||
if (exp_timestamp > 0)
|
||||
append_expire_info (output_buffer, line_prefix, "Signature", exp_timestamp,
|
||||
sig_expired);
|
||||
append_expire_info (output_buffer, line_prefix, "Signature", exp_timestamp, sig_expired);
|
||||
if (key_exp_timestamp > 0)
|
||||
append_expire_info (output_buffer, line_prefix, "Key", key_exp_timestamp,
|
||||
key_expired);
|
||||
append_expire_info (output_buffer, line_prefix, "Key", key_exp_timestamp, key_expired);
|
||||
if (key_exp_timestamp_primary > 0 && (g_strcmp0 (fingerprint, fingerprint_primary) != 0))
|
||||
append_expire_info (output_buffer, line_prefix, "Primary key",
|
||||
key_exp_timestamp_primary, key_expired);
|
||||
append_expire_info (output_buffer, line_prefix, "Primary key", key_exp_timestamp_primary,
|
||||
key_expired);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -759,8 +711,7 @@ ostree_gpg_verify_result_describe_variant (GVariant *variant,
|
||||
* Since: 2016.6
|
||||
*/
|
||||
gboolean
|
||||
ostree_gpg_verify_result_require_valid_signature (OstreeGpgVerifyResult *result,
|
||||
GError **error)
|
||||
ostree_gpg_verify_result_require_valid_signature (OstreeGpgVerifyResult *result, GError **error)
|
||||
{
|
||||
if (result == NULL)
|
||||
return FALSE;
|
||||
@ -775,7 +726,7 @@ ostree_gpg_verify_result_require_valid_signature (OstreeGpgVerifyResult *result,
|
||||
* valid key.
|
||||
*/
|
||||
gint code = OSTREE_GPG_ERROR_NO_SIGNATURE;
|
||||
g_autoptr(GString) buffer = g_string_sized_new (256);
|
||||
g_autoptr (GString) buffer = g_string_sized_new (256);
|
||||
guint nsigs = ostree_gpg_verify_result_count_all (result);
|
||||
|
||||
if (nsigs == 0)
|
||||
@ -785,21 +736,21 @@ ostree_gpg_verify_result_require_valid_signature (OstreeGpgVerifyResult *result,
|
||||
{
|
||||
for (int i = nsigs - 1; i >= 0; i--)
|
||||
{
|
||||
g_autoptr(GVariant) info = ostree_gpg_verify_result_get_all (result, i);
|
||||
g_autoptr (GVariant) info = ostree_gpg_verify_result_get_all (result, i);
|
||||
ostree_gpg_verify_result_describe_variant (info, buffer, "",
|
||||
OSTREE_GPG_SIGNATURE_FORMAT_DEFAULT);
|
||||
|
||||
if (i == nsigs - 1)
|
||||
{
|
||||
gboolean key_missing, key_revoked, key_expired, sig_expired;
|
||||
g_variant_get_child (info, OSTREE_GPG_SIGNATURE_ATTR_KEY_MISSING,
|
||||
"b", &key_missing);
|
||||
g_variant_get_child (info, OSTREE_GPG_SIGNATURE_ATTR_KEY_REVOKED,
|
||||
"b", &key_revoked);
|
||||
g_variant_get_child (info, OSTREE_GPG_SIGNATURE_ATTR_KEY_EXPIRED,
|
||||
"b", &key_expired);
|
||||
g_variant_get_child (info, OSTREE_GPG_SIGNATURE_ATTR_SIG_EXPIRED,
|
||||
"b", &sig_expired);
|
||||
g_variant_get_child (info, OSTREE_GPG_SIGNATURE_ATTR_KEY_MISSING, "b",
|
||||
&key_missing);
|
||||
g_variant_get_child (info, OSTREE_GPG_SIGNATURE_ATTR_KEY_REVOKED, "b",
|
||||
&key_revoked);
|
||||
g_variant_get_child (info, OSTREE_GPG_SIGNATURE_ATTR_KEY_EXPIRED, "b",
|
||||
&key_expired);
|
||||
g_variant_get_child (info, OSTREE_GPG_SIGNATURE_ATTR_SIG_EXPIRED, "b",
|
||||
&sig_expired);
|
||||
|
||||
if (key_missing)
|
||||
code = OSTREE_GPG_ERROR_MISSING_KEY;
|
||||
|
@ -24,8 +24,7 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_GPG_VERIFY_RESULT \
|
||||
(ostree_gpg_verify_result_get_type ())
|
||||
#define OSTREE_TYPE_GPG_VERIFY_RESULT (ostree_gpg_verify_result_get_type ())
|
||||
#define OSTREE_GPG_VERIFY_RESULT(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), OSTREE_TYPE_GPG_VERIFY_RESULT, OstreeGpgVerifyResult))
|
||||
#define OSTREE_IS_GPG_VERIFY_RESULT(obj) \
|
||||
@ -80,7 +79,8 @@ typedef struct OstreeGpgVerifyResult OstreeGpgVerifyResult;
|
||||
* Signature attributes available from an #OstreeGpgVerifyResult.
|
||||
* The attribute's #GVariantType is shown in brackets.
|
||||
**/
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
OSTREE_GPG_SIGNATURE_ATTR_VALID,
|
||||
OSTREE_GPG_SIGNATURE_ATTR_SIG_EXPIRED,
|
||||
OSTREE_GPG_SIGNATURE_ATTR_KEY_EXPIRED,
|
||||
@ -108,19 +108,15 @@ _OSTREE_PUBLIC
|
||||
guint ostree_gpg_verify_result_count_valid (OstreeGpgVerifyResult *result);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_gpg_verify_result_lookup (OstreeGpgVerifyResult *result,
|
||||
const gchar *key_id,
|
||||
gboolean ostree_gpg_verify_result_lookup (OstreeGpgVerifyResult *result, const gchar *key_id,
|
||||
guint *out_signature_index);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
GVariant * ostree_gpg_verify_result_get (OstreeGpgVerifyResult *result,
|
||||
guint signature_index,
|
||||
OstreeGpgSignatureAttr *attrs,
|
||||
guint n_attrs);
|
||||
GVariant *ostree_gpg_verify_result_get (OstreeGpgVerifyResult *result, guint signature_index,
|
||||
OstreeGpgSignatureAttr *attrs, guint n_attrs);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
GVariant * ostree_gpg_verify_result_get_all (OstreeGpgVerifyResult *result,
|
||||
guint signature_index);
|
||||
GVariant *ostree_gpg_verify_result_get_all (OstreeGpgVerifyResult *result, guint signature_index);
|
||||
|
||||
/**
|
||||
* OstreeGpgSignatureFormatFlags:
|
||||
@ -131,20 +127,18 @@ GVariant * ostree_gpg_verify_result_get_all (OstreeGpgVerifyResult *result,
|
||||
* there's only one possible output format, but this enumeration allows
|
||||
* for future variations.
|
||||
**/
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
OSTREE_GPG_SIGNATURE_FORMAT_DEFAULT = (0 << 0),
|
||||
} OstreeGpgSignatureFormatFlags;
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_gpg_verify_result_describe (OstreeGpgVerifyResult *result,
|
||||
guint signature_index,
|
||||
GString *output_buffer,
|
||||
const gchar *line_prefix,
|
||||
void ostree_gpg_verify_result_describe (OstreeGpgVerifyResult *result, guint signature_index,
|
||||
GString *output_buffer, const gchar *line_prefix,
|
||||
OstreeGpgSignatureFormatFlags flags);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_gpg_verify_result_describe_variant (GVariant *variant,
|
||||
GString *output_buffer,
|
||||
void ostree_gpg_verify_result_describe_variant (GVariant *variant, GString *output_buffer,
|
||||
const gchar *line_prefix,
|
||||
OstreeGpgSignatureFormatFlags flags);
|
||||
|
||||
@ -156,7 +150,8 @@ gboolean ostree_gpg_verify_result_require_valid_signature (OstreeGpgVerifyResult
|
||||
* OstreeGpgError:
|
||||
* @OSTREE_GPG_ERROR_NO_SIGNATURE: A signature was expected, but not found.
|
||||
* @OSTREE_GPG_ERROR_INVALID_SIGNATURE: A signature was malformed.
|
||||
* @OSTREE_GPG_ERROR_MISSING_KEY: A signature was found, but was created with a key not in the configured keyrings.
|
||||
* @OSTREE_GPG_ERROR_MISSING_KEY: A signature was found, but was created with a key not in the
|
||||
* configured keyrings.
|
||||
* @OSTREE_GPG_ERROR_EXPIRED_SIGNATURE: A signature was expired. Since: 2020.1.
|
||||
* @OSTREE_GPG_ERROR_EXPIRED_KEY: A signature was found, but the key used to
|
||||
* sign it has expired. Since: 2020.1.
|
||||
@ -168,7 +163,8 @@ gboolean ostree_gpg_verify_result_require_valid_signature (OstreeGpgVerifyResult
|
||||
*
|
||||
* Since: 2017.10
|
||||
*/
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
OSTREE_GPG_ERROR_NO_SIGNATURE = 0,
|
||||
OSTREE_GPG_ERROR_INVALID_SIGNATURE,
|
||||
OSTREE_GPG_ERROR_MISSING_KEY,
|
||||
|
@ -19,24 +19,24 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib-unix.h>
|
||||
#include <gio/gunixoutputstream.h>
|
||||
#include <errno.h>
|
||||
#include <gio/gunixoutputstream.h>
|
||||
#include <glib-unix.h>
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_LIBMOUNT
|
||||
#include <libmount.h>
|
||||
#endif
|
||||
#include <sys/statvfs.h>
|
||||
#include <stdbool.h>
|
||||
#include "otutil.h"
|
||||
#include <stdbool.h>
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
#include "ostree.h"
|
||||
#include "ostree-core-private.h"
|
||||
#include "ostree-cmd-private.h"
|
||||
#include "ostree-core-private.h"
|
||||
#include "ostree.h"
|
||||
|
||||
#ifdef HAVE_LIBMOUNT
|
||||
typedef FILE OtLibMountFile;
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(OtLibMountFile, endmntent)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (OtLibMountFile, endmntent)
|
||||
|
||||
/* Taken from systemd path-util.c */
|
||||
static bool
|
||||
@ -46,7 +46,7 @@ is_path (const char *p)
|
||||
}
|
||||
|
||||
/* Taken from systemd path-util.c */
|
||||
static char*
|
||||
static char *
|
||||
path_kill_slashes (char *path)
|
||||
{
|
||||
char *f, *t;
|
||||
@ -91,8 +91,7 @@ path_kill_slashes (char *path)
|
||||
* mounted yet.
|
||||
*/
|
||||
static char *
|
||||
stateroot_from_ostree_cmdline (const char *ostree_cmdline,
|
||||
GError **error)
|
||||
stateroot_from_ostree_cmdline (const char *ostree_cmdline, GError **error)
|
||||
{
|
||||
static GRegex *regex;
|
||||
static gsize regex_initialized;
|
||||
@ -103,7 +102,7 @@ stateroot_from_ostree_cmdline (const char *ostree_cmdline,
|
||||
g_once_init_leave (®ex_initialized, 1);
|
||||
}
|
||||
|
||||
g_autoptr(GMatchInfo) match = NULL;
|
||||
g_autoptr (GMatchInfo) match = NULL;
|
||||
if (!g_regex_match (regex, ostree_cmdline, 0, &match))
|
||||
return glnx_null_throw (error, "Failed to parse %s", ostree_cmdline);
|
||||
|
||||
@ -113,10 +112,8 @@ stateroot_from_ostree_cmdline (const char *ostree_cmdline,
|
||||
|
||||
/* Forcibly enable our internal units, since we detected ostree= on the kernel cmdline */
|
||||
static gboolean
|
||||
require_internal_units (const char *normal_dir,
|
||||
const char *early_dir,
|
||||
const char *late_dir,
|
||||
GError **error)
|
||||
require_internal_units (const char *normal_dir, const char *early_dir, const char *late_dir,
|
||||
GError **error)
|
||||
{
|
||||
#ifdef SYSTEM_DATA_UNIT_PATH
|
||||
GCancellable *cancellable = NULL;
|
||||
@ -125,16 +122,23 @@ require_internal_units (const char *normal_dir,
|
||||
if (!glnx_opendirat (AT_FDCWD, normal_dir, TRUE, &normal_dir_dfd, error))
|
||||
return FALSE;
|
||||
|
||||
if (!glnx_shutil_mkdir_p_at (normal_dir_dfd, "local-fs.target.requires", 0755, cancellable, error))
|
||||
if (!glnx_shutil_mkdir_p_at (normal_dir_dfd, "local-fs.target.requires", 0755, cancellable,
|
||||
error))
|
||||
return FALSE;
|
||||
if (symlinkat (SYSTEM_DATA_UNIT_PATH "/ostree-remount.service", normal_dir_dfd, "local-fs.target.requires/ostree-remount.service") < 0)
|
||||
if (symlinkat (SYSTEM_DATA_UNIT_PATH "/ostree-remount.service", normal_dir_dfd,
|
||||
"local-fs.target.requires/ostree-remount.service")
|
||||
< 0)
|
||||
return glnx_throw_errno_prefix (error, "symlinkat");
|
||||
|
||||
if (!glnx_shutil_mkdir_p_at (normal_dir_dfd, "multi-user.target.wants", 0755, cancellable, error))
|
||||
return FALSE;
|
||||
if (symlinkat (SYSTEM_DATA_UNIT_PATH "/ostree-finalize-staged.path", normal_dir_dfd, "multi-user.target.wants/ostree-finalize-staged.path") < 0)
|
||||
if (symlinkat (SYSTEM_DATA_UNIT_PATH "/ostree-finalize-staged.path", normal_dir_dfd,
|
||||
"multi-user.target.wants/ostree-finalize-staged.path")
|
||||
< 0)
|
||||
return glnx_throw_errno_prefix (error, "symlinkat");
|
||||
if (symlinkat (SYSTEM_DATA_UNIT_PATH "/ostree-boot-complete.service", normal_dir_dfd, "multi-user.target.wants/ostree-boot-complete.service") < 0)
|
||||
if (symlinkat (SYSTEM_DATA_UNIT_PATH "/ostree-boot-complete.service", normal_dir_dfd,
|
||||
"multi-user.target.wants/ostree-boot-complete.service")
|
||||
< 0)
|
||||
return glnx_throw_errno_prefix (error, "symlinkat");
|
||||
|
||||
return TRUE;
|
||||
@ -145,11 +149,8 @@ require_internal_units (const char *normal_dir,
|
||||
|
||||
/* Generate var.mount */
|
||||
static gboolean
|
||||
fstab_generator (const char *ostree_cmdline,
|
||||
const char *normal_dir,
|
||||
const char *early_dir,
|
||||
const char *late_dir,
|
||||
GError **error)
|
||||
fstab_generator (const char *ostree_cmdline, const char *normal_dir, const char *early_dir,
|
||||
const char *late_dir, GError **error)
|
||||
{
|
||||
#ifdef HAVE_LIBMOUNT
|
||||
/* Not currently cancellable, but define a var in case we care later */
|
||||
@ -164,7 +165,7 @@ fstab_generator (const char *ostree_cmdline,
|
||||
return FALSE;
|
||||
|
||||
/* Load /etc/fstab if it exists, and look for a /var mount */
|
||||
g_autoptr(OtLibMountFile) fstab = setmntent (fstab_path, "re");
|
||||
g_autoptr (OtLibMountFile) fstab = setmntent (fstab_path, "re");
|
||||
gboolean found_var_mnt = FALSE;
|
||||
if (!fstab)
|
||||
{
|
||||
@ -204,11 +205,12 @@ fstab_generator (const char *ostree_cmdline,
|
||||
/* Generate our bind mount unit */
|
||||
const char *stateroot_var_path = glnx_strjoina ("/sysroot/ostree/deploy/", stateroot, "/var");
|
||||
|
||||
g_auto(GLnxTmpfile) tmpf = { 0, };
|
||||
if (!glnx_open_tmpfile_linkable_at (normal_dir_dfd, ".", O_WRONLY | O_CLOEXEC,
|
||||
&tmpf, error))
|
||||
g_auto (GLnxTmpfile) tmpf = {
|
||||
0,
|
||||
};
|
||||
if (!glnx_open_tmpfile_linkable_at (normal_dir_dfd, ".", O_WRONLY | O_CLOEXEC, &tmpf, error))
|
||||
return FALSE;
|
||||
g_autoptr(GOutputStream) outstream = g_unix_output_stream_new (tmpf.fd, FALSE);
|
||||
g_autoptr (GOutputStream) outstream = g_unix_output_stream_new (tmpf.fd, FALSE);
|
||||
gsize bytes_written;
|
||||
/* This code is inspired by systemd's fstab-generator.c.
|
||||
*
|
||||
@ -226,8 +228,7 @@ fstab_generator (const char *ostree_cmdline,
|
||||
"Where=%s\n"
|
||||
"What=%s\n"
|
||||
"Options=bind\n",
|
||||
var_path,
|
||||
stateroot_var_path))
|
||||
var_path, stateroot_var_path))
|
||||
return FALSE;
|
||||
if (!g_output_stream_flush (outstream, cancellable, error))
|
||||
return FALSE;
|
||||
@ -236,8 +237,8 @@ fstab_generator (const char *ostree_cmdline,
|
||||
if (!glnx_fchmod (tmpf.fd, 0644, error))
|
||||
return FALSE;
|
||||
/* Error out if somehow it already exists, that'll help us debug conflicts */
|
||||
if (!glnx_link_tmpfile_at (&tmpf, GLNX_LINK_TMPFILE_NOREPLACE,
|
||||
normal_dir_dfd, "var.mount", error))
|
||||
if (!glnx_link_tmpfile_at (&tmpf, GLNX_LINK_TMPFILE_NOREPLACE, normal_dir_dfd, "var.mount",
|
||||
error))
|
||||
return FALSE;
|
||||
|
||||
/* And ensure it's required; newer systemd will auto-inject fs dependencies
|
||||
@ -245,7 +246,8 @@ fstab_generator (const char *ostree_cmdline,
|
||||
* need this. It's what the fstab generator does. And my mother always said,
|
||||
* listen to the fstab generator.
|
||||
*/
|
||||
if (!glnx_shutil_mkdir_p_at (normal_dir_dfd, "local-fs.target.requires", 0755, cancellable, error))
|
||||
if (!glnx_shutil_mkdir_p_at (normal_dir_dfd, "local-fs.target.requires", 0755, cancellable,
|
||||
error))
|
||||
return FALSE;
|
||||
if (symlinkat ("../var.mount", normal_dir_dfd, "local-fs.target.requires/var.mount") < 0)
|
||||
return glnx_throw_errno_prefix (error, "symlinkat");
|
||||
@ -258,11 +260,8 @@ fstab_generator (const char *ostree_cmdline,
|
||||
|
||||
/* Implementation of ostree-system-generator */
|
||||
gboolean
|
||||
_ostree_impl_system_generator (const char *ostree_cmdline,
|
||||
const char *normal_dir,
|
||||
const char *early_dir,
|
||||
const char *late_dir,
|
||||
GError **error)
|
||||
_ostree_impl_system_generator (const char *ostree_cmdline, const char *normal_dir,
|
||||
const char *early_dir, const char *late_dir, GError **error)
|
||||
{
|
||||
if (!require_internal_units (normal_dir, early_dir, late_dir, error))
|
||||
return FALSE;
|
||||
|
@ -17,18 +17,20 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ostree-kernel-args.h"
|
||||
#include "libglnx.h"
|
||||
#include "ostree-kernel-args.h"
|
||||
#include "otutil.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
struct _OstreeKernelArgs {
|
||||
GPtrArray *order;
|
||||
struct _OstreeKernelArgs
|
||||
{
|
||||
GPtrArray *order;
|
||||
GHashTable *table;
|
||||
};
|
||||
|
||||
struct _OstreeKernelArgsEntry {
|
||||
struct _OstreeKernelArgsEntry
|
||||
{
|
||||
char *key;
|
||||
char *value;
|
||||
};
|
||||
@ -46,30 +48,26 @@ _ostree_kernel_args_entry_get_value (const OstreeKernelArgsEntry *e)
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_kernel_args_entry_set_key (OstreeKernelArgsEntry *e,
|
||||
char *key)
|
||||
_ostree_kernel_args_entry_set_key (OstreeKernelArgsEntry *e, char *key)
|
||||
{
|
||||
e->key = key;
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_kernel_args_entry_set_value (OstreeKernelArgsEntry *e,
|
||||
char *value)
|
||||
_ostree_kernel_args_entry_set_value (OstreeKernelArgsEntry *e, char *value)
|
||||
{
|
||||
e->value = value;
|
||||
}
|
||||
|
||||
char *
|
||||
_ostree_kernel_args_get_key_index (const OstreeKernelArgs *kargs,
|
||||
int i)
|
||||
_ostree_kernel_args_get_key_index (const OstreeKernelArgs *kargs, int i)
|
||||
{
|
||||
OstreeKernelArgsEntry *e = kargs->order->pdata[i];
|
||||
return e->key;
|
||||
}
|
||||
|
||||
char *
|
||||
_ostree_kernel_args_get_value_index (const OstreeKernelArgs *kargs,
|
||||
int i)
|
||||
_ostree_kernel_args_get_value_index (const OstreeKernelArgs *kargs, int i)
|
||||
{
|
||||
OstreeKernelArgsEntry *e = kargs->order->pdata[i];
|
||||
return e->value;
|
||||
@ -100,24 +98,21 @@ kernel_args_entry_free_from_table (gpointer data)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
kernel_args_entry_value_equal (gconstpointer data,
|
||||
gconstpointer value)
|
||||
kernel_args_entry_value_equal (gconstpointer data, gconstpointer value)
|
||||
{
|
||||
const OstreeKernelArgsEntry *e = data;
|
||||
return g_strcmp0 (_ostree_kernel_args_entry_get_value (e), value) == 0;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
kernel_args_entry_key_equal (gconstpointer data,
|
||||
gconstpointer key)
|
||||
kernel_args_entry_key_equal (gconstpointer data, gconstpointer key)
|
||||
{
|
||||
const OstreeKernelArgsEntry *e = data;
|
||||
return g_strcmp0 (_ostree_kernel_args_entry_get_key (e), key) == 0;
|
||||
}
|
||||
|
||||
static void
|
||||
kernel_args_entry_replace_value (OstreeKernelArgsEntry *e,
|
||||
const char *value)
|
||||
kernel_args_entry_replace_value (OstreeKernelArgsEntry *e, const char *value)
|
||||
{
|
||||
g_assert (e);
|
||||
_ostree_kernel_args_entry_value_free (e);
|
||||
@ -125,8 +120,7 @@ kernel_args_entry_replace_value (OstreeKernelArgsEntry *e,
|
||||
}
|
||||
|
||||
static void
|
||||
kernel_args_remove_entries_from_order (GPtrArray *order,
|
||||
GPtrArray *entries)
|
||||
kernel_args_remove_entries_from_order (GPtrArray *order, GPtrArray *entries)
|
||||
{
|
||||
g_assert (entries);
|
||||
for (int i = 0; i < entries->len; i++)
|
||||
@ -144,12 +138,11 @@ split_keyeq (char *arg)
|
||||
|
||||
// Note: key/val are in a single allocation block, so we don't free val.
|
||||
*eq = '\0';
|
||||
return eq+1;
|
||||
return eq + 1;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_arg_has_prefix (const char *arg,
|
||||
char **prefixes)
|
||||
_arg_has_prefix (const char *arg, char **prefixes)
|
||||
{
|
||||
char **strviter;
|
||||
|
||||
@ -165,8 +158,7 @@ _arg_has_prefix (const char *arg,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
strcmp0_equal (gconstpointer v1,
|
||||
gconstpointer v2)
|
||||
strcmp0_equal (gconstpointer v1, gconstpointer v2)
|
||||
{
|
||||
return g_strcmp0 (v1, v2) == 0;
|
||||
}
|
||||
@ -187,8 +179,8 @@ ostree_kernel_args_new (void)
|
||||
ret = g_new0 (OstreeKernelArgs, 1);
|
||||
/* Hash table owns the kernel args entries, since it uses keys to index,
|
||||
* and its values are used to locate entries in the order array. */
|
||||
ret->table = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free, (GDestroyNotify)g_ptr_array_unref);
|
||||
ret->table
|
||||
= g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_ptr_array_unref);
|
||||
ret->order = g_ptr_array_new_with_free_func (NULL);
|
||||
return ret;
|
||||
}
|
||||
@ -222,7 +214,7 @@ ostree_kernel_args_free (OstreeKernelArgs *kargs)
|
||||
void
|
||||
ostree_kernel_args_cleanup (void *loc)
|
||||
{
|
||||
ostree_kernel_args_free (*((OstreeKernelArgs**)loc));
|
||||
ostree_kernel_args_free (*((OstreeKernelArgs **)loc));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -235,7 +227,7 @@ ostree_kernel_args_cleanup (void *loc)
|
||||
*
|
||||
* Since: 2019.3
|
||||
**/
|
||||
GHashTable*
|
||||
GHashTable *
|
||||
_ostree_kernel_arg_get_kargs_table (OstreeKernelArgs *kargs)
|
||||
{
|
||||
if (kargs != NULL)
|
||||
@ -253,7 +245,7 @@ _ostree_kernel_arg_get_kargs_table (OstreeKernelArgs *kargs)
|
||||
*
|
||||
* Since: 2019.3
|
||||
**/
|
||||
GPtrArray*
|
||||
GPtrArray *
|
||||
_ostree_kernel_arg_get_key_array (OstreeKernelArgs *kargs)
|
||||
{
|
||||
if (kargs != NULL)
|
||||
@ -291,9 +283,7 @@ _ostree_kernel_arg_get_key_array (OstreeKernelArgs *kargs)
|
||||
* Since: 2019.3
|
||||
**/
|
||||
gboolean
|
||||
ostree_kernel_args_new_replace (OstreeKernelArgs *kargs,
|
||||
const char *arg,
|
||||
GError **error)
|
||||
ostree_kernel_args_new_replace (OstreeKernelArgs *kargs, const char *arg, GError **error)
|
||||
{
|
||||
g_autofree char *arg_owned = g_strdup (arg);
|
||||
const char *key = arg_owned;
|
||||
@ -345,9 +335,7 @@ ostree_kernel_args_new_replace (OstreeKernelArgs *kargs,
|
||||
* Since: 2019.3
|
||||
**/
|
||||
gboolean
|
||||
ostree_kernel_args_delete_key_entry (OstreeKernelArgs *kargs,
|
||||
const char *key,
|
||||
GError **error)
|
||||
ostree_kernel_args_delete_key_entry (OstreeKernelArgs *kargs, const char *key, GError **error)
|
||||
{
|
||||
GPtrArray *entries = g_hash_table_lookup (kargs->table, key);
|
||||
if (!entries)
|
||||
@ -358,8 +346,7 @@ ostree_kernel_args_delete_key_entry (OstreeKernelArgs *kargs,
|
||||
|
||||
if (!g_hash_table_remove (kargs->table, key))
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"Failed to find kernel argument '%s'",
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to find kernel argument '%s'",
|
||||
key);
|
||||
return FALSE;
|
||||
}
|
||||
@ -392,9 +379,7 @@ ostree_kernel_args_delete_key_entry (OstreeKernelArgs *kargs,
|
||||
* Since: 2019.3
|
||||
**/
|
||||
gboolean
|
||||
ostree_kernel_args_delete (OstreeKernelArgs *kargs,
|
||||
const char *arg,
|
||||
GError **error)
|
||||
ostree_kernel_args_delete (OstreeKernelArgs *kargs, const char *arg, GError **error)
|
||||
{
|
||||
g_autofree char *arg_owned = g_strdup (arg);
|
||||
const char *key = arg_owned;
|
||||
@ -444,8 +429,7 @@ ostree_kernel_args_delete (OstreeKernelArgs *kargs,
|
||||
* Since: 2019.3
|
||||
**/
|
||||
void
|
||||
ostree_kernel_args_replace_take (OstreeKernelArgs *kargs,
|
||||
char *arg)
|
||||
ostree_kernel_args_replace_take (OstreeKernelArgs *kargs, char *arg)
|
||||
{
|
||||
gboolean existed;
|
||||
GPtrArray *entries = g_ptr_array_new_with_free_func (kernel_args_entry_free_from_table);
|
||||
@ -466,7 +450,8 @@ ostree_kernel_args_replace_take (OstreeKernelArgs *kargs,
|
||||
g_assert_cmpuint (old_entries->len, >, 0);
|
||||
|
||||
guint old_order_index = 0;
|
||||
g_assert (ot_ptr_array_find_with_equal_func (kargs->order, old_key, kernel_args_entry_key_equal, &old_order_index));
|
||||
g_assert (ot_ptr_array_find_with_equal_func (kargs->order, old_key,
|
||||
kernel_args_entry_key_equal, &old_order_index));
|
||||
kernel_args_remove_entries_from_order (kargs->order, old_entries);
|
||||
|
||||
g_assert_cmpstr (old_key, ==, arg);
|
||||
@ -495,8 +480,7 @@ ostree_kernel_args_replace_take (OstreeKernelArgs *kargs,
|
||||
* Since: 2019.3
|
||||
**/
|
||||
void
|
||||
ostree_kernel_args_replace (OstreeKernelArgs *kargs,
|
||||
const char *arg)
|
||||
ostree_kernel_args_replace (OstreeKernelArgs *kargs, const char *arg)
|
||||
{
|
||||
ostree_kernel_args_replace_take (kargs, g_strdup (arg));
|
||||
}
|
||||
@ -513,8 +497,7 @@ ostree_kernel_args_replace (OstreeKernelArgs *kargs,
|
||||
* Since: 2019.3
|
||||
**/
|
||||
void
|
||||
ostree_kernel_args_append (OstreeKernelArgs *kargs,
|
||||
const char *arg)
|
||||
ostree_kernel_args_append (OstreeKernelArgs *kargs, const char *arg)
|
||||
{
|
||||
gboolean existed = TRUE;
|
||||
GPtrArray *entries = NULL;
|
||||
@ -551,8 +534,7 @@ ostree_kernel_args_append (OstreeKernelArgs *kargs,
|
||||
* Since: 2019.3
|
||||
**/
|
||||
void
|
||||
ostree_kernel_args_replace_argv (OstreeKernelArgs *kargs,
|
||||
char **argv)
|
||||
ostree_kernel_args_replace_argv (OstreeKernelArgs *kargs, char **argv)
|
||||
{
|
||||
char **strviter;
|
||||
|
||||
@ -574,9 +556,7 @@ ostree_kernel_args_replace_argv (OstreeKernelArgs *kargs,
|
||||
* Since: 2019.3
|
||||
**/
|
||||
void
|
||||
ostree_kernel_args_append_argv_filtered (OstreeKernelArgs *kargs,
|
||||
char **argv,
|
||||
char **prefixes)
|
||||
ostree_kernel_args_append_argv_filtered (OstreeKernelArgs *kargs, char **argv, char **prefixes)
|
||||
{
|
||||
char **strviter;
|
||||
|
||||
@ -600,8 +580,7 @@ ostree_kernel_args_append_argv_filtered (OstreeKernelArgs *kargs,
|
||||
* Since: 2019.3
|
||||
**/
|
||||
void
|
||||
ostree_kernel_args_append_argv (OstreeKernelArgs *kargs,
|
||||
char **argv)
|
||||
ostree_kernel_args_append_argv (OstreeKernelArgs *kargs, char **argv)
|
||||
{
|
||||
ostree_kernel_args_append_argv_filtered (kargs, argv, NULL);
|
||||
}
|
||||
@ -620,32 +599,29 @@ ostree_kernel_args_append_argv (OstreeKernelArgs *kargs,
|
||||
* Since: 2019.3
|
||||
**/
|
||||
gboolean
|
||||
ostree_kernel_args_append_proc_cmdline (OstreeKernelArgs *kargs,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_kernel_args_append_proc_cmdline (OstreeKernelArgs *kargs, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GFile) proc_cmdline_path = g_file_new_for_path ("/proc/cmdline");
|
||||
g_autoptr (GFile) proc_cmdline_path = g_file_new_for_path ("/proc/cmdline");
|
||||
g_autofree char *proc_cmdline = NULL;
|
||||
gsize proc_cmdline_len = 0;
|
||||
g_auto(GStrv) proc_cmdline_args = NULL;
|
||||
g_auto (GStrv) proc_cmdline_args = NULL;
|
||||
/* When updating the filter list don't forget to update the list in the tests
|
||||
* e.g. tests/test-admin-deploy-karg.sh and
|
||||
* tests/test-admin-instutil-set-kargs.sh
|
||||
*/
|
||||
char *filtered_prefixes[] = { "BOOT_IMAGE=", /* GRUB 2 */
|
||||
"initrd=", /* sd-boot */
|
||||
"initrd=", /* sd-boot */
|
||||
NULL };
|
||||
|
||||
if (!g_file_load_contents (proc_cmdline_path, cancellable,
|
||||
&proc_cmdline, &proc_cmdline_len,
|
||||
NULL, error))
|
||||
if (!g_file_load_contents (proc_cmdline_path, cancellable, &proc_cmdline, &proc_cmdline_len, NULL,
|
||||
error))
|
||||
return FALSE;
|
||||
|
||||
g_strchomp (proc_cmdline);
|
||||
|
||||
proc_cmdline_args = g_strsplit (proc_cmdline, " ", -1);
|
||||
ostree_kernel_args_append_argv_filtered (kargs, proc_cmdline_args,
|
||||
filtered_prefixes);
|
||||
ostree_kernel_args_append_argv_filtered (kargs, proc_cmdline_args, filtered_prefixes);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -660,8 +636,7 @@ ostree_kernel_args_append_proc_cmdline (OstreeKernelArgs *kargs,
|
||||
* Since: 2019.3
|
||||
**/
|
||||
void
|
||||
ostree_kernel_args_parse_append (OstreeKernelArgs *kargs,
|
||||
const char *options)
|
||||
ostree_kernel_args_parse_append (OstreeKernelArgs *kargs, const char *options)
|
||||
{
|
||||
char **args = NULL;
|
||||
char **iter;
|
||||
@ -730,7 +705,7 @@ ostree_kernel_args_to_strv (OstreeKernelArgs *kargs)
|
||||
}
|
||||
g_ptr_array_add (strv, NULL);
|
||||
|
||||
return (char**)g_ptr_array_free (strv, FALSE);
|
||||
return (char **)g_ptr_array_free (strv, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -801,7 +776,7 @@ ostree_kernel_args_get_last_value (OstreeKernelArgs *kargs, const char *key)
|
||||
return NULL;
|
||||
|
||||
g_assert (entries->len > 0);
|
||||
const OstreeKernelArgsEntry *e = entries->pdata[entries->len-1];
|
||||
const OstreeKernelArgsEntry *e = entries->pdata[entries->len - 1];
|
||||
return _ostree_kernel_args_entry_get_value (e);
|
||||
}
|
||||
|
||||
@ -817,8 +792,7 @@ ostree_kernel_args_get_last_value (OstreeKernelArgs *kargs, const char *key)
|
||||
* Since: 2022.5
|
||||
**/
|
||||
void
|
||||
ostree_kernel_args_append_if_missing (OstreeKernelArgs *kargs,
|
||||
const char *arg)
|
||||
ostree_kernel_args_append_if_missing (OstreeKernelArgs *kargs, const char *arg)
|
||||
{
|
||||
// Don't insert a duplicate key.
|
||||
if (ostree_kernel_args_contains (kargs, arg))
|
||||
@ -840,8 +814,7 @@ ostree_kernel_args_append_if_missing (OstreeKernelArgs *kargs,
|
||||
* Since: 2022.7
|
||||
**/
|
||||
gboolean
|
||||
ostree_kernel_args_contains (OstreeKernelArgs *kargs,
|
||||
const char *arg)
|
||||
ostree_kernel_args_contains (OstreeKernelArgs *kargs, const char *arg)
|
||||
{
|
||||
g_autofree char *key = g_strdup (arg);
|
||||
split_keyeq (key);
|
||||
@ -862,9 +835,7 @@ ostree_kernel_args_contains (OstreeKernelArgs *kargs,
|
||||
* Since: 2022.7
|
||||
**/
|
||||
gboolean
|
||||
ostree_kernel_args_delete_if_present (OstreeKernelArgs *kargs,
|
||||
const char *arg,
|
||||
GError **error)
|
||||
ostree_kernel_args_delete_if_present (OstreeKernelArgs *kargs, const char *arg, GError **error)
|
||||
{
|
||||
if (ostree_kernel_args_contains (kargs, arg))
|
||||
return ostree_kernel_args_delete (kargs, arg, error);
|
||||
|
@ -17,10 +17,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include "ostree-types.h"
|
||||
#include <gio/gio.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -31,33 +31,21 @@ GHashTable *_ostree_kernel_arg_get_kargs_table (OstreeKernelArgs *kargs);
|
||||
|
||||
GPtrArray *_ostree_kernel_arg_get_key_array (OstreeKernelArgs *kargs);
|
||||
|
||||
char *
|
||||
_ostree_kernel_args_entry_get_key (const OstreeKernelArgsEntry *e);
|
||||
char *_ostree_kernel_args_entry_get_key (const OstreeKernelArgsEntry *e);
|
||||
|
||||
char *
|
||||
_ostree_kernel_args_entry_get_value (const OstreeKernelArgsEntry *e);
|
||||
char *_ostree_kernel_args_entry_get_value (const OstreeKernelArgsEntry *e);
|
||||
|
||||
void
|
||||
_ostree_kernel_args_entry_set_key (OstreeKernelArgsEntry *e,
|
||||
char *key);
|
||||
void _ostree_kernel_args_entry_set_key (OstreeKernelArgsEntry *e, char *key);
|
||||
|
||||
void
|
||||
_ostree_kernel_args_entry_set_value (OstreeKernelArgsEntry *e,
|
||||
char *value);
|
||||
void _ostree_kernel_args_entry_set_value (OstreeKernelArgsEntry *e, char *value);
|
||||
|
||||
char *
|
||||
_ostree_kernel_args_get_key_index (const OstreeKernelArgs *kargs,
|
||||
int i);
|
||||
char *_ostree_kernel_args_get_key_index (const OstreeKernelArgs *kargs, int i);
|
||||
|
||||
char *
|
||||
_ostree_kernel_args_get_value_index (const OstreeKernelArgs *kargs,
|
||||
int i);
|
||||
char *_ostree_kernel_args_get_value_index (const OstreeKernelArgs *kargs, int i);
|
||||
|
||||
OstreeKernelArgsEntry *
|
||||
_ostree_kernel_args_entry_new (void);
|
||||
OstreeKernelArgsEntry *_ostree_kernel_args_entry_new (void);
|
||||
|
||||
void
|
||||
_ostree_kernel_args_entry_value_free (OstreeKernelArgsEntry *e);
|
||||
void _ostree_kernel_args_entry_value_free (OstreeKernelArgsEntry *e);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_kernel_args_free (OstreeKernelArgs *kargs);
|
||||
@ -69,57 +57,43 @@ _OSTREE_PUBLIC
|
||||
void ostree_kernel_args_cleanup (void *loc);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_kernel_args_replace_take (OstreeKernelArgs *kargs,
|
||||
char *arg);
|
||||
void ostree_kernel_args_replace_take (OstreeKernelArgs *kargs, char *arg);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_kernel_args_replace (OstreeKernelArgs *kargs,
|
||||
const char *arg);
|
||||
void ostree_kernel_args_replace (OstreeKernelArgs *kargs, const char *arg);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_kernel_args_replace_argv (OstreeKernelArgs *kargs,
|
||||
char **argv);
|
||||
void ostree_kernel_args_replace_argv (OstreeKernelArgs *kargs, char **argv);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_kernel_args_append (OstreeKernelArgs *kargs,
|
||||
const char *arg);
|
||||
void ostree_kernel_args_append (OstreeKernelArgs *kargs, const char *arg);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_kernel_args_append_argv (OstreeKernelArgs *kargs,
|
||||
char **argv);
|
||||
void ostree_kernel_args_append_argv (OstreeKernelArgs *kargs, char **argv);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_kernel_args_append_argv_filtered (OstreeKernelArgs *kargs,
|
||||
char **argv,
|
||||
void ostree_kernel_args_append_argv_filtered (OstreeKernelArgs *kargs, char **argv,
|
||||
char **prefixes);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_kernel_args_new_replace (OstreeKernelArgs *kargs,
|
||||
const char *arg,
|
||||
GError **error);
|
||||
gboolean ostree_kernel_args_new_replace (OstreeKernelArgs *kargs, const char *arg, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_kernel_args_delete (OstreeKernelArgs *kargs,
|
||||
const char *arg,
|
||||
GError **error);
|
||||
gboolean ostree_kernel_args_delete (OstreeKernelArgs *kargs, const char *arg, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_kernel_args_delete_key_entry (OstreeKernelArgs *kargs,
|
||||
const char *key,
|
||||
GError **error);
|
||||
gboolean ostree_kernel_args_delete_key_entry (OstreeKernelArgs *kargs, const char *key,
|
||||
GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_kernel_args_append_proc_cmdline (OstreeKernelArgs *kargs,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_kernel_args_append_proc_cmdline (OstreeKernelArgs *kargs, GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_kernel_args_parse_append (OstreeKernelArgs *kargs,
|
||||
const char *options);
|
||||
void ostree_kernel_args_parse_append (OstreeKernelArgs *kargs, const char *options);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
const char *ostree_kernel_args_get_last_value (OstreeKernelArgs *kargs,
|
||||
const char *key);
|
||||
const char *ostree_kernel_args_get_last_value (OstreeKernelArgs *kargs, const char *key);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeKernelArgs *ostree_kernel_args_from_string (const char *options);
|
||||
@ -131,15 +105,12 @@ _OSTREE_PUBLIC
|
||||
char *ostree_kernel_args_to_string (OstreeKernelArgs *kargs);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_kernel_args_append_if_missing (OstreeKernelArgs *kargs,
|
||||
const char *arg);
|
||||
void ostree_kernel_args_append_if_missing (OstreeKernelArgs *kargs, const char *arg);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_kernel_args_contains (OstreeKernelArgs *kargs,
|
||||
const char *arg);
|
||||
gboolean ostree_kernel_args_contains (OstreeKernelArgs *kargs, const char *arg);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_kernel_args_delete_if_present (OstreeKernelArgs *kargs,
|
||||
const char *arg,
|
||||
GError **error);
|
||||
gboolean ostree_kernel_args_delete_if_present (OstreeKernelArgs *kargs, const char *arg,
|
||||
GError **error);
|
||||
G_END_DECLS
|
||||
|
@ -20,38 +20,32 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
|
||||
#include "ostree-libarchive-input-stream.h"
|
||||
#include <archive.h>
|
||||
#include <gio/gio.h>
|
||||
#include "ostree-libarchive-input-stream.h"
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_ARCHIVE
|
||||
};
|
||||
|
||||
struct _OstreeLibarchiveInputStreamPrivate {
|
||||
struct _OstreeLibarchiveInputStreamPrivate
|
||||
{
|
||||
struct archive *archive;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (OstreeLibarchiveInputStream, _ostree_libarchive_input_stream, G_TYPE_INPUT_STREAM)
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (OstreeLibarchiveInputStream, _ostree_libarchive_input_stream,
|
||||
G_TYPE_INPUT_STREAM)
|
||||
|
||||
static void ostree_libarchive_input_stream_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void ostree_libarchive_input_stream_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static gssize ostree_libarchive_input_stream_read (GInputStream *stream,
|
||||
void *buffer,
|
||||
gsize count,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
static gboolean ostree_libarchive_input_stream_close (GInputStream *stream,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
static void ostree_libarchive_input_stream_set_property (GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec);
|
||||
static void ostree_libarchive_input_stream_get_property (GObject *object, guint prop_id,
|
||||
GValue *value, GParamSpec *pspec);
|
||||
static gssize ostree_libarchive_input_stream_read (GInputStream *stream, void *buffer, gsize count,
|
||||
GCancellable *cancellable, GError **error);
|
||||
static gboolean ostree_libarchive_input_stream_close (GInputStream *stream,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
static void
|
||||
ostree_libarchive_input_stream_finalize (GObject *object)
|
||||
@ -77,21 +71,15 @@ _ostree_libarchive_input_stream_class_init (OstreeLibarchiveInputStreamClass *kl
|
||||
*
|
||||
* The archive that the stream reads from.
|
||||
*/
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_ARCHIVE,
|
||||
g_param_spec_pointer ("archive",
|
||||
"", "",
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (
|
||||
gobject_class, PROP_ARCHIVE,
|
||||
g_param_spec_pointer ("archive", "", "",
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
static void
|
||||
ostree_libarchive_input_stream_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
ostree_libarchive_input_stream_set_property (GObject *object, guint prop_id, const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
OstreeLibarchiveInputStream *self;
|
||||
|
||||
@ -109,10 +97,8 @@ ostree_libarchive_input_stream_set_property (GObject *object,
|
||||
}
|
||||
|
||||
static void
|
||||
ostree_libarchive_input_stream_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
ostree_libarchive_input_stream_get_property (GObject *object, guint prop_id, GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
OstreeLibarchiveInputStream *self;
|
||||
|
||||
@ -139,19 +125,14 @@ _ostree_libarchive_input_stream_new (struct archive *a)
|
||||
{
|
||||
OstreeLibarchiveInputStream *stream;
|
||||
|
||||
stream = g_object_new (OSTREE_TYPE_LIBARCHIVE_INPUT_STREAM,
|
||||
"archive", a,
|
||||
NULL);
|
||||
stream = g_object_new (OSTREE_TYPE_LIBARCHIVE_INPUT_STREAM, "archive", a, NULL);
|
||||
|
||||
return G_INPUT_STREAM (stream);
|
||||
}
|
||||
|
||||
static gssize
|
||||
ostree_libarchive_input_stream_read (GInputStream *stream,
|
||||
void *buffer,
|
||||
gsize count,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_libarchive_input_stream_read (GInputStream *stream, void *buffer, gsize count,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
OstreeLibarchiveInputStream *self;
|
||||
gssize res = -1;
|
||||
@ -164,17 +145,16 @@ ostree_libarchive_input_stream_read (GInputStream *stream,
|
||||
res = archive_read_data (self->priv->archive, buffer, count);
|
||||
if (res < 0)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"%s", archive_error_string (self->priv->archive));
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s",
|
||||
archive_error_string (self->priv->archive));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ostree_libarchive_input_stream_close (GInputStream *stream,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_libarchive_input_stream_close (GInputStream *stream, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -21,21 +21,29 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include "ostree-libarchive-private.h"
|
||||
#include <gio/gio.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_LIBARCHIVE_INPUT_STREAM (_ostree_libarchive_input_stream_get_type ())
|
||||
#define OSTREE_LIBARCHIVE_INPUT_STREAM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_LIBARCHIVE_INPUT_STREAM, OstreeLibarchiveInputStream))
|
||||
#define OSTREE_LIBARCHIVE_INPUT_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), OSTREE_TYPE_LIBARCHIVE_INPUT_STREAM, OstreeLibarchiveInputStreamClass))
|
||||
#define OSTREE_IS_LIBARCHIVE_INPUT_STREAM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_LIBARCHIVE_INPUT_STREAM))
|
||||
#define OSTREE_IS_LIBARCHIVE_INPUT_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_LIBARCHIVE_INPUT_STREAM))
|
||||
#define OSTREE_LIBARCHIVE_INPUT_STREAM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_LIBARCHIVE_INPUT_STREAM, OstreeLibarchiveInputStreamClass))
|
||||
#define OSTREE_TYPE_LIBARCHIVE_INPUT_STREAM (_ostree_libarchive_input_stream_get_type ())
|
||||
#define OSTREE_LIBARCHIVE_INPUT_STREAM(o) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_LIBARCHIVE_INPUT_STREAM, \
|
||||
OstreeLibarchiveInputStream))
|
||||
#define OSTREE_LIBARCHIVE_INPUT_STREAM_CLASS(k) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((k), OSTREE_TYPE_LIBARCHIVE_INPUT_STREAM, \
|
||||
OstreeLibarchiveInputStreamClass))
|
||||
#define OSTREE_IS_LIBARCHIVE_INPUT_STREAM(o) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_LIBARCHIVE_INPUT_STREAM))
|
||||
#define OSTREE_IS_LIBARCHIVE_INPUT_STREAM_CLASS(k) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_LIBARCHIVE_INPUT_STREAM))
|
||||
#define OSTREE_LIBARCHIVE_INPUT_STREAM_GET_CLASS(o) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_LIBARCHIVE_INPUT_STREAM, \
|
||||
OstreeLibarchiveInputStreamClass))
|
||||
|
||||
typedef struct _OstreeLibarchiveInputStream OstreeLibarchiveInputStream;
|
||||
typedef struct _OstreeLibarchiveInputStreamClass OstreeLibarchiveInputStreamClass;
|
||||
typedef struct _OstreeLibarchiveInputStreamPrivate OstreeLibarchiveInputStreamPrivate;
|
||||
typedef struct _OstreeLibarchiveInputStream OstreeLibarchiveInputStream;
|
||||
typedef struct _OstreeLibarchiveInputStreamClass OstreeLibarchiveInputStreamClass;
|
||||
typedef struct _OstreeLibarchiveInputStreamPrivate OstreeLibarchiveInputStreamPrivate;
|
||||
|
||||
struct _OstreeLibarchiveInputStream
|
||||
{
|
||||
@ -58,8 +66,8 @@ struct _OstreeLibarchiveInputStreamClass
|
||||
void (*_g_reserved5) (void);
|
||||
};
|
||||
|
||||
GType _ostree_libarchive_input_stream_get_type (void) G_GNUC_CONST;
|
||||
GType _ostree_libarchive_input_stream_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GInputStream * _ostree_libarchive_input_stream_new (struct archive *a);
|
||||
GInputStream *_ostree_libarchive_input_stream_new (struct archive *a);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -26,8 +26,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include "otutil.h"
|
||||
#include <gio/gio.h>
|
||||
#ifdef HAVE_LIBARCHIVE
|
||||
#include <archive.h>
|
||||
#include <archive_entry.h>
|
||||
@ -37,11 +37,11 @@ G_BEGIN_DECLS
|
||||
|
||||
#ifdef HAVE_LIBARCHIVE
|
||||
typedef struct archive OtAutoArchiveWrite;
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(OtAutoArchiveWrite, archive_write_free)
|
||||
typedef struct archive_entry OtArchiveEntry;
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(OtArchiveEntry, archive_entry_free)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (OtAutoArchiveWrite, archive_write_free)
|
||||
typedef struct archive_entry OtArchiveEntry;
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (OtArchiveEntry, archive_entry_free)
|
||||
typedef struct archive OtAutoArchiveRead;
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(OtAutoArchiveRead, archive_read_free)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (OtAutoArchiveRead, archive_read_free)
|
||||
|
||||
static inline OtAutoArchiveRead *
|
||||
ot_archive_read_new (void)
|
||||
@ -61,12 +61,12 @@ ot_archive_read_new (void)
|
||||
static inline OtAutoArchiveRead *
|
||||
ot_open_archive_read (const char *path, GError **error)
|
||||
{
|
||||
g_autoptr(OtAutoArchiveRead) a = ot_archive_read_new ();
|
||||
g_autoptr (OtAutoArchiveRead) a = ot_archive_read_new ();
|
||||
|
||||
if (archive_read_open_filename (a, path, 8192) != ARCHIVE_OK)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"archive_read_open_filename: %s", archive_error_string (a));
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "archive_read_open_filename: %s",
|
||||
archive_error_string (a));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -76,12 +76,12 @@ ot_open_archive_read (const char *path, GError **error)
|
||||
static inline OtAutoArchiveRead *
|
||||
ot_open_archive_read_fd (int fd, GError **error)
|
||||
{
|
||||
g_autoptr(OtAutoArchiveRead) a = ot_archive_read_new ();
|
||||
g_autoptr (OtAutoArchiveRead) a = ot_archive_read_new ();
|
||||
|
||||
if (archive_read_open_fd (a, fd, 8192) != ARCHIVE_OK)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"archive_read_open_fd: %s", archive_error_string (a));
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "archive_read_open_fd: %s",
|
||||
archive_error_string (a));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -27,8 +27,8 @@
|
||||
// This should be the only file including linux/fs.h; see
|
||||
// https://sourceware.org/glibc/wiki/Release/2.36#Usage_of_.3Clinux.2Fmount.h.3E_and_.3Csys.2Fmount.h.3E
|
||||
// https://github.com/ostreedev/ostree/issues/2685
|
||||
#include <linux/fs.h>
|
||||
#include <ext2fs/ext2_fs.h>
|
||||
#include <linux/fs.h>
|
||||
|
||||
/**
|
||||
* _ostree_linuxfs_fd_alter_immutable_flag:
|
||||
@ -45,10 +45,8 @@
|
||||
* silently do nothing.
|
||||
*/
|
||||
gboolean
|
||||
_ostree_linuxfs_fd_alter_immutable_flag (int fd,
|
||||
gboolean new_immutable_state,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_linuxfs_fd_alter_immutable_flag (int fd, gboolean new_immutable_state,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
static gint no_alter_immutable = 0;
|
||||
|
||||
@ -70,7 +68,7 @@ _ostree_linuxfs_fd_alter_immutable_flag (int fd,
|
||||
{
|
||||
gboolean prev_immutable_state = (flags & EXT2_IMMUTABLE_FL) > 0;
|
||||
if (prev_immutable_state == new_immutable_state)
|
||||
return TRUE; /* Nothing to do */
|
||||
return TRUE; /* Nothing to do */
|
||||
|
||||
if (new_immutable_state)
|
||||
flags |= EXT2_IMMUTABLE_FL;
|
||||
|
@ -23,11 +23,8 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
gboolean
|
||||
_ostree_linuxfs_fd_alter_immutable_flag (int fd,
|
||||
gboolean new_immutable_state,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean _ostree_linuxfs_fd_alter_immutable_flag (int fd, gboolean new_immutable_state,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
int _ostree_linuxfs_filesystem_freeze (int fd);
|
||||
int _ostree_linuxfs_filesystem_thaw (int fd);
|
||||
|
@ -26,8 +26,7 @@
|
||||
#include <string.h>
|
||||
|
||||
GConverterResult
|
||||
_ostree_lzma_return (lzma_ret res,
|
||||
GError **error)
|
||||
_ostree_lzma_return (lzma_ret res, GError **error)
|
||||
{
|
||||
switch (res)
|
||||
{
|
||||
@ -36,40 +35,32 @@ _ostree_lzma_return (lzma_ret res,
|
||||
case LZMA_STREAM_END:
|
||||
return G_CONVERTER_FINISHED;
|
||||
case LZMA_NO_CHECK:
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"Stream is corrupt");
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Stream is corrupt");
|
||||
return G_CONVERTER_ERROR;
|
||||
case LZMA_UNSUPPORTED_CHECK:
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"Cannot calculate integrity check");
|
||||
"Cannot calculate integrity check");
|
||||
return G_CONVERTER_ERROR;
|
||||
case LZMA_MEM_ERROR:
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"Out of memory");
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Out of memory");
|
||||
return G_CONVERTER_ERROR;
|
||||
case LZMA_MEMLIMIT_ERROR:
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"Exceeded memory limit");
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Exceeded memory limit");
|
||||
return G_CONVERTER_ERROR;
|
||||
case LZMA_FORMAT_ERROR:
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"File format not recognized");
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "File format not recognized");
|
||||
return G_CONVERTER_ERROR;
|
||||
case LZMA_OPTIONS_ERROR:
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"Invalid or unsupported options");
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid or unsupported options");
|
||||
return G_CONVERTER_ERROR;
|
||||
case LZMA_DATA_ERROR:
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"Data is corrupt");
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Data is corrupt");
|
||||
return G_CONVERTER_ERROR;
|
||||
case LZMA_BUF_ERROR:
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_PARTIAL_INPUT,
|
||||
"Input buffer too small");
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_PARTIAL_INPUT, "Input buffer too small");
|
||||
return G_CONVERTER_ERROR;
|
||||
default:
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"Unrecognized LZMA error");
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unrecognized LZMA error");
|
||||
return G_CONVERTER_ERROR;
|
||||
}
|
||||
}
|
||||
|
@ -20,14 +20,15 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ostree-lzma-compressor.h"
|
||||
#include "ostree-lzma-common.h"
|
||||
#include "ostree-lzma-compressor.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <lzma.h>
|
||||
#include <string.h>
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_PARAMS
|
||||
};
|
||||
@ -40,7 +41,7 @@ enum {
|
||||
* LZMA.
|
||||
*/
|
||||
|
||||
static void _ostree_lzma_compressor_iface_init (GConverterIface *iface);
|
||||
static void _ostree_lzma_compressor_iface_init (GConverterIface *iface);
|
||||
|
||||
/**
|
||||
* OstreeLzmaCompressor:
|
||||
@ -56,10 +57,9 @@ struct _OstreeLzmaCompressor
|
||||
gboolean initialized;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (OstreeLzmaCompressor, _ostree_lzma_compressor,
|
||||
G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_CONVERTER,
|
||||
_ostree_lzma_compressor_iface_init))
|
||||
G_DEFINE_TYPE_WITH_CODE (OstreeLzmaCompressor, _ostree_lzma_compressor, G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_CONVERTER,
|
||||
_ostree_lzma_compressor_iface_init))
|
||||
|
||||
static void
|
||||
_ostree_lzma_compressor_finalize (GObject *object)
|
||||
@ -73,10 +73,8 @@ _ostree_lzma_compressor_finalize (GObject *object)
|
||||
}
|
||||
|
||||
static void
|
||||
_ostree_lzma_compressor_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
_ostree_lzma_compressor_set_property (GObject *object, guint prop_id, const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
OstreeLzmaCompressor *self = OSTREE_LZMA_COMPRESSOR (object);
|
||||
|
||||
@ -90,14 +88,11 @@ _ostree_lzma_compressor_set_property (GObject *object,
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
_ostree_lzma_compressor_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
_ostree_lzma_compressor_get_property (GObject *object, guint prop_id, GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
OstreeLzmaCompressor *self = OSTREE_LZMA_COMPRESSOR (object);
|
||||
|
||||
@ -129,21 +124,16 @@ _ostree_lzma_compressor_class_init (OstreeLzmaCompressorClass *klass)
|
||||
gobject_class->get_property = _ostree_lzma_compressor_get_property;
|
||||
gobject_class->set_property = _ostree_lzma_compressor_set_property;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_PARAMS,
|
||||
g_param_spec_variant ("params", "", "",
|
||||
G_VARIANT_TYPE ("a{sv}"),
|
||||
NULL,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property (
|
||||
gobject_class, PROP_PARAMS,
|
||||
g_param_spec_variant ("params", "", "", G_VARIANT_TYPE ("a{sv}"), NULL,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
OstreeLzmaCompressor *
|
||||
_ostree_lzma_compressor_new (GVariant *params)
|
||||
{
|
||||
return g_object_new (OSTREE_TYPE_LZMA_COMPRESSOR,
|
||||
"params", params,
|
||||
NULL);
|
||||
return g_object_new (OSTREE_TYPE_LZMA_COMPRESSOR, "params", params, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -161,15 +151,9 @@ _ostree_lzma_compressor_reset (GConverter *converter)
|
||||
}
|
||||
|
||||
static GConverterResult
|
||||
_ostree_lzma_compressor_convert (GConverter *converter,
|
||||
const void *inbuf,
|
||||
gsize inbuf_size,
|
||||
void *outbuf,
|
||||
gsize outbuf_size,
|
||||
GConverterFlags flags,
|
||||
gsize *bytes_read,
|
||||
gsize *bytes_written,
|
||||
GError **error)
|
||||
_ostree_lzma_compressor_convert (GConverter *converter, const void *inbuf, gsize inbuf_size,
|
||||
void *outbuf, gsize outbuf_size, GConverterFlags flags,
|
||||
gsize *bytes_read, gsize *bytes_written, GError **error)
|
||||
{
|
||||
OstreeLzmaCompressor *self = OSTREE_LZMA_COMPRESSOR (converter);
|
||||
int res;
|
||||
@ -177,8 +161,7 @@ _ostree_lzma_compressor_convert (GConverter *converter,
|
||||
|
||||
if (inbuf_size != 0 && outbuf_size == 0)
|
||||
{
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NO_SPACE,
|
||||
"Output buffer too small");
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NO_SPACE, "Output buffer too small");
|
||||
return G_CONVERTER_ERROR;
|
||||
}
|
||||
|
||||
@ -209,7 +192,7 @@ _ostree_lzma_compressor_convert (GConverter *converter,
|
||||
*bytes_read = inbuf_size - self->lstream.avail_in;
|
||||
*bytes_written = outbuf_size - self->lstream.avail_out;
|
||||
|
||||
out:
|
||||
out:
|
||||
return _ostree_lzma_return (res, error);
|
||||
}
|
||||
|
||||
|
@ -23,22 +23,26 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_LZMA_COMPRESSOR (_ostree_lzma_compressor_get_type ())
|
||||
#define OSTREE_LZMA_COMPRESSOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_LZMA_COMPRESSOR, OstreeLzmaCompressor))
|
||||
#define OSTREE_LZMA_COMPRESSOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), OSTREE_TYPE_LZMA_COMPRESSOR, OstreeLzmaCompressorClass))
|
||||
#define OSTREE_IS_LZMA_COMPRESSOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_LZMA_COMPRESSOR))
|
||||
#define OSTREE_IS_LZMA_COMPRESSOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_LZMA_COMPRESSOR))
|
||||
#define OSTREE_LZMA_COMPRESSOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_LZMA_COMPRESSOR, OstreeLzmaCompressorClass))
|
||||
#define OSTREE_TYPE_LZMA_COMPRESSOR (_ostree_lzma_compressor_get_type ())
|
||||
#define OSTREE_LZMA_COMPRESSOR(o) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_LZMA_COMPRESSOR, OstreeLzmaCompressor))
|
||||
#define OSTREE_LZMA_COMPRESSOR_CLASS(k) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((k), OSTREE_TYPE_LZMA_COMPRESSOR, OstreeLzmaCompressorClass))
|
||||
#define OSTREE_IS_LZMA_COMPRESSOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_LZMA_COMPRESSOR))
|
||||
#define OSTREE_IS_LZMA_COMPRESSOR_CLASS(k) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_LZMA_COMPRESSOR))
|
||||
#define OSTREE_LZMA_COMPRESSOR_GET_CLASS(o) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_LZMA_COMPRESSOR, OstreeLzmaCompressorClass))
|
||||
|
||||
typedef struct _OstreeLzmaCompressorClass OstreeLzmaCompressorClass;
|
||||
typedef struct _OstreeLzmaCompressor OstreeLzmaCompressor;
|
||||
typedef struct _OstreeLzmaCompressorClass OstreeLzmaCompressorClass;
|
||||
typedef struct _OstreeLzmaCompressor OstreeLzmaCompressor;
|
||||
|
||||
struct _OstreeLzmaCompressorClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
GType _ostree_lzma_compressor_get_type (void) G_GNUC_CONST;
|
||||
GType _ostree_lzma_compressor_get_type (void) G_GNUC_CONST;
|
||||
|
||||
OstreeLzmaCompressor *_ostree_lzma_compressor_new (GVariant *params);
|
||||
|
||||
|
@ -19,14 +19,15 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ostree-lzma-decompressor.h"
|
||||
#include "ostree-lzma-common.h"
|
||||
#include "ostree-lzma-decompressor.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <lzma.h>
|
||||
#include <string.h>
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
};
|
||||
|
||||
@ -38,7 +39,7 @@ enum {
|
||||
* LZMA.
|
||||
*/
|
||||
|
||||
static void _ostree_lzma_decompressor_iface_init (GConverterIface *iface);
|
||||
static void _ostree_lzma_decompressor_iface_init (GConverterIface *iface);
|
||||
|
||||
struct _OstreeLzmaDecompressor
|
||||
{
|
||||
@ -48,10 +49,9 @@ struct _OstreeLzmaDecompressor
|
||||
gboolean initialized;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (OstreeLzmaDecompressor, _ostree_lzma_decompressor,
|
||||
G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_CONVERTER,
|
||||
_ostree_lzma_decompressor_iface_init))
|
||||
G_DEFINE_TYPE_WITH_CODE (OstreeLzmaDecompressor, _ostree_lzma_decompressor, G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_CONVERTER,
|
||||
_ostree_lzma_decompressor_iface_init))
|
||||
|
||||
static void
|
||||
_ostree_lzma_decompressor_finalize (GObject *object)
|
||||
@ -100,23 +100,16 @@ _ostree_lzma_decompressor_reset (GConverter *converter)
|
||||
}
|
||||
|
||||
static GConverterResult
|
||||
_ostree_lzma_decompressor_convert (GConverter *converter,
|
||||
const void *inbuf,
|
||||
gsize inbuf_size,
|
||||
void *outbuf,
|
||||
gsize outbuf_size,
|
||||
GConverterFlags flags,
|
||||
gsize *bytes_read,
|
||||
gsize *bytes_written,
|
||||
GError **error)
|
||||
_ostree_lzma_decompressor_convert (GConverter *converter, const void *inbuf, gsize inbuf_size,
|
||||
void *outbuf, gsize outbuf_size, GConverterFlags flags,
|
||||
gsize *bytes_read, gsize *bytes_written, GError **error)
|
||||
{
|
||||
OstreeLzmaDecompressor *self = OSTREE_LZMA_DECOMPRESSOR (converter);
|
||||
int res;
|
||||
|
||||
if (inbuf_size != 0 && outbuf_size == 0)
|
||||
{
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NO_SPACE,
|
||||
"Output buffer too small");
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NO_SPACE, "Output buffer too small");
|
||||
return G_CONVERTER_ERROR;
|
||||
}
|
||||
|
||||
@ -141,7 +134,7 @@ _ostree_lzma_decompressor_convert (GConverter *converter,
|
||||
*bytes_read = inbuf_size - self->lstream.avail_in;
|
||||
*bytes_written = outbuf_size - self->lstream.avail_out;
|
||||
|
||||
out:
|
||||
out:
|
||||
return _ostree_lzma_return (res, error);
|
||||
}
|
||||
|
||||
|
@ -23,15 +23,20 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_LZMA_DECOMPRESSOR (_ostree_lzma_decompressor_get_type ())
|
||||
#define OSTREE_LZMA_DECOMPRESSOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_LZMA_DECOMPRESSOR, OstreeLzmaDecompressor))
|
||||
#define OSTREE_LZMA_DECOMPRESSOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), OSTREE_TYPE_LZMA_DECOMPRESSOR, OstreeLzmaDecompressorClass))
|
||||
#define OSTREE_IS_LZMA_DECOMPRESSOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_LZMA_DECOMPRESSOR))
|
||||
#define OSTREE_IS_LZMA_DECOMPRESSOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_LZMA_DECOMPRESSOR))
|
||||
#define OSTREE_LZMA_DECOMPRESSOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_LZMA_DECOMPRESSOR, OstreeLzmaDecompressorClass))
|
||||
#define OSTREE_TYPE_LZMA_DECOMPRESSOR (_ostree_lzma_decompressor_get_type ())
|
||||
#define OSTREE_LZMA_DECOMPRESSOR(o) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_LZMA_DECOMPRESSOR, OstreeLzmaDecompressor))
|
||||
#define OSTREE_LZMA_DECOMPRESSOR_CLASS(k) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((k), OSTREE_TYPE_LZMA_DECOMPRESSOR, OstreeLzmaDecompressorClass))
|
||||
#define OSTREE_IS_LZMA_DECOMPRESSOR(o) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_LZMA_DECOMPRESSOR))
|
||||
#define OSTREE_IS_LZMA_DECOMPRESSOR_CLASS(k) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_LZMA_DECOMPRESSOR))
|
||||
#define OSTREE_LZMA_DECOMPRESSOR_GET_CLASS(o) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_LZMA_DECOMPRESSOR, OstreeLzmaDecompressorClass))
|
||||
|
||||
typedef struct _OstreeLzmaDecompressorClass OstreeLzmaDecompressorClass;
|
||||
typedef struct _OstreeLzmaDecompressor OstreeLzmaDecompressor;
|
||||
typedef struct _OstreeLzmaDecompressorClass OstreeLzmaDecompressorClass;
|
||||
typedef struct _OstreeLzmaDecompressor OstreeLzmaDecompressor;
|
||||
|
||||
struct _OstreeLzmaDecompressorClass
|
||||
{
|
||||
@ -39,7 +44,7 @@ struct _OstreeLzmaDecompressorClass
|
||||
};
|
||||
|
||||
GLIB_AVAILABLE_IN_ALL
|
||||
GType _ostree_lzma_decompressor_get_type (void) G_GNUC_CONST;
|
||||
GType _ostree_lzma_decompressor_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GLIB_AVAILABLE_IN_ALL
|
||||
OstreeLzmaDecompressor *_ostree_lzma_decompressor_new (void);
|
||||
|
@ -19,13 +19,14 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ostree-metalink.h"
|
||||
#include "ostree-fetcher-util.h"
|
||||
#include "ostree-metalink.h"
|
||||
#include <gio/gfiledescriptorbased.h>
|
||||
|
||||
#include "otutil.h"
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
OSTREE_METALINK_STATE_INITIAL,
|
||||
OSTREE_METALINK_STATE_METALINK,
|
||||
OSTREE_METALINK_STATE_FILES,
|
||||
@ -83,8 +84,7 @@ typedef struct
|
||||
} OstreeMetalinkRequest;
|
||||
|
||||
static void
|
||||
state_transition (OstreeMetalinkRequest *self,
|
||||
OstreeMetalinkState new_state)
|
||||
state_transition (OstreeMetalinkRequest *self, OstreeMetalinkState new_state)
|
||||
{
|
||||
g_assert (self->state != new_state);
|
||||
|
||||
@ -95,21 +95,16 @@ state_transition (OstreeMetalinkRequest *self,
|
||||
}
|
||||
|
||||
static void
|
||||
unknown_element (OstreeMetalinkRequest *self,
|
||||
const char *element_name,
|
||||
GError **error)
|
||||
unknown_element (OstreeMetalinkRequest *self, const char *element_name, GError **error)
|
||||
{
|
||||
state_transition (self, OSTREE_METALINK_STATE_PASSTHROUGH);
|
||||
g_assert (self->passthrough_depth == 0);
|
||||
}
|
||||
|
||||
static void
|
||||
metalink_parser_start (GMarkupParseContext *context,
|
||||
const gchar *element_name,
|
||||
const gchar **attribute_names,
|
||||
const gchar **attribute_values,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
metalink_parser_start (GMarkupParseContext *context, const gchar *element_name,
|
||||
const gchar **attribute_names, const gchar **attribute_values,
|
||||
gpointer user_data, GError **error)
|
||||
{
|
||||
OstreeMetalinkRequest *self = user_data;
|
||||
|
||||
@ -139,13 +134,8 @@ metalink_parser_start (GMarkupParseContext *context,
|
||||
{
|
||||
const char *file_name;
|
||||
|
||||
if (!g_markup_collect_attributes (element_name,
|
||||
attribute_names,
|
||||
attribute_values,
|
||||
error,
|
||||
G_MARKUP_COLLECT_STRING,
|
||||
"name",
|
||||
&file_name,
|
||||
if (!g_markup_collect_attributes (element_name, attribute_names, attribute_values, error,
|
||||
G_MARKUP_COLLECT_STRING, "name", &file_name,
|
||||
G_MARKUP_COLLECT_INVALID))
|
||||
goto out;
|
||||
|
||||
@ -181,16 +171,11 @@ metalink_parser_start (GMarkupParseContext *context,
|
||||
case OSTREE_METALINK_STATE_VERIFICATION:
|
||||
if (strcmp (element_name, "hash") == 0)
|
||||
{
|
||||
char *verification_type_str = NULL;
|
||||
char *verification_type_str = NULL;
|
||||
|
||||
state_transition (self, OSTREE_METALINK_STATE_HASH);
|
||||
if (!g_markup_collect_attributes (element_name,
|
||||
attribute_names,
|
||||
attribute_values,
|
||||
error,
|
||||
G_MARKUP_COLLECT_STRING,
|
||||
"type",
|
||||
&verification_type_str,
|
||||
if (!g_markup_collect_attributes (element_name, attribute_names, attribute_values, error,
|
||||
G_MARKUP_COLLECT_STRING, "type", &verification_type_str,
|
||||
G_MARKUP_COLLECT_INVALID))
|
||||
goto out;
|
||||
|
||||
@ -227,23 +212,11 @@ metalink_parser_start (GMarkupParseContext *context,
|
||||
{
|
||||
const char *protocol;
|
||||
|
||||
if (!g_markup_collect_attributes (element_name,
|
||||
attribute_names,
|
||||
attribute_values,
|
||||
error,
|
||||
G_MARKUP_COLLECT_STRING,
|
||||
"protocol",
|
||||
&protocol,
|
||||
G_MARKUP_COLLECT_STRING,
|
||||
"type",
|
||||
NULL,
|
||||
G_MARKUP_COLLECT_STRING,
|
||||
"location",
|
||||
NULL,
|
||||
G_MARKUP_COLLECT_STRING,
|
||||
"preference",
|
||||
NULL,
|
||||
G_MARKUP_COLLECT_INVALID))
|
||||
if (!g_markup_collect_attributes (
|
||||
element_name, attribute_names, attribute_values, error, G_MARKUP_COLLECT_STRING,
|
||||
"protocol", &protocol, G_MARKUP_COLLECT_STRING, "type", NULL,
|
||||
G_MARKUP_COLLECT_STRING, "location", NULL, G_MARKUP_COLLECT_STRING, "preference",
|
||||
NULL, G_MARKUP_COLLECT_INVALID))
|
||||
goto out;
|
||||
|
||||
/* Ignore non-HTTP resources */
|
||||
@ -263,15 +236,13 @@ metalink_parser_start (GMarkupParseContext *context,
|
||||
break;
|
||||
}
|
||||
|
||||
out:
|
||||
out:
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
metalink_parser_end (GMarkupParseContext *context,
|
||||
const gchar *element_name,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
metalink_parser_end (GMarkupParseContext *context, const gchar *element_name, gpointer user_data,
|
||||
GError **error)
|
||||
{
|
||||
OstreeMetalinkRequest *self = user_data;
|
||||
|
||||
@ -309,11 +280,8 @@ metalink_parser_end (GMarkupParseContext *context,
|
||||
}
|
||||
|
||||
static void
|
||||
metalink_parser_text (GMarkupParseContext *context,
|
||||
const gchar *text,
|
||||
gsize text_len,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
metalink_parser_text (GMarkupParseContext *context, const gchar *text, gsize text_len,
|
||||
gpointer user_data, GError **error)
|
||||
{
|
||||
OstreeMetalinkRequest *self = user_data;
|
||||
|
||||
@ -366,7 +334,6 @@ metalink_parser_text (GMarkupParseContext *context,
|
||||
case OSTREE_METALINK_STATE_PASSTHROUGH:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
@ -397,13 +364,10 @@ _ostree_metalink_init (OstreeMetalink *self)
|
||||
}
|
||||
|
||||
OstreeMetalink *
|
||||
_ostree_metalink_new (OstreeFetcher *fetcher,
|
||||
const char *requested_file,
|
||||
guint64 max_size,
|
||||
OstreeFetcherURI *uri,
|
||||
guint n_network_retries)
|
||||
_ostree_metalink_new (OstreeFetcher *fetcher, const char *requested_file, guint64 max_size,
|
||||
OstreeFetcherURI *uri, guint n_network_retries)
|
||||
{
|
||||
OstreeMetalink *self = (OstreeMetalink*)g_object_new (OSTREE_TYPE_METALINK, NULL);
|
||||
OstreeMetalink *self = (OstreeMetalink *)g_object_new (OSTREE_TYPE_METALINK, NULL);
|
||||
|
||||
self->fetcher = g_object_ref (fetcher);
|
||||
self->requested_file = g_strdup (requested_file);
|
||||
@ -423,31 +387,23 @@ valid_hex_checksum (const char *s, gsize expected_len)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
try_one_url (OstreeMetalinkRequest *self,
|
||||
OstreeFetcherURI *uri,
|
||||
GBytes **out_data,
|
||||
GError **error)
|
||||
try_one_url (OstreeMetalinkRequest *self, OstreeFetcherURI *uri, GBytes **out_data, GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
g_autoptr(GBytes) bytes = NULL;
|
||||
g_autoptr (GBytes) bytes = NULL;
|
||||
gssize n_bytes;
|
||||
|
||||
if (!_ostree_fetcher_request_uri_to_membuf (self->metalink->fetcher,
|
||||
uri, 0,
|
||||
NULL, 0,
|
||||
self->metalink->n_network_retries,
|
||||
&bytes,
|
||||
NULL, NULL, NULL,
|
||||
self->metalink->max_size,
|
||||
self->cancellable,
|
||||
error))
|
||||
if (!_ostree_fetcher_request_uri_to_membuf (
|
||||
self->metalink->fetcher, uri, 0, NULL, 0, self->metalink->n_network_retries, &bytes, NULL,
|
||||
NULL, NULL, self->metalink->max_size, self->cancellable, error))
|
||||
goto out;
|
||||
|
||||
n_bytes = g_bytes_get_size (bytes);
|
||||
if (n_bytes != self->size)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"Expected size is %" G_GUINT64_FORMAT " bytes but content is %" G_GSSIZE_FORMAT " bytes",
|
||||
"Expected size is %" G_GUINT64_FORMAT " bytes but content is %" G_GSSIZE_FORMAT
|
||||
" bytes",
|
||||
self->size, n_bytes);
|
||||
goto out;
|
||||
}
|
||||
@ -461,8 +417,8 @@ try_one_url (OstreeMetalinkRequest *self,
|
||||
if (strcmp (self->verification_sha512, actual) != 0)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"Expected checksum is %s but actual is %s",
|
||||
self->verification_sha512, actual);
|
||||
"Expected checksum is %s but actual is %s", self->verification_sha512,
|
||||
actual);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
@ -475,8 +431,8 @@ try_one_url (OstreeMetalinkRequest *self,
|
||||
if (strcmp (self->verification_sha256, actual) != 0)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"Expected checksum is %s but actual is %s",
|
||||
self->verification_sha256, actual);
|
||||
"Expected checksum is %s but actual is %s", self->verification_sha256,
|
||||
actual);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
@ -484,24 +440,21 @@ try_one_url (OstreeMetalinkRequest *self,
|
||||
ret = TRUE;
|
||||
if (out_data)
|
||||
*out_data = g_steal_pointer (&bytes);
|
||||
out:
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
try_metalink_targets (OstreeMetalinkRequest *self,
|
||||
OstreeFetcherURI **out_target_uri,
|
||||
GBytes **out_data,
|
||||
GError **error)
|
||||
try_metalink_targets (OstreeMetalinkRequest *self, OstreeFetcherURI **out_target_uri,
|
||||
GBytes **out_data, GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
OstreeFetcherURI *target_uri = NULL;
|
||||
g_autoptr(GBytes) ret_data = NULL;
|
||||
g_autoptr (GBytes) ret_data = NULL;
|
||||
|
||||
if (!self->found_a_file_element)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"No <file> element found");
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "No <file> element found");
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -510,8 +463,8 @@ try_metalink_targets (OstreeMetalinkRequest *self,
|
||||
/* XXX Use NOT_FOUND here so we can distinguish not finding the
|
||||
* requested file from other errors. This is a bit of a hack
|
||||
* through; metalinks should have their own error enum. */
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
||||
"No <file name='%s'> found", self->metalink->requested_file);
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "No <file name='%s'> found",
|
||||
self->metalink->requested_file);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -524,27 +477,23 @@ try_metalink_targets (OstreeMetalinkRequest *self,
|
||||
|
||||
if (self->verification_sha256 && !valid_hex_checksum (self->verification_sha256, 64))
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"Invalid hash digest for sha256");
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid hash digest for sha256");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (self->verification_sha512 && !valid_hex_checksum (self->verification_sha512, 128))
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"Invalid hash digest for sha512");
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid hash digest for sha512");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (self->urls->len == 0)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"No <url method='http'> elements found");
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "No <url method='http'> elements found");
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (self->current_url_index = 0;
|
||||
self->current_url_index < self->urls->len;
|
||||
for (self->current_url_index = 0; self->current_url_index < self->urls->len;
|
||||
self->current_url_index++)
|
||||
{
|
||||
GError *temp_error = NULL;
|
||||
@ -565,8 +514,8 @@ try_metalink_targets (OstreeMetalinkRequest *self,
|
||||
{
|
||||
g_assert (self->last_metalink_error != NULL);
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"Exhausted %u metalink targets, last error: %s",
|
||||
self->urls->len, self->last_metalink_error);
|
||||
"Exhausted %u metalink targets, last error: %s", self->urls->len,
|
||||
self->last_metalink_error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -575,38 +524,32 @@ try_metalink_targets (OstreeMetalinkRequest *self,
|
||||
*out_target_uri = _ostree_fetcher_uri_clone (target_uri);
|
||||
if (out_data)
|
||||
*out_data = g_steal_pointer (&ret_data);
|
||||
out:
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const GMarkupParser metalink_parser = {
|
||||
metalink_parser_start,
|
||||
metalink_parser_end,
|
||||
metalink_parser_text,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
static const GMarkupParser metalink_parser
|
||||
= { metalink_parser_start, metalink_parser_end, metalink_parser_text, NULL, NULL };
|
||||
|
||||
typedef struct
|
||||
{
|
||||
OstreeFetcherURI **out_target_uri;
|
||||
GBytes **out_data;
|
||||
gboolean success;
|
||||
GError **error;
|
||||
GMainLoop *loop;
|
||||
OstreeFetcherURI **out_target_uri;
|
||||
GBytes **out_data;
|
||||
gboolean success;
|
||||
GError **error;
|
||||
GMainLoop *loop;
|
||||
} FetchMetalinkSyncData;
|
||||
|
||||
gboolean
|
||||
_ostree_metalink_request_sync (OstreeMetalink *self,
|
||||
OstreeFetcherURI **out_target_uri,
|
||||
GBytes **out_data,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_metalink_request_sync (OstreeMetalink *self, OstreeFetcherURI **out_target_uri,
|
||||
GBytes **out_data, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
OstreeMetalinkRequest request = { 0, };
|
||||
g_autoptr(GMainContext) mainctx = NULL;
|
||||
g_autoptr(GBytes) contents = NULL;
|
||||
OstreeMetalinkRequest request = {
|
||||
0,
|
||||
};
|
||||
g_autoptr (GMainContext) mainctx = NULL;
|
||||
g_autoptr (GBytes) contents = NULL;
|
||||
gsize len;
|
||||
const guint8 *data;
|
||||
|
||||
@ -614,25 +557,24 @@ _ostree_metalink_request_sync (OstreeMetalink *self,
|
||||
g_main_context_push_thread_default (mainctx);
|
||||
|
||||
request.metalink = g_object_ref (self);
|
||||
request.urls = g_ptr_array_new_with_free_func ((GDestroyNotify) _ostree_fetcher_uri_free);
|
||||
request.parser = g_markup_parse_context_new (&metalink_parser, G_MARKUP_PREFIX_ERROR_POSITION, &request, NULL);
|
||||
request.urls = g_ptr_array_new_with_free_func ((GDestroyNotify)_ostree_fetcher_uri_free);
|
||||
request.parser = g_markup_parse_context_new (&metalink_parser, G_MARKUP_PREFIX_ERROR_POSITION,
|
||||
&request, NULL);
|
||||
|
||||
if (!_ostree_fetcher_request_uri_to_membuf (self->fetcher, self->uri, 0,
|
||||
NULL, 0,
|
||||
self->n_network_retries,
|
||||
&contents, NULL, NULL, NULL, self->max_size,
|
||||
cancellable, error))
|
||||
if (!_ostree_fetcher_request_uri_to_membuf (self->fetcher, self->uri, 0, NULL, 0,
|
||||
self->n_network_retries, &contents, NULL, NULL, NULL,
|
||||
self->max_size, cancellable, error))
|
||||
goto out;
|
||||
|
||||
data = g_bytes_get_data (contents, &len);
|
||||
if (!g_markup_parse_context_parse (request.parser, (const char*)data, len, error))
|
||||
if (!g_markup_parse_context_parse (request.parser, (const char *)data, len, error))
|
||||
goto out;
|
||||
|
||||
if (!try_metalink_targets (&request, out_target_uri, out_data, error))
|
||||
goto out;
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
out:
|
||||
if (mainctx)
|
||||
g_main_context_pop_thread_default (mainctx);
|
||||
g_clear_object (&request.metalink);
|
||||
|
@ -25,15 +25,17 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_METALINK (_ostree_metalink_get_type ())
|
||||
#define OSTREE_METALINK(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_METALINK, OstreeMetalink))
|
||||
#define OSTREE_METALINK_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), OSTREE_TYPE_METALINK, OstreeMetalinkClass))
|
||||
#define OSTREE_IS_METALINK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_METALINK))
|
||||
#define OSTREE_IS_METALINK_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_METALINK))
|
||||
#define OSTREE_METALINK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_METALINK, OstreeMetalinkClass))
|
||||
#define OSTREE_TYPE_METALINK (_ostree_metalink_get_type ())
|
||||
#define OSTREE_METALINK(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_METALINK, OstreeMetalink))
|
||||
#define OSTREE_METALINK_CLASS(k) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((k), OSTREE_TYPE_METALINK, OstreeMetalinkClass))
|
||||
#define OSTREE_IS_METALINK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_METALINK))
|
||||
#define OSTREE_IS_METALINK_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_METALINK))
|
||||
#define OSTREE_METALINK_GET_CLASS(o) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_METALINK, OstreeMetalinkClass))
|
||||
|
||||
typedef struct OstreeMetalinkClass OstreeMetalinkClass;
|
||||
typedef struct OstreeMetalink OstreeMetalink;
|
||||
typedef struct OstreeMetalinkClass OstreeMetalinkClass;
|
||||
typedef struct OstreeMetalink OstreeMetalink;
|
||||
|
||||
struct OstreeMetalinkClass
|
||||
{
|
||||
@ -41,19 +43,15 @@ struct OstreeMetalinkClass
|
||||
};
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeMetalink, g_object_unref)
|
||||
|
||||
GType _ostree_metalink_get_type (void) G_GNUC_CONST;
|
||||
GType _ostree_metalink_get_type (void) G_GNUC_CONST;
|
||||
|
||||
OstreeMetalink *_ostree_metalink_new (OstreeFetcher *fetcher,
|
||||
const char *requested_file,
|
||||
guint64 max_size,
|
||||
OstreeFetcherURI *uri,
|
||||
guint n_network_retries);
|
||||
OstreeMetalink *_ostree_metalink_new (OstreeFetcher *fetcher, const char *requested_file,
|
||||
guint64 max_size, OstreeFetcherURI *uri,
|
||||
guint n_network_retries);
|
||||
|
||||
gboolean _ostree_metalink_request_sync (OstreeMetalink *self,
|
||||
OstreeFetcherURI **out_target_uri,
|
||||
GBytes **out_data,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean _ostree_metalink_request_sync (OstreeMetalink *self, OstreeFetcherURI **out_target_uri,
|
||||
GBytes **out_data, GCancellable *cancellable,
|
||||
GError **error);
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
|
@ -21,8 +21,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "otutil.h"
|
||||
#include "ostree.h"
|
||||
#include "otutil.h"
|
||||
|
||||
#include "ostree-core-private.h"
|
||||
|
||||
@ -38,13 +38,14 @@
|
||||
* programmatically.
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
MTREE_STATE_WHOLE,
|
||||
typedef enum
|
||||
{
|
||||
MTREE_STATE_WHOLE,
|
||||
|
||||
/* MTREE_STATE_LAZY allows us to not read files and subdirs from the objects
|
||||
* on disk until they're actually needed - often they won't be needed at
|
||||
* all. */
|
||||
MTREE_STATE_LAZY
|
||||
/* MTREE_STATE_LAZY allows us to not read files and subdirs from the objects
|
||||
* on disk until they're actually needed - often they won't be needed at
|
||||
* all. */
|
||||
MTREE_STATE_LAZY
|
||||
} OstreeMutableTreeState;
|
||||
|
||||
/**
|
||||
@ -132,8 +133,7 @@ ostree_mutable_tree_class_init (OstreeMutableTreeClass *klass)
|
||||
*
|
||||
* Ownership of @child is transferred from the caller to @self */
|
||||
static void
|
||||
insert_child_mtree (OstreeMutableTree *self, const gchar* name,
|
||||
OstreeMutableTree *child)
|
||||
insert_child_mtree (OstreeMutableTree *self, const gchar *name, OstreeMutableTree *child)
|
||||
{
|
||||
g_assert_null (child->parent);
|
||||
g_hash_table_insert (self->subdirs, g_strdup (name), child);
|
||||
@ -147,7 +147,7 @@ remove_child_mtree (gpointer data)
|
||||
* non-owning reference back to parent. If the parent goes out of scope the
|
||||
* children may still be alive because they're reference counted. This
|
||||
* removes the reference to the parent before it goes stale. */
|
||||
OstreeMutableTree *child = (OstreeMutableTree*) data;
|
||||
OstreeMutableTree *child = (OstreeMutableTree *)data;
|
||||
child->parent = NULL;
|
||||
g_object_unref (child);
|
||||
}
|
||||
@ -155,30 +155,27 @@ remove_child_mtree (gpointer data)
|
||||
static void
|
||||
ostree_mutable_tree_init (OstreeMutableTree *self)
|
||||
{
|
||||
self->files = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free, g_free);
|
||||
self->subdirs = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free, remove_child_mtree);
|
||||
self->files = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
||||
self->subdirs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, remove_child_mtree);
|
||||
self->state = MTREE_STATE_WHOLE;
|
||||
}
|
||||
|
||||
static void
|
||||
invalidate_contents_checksum (OstreeMutableTree *self)
|
||||
{
|
||||
while (self) {
|
||||
if (!self->contents_checksum)
|
||||
break;
|
||||
while (self)
|
||||
{
|
||||
if (!self->contents_checksum)
|
||||
break;
|
||||
|
||||
g_clear_pointer (&self->contents_checksum, g_free);
|
||||
self = self->parent;
|
||||
}
|
||||
g_clear_pointer (&self->contents_checksum, g_free);
|
||||
self = self->parent;
|
||||
}
|
||||
}
|
||||
|
||||
/* Go from state LAZY to state WHOLE by reading the tree from disk */
|
||||
static gboolean
|
||||
_ostree_mutable_tree_make_whole (OstreeMutableTree *self,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_mutable_tree_make_whole (OstreeMutableTree *self, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
if (self->state == MTREE_STATE_WHOLE)
|
||||
return TRUE;
|
||||
@ -190,13 +187,13 @@ _ostree_mutable_tree_make_whole (OstreeMutableTree *self,
|
||||
g_assert_cmpuint (g_hash_table_size (self->files), ==, 0);
|
||||
g_assert_cmpuint (g_hash_table_size (self->subdirs), ==, 0);
|
||||
|
||||
g_autoptr(GVariant) dirtree = NULL;
|
||||
if (!ostree_repo_load_variant (self->repo, OSTREE_OBJECT_TYPE_DIR_TREE,
|
||||
self->contents_checksum, &dirtree, error))
|
||||
g_autoptr (GVariant) dirtree = NULL;
|
||||
if (!ostree_repo_load_variant (self->repo, OSTREE_OBJECT_TYPE_DIR_TREE, self->contents_checksum,
|
||||
&dirtree, error))
|
||||
return FALSE;
|
||||
|
||||
{
|
||||
g_autoptr(GVariant) dir_file_contents = g_variant_get_child_value (dirtree, 0);
|
||||
g_autoptr (GVariant) dir_file_contents = g_variant_get_child_value (dirtree, 0);
|
||||
GVariantIter viter;
|
||||
g_variant_iter_init (&viter, dir_file_contents);
|
||||
const char *fname;
|
||||
@ -205,28 +202,28 @@ _ostree_mutable_tree_make_whole (OstreeMutableTree *self,
|
||||
{
|
||||
char tmp_checksum[OSTREE_SHA256_STRING_LEN + 1];
|
||||
_ostree_checksum_inplace_from_bytes_v (contents_csum_v, tmp_checksum);
|
||||
g_hash_table_insert (self->files, g_strdup (fname),
|
||||
g_strdup (tmp_checksum));
|
||||
g_hash_table_insert (self->files, g_strdup (fname), g_strdup (tmp_checksum));
|
||||
}
|
||||
}
|
||||
|
||||
/* Process subdirectories */
|
||||
{
|
||||
g_autoptr(GVariant) dir_subdirs = g_variant_get_child_value (dirtree, 1);
|
||||
g_autoptr (GVariant) dir_subdirs = g_variant_get_child_value (dirtree, 1);
|
||||
const char *dname;
|
||||
GVariant *subdirtree_csum_v = NULL;
|
||||
GVariant *subdirmeta_csum_v = NULL;
|
||||
GVariantIter viter;
|
||||
g_variant_iter_init (&viter, dir_subdirs);
|
||||
while (g_variant_iter_loop (&viter, "(&s@ay@ay)", &dname,
|
||||
&subdirtree_csum_v, &subdirmeta_csum_v))
|
||||
while (
|
||||
g_variant_iter_loop (&viter, "(&s@ay@ay)", &dname, &subdirtree_csum_v, &subdirmeta_csum_v))
|
||||
{
|
||||
char subdirtree_checksum[OSTREE_SHA256_STRING_LEN+1];
|
||||
char subdirtree_checksum[OSTREE_SHA256_STRING_LEN + 1];
|
||||
_ostree_checksum_inplace_from_bytes_v (subdirtree_csum_v, subdirtree_checksum);
|
||||
char subdirmeta_checksum[OSTREE_SHA256_STRING_LEN+1];
|
||||
char subdirmeta_checksum[OSTREE_SHA256_STRING_LEN + 1];
|
||||
_ostree_checksum_inplace_from_bytes_v (subdirmeta_csum_v, subdirmeta_checksum);
|
||||
insert_child_mtree (self, dname, ostree_mutable_tree_new_from_checksum (
|
||||
self->repo, subdirtree_checksum, subdirmeta_checksum));
|
||||
insert_child_mtree (self, dname,
|
||||
ostree_mutable_tree_new_from_checksum (self->repo, subdirtree_checksum,
|
||||
subdirmeta_checksum));
|
||||
}
|
||||
}
|
||||
|
||||
@ -247,8 +244,7 @@ _assert_ostree_mutable_tree_make_whole (OstreeMutableTree *self)
|
||||
}
|
||||
|
||||
void
|
||||
ostree_mutable_tree_set_metadata_checksum (OstreeMutableTree *self,
|
||||
const char *checksum)
|
||||
ostree_mutable_tree_set_metadata_checksum (OstreeMutableTree *self, const char *checksum)
|
||||
{
|
||||
if (g_strcmp0 (checksum, self->metadata_checksum) == 0)
|
||||
return;
|
||||
@ -265,16 +261,15 @@ ostree_mutable_tree_get_metadata_checksum (OstreeMutableTree *self)
|
||||
}
|
||||
|
||||
void
|
||||
ostree_mutable_tree_set_contents_checksum (OstreeMutableTree *self,
|
||||
const char *checksum)
|
||||
ostree_mutable_tree_set_contents_checksum (OstreeMutableTree *self, const char *checksum)
|
||||
{
|
||||
if (g_strcmp0 (checksum, self->contents_checksum) == 0)
|
||||
return;
|
||||
|
||||
if (checksum && self->contents_checksum)
|
||||
g_warning ("Setting a contents checksum on an OstreeMutableTree that "
|
||||
"already has a checksum set. Old checksum %s, new checksum %s",
|
||||
self->contents_checksum, checksum);
|
||||
"already has a checksum set. Old checksum %s, new checksum %s",
|
||||
self->contents_checksum, checksum);
|
||||
|
||||
_assert_ostree_mutable_tree_make_whole (self);
|
||||
|
||||
@ -291,17 +286,13 @@ ostree_mutable_tree_get_contents_checksum (OstreeMutableTree *self)
|
||||
static gboolean
|
||||
set_error_noent (GError **error, const char *path)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
||||
"No such file or directory: %s",
|
||||
path);
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "No such file or directory: %s", path);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
ostree_mutable_tree_replace_file (OstreeMutableTree *self,
|
||||
const char *name,
|
||||
const char *checksum,
|
||||
GError **error)
|
||||
ostree_mutable_tree_replace_file (OstreeMutableTree *self, const char *name, const char *checksum,
|
||||
GError **error)
|
||||
{
|
||||
if (!ot_util_filename_validate (name, error))
|
||||
return FALSE;
|
||||
@ -313,9 +304,7 @@ ostree_mutable_tree_replace_file (OstreeMutableTree *self,
|
||||
return glnx_throw (error, "Can't replace directory with file: %s", name);
|
||||
|
||||
invalidate_contents_checksum (self);
|
||||
g_hash_table_replace (self->files,
|
||||
g_strdup (name),
|
||||
g_strdup (checksum));
|
||||
g_hash_table_replace (self->files, g_strdup (name), g_strdup (checksum));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -331,10 +320,8 @@ ostree_mutable_tree_replace_file (OstreeMutableTree *self,
|
||||
* Since: 2018.9
|
||||
*/
|
||||
gboolean
|
||||
ostree_mutable_tree_remove (OstreeMutableTree *self,
|
||||
const char *name,
|
||||
gboolean allow_noent,
|
||||
GError **error)
|
||||
ostree_mutable_tree_remove (OstreeMutableTree *self, const char *name, gboolean allow_noent,
|
||||
GError **error)
|
||||
{
|
||||
if (!ot_util_filename_validate (name, error))
|
||||
return FALSE;
|
||||
@ -342,8 +329,7 @@ ostree_mutable_tree_remove (OstreeMutableTree *self,
|
||||
if (!_ostree_mutable_tree_make_whole (self, NULL, error))
|
||||
return FALSE;
|
||||
|
||||
if (!g_hash_table_remove (self->files, name) &&
|
||||
!g_hash_table_remove (self->subdirs, name))
|
||||
if (!g_hash_table_remove (self->files, name) && !g_hash_table_remove (self->subdirs, name))
|
||||
{
|
||||
if (allow_noent)
|
||||
return TRUE; /* NB: early return */
|
||||
@ -365,10 +351,8 @@ ostree_mutable_tree_remove (OstreeMutableTree *self,
|
||||
* it if it doesn't exist.
|
||||
*/
|
||||
gboolean
|
||||
ostree_mutable_tree_ensure_dir (OstreeMutableTree *self,
|
||||
const char *name,
|
||||
OstreeMutableTree **out_subdir,
|
||||
GError **error)
|
||||
ostree_mutable_tree_ensure_dir (OstreeMutableTree *self, const char *name,
|
||||
OstreeMutableTree **out_subdir, GError **error)
|
||||
{
|
||||
if (!ot_util_filename_validate (name, error))
|
||||
return FALSE;
|
||||
@ -379,8 +363,8 @@ ostree_mutable_tree_ensure_dir (OstreeMutableTree *self,
|
||||
if (g_hash_table_lookup (self->files, name))
|
||||
return glnx_throw (error, "Can't replace file with directory: %s", name);
|
||||
|
||||
g_autoptr(OstreeMutableTree) ret_dir =
|
||||
ot_gobject_refz (g_hash_table_lookup (self->subdirs, name));
|
||||
g_autoptr (OstreeMutableTree) ret_dir
|
||||
= ot_gobject_refz (g_hash_table_lookup (self->subdirs, name));
|
||||
if (!ret_dir)
|
||||
{
|
||||
ret_dir = ostree_mutable_tree_new ();
|
||||
@ -408,18 +392,15 @@ ostree_mutable_tree_ensure_dir (OstreeMutableTree *self,
|
||||
* filled, %FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
ostree_mutable_tree_lookup (OstreeMutableTree *self,
|
||||
const char *name,
|
||||
char **out_file_checksum,
|
||||
OstreeMutableTree **out_subdir,
|
||||
GError **error)
|
||||
ostree_mutable_tree_lookup (OstreeMutableTree *self, const char *name, char **out_file_checksum,
|
||||
OstreeMutableTree **out_subdir, GError **error)
|
||||
{
|
||||
if (!_ostree_mutable_tree_make_whole (self, NULL, error))
|
||||
return FALSE;
|
||||
|
||||
g_autofree char *ret_file_checksum = NULL;
|
||||
g_autoptr(OstreeMutableTree) ret_subdir =
|
||||
ot_gobject_refz (g_hash_table_lookup (self->subdirs, name));
|
||||
g_autoptr (OstreeMutableTree) ret_subdir
|
||||
= ot_gobject_refz (g_hash_table_lookup (self->subdirs, name));
|
||||
if (!ret_subdir)
|
||||
{
|
||||
ret_file_checksum = g_strdup (g_hash_table_lookup (self->files, name));
|
||||
@ -446,11 +427,9 @@ ostree_mutable_tree_lookup (OstreeMutableTree *self,
|
||||
* exist.
|
||||
*/
|
||||
gboolean
|
||||
ostree_mutable_tree_ensure_parent_dirs (OstreeMutableTree *self,
|
||||
GPtrArray *split_path,
|
||||
const char *metadata_checksum,
|
||||
OstreeMutableTree **out_parent,
|
||||
GError **error)
|
||||
ostree_mutable_tree_ensure_parent_dirs (OstreeMutableTree *self, GPtrArray *split_path,
|
||||
const char *metadata_checksum,
|
||||
OstreeMutableTree **out_parent, GError **error)
|
||||
{
|
||||
g_assert (metadata_checksum != NULL);
|
||||
|
||||
@ -461,7 +440,7 @@ ostree_mutable_tree_ensure_parent_dirs (OstreeMutableTree *self,
|
||||
ostree_mutable_tree_set_metadata_checksum (self, metadata_checksum);
|
||||
|
||||
OstreeMutableTree *subdir = self; /* nofree */
|
||||
for (guint i = 0; i+1 < split_path->len; i++)
|
||||
for (guint i = 0; i + 1 < split_path->len; i++)
|
||||
{
|
||||
const char *name = split_path->pdata[i];
|
||||
if (g_hash_table_lookup (subdir->files, name))
|
||||
@ -507,10 +486,9 @@ const char empty_tree_csum[] = "6e340b9cffb37a989ca544e6bb780a2c78901d3fb3373876
|
||||
* Since: 2018.7
|
||||
*/
|
||||
gboolean
|
||||
ostree_mutable_tree_fill_empty_from_dirtree (OstreeMutableTree *self,
|
||||
OstreeRepo *repo,
|
||||
const char *contents_checksum,
|
||||
const char *metadata_checksum)
|
||||
ostree_mutable_tree_fill_empty_from_dirtree (OstreeMutableTree *self, OstreeRepo *repo,
|
||||
const char *contents_checksum,
|
||||
const char *metadata_checksum)
|
||||
{
|
||||
g_return_val_if_fail (repo, FALSE);
|
||||
g_return_val_if_fail (contents_checksum, FALSE);
|
||||
@ -520,8 +498,8 @@ ostree_mutable_tree_fill_empty_from_dirtree (OstreeMutableTree *self,
|
||||
{
|
||||
case MTREE_STATE_LAZY:
|
||||
{
|
||||
if (g_strcmp0 (contents_checksum, self->contents_checksum) == 0 ||
|
||||
g_strcmp0 (empty_tree_csum, self->contents_checksum) == 0)
|
||||
if (g_strcmp0 (contents_checksum, self->contents_checksum) == 0
|
||||
|| g_strcmp0 (empty_tree_csum, self->contents_checksum) == 0)
|
||||
break;
|
||||
|
||||
if (g_strcmp0 (empty_tree_csum, contents_checksum) == 0)
|
||||
@ -534,8 +512,7 @@ ostree_mutable_tree_fill_empty_from_dirtree (OstreeMutableTree *self,
|
||||
return FALSE;
|
||||
}
|
||||
case MTREE_STATE_WHOLE:
|
||||
if (g_hash_table_size (self->files) == 0 &&
|
||||
g_hash_table_size (self->subdirs) == 0)
|
||||
if (g_hash_table_size (self->files) == 0 && g_hash_table_size (self->subdirs) == 0)
|
||||
break;
|
||||
/* We're not empty - can't convert to a LAZY tree */
|
||||
return FALSE;
|
||||
@ -566,11 +543,8 @@ ostree_mutable_tree_fill_empty_from_dirtree (OstreeMutableTree *self,
|
||||
* child will be returned in @out_subdir.
|
||||
*/
|
||||
gboolean
|
||||
ostree_mutable_tree_walk (OstreeMutableTree *self,
|
||||
GPtrArray *split_path,
|
||||
guint start,
|
||||
OstreeMutableTree **out_subdir,
|
||||
GError **error)
|
||||
ostree_mutable_tree_walk (OstreeMutableTree *self, GPtrArray *split_path, guint start,
|
||||
OstreeMutableTree **out_subdir, GError **error)
|
||||
{
|
||||
g_return_val_if_fail (start < split_path->len, FALSE);
|
||||
|
||||
@ -585,7 +559,7 @@ ostree_mutable_tree_walk (OstreeMutableTree *self,
|
||||
return FALSE;
|
||||
OstreeMutableTree *subdir = g_hash_table_lookup (self->subdirs, split_path->pdata[start]);
|
||||
if (!subdir)
|
||||
return set_error_noent (error, (char*)split_path->pdata[start]);
|
||||
return set_error_noent (error, (char *)split_path->pdata[start]);
|
||||
|
||||
return ostree_mutable_tree_walk (subdir, split_path, start + 1, out_subdir, error);
|
||||
}
|
||||
@ -630,8 +604,7 @@ ostree_mutable_tree_get_files (OstreeMutableTree *self)
|
||||
* Returns: `TRUE` on success
|
||||
*/
|
||||
gboolean
|
||||
ostree_mutable_tree_check_error (OstreeMutableTree *self,
|
||||
GError **error)
|
||||
ostree_mutable_tree_check_error (OstreeMutableTree *self, GError **error)
|
||||
{
|
||||
if (self->cached_error)
|
||||
{
|
||||
@ -650,7 +623,7 @@ ostree_mutable_tree_check_error (OstreeMutableTree *self,
|
||||
OstreeMutableTree *
|
||||
ostree_mutable_tree_new (void)
|
||||
{
|
||||
return (OstreeMutableTree*)g_object_new (OSTREE_TYPE_MUTABLE_TREE, NULL);
|
||||
return (OstreeMutableTree *)g_object_new (OSTREE_TYPE_MUTABLE_TREE, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -667,11 +640,10 @@ ostree_mutable_tree_new (void)
|
||||
* Since: 2018.7
|
||||
*/
|
||||
OstreeMutableTree *
|
||||
ostree_mutable_tree_new_from_checksum (OstreeRepo *repo,
|
||||
const char *contents_checksum,
|
||||
ostree_mutable_tree_new_from_checksum (OstreeRepo *repo, const char *contents_checksum,
|
||||
const char *metadata_checksum)
|
||||
{
|
||||
OstreeMutableTree* out = (OstreeMutableTree*)g_object_new (OSTREE_TYPE_MUTABLE_TREE, NULL);
|
||||
OstreeMutableTree *out = (OstreeMutableTree *)g_object_new (OSTREE_TYPE_MUTABLE_TREE, NULL);
|
||||
out->state = MTREE_STATE_LAZY;
|
||||
out->repo = g_object_ref (repo);
|
||||
out->contents_checksum = g_strdup (contents_checksum);
|
||||
@ -691,26 +663,22 @@ ostree_mutable_tree_new_from_checksum (OstreeRepo *repo,
|
||||
* Since: 2021.5
|
||||
*/
|
||||
OstreeMutableTree *
|
||||
ostree_mutable_tree_new_from_commit (OstreeRepo *repo,
|
||||
const char *rev,
|
||||
GError **error)
|
||||
ostree_mutable_tree_new_from_commit (OstreeRepo *repo, const char *rev, GError **error)
|
||||
{
|
||||
g_autofree char *commit = NULL;
|
||||
if (!ostree_repo_resolve_rev (repo, rev, FALSE, &commit, error))
|
||||
return NULL;
|
||||
g_autoptr(GVariant) commit_v = NULL;
|
||||
g_autoptr (GVariant) commit_v = NULL;
|
||||
if (!ostree_repo_load_commit (repo, commit, &commit_v, NULL, error))
|
||||
return NULL;
|
||||
|
||||
g_autoptr(GVariant) contents_checksum_v = NULL;
|
||||
g_autoptr(GVariant) metadata_checksum_v = NULL;
|
||||
g_autoptr (GVariant) contents_checksum_v = NULL;
|
||||
g_autoptr (GVariant) metadata_checksum_v = NULL;
|
||||
char contents_checksum[OSTREE_SHA256_STRING_LEN + 1];
|
||||
char metadata_checksum[OSTREE_SHA256_STRING_LEN + 1];
|
||||
g_variant_get_child (commit_v, 6, "@ay", &contents_checksum_v);
|
||||
ostree_checksum_inplace_from_bytes (g_variant_get_data (contents_checksum_v),
|
||||
contents_checksum);
|
||||
ostree_checksum_inplace_from_bytes (g_variant_get_data (contents_checksum_v), contents_checksum);
|
||||
g_variant_get_child (commit_v, 7, "@ay", &metadata_checksum_v);
|
||||
ostree_checksum_inplace_from_bytes (g_variant_get_data (metadata_checksum_v),
|
||||
metadata_checksum);
|
||||
ostree_checksum_inplace_from_bytes (g_variant_get_data (metadata_checksum_v), metadata_checksum);
|
||||
return ostree_mutable_tree_new_from_checksum (repo, contents_checksum, metadata_checksum);
|
||||
}
|
||||
|
@ -25,18 +25,22 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_MUTABLE_TREE (ostree_mutable_tree_get_type ())
|
||||
#define OSTREE_MUTABLE_TREE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_MUTABLE_TREE, OstreeMutableTree))
|
||||
#define OSTREE_MUTABLE_TREE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), OSTREE_TYPE_MUTABLE_TREE, OstreeMutableTreeClass))
|
||||
#define OSTREE_IS_MUTABLE_TREE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_MUTABLE_TREE))
|
||||
#define OSTREE_IS_MUTABLE_TREE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_MUTABLE_TREE))
|
||||
#define OSTREE_MUTABLE_TREE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_MUTABLE_TREE, OstreeMutableTreeClass))
|
||||
#define OSTREE_TYPE_MUTABLE_TREE (ostree_mutable_tree_get_type ())
|
||||
#define OSTREE_MUTABLE_TREE(o) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_MUTABLE_TREE, OstreeMutableTree))
|
||||
#define OSTREE_MUTABLE_TREE_CLASS(k) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((k), OSTREE_TYPE_MUTABLE_TREE, OstreeMutableTreeClass))
|
||||
#define OSTREE_IS_MUTABLE_TREE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_MUTABLE_TREE))
|
||||
#define OSTREE_IS_MUTABLE_TREE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_MUTABLE_TREE))
|
||||
#define OSTREE_MUTABLE_TREE_GET_CLASS(o) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_MUTABLE_TREE, OstreeMutableTreeClass))
|
||||
|
||||
typedef struct OstreeMutableTreeClass OstreeMutableTreeClass;
|
||||
typedef struct OstreeMutableTreeClass OstreeMutableTreeClass;
|
||||
|
||||
typedef struct {
|
||||
gboolean in_files;
|
||||
GHashTableIter iter;
|
||||
typedef struct
|
||||
{
|
||||
gboolean in_files;
|
||||
GHashTableIter iter;
|
||||
} OstreeMutableTreeIter;
|
||||
|
||||
struct OstreeMutableTreeClass
|
||||
@ -45,90 +49,69 @@ struct OstreeMutableTreeClass
|
||||
};
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
GType ostree_mutable_tree_get_type (void) G_GNUC_CONST;
|
||||
GType ostree_mutable_tree_get_type (void) G_GNUC_CONST;
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeMutableTree *ostree_mutable_tree_new (void);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeMutableTree *
|
||||
ostree_mutable_tree_new_from_commit (OstreeRepo *repo,
|
||||
const char *rev,
|
||||
GError **error);
|
||||
OstreeMutableTree *ostree_mutable_tree_new_from_commit (OstreeRepo *repo, const char *rev,
|
||||
GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeMutableTree * ostree_mutable_tree_new_from_checksum (OstreeRepo *repo,
|
||||
const char *contents_checksum,
|
||||
const char *metadata_checksum);
|
||||
OstreeMutableTree *ostree_mutable_tree_new_from_checksum (OstreeRepo *repo,
|
||||
const char *contents_checksum,
|
||||
const char *metadata_checksum);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_mutable_tree_set_metadata_checksum (OstreeMutableTree *self,
|
||||
const char *checksum);
|
||||
void ostree_mutable_tree_set_metadata_checksum (OstreeMutableTree *self, const char *checksum);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
const char *ostree_mutable_tree_get_metadata_checksum (OstreeMutableTree *self);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_mutable_tree_set_contents_checksum (OstreeMutableTree *self,
|
||||
const char *checksum);
|
||||
void ostree_mutable_tree_set_contents_checksum (OstreeMutableTree *self, const char *checksum);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
const char *ostree_mutable_tree_get_contents_checksum (OstreeMutableTree *self);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_mutable_tree_replace_file (OstreeMutableTree *self,
|
||||
const char *name,
|
||||
const char *checksum,
|
||||
GError **error);
|
||||
gboolean ostree_mutable_tree_replace_file (OstreeMutableTree *self, const char *name,
|
||||
const char *checksum, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_mutable_tree_remove (OstreeMutableTree *self,
|
||||
const char *name,
|
||||
gboolean allow_noent,
|
||||
GError **error);
|
||||
gboolean ostree_mutable_tree_remove (OstreeMutableTree *self, const char *name,
|
||||
gboolean allow_noent, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_mutable_tree_ensure_dir (OstreeMutableTree *self,
|
||||
const char *name,
|
||||
OstreeMutableTree **out_subdir,
|
||||
GError **error);
|
||||
gboolean ostree_mutable_tree_ensure_dir (OstreeMutableTree *self, const char *name,
|
||||
OstreeMutableTree **out_subdir, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_mutable_tree_lookup (OstreeMutableTree *self,
|
||||
const char *name,
|
||||
char **out_file_checksum,
|
||||
OstreeMutableTree **out_subdir,
|
||||
GError **error);
|
||||
gboolean ostree_mutable_tree_lookup (OstreeMutableTree *self, const char *name,
|
||||
char **out_file_checksum, OstreeMutableTree **out_subdir,
|
||||
GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean
|
||||
ostree_mutable_tree_ensure_parent_dirs (OstreeMutableTree *self,
|
||||
GPtrArray *split_path,
|
||||
const char *metadata_checksum,
|
||||
OstreeMutableTree **out_parent,
|
||||
GError **error);
|
||||
gboolean ostree_mutable_tree_ensure_parent_dirs (OstreeMutableTree *self, GPtrArray *split_path,
|
||||
const char *metadata_checksum,
|
||||
OstreeMutableTree **out_parent, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_mutable_tree_walk (OstreeMutableTree *self,
|
||||
GPtrArray *split_path,
|
||||
guint start,
|
||||
OstreeMutableTree **out_subdir,
|
||||
GError **error);
|
||||
gboolean ostree_mutable_tree_walk (OstreeMutableTree *self, GPtrArray *split_path, guint start,
|
||||
OstreeMutableTree **out_subdir, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_mutable_tree_fill_empty_from_dirtree (OstreeMutableTree *self,
|
||||
OstreeRepo *repo,
|
||||
const char *contents_checksum,
|
||||
const char *metadata_checksum);
|
||||
gboolean ostree_mutable_tree_fill_empty_from_dirtree (OstreeMutableTree *self, OstreeRepo *repo,
|
||||
const char *contents_checksum,
|
||||
const char *metadata_checksum);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean
|
||||
ostree_mutable_tree_check_error (OstreeMutableTree *self,
|
||||
GError **error);
|
||||
gboolean ostree_mutable_tree_check_error (OstreeMutableTree *self, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
GHashTable * ostree_mutable_tree_get_subdirs (OstreeMutableTree *self);
|
||||
GHashTable *ostree_mutable_tree_get_subdirs (OstreeMutableTree *self);
|
||||
_OSTREE_PUBLIC
|
||||
GHashTable * ostree_mutable_tree_get_files (OstreeMutableTree *self);
|
||||
GHashTable *ostree_mutable_tree_get_files (OstreeMutableTree *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -23,17 +23,17 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
#include <libglnx.h>
|
||||
|
||||
#include "ostree-autocleanups.h"
|
||||
#include "ostree-core.h"
|
||||
#include "ostree-core-private.h"
|
||||
#include "ostree-core.h"
|
||||
#include "ostree-ref.h"
|
||||
|
||||
G_DEFINE_BOXED_TYPE (OstreeCollectionRef, ostree_collection_ref,
|
||||
ostree_collection_ref_dup, ostree_collection_ref_free)
|
||||
G_DEFINE_BOXED_TYPE (OstreeCollectionRef, ostree_collection_ref, ostree_collection_ref_dup,
|
||||
ostree_collection_ref_free)
|
||||
|
||||
/**
|
||||
* ostree_collection_ref_new:
|
||||
@ -49,13 +49,12 @@ G_DEFINE_BOXED_TYPE (OstreeCollectionRef, ostree_collection_ref,
|
||||
* Since: 2018.6
|
||||
*/
|
||||
OstreeCollectionRef *
|
||||
ostree_collection_ref_new (const gchar *collection_id,
|
||||
const gchar *ref_name)
|
||||
ostree_collection_ref_new (const gchar *collection_id, const gchar *ref_name)
|
||||
{
|
||||
g_autoptr(OstreeCollectionRef) collection_ref = NULL;
|
||||
g_autoptr (OstreeCollectionRef) collection_ref = NULL;
|
||||
|
||||
g_return_val_if_fail (collection_id == NULL ||
|
||||
ostree_validate_collection_id (collection_id, NULL), NULL);
|
||||
g_return_val_if_fail (
|
||||
collection_id == NULL || ostree_validate_collection_id (collection_id, NULL), NULL);
|
||||
g_return_val_if_fail (ostree_validate_rev (ref_name, NULL), NULL);
|
||||
|
||||
collection_ref = g_new0 (OstreeCollectionRef, 1);
|
||||
@ -133,13 +132,12 @@ ostree_collection_ref_hash (gconstpointer ref)
|
||||
* Since: 2018.6
|
||||
*/
|
||||
gboolean
|
||||
ostree_collection_ref_equal (gconstpointer ref1,
|
||||
gconstpointer ref2)
|
||||
ostree_collection_ref_equal (gconstpointer ref1, gconstpointer ref2)
|
||||
{
|
||||
const OstreeCollectionRef *_ref1 = ref1, *_ref2 = ref2;
|
||||
|
||||
return (g_strcmp0 (_ref1->collection_id, _ref2->collection_id) == 0 &&
|
||||
g_strcmp0 (_ref1->ref_name, _ref2->ref_name) == 0);
|
||||
return (g_strcmp0 (_ref1->collection_id, _ref2->collection_id) == 0
|
||||
&& g_strcmp0 (_ref1->ref_name, _ref2->ref_name) == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,14 +152,14 @@ ostree_collection_ref_equal (gconstpointer ref1,
|
||||
* Since: 2018.6
|
||||
*/
|
||||
OstreeCollectionRef **
|
||||
ostree_collection_ref_dupv (const OstreeCollectionRef * const *refs)
|
||||
ostree_collection_ref_dupv (const OstreeCollectionRef *const *refs)
|
||||
{
|
||||
gsize i, n_refs = g_strv_length ((gchar **) refs); /* hack */
|
||||
g_auto(OstreeCollectionRefv) new_refs = NULL;
|
||||
gsize i, n_refs = g_strv_length ((gchar **)refs); /* hack */
|
||||
g_auto (OstreeCollectionRefv) new_refs = NULL;
|
||||
|
||||
g_return_val_if_fail (refs != NULL, NULL);
|
||||
|
||||
new_refs = g_new0 (OstreeCollectionRef*, n_refs + 1);
|
||||
new_refs = g_new0 (OstreeCollectionRef *, n_refs + 1);
|
||||
|
||||
for (i = 0; i < n_refs; i++)
|
||||
new_refs[i] = ostree_collection_ref_dup (refs[i]);
|
||||
|
@ -23,8 +23,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "ostree-types.h"
|
||||
|
||||
@ -44,16 +44,15 @@ G_BEGIN_DECLS
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
gchar *collection_id; /* (nullable) */
|
||||
gchar *ref_name; /* (not nullable) */
|
||||
gchar *collection_id; /* (nullable) */
|
||||
gchar *ref_name; /* (not nullable) */
|
||||
} OstreeCollectionRef;
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
GType ostree_collection_ref_get_type (void);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeCollectionRef *ostree_collection_ref_new (const gchar *collection_id,
|
||||
const gchar *ref_name);
|
||||
OstreeCollectionRef *ostree_collection_ref_new (const gchar *collection_id, const gchar *ref_name);
|
||||
_OSTREE_PUBLIC
|
||||
OstreeCollectionRef *ostree_collection_ref_dup (const OstreeCollectionRef *ref);
|
||||
_OSTREE_PUBLIC
|
||||
@ -62,11 +61,10 @@ void ostree_collection_ref_free (OstreeCollectionRef *ref);
|
||||
_OSTREE_PUBLIC
|
||||
guint ostree_collection_ref_hash (gconstpointer ref);
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_collection_ref_equal (gconstpointer ref1,
|
||||
gconstpointer ref2);
|
||||
gboolean ostree_collection_ref_equal (gconstpointer ref1, gconstpointer ref2);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeCollectionRef **ostree_collection_ref_dupv (const OstreeCollectionRef * const *refs);
|
||||
OstreeCollectionRef **ostree_collection_ref_dupv (const OstreeCollectionRef *const *refs);
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_collection_ref_freev (OstreeCollectionRef **refs);
|
||||
|
||||
@ -82,6 +80,6 @@ void ostree_collection_ref_freev (OstreeCollectionRef **refs);
|
||||
*
|
||||
* Since: 2018.6
|
||||
*/
|
||||
typedef OstreeCollectionRef** OstreeCollectionRefv;
|
||||
typedef OstreeCollectionRef **OstreeCollectionRefv;
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -26,8 +26,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "libglnx.h"
|
||||
#include "ostree-remote.h"
|
||||
@ -38,24 +38,23 @@ G_BEGIN_DECLS
|
||||
/* @refspec_name is set if this is a dynamic remote. It’s the name of the static
|
||||
* remote which this one inherits from, and is what should be used in refspecs
|
||||
* for pulls from this remote. If it’s %NULL, @name should be used instead. */
|
||||
struct OstreeRemote {
|
||||
int ref_count; /* atomic */
|
||||
char *name; /* (not nullable) */
|
||||
char *refspec_name; /* (nullable) */
|
||||
char *group; /* group name in options (not nullable) */
|
||||
char *keyring; /* keyring name ($refspec_name.trustedkeys.gpg) (not nullable) */
|
||||
GFile *file; /* NULL if remote defined in repo/config */
|
||||
struct OstreeRemote
|
||||
{
|
||||
int ref_count; /* atomic */
|
||||
char *name; /* (not nullable) */
|
||||
char *refspec_name; /* (nullable) */
|
||||
char *group; /* group name in options (not nullable) */
|
||||
char *keyring; /* keyring name ($refspec_name.trustedkeys.gpg) (not nullable) */
|
||||
GFile *file; /* NULL if remote defined in repo/config */
|
||||
GKeyFile *options;
|
||||
};
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
OstreeRemote *ostree_remote_new (const gchar *name);
|
||||
G_GNUC_INTERNAL
|
||||
OstreeRemote *ostree_remote_new_dynamic (const gchar *name,
|
||||
const gchar *refspec_name);
|
||||
OstreeRemote *ostree_remote_new_dynamic (const gchar *name, const gchar *refspec_name);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
OstreeRemote *ostree_remote_new_from_keyfile (GKeyFile *keyfile,
|
||||
const gchar *group);
|
||||
OstreeRemote *ostree_remote_new_from_keyfile (GKeyFile *keyfile, const gchar *group);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -26,13 +26,13 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ostree-remote.h"
|
||||
#include "ostree-remote-private.h"
|
||||
#include "ostree-remote.h"
|
||||
#include "ot-keyfile-utils.h"
|
||||
|
||||
/**
|
||||
@ -58,8 +58,7 @@ ostree_remote_new (const gchar *name)
|
||||
}
|
||||
|
||||
OstreeRemote *
|
||||
ostree_remote_new_dynamic (const gchar *name,
|
||||
const gchar *refspec_name)
|
||||
ostree_remote_new_dynamic (const gchar *name, const gchar *refspec_name)
|
||||
{
|
||||
OstreeRemote *remote;
|
||||
|
||||
@ -71,17 +70,17 @@ ostree_remote_new_dynamic (const gchar *name,
|
||||
remote->name = g_strdup (name);
|
||||
remote->refspec_name = g_strdup (refspec_name);
|
||||
remote->group = g_strdup_printf ("remote \"%s\"", (refspec_name != NULL) ? refspec_name : name);
|
||||
remote->keyring = g_strdup_printf ("%s.trustedkeys.gpg", (refspec_name != NULL) ? refspec_name : name);
|
||||
remote->keyring
|
||||
= g_strdup_printf ("%s.trustedkeys.gpg", (refspec_name != NULL) ? refspec_name : name);
|
||||
remote->options = g_key_file_new ();
|
||||
|
||||
return remote;
|
||||
}
|
||||
|
||||
OstreeRemote *
|
||||
ostree_remote_new_from_keyfile (GKeyFile *keyfile,
|
||||
const gchar *group)
|
||||
ostree_remote_new_from_keyfile (GKeyFile *keyfile, const gchar *group)
|
||||
{
|
||||
g_autoptr(GMatchInfo) match = NULL;
|
||||
g_autoptr (GMatchInfo) match = NULL;
|
||||
OstreeRemote *remote;
|
||||
g_autofree gchar *name = NULL;
|
||||
|
||||
@ -156,9 +155,7 @@ ostree_remote_unref (OstreeRemote *remote)
|
||||
}
|
||||
}
|
||||
|
||||
G_DEFINE_BOXED_TYPE(OstreeRemote, ostree_remote,
|
||||
ostree_remote_ref,
|
||||
ostree_remote_unref);
|
||||
G_DEFINE_BOXED_TYPE (OstreeRemote, ostree_remote, ostree_remote_ref, ostree_remote_unref);
|
||||
|
||||
/**
|
||||
* ostree_remote_get_name:
|
||||
|
@ -26,8 +26,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "ostree-types.h"
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -24,7 +24,7 @@
|
||||
|
||||
#ifndef __GI_SCANNER__
|
||||
#ifndef G_GNUC_DEPRECATED_FOR
|
||||
# define G_GNUC_DEPRECATED_FOR(x)
|
||||
#define G_GNUC_DEPRECATED_FOR(x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -39,7 +39,8 @@ G_BEGIN_DECLS
|
||||
* supercedes previous separate enumeration usage in
|
||||
* ostree_repo_checkout_tree().
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
OstreeRepoCheckoutMode mode;
|
||||
OstreeRepoCheckoutOverwriteMode overwrite_mode;
|
||||
|
||||
@ -58,13 +59,10 @@ typedef struct {
|
||||
} OstreeRepoCheckoutOptions;
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_repo_checkout_tree_at (OstreeRepo *self,
|
||||
OstreeRepoCheckoutOptions *options,
|
||||
int destination_dfd,
|
||||
const char *destination_path,
|
||||
const char *commit,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
G_GNUC_DEPRECATED_FOR(ostree_repo_checkout_at);
|
||||
gboolean ostree_repo_checkout_tree_at (OstreeRepo *self, OstreeRepoCheckoutOptions *options,
|
||||
int destination_dfd, const char *destination_path,
|
||||
const char *commit, GCancellable *cancellable,
|
||||
GError **error)
|
||||
G_GNUC_DEPRECATED_FOR (ostree_repo_checkout_at);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -38,13 +38,10 @@ struct _OstreeRepoFileEnumerator
|
||||
#define ostree_repo_file_enumerator_get_type _ostree_repo_file_enumerator_get_type
|
||||
G_DEFINE_TYPE (OstreeRepoFileEnumerator, ostree_repo_file_enumerator, G_TYPE_FILE_ENUMERATOR);
|
||||
|
||||
static GFileInfo *ostree_repo_file_enumerator_next_file (GFileEnumerator *enumerator,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
static gboolean ostree_repo_file_enumerator_close (GFileEnumerator *enumerator,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
static GFileInfo *ostree_repo_file_enumerator_next_file (GFileEnumerator *enumerator,
|
||||
GCancellable *cancellable, GError **error);
|
||||
static gboolean ostree_repo_file_enumerator_close (GFileEnumerator *enumerator,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
static void
|
||||
ostree_repo_file_enumerator_dispose (GObject *object)
|
||||
@ -71,7 +68,6 @@ ostree_repo_file_enumerator_finalize (GObject *object)
|
||||
G_OBJECT_CLASS (ostree_repo_file_enumerator_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
ostree_repo_file_enumerator_class_init (OstreeRepoFileEnumeratorClass *klass)
|
||||
{
|
||||
@ -91,17 +87,13 @@ ostree_repo_file_enumerator_init (OstreeRepoFileEnumerator *self)
|
||||
}
|
||||
|
||||
GFileEnumerator *
|
||||
_ostree_repo_file_enumerator_new (OstreeRepoFile *dir,
|
||||
const char *attributes,
|
||||
GFileQueryInfoFlags flags,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
_ostree_repo_file_enumerator_new (OstreeRepoFile *dir, const char *attributes,
|
||||
GFileQueryInfoFlags flags, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
OstreeRepoFileEnumerator *self;
|
||||
|
||||
self = g_object_new (OSTREE_TYPE_REPO_FILE_ENUMERATOR,
|
||||
"container", dir,
|
||||
NULL);
|
||||
self = g_object_new (OSTREE_TYPE_REPO_FILE_ENUMERATOR, "container", dir, NULL);
|
||||
|
||||
self->dir = g_object_ref (dir);
|
||||
self->attributes = g_strdup (attributes);
|
||||
@ -111,32 +103,29 @@ _ostree_repo_file_enumerator_new (OstreeRepoFile *dir,
|
||||
}
|
||||
|
||||
static GFileInfo *
|
||||
ostree_repo_file_enumerator_next_file (GFileEnumerator *enumerator,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_repo_file_enumerator_next_file (GFileEnumerator *enumerator, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
OstreeRepoFileEnumerator *self = OSTREE_REPO_FILE_ENUMERATOR (enumerator);
|
||||
gboolean ret = FALSE;
|
||||
GFileInfo *info = NULL;
|
||||
|
||||
if (!ostree_repo_file_tree_query_child (self->dir, self->index,
|
||||
self->attributes, self->flags,
|
||||
if (!ostree_repo_file_tree_query_child (self->dir, self->index, self->attributes, self->flags,
|
||||
&info, cancellable, error))
|
||||
goto out;
|
||||
|
||||
self->index++;
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
out:
|
||||
if (!ret)
|
||||
g_clear_object (&info);
|
||||
return info;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ostree_repo_file_enumerator_close (GFileEnumerator *enumerator,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_repo_file_enumerator_close (GFileEnumerator *enumerator, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -25,15 +25,20 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_REPO_FILE_ENUMERATOR (_ostree_repo_file_enumerator_get_type ())
|
||||
#define OSTREE_REPO_FILE_ENUMERATOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_REPO_FILE_ENUMERATOR, OstreeRepoFileEnumerator))
|
||||
#define OSTREE_REPO_FILE_ENUMERATOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), OSTREE_TYPE_REPO_FILE_ENUMERATOR, OstreeRepoFileEnumeratorClass))
|
||||
#define OSTREE_IS_REPO_FILE_ENUMERATOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_REPO_FILE_ENUMERATOR))
|
||||
#define OSTREE_IS_REPO_FILE_ENUMERATOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_REPO_FILE_ENUMERATOR))
|
||||
#define OSTREE_REPO_FILE_ENUMERATOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_REPO_FILE_ENUMERATOR, OstreeRepoFileEnumeratorClass))
|
||||
#define OSTREE_TYPE_REPO_FILE_ENUMERATOR (_ostree_repo_file_enumerator_get_type ())
|
||||
#define OSTREE_REPO_FILE_ENUMERATOR(o) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_REPO_FILE_ENUMERATOR, OstreeRepoFileEnumerator))
|
||||
#define OSTREE_REPO_FILE_ENUMERATOR_CLASS(k) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((k), OSTREE_TYPE_REPO_FILE_ENUMERATOR, OstreeRepoFileEnumeratorClass))
|
||||
#define OSTREE_IS_REPO_FILE_ENUMERATOR(o) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_REPO_FILE_ENUMERATOR))
|
||||
#define OSTREE_IS_REPO_FILE_ENUMERATOR_CLASS(k) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_REPO_FILE_ENUMERATOR))
|
||||
#define OSTREE_REPO_FILE_ENUMERATOR_GET_CLASS(o) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_REPO_FILE_ENUMERATOR, OstreeRepoFileEnumeratorClass))
|
||||
|
||||
typedef struct _OstreeRepoFileEnumerator OstreeRepoFileEnumerator;
|
||||
typedef struct _OstreeRepoFileEnumeratorClass OstreeRepoFileEnumeratorClass;
|
||||
typedef struct _OstreeRepoFileEnumerator OstreeRepoFileEnumerator;
|
||||
typedef struct _OstreeRepoFileEnumeratorClass OstreeRepoFileEnumeratorClass;
|
||||
|
||||
struct _OstreeRepoFileEnumeratorClass
|
||||
{
|
||||
@ -41,13 +46,11 @@ struct _OstreeRepoFileEnumeratorClass
|
||||
};
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
GType _ostree_repo_file_enumerator_get_type (void) G_GNUC_CONST;
|
||||
GType _ostree_repo_file_enumerator_get_type (void) G_GNUC_CONST;
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
GFileEnumerator * _ostree_repo_file_enumerator_new (OstreeRepoFile *dir,
|
||||
const char *attributes,
|
||||
GFileQueryInfoFlags flags,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
GFileEnumerator *_ostree_repo_file_enumerator_new (OstreeRepoFile *dir, const char *attributes,
|
||||
GFileQueryInfoFlags flags,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -22,9 +22,9 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "otutil.h"
|
||||
#include "ostree-repo-file-enumerator.h"
|
||||
#include "ostree-repo-private.h"
|
||||
#include "otutil.h"
|
||||
|
||||
static void ostree_repo_file_file_iface_init (GFileIface *iface);
|
||||
|
||||
@ -46,8 +46,7 @@ struct OstreeRepoFile
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (OstreeRepoFile, ostree_repo_file, G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_FILE,
|
||||
ostree_repo_file_file_iface_init))
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_FILE, ostree_repo_file_file_iface_init))
|
||||
|
||||
static void
|
||||
ostree_repo_file_finalize (GObject *object)
|
||||
@ -98,15 +97,13 @@ ostree_repo_file_init (OstreeRepoFile *self)
|
||||
static gboolean
|
||||
set_error_noent (GFile *self, GError **error)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
||||
"No such file or directory: %s",
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "No such file or directory: %s",
|
||||
gs_file_get_path_cached (self));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
OstreeRepoFile *
|
||||
_ostree_repo_file_new_root (OstreeRepo *repo,
|
||||
const char *contents_checksum,
|
||||
_ostree_repo_file_new_root (OstreeRepo *repo, const char *contents_checksum,
|
||||
const char *metadata_checksum)
|
||||
{
|
||||
OstreeRepoFile *self;
|
||||
@ -126,8 +123,7 @@ _ostree_repo_file_new_root (OstreeRepo *repo,
|
||||
}
|
||||
|
||||
static OstreeRepoFile *
|
||||
ostree_repo_file_new_child (OstreeRepoFile *parent,
|
||||
const char *name)
|
||||
ostree_repo_file_new_child (OstreeRepoFile *parent, const char *name)
|
||||
{
|
||||
OstreeRepoFile *self;
|
||||
size_t len;
|
||||
@ -136,21 +132,19 @@ ostree_repo_file_new_child (OstreeRepoFile *parent,
|
||||
self->repo = g_object_ref (parent->repo);
|
||||
self->parent = g_object_ref (parent);
|
||||
self->name = g_strdup (name);
|
||||
len = strlen(self->name);
|
||||
if (self->name[len-1] == '/')
|
||||
self->name[len-1] = '\0';
|
||||
len = strlen (self->name);
|
||||
if (self->name[len - 1] == '/')
|
||||
self->name[len - 1] = '\0';
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
OstreeRepoFile *
|
||||
_ostree_repo_file_new_for_commit (OstreeRepo *repo,
|
||||
const char *commit,
|
||||
GError **error)
|
||||
_ostree_repo_file_new_for_commit (OstreeRepo *repo, const char *commit, GError **error)
|
||||
{
|
||||
g_autoptr(GVariant) commit_v = NULL;
|
||||
g_autoptr(GVariant) tree_contents_csum_v = NULL;
|
||||
g_autoptr(GVariant) tree_metadata_csum_v = NULL;
|
||||
g_autoptr (GVariant) commit_v = NULL;
|
||||
g_autoptr (GVariant) tree_contents_csum_v = NULL;
|
||||
g_autoptr (GVariant) tree_metadata_csum_v = NULL;
|
||||
char tree_contents_csum[OSTREE_SHA256_STRING_LEN + 1];
|
||||
char tree_metadata_csum[OSTREE_SHA256_STRING_LEN + 1];
|
||||
|
||||
@ -158,8 +152,7 @@ _ostree_repo_file_new_for_commit (OstreeRepo *repo,
|
||||
g_return_val_if_fail (commit != NULL, NULL);
|
||||
g_return_val_if_fail (strlen (commit) == OSTREE_SHA256_STRING_LEN, NULL);
|
||||
|
||||
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT,
|
||||
commit, &commit_v, error))
|
||||
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, commit, &commit_v, error))
|
||||
return NULL;
|
||||
|
||||
/* PARSE OSTREE_OBJECT_TYPE_COMMIT */
|
||||
@ -175,11 +168,10 @@ _ostree_repo_file_new_for_commit (OstreeRepo *repo,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
do_resolve (OstreeRepoFile *self,
|
||||
GError **error)
|
||||
do_resolve (OstreeRepoFile *self, GError **error)
|
||||
{
|
||||
g_autoptr(GVariant) root_contents = NULL;
|
||||
g_autoptr(GVariant) root_metadata = NULL;
|
||||
g_autoptr (GVariant) root_contents = NULL;
|
||||
g_autoptr (GVariant) root_metadata = NULL;
|
||||
|
||||
g_assert (self->parent == NULL);
|
||||
|
||||
@ -200,16 +192,15 @@ do_resolve (OstreeRepoFile *self,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
do_resolve_nonroot (OstreeRepoFile *self,
|
||||
GError **error)
|
||||
do_resolve_nonroot (OstreeRepoFile *self, GError **error)
|
||||
{
|
||||
gboolean is_dir;
|
||||
int i;
|
||||
g_autoptr(GVariant) container = NULL;
|
||||
g_autoptr(GVariant) tree_contents = NULL;
|
||||
g_autoptr(GVariant) tree_metadata = NULL;
|
||||
g_autoptr(GVariant) contents_csum_v = NULL;
|
||||
g_autoptr(GVariant) metadata_csum_v = NULL;
|
||||
g_autoptr (GVariant) container = NULL;
|
||||
g_autoptr (GVariant) tree_contents = NULL;
|
||||
g_autoptr (GVariant) tree_metadata = NULL;
|
||||
g_autoptr (GVariant) contents_csum_v = NULL;
|
||||
g_autoptr (GVariant) metadata_csum_v = NULL;
|
||||
g_autofree char *tmp_checksum = NULL;
|
||||
|
||||
if (!ostree_repo_file_ensure_resolved (self->parent, error))
|
||||
@ -217,8 +208,7 @@ do_resolve_nonroot (OstreeRepoFile *self,
|
||||
|
||||
if (!self->parent->tree_contents)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY,
|
||||
"Not a directory");
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY, "Not a directory");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -226,7 +216,7 @@ do_resolve_nonroot (OstreeRepoFile *self,
|
||||
|
||||
if (i < 0)
|
||||
{
|
||||
set_error_noent ((GFile*)self, error);
|
||||
set_error_noent ((GFile *)self, error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -239,21 +229,18 @@ do_resolve_nonroot (OstreeRepoFile *self,
|
||||
self->index = g_variant_n_children (files_variant) + i;
|
||||
g_clear_pointer (&files_variant, g_variant_unref);
|
||||
|
||||
g_variant_get_child (container, i, "(&s@ay@ay)",
|
||||
&name, &contents_csum_v, &metadata_csum_v);
|
||||
g_variant_get_child (container, i, "(&s@ay@ay)", &name, &contents_csum_v, &metadata_csum_v);
|
||||
|
||||
g_free (tmp_checksum);
|
||||
tmp_checksum = ostree_checksum_from_bytes_v (contents_csum_v);
|
||||
if (!ostree_repo_load_variant (self->repo, OSTREE_OBJECT_TYPE_DIR_TREE,
|
||||
tmp_checksum, &tree_contents,
|
||||
error))
|
||||
if (!ostree_repo_load_variant (self->repo, OSTREE_OBJECT_TYPE_DIR_TREE, tmp_checksum,
|
||||
&tree_contents, error))
|
||||
return FALSE;
|
||||
|
||||
g_free (tmp_checksum);
|
||||
tmp_checksum = ostree_checksum_from_bytes_v (metadata_csum_v);
|
||||
if (!ostree_repo_load_variant (self->repo, OSTREE_OBJECT_TYPE_DIR_META,
|
||||
tmp_checksum, &tree_metadata,
|
||||
error))
|
||||
if (!ostree_repo_load_variant (self->repo, OSTREE_OBJECT_TYPE_DIR_META, tmp_checksum,
|
||||
&tree_metadata, error))
|
||||
return FALSE;
|
||||
|
||||
self->tree_contents = tree_contents;
|
||||
@ -279,8 +266,7 @@ do_resolve_nonroot (OstreeRepoFile *self,
|
||||
* Returns: %FALSE if the operation failed, %TRUE otherwise
|
||||
*/
|
||||
gboolean
|
||||
ostree_repo_file_ensure_resolved (OstreeRepoFile *self,
|
||||
GError **error)
|
||||
ostree_repo_file_ensure_resolved (OstreeRepoFile *self, GError **error)
|
||||
{
|
||||
if (self->parent == NULL)
|
||||
{
|
||||
@ -308,25 +294,23 @@ ostree_repo_file_ensure_resolved (OstreeRepoFile *self,
|
||||
* @error: Error
|
||||
*/
|
||||
gboolean
|
||||
ostree_repo_file_get_xattrs (OstreeRepoFile *self,
|
||||
GVariant **out_xattrs,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_repo_file_get_xattrs (OstreeRepoFile *self, GVariant **out_xattrs, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
if (!ostree_repo_file_ensure_resolved (self, error))
|
||||
return FALSE;
|
||||
|
||||
g_autoptr(GVariant) ret_xattrs = NULL;
|
||||
g_autoptr (GVariant) ret_xattrs = NULL;
|
||||
if (self->tree_metadata)
|
||||
ret_xattrs = g_variant_get_child_value (self->tree_metadata, 3);
|
||||
else
|
||||
{
|
||||
if (!ostree_repo_load_file (self->repo, ostree_repo_file_get_checksum (self),
|
||||
NULL, NULL, &ret_xattrs, cancellable, error))
|
||||
if (!ostree_repo_load_file (self->repo, ostree_repo_file_get_checksum (self), NULL, NULL,
|
||||
&ret_xattrs, cancellable, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ot_transfer_out_value(out_xattrs, &ret_xattrs);
|
||||
ot_transfer_out_value (out_xattrs, &ret_xattrs);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -340,7 +324,7 @@ ostree_repo_file_get_xattrs (OstreeRepoFile *self,
|
||||
* Returns: (nullable): The GVariant representing the children of this directory.
|
||||
*/
|
||||
GVariant *
|
||||
ostree_repo_file_tree_get_contents (OstreeRepoFile *self)
|
||||
ostree_repo_file_tree_get_contents (OstreeRepoFile *self)
|
||||
{
|
||||
return self->tree_contents;
|
||||
}
|
||||
@ -355,7 +339,7 @@ ostree_repo_file_tree_get_contents (OstreeRepoFile *self)
|
||||
* Returns: (nullable): The GVariant representing the metadata for this directory.
|
||||
*/
|
||||
GVariant *
|
||||
ostree_repo_file_tree_get_metadata (OstreeRepoFile *self)
|
||||
ostree_repo_file_tree_get_metadata (OstreeRepoFile *self)
|
||||
{
|
||||
return self->tree_metadata;
|
||||
}
|
||||
@ -367,9 +351,7 @@ ostree_repo_file_tree_get_metadata (OstreeRepoFile *self)
|
||||
* Replace the metadata checksum and metadata object.
|
||||
*/
|
||||
void
|
||||
ostree_repo_file_tree_set_metadata (OstreeRepoFile *self,
|
||||
const char *checksum,
|
||||
GVariant *metadata)
|
||||
ostree_repo_file_tree_set_metadata (OstreeRepoFile *self, const char *checksum, GVariant *metadata)
|
||||
{
|
||||
g_clear_pointer (&self->tree_metadata, g_variant_unref);
|
||||
self->tree_metadata = g_variant_ref (metadata);
|
||||
@ -381,10 +363,11 @@ ostree_repo_file_tree_set_metadata (OstreeRepoFile *self,
|
||||
* ostree_repo_file_tree_get_contents_checksum:
|
||||
* @self: A repo file
|
||||
*
|
||||
* Returns: (nullable): The SHA256 digest of the content object, or %NULL if this is not a directory.
|
||||
* Returns: (nullable): The SHA256 digest of the content object, or %NULL if this is not a
|
||||
* directory.
|
||||
*/
|
||||
const char *
|
||||
ostree_repo_file_tree_get_contents_checksum (OstreeRepoFile *self)
|
||||
ostree_repo_file_tree_get_contents_checksum (OstreeRepoFile *self)
|
||||
{
|
||||
return self->tree_contents_checksum;
|
||||
}
|
||||
@ -393,10 +376,11 @@ ostree_repo_file_tree_get_contents_checksum (OstreeRepoFile *self)
|
||||
* ostree_repo_file_tree_get_metadata_checksum:
|
||||
* @self: A repo file
|
||||
*
|
||||
* Returns: (nullable): The SHA256 digest of the metadata object, or %NULL if this is not a directory.
|
||||
* Returns: (nullable): The SHA256 digest of the metadata object, or %NULL if this is not a
|
||||
* directory.
|
||||
*/
|
||||
const char *
|
||||
ostree_repo_file_tree_get_metadata_checksum (OstreeRepoFile *self)
|
||||
ostree_repo_file_tree_get_metadata_checksum (OstreeRepoFile *self)
|
||||
{
|
||||
return self->tree_metadata_checksum;
|
||||
}
|
||||
@ -408,7 +392,7 @@ ostree_repo_file_tree_get_metadata_checksum (OstreeRepoFile *self)
|
||||
* Returns: (transfer none): Repository
|
||||
*/
|
||||
OstreeRepo *
|
||||
ostree_repo_file_get_repo (OstreeRepoFile *self)
|
||||
ostree_repo_file_get_repo (OstreeRepoFile *self)
|
||||
{
|
||||
return self->repo;
|
||||
}
|
||||
@ -420,7 +404,7 @@ ostree_repo_file_get_repo (OstreeRepoFile *self)
|
||||
* Returns: (transfer none): The root directory for the commit referenced by this file
|
||||
*/
|
||||
OstreeRepoFile *
|
||||
ostree_repo_file_get_root (OstreeRepoFile *self)
|
||||
ostree_repo_file_get_root (OstreeRepoFile *self)
|
||||
{
|
||||
OstreeRepoFile *parent = self;
|
||||
|
||||
@ -433,10 +417,11 @@ ostree_repo_file_get_root (OstreeRepoFile *self)
|
||||
* ostree_repo_file_tree_get_checksum:
|
||||
* @self: A repo file
|
||||
*
|
||||
* Returns: For non-directories, the SHA-256 digest of the object. For directories, the metadata digest will be returned.
|
||||
* Returns: For non-directories, the SHA-256 digest of the object. For directories, the metadata
|
||||
* digest will be returned.
|
||||
*/
|
||||
const char *
|
||||
ostree_repo_file_get_checksum (OstreeRepoFile *self)
|
||||
ostree_repo_file_get_checksum (OstreeRepoFile *self)
|
||||
{
|
||||
int n;
|
||||
gboolean is_dir;
|
||||
@ -458,13 +443,11 @@ ostree_repo_file_get_checksum (OstreeRepoFile *self)
|
||||
|
||||
if (is_dir)
|
||||
{
|
||||
g_variant_get_child (dirs_variant, n,
|
||||
"(@s@ay@ay)", NULL, NULL, &csum_bytes);
|
||||
g_variant_get_child (dirs_variant, n, "(@s@ay@ay)", NULL, NULL, &csum_bytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_variant_get_child (files_variant, n,
|
||||
"(@s@ay)", NULL, &csum_bytes);
|
||||
g_variant_get_child (files_variant, n, "(@s@ay)", NULL, &csum_bytes);
|
||||
}
|
||||
g_clear_pointer (&files_variant, g_variant_unref);
|
||||
g_clear_pointer (&dirs_variant, g_variant_unref);
|
||||
@ -483,8 +466,7 @@ ostree_repo_file_is_native (GFile *file)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ostree_repo_file_has_uri_scheme (GFile *file,
|
||||
const char *uri_scheme)
|
||||
ostree_repo_file_has_uri_scheme (GFile *file, const char *uri_scheme)
|
||||
{
|
||||
return g_ascii_strcasecmp (uri_scheme, "ostree") == 0;
|
||||
}
|
||||
@ -547,10 +529,8 @@ ostree_repo_file_get_uri (GFile *file)
|
||||
path = gs_file_get_path_cached (file);
|
||||
uri_path = g_filename_to_uri (path, NULL, NULL);
|
||||
g_assert (g_str_has_prefix (uri_path, "file://"));
|
||||
ret = g_strconcat ("ostree://",
|
||||
root->tree_contents_checksum, "/", root->tree_metadata_checksum,
|
||||
uri_path+strlen("file://"),
|
||||
NULL);
|
||||
ret = g_strconcat ("ostree://", root->tree_contents_checksum, "/", root->tree_metadata_checksum,
|
||||
uri_path + strlen ("file://"), NULL);
|
||||
g_free (uri_path);
|
||||
|
||||
return ret;
|
||||
@ -567,7 +547,7 @@ ostree_repo_file_get_parent (GFile *file)
|
||||
{
|
||||
OstreeRepoFile *self = OSTREE_REPO_FILE (file);
|
||||
|
||||
return (GFile*)g_object_ref (self->parent);
|
||||
return (GFile *)g_object_ref (self->parent);
|
||||
}
|
||||
|
||||
static GFile *
|
||||
@ -578,7 +558,8 @@ ostree_repo_file_dup (GFile *file)
|
||||
if (self->parent)
|
||||
return G_FILE (ostree_repo_file_new_child (self->parent, self->name));
|
||||
else
|
||||
return G_FILE (_ostree_repo_file_new_root (self->repo, self->tree_contents_checksum, self->tree_metadata_checksum));
|
||||
return G_FILE (_ostree_repo_file_new_root (self->repo, self->tree_contents_checksum,
|
||||
self->tree_metadata_checksum));
|
||||
}
|
||||
|
||||
static guint
|
||||
@ -593,29 +574,27 @@ ostree_repo_file_hash (GFile *file)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ostree_repo_file_equal (GFile *file1,
|
||||
GFile *file2)
|
||||
ostree_repo_file_equal (GFile *file1, GFile *file2)
|
||||
{
|
||||
OstreeRepoFile *self1 = OSTREE_REPO_FILE (file1);
|
||||
OstreeRepoFile *self2 = OSTREE_REPO_FILE (file2);
|
||||
|
||||
if (self1->parent && self2->parent)
|
||||
{
|
||||
return (g_str_equal (self1->name, self2->name) &&
|
||||
g_file_equal ((GFile*)self1->parent, (GFile*)self2->parent));
|
||||
return (g_str_equal (self1->name, self2->name)
|
||||
&& g_file_equal ((GFile *)self1->parent, (GFile *)self2->parent));
|
||||
}
|
||||
else if (!self1->parent && !self2->parent)
|
||||
{
|
||||
return (g_str_equal (self1->tree_contents_checksum, self2->tree_contents_checksum) &&
|
||||
g_str_equal (self1->tree_metadata_checksum, self2->tree_metadata_checksum));
|
||||
return (g_str_equal (self1->tree_contents_checksum, self2->tree_contents_checksum)
|
||||
&& g_str_equal (self1->tree_metadata_checksum, self2->tree_metadata_checksum));
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static const char *
|
||||
match_prefix (const char *path,
|
||||
const char *prefix)
|
||||
match_prefix (const char *path, const char *prefix)
|
||||
{
|
||||
int prefix_len;
|
||||
|
||||
@ -625,16 +604,14 @@ match_prefix (const char *path,
|
||||
|
||||
/* Handle the case where prefix is the root, so that
|
||||
* the IS_DIR_SEPRARATOR check below works */
|
||||
if (prefix_len > 0 &&
|
||||
G_IS_DIR_SEPARATOR (prefix[prefix_len-1]))
|
||||
if (prefix_len > 0 && G_IS_DIR_SEPARATOR (prefix[prefix_len - 1]))
|
||||
prefix_len--;
|
||||
|
||||
return path + prefix_len;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ostree_repo_file_prefix_matches (GFile *parent,
|
||||
GFile *descendant)
|
||||
ostree_repo_file_prefix_matches (GFile *parent, GFile *descendant)
|
||||
{
|
||||
const char *remainder;
|
||||
const char *parent_path;
|
||||
@ -649,8 +626,7 @@ ostree_repo_file_prefix_matches (GFile *parent,
|
||||
}
|
||||
|
||||
static char *
|
||||
ostree_repo_file_get_relative_path (GFile *parent,
|
||||
GFile *descendant)
|
||||
ostree_repo_file_get_relative_path (GFile *parent, GFile *descendant)
|
||||
{
|
||||
const char *remainder;
|
||||
const char *parent_path;
|
||||
@ -666,8 +642,7 @@ ostree_repo_file_get_relative_path (GFile *parent,
|
||||
}
|
||||
|
||||
static GFile *
|
||||
ostree_repo_file_resolve_relative_path (GFile *file,
|
||||
const char *relative_path)
|
||||
ostree_repo_file_resolve_relative_path (GFile *file, const char *relative_path)
|
||||
{
|
||||
OstreeRepoFile *self = OSTREE_REPO_FILE (file);
|
||||
OstreeRepoFile *parent;
|
||||
@ -680,13 +655,13 @@ ostree_repo_file_resolve_relative_path (GFile *file,
|
||||
g_assert (*relative_path == '/');
|
||||
|
||||
if (strcmp (relative_path, "/") == 0)
|
||||
return (GFile*)g_object_ref (ostree_repo_file_get_root (self));
|
||||
return (GFile *)g_object_ref (ostree_repo_file_get_root (self));
|
||||
|
||||
if (self->parent)
|
||||
return ostree_repo_file_resolve_relative_path ((GFile*)ostree_repo_file_get_root (self),
|
||||
relative_path+1);
|
||||
return ostree_repo_file_resolve_relative_path ((GFile *)ostree_repo_file_get_root (self),
|
||||
relative_path + 1);
|
||||
else
|
||||
relative_path = relative_path+1;
|
||||
relative_path = relative_path + 1;
|
||||
}
|
||||
|
||||
rest = strchr (relative_path, '/');
|
||||
@ -702,47 +677,38 @@ ostree_repo_file_resolve_relative_path (GFile *file,
|
||||
g_free (filename);
|
||||
|
||||
if (!rest)
|
||||
ret = (GFile*)parent;
|
||||
ret = (GFile *)parent;
|
||||
else
|
||||
{
|
||||
ret = ostree_repo_file_resolve_relative_path ((GFile*)parent, rest);
|
||||
ret = ostree_repo_file_resolve_relative_path ((GFile *)parent, rest);
|
||||
g_clear_object (&parent);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static GFileEnumerator *
|
||||
ostree_repo_file_enumerate_children (GFile *file,
|
||||
const char *attributes,
|
||||
GFileQueryInfoFlags flags,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_repo_file_enumerate_children (GFile *file, const char *attributes, GFileQueryInfoFlags flags,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
OstreeRepoFile *self = OSTREE_REPO_FILE (file);
|
||||
return _ostree_repo_file_enumerator_new (self,
|
||||
attributes, flags,
|
||||
cancellable, error);
|
||||
return _ostree_repo_file_enumerator_new (self, attributes, flags, cancellable, error);
|
||||
}
|
||||
|
||||
static GFile *
|
||||
ostree_repo_file_get_child_for_display_name (GFile *file,
|
||||
const char *display_name,
|
||||
GError **error)
|
||||
ostree_repo_file_get_child_for_display_name (GFile *file, const char *display_name, GError **error)
|
||||
{
|
||||
return g_file_get_child (file, display_name);
|
||||
}
|
||||
|
||||
static void
|
||||
set_info_from_dirmeta (GFileInfo *info,
|
||||
GVariant *metadata)
|
||||
set_info_from_dirmeta (GFileInfo *info, GVariant *metadata)
|
||||
{
|
||||
guint32 uid, gid, mode;
|
||||
|
||||
g_file_info_set_attribute_uint32 (info, "standard::type", G_FILE_TYPE_DIRECTORY);
|
||||
|
||||
/* PARSE OSTREE_OBJECT_TYPE_DIR_META */
|
||||
g_variant_get (metadata, "(uuu@a(ayay))",
|
||||
&uid, &gid, &mode, NULL);
|
||||
g_variant_get (metadata, "(uuu@a(ayay))", &uid, &gid, &mode, NULL);
|
||||
uid = GUINT32_FROM_BE (uid);
|
||||
gid = GUINT32_FROM_BE (gid);
|
||||
mode = GUINT32_FROM_BE (mode);
|
||||
@ -753,31 +719,26 @@ set_info_from_dirmeta (GFileInfo *info,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
query_child_info_dir (OstreeRepo *repo,
|
||||
const char *metadata_checksum,
|
||||
GFileAttributeMatcher *matcher,
|
||||
GFileQueryInfoFlags flags,
|
||||
GFileInfo **out_info,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
query_child_info_dir (OstreeRepo *repo, const char *metadata_checksum,
|
||||
GFileAttributeMatcher *matcher, GFileQueryInfoFlags flags,
|
||||
GFileInfo **out_info, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
|
||||
g_autoptr(GFileInfo) ret_info = g_file_info_new ();
|
||||
g_autoptr (GFileInfo) ret_info = g_file_info_new ();
|
||||
|
||||
g_file_info_set_attribute_uint32 (ret_info, "standard::type",
|
||||
G_FILE_TYPE_DIRECTORY);
|
||||
g_file_info_set_attribute_uint32 (ret_info, "standard::type", G_FILE_TYPE_DIRECTORY);
|
||||
|
||||
if (g_file_attribute_matcher_matches (matcher, "unix::mode"))
|
||||
{
|
||||
g_autoptr(GVariant) metadata = NULL;
|
||||
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_DIR_META,
|
||||
metadata_checksum, &metadata, error))
|
||||
g_autoptr (GVariant) metadata = NULL;
|
||||
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_DIR_META, metadata_checksum,
|
||||
&metadata, error))
|
||||
return FALSE;
|
||||
|
||||
set_info_from_dirmeta (ret_info, metadata);
|
||||
}
|
||||
|
||||
ot_transfer_out_value(out_info, &ret_info);
|
||||
ot_transfer_out_value (out_info, &ret_info);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -789,10 +750,8 @@ query_child_info_dir (OstreeRepo *repo,
|
||||
* @out_container: (out):
|
||||
*/
|
||||
int
|
||||
ostree_repo_file_tree_find_child (OstreeRepoFile *self,
|
||||
const char *name,
|
||||
gboolean *is_dir,
|
||||
GVariant **out_container)
|
||||
ostree_repo_file_tree_find_child (OstreeRepoFile *self, const char *name, gboolean *is_dir,
|
||||
GVariant **out_container)
|
||||
{
|
||||
int i;
|
||||
GVariant *files_variant = NULL;
|
||||
@ -846,23 +805,19 @@ ostree_repo_file_tree_find_child (OstreeRepoFile *self,
|
||||
* Returns: %TRUE on success and the @out_info is set, %FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
ostree_repo_file_tree_query_child (OstreeRepoFile *self,
|
||||
int n,
|
||||
const char *attributes,
|
||||
GFileQueryInfoFlags flags,
|
||||
GFileInfo **out_info,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_repo_file_tree_query_child (OstreeRepoFile *self, int n, const char *attributes,
|
||||
GFileQueryInfoFlags flags, GFileInfo **out_info,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
const char *name = NULL;
|
||||
int c;
|
||||
g_autoptr(GFileInfo) ret_info = NULL;
|
||||
g_autoptr(GVariant) files_variant = NULL;
|
||||
g_autoptr(GVariant) dirs_variant = NULL;
|
||||
g_autoptr(GVariant) content_csum_v = NULL;
|
||||
g_autoptr(GVariant) meta_csum_v = NULL;
|
||||
char tmp_checksum[OSTREE_SHA256_STRING_LEN+1];
|
||||
g_autoptr (GFileInfo) ret_info = NULL;
|
||||
g_autoptr (GVariant) files_variant = NULL;
|
||||
g_autoptr (GVariant) dirs_variant = NULL;
|
||||
g_autoptr (GVariant) content_csum_v = NULL;
|
||||
g_autoptr (GVariant) meta_csum_v = NULL;
|
||||
char tmp_checksum[OSTREE_SHA256_STRING_LEN + 1];
|
||||
GFileAttributeMatcher *matcher = NULL;
|
||||
|
||||
if (!ostree_repo_file_ensure_resolved (self, error))
|
||||
@ -887,8 +842,8 @@ ostree_repo_file_tree_query_child (OstreeRepoFile *self,
|
||||
|
||||
ostree_checksum_inplace_from_bytes (csum_bytes, tmp_checksum);
|
||||
|
||||
if (!ostree_repo_load_file (self->repo, tmp_checksum, NULL, &ret_info, NULL,
|
||||
cancellable, error))
|
||||
if (!ostree_repo_load_file (self->repo, tmp_checksum, NULL, &ret_info, NULL, cancellable,
|
||||
error))
|
||||
goto out;
|
||||
}
|
||||
else
|
||||
@ -901,16 +856,14 @@ ostree_repo_file_tree_query_child (OstreeRepoFile *self,
|
||||
{
|
||||
const guchar *csum_bytes;
|
||||
|
||||
g_variant_get_child (dirs_variant, n, "(&s@ay@ay)",
|
||||
&name, NULL, &meta_csum_v);
|
||||
g_variant_get_child (dirs_variant, n, "(&s@ay@ay)", &name, NULL, &meta_csum_v);
|
||||
csum_bytes = ostree_checksum_bytes_peek_validate (meta_csum_v, error);
|
||||
if (csum_bytes == NULL)
|
||||
goto out;
|
||||
|
||||
ostree_checksum_inplace_from_bytes (csum_bytes, tmp_checksum);
|
||||
|
||||
if (!query_child_info_dir (self->repo, tmp_checksum,
|
||||
matcher, flags, &ret_info,
|
||||
if (!query_child_info_dir (self->repo, tmp_checksum, matcher, flags, &ret_info,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
@ -918,10 +871,8 @@ ostree_repo_file_tree_query_child (OstreeRepoFile *self,
|
||||
|
||||
if (name)
|
||||
{
|
||||
g_file_info_set_attribute_byte_string (ret_info, "standard::name",
|
||||
name);
|
||||
g_file_info_set_attribute_string (ret_info, "standard::display-name",
|
||||
name);
|
||||
g_file_info_set_attribute_byte_string (ret_info, "standard::name", name);
|
||||
g_file_info_set_attribute_string (ret_info, "standard::display-name", name);
|
||||
if (*name == '.')
|
||||
g_file_info_set_is_hidden (ret_info, TRUE);
|
||||
}
|
||||
@ -931,22 +882,19 @@ ostree_repo_file_tree_query_child (OstreeRepoFile *self,
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
ot_transfer_out_value(out_info, &ret_info);
|
||||
out:
|
||||
ot_transfer_out_value (out_info, &ret_info);
|
||||
out:
|
||||
if (matcher)
|
||||
g_file_attribute_matcher_unref (matcher);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static GFileInfo *
|
||||
ostree_repo_file_query_info (GFile *file,
|
||||
const char *attributes,
|
||||
GFileQueryInfoFlags flags,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_repo_file_query_info (GFile *file, const char *attributes, GFileQueryInfoFlags flags,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
OstreeRepoFile *self = OSTREE_REPO_FILE (file);
|
||||
g_autoptr(GFileInfo) info = NULL;
|
||||
g_autoptr (GFileInfo) info = NULL;
|
||||
|
||||
if (!ostree_repo_file_ensure_resolved (self, error))
|
||||
return NULL;
|
||||
@ -958,9 +906,8 @@ ostree_repo_file_query_info (GFile *file,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ostree_repo_file_tree_query_child (self->parent, self->index,
|
||||
attributes, flags,
|
||||
&info, cancellable, error))
|
||||
if (!ostree_repo_file_tree_query_child (self->parent, self->index, attributes, flags, &info,
|
||||
cancellable, error))
|
||||
return NULL;
|
||||
g_assert (info != NULL);
|
||||
}
|
||||
@ -969,57 +916,49 @@ ostree_repo_file_query_info (GFile *file,
|
||||
}
|
||||
|
||||
static GFileAttributeInfoList *
|
||||
ostree_repo_file_query_settable_attributes (GFile *file,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_repo_file_query_settable_attributes (GFile *file, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
return g_file_attribute_info_list_new ();
|
||||
}
|
||||
|
||||
static GFileAttributeInfoList *
|
||||
ostree_repo_file_query_writable_namespaces (GFile *file,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_repo_file_query_writable_namespaces (GFile *file, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
return g_file_attribute_info_list_new ();
|
||||
}
|
||||
|
||||
static GFileInputStream *
|
||||
ostree_repo_file_read (GFile *file,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
ostree_repo_file_read (GFile *file, GCancellable *cancellable, GError **error)
|
||||
{
|
||||
OstreeRepoFile *self = OSTREE_REPO_FILE (file);
|
||||
const char *checksum;
|
||||
g_autoptr(GInputStream) ret_stream = NULL;
|
||||
g_autoptr (GInputStream) ret_stream = NULL;
|
||||
|
||||
if (!ostree_repo_file_ensure_resolved (self, error))
|
||||
return FALSE;
|
||||
|
||||
if (self->tree_contents)
|
||||
{
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY,
|
||||
"Can't open directory");
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY, "Can't open directory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
checksum = ostree_repo_file_get_checksum (self);
|
||||
|
||||
g_autoptr(GFileInfo) finfo = NULL;
|
||||
if (!ostree_repo_load_file (self->repo, checksum, NULL,
|
||||
&finfo, NULL, cancellable, error))
|
||||
g_autoptr (GFileInfo) finfo = NULL;
|
||||
if (!ostree_repo_load_file (self->repo, checksum, NULL, &finfo, NULL, cancellable, error))
|
||||
return NULL;
|
||||
if (g_file_info_get_file_type (finfo) == G_FILE_TYPE_REGULAR)
|
||||
{
|
||||
if (!ostree_repo_load_file (self->repo, checksum, &ret_stream,
|
||||
NULL, NULL, cancellable, error))
|
||||
if (!ostree_repo_load_file (self->repo, checksum, &ret_stream, NULL, NULL, cancellable,
|
||||
error))
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_autoptr(GFile) parent = g_file_get_parent (file);
|
||||
g_autoptr (GFile) parent = g_file_get_parent (file);
|
||||
const char *target = g_file_info_get_symlink_target (finfo);
|
||||
g_autoptr(GFile) dest = g_file_resolve_relative_path (parent, target);
|
||||
g_autoptr (GFile) dest = g_file_resolve_relative_path (parent, target);
|
||||
return g_file_read (dest, cancellable, error);
|
||||
}
|
||||
|
||||
|
@ -25,14 +25,17 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define OSTREE_TYPE_REPO_FILE (ostree_repo_file_get_type ())
|
||||
#define OSTREE_REPO_FILE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_REPO_FILE, OstreeRepoFile))
|
||||
#define OSTREE_REPO_FILE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), OSTREE_TYPE_REPO_FILE, OstreeRepoFileClass))
|
||||
#define OSTREE_IS_REPO_FILE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_REPO_FILE))
|
||||
#define OSTREE_IS_REPO_FILE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_REPO_FILE))
|
||||
#define OSTREE_REPO_FILE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_REPO_FILE, OstreeRepoFileClass))
|
||||
#define OSTREE_TYPE_REPO_FILE (ostree_repo_file_get_type ())
|
||||
#define OSTREE_REPO_FILE(o) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_REPO_FILE, OstreeRepoFile))
|
||||
#define OSTREE_REPO_FILE_CLASS(k) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((k), OSTREE_TYPE_REPO_FILE, OstreeRepoFileClass))
|
||||
#define OSTREE_IS_REPO_FILE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_REPO_FILE))
|
||||
#define OSTREE_IS_REPO_FILE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_REPO_FILE))
|
||||
#define OSTREE_REPO_FILE_GET_CLASS(o) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_REPO_FILE, OstreeRepoFileClass))
|
||||
|
||||
typedef struct _OstreeRepoFileClass OstreeRepoFileClass;
|
||||
typedef struct _OstreeRepoFileClass OstreeRepoFileClass;
|
||||
|
||||
struct _OstreeRepoFileClass
|
||||
{
|
||||
@ -40,32 +43,28 @@ struct _OstreeRepoFileClass
|
||||
};
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
GType ostree_repo_file_get_type (void) G_GNUC_CONST;
|
||||
GType ostree_repo_file_get_type (void) G_GNUC_CONST;
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_repo_file_ensure_resolved (OstreeRepoFile *self,
|
||||
GError **error);
|
||||
gboolean ostree_repo_file_ensure_resolved (OstreeRepoFile *self, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_repo_file_get_xattrs (OstreeRepoFile *self,
|
||||
GVariant **out_xattrs,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_repo_file_get_xattrs (OstreeRepoFile *self, GVariant **out_xattrs,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeRepo * ostree_repo_file_get_repo (OstreeRepoFile *self);
|
||||
OstreeRepo *ostree_repo_file_get_repo (OstreeRepoFile *self);
|
||||
_OSTREE_PUBLIC
|
||||
OstreeRepoFile * ostree_repo_file_get_root (OstreeRepoFile *self);
|
||||
OstreeRepoFile *ostree_repo_file_get_root (OstreeRepoFile *self);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_repo_file_tree_set_metadata (OstreeRepoFile *self,
|
||||
const char *checksum,
|
||||
GVariant *metadata);
|
||||
void ostree_repo_file_tree_set_metadata (OstreeRepoFile *self, const char *checksum,
|
||||
GVariant *metadata);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
const char *ostree_repo_file_tree_get_contents_checksum (OstreeRepoFile *self);
|
||||
const char *ostree_repo_file_tree_get_contents_checksum (OstreeRepoFile *self);
|
||||
_OSTREE_PUBLIC
|
||||
const char *ostree_repo_file_tree_get_metadata_checksum (OstreeRepoFile *self);
|
||||
const char *ostree_repo_file_tree_get_metadata_checksum (OstreeRepoFile *self);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
GVariant *ostree_repo_file_tree_get_contents (OstreeRepoFile *self);
|
||||
@ -73,21 +72,15 @@ _OSTREE_PUBLIC
|
||||
GVariant *ostree_repo_file_tree_get_metadata (OstreeRepoFile *self);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
const char * ostree_repo_file_get_checksum (OstreeRepoFile *self);
|
||||
const char *ostree_repo_file_get_checksum (OstreeRepoFile *self);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
int ostree_repo_file_tree_find_child (OstreeRepoFile *self,
|
||||
const char *name,
|
||||
gboolean *is_dir,
|
||||
GVariant **out_container);
|
||||
int ostree_repo_file_tree_find_child (OstreeRepoFile *self, const char *name, gboolean *is_dir,
|
||||
GVariant **out_container);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_repo_file_tree_query_child (OstreeRepoFile *self,
|
||||
int n,
|
||||
const char *attributes,
|
||||
GFileQueryInfoFlags flags,
|
||||
GFileInfo **out_info,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean ostree_repo_file_tree_query_child (OstreeRepoFile *self, int n, const char *attributes,
|
||||
GFileQueryInfoFlags flags, GFileInfo **out_info,
|
||||
GCancellable *cancellable, GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -25,23 +25,19 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <avahi-common/strlst.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
#include <libglnx.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ostree-autocleanups.h"
|
||||
#include "ostree-repo-finder-avahi.h"
|
||||
#include "ostree-repo-finder-avahi-private.h"
|
||||
#include "ostree-repo-finder-avahi.h"
|
||||
|
||||
/* Reference: RFC 6763, §6. */
|
||||
static gboolean
|
||||
parse_txt_record (const guint8 *txt,
|
||||
gsize txt_len,
|
||||
const gchar **key,
|
||||
gsize *key_len,
|
||||
const guint8 **value,
|
||||
gsize *value_len)
|
||||
parse_txt_record (const guint8 *txt, gsize txt_len, const gchar **key, gsize *key_len,
|
||||
const guint8 **value, gsize *value_len)
|
||||
{
|
||||
gsize i;
|
||||
|
||||
@ -54,7 +50,7 @@ parse_txt_record (const guint8 *txt,
|
||||
if (txt_len > 8900)
|
||||
return FALSE;
|
||||
|
||||
*key = (const gchar *) txt;
|
||||
*key = (const gchar *)txt;
|
||||
*key_len = 0;
|
||||
*value = NULL;
|
||||
*value_len = 0;
|
||||
@ -92,9 +88,9 @@ GHashTable *
|
||||
_ostree_txt_records_parse (AvahiStringList *txt_list)
|
||||
{
|
||||
AvahiStringList *l;
|
||||
g_autoptr(GHashTable) out = NULL;
|
||||
g_autoptr (GHashTable) out = NULL;
|
||||
|
||||
out = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_bytes_unref);
|
||||
out = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_bytes_unref);
|
||||
|
||||
for (l = txt_list; l != NULL; l = avahi_string_list_get_next (l))
|
||||
{
|
||||
@ -104,15 +100,14 @@ _ostree_txt_records_parse (AvahiStringList *txt_list)
|
||||
const guint8 *value;
|
||||
gsize key_len, value_len;
|
||||
g_autofree gchar *key_allocated = NULL;
|
||||
g_autoptr(GBytes) value_allocated = NULL;
|
||||
g_autoptr (GBytes) value_allocated = NULL;
|
||||
|
||||
txt = avahi_string_list_get_text (l);
|
||||
txt_len = avahi_string_list_get_size (l);
|
||||
|
||||
if (!parse_txt_record (txt, txt_len, &key, &key_len, &value, &value_len))
|
||||
{
|
||||
g_debug ("Ignoring invalid TXT record of length %" G_GSIZE_FORMAT,
|
||||
txt_len);
|
||||
g_debug ("Ignoring invalid TXT record of length %" G_GSIZE_FORMAT, txt_len);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -130,7 +125,8 @@ _ostree_txt_records_parse (AvahiStringList *txt_list)
|
||||
if (value != NULL)
|
||||
value_allocated = g_bytes_new_static (value, value_len);
|
||||
|
||||
g_hash_table_insert (out, g_steal_pointer (&key_allocated), g_steal_pointer (&value_allocated));
|
||||
g_hash_table_insert (out, g_steal_pointer (&key_allocated),
|
||||
g_steal_pointer (&value_allocated));
|
||||
}
|
||||
|
||||
return g_steal_pointer (&out);
|
||||
|
@ -24,8 +24,8 @@
|
||||
|
||||
#include <avahi-common/strlst.h>
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -23,8 +23,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "ostree-repo-finder.h"
|
||||
#include "ostree-types.h"
|
||||
@ -35,27 +35,39 @@ G_BEGIN_DECLS
|
||||
|
||||
/* Manually expanded version of the following, omitting autoptr support (for GLib < 2.44):
|
||||
_OSTREE_PUBLIC
|
||||
G_DECLARE_FINAL_TYPE (OstreeRepoFinderAvahi, ostree_repo_finder_avahi, OSTREE, REPO_FINDER_AVAHI, GObject) */
|
||||
G_DECLARE_FINAL_TYPE (OstreeRepoFinderAvahi, ostree_repo_finder_avahi, OSTREE, REPO_FINDER_AVAHI,
|
||||
GObject) */
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
GType ostree_repo_finder_avahi_get_type (void);
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
typedef struct _OstreeRepoFinderAvahi OstreeRepoFinderAvahi;
|
||||
typedef struct { GObjectClass parent_class; } OstreeRepoFinderAvahiClass;
|
||||
typedef struct
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
} OstreeRepoFinderAvahiClass;
|
||||
|
||||
static inline OstreeRepoFinderAvahi *OSTREE_REPO_FINDER_AVAHI (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_repo_finder_avahi_get_type (), OstreeRepoFinderAvahi); }
|
||||
static inline gboolean OSTREE_IS_REPO_FINDER_AVAHI (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_repo_finder_avahi_get_type ()); }
|
||||
static inline OstreeRepoFinderAvahi *
|
||||
OSTREE_REPO_FINDER_AVAHI (gpointer ptr)
|
||||
{
|
||||
return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_repo_finder_avahi_get_type (),
|
||||
OstreeRepoFinderAvahi);
|
||||
}
|
||||
static inline gboolean
|
||||
OSTREE_IS_REPO_FINDER_AVAHI (gpointer ptr)
|
||||
{
|
||||
return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_repo_finder_avahi_get_type ());
|
||||
}
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeRepoFinderAvahi *ostree_repo_finder_avahi_new (GMainContext *context);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_repo_finder_avahi_start (OstreeRepoFinderAvahi *self,
|
||||
GError **error);
|
||||
void ostree_repo_finder_avahi_start (OstreeRepoFinderAvahi *self, GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_repo_finder_avahi_stop (OstreeRepoFinderAvahi *self);
|
||||
void ostree_repo_finder_avahi_stop (OstreeRepoFinderAvahi *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -24,16 +24,16 @@
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
#include <libglnx.h>
|
||||
|
||||
#include "ostree-autocleanups.h"
|
||||
#include "ostree-remote-private.h"
|
||||
#include "ostree-repo.h"
|
||||
#include "ostree-repo-private.h"
|
||||
#include "ostree-repo-finder.h"
|
||||
#include "ostree-repo-finder-config.h"
|
||||
#include "ostree-repo-finder.h"
|
||||
#include "ostree-repo-private.h"
|
||||
#include "ostree-repo.h"
|
||||
|
||||
/**
|
||||
* SECTION:ostree-repo-finder-config
|
||||
@ -65,42 +65,40 @@ struct _OstreeRepoFinderConfig
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (OstreeRepoFinderConfig, ostree_repo_finder_config, G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_REPO_FINDER, ostree_repo_finder_config_iface_init))
|
||||
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_REPO_FINDER,
|
||||
ostree_repo_finder_config_iface_init))
|
||||
|
||||
static gint
|
||||
results_compare_cb (gconstpointer a,
|
||||
gconstpointer b)
|
||||
results_compare_cb (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
const OstreeRepoFinderResult *result_a = *((const OstreeRepoFinderResult **) a);
|
||||
const OstreeRepoFinderResult *result_b = *((const OstreeRepoFinderResult **) b);
|
||||
const OstreeRepoFinderResult *result_a = *((const OstreeRepoFinderResult **)a);
|
||||
const OstreeRepoFinderResult *result_b = *((const OstreeRepoFinderResult **)b);
|
||||
|
||||
return ostree_repo_finder_result_compare (result_a, result_b);
|
||||
}
|
||||
|
||||
static void
|
||||
ostree_repo_finder_config_resolve_async (OstreeRepoFinder *finder,
|
||||
const OstreeCollectionRef * const *refs,
|
||||
OstreeRepo *parent_repo,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
ostree_repo_finder_config_resolve_async (OstreeRepoFinder *finder,
|
||||
const OstreeCollectionRef *const *refs,
|
||||
OstreeRepo *parent_repo, GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback, gpointer user_data)
|
||||
{
|
||||
g_autoptr(GTask) task = NULL;
|
||||
g_autoptr(GPtrArray) results = NULL;
|
||||
const gint priority = 100; /* arbitrarily chosen; lower than the others */
|
||||
g_autoptr (GTask) task = NULL;
|
||||
g_autoptr (GPtrArray) results = NULL;
|
||||
const gint priority = 100; /* arbitrarily chosen; lower than the others */
|
||||
gsize i, j;
|
||||
g_autoptr(GHashTable) repo_name_to_refs = NULL; /* (element-type utf8 GHashTable) */
|
||||
GHashTable *supported_ref_to_checksum; /* (element-type OstreeCollectionRef utf8) */
|
||||
g_autoptr (GHashTable) repo_name_to_refs = NULL; /* (element-type utf8 GHashTable) */
|
||||
GHashTable *supported_ref_to_checksum; /* (element-type OstreeCollectionRef utf8) */
|
||||
GHashTableIter iter;
|
||||
const gchar *remote_name;
|
||||
g_auto(GStrv) remotes = NULL;
|
||||
g_auto (GStrv) remotes = NULL;
|
||||
guint n_remotes = 0;
|
||||
|
||||
task = g_task_new (finder, cancellable, callback, user_data);
|
||||
g_task_set_source_tag (task, ostree_repo_finder_config_resolve_async);
|
||||
results = g_ptr_array_new_with_free_func ((GDestroyNotify) ostree_repo_finder_result_free);
|
||||
repo_name_to_refs = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
|
||||
(GDestroyNotify) g_hash_table_unref);
|
||||
results = g_ptr_array_new_with_free_func ((GDestroyNotify)ostree_repo_finder_result_free);
|
||||
repo_name_to_refs
|
||||
= g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify)g_hash_table_unref);
|
||||
|
||||
/* List all remotes in this #OstreeRepo and see which of their ref lists
|
||||
* intersect with @refs. */
|
||||
@ -110,17 +108,17 @@ ostree_repo_finder_config_resolve_async (OstreeRepoFinder *find
|
||||
|
||||
for (i = 0; i < n_remotes; i++)
|
||||
{
|
||||
g_autoptr(GError) local_error = NULL;
|
||||
g_autoptr(GHashTable) remote_refs = NULL; /* (element-type OstreeCollectionRef utf8) */
|
||||
g_autoptr (GError) local_error = NULL;
|
||||
g_autoptr (GHashTable) remote_refs = NULL; /* (element-type OstreeCollectionRef utf8) */
|
||||
const gchar *checksum;
|
||||
g_autofree gchar *remote_collection_id = NULL;
|
||||
gboolean resolved_a_ref = FALSE;
|
||||
|
||||
remote_name = remotes[i];
|
||||
|
||||
if (!ostree_repo_get_remote_option (parent_repo, remote_name, "collection-id",
|
||||
NULL, &remote_collection_id, &local_error) ||
|
||||
!ostree_validate_collection_id (remote_collection_id, &local_error))
|
||||
if (!ostree_repo_get_remote_option (parent_repo, remote_name, "collection-id", NULL,
|
||||
&remote_collection_id, &local_error)
|
||||
|| !ostree_validate_collection_id (remote_collection_id, &local_error))
|
||||
{
|
||||
g_debug ("Ignoring remote ‘%s’ due to no valid collection ID being configured for it: %s",
|
||||
remote_name, local_error->message);
|
||||
@ -128,54 +126,55 @@ ostree_repo_finder_config_resolve_async (OstreeRepoFinder *find
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ostree_repo_remote_list_collection_refs (parent_repo, remote_name,
|
||||
&remote_refs, cancellable,
|
||||
&local_error))
|
||||
if (!ostree_repo_remote_list_collection_refs (parent_repo, remote_name, &remote_refs,
|
||||
cancellable, &local_error))
|
||||
{
|
||||
g_debug ("Ignoring remote ‘%s’ due to error loading its refs: %s",
|
||||
remote_name, local_error->message);
|
||||
g_debug ("Ignoring remote ‘%s’ due to error loading its refs: %s", remote_name,
|
||||
local_error->message);
|
||||
g_clear_error (&local_error);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (j = 0; refs[j] != NULL; j++)
|
||||
{
|
||||
if (g_strcmp0 (refs[j]->collection_id, remote_collection_id) == 0 &&
|
||||
g_hash_table_lookup_extended (remote_refs, refs[j], NULL, (gpointer *) &checksum))
|
||||
if (g_strcmp0 (refs[j]->collection_id, remote_collection_id) == 0
|
||||
&& g_hash_table_lookup_extended (remote_refs, refs[j], NULL, (gpointer *)&checksum))
|
||||
{
|
||||
/* The requested ref is listed in the refs for this remote. Add
|
||||
* the remote to the results, and the ref to its
|
||||
* @supported_ref_to_checksum. */
|
||||
g_debug ("Resolved ref (%s, %s) to remote ‘%s’.",
|
||||
refs[j]->collection_id, refs[j]->ref_name, remote_name);
|
||||
g_debug ("Resolved ref (%s, %s) to remote ‘%s’.", refs[j]->collection_id,
|
||||
refs[j]->ref_name, remote_name);
|
||||
resolved_a_ref = TRUE;
|
||||
|
||||
supported_ref_to_checksum = g_hash_table_lookup (repo_name_to_refs, remote_name);
|
||||
|
||||
if (supported_ref_to_checksum == NULL)
|
||||
{
|
||||
supported_ref_to_checksum = g_hash_table_new_full (ostree_collection_ref_hash,
|
||||
ostree_collection_ref_equal,
|
||||
NULL, g_free);
|
||||
g_hash_table_insert (repo_name_to_refs, (gpointer) remote_name, supported_ref_to_checksum /* transfer */);
|
||||
supported_ref_to_checksum = g_hash_table_new_full (
|
||||
ostree_collection_ref_hash, ostree_collection_ref_equal, NULL, g_free);
|
||||
g_hash_table_insert (repo_name_to_refs, (gpointer)remote_name,
|
||||
supported_ref_to_checksum /* transfer */);
|
||||
}
|
||||
|
||||
g_hash_table_insert (supported_ref_to_checksum,
|
||||
(gpointer) refs[j], g_strdup (checksum));
|
||||
g_hash_table_insert (supported_ref_to_checksum, (gpointer)refs[j],
|
||||
g_strdup (checksum));
|
||||
}
|
||||
}
|
||||
|
||||
if (!resolved_a_ref)
|
||||
g_debug ("Ignoring remote ‘%s’ due to it not advertising any of the requested refs.", remote_name);
|
||||
g_debug ("Ignoring remote ‘%s’ due to it not advertising any of the requested refs.",
|
||||
remote_name);
|
||||
}
|
||||
|
||||
/* Aggregate the results. */
|
||||
g_hash_table_iter_init (&iter, repo_name_to_refs);
|
||||
|
||||
while (g_hash_table_iter_next (&iter, (gpointer *) &remote_name, (gpointer *) &supported_ref_to_checksum))
|
||||
while (g_hash_table_iter_next (&iter, (gpointer *)&remote_name,
|
||||
(gpointer *)&supported_ref_to_checksum))
|
||||
{
|
||||
g_autoptr(GError) local_error = NULL;
|
||||
g_autoptr(OstreeRemote) remote = NULL;
|
||||
g_autoptr (GError) local_error = NULL;
|
||||
g_autoptr (OstreeRemote) remote = NULL;
|
||||
|
||||
/* We don’t know what last-modified timestamp the remote has without
|
||||
* making expensive HTTP queries, so leave that information blank. We
|
||||
@ -185,23 +184,22 @@ ostree_repo_finder_config_resolve_async (OstreeRepoFinder *find
|
||||
remote = _ostree_repo_get_remote_inherited (parent_repo, remote_name, &local_error);
|
||||
if (remote == NULL)
|
||||
{
|
||||
g_debug ("Configuration for remote ‘%s’ could not be found. Ignoring.",
|
||||
remote_name);
|
||||
g_debug ("Configuration for remote ‘%s’ could not be found. Ignoring.", remote_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
g_ptr_array_add (results, ostree_repo_finder_result_new (remote, finder, priority, supported_ref_to_checksum, NULL, 0));
|
||||
g_ptr_array_add (results, ostree_repo_finder_result_new (remote, finder, priority,
|
||||
supported_ref_to_checksum, NULL, 0));
|
||||
}
|
||||
|
||||
g_ptr_array_sort (results, results_compare_cb);
|
||||
|
||||
g_task_return_pointer (task, g_steal_pointer (&results), (GDestroyNotify) g_ptr_array_unref);
|
||||
g_task_return_pointer (task, g_steal_pointer (&results), (GDestroyNotify)g_ptr_array_unref);
|
||||
}
|
||||
|
||||
static GPtrArray *
|
||||
ostree_repo_finder_config_resolve_finish (OstreeRepoFinder *finder,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
ostree_repo_finder_config_resolve_finish (OstreeRepoFinder *finder, GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (g_task_is_valid (result, finder), NULL);
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
|
@ -23,8 +23,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "ostree-repo-finder.h"
|
||||
#include "ostree-types.h"
|
||||
@ -35,17 +35,30 @@ G_BEGIN_DECLS
|
||||
|
||||
/* Manually expanded version of the following, omitting autoptr support (for GLib < 2.44):
|
||||
_OSTREE_PUBLIC
|
||||
G_DECLARE_FINAL_TYPE (OstreeRepoFinderConfig, ostree_repo_finder_config, OSTREE, REPO_FINDER_CONFIG, GObject) */
|
||||
G_DECLARE_FINAL_TYPE (OstreeRepoFinderConfig, ostree_repo_finder_config, OSTREE,
|
||||
REPO_FINDER_CONFIG, GObject) */
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
GType ostree_repo_finder_config_get_type (void);
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
typedef struct _OstreeRepoFinderConfig OstreeRepoFinderConfig;
|
||||
typedef struct { GObjectClass parent_class; } OstreeRepoFinderConfigClass;
|
||||
typedef struct
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
} OstreeRepoFinderConfigClass;
|
||||
|
||||
static inline OstreeRepoFinderConfig *OSTREE_REPO_FINDER_CONFIG (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_repo_finder_config_get_type (), OstreeRepoFinderConfig); }
|
||||
static inline gboolean OSTREE_IS_REPO_FINDER_CONFIG (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_repo_finder_config_get_type ()); }
|
||||
static inline OstreeRepoFinderConfig *
|
||||
OSTREE_REPO_FINDER_CONFIG (gpointer ptr)
|
||||
{
|
||||
return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_repo_finder_config_get_type (),
|
||||
OstreeRepoFinderConfig);
|
||||
}
|
||||
static inline gboolean
|
||||
OSTREE_IS_REPO_FINDER_CONFIG (gpointer ptr)
|
||||
{
|
||||
return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_repo_finder_config_get_type ());
|
||||
}
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
|
@ -24,16 +24,16 @@
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <gio/gunixmounts.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
#include <libglnx.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ostree-autocleanups.h"
|
||||
#include "ostree-remote-private.h"
|
||||
#include "ostree-repo-private.h"
|
||||
#include "ostree-repo-finder.h"
|
||||
#include "ostree-repo-finder-mount.h"
|
||||
#include "ostree-repo-finder.h"
|
||||
#include "ostree-repo-private.h"
|
||||
|
||||
/**
|
||||
* SECTION:ostree-repo-finder-mount
|
||||
@ -69,7 +69,7 @@
|
||||
* Since: 2018.6
|
||||
*/
|
||||
|
||||
typedef GList/*<owned GObject>*/ ObjectList;
|
||||
typedef GList /*<owned GObject>*/ ObjectList;
|
||||
|
||||
static void
|
||||
object_list_free (ObjectList *list)
|
||||
@ -85,16 +85,17 @@ struct _OstreeRepoFinderMount
|
||||
{
|
||||
GObject parent_instance;
|
||||
|
||||
GVolumeMonitor *monitor; /* owned */
|
||||
GVolumeMonitor *monitor; /* owned */
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (OstreeRepoFinderMount, ostree_repo_finder_mount, G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_REPO_FINDER, ostree_repo_finder_mount_iface_init))
|
||||
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_REPO_FINDER,
|
||||
ostree_repo_finder_mount_iface_init))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gchar *uri;
|
||||
OstreeRemote *keyring_remote; /* (owned) */
|
||||
OstreeRemote *keyring_remote; /* (owned) */
|
||||
} UriAndKeyring;
|
||||
|
||||
static void
|
||||
@ -108,10 +109,9 @@ uri_and_keyring_free (UriAndKeyring *data)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UriAndKeyring, uri_and_keyring_free)
|
||||
|
||||
static UriAndKeyring *
|
||||
uri_and_keyring_new (const gchar *uri,
|
||||
OstreeRemote *keyring_remote)
|
||||
uri_and_keyring_new (const gchar *uri, OstreeRemote *keyring_remote)
|
||||
{
|
||||
g_autoptr(UriAndKeyring) data = NULL;
|
||||
g_autoptr (UriAndKeyring) data = NULL;
|
||||
|
||||
data = g_new0 (UriAndKeyring, 1);
|
||||
data->uri = g_strdup (uri);
|
||||
@ -129,13 +129,12 @@ uri_and_keyring_hash (gconstpointer key)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
uri_and_keyring_equal (gconstpointer a,
|
||||
gconstpointer b)
|
||||
uri_and_keyring_equal (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
const UriAndKeyring *_a = a, *_b = b;
|
||||
|
||||
return (g_str_equal (_a->uri, _b->uri) &&
|
||||
g_str_equal (_a->keyring_remote->keyring, _b->keyring_remote->keyring));
|
||||
return (g_str_equal (_a->uri, _b->uri)
|
||||
&& g_str_equal (_a->keyring_remote->keyring, _b->keyring_remote->keyring));
|
||||
}
|
||||
|
||||
/* This must return a valid remote name (suitable for use in a refspec). */
|
||||
@ -143,7 +142,8 @@ static gchar *
|
||||
uri_and_keyring_to_name (UriAndKeyring *data)
|
||||
{
|
||||
g_autofree gchar *escaped_uri = g_uri_escape_string (data->uri, NULL, FALSE);
|
||||
g_autofree gchar *escaped_keyring = g_uri_escape_string (data->keyring_remote->keyring, NULL, FALSE);
|
||||
g_autofree gchar *escaped_keyring
|
||||
= g_uri_escape_string (data->keyring_remote->keyring, NULL, FALSE);
|
||||
|
||||
/* FIXME: Need a better separator than `_`, since it’s not escaped in the input. */
|
||||
g_autofree gchar *out = g_strdup_printf ("%s_%s", escaped_uri, escaped_keyring);
|
||||
@ -160,20 +160,19 @@ uri_and_keyring_to_name (UriAndKeyring *data)
|
||||
}
|
||||
|
||||
static gint
|
||||
results_compare_cb (gconstpointer a,
|
||||
gconstpointer b)
|
||||
results_compare_cb (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
const OstreeRepoFinderResult *result_a = *((const OstreeRepoFinderResult **) a);
|
||||
const OstreeRepoFinderResult *result_b = *((const OstreeRepoFinderResult **) b);
|
||||
const OstreeRepoFinderResult *result_a = *((const OstreeRepoFinderResult **)a);
|
||||
const OstreeRepoFinderResult *result_b = *((const OstreeRepoFinderResult **)b);
|
||||
|
||||
return ostree_repo_finder_result_compare (result_a, result_b);
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *ordering_name; /* (owned) */
|
||||
OstreeRepo *repo; /* (owned) */
|
||||
GHashTable *refs; /* (owned) (element-type OstreeCollectionRef utf8) */
|
||||
char *ordering_name; /* (owned) */
|
||||
OstreeRepo *repo; /* (owned) */
|
||||
GHashTable *refs; /* (owned) (element-type OstreeCollectionRef utf8) */
|
||||
} RepoAndRefs;
|
||||
|
||||
static void
|
||||
@ -185,8 +184,7 @@ repo_and_refs_clear (RepoAndRefs *data)
|
||||
}
|
||||
|
||||
static gint
|
||||
repo_and_refs_compare (gconstpointer a,
|
||||
gconstpointer b)
|
||||
repo_and_refs_compare (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
const RepoAndRefs *_a = a;
|
||||
const RepoAndRefs *_b = b;
|
||||
@ -198,23 +196,17 @@ repo_and_refs_compare (gconstpointer a,
|
||||
* to the @parent_repo, and can be opened. If so, return it as @out_repo and
|
||||
* all its collection–refs as @out_refs, to be added into the results. */
|
||||
static gboolean
|
||||
scan_repo (int dfd,
|
||||
const char *path,
|
||||
const char *mount_name,
|
||||
const struct stat *mount_root_stbuf,
|
||||
OstreeRepo *parent_repo,
|
||||
OstreeRepo **out_repo,
|
||||
GHashTable **out_refs,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
scan_repo (int dfd, const char *path, const char *mount_name, const struct stat *mount_root_stbuf,
|
||||
OstreeRepo *parent_repo, OstreeRepo **out_repo, GHashTable **out_refs,
|
||||
GCancellable *cancellable, GError **error)
|
||||
{
|
||||
g_autoptr(GError) local_error = NULL;
|
||||
g_autoptr (GError) local_error = NULL;
|
||||
|
||||
g_autoptr(OstreeRepo) repo = ostree_repo_open_at (dfd, path, cancellable, &local_error);
|
||||
g_autoptr (OstreeRepo) repo = ostree_repo_open_at (dfd, path, cancellable, &local_error);
|
||||
if (repo == NULL)
|
||||
{
|
||||
g_debug ("Ignoring repository ‘%s’ on mount ‘%s’ as it could not be opened: %s",
|
||||
path, mount_name, local_error->message);
|
||||
g_debug ("Ignoring repository ‘%s’ on mount ‘%s’ as it could not be opened: %s", path,
|
||||
mount_name, local_error->message);
|
||||
g_propagate_error (error, g_steal_pointer (&local_error));
|
||||
return FALSE;
|
||||
}
|
||||
@ -224,8 +216,8 @@ scan_repo (int dfd,
|
||||
|
||||
if (!glnx_fstat (repo_dfd, &stbuf, &local_error))
|
||||
{
|
||||
g_debug ("Ignoring repository ‘%s’ on mount ‘%s’ as querying its info failed: %s",
|
||||
path, mount_name, local_error->message);
|
||||
g_debug ("Ignoring repository ‘%s’ on mount ‘%s’ as querying its info failed: %s", path,
|
||||
mount_name, local_error->message);
|
||||
g_propagate_error (error, g_steal_pointer (&local_error));
|
||||
return FALSE;
|
||||
}
|
||||
@ -234,29 +226,30 @@ scan_repo (int dfd,
|
||||
* allow ref symlinks to point somewhere outside of the mounted volume. */
|
||||
if (stbuf.st_dev != mount_root_stbuf->st_dev)
|
||||
{
|
||||
g_debug ("Ignoring repository ‘%s’ on mount ‘%s’ as it’s on a different file system from the mount",
|
||||
g_debug ("Ignoring repository ‘%s’ on mount ‘%s’ as it’s on a different file system from "
|
||||
"the mount",
|
||||
path, mount_name);
|
||||
return glnx_throw (error, "Repository is on a different file system from the mount");
|
||||
}
|
||||
|
||||
/* Exclude repositories which resolve to @parent_repo. */
|
||||
if (stbuf.st_dev == parent_repo->device &&
|
||||
stbuf.st_ino == parent_repo->inode)
|
||||
if (stbuf.st_dev == parent_repo->device && stbuf.st_ino == parent_repo->inode)
|
||||
{
|
||||
g_debug ("Ignoring repository ‘%s’ on mount ‘%s’ as it is the same as the one we are resolving",
|
||||
path, mount_name);
|
||||
g_debug (
|
||||
"Ignoring repository ‘%s’ on mount ‘%s’ as it is the same as the one we are resolving",
|
||||
path, mount_name);
|
||||
return glnx_throw (error, "Repository is the same as the one we are resolving");
|
||||
}
|
||||
|
||||
/* List the repo’s refs and return them. */
|
||||
g_autoptr(GHashTable) repo_refs = NULL; /* (element-type OstreeCollectionRef utf8) */
|
||||
g_autoptr (GHashTable) repo_refs = NULL; /* (element-type OstreeCollectionRef utf8) */
|
||||
|
||||
if (!ostree_repo_list_collection_refs (repo, NULL, &repo_refs,
|
||||
OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES,
|
||||
cancellable, &local_error))
|
||||
OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES, cancellable,
|
||||
&local_error))
|
||||
{
|
||||
g_debug ("Ignoring repository ‘%s’ on mount ‘%s’ as its refs could not be listed: %s",
|
||||
path, mount_name, local_error->message);
|
||||
g_debug ("Ignoring repository ‘%s’ on mount ‘%s’ as its refs could not be listed: %s", path,
|
||||
mount_name, local_error->message);
|
||||
g_propagate_error (error, g_steal_pointer (&local_error));
|
||||
return FALSE;
|
||||
}
|
||||
@ -270,54 +263,43 @@ scan_repo (int dfd,
|
||||
}
|
||||
|
||||
static void
|
||||
scan_and_add_repo (int dfd,
|
||||
const char *path,
|
||||
gboolean sortable,
|
||||
const char *mount_name,
|
||||
const struct stat *mount_root_stbuf,
|
||||
OstreeRepo *parent_repo,
|
||||
GArray *inout_repos_refs,
|
||||
GCancellable *cancellable)
|
||||
scan_and_add_repo (int dfd, const char *path, gboolean sortable, const char *mount_name,
|
||||
const struct stat *mount_root_stbuf, OstreeRepo *parent_repo,
|
||||
GArray *inout_repos_refs, GCancellable *cancellable)
|
||||
{
|
||||
g_autoptr(GHashTable) repo_refs = NULL;
|
||||
g_autoptr(OstreeRepo) repo = NULL;
|
||||
g_autoptr (GHashTable) repo_refs = NULL;
|
||||
g_autoptr (OstreeRepo) repo = NULL;
|
||||
|
||||
if (scan_repo (dfd, path,
|
||||
mount_name, mount_root_stbuf,
|
||||
parent_repo, &repo, &repo_refs, cancellable, NULL))
|
||||
if (scan_repo (dfd, path, mount_name, mount_root_stbuf, parent_repo, &repo, &repo_refs,
|
||||
cancellable, NULL))
|
||||
{
|
||||
RepoAndRefs val = {
|
||||
sortable ? g_strdup (path) : NULL,
|
||||
g_steal_pointer (&repo),
|
||||
g_steal_pointer (&repo_refs)
|
||||
};
|
||||
RepoAndRefs val = { sortable ? g_strdup (path) : NULL, g_steal_pointer (&repo),
|
||||
g_steal_pointer (&repo_refs) };
|
||||
g_array_append_val (inout_repos_refs, val);
|
||||
|
||||
g_debug ("%s: Adding repo ‘%s’ on mount ‘%s’ (%ssortable)",
|
||||
G_STRFUNC, path, mount_name, sortable ? "" : "not ");
|
||||
g_debug ("%s: Adding repo ‘%s’ on mount ‘%s’ (%ssortable)", G_STRFUNC, path, mount_name,
|
||||
sortable ? "" : "not ");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ostree_repo_finder_mount_resolve_async (OstreeRepoFinder *finder,
|
||||
const OstreeCollectionRef * const *refs,
|
||||
OstreeRepo *parent_repo,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
ostree_repo_finder_mount_resolve_async (OstreeRepoFinder *finder,
|
||||
const OstreeCollectionRef *const *refs,
|
||||
OstreeRepo *parent_repo, GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback, gpointer user_data)
|
||||
{
|
||||
OstreeRepoFinderMount *self = OSTREE_REPO_FINDER_MOUNT (finder);
|
||||
g_autoptr(GTask) task = NULL;
|
||||
g_autoptr(ObjectList) mounts = NULL;
|
||||
g_autoptr(GPtrArray) results = NULL; /* (element-type OstreeRepoFinderResult) */
|
||||
g_autoptr (GTask) task = NULL;
|
||||
g_autoptr (ObjectList) mounts = NULL;
|
||||
g_autoptr (GPtrArray) results = NULL; /* (element-type OstreeRepoFinderResult) */
|
||||
GList *l;
|
||||
const gint priority = 50; /* arbitrarily chosen */
|
||||
const gint priority = 50; /* arbitrarily chosen */
|
||||
|
||||
task = g_task_new (finder, cancellable, callback, user_data);
|
||||
g_task_set_source_tag (task, ostree_repo_finder_mount_resolve_async);
|
||||
|
||||
mounts = g_volume_monitor_get_mounts (self->monitor);
|
||||
results = g_ptr_array_new_with_free_func ((GDestroyNotify) ostree_repo_finder_result_free);
|
||||
results = g_ptr_array_new_with_free_func ((GDestroyNotify)ostree_repo_finder_result_free);
|
||||
|
||||
g_debug ("%s: Found %u mounts", G_STRFUNC, g_list_length (mounts));
|
||||
|
||||
@ -325,16 +307,16 @@ ostree_repo_finder_mount_resolve_async (OstreeRepoFinder *finde
|
||||
{
|
||||
GMount *mount = G_MOUNT (l->data);
|
||||
g_autofree gchar *mount_name = NULL;
|
||||
g_autoptr(GFile) mount_root = NULL;
|
||||
g_autoptr (GFile) mount_root = NULL;
|
||||
g_autofree gchar *mount_root_path = NULL;
|
||||
glnx_autofd int mount_root_dfd = -1;
|
||||
struct stat mount_root_stbuf;
|
||||
glnx_autofd int repos_dfd = -1;
|
||||
gsize i;
|
||||
g_autoptr(GHashTable) repo_to_refs = NULL; /* (element-type UriAndKeyring GHashTable) */
|
||||
GHashTable *supported_ref_to_checksum; /* (element-type OstreeCollectionRef utf8) */
|
||||
g_autoptr (GHashTable) repo_to_refs = NULL; /* (element-type UriAndKeyring GHashTable) */
|
||||
GHashTable *supported_ref_to_checksum; /* (element-type OstreeCollectionRef utf8) */
|
||||
GHashTableIter iter;
|
||||
g_autoptr(GError) local_error = NULL;
|
||||
g_autoptr (GError) local_error = NULL;
|
||||
|
||||
mount_name = g_mount_get_name (mount);
|
||||
|
||||
@ -350,18 +332,19 @@ ostree_repo_finder_mount_resolve_async (OstreeRepoFinder *finde
|
||||
|
||||
if (!glnx_opendirat (AT_FDCWD, mount_root_path, TRUE, &mount_root_dfd, &local_error))
|
||||
{
|
||||
g_debug ("Ignoring mount ‘%s’ as ‘%s’ directory can’t be opened: %s",
|
||||
mount_name, mount_root_path, local_error->message);
|
||||
g_debug ("Ignoring mount ‘%s’ as ‘%s’ directory can’t be opened: %s", mount_name,
|
||||
mount_root_path, local_error->message);
|
||||
continue;
|
||||
}
|
||||
|
||||
#if GLIB_CHECK_VERSION(2, 55, 0)
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS /* remove once GLIB_VERSION_MAX_ALLOWED ≥ 2.56 */
|
||||
g_autoptr(GUnixMountEntry) mount_entry = g_unix_mount_at (mount_root_path, NULL);
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS /* remove once GLIB_VERSION_MAX_ALLOWED ≥ 2.56 */
|
||||
g_autoptr (GUnixMountEntry) mount_entry
|
||||
= g_unix_mount_at (mount_root_path, NULL);
|
||||
|
||||
if (mount_entry != NULL &&
|
||||
(g_unix_is_system_fs_type (g_unix_mount_get_fs_type (mount_entry)) ||
|
||||
g_unix_is_system_device_path (g_unix_mount_get_device_path (mount_entry))))
|
||||
if (mount_entry != NULL
|
||||
&& (g_unix_is_system_fs_type (g_unix_mount_get_fs_type (mount_entry))
|
||||
|| g_unix_is_system_device_path (g_unix_mount_get_device_path (mount_entry))))
|
||||
{
|
||||
g_debug ("Ignoring mount ‘%s’ as its file system type (%s) or device "
|
||||
"path (%s) indicate it’s a system mount.",
|
||||
@ -369,16 +352,16 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS /* remove once GLIB_VERSION_MAX_ALLOWED ≥ 2.
|
||||
g_unix_mount_get_device_path (mount_entry));
|
||||
continue;
|
||||
}
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
#endif /* GLib 2.56.0 */
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
#endif /* GLib 2.56.0 */
|
||||
|
||||
/* stat() the mount root so we can later check whether the resolved
|
||||
* repositories for individual refs are on the same device (to avoid the
|
||||
* symlinks for them pointing outside the mount root). */
|
||||
if (!glnx_fstat (mount_root_dfd, &mount_root_stbuf, &local_error))
|
||||
{
|
||||
g_debug ("Ignoring mount ‘%s’ as querying info of ‘%s’ failed: %s",
|
||||
mount_name, mount_root_path, local_error->message);
|
||||
g_debug ("Ignoring mount ‘%s’ as querying info of ‘%s’ failed: %s", mount_name,
|
||||
mount_root_path, local_error->message);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -389,13 +372,13 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
|
||||
/* List all the repositories in the repos.d directory. */
|
||||
/* (element-type GHashTable (element-type OstreeCollectionRef utf8)) */
|
||||
g_autoptr(GArray) repos_refs = g_array_new (FALSE, TRUE, sizeof (RepoAndRefs));
|
||||
g_array_set_clear_func (repos_refs, (GDestroyNotify) repo_and_refs_clear);
|
||||
g_autoptr (GArray) repos_refs = g_array_new (FALSE, TRUE, sizeof (RepoAndRefs));
|
||||
g_array_set_clear_func (repos_refs, (GDestroyNotify)repo_and_refs_clear);
|
||||
|
||||
GLnxDirFdIterator repos_iter;
|
||||
|
||||
if (repos_dfd >= 0 &&
|
||||
!glnx_dirfd_iterator_init_at (repos_dfd, ".", TRUE, &repos_iter, &local_error))
|
||||
if (repos_dfd >= 0
|
||||
&& !glnx_dirfd_iterator_init_at (repos_dfd, ".", TRUE, &repos_iter, &local_error))
|
||||
{
|
||||
g_debug ("Error iterating over ‘%s/.ostree/repos.d’ directory in mount ‘%s’: %s",
|
||||
mount_root_path, mount_name, local_error->message);
|
||||
@ -408,7 +391,8 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
{
|
||||
struct dirent *repo_dent;
|
||||
|
||||
if (!glnx_dirfd_iterator_next_dent (&repos_iter, &repo_dent, cancellable, &local_error))
|
||||
if (!glnx_dirfd_iterator_next_dent (&repos_iter, &repo_dent, cancellable,
|
||||
&local_error))
|
||||
{
|
||||
g_debug ("Error iterating over ‘%s/.ostree/repos.d’ directory in mount ‘%s’: %s",
|
||||
mount_root_path, mount_name, local_error->message);
|
||||
@ -421,8 +405,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
break;
|
||||
|
||||
/* Grab the set of collection–refs from the repo if we can open it. */
|
||||
scan_and_add_repo (repos_dfd, repo_dent->d_name, TRUE,
|
||||
mount_name, &mount_root_stbuf,
|
||||
scan_and_add_repo (repos_dfd, repo_dent->d_name, TRUE, mount_name, &mount_root_stbuf,
|
||||
parent_repo, repos_refs, cancellable);
|
||||
}
|
||||
}
|
||||
@ -433,30 +416,29 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
/* Also check the well-known special-case directories in the mount.
|
||||
* Add them after sorting, so they’re always last.
|
||||
* NOTE: If you change these, update the man page. */
|
||||
const gchar * const well_known_repos[] =
|
||||
{
|
||||
".ostree/repo",
|
||||
"ostree/repo",
|
||||
"var/lib/flatpak/repo",
|
||||
};
|
||||
const gchar *const well_known_repos[] = {
|
||||
".ostree/repo",
|
||||
"ostree/repo",
|
||||
"var/lib/flatpak/repo",
|
||||
};
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (well_known_repos); i++)
|
||||
scan_and_add_repo (mount_root_dfd, well_known_repos[i], FALSE,
|
||||
mount_name, &mount_root_stbuf,
|
||||
parent_repo, repos_refs, cancellable);
|
||||
scan_and_add_repo (mount_root_dfd, well_known_repos[i], FALSE, mount_name,
|
||||
&mount_root_stbuf, parent_repo, repos_refs, cancellable);
|
||||
|
||||
/* Check whether a subdirectory exists for any of the @refs we’re looking
|
||||
* for. If so, and it’s a symbolic link, dereference it so multiple links
|
||||
* to the same repository (containing multiple refs) are coalesced.
|
||||
* Otherwise, include it as a result by itself. */
|
||||
repo_to_refs = g_hash_table_new_full (uri_and_keyring_hash, uri_and_keyring_equal,
|
||||
(GDestroyNotify) uri_and_keyring_free, (GDestroyNotify) g_hash_table_unref);
|
||||
(GDestroyNotify)uri_and_keyring_free,
|
||||
(GDestroyNotify)g_hash_table_unref);
|
||||
|
||||
for (i = 0; refs[i] != NULL; i++)
|
||||
{
|
||||
const OstreeCollectionRef *ref = refs[i];
|
||||
g_autofree gchar *resolved_repo_uri = NULL;
|
||||
g_autoptr(UriAndKeyring) resolved_repo = NULL;
|
||||
g_autoptr (UriAndKeyring) resolved_repo = NULL;
|
||||
|
||||
for (gsize j = 0; j < repos_refs->len; j++)
|
||||
{
|
||||
@ -464,27 +446,29 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
OstreeRepo *repo = repo_and_refs->repo;
|
||||
GHashTable *repo_refs = repo_and_refs->refs;
|
||||
g_autofree char *repo_path = g_file_get_path (ostree_repo_get_path (repo));
|
||||
g_autoptr(OstreeRemote) keyring_remote = NULL;
|
||||
g_autoptr (OstreeRemote) keyring_remote = NULL;
|
||||
|
||||
const gchar *checksum = g_hash_table_lookup (repo_refs, ref);
|
||||
|
||||
if (checksum == NULL)
|
||||
{
|
||||
g_debug ("Ignoring repository ‘%s’ when looking for ref (%s, %s) on mount ‘%s’ as it doesn’t contain the ref.",
|
||||
g_debug ("Ignoring repository ‘%s’ when looking for ref (%s, %s) on mount ‘%s’ "
|
||||
"as it doesn’t contain the ref.",
|
||||
repo_path, ref->collection_id, ref->ref_name, mount_name);
|
||||
g_clear_error (&local_error);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Finally, look up the GPG keyring for this ref. */
|
||||
keyring_remote = ostree_repo_resolve_keyring_for_collection (parent_repo,
|
||||
ref->collection_id,
|
||||
cancellable, &local_error);
|
||||
keyring_remote = ostree_repo_resolve_keyring_for_collection (
|
||||
parent_repo, ref->collection_id, cancellable, &local_error);
|
||||
|
||||
if (keyring_remote == NULL)
|
||||
{
|
||||
g_debug ("Ignoring repository ‘%s’ when looking for ref (%s, %s) on mount ‘%s’ due to missing keyring: %s",
|
||||
repo_path, ref->collection_id, ref->ref_name, mount_name, local_error->message);
|
||||
g_debug ("Ignoring repository ‘%s’ when looking for ref (%s, %s) on mount ‘%s’ "
|
||||
"due to missing keyring: %s",
|
||||
repo_path, ref->collection_id, ref->ref_name, mount_name,
|
||||
local_error->message);
|
||||
g_clear_error (&local_error);
|
||||
continue;
|
||||
}
|
||||
@ -495,7 +479,8 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
* to deduplicate the results. */
|
||||
g_autofree char *canonical_repo_path = realpath (repo_path, NULL);
|
||||
resolved_repo_uri = g_strconcat ("file://", canonical_repo_path, NULL);
|
||||
g_debug ("Resolved ref (%s, %s) on mount ‘%s’ to repo URI ‘%s’ with keyring ‘%s’ from remote ‘%s’.",
|
||||
g_debug ("Resolved ref (%s, %s) on mount ‘%s’ to repo URI ‘%s’ with keyring ‘%s’ "
|
||||
"from remote ‘%s’.",
|
||||
ref->collection_id, ref->ref_name, mount_name, resolved_repo_uri,
|
||||
keyring_remote->keyring, keyring_remote->name);
|
||||
|
||||
@ -505,13 +490,13 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
|
||||
if (supported_ref_to_checksum == NULL)
|
||||
{
|
||||
supported_ref_to_checksum = g_hash_table_new_full (ostree_collection_ref_hash,
|
||||
ostree_collection_ref_equal,
|
||||
NULL, g_free);
|
||||
g_hash_table_insert (repo_to_refs, g_steal_pointer (&resolved_repo), supported_ref_to_checksum /* transfer */);
|
||||
supported_ref_to_checksum = g_hash_table_new_full (
|
||||
ostree_collection_ref_hash, ostree_collection_ref_equal, NULL, g_free);
|
||||
g_hash_table_insert (repo_to_refs, g_steal_pointer (&resolved_repo),
|
||||
supported_ref_to_checksum /* transfer */);
|
||||
}
|
||||
|
||||
g_hash_table_insert (supported_ref_to_checksum, (gpointer) ref, g_strdup (checksum));
|
||||
g_hash_table_insert (supported_ref_to_checksum, (gpointer)ref, g_strdup (checksum));
|
||||
|
||||
/* We’ve found a result for this collection–ref. No point in checking
|
||||
* the other repos on the mount, since pulling in parallel from them won’t help. */
|
||||
@ -523,9 +508,10 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
g_hash_table_iter_init (&iter, repo_to_refs);
|
||||
|
||||
UriAndKeyring *repo;
|
||||
while (g_hash_table_iter_next (&iter, (gpointer *) &repo, (gpointer *) &supported_ref_to_checksum))
|
||||
while (
|
||||
g_hash_table_iter_next (&iter, (gpointer *)&repo, (gpointer *)&supported_ref_to_checksum))
|
||||
{
|
||||
g_autoptr(OstreeRemote) remote = NULL;
|
||||
g_autoptr (OstreeRemote) remote = NULL;
|
||||
|
||||
/* Build an #OstreeRemote. Use the escaped URI, since remote->name
|
||||
* is used in file paths, so needs to not contain special characters. */
|
||||
@ -544,19 +530,20 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
* the code in ostree_repo_pull_from_remotes_async() will be able to
|
||||
* check it just as quickly as we can here; so don’t duplicate the
|
||||
* code. */
|
||||
g_ptr_array_add (results, ostree_repo_finder_result_new (remote, finder, priority, supported_ref_to_checksum, NULL, 0));
|
||||
g_ptr_array_add (results,
|
||||
ostree_repo_finder_result_new (remote, finder, priority,
|
||||
supported_ref_to_checksum, NULL, 0));
|
||||
}
|
||||
}
|
||||
|
||||
g_ptr_array_sort (results, results_compare_cb);
|
||||
|
||||
g_task_return_pointer (task, g_steal_pointer (&results), (GDestroyNotify) g_ptr_array_unref);
|
||||
g_task_return_pointer (task, g_steal_pointer (&results), (GDestroyNotify)g_ptr_array_unref);
|
||||
}
|
||||
|
||||
static GPtrArray *
|
||||
ostree_repo_finder_mount_resolve_finish (OstreeRepoFinder *self,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
ostree_repo_finder_mount_resolve_finish (OstreeRepoFinder *self, GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (g_task_is_valid (result, self), NULL);
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
@ -585,14 +572,12 @@ typedef enum
|
||||
} OstreeRepoFinderMountProperty;
|
||||
|
||||
static void
|
||||
ostree_repo_finder_mount_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
ostree_repo_finder_mount_get_property (GObject *object, guint property_id, GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
OstreeRepoFinderMount *self = OSTREE_REPO_FINDER_MOUNT (object);
|
||||
|
||||
switch ((OstreeRepoFinderMountProperty) property_id)
|
||||
switch ((OstreeRepoFinderMountProperty)property_id)
|
||||
{
|
||||
case PROP_MONITOR:
|
||||
g_value_set_object (value, self->monitor);
|
||||
@ -603,14 +588,12 @@ ostree_repo_finder_mount_get_property (GObject *object,
|
||||
}
|
||||
|
||||
static void
|
||||
ostree_repo_finder_mount_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
ostree_repo_finder_mount_set_property (GObject *object, guint property_id, const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
OstreeRepoFinderMount *self = OSTREE_REPO_FINDER_MOUNT (object);
|
||||
|
||||
switch ((OstreeRepoFinderMountProperty) property_id)
|
||||
switch ((OstreeRepoFinderMountProperty)property_id)
|
||||
{
|
||||
case PROP_MONITOR:
|
||||
/* Construct-only. */
|
||||
@ -649,16 +632,14 @@ ostree_repo_finder_mount_class_init (OstreeRepoFinderMountClass *klass)
|
||||
*
|
||||
* Since: 2018.6
|
||||
*/
|
||||
g_object_class_install_property (object_class, PROP_MONITOR,
|
||||
g_param_spec_object ("monitor",
|
||||
"Volume Monitor",
|
||||
"Volume monitor to use "
|
||||
"to look up mounted "
|
||||
"volumes when queried.",
|
||||
G_TYPE_VOLUME_MONITOR,
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property (
|
||||
object_class, PROP_MONITOR,
|
||||
g_param_spec_object ("monitor", "Volume Monitor",
|
||||
"Volume monitor to use "
|
||||
"to look up mounted "
|
||||
"volumes when queried.",
|
||||
G_TYPE_VOLUME_MONITOR,
|
||||
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -685,7 +666,5 @@ ostree_repo_finder_mount_new (GVolumeMonitor *monitor)
|
||||
{
|
||||
g_return_val_if_fail (monitor == NULL || G_IS_VOLUME_MONITOR (monitor), NULL);
|
||||
|
||||
return g_object_new (OSTREE_TYPE_REPO_FINDER_MOUNT,
|
||||
"monitor", monitor,
|
||||
NULL);
|
||||
return g_object_new (OSTREE_TYPE_REPO_FINDER_MOUNT, "monitor", monitor, NULL);
|
||||
}
|
||||
|
@ -23,8 +23,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "ostree-repo-finder.h"
|
||||
#include "ostree-types.h"
|
||||
@ -35,17 +35,30 @@ G_BEGIN_DECLS
|
||||
|
||||
/* Manually expanded version of the following, omitting autoptr support (for GLib < 2.44):
|
||||
_OSTREE_PUBLIC
|
||||
G_DECLARE_FINAL_TYPE (OstreeRepoFinderMount, ostree_repo_finder_mount, OSTREE, REPO_FINDER_MOUNT, GObject) */
|
||||
G_DECLARE_FINAL_TYPE (OstreeRepoFinderMount, ostree_repo_finder_mount, OSTREE, REPO_FINDER_MOUNT,
|
||||
GObject) */
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
GType ostree_repo_finder_mount_get_type (void);
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
typedef struct _OstreeRepoFinderMount OstreeRepoFinderMount;
|
||||
typedef struct { GObjectClass parent_class; } OstreeRepoFinderMountClass;
|
||||
typedef struct
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
} OstreeRepoFinderMountClass;
|
||||
|
||||
static inline OstreeRepoFinderMount *OSTREE_REPO_FINDER_MOUNT (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_repo_finder_mount_get_type (), OstreeRepoFinderMount); }
|
||||
static inline gboolean OSTREE_IS_REPO_FINDER_MOUNT (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_repo_finder_mount_get_type ()); }
|
||||
static inline OstreeRepoFinderMount *
|
||||
OSTREE_REPO_FINDER_MOUNT (gpointer ptr)
|
||||
{
|
||||
return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_repo_finder_mount_get_type (),
|
||||
OstreeRepoFinderMount);
|
||||
}
|
||||
static inline gboolean
|
||||
OSTREE_IS_REPO_FINDER_MOUNT (gpointer ptr)
|
||||
{
|
||||
return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_repo_finder_mount_get_type ());
|
||||
}
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
|
@ -24,16 +24,16 @@
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
#include <libglnx.h>
|
||||
|
||||
#include "ostree-autocleanups.h"
|
||||
#include "ostree-remote-private.h"
|
||||
#include "ostree-repo.h"
|
||||
#include "ostree-repo-private.h"
|
||||
#include "ostree-repo-finder.h"
|
||||
#include "ostree-repo-finder-override.h"
|
||||
#include "ostree-repo-finder.h"
|
||||
#include "ostree-repo-private.h"
|
||||
#include "ostree-repo.h"
|
||||
|
||||
/**
|
||||
* SECTION:ostree-repo-finder-override
|
||||
@ -68,26 +68,25 @@ struct _OstreeRepoFinderOverride
|
||||
{
|
||||
GObject parent_instance;
|
||||
|
||||
GPtrArray *override_uris; /* (owned) (element-type utf8) */
|
||||
GPtrArray *override_uris; /* (owned) (element-type utf8) */
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (OstreeRepoFinderOverride, ostree_repo_finder_override, G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_REPO_FINDER, ostree_repo_finder_override_iface_init))
|
||||
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_REPO_FINDER,
|
||||
ostree_repo_finder_override_iface_init))
|
||||
|
||||
static gint
|
||||
results_compare_cb (gconstpointer a,
|
||||
gconstpointer b)
|
||||
results_compare_cb (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
const OstreeRepoFinderResult *result_a = *((const OstreeRepoFinderResult **) a);
|
||||
const OstreeRepoFinderResult *result_b = *((const OstreeRepoFinderResult **) b);
|
||||
const OstreeRepoFinderResult *result_a = *((const OstreeRepoFinderResult **)a);
|
||||
const OstreeRepoFinderResult *result_b = *((const OstreeRepoFinderResult **)b);
|
||||
|
||||
return ostree_repo_finder_result_compare (result_a, result_b);
|
||||
}
|
||||
|
||||
/* This must return a valid remote name (suitable for use in a refspec). */
|
||||
static gchar *
|
||||
uri_and_keyring_to_name (const gchar *uri,
|
||||
const gchar *keyring)
|
||||
uri_and_keyring_to_name (const gchar *uri, const gchar *keyring)
|
||||
{
|
||||
g_autofree gchar *escaped_uri = g_uri_escape_string (uri, NULL, FALSE);
|
||||
g_autofree gchar *escaped_keyring = g_uri_escape_string (keyring, NULL, FALSE);
|
||||
@ -109,22 +108,17 @@ uri_and_keyring_to_name (const gchar *uri,
|
||||
/* Version of ostree_repo_remote_list_collection_refs() which takes an
|
||||
* #OstreeRemote. */
|
||||
static gboolean
|
||||
repo_remote_list_collection_refs (OstreeRepo *repo,
|
||||
const gchar *remote_uri,
|
||||
GHashTable **out_all_refs,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
repo_remote_list_collection_refs (OstreeRepo *repo, const gchar *remote_uri,
|
||||
GHashTable **out_all_refs, GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
g_autofree gchar *name = uri_and_keyring_to_name (remote_uri, "");
|
||||
g_autoptr(OstreeRemote) remote = ostree_remote_new (name);
|
||||
g_autoptr (OstreeRemote) remote = ostree_remote_new (name);
|
||||
g_key_file_set_string (remote->options, remote->group, "url", remote_uri);
|
||||
|
||||
gboolean remote_already_existed = _ostree_repo_add_remote (repo, remote);
|
||||
gboolean success = ostree_repo_remote_list_collection_refs (repo,
|
||||
remote->name,
|
||||
out_all_refs,
|
||||
cancellable,
|
||||
error);
|
||||
gboolean success = ostree_repo_remote_list_collection_refs (repo, remote->name, out_all_refs,
|
||||
cancellable, error);
|
||||
|
||||
if (!remote_already_existed)
|
||||
_ostree_repo_remove_remote (repo, remote);
|
||||
@ -133,77 +127,73 @@ repo_remote_list_collection_refs (OstreeRepo *repo,
|
||||
}
|
||||
|
||||
static void
|
||||
ostree_repo_finder_override_resolve_async (OstreeRepoFinder *finder,
|
||||
const OstreeCollectionRef * const *refs,
|
||||
OstreeRepo *parent_repo,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
ostree_repo_finder_override_resolve_async (OstreeRepoFinder *finder,
|
||||
const OstreeCollectionRef *const *refs,
|
||||
OstreeRepo *parent_repo, GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback, gpointer user_data)
|
||||
{
|
||||
OstreeRepoFinderOverride *self = OSTREE_REPO_FINDER_OVERRIDE (finder);
|
||||
g_autoptr(GTask) task = NULL;
|
||||
g_autoptr(GPtrArray) results = NULL;
|
||||
const gint priority = 20; /* arbitrarily chosen; higher priority than the others */
|
||||
g_autoptr (GTask) task = NULL;
|
||||
g_autoptr (GPtrArray) results = NULL;
|
||||
const gint priority = 20; /* arbitrarily chosen; higher priority than the others */
|
||||
gsize i, j;
|
||||
g_autoptr(GHashTable) repo_remote_to_refs = NULL; /* (element-type OstreeRemote GHashTable) */
|
||||
GHashTable *supported_ref_to_checksum; /* (element-type OstreeCollectionRef utf8) */
|
||||
g_autoptr (GHashTable) repo_remote_to_refs = NULL; /* (element-type OstreeRemote GHashTable) */
|
||||
GHashTable *supported_ref_to_checksum; /* (element-type OstreeCollectionRef utf8) */
|
||||
GHashTableIter iter;
|
||||
const gchar *remote_uri;
|
||||
|
||||
task = g_task_new (finder, cancellable, callback, user_data);
|
||||
g_task_set_source_tag (task, ostree_repo_finder_override_resolve_async);
|
||||
results = g_ptr_array_new_with_free_func ((GDestroyNotify) ostree_repo_finder_result_free);
|
||||
repo_remote_to_refs = g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
||||
(GDestroyNotify) ostree_remote_unref,
|
||||
(GDestroyNotify) g_hash_table_unref);
|
||||
results = g_ptr_array_new_with_free_func ((GDestroyNotify)ostree_repo_finder_result_free);
|
||||
repo_remote_to_refs
|
||||
= g_hash_table_new_full (g_direct_hash, g_direct_equal, (GDestroyNotify)ostree_remote_unref,
|
||||
(GDestroyNotify)g_hash_table_unref);
|
||||
|
||||
g_debug ("%s: Checking %u overrides", G_STRFUNC, self->override_uris->len);
|
||||
|
||||
for (i = 0; i < self->override_uris->len; i++)
|
||||
{
|
||||
g_autoptr(GError) local_error = NULL;
|
||||
g_autoptr(GHashTable) remote_refs = NULL; /* (element-type OstreeCollectionRef utf8) */
|
||||
g_autoptr (GError) local_error = NULL;
|
||||
g_autoptr (GHashTable) remote_refs = NULL; /* (element-type OstreeCollectionRef utf8) */
|
||||
const gchar *checksum;
|
||||
gboolean resolved_a_ref = FALSE;
|
||||
|
||||
remote_uri = self->override_uris->pdata[i];
|
||||
|
||||
if (!repo_remote_list_collection_refs (parent_repo, remote_uri,
|
||||
&remote_refs, cancellable,
|
||||
if (!repo_remote_list_collection_refs (parent_repo, remote_uri, &remote_refs, cancellable,
|
||||
&local_error))
|
||||
{
|
||||
g_debug ("Ignoring remote ‘%s’ due to error loading its refs: %s",
|
||||
remote_uri, local_error->message);
|
||||
g_debug ("Ignoring remote ‘%s’ due to error loading its refs: %s", remote_uri,
|
||||
local_error->message);
|
||||
g_clear_error (&local_error);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (j = 0; refs[j] != NULL; j++)
|
||||
{
|
||||
g_autoptr(OstreeRemote) keyring_remote = NULL;
|
||||
g_autoptr (OstreeRemote) keyring_remote = NULL;
|
||||
|
||||
/* Look up the GPG keyring for this ref. */
|
||||
keyring_remote = ostree_repo_resolve_keyring_for_collection (parent_repo,
|
||||
refs[j]->collection_id,
|
||||
cancellable, &local_error);
|
||||
keyring_remote = ostree_repo_resolve_keyring_for_collection (
|
||||
parent_repo, refs[j]->collection_id, cancellable, &local_error);
|
||||
|
||||
if (keyring_remote == NULL)
|
||||
{
|
||||
g_debug ("Ignoring ref (%s, %s) due to missing keyring: %s",
|
||||
refs[j]->collection_id, refs[j]->ref_name, local_error->message);
|
||||
g_debug ("Ignoring ref (%s, %s) due to missing keyring: %s", refs[j]->collection_id,
|
||||
refs[j]->ref_name, local_error->message);
|
||||
g_clear_error (&local_error);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (g_hash_table_lookup_extended (remote_refs, refs[j], NULL, (gpointer *) &checksum))
|
||||
if (g_hash_table_lookup_extended (remote_refs, refs[j], NULL, (gpointer *)&checksum))
|
||||
{
|
||||
g_autoptr(OstreeRemote) remote = NULL;
|
||||
g_autoptr (OstreeRemote) remote = NULL;
|
||||
|
||||
/* The requested ref is listed in the refs for this remote. Add
|
||||
* the remote to the results, and the ref to its
|
||||
* @supported_ref_to_checksum. */
|
||||
g_debug ("Resolved ref (%s, %s) to remote ‘%s’.",
|
||||
refs[j]->collection_id, refs[j]->ref_name, remote_uri);
|
||||
g_debug ("Resolved ref (%s, %s) to remote ‘%s’.", refs[j]->collection_id,
|
||||
refs[j]->ref_name, remote_uri);
|
||||
resolved_a_ref = TRUE;
|
||||
|
||||
/* Build an #OstreeRemote. Use the escaped URI, since remote->name
|
||||
@ -220,14 +210,14 @@ ostree_repo_finder_override_resolve_async (OstreeRepoFinder *fi
|
||||
|
||||
if (supported_ref_to_checksum == NULL)
|
||||
{
|
||||
supported_ref_to_checksum = g_hash_table_new_full (ostree_collection_ref_hash,
|
||||
ostree_collection_ref_equal,
|
||||
NULL, g_free);
|
||||
g_hash_table_insert (repo_remote_to_refs, ostree_remote_ref (remote), supported_ref_to_checksum /* transfer */);
|
||||
supported_ref_to_checksum = g_hash_table_new_full (
|
||||
ostree_collection_ref_hash, ostree_collection_ref_equal, NULL, g_free);
|
||||
g_hash_table_insert (repo_remote_to_refs, ostree_remote_ref (remote),
|
||||
supported_ref_to_checksum /* transfer */);
|
||||
}
|
||||
|
||||
g_hash_table_insert (supported_ref_to_checksum,
|
||||
(gpointer) refs[j], g_strdup (checksum));
|
||||
g_hash_table_insert (supported_ref_to_checksum, (gpointer)refs[j],
|
||||
g_strdup (checksum));
|
||||
}
|
||||
}
|
||||
|
||||
@ -240,18 +230,19 @@ ostree_repo_finder_override_resolve_async (OstreeRepoFinder *fi
|
||||
g_hash_table_iter_init (&iter, repo_remote_to_refs);
|
||||
|
||||
OstreeRemote *remote;
|
||||
while (g_hash_table_iter_next (&iter, (gpointer *) &remote, (gpointer *) &supported_ref_to_checksum))
|
||||
g_ptr_array_add (results, ostree_repo_finder_result_new (remote, finder, priority, supported_ref_to_checksum, NULL, 0));
|
||||
while (
|
||||
g_hash_table_iter_next (&iter, (gpointer *)&remote, (gpointer *)&supported_ref_to_checksum))
|
||||
g_ptr_array_add (results, ostree_repo_finder_result_new (remote, finder, priority,
|
||||
supported_ref_to_checksum, NULL, 0));
|
||||
|
||||
g_ptr_array_sort (results, results_compare_cb);
|
||||
|
||||
g_task_return_pointer (task, g_steal_pointer (&results), (GDestroyNotify) g_ptr_array_unref);
|
||||
g_task_return_pointer (task, g_steal_pointer (&results), (GDestroyNotify)g_ptr_array_unref);
|
||||
}
|
||||
|
||||
static GPtrArray *
|
||||
ostree_repo_finder_override_resolve_finish (OstreeRepoFinder *finder,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
ostree_repo_finder_override_resolve_finish (OstreeRepoFinder *finder, GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (g_task_is_valid (result, finder), NULL);
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
@ -260,7 +251,7 @@ ostree_repo_finder_override_resolve_finish (OstreeRepoFinder *finder,
|
||||
static void
|
||||
ostree_repo_finder_override_init (OstreeRepoFinderOverride *self)
|
||||
{
|
||||
self->override_uris = g_ptr_array_new_with_free_func ((GDestroyNotify) g_free);
|
||||
self->override_uris = g_ptr_array_new_with_free_func ((GDestroyNotify)g_free);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -312,8 +303,7 @@ ostree_repo_finder_override_new (void)
|
||||
* Since: 2018.6
|
||||
*/
|
||||
void
|
||||
ostree_repo_finder_override_add_uri (OstreeRepoFinderOverride *self,
|
||||
const gchar *uri)
|
||||
ostree_repo_finder_override_add_uri (OstreeRepoFinderOverride *self, const gchar *uri)
|
||||
{
|
||||
g_return_if_fail (OSTREE_IS_REPO_FINDER_OVERRIDE (self));
|
||||
g_return_if_fail (uri != NULL);
|
||||
|
@ -23,8 +23,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "ostree-repo-finder.h"
|
||||
#include "ostree-types.h"
|
||||
@ -35,24 +35,36 @@ G_BEGIN_DECLS
|
||||
|
||||
/* Manually expanded version of the following, omitting autoptr support (for GLib < 2.44):
|
||||
_OSTREE_PUBLIC
|
||||
G_DECLARE_FINAL_TYPE (OstreeRepoFinderOverride, ostree_repo_finder_override, OSTREE, REPO_FINDER_OVERRIDE, GObject) */
|
||||
G_DECLARE_FINAL_TYPE (OstreeRepoFinderOverride, ostree_repo_finder_override, OSTREE,
|
||||
REPO_FINDER_OVERRIDE, GObject) */
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
GType ostree_repo_finder_override_get_type (void);
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
typedef struct _OstreeRepoFinderOverride OstreeRepoFinderOverride;
|
||||
typedef struct { GObjectClass parent_class; } OstreeRepoFinderOverrideClass;
|
||||
typedef struct
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
} OstreeRepoFinderOverrideClass;
|
||||
|
||||
static inline OstreeRepoFinderOverride *OSTREE_REPO_FINDER_OVERRIDE (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_repo_finder_override_get_type (), OstreeRepoFinderOverride); }
|
||||
static inline gboolean OSTREE_IS_REPO_FINDER_OVERRIDE (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_repo_finder_override_get_type ()); }
|
||||
static inline OstreeRepoFinderOverride *
|
||||
OSTREE_REPO_FINDER_OVERRIDE (gpointer ptr)
|
||||
{
|
||||
return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_repo_finder_override_get_type (),
|
||||
OstreeRepoFinderOverride);
|
||||
}
|
||||
static inline gboolean
|
||||
OSTREE_IS_REPO_FINDER_OVERRIDE (gpointer ptr)
|
||||
{
|
||||
return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_repo_finder_override_get_type ());
|
||||
}
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeRepoFinderOverride *ostree_repo_finder_override_new (void);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_repo_finder_override_add_uri (OstreeRepoFinderOverride *self,
|
||||
const gchar *uri);
|
||||
void ostree_repo_finder_override_add_uri (OstreeRepoFinderOverride *self, const gchar *uri);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -23,8 +23,8 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
#include <libglnx.h>
|
||||
|
||||
#include "ostree-autocleanups.h"
|
||||
@ -48,15 +48,14 @@ ostree_repo_finder_default_init (OstreeRepoFinderInterface *iface)
|
||||
static gboolean
|
||||
is_valid_collection_ref (const OstreeCollectionRef *ref)
|
||||
{
|
||||
return (ref != NULL &&
|
||||
ostree_validate_rev (ref->ref_name, NULL) &&
|
||||
ostree_validate_collection_id (ref->collection_id, NULL));
|
||||
return (ref != NULL && ostree_validate_rev (ref->ref_name, NULL)
|
||||
&& ostree_validate_collection_id (ref->collection_id, NULL));
|
||||
}
|
||||
|
||||
/* Validate @refs is non-%NULL, non-empty, and contains only valid collection
|
||||
* and ref names. */
|
||||
static gboolean
|
||||
is_valid_collection_ref_array (const OstreeCollectionRef * const *refs)
|
||||
is_valid_collection_ref_array (const OstreeCollectionRef *const *refs)
|
||||
{
|
||||
gsize i;
|
||||
|
||||
@ -86,7 +85,7 @@ is_valid_collection_ref_map (GHashTable *ref_to_checksum)
|
||||
|
||||
g_hash_table_iter_init (&iter, ref_to_checksum);
|
||||
|
||||
while (g_hash_table_iter_next (&iter, (gpointer *) &ref, (gpointer *) &checksum))
|
||||
while (g_hash_table_iter_next (&iter, (gpointer *)&ref, (gpointer *)&checksum))
|
||||
{
|
||||
g_assert (ref != NULL);
|
||||
g_assert (checksum != NULL);
|
||||
@ -100,9 +99,7 @@ is_valid_collection_ref_map (GHashTable *ref_to_checksum)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void resolve_cb (GObject *obj,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data);
|
||||
static void resolve_cb (GObject *obj, GAsyncResult *result, gpointer user_data);
|
||||
|
||||
/**
|
||||
* ostree_repo_finder_resolve_async:
|
||||
@ -140,15 +137,14 @@ static void resolve_cb (GObject *obj,
|
||||
* Since: 2018.6
|
||||
*/
|
||||
void
|
||||
ostree_repo_finder_resolve_async (OstreeRepoFinder *self,
|
||||
const OstreeCollectionRef * const *refs,
|
||||
OstreeRepo *parent_repo,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
ostree_repo_finder_resolve_async (OstreeRepoFinder *self, const OstreeCollectionRef *const *refs,
|
||||
OstreeRepo *parent_repo, GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback, gpointer user_data)
|
||||
{
|
||||
g_autoptr(GTask) task = NULL;
|
||||
OstreeRepoFinder *finders[2] = { NULL, };
|
||||
g_autoptr (GTask) task = NULL;
|
||||
OstreeRepoFinder *finders[2] = {
|
||||
NULL,
|
||||
};
|
||||
|
||||
g_return_if_fail (OSTREE_IS_REPO_FINDER (self));
|
||||
g_return_if_fail (is_valid_collection_ref_array (refs));
|
||||
@ -160,18 +156,16 @@ ostree_repo_finder_resolve_async (OstreeRepoFinder *self,
|
||||
|
||||
finders[0] = self;
|
||||
|
||||
ostree_repo_finder_resolve_all_async (finders, refs, parent_repo, cancellable,
|
||||
resolve_cb, g_steal_pointer (&task));
|
||||
ostree_repo_finder_resolve_all_async (finders, refs, parent_repo, cancellable, resolve_cb,
|
||||
g_steal_pointer (&task));
|
||||
}
|
||||
|
||||
static void
|
||||
resolve_cb (GObject *obj,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
resolve_cb (GObject *obj, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
g_autoptr(GTask) task = NULL;
|
||||
g_autoptr(GPtrArray) results = NULL;
|
||||
g_autoptr(GError) local_error = NULL;
|
||||
g_autoptr (GTask) task = NULL;
|
||||
g_autoptr (GPtrArray) results = NULL;
|
||||
g_autoptr (GError) local_error = NULL;
|
||||
|
||||
task = G_TASK (user_data);
|
||||
|
||||
@ -182,7 +176,7 @@ resolve_cb (GObject *obj,
|
||||
if (local_error != NULL)
|
||||
g_task_return_error (task, g_steal_pointer (&local_error));
|
||||
else
|
||||
g_task_return_pointer (task, g_steal_pointer (&results), (GDestroyNotify) g_ptr_array_unref);
|
||||
g_task_return_pointer (task, g_steal_pointer (&results), (GDestroyNotify)g_ptr_array_unref);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -198,9 +192,7 @@ resolve_cb (GObject *obj,
|
||||
* Since: 2018.6
|
||||
*/
|
||||
GPtrArray *
|
||||
ostree_repo_finder_resolve_finish (OstreeRepoFinder *self,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
ostree_repo_finder_resolve_finish (OstreeRepoFinder *self, GAsyncResult *result, GError **error)
|
||||
{
|
||||
g_return_val_if_fail (OSTREE_IS_REPO_FINDER (self), NULL);
|
||||
g_return_val_if_fail (g_task_is_valid (result, self), NULL);
|
||||
@ -210,11 +202,10 @@ ostree_repo_finder_resolve_finish (OstreeRepoFinder *self,
|
||||
}
|
||||
|
||||
static gint
|
||||
sort_results_cb (gconstpointer a,
|
||||
gconstpointer b)
|
||||
sort_results_cb (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
const OstreeRepoFinderResult *result_a = *((const OstreeRepoFinderResult **) a);
|
||||
const OstreeRepoFinderResult *result_b = *((const OstreeRepoFinderResult **) b);
|
||||
const OstreeRepoFinderResult *result_a = *((const OstreeRepoFinderResult **)a);
|
||||
const OstreeRepoFinderResult *result_b = *((const OstreeRepoFinderResult **)b);
|
||||
|
||||
return ostree_repo_finder_result_compare (result_a, result_b);
|
||||
}
|
||||
@ -235,9 +226,7 @@ resolve_all_data_free (ResolveAllData *data)
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ResolveAllData, resolve_all_data_free)
|
||||
|
||||
static void resolve_all_cb (GObject *obj,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data);
|
||||
static void resolve_all_cb (GObject *obj, GAsyncResult *result, gpointer user_data);
|
||||
static void resolve_all_finished_one (GTask *task);
|
||||
|
||||
/**
|
||||
@ -256,18 +245,16 @@ static void resolve_all_finished_one (GTask *task);
|
||||
* Since: 2018.6
|
||||
*/
|
||||
void
|
||||
ostree_repo_finder_resolve_all_async (OstreeRepoFinder * const *finders,
|
||||
const OstreeCollectionRef * const *refs,
|
||||
OstreeRepo *parent_repo,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
ostree_repo_finder_resolve_all_async (OstreeRepoFinder *const *finders,
|
||||
const OstreeCollectionRef *const *refs,
|
||||
OstreeRepo *parent_repo, GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback, gpointer user_data)
|
||||
{
|
||||
g_autoptr(GTask) task = NULL;
|
||||
g_autoptr(ResolveAllData) data = NULL;
|
||||
g_autoptr (GTask) task = NULL;
|
||||
g_autoptr (ResolveAllData) data = NULL;
|
||||
gsize i;
|
||||
g_autoptr(GString) refs_str = NULL;
|
||||
g_autoptr(GString) finders_str = NULL;
|
||||
g_autoptr (GString) refs_str = NULL;
|
||||
g_autoptr (GString) finders_str = NULL;
|
||||
|
||||
g_return_if_fail (finders != NULL && finders[0] != NULL);
|
||||
g_return_if_fail (is_valid_collection_ref_array (refs));
|
||||
@ -279,8 +266,7 @@ ostree_repo_finder_resolve_all_async (OstreeRepoFinder * const *finders
|
||||
{
|
||||
if (i != 0)
|
||||
g_string_append (refs_str, ", ");
|
||||
g_string_append_printf (refs_str, "(%s, %s)",
|
||||
refs[i]->collection_id, refs[i]->ref_name);
|
||||
g_string_append_printf (refs_str, "(%s, %s)", refs[i]->collection_id, refs[i]->ref_name);
|
||||
}
|
||||
|
||||
finders_str = g_string_new ("");
|
||||
@ -291,16 +277,15 @@ ostree_repo_finder_resolve_all_async (OstreeRepoFinder * const *finders
|
||||
g_string_append (finders_str, g_type_name (G_TYPE_FROM_INSTANCE (finders[i])));
|
||||
}
|
||||
|
||||
g_debug ("%s: Resolving refs [%s] with finders [%s]", G_STRFUNC,
|
||||
refs_str->str, finders_str->str);
|
||||
g_debug ("%s: Resolving refs [%s] with finders [%s]", G_STRFUNC, refs_str->str, finders_str->str);
|
||||
|
||||
task = g_task_new (NULL, cancellable, callback, user_data);
|
||||
g_task_set_source_tag (task, ostree_repo_finder_resolve_all_async);
|
||||
|
||||
data = g_new0 (ResolveAllData, 1);
|
||||
data->n_finders_pending = 1; /* while setting up the loop */
|
||||
data->results = g_ptr_array_new_with_free_func ((GDestroyNotify) ostree_repo_finder_result_free);
|
||||
g_task_set_task_data (task, data, (GDestroyNotify) resolve_all_data_free);
|
||||
data->n_finders_pending = 1; /* while setting up the loop */
|
||||
data->results = g_ptr_array_new_with_free_func ((GDestroyNotify)ostree_repo_finder_result_free);
|
||||
g_task_set_task_data (task, data, (GDestroyNotify)resolve_all_data_free);
|
||||
|
||||
/* Start all the asynchronous queries in parallel. */
|
||||
for (i = 0; finders[i] != NULL; i++)
|
||||
@ -310,20 +295,20 @@ ostree_repo_finder_resolve_all_async (OstreeRepoFinder * const *finders
|
||||
|
||||
iface = OSTREE_REPO_FINDER_GET_IFACE (finder);
|
||||
g_assert (iface->resolve_async != NULL);
|
||||
iface->resolve_async (finder, refs, parent_repo, cancellable, resolve_all_cb, g_object_ref (task));
|
||||
iface->resolve_async (finder, refs, parent_repo, cancellable, resolve_all_cb,
|
||||
g_object_ref (task));
|
||||
data->n_finders_pending++;
|
||||
}
|
||||
|
||||
resolve_all_finished_one (task);
|
||||
data = NULL; /* passed to the GTask above */
|
||||
data = NULL; /* passed to the GTask above */
|
||||
}
|
||||
|
||||
/* Modifies both arrays in place. */
|
||||
static void
|
||||
array_concatenate_steal (GPtrArray *array,
|
||||
GPtrArray *to_concatenate) /* (transfer full) */
|
||||
array_concatenate_steal (GPtrArray *array, GPtrArray *to_concatenate) /* (transfer full) */
|
||||
{
|
||||
g_autoptr(GPtrArray) array_to_concatenate = to_concatenate;
|
||||
g_autoptr (GPtrArray) array_to_concatenate = to_concatenate;
|
||||
gsize i;
|
||||
|
||||
for (i = 0; i < array_to_concatenate->len; i++)
|
||||
@ -339,15 +324,13 @@ array_concatenate_steal (GPtrArray *array,
|
||||
}
|
||||
|
||||
static void
|
||||
resolve_all_cb (GObject *obj,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
resolve_all_cb (GObject *obj, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
OstreeRepoFinder *finder;
|
||||
OstreeRepoFinderInterface *iface;
|
||||
g_autoptr(GTask) task = NULL;
|
||||
g_autoptr(GPtrArray) results = NULL;
|
||||
g_autoptr(GError) local_error = NULL;
|
||||
g_autoptr (GTask) task = NULL;
|
||||
g_autoptr (GPtrArray) results = NULL;
|
||||
g_autoptr (GError) local_error = NULL;
|
||||
ResolveAllData *data;
|
||||
|
||||
finder = OSTREE_REPO_FINDER (obj);
|
||||
@ -379,7 +362,7 @@ resolve_all_finished_one (GTask *task)
|
||||
if (data->n_finders_pending == 0)
|
||||
{
|
||||
gsize i;
|
||||
g_autoptr(GString) results_str = NULL;
|
||||
g_autoptr (GString) results_str = NULL;
|
||||
|
||||
g_ptr_array_sort (data->results, sort_results_cb);
|
||||
|
||||
@ -397,7 +380,8 @@ resolve_all_finished_one (GTask *task)
|
||||
|
||||
g_debug ("%s: Finished, results: %s", G_STRFUNC, results_str->str);
|
||||
|
||||
g_task_return_pointer (task, g_steal_pointer (&data->results), (GDestroyNotify) g_ptr_array_unref);
|
||||
g_task_return_pointer (task, g_steal_pointer (&data->results),
|
||||
(GDestroyNotify)g_ptr_array_unref);
|
||||
}
|
||||
}
|
||||
|
||||
@ -413,8 +397,7 @@ resolve_all_finished_one (GTask *task)
|
||||
* Since: 2018.6
|
||||
*/
|
||||
GPtrArray *
|
||||
ostree_repo_finder_resolve_all_finish (GAsyncResult *result,
|
||||
GError **error)
|
||||
ostree_repo_finder_resolve_all_finish (GAsyncResult *result, GError **error)
|
||||
{
|
||||
g_return_val_if_fail (g_task_is_valid (result, NULL), NULL);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||
@ -448,14 +431,11 @@ G_DEFINE_BOXED_TYPE (OstreeRepoFinderResult, ostree_repo_finder_result,
|
||||
* Since: 2018.6
|
||||
*/
|
||||
OstreeRepoFinderResult *
|
||||
ostree_repo_finder_result_new (OstreeRemote *remote,
|
||||
OstreeRepoFinder *finder,
|
||||
gint priority,
|
||||
GHashTable *ref_to_checksum,
|
||||
GHashTable *ref_to_timestamp,
|
||||
guint64 summary_last_modified)
|
||||
ostree_repo_finder_result_new (OstreeRemote *remote, OstreeRepoFinder *finder, gint priority,
|
||||
GHashTable *ref_to_checksum, GHashTable *ref_to_timestamp,
|
||||
guint64 summary_last_modified)
|
||||
{
|
||||
g_autoptr(OstreeRepoFinderResult) result = NULL;
|
||||
g_autoptr (OstreeRepoFinderResult) result = NULL;
|
||||
|
||||
g_return_val_if_fail (remote != NULL, NULL);
|
||||
g_return_val_if_fail (OSTREE_IS_REPO_FINDER (finder), NULL);
|
||||
@ -486,9 +466,9 @@ ostree_repo_finder_result_dup (OstreeRepoFinderResult *result)
|
||||
{
|
||||
g_return_val_if_fail (result != NULL, NULL);
|
||||
|
||||
return ostree_repo_finder_result_new (result->remote, result->finder,
|
||||
result->priority, result->ref_to_checksum,
|
||||
result->ref_to_timestamp, result->summary_last_modified);
|
||||
return ostree_repo_finder_result_new (result->remote, result->finder, result->priority,
|
||||
result->ref_to_checksum, result->ref_to_timestamp,
|
||||
result->summary_last_modified);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -504,8 +484,7 @@ ostree_repo_finder_result_dup (OstreeRepoFinderResult *result)
|
||||
* Since: 2018.6
|
||||
*/
|
||||
gint
|
||||
ostree_repo_finder_result_compare (const OstreeRepoFinderResult *a,
|
||||
const OstreeRepoFinderResult *b)
|
||||
ostree_repo_finder_result_compare (const OstreeRepoFinderResult *a, const OstreeRepoFinderResult *b)
|
||||
{
|
||||
guint a_n_refs, b_n_refs;
|
||||
|
||||
@ -518,8 +497,8 @@ ostree_repo_finder_result_compare (const OstreeRepoFinderResult *a,
|
||||
if (a->priority != b->priority)
|
||||
return a->priority - b->priority;
|
||||
|
||||
if (a->summary_last_modified != 0 && b->summary_last_modified != 0 &&
|
||||
a->summary_last_modified != b->summary_last_modified)
|
||||
if (a->summary_last_modified != 0 && b->summary_last_modified != 0
|
||||
&& a->summary_last_modified != b->summary_last_modified)
|
||||
return a->summary_last_modified - b->summary_last_modified;
|
||||
|
||||
gpointer value;
|
||||
@ -537,7 +516,7 @@ ostree_repo_finder_result_compare (const OstreeRepoFinderResult *a,
|
||||
b_n_refs++;
|
||||
|
||||
if (a_n_refs != b_n_refs)
|
||||
return (gint) a_n_refs - (gint) b_n_refs;
|
||||
return (gint)a_n_refs - (gint)b_n_refs;
|
||||
|
||||
return g_strcmp0 (a->remote->name, b->remote->name);
|
||||
}
|
||||
|
@ -23,8 +23,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "ostree-ref.h"
|
||||
#include "ostree-remote.h"
|
||||
@ -44,48 +44,50 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
typedef struct _OstreeRepoFinder OstreeRepoFinder;
|
||||
typedef struct _OstreeRepoFinderInterface OstreeRepoFinderInterface;
|
||||
|
||||
static inline OstreeRepoFinder *OSTREE_REPO_FINDER (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_repo_finder_get_type (), OstreeRepoFinder); }
|
||||
static inline gboolean OSTREE_IS_REPO_FINDER (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_repo_finder_get_type ()); }
|
||||
static inline OstreeRepoFinderInterface *OSTREE_REPO_FINDER_GET_IFACE (gpointer ptr) { return G_TYPE_INSTANCE_GET_INTERFACE (ptr, ostree_repo_finder_get_type (), OstreeRepoFinderInterface); }
|
||||
static inline OstreeRepoFinder *
|
||||
OSTREE_REPO_FINDER (gpointer ptr)
|
||||
{
|
||||
return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_repo_finder_get_type (), OstreeRepoFinder);
|
||||
}
|
||||
static inline gboolean
|
||||
OSTREE_IS_REPO_FINDER (gpointer ptr)
|
||||
{
|
||||
return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_repo_finder_get_type ());
|
||||
}
|
||||
static inline OstreeRepoFinderInterface *
|
||||
OSTREE_REPO_FINDER_GET_IFACE (gpointer ptr)
|
||||
{
|
||||
return G_TYPE_INSTANCE_GET_INTERFACE (ptr, ostree_repo_finder_get_type (),
|
||||
OstreeRepoFinderInterface);
|
||||
}
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
|
||||
struct _OstreeRepoFinderInterface
|
||||
{
|
||||
GTypeInterface g_iface;
|
||||
|
||||
void (*resolve_async) (OstreeRepoFinder *self,
|
||||
const OstreeCollectionRef * const *refs,
|
||||
OstreeRepo *parent_repo,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
GPtrArray *(*resolve_finish) (OstreeRepoFinder *self,
|
||||
GAsyncResult *result,
|
||||
GError **error);
|
||||
void (*resolve_async) (OstreeRepoFinder *self, const OstreeCollectionRef *const *refs,
|
||||
OstreeRepo *parent_repo, GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback, gpointer user_data);
|
||||
GPtrArray *(*resolve_finish) (OstreeRepoFinder *self, GAsyncResult *result, GError **error);
|
||||
};
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_repo_finder_resolve_async (OstreeRepoFinder *self,
|
||||
const OstreeCollectionRef * const *refs,
|
||||
OstreeRepo *parent_repo,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
void ostree_repo_finder_resolve_async (OstreeRepoFinder *self,
|
||||
const OstreeCollectionRef *const *refs,
|
||||
OstreeRepo *parent_repo, GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback, gpointer user_data);
|
||||
_OSTREE_PUBLIC
|
||||
GPtrArray *ostree_repo_finder_resolve_finish (OstreeRepoFinder *self,
|
||||
GAsyncResult *result,
|
||||
GError **error);
|
||||
GPtrArray *ostree_repo_finder_resolve_finish (OstreeRepoFinder *self, GAsyncResult *result,
|
||||
GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_repo_finder_resolve_all_async (OstreeRepoFinder * const *finders,
|
||||
const OstreeCollectionRef * const *refs,
|
||||
OstreeRepo *parent_repo,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
void ostree_repo_finder_resolve_all_async (OstreeRepoFinder *const *finders,
|
||||
const OstreeCollectionRef *const *refs,
|
||||
OstreeRepo *parent_repo, GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback, gpointer user_data);
|
||||
_OSTREE_PUBLIC
|
||||
GPtrArray *ostree_repo_finder_resolve_all_finish (GAsyncResult *result,
|
||||
GError **error);
|
||||
GPtrArray *ostree_repo_finder_resolve_all_finish (GAsyncResult *result, GError **error);
|
||||
|
||||
/**
|
||||
* OstreeRepoFinderResult:
|
||||
@ -152,12 +154,11 @@ _OSTREE_PUBLIC
|
||||
GType ostree_repo_finder_result_get_type (void);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
OstreeRepoFinderResult *ostree_repo_finder_result_new (OstreeRemote *remote,
|
||||
OstreeRepoFinder *finder,
|
||||
gint priority,
|
||||
GHashTable *ref_to_checksum,
|
||||
GHashTable *ref_to_timestamp,
|
||||
guint64 summary_last_modified);
|
||||
OstreeRepoFinderResult *ostree_repo_finder_result_new (OstreeRemote *remote,
|
||||
OstreeRepoFinder *finder, gint priority,
|
||||
GHashTable *ref_to_checksum,
|
||||
GHashTable *ref_to_timestamp,
|
||||
guint64 summary_last_modified);
|
||||
_OSTREE_PUBLIC
|
||||
OstreeRepoFinderResult *ostree_repo_finder_result_dup (OstreeRepoFinderResult *result);
|
||||
_OSTREE_PUBLIC
|
||||
@ -178,7 +179,7 @@ void ostree_repo_finder_result_free (OstreeRepoFinderResult *result);
|
||||
*
|
||||
* Since: 2018.6
|
||||
*/
|
||||
typedef OstreeRepoFinderResult** OstreeRepoFinderResultv;
|
||||
typedef OstreeRepoFinderResult **OstreeRepoFinderResultv;
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_repo_finder_result_freev (OstreeRepoFinderResult **results);
|
||||
|
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user