From 1574f3f7395f85c77a4b51420f2925c22900d6a5 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 1 May 2023 17:22:02 -0400 Subject: lib: Fix one include We need all the ostree bits here. --- src/libostree/ostree-chain-input-stream.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libostree/ostree-chain-input-stream.h b/src/libostree/ostree-chain-input-stream.h index 539f0ebc..2b6f4896 100644 --- a/src/libostree/ostree-chain-input-stream.h +++ b/src/libostree/ostree-chain-input-stream.h @@ -22,7 +22,7 @@ #ifndef __GI_SCANNER__ -#include +#include G_BEGIN_DECLS -- cgit v1.2.1 From a917813bb82b6ec7083da24064439b656971748d Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 2 May 2023 08:41:24 -0400 Subject: clang-format: Don't align backslashes This increases compatibility between clang-15 and clang-16. Also, I don't care about the aesthetics here. --- .clang-format | 1 + 1 file changed, 1 insertion(+) diff --git a/.clang-format b/.clang-format index 59902b6c..6c64639a 100644 --- a/.clang-format +++ b/.clang-format @@ -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 -- cgit v1.2.1 From 453aed97f688c606622562145fa1f7c10096ba14 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 1 May 2023 14:24:29 -0400 Subject: tree-wide: Run clang-format This is a one-time tree wide reformatting to ensure consistency going forward. --- rust-bindings/sys/tests/constant.c | 336 +-- rust-bindings/sys/tests/layout.c | 165 +- rust-bindings/sys/tests/manual.h | 6 +- src/libostree/bupsplit.c | 108 +- src/libostree/bupsplit.h | 11 +- src/libostree/ostree-async-progress.c | 84 +- src/libostree/ostree-async-progress.h | 63 +- src/libostree/ostree-autocleanups.h | 3 +- src/libostree/ostree-bloom-private.h | 22 +- src/libostree/ostree-bloom.c | 288 +- src/libostree/ostree-bootconfig-parser.c | 81 +- src/libostree/ostree-bootconfig-parser.h | 49 +- src/libostree/ostree-bootloader-aboot.c | 122 +- src/libostree/ostree-bootloader-aboot.h | 8 +- src/libostree/ostree-bootloader-grub2.c | 146 +- src/libostree/ostree-bootloader-grub2.h | 12 +- src/libostree/ostree-bootloader-syslinux.c | 76 +- src/libostree/ostree-bootloader-syslinux.h | 8 +- src/libostree/ostree-bootloader-uboot.c | 62 +- src/libostree/ostree-bootloader-uboot.h | 8 +- src/libostree/ostree-bootloader-zipl.c | 240 +- src/libostree/ostree-bootloader-zipl.h | 8 +- src/libostree/ostree-bootloader.c | 30 +- src/libostree/ostree-bootloader.h | 55 +- src/libostree/ostree-chain-input-stream.c | 90 +- src/libostree/ostree-chain-input-stream.h | 27 +- src/libostree/ostree-checksum-input-stream.c | 79 +- src/libostree/ostree-checksum-input-stream.h | 30 +- src/libostree/ostree-cmd-private.c | 22 +- src/libostree/ostree-cmd-private.h | 35 +- src/libostree/ostree-content-writer.c | 57 +- src/libostree/ostree-content-writer.h | 9 +- src/libostree/ostree-core-private.h | 141 +- src/libostree/ostree-core.c | 854 +++--- src/libostree/ostree-core.h | 303 +- src/libostree/ostree-date-utils-private.h | 3 +- src/libostree/ostree-date-utils.c | 56 +- src/libostree/ostree-deployment-private.h | 8 +- src/libostree/ostree-deployment.c | 53 +- src/libostree/ostree-deployment.h | 14 +- src/libostree/ostree-diff.c | 184 +- src/libostree/ostree-diff.h | 44 +- src/libostree/ostree-dummy-enumtypes.h | 3 +- src/libostree/ostree-fetcher-curl.c | 326 +- src/libostree/ostree-fetcher-soup.c | 600 ++-- src/libostree/ostree-fetcher-soup3.c | 382 +-- src/libostree/ostree-fetcher-uri.c | 86 +- src/libostree/ostree-fetcher-util.c | 170 +- src/libostree/ostree-fetcher-util.h | 50 +- src/libostree/ostree-fetcher.h | 162 +- src/libostree/ostree-gpg-verifier.c | 199 +- src/libostree/ostree-gpg-verifier.h | 85 +- src/libostree/ostree-gpg-verify-result-dummy.c | 43 +- src/libostree/ostree-gpg-verify-result-private.h | 3 +- src/libostree/ostree-gpg-verify-result.c | 421 ++- src/libostree/ostree-gpg-verify-result.h | 36 +- src/libostree/ostree-impl-system-generator.c | 77 +- src/libostree/ostree-kernel-args.c | 125 +- src/libostree/ostree-kernel-args.h | 85 +- src/libostree/ostree-libarchive-input-stream.c | 82 +- src/libostree/ostree-libarchive-input-stream.h | 32 +- src/libostree/ostree-libarchive-private.h | 22 +- src/libostree/ostree-linuxfsutil.c | 10 +- src/libostree/ostree-linuxfsutil.h | 7 +- src/libostree/ostree-lzma-common.c | 29 +- src/libostree/ostree-lzma-compressor.c | 59 +- src/libostree/ostree-lzma-compressor.h | 24 +- src/libostree/ostree-lzma-decompressor.c | 31 +- src/libostree/ostree-lzma-decompressor.h | 25 +- src/libostree/ostree-metalink.c | 206 +- src/libostree/ostree-metalink.h | 38 +- src/libostree/ostree-mutable-tree.c | 182 +- src/libostree/ostree-mutable-tree.h | 105 +- src/libostree/ostree-ref.c | 32 +- src/libostree/ostree-ref.h | 16 +- src/libostree/ostree-remote-private.h | 23 +- src/libostree/ostree-remote.c | 19 +- src/libostree/ostree-remote.h | 2 +- src/libostree/ostree-repo-checkout.c | 746 +++-- src/libostree/ostree-repo-commit.c | 1828 +++++------- src/libostree/ostree-repo-deprecated.h | 18 +- src/libostree/ostree-repo-file-enumerator.c | 39 +- src/libostree/ostree-repo-file-enumerator.h | 33 +- src/libostree/ostree-repo-file.c | 309 +- src/libostree/ostree-repo-file.h | 61 +- src/libostree/ostree-repo-finder-avahi-parser.c | 26 +- src/libostree/ostree-repo-finder-avahi-private.h | 2 +- src/libostree/ostree-repo-finder-avahi.c | 503 ++-- src/libostree/ostree-repo-finder-avahi.h | 28 +- src/libostree/ostree-repo-finder-config.c | 108 +- src/libostree/ostree-repo-finder-config.h | 23 +- src/libostree/ostree-repo-finder-mount.c | 289 +- src/libostree/ostree-repo-finder-mount.h | 23 +- src/libostree/ostree-repo-finder-override.c | 128 +- src/libostree/ostree-repo-finder-override.h | 26 +- src/libostree/ostree-repo-finder.c | 145 +- src/libostree/ostree-repo-finder.h | 75 +- src/libostree/ostree-repo-libarchive.c | 537 ++-- src/libostree/ostree-repo-os.c | 28 +- src/libostree/ostree-repo-os.h | 6 +- src/libostree/ostree-repo-private.h | 496 ++- src/libostree/ostree-repo-prune.c | 221 +- src/libostree/ostree-repo-pull-private.h | 231 +- src/libostree/ostree-repo-pull-verify.c | 184 +- src/libostree/ostree-repo-pull.c | 3156 +++++++++----------- src/libostree/ostree-repo-refs.c | 502 ++-- ...ostree-repo-static-delta-compilation-analysis.c | 136 +- .../ostree-repo-static-delta-compilation.c | 786 +++-- src/libostree/ostree-repo-static-delta-core.c | 622 ++-- src/libostree/ostree-repo-static-delta-private.h | 156 +- .../ostree-repo-static-delta-processing.c | 373 +-- src/libostree/ostree-repo-traverse.c | 289 +- src/libostree/ostree-repo-verity.c | 61 +- src/libostree/ostree-repo.c | 2575 +++++++--------- src/libostree/ostree-repo.h | 1403 ++++----- src/libostree/ostree-rollsum.c | 47 +- src/libostree/ostree-rollsum.h | 11 +- src/libostree/ostree-sepolicy-private.h | 12 +- src/libostree/ostree-sepolicy.c | 207 +- src/libostree/ostree-sepolicy.h | 55 +- src/libostree/ostree-sign-dummy.c | 66 +- src/libostree/ostree-sign-dummy.h | 40 +- src/libostree/ostree-sign-ed25519.c | 222 +- src/libostree/ostree-sign-ed25519.h | 59 +- src/libostree/ostree-sign-private.h | 8 +- src/libostree/ostree-sign.c | 234 +- src/libostree/ostree-sign.h | 127 +- src/libostree/ostree-sysroot-cleanup.c | 220 +- src/libostree/ostree-sysroot-deploy.c | 1566 +++++----- src/libostree/ostree-sysroot-private.h | 180 +- src/libostree/ostree-sysroot-upgrader.c | 296 +- src/libostree/ostree-sysroot-upgrader.h | 67 +- src/libostree/ostree-sysroot.c | 692 ++--- src/libostree/ostree-sysroot.h | 254 +- .../ostree-tls-cert-interaction-private.h | 35 +- src/libostree/ostree-tls-cert-interaction.c | 12 +- src/libostree/ostree-varint.c | 145 +- src/libostree/ostree-varint.h | 6 +- src/libotutil/ot-checksum-instream.c | 50 +- src/libotutil/ot-checksum-instream.h | 33 +- src/libotutil/ot-checksum-utils.c | 93 +- src/libotutil/ot-checksum-utils.h | 54 +- src/libotutil/ot-fs-utils.c | 96 +- src/libotutil/ot-fs-utils.h | 78 +- src/libotutil/ot-gio-utils.c | 44 +- src/libotutil/ot-gio-utils.h | 42 +- src/libotutil/ot-gpg-utils.c | 373 ++- src/libotutil/ot-gpg-utils.h | 31 +- src/libotutil/ot-keyfile-utils.c | 77 +- src/libotutil/ot-keyfile-utils.h | 70 +- src/libotutil/ot-tool-util.c | 35 +- src/libotutil/ot-tool-util.h | 18 +- src/libotutil/ot-unix-utils.c | 52 +- src/libotutil/ot-unix-utils.h | 10 +- src/libotutil/ot-variant-builder.c | 277 +- src/libotutil/ot-variant-builder.h | 39 +- src/libotutil/ot-variant-utils.c | 37 +- src/libotutil/ot-variant-utils.h | 19 +- src/libotutil/otutil.h | 60 +- src/libotutil/zbase32.c | 157 +- src/libotutil/zbase32.h | 6 +- src/ostree/main.c | 102 +- src/ostree/ostree-trivial-httpd.c | 337 ++- src/ostree/ot-admin-builtin-boot-complete.c | 21 +- src/ostree/ot-admin-builtin-cleanup.c | 19 +- src/ostree/ot-admin-builtin-deploy.c | 114 +- src/ostree/ot-admin-builtin-diff.c | 49 +- src/ostree/ot-admin-builtin-finalize-staged.c | 35 +- src/ostree/ot-admin-builtin-init-fs.c | 36 +- src/ostree/ot-admin-builtin-instutil.c | 32 +- src/ostree/ot-admin-builtin-kargs.c | 16 +- src/ostree/ot-admin-builtin-os-init.c | 16 +- src/ostree/ot-admin-builtin-pin.c | 39 +- src/ostree/ot-admin-builtin-set-origin.c | 68 +- src/ostree/ot-admin-builtin-status.c | 110 +- src/ostree/ot-admin-builtin-switch.c | 62 +- src/ostree/ot-admin-builtin-undeploy.c | 28 +- src/ostree/ot-admin-builtin-unlock.c | 31 +- src/ostree/ot-admin-builtin-upgrade.c | 60 +- src/ostree/ot-admin-builtins.h | 42 +- src/ostree/ot-admin-functions.c | 41 +- src/ostree/ot-admin-functions.h | 32 +- .../ot-admin-instutil-builtin-grub2-generate.c | 34 +- ...admin-instutil-builtin-selinux-ensure-labeled.c | 111 +- src/ostree/ot-admin-instutil-builtin-set-kargs.c | 54 +- src/ostree/ot-admin-instutil-builtins.h | 13 +- src/ostree/ot-admin-kargs-builtin-edit-in-place.c | 30 +- src/ostree/ot-admin-kargs-builtins.h | 9 +- src/ostree/ot-builtin-admin.c | 72 +- src/ostree/ot-builtin-cat.c | 32 +- src/ostree/ot-builtin-checkout.c | 175 +- src/ostree/ot-builtin-checksum.c | 49 +- src/ostree/ot-builtin-commit.c | 412 ++- src/ostree/ot-builtin-config.c | 72 +- src/ostree/ot-builtin-create-usb.c | 95 +- src/ostree/ot-builtin-diff.c | 81 +- src/ostree/ot-builtin-export.c | 58 +- src/ostree/ot-builtin-find-remotes.c | 164 +- src/ostree/ot-builtin-fsck.c | 189 +- src/ostree/ot-builtin-gpg-sign.c | 73 +- src/ostree/ot-builtin-init.c | 30 +- src/ostree/ot-builtin-log.c | 38 +- src/ostree/ot-builtin-ls.c | 104 +- src/ostree/ot-builtin-prune.c | 165 +- src/ostree/ot-builtin-pull-local.c | 118 +- src/ostree/ot-builtin-pull.c | 213 +- src/ostree/ot-builtin-refs.c | 105 +- src/ostree/ot-builtin-remote.c | 53 +- src/ostree/ot-builtin-reset.c | 26 +- src/ostree/ot-builtin-rev-parse.c | 27 +- src/ostree/ot-builtin-show.c | 201 +- src/ostree/ot-builtin-sign.c | 85 +- src/ostree/ot-builtin-static-delta.c | 317 +- src/ostree/ot-builtin-summary.c | 91 +- src/ostree/ot-builtin-trivial-httpd.c | 11 +- src/ostree/ot-builtins.h | 60 +- src/ostree/ot-dump.c | 171 +- src/ostree/ot-dump.h | 21 +- src/ostree/ot-editor.c | 26 +- src/ostree/ot-editor.h | 4 +- src/ostree/ot-main.c | 220 +- src/ostree/ot-main.h | 71 +- src/ostree/ot-remote-builtin-add-cookie.c | 23 +- src/ostree/ot-remote-builtin-add.c | 142 +- src/ostree/ot-remote-builtin-delete-cookie.c | 20 +- src/ostree/ot-remote-builtin-delete.c | 37 +- src/ostree/ot-remote-builtin-gpg-import.c | 53 +- src/ostree/ot-remote-builtin-gpg-list-keys.c | 26 +- src/ostree/ot-remote-builtin-list-cookies.c | 17 +- src/ostree/ot-remote-builtin-list.c | 20 +- src/ostree/ot-remote-builtin-refs.c | 28 +- src/ostree/ot-remote-builtin-show-url.c | 17 +- src/ostree/ot-remote-builtin-summary.c | 54 +- src/ostree/ot-remote-builtins.h | 28 +- src/ostree/ot-remote-cookie-util.c | 91 +- src/ostree/ot-remote-cookie-util.h | 17 +- src/rofiles-fuse/main.c | 171 +- src/switchroot/ostree-mount-util.h | 16 +- src/switchroot/ostree-prepare-root.c | 98 +- src/switchroot/ostree-remount.c | 42 +- src/switchroot/ostree-system-generator.c | 15 +- tests/libostreetest.c | 40 +- tests/libostreetest.h | 12 +- tests/repo-finder-mount.c | 50 +- tests/test-basic-c.c | 280 +- tests/test-bloom.c | 37 +- tests/test-bsdiff.c | 34 +- tests/test-checksum.c | 25 +- tests/test-commit-sign-sh-ext.c | 33 +- tests/test-gpg-verify-result.c | 354 +-- tests/test-include-ostree-h.c | 5 +- tests/test-kargs.c | 71 +- tests/test-keyfile-utils.c | 155 +- tests/test-libarchive-import.c | 182 +- tests/test-lzma.c | 65 +- tests/test-mock-gio.c | 38 +- tests/test-mock-gio.h | 92 +- tests/test-mutable-tree.c | 52 +- tests/test-ot-opt-utils.c | 15 +- tests/test-ot-tool-util.c | 29 +- tests/test-ot-unix-utils.c | 15 +- tests/test-pull-c.c | 52 +- tests/test-repo-finder-avahi.c | 117 +- tests/test-repo-finder-config.c | 210 +- tests/test-repo-finder-mount.c | 327 +- tests/test-repo.c | 275 +- tests/test-rfc2616-dates.c | 97 +- tests/test-rollsum-cli.c | 10 +- tests/test-rollsum.c | 90 +- tests/test-sysroot-c.c | 25 +- tests/test-varint.c | 23 +- 271 files changed, 17169 insertions(+), 22007 deletions(-) diff --git a/rust-bindings/sys/tests/constant.c b/rust-bindings/sys/tests/constant.c index d65f4666..7b3a9d7c 100644 --- a/rust-bindings/sys/tests/constant.c +++ b/rust-bindings/sys/tests/constant.c @@ -6,172 +6,174 @@ #include #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; } diff --git a/rust-bindings/sys/tests/layout.c b/rust-bindings/sys/tests/layout.c index 0def4cc7..b1c8f939 100644 --- a/rust-bindings/sys/tests/layout.c +++ b/rust-bindings/sys/tests/layout.c @@ -6,60 +6,113 @@ #include #include -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; } diff --git a/rust-bindings/sys/tests/manual.h b/rust-bindings/sys/tests/manual.h index 0e2e16c3..15ce6fb4 100644 --- a/rust-bindings/sys/tests/manual.h +++ b/rust-bindings/sys/tests/manual.h @@ -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 diff --git a/src/libostree/bupsplit.c b/src/libostree/bupsplit.c index f2de86f3..7e5f3ab6 100644 --- a/src/libostree/bupsplit.c +++ b/src/libostree/bupsplit.c @@ -28,10 +28,10 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "bupsplit.h" -#include #include -#include +#include #include +#include // 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; } diff --git a/src/libostree/bupsplit.h b/src/libostree/bupsplit.h index d7710d49..1db9e255 100644 --- a/src/libostree/bupsplit.h +++ b/src/libostree/bupsplit.h @@ -34,16 +34,17 @@ #include #define BUP_BLOBBITS (13) -#define BUP_BLOBSIZE (1<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 (); diff --git a/src/libostree/ostree-async-progress.h b/src/libostree/ostree-async-progress.h index afd45f1f..30068923 100644 --- a/src/libostree/ostree-async-progress.h +++ b/src/libostree/ostree-async-progress.h @@ -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)) - -typedef struct OstreeAsyncProgress OstreeAsyncProgress; -typedef struct OstreeAsyncProgressClass 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; 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 diff --git a/src/libostree/ostree-autocleanups.h b/src/libostree/ostree-autocleanups.h index 56274949..d087e6ae 100644 --- a/src/libostree/ostree-autocleanups.h +++ b/src/libostree/ostree-autocleanups.h @@ -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) diff --git a/src/libostree/ostree-bloom-private.h b/src/libostree/ostree-bloom-private.h index e9ec2baf..3a608af3 100644 --- a/src/libostree/ostree-bloom-private.h +++ b/src/libostree/ostree-bloom-private.h @@ -23,8 +23,8 @@ #pragma once #include -#include #include +#include #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 diff --git a/src/libostree/ostree-bloom.c b/src/libostree/ostree-bloom.c index 8c1017d7..6c1d1f14 100644 --- a/src/libostree/ostree-bloom.c +++ b/src/libostree/ostree-bloom.c @@ -24,8 +24,8 @@ #include #include -#include #include +#include #include #include @@ -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 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 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 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 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 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) { - - 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; - - for (; in != end; in += 8) { - m = U8TO64_LE(in); - v3 ^= m; - - TRACE; - for (i = 0; i < cROUNDS; ++i) - SIPROUND; - - v0 ^= m; +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; + + if (outlen == 16) + v1 ^= 0xee; + + for (; in != end; in += 8) + { + m = U8TO64_LE (in); + v3 ^= m; + + TRACE; + for (i = 0; i < cROUNDS; ++i) + SIPROUND; + + 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); + b = v0 ^ v1 ^ v2 ^ v3; + U64TO8_LE (out, b); - if (outlen == 8) - return 0; + if (outlen == 8) + return 0; - v1 ^= 0xdd; + v1 ^= 0xdd; - TRACE; - for (i = 0; i < dROUNDS; ++i) - SIPROUND; + 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 + 8, b); - return 0; + 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); } diff --git a/src/libostree/ostree-bootconfig-parser.c b/src/libostree/ostree-bootconfig-parser.c index a8ca04d6..4c3e80d0 100644 --- a/src/libostree/ostree-bootconfig-parser.c +++ b/src/libostree/ostree-bootconfig-parser.c @@ -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); } diff --git a/src/libostree/ostree-bootconfig-parser.h b/src/libostree/ostree-bootconfig-parser.h index 6d8359da..5fdad72e 100644 --- a/src/libostree/ostree-bootconfig-parser.h +++ b/src/libostree/ostree-bootconfig-parser.h @@ -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 diff --git a/src/libostree/ostree-bootloader-aboot.c b/src/libostree/ostree-bootloader-aboot.c index 9370aa6e..c21bd67c 100644 --- a/src/libostree/ostree-bootloader-aboot.c +++ b/src/libostree/ostree-bootloader-aboot.c @@ -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 @@ -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_check_exit_status (estatus, error)) { - return FALSE; - } - - if (!glnx_unlinkat (self->sysroot->sysroot_fd, aboot_requires_execute_path, 0, 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 (!glnx_unlinkat (self->sysroot->sysroot_fd, aboot_requires_execute_path, 0, error)) + { + return FALSE; + } return TRUE; } diff --git a/src/libostree/ostree-bootloader-aboot.h b/src/libostree/ostree-bootloader-aboot.h index f05457da..690220a5 100644 --- a/src/libostree/ostree-bootloader-aboot.h +++ b/src/libostree/ostree-bootloader-aboot.h @@ -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 diff --git a/src/libostree/ostree-bootloader-grub2.c b/src/libostree/ostree-bootloader-grub2.c index fff3b95c..e1ee7868 100644 --- a/src/libostree/ostree-bootloader-grub2.c +++ b/src/libostree/ostree-bootloader-grub2.c @@ -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 #include @@ -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; } diff --git a/src/libostree/ostree-bootloader-grub2.h b/src/libostree/ostree-bootloader-grub2.h index 2b0d99c5..8f6c3de5 100644 --- a/src/libostree/ostree-bootloader-grub2.h +++ b/src/libostree/ostree-bootloader-grub2.h @@ -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 diff --git a/src/libostree/ostree-bootloader-syslinux.c b/src/libostree/ostree-bootloader-syslinux.c index 8add0f11..1e71ef23 100644 --- a/src/libostree/ostree-bootloader-syslinux.c +++ b/src/libostree/ostree-bootloader-syslinux.c @@ -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 @@ -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 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; diff --git a/src/libostree/ostree-bootloader-syslinux.h b/src/libostree/ostree-bootloader-syslinux.h index bed9a6c8..311e962f 100644 --- a/src/libostree/ostree-bootloader-syslinux.h +++ b/src/libostree/ostree-bootloader-syslinux.h @@ -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 diff --git a/src/libostree/ostree-bootloader-uboot.c b/src/libostree/ostree-bootloader-uboot.c index d0207ad5..41280cf1 100644 --- a/src/libostree/ostree-bootloader-uboot.c +++ b/src/libostree/ostree-bootloader-uboot.c @@ -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 @@ -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; diff --git a/src/libostree/ostree-bootloader-uboot.h b/src/libostree/ostree-bootloader-uboot.h index ac777fa9..8e2ed24f 100644 --- a/src/libostree/ostree-bootloader-uboot.h +++ b/src/libostree/ostree-bootloader-uboot.h @@ -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 diff --git a/src/libostree/ostree-bootloader-zipl.c b/src/libostree/ostree-bootloader-zipl.c index c9ca4219..4ff093ff 100644 --- a/src/libostree/ostree-bootloader-zipl.c +++ b/src/libostree/ostree-bootloader-zipl.c @@ -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 #include #include -#include -#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; - - 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); + 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); 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; diff --git a/src/libostree/ostree-bootloader-zipl.h b/src/libostree/ostree-bootloader-zipl.h index e3f0b2b3..97ba7dd0 100644 --- a/src/libostree/ostree-bootloader-zipl.h +++ b/src/libostree/ostree-bootloader-zipl.h @@ -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 diff --git a/src/libostree/ostree-bootloader.c b/src/libostree/ostree-bootloader.c index 788fb2c4..4fd8c4ca 100644 --- a/src/libostree/ostree-bootloader.c +++ b/src/libostree/ostree-bootloader.c @@ -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)); diff --git a/src/libostree/ostree-bootloader.h b/src/libostree/ostree-bootloader.h index 00f5632c..bb326f5a 100644 --- a/src/libostree/ostree-bootloader.h +++ b/src/libostree/ostree-bootloader.h @@ -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 diff --git a/src/libostree/ostree-chain-input-stream.c b/src/libostree/ostree-chain-input-stream.c index 22f40227..63f5c1d7 100644 --- a/src/libostree/ostree-chain-input-stream.c +++ b/src/libostree/ostree-chain-input-stream.c @@ -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; } diff --git a/src/libostree/ostree-chain-input-stream.h b/src/libostree/ostree-chain-input-stream.h index 2b6f4896..d6396774 100644 --- a/src/libostree/ostree-chain-input-stream.h +++ b/src/libostree/ostree-chain-input-stream.h @@ -26,16 +26,21 @@ 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 diff --git a/src/libostree/ostree-checksum-input-stream.c b/src/libostree/ostree-checksum-input-stream.c index 6481bf07..f06a95d8 100644 --- a/src/libostree/ostree-checksum-input-stream.c +++ b/src/libostree/ostree-checksum-input-stream.c @@ -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) - -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); +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_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); diff --git a/src/libostree/ostree-checksum-input-stream.h b/src/libostree/ostree-checksum-input-stream.h index 4138cd7e..1c5cc371 100644 --- a/src/libostree/ostree-checksum-input-stream.h +++ b/src/libostree/ostree-checksum-input-stream.h @@ -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 diff --git a/src/libostree/ostree-cmd-private.c b/src/libostree/ostree-cmd-private.c index 173d430e..239d3cd3 100644 --- a/src/libostree/ostree-cmd-private.c +++ b/src/libostree/ostree-cmd-private.c @@ -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; diff --git a/src/libostree/ostree-cmd-private.h b/src/libostree/ostree-cmd-private.h index 17f943c8..15d95f7f 100644 --- a/src/libostree/ostree-cmd-private.h +++ b/src/libostree/ostree-cmd-private.h @@ -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 diff --git a/src/libostree/ostree-content-writer.c b/src/libostree/ostree-content-writer.c index 3bc5dd17..bbca2879 100644 --- a/src/libostree/ostree-content-writer.c +++ b/src/libostree/ostree-content-writer.c @@ -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; diff --git a/src/libostree/ostree-content-writer.h b/src/libostree/ostree-content-writer.h index 219860dd..26a17b7c 100644 --- a/src/libostree/ostree-content-writer.h +++ b/src/libostree/ostree-content-writer.h @@ -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 diff --git a/src/libostree/ostree-core-private.h b/src/libostree/ostree-core-private.h index cac45f78..3c4b391e 100644 --- a/src/libostree/ostree-core-private.h +++ b/src/libostree/ostree-core-private.h @@ -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_compare_timestamps (const char *current_rev, - guint64 current_ts, - const char *new_rev, - guint64 new_ts, - 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); G_END_DECLS diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c index adb9d70c..921401c1 100644 --- a/src/libostree/ostree-core.c +++ b/src/libostree/ostree-core.c @@ -22,39 +22,38 @@ #include "config.h" -#include -#include -#include -#include -#include #include "libglnx.h" -#include "ostree.h" -#include "ostree-core-private.h" #include "ostree-chain-input-stream.h" +#include "ostree-core-private.h" #include "ostree-varint.h" +#include "ostree.h" #include "otutil.h" +#include +#include +#include +#include +#include /* Generic ABI checks */ -G_STATIC_ASSERT(OSTREE_REPO_MODE_BARE == 0); -G_STATIC_ASSERT(OSTREE_REPO_MODE_ARCHIVE_Z2 == 1); -G_STATIC_ASSERT(OSTREE_REPO_MODE_ARCHIVE == OSTREE_REPO_MODE_ARCHIVE_Z2); -G_STATIC_ASSERT(OSTREE_REPO_MODE_BARE_USER == 2); -G_STATIC_ASSERT(OSTREE_REPO_MODE_BARE_USER_ONLY == 3); -G_STATIC_ASSERT(OSTREE_REPO_MODE_BARE_SPLIT_XATTRS == 4); +G_STATIC_ASSERT (OSTREE_REPO_MODE_BARE == 0); +G_STATIC_ASSERT (OSTREE_REPO_MODE_ARCHIVE_Z2 == 1); +G_STATIC_ASSERT (OSTREE_REPO_MODE_ARCHIVE == OSTREE_REPO_MODE_ARCHIVE_Z2); +G_STATIC_ASSERT (OSTREE_REPO_MODE_BARE_USER == 2); +G_STATIC_ASSERT (OSTREE_REPO_MODE_BARE_USER_ONLY == 3); +G_STATIC_ASSERT (OSTREE_REPO_MODE_BARE_SPLIT_XATTRS == 4); static GBytes *variant_to_lenprefixed_buffer (GVariant *variant); #define ALIGN_VALUE(this, boundary) \ - (( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)) & (~(((unsigned long)(boundary))-1))) + ((((unsigned long)(this)) + (((unsigned long)(boundary)) - 1)) \ + & (~(((unsigned long)(boundary)) - 1))) /* Return a copy of @input suitable for addition to * a GError message; newlines are quashed, the value * is forced to be UTF-8, is truncated to @maxlen (if maxlen != -1). */ static char * -quash_string_for_error_message (const char *input, - ssize_t len, - ssize_t maxlen) +quash_string_for_error_message (const char *input, ssize_t len, ssize_t maxlen) { if (len == -1) len = strlen (input); @@ -81,16 +80,10 @@ quash_string_for_error_message (const char *input, return buf; } -static gboolean -file_header_parse (GVariant *metadata, - GFileInfo **out_file_info, - GVariant **out_xattrs, - GError **error); -static gboolean -zlib_file_header_parse (GVariant *metadata, - GFileInfo **out_file_info, - GVariant **out_xattrs, - GError **error); +static gboolean file_header_parse (GVariant *metadata, GFileInfo **out_file_info, + GVariant **out_xattrs, GError **error); +static gboolean zlib_file_header_parse (GVariant *metadata, GFileInfo **out_file_info, + GVariant **out_xattrs, GError **error); /** * SECTION:ostree-core @@ -139,8 +132,7 @@ ostree_metadata_variant_type (OstreeObjectType objtype) * Returns: %TRUE if @sha256 is a valid checksum string, %FALSE otherwise */ gboolean -ostree_validate_checksum_string (const char *sha256, - GError **error) +ostree_validate_checksum_string (const char *sha256, GError **error) { return ostree_validate_structureof_checksum_string (sha256, error); } @@ -169,21 +161,19 @@ ostree_validate_checksum_string (const char *sha256, * Returns: %TRUE on successful parsing, %FALSE otherwise */ gboolean -ostree_parse_refspec (const char *refspec, - char **out_remote, - char **out_ref, - GError **error) +ostree_parse_refspec (const char *refspec, char **out_remote, char **out_ref, GError **error) { static GRegex *regex; static gsize regex_initialized; if (g_once_init_enter (®ex_initialized)) { - regex = g_regex_new ("^(" OSTREE_REMOTE_NAME_REGEXP ":)?(" OSTREE_REF_REGEXP ")$", 0, 0, NULL); + regex + = g_regex_new ("^(" OSTREE_REMOTE_NAME_REGEXP ":)?(" OSTREE_REF_REGEXP ")$", 0, 0, NULL); g_assert (regex); g_once_init_leave (®ex_initialized, 1); } - g_autoptr(GMatchInfo) match = NULL; + g_autoptr (GMatchInfo) match = NULL; if (!g_regex_match (regex, refspec, 0, &match)) return glnx_throw (error, "Invalid refspec %s", refspec); @@ -195,7 +185,7 @@ ostree_parse_refspec (const char *refspec, else { /* Trim the : */ - remote[strlen(remote)-1] = '\0'; + remote[strlen (remote) - 1] = '\0'; } if (out_remote) @@ -206,8 +196,7 @@ ostree_parse_refspec (const char *refspec, } gboolean -_ostree_validate_ref_fragment (const char *fragment, - GError **error) +_ostree_validate_ref_fragment (const char *fragment, GError **error) { static GRegex *regex; static gsize regex_initialized; @@ -218,7 +207,7 @@ _ostree_validate_ref_fragment (const char *fragment, g_once_init_leave (®ex_initialized, 1); } - g_autoptr(GMatchInfo) match = NULL; + g_autoptr (GMatchInfo) match = NULL; if (!g_regex_match (regex, fragment, 0, &match)) return glnx_throw (error, "Invalid ref fragment '%s'", fragment); @@ -233,10 +222,9 @@ _ostree_validate_ref_fragment (const char *fragment, * Returns: %TRUE if @rev is a valid ref string */ gboolean -ostree_validate_rev (const char *rev, - GError **error) +ostree_validate_rev (const char *rev, GError **error) { - g_autoptr(GMatchInfo) match = NULL; + g_autoptr (GMatchInfo) match = NULL; static gsize regex_initialized; static GRegex *regex; @@ -262,10 +250,9 @@ ostree_validate_rev (const char *rev, * Since: 2017.8 */ gboolean -ostree_validate_remote_name (const char *remote_name, - GError **error) +ostree_validate_remote_name (const char *remote_name, GError **error) { - g_autoptr(GMatchInfo) match = NULL; + g_autoptr (GMatchInfo) match = NULL; static gsize regex_initialized; static GRegex *regex; @@ -321,8 +308,7 @@ ostree_validate_collection_id (const char *collection_id, GError **error) * as @xattrs (which if NULL, is taken to be the empty set). */ GBytes * -_ostree_file_header_new (GFileInfo *file_info, - GVariant *xattrs) +_ostree_file_header_new (GFileInfo *file_info, GVariant *xattrs) { guint32 uid = g_file_info_get_attribute_uint32 (file_info, "unix::uid"); @@ -335,13 +321,13 @@ _ostree_file_header_new (GFileInfo *file_info, else symlink_target = ""; - g_autoptr(GVariant) tmp_xattrs = NULL; + g_autoptr (GVariant) tmp_xattrs = NULL; if (xattrs == NULL) tmp_xattrs = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("(ayay)"), NULL, 0)); - g_autoptr(GVariant) ret = g_variant_new ("(uuuus@a(ayay))", GUINT32_TO_BE (uid), - GUINT32_TO_BE (gid), GUINT32_TO_BE (mode), 0, - symlink_target, xattrs ?: tmp_xattrs); + g_autoptr (GVariant) ret + = g_variant_new ("(uuuus@a(ayay))", GUINT32_TO_BE (uid), GUINT32_TO_BE (gid), + GUINT32_TO_BE (mode), 0, symlink_target, xattrs ?: tmp_xattrs); return variant_to_lenprefixed_buffer (g_variant_ref_sink (ret)); } @@ -352,8 +338,7 @@ _ostree_file_header_new (GFileInfo *file_info, * user.ostreemeta xattr. */ GBytes * -_ostree_zlib_file_header_new (GFileInfo *file_info, - GVariant *xattrs) +_ostree_zlib_file_header_new (GFileInfo *file_info, GVariant *xattrs) { guint64 size = 0; guint32 uid = g_file_info_get_attribute_uint32 (file_info, "unix::uid"); @@ -369,14 +354,13 @@ _ostree_zlib_file_header_new (GFileInfo *file_info, if (g_file_info_has_attribute (file_info, "standard::size")) size = g_file_info_get_size (file_info); - g_autoptr(GVariant) tmp_xattrs = NULL; + g_autoptr (GVariant) tmp_xattrs = NULL; if (xattrs == NULL) tmp_xattrs = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("(ayay)"), NULL, 0)); - g_autoptr(GVariant) ret = g_variant_new ("(tuuuus@a(ayay))", - GUINT64_TO_BE (size), GUINT32_TO_BE (uid), - GUINT32_TO_BE (gid), GUINT32_TO_BE (mode), 0, - symlink_target, xattrs ?: tmp_xattrs); + g_autoptr (GVariant) ret = g_variant_new ( + "(tuuuus@a(ayay))", GUINT64_TO_BE (size), GUINT32_TO_BE (uid), GUINT32_TO_BE (gid), + GUINT32_TO_BE (mode), 0, symlink_target, xattrs ?: tmp_xattrs); return variant_to_lenprefixed_buffer (g_variant_ref_sink (ret)); } @@ -387,27 +371,27 @@ static GBytes * variant_to_lenprefixed_buffer (GVariant *variant) { /* This string is really a binary memory buffer */ - g_autoptr(GString) buf = g_string_new (NULL); + g_autoptr (GString) buf = g_string_new (NULL); /* Write variant size */ const guint64 variant_size = g_variant_get_size (variant); g_assert (variant_size < G_MAXUINT32); - const guint32 variant_size_u32_be = GUINT32_TO_BE((guint32) variant_size); + const guint32 variant_size_u32_be = GUINT32_TO_BE ((guint32)variant_size); - g_string_append_len (buf, (char*)&variant_size_u32_be, sizeof (variant_size_u32_be)); + g_string_append_len (buf, (char *)&variant_size_u32_be, sizeof (variant_size_u32_be)); - /* Write NULs for alignment. At the moment this is a constant 4 bytes (i.e. - * align to 8, since the length is 4 bytes). If we ever change this, the - * logic is here: - */ - // const gsize alignment_offset = sizeof (variant_size_u32_be); - // const guint bits = alignment_offset & 7; /* mod 8 */ - // const guint padding_len = alignment - bits; - #define padding_len sizeof(guint32) - const guchar padding_nuls[padding_len] = {0, 0, 0, 0}; - g_string_append_len (buf, (char*)padding_nuls, padding_len); - #undef padding_len - - g_string_append_len (buf, (char*)g_variant_get_data (variant), g_variant_get_size (variant)); +/* Write NULs for alignment. At the moment this is a constant 4 bytes (i.e. + * align to 8, since the length is 4 bytes). If we ever change this, the + * logic is here: + */ +// const gsize alignment_offset = sizeof (variant_size_u32_be); +// const guint bits = alignment_offset & 7; /* mod 8 */ +// const guint padding_len = alignment - bits; +#define padding_len sizeof (guint32) + const guchar padding_nuls[padding_len] = { 0, 0, 0, 0 }; + g_string_append_len (buf, (char *)padding_nuls, padding_len); +#undef padding_len + + g_string_append_len (buf, (char *)g_variant_get_data (variant), g_variant_get_size (variant)); return g_string_free_to_bytes (g_steal_pointer (&buf)); } @@ -419,14 +403,13 @@ variant_to_lenprefixed_buffer (GVariant *variant) * Combines @file_header and @input into a single stream. */ static GInputStream * -header_and_input_to_stream (GBytes *file_header, - GInputStream *input) +header_and_input_to_stream (GBytes *file_header, GInputStream *input) { /* Our result stream chain */ - g_autoptr(GPtrArray) streams = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref); + g_autoptr (GPtrArray) streams = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref); /* Append the header to the chain */ - g_autoptr(GInputStream) header_in_stream = g_memory_input_stream_new_from_bytes (file_header); + g_autoptr (GInputStream) header_in_stream = g_memory_input_stream_new_from_bytes (file_header); g_ptr_array_add (streams, g_object_ref (header_in_stream)); @@ -435,27 +418,23 @@ header_and_input_to_stream (GBytes *file_header, g_ptr_array_add (streams, g_object_ref (input)); /* Return the result stream */ - return (GInputStream*)ostree_chain_input_stream_new (streams); + return (GInputStream *)ostree_chain_input_stream_new (streams); } /* Convert file metadata + file content into an archive-format stream. */ gboolean -_ostree_raw_file_to_archive_stream (GInputStream *input, - GFileInfo *file_info, - GVariant *xattrs, - guint compression_level, - GInputStream **out_input, - GCancellable *cancellable, - GError **error) -{ - g_autoptr(GInputStream) zlib_input = NULL; +_ostree_raw_file_to_archive_stream (GInputStream *input, GFileInfo *file_info, GVariant *xattrs, + guint compression_level, GInputStream **out_input, + GCancellable *cancellable, GError **error) +{ + g_autoptr (GInputStream) zlib_input = NULL; if (input != NULL) { - g_autoptr(GConverter) zlib_compressor = - G_CONVERTER (g_zlib_compressor_new (G_ZLIB_COMPRESSOR_FORMAT_RAW, compression_level)); + g_autoptr (GConverter) zlib_compressor + = G_CONVERTER (g_zlib_compressor_new (G_ZLIB_COMPRESSOR_FORMAT_RAW, compression_level)); zlib_input = g_converter_input_stream_new (input, zlib_compressor); } - g_autoptr(GBytes) file_header = _ostree_zlib_file_header_new (file_info, xattrs); + g_autoptr (GBytes) file_header = _ostree_zlib_file_header_new (file_info, xattrs); *out_input = header_and_input_to_stream (file_header, zlib_input); return TRUE; } @@ -475,16 +454,13 @@ _ostree_raw_file_to_archive_stream (GInputStream *input, * Since: 2016.6 */ gboolean -ostree_raw_file_to_archive_z2_stream (GInputStream *input, - GFileInfo *file_info, - GVariant *xattrs, - GInputStream **out_input, - GCancellable *cancellable, - GError **error) +ostree_raw_file_to_archive_z2_stream (GInputStream *input, GFileInfo *file_info, GVariant *xattrs, + GInputStream **out_input, GCancellable *cancellable, + GError **error) { return _ostree_raw_file_to_archive_stream (input, file_info, xattrs, - OSTREE_ARCHIVE_DEFAULT_COMPRESSION_LEVEL, - out_input, cancellable, error); + OSTREE_ARCHIVE_DEFAULT_COMPRESSION_LEVEL, out_input, + cancellable, error); } /** @@ -506,25 +482,21 @@ ostree_raw_file_to_archive_z2_stream (GInputStream *input, * Since: 2017.3 */ 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_raw_file_to_archive_z2_stream_with_options (GInputStream *input, GFileInfo *file_info, + GVariant *xattrs, GVariant *options, + GInputStream **out_input, + GCancellable *cancellable, GError **error) { gint compression_level = -1; if (options) - (void) g_variant_lookup (options, "compression-level", "i", &compression_level); + (void)g_variant_lookup (options, "compression-level", "i", &compression_level); if (compression_level < 0) compression_level = OSTREE_ARCHIVE_DEFAULT_COMPRESSION_LEVEL; - return _ostree_raw_file_to_archive_stream (input, file_info, xattrs, - compression_level, - out_input, cancellable, error); + return _ostree_raw_file_to_archive_stream (input, file_info, xattrs, compression_level, out_input, + cancellable, error); } /** @@ -542,15 +514,11 @@ ostree_raw_file_to_archive_z2_stream_with_options (GInputStream *input, * for writing data to an #OstreeRepo. */ gboolean -ostree_raw_file_to_content_stream (GInputStream *input, - GFileInfo *file_info, - GVariant *xattrs, - GInputStream **out_input, - guint64 *out_length, - GCancellable *cancellable, - GError **error) -{ - g_autoptr(GBytes) file_header = _ostree_file_header_new (file_info, xattrs); +ostree_raw_file_to_content_stream (GInputStream *input, GFileInfo *file_info, GVariant *xattrs, + GInputStream **out_input, guint64 *out_length, + GCancellable *cancellable, GError **error) +{ + g_autoptr (GBytes) file_header = _ostree_file_header_new (file_info, xattrs); *out_input = header_and_input_to_stream (file_header, input); if (out_length) *out_length = g_bytes_get_size (file_header); @@ -575,69 +543,51 @@ ostree_raw_file_to_content_stream (GInputStream *input, * converts an object content stream back into components. */ 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_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) { guint32 archive_header_size; guchar dummy[4]; gsize bytes_read; - if (!g_input_stream_read_all (input, - &archive_header_size, 4, &bytes_read, - cancellable, error)) + if (!g_input_stream_read_all (input, &archive_header_size, 4, &bytes_read, cancellable, error)) return FALSE; archive_header_size = GUINT32_FROM_BE (archive_header_size); if (archive_header_size > input_length) - return glnx_throw (error, "File header size %u exceeds size %" G_GUINT64_FORMAT, - (guint)archive_header_size, input_length); + return glnx_throw (error, "File header size %u exceeds size %" G_GUINT64_FORMAT, + (guint)archive_header_size, input_length); else if (archive_header_size == 0) return glnx_throw (error, "File header size is zero"); /* Skip over padding */ - if (!g_input_stream_read_all (input, - dummy, 4, &bytes_read, - cancellable, error)) + if (!g_input_stream_read_all (input, dummy, 4, &bytes_read, cancellable, error)) return FALSE; g_autofree guchar *buf = g_malloc (archive_header_size); - if (!g_input_stream_read_all (input, buf, archive_header_size, &bytes_read, - cancellable, error)) + if (!g_input_stream_read_all (input, buf, archive_header_size, &bytes_read, cancellable, error)) return FALSE; - g_autoptr(GVariant) file_header = - g_variant_ref_sink(g_variant_new_from_data (compressed ? _OSTREE_ZLIB_FILE_HEADER_GVARIANT_FORMAT : _OSTREE_FILE_HEADER_GVARIANT_FORMAT, - buf, archive_header_size, trusted, - g_free, buf)); + g_autoptr (GVariant) file_header = g_variant_ref_sink (g_variant_new_from_data ( + compressed ? _OSTREE_ZLIB_FILE_HEADER_GVARIANT_FORMAT : _OSTREE_FILE_HEADER_GVARIANT_FORMAT, + buf, archive_header_size, trusted, g_free, buf)); buf = NULL; - g_autoptr(GFileInfo) ret_file_info = NULL; - g_autoptr(GVariant) ret_xattrs = NULL; + g_autoptr (GFileInfo) ret_file_info = NULL; + g_autoptr (GVariant) ret_xattrs = NULL; if (compressed) { - if (!zlib_file_header_parse (file_header, - &ret_file_info, - out_xattrs ? &ret_xattrs : NULL, + if (!zlib_file_header_parse (file_header, &ret_file_info, out_xattrs ? &ret_xattrs : NULL, error)) return FALSE; } else { - if (!file_header_parse (file_header, - &ret_file_info, - out_xattrs ? &ret_xattrs : NULL, - error)) + if (!file_header_parse (file_header, &ret_file_info, out_xattrs ? &ret_xattrs : NULL, error)) return FALSE; g_file_info_set_size (ret_file_info, input_length - archive_header_size - 8); } - g_autoptr(GInputStream) ret_input = NULL; - if (g_file_info_get_file_type (ret_file_info) == G_FILE_TYPE_REGULAR - && out_input) + g_autoptr (GInputStream) ret_input = NULL; + if (g_file_info_get_file_type (ret_file_info) == G_FILE_TYPE_REGULAR && out_input) { /* Give the input stream at its current position as return value; * assuming the caller doesn't seek, this should be fine. We might @@ -645,7 +595,8 @@ ostree_content_stream_parse (gboolean compressed, **/ if (compressed) { - g_autoptr(GConverter) zlib_decomp = (GConverter*)g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_RAW); + g_autoptr (GConverter) zlib_decomp + = (GConverter *)g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_RAW); ret_input = g_converter_input_stream_new (input, zlib_decomp); } else @@ -674,15 +625,9 @@ ostree_content_stream_parse (gboolean compressed, * converts an object content stream back into components. */ 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_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) { glnx_autofd int fd = -1; if (!glnx_openat_rdonly (parent_dfd, path, TRUE, &fd, error)) @@ -692,14 +637,13 @@ ostree_content_file_parse_at (gboolean compressed, if (!glnx_fstat (fd, &stbuf, error)) return FALSE; - g_autoptr(GInputStream) file_input = g_unix_input_stream_new (g_steal_fd (&fd), TRUE); + g_autoptr (GInputStream) file_input = g_unix_input_stream_new (g_steal_fd (&fd), TRUE); - g_autoptr(GFileInfo) ret_file_info = NULL; - g_autoptr(GVariant) ret_xattrs = NULL; - g_autoptr(GInputStream) ret_input = NULL; + g_autoptr (GFileInfo) ret_file_info = NULL; + g_autoptr (GVariant) ret_xattrs = NULL; + g_autoptr (GInputStream) ret_input = NULL; if (!ostree_content_stream_parse (compressed, file_input, stbuf.st_size, trusted, - out_input ? &ret_input : NULL, - &ret_file_info, &ret_xattrs, + out_input ? &ret_input : NULL, &ret_file_info, &ret_xattrs, cancellable, error)) return FALSE; @@ -724,29 +668,18 @@ ostree_content_file_parse_at (gboolean compressed, * converts an object content stream back into components. */ 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) -{ - return ostree_content_file_parse_at (compressed, AT_FDCWD, - gs_file_get_path_cached (content_path), - trusted, - out_input, out_file_info, out_xattrs, - cancellable, error); +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) +{ + return ostree_content_file_parse_at (compressed, AT_FDCWD, gs_file_get_path_cached (content_path), + trusted, out_input, out_file_info, out_xattrs, cancellable, + error); } static gboolean -break_symhardlink (int dfd, - const char *path, - struct stat *stbuf, - GLnxFileCopyFlags copyflags, - GCancellable *cancellable, - GError **error) +break_symhardlink (int dfd, const char *path, struct stat *stbuf, GLnxFileCopyFlags copyflags, + GCancellable *cancellable, GError **error) { guint count; gboolean copy_success = FALSE; @@ -754,12 +687,11 @@ break_symhardlink (int dfd, for (count = 0; count < 100; count++) { - g_autoptr(GError) tmp_error = NULL; + g_autoptr (GError) tmp_error = NULL; glnx_gen_temp_name (path_tmp); - if (!glnx_file_copy_at (dfd, path, stbuf, dfd, path_tmp, copyflags, - cancellable, &tmp_error)) + if (!glnx_file_copy_at (dfd, path, stbuf, dfd, path_tmp, copyflags, cancellable, &tmp_error)) { if (g_error_matches (tmp_error, G_IO_ERROR, G_IO_ERROR_EXISTS)) continue; @@ -808,11 +740,9 @@ break_symhardlink (int dfd, * * Since: 2017.15 */ -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) { struct stat stbuf; @@ -820,7 +750,7 @@ gboolean ostree_break_hardlink (int dfd, return FALSE; if (stbuf.st_nlink <= 1) - return TRUE; /* Note early return */ + return TRUE; /* Note early return */ const GLnxFileCopyFlags copyflags = skip_xattrs ? GLNX_FILE_COPY_NOXATTRS : 0; @@ -829,12 +759,10 @@ gboolean ostree_break_hardlink (int dfd, * as glnx_file_copy_at() is documented to do an O_TMPFILE + rename() * with GLNX_FILE_COPY_OVERWRITE. */ - return glnx_file_copy_at (dfd, path, &stbuf, dfd, path, - copyflags | GLNX_FILE_COPY_OVERWRITE, + return glnx_file_copy_at (dfd, path, &stbuf, dfd, path, copyflags | GLNX_FILE_COPY_OVERWRITE, cancellable, error); else if (S_ISLNK (stbuf.st_mode)) - return break_symhardlink (dfd, path, &stbuf, copyflags, - cancellable, error); + return break_symhardlink (dfd, path, &stbuf, copyflags, cancellable, error); else return glnx_throw (error, "Unsupported type for entry '%s'", path); @@ -899,16 +827,14 @@ ostree_fs_get_all_xattrs_at (int dfd, const char *path, GCancellable *cancellabl * Compute the OSTree checksum for a given input. */ gboolean -ostree_checksum_file_from_input (GFileInfo *file_info, - GVariant *xattrs, - GInputStream *in, - OstreeObjectType objtype, - guchar **out_csum, - GCancellable *cancellable, - GError **error) +ostree_checksum_file_from_input (GFileInfo *file_info, GVariant *xattrs, GInputStream *in, + OstreeObjectType objtype, guchar **out_csum, + GCancellable *cancellable, GError **error) { - g_auto(OtChecksum) checksum = { 0, }; + g_auto (OtChecksum) checksum = { + 0, + }; ot_checksum_init (&checksum); if (OSTREE_OBJECT_TYPE_IS_META (objtype)) @@ -918,13 +844,12 @@ ostree_checksum_file_from_input (GFileInfo *file_info, } else if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY) { - g_autoptr(GVariant) dirmeta = ostree_create_directory_metadata (file_info, xattrs); - ot_checksum_update (&checksum, g_variant_get_data (dirmeta), - g_variant_get_size (dirmeta)); + g_autoptr (GVariant) dirmeta = ostree_create_directory_metadata (file_info, xattrs); + ot_checksum_update (&checksum, g_variant_get_data (dirmeta), g_variant_get_size (dirmeta)); } else { - g_autoptr(GBytes) file_header = _ostree_file_header_new (file_info, xattrs); + g_autoptr (GBytes) file_header = _ostree_file_header_new (file_info, xattrs); ot_checksum_update_bytes (&checksum, file_header); @@ -951,44 +876,40 @@ ostree_checksum_file_from_input (GFileInfo *file_info, * Compute the OSTree checksum for a given file. */ gboolean -ostree_checksum_file (GFile *f, - OstreeObjectType objtype, - guchar **out_csum, - GCancellable *cancellable, - GError **error) +ostree_checksum_file (GFile *f, OstreeObjectType objtype, guchar **out_csum, + GCancellable *cancellable, GError **error) { if (g_cancellable_set_error_if_cancelled (cancellable, error)) return FALSE; - g_autoptr(GFileInfo) file_info = - g_file_query_info (f, OSTREE_GIO_FAST_QUERYINFO, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - cancellable, error); + g_autoptr (GFileInfo) file_info = g_file_query_info ( + f, OSTREE_GIO_FAST_QUERYINFO, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!file_info) return FALSE; - g_autoptr(GInputStream) in = NULL; + g_autoptr (GInputStream) in = NULL; if (g_file_info_get_file_type (file_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_autoptr(GVariant) xattrs = NULL; + g_autoptr (GVariant) xattrs = NULL; if (objtype == OSTREE_OBJECT_TYPE_FILE) { - xattrs = ostree_fs_get_all_xattrs_at (AT_FDCWD, gs_file_get_path_cached (f), cancellable, error); + xattrs + = ostree_fs_get_all_xattrs_at (AT_FDCWD, gs_file_get_path_cached (f), cancellable, error); if (!xattrs) return FALSE; } g_autofree guchar *ret_csum = NULL; - if (!ostree_checksum_file_from_input (file_info, xattrs, in, objtype, - &ret_csum, cancellable, error)) + if (!ostree_checksum_file_from_input (file_info, xattrs, in, objtype, &ret_csum, cancellable, + error)) return FALSE; - ot_transfer_out_value(out_csum, &ret_csum); + ot_transfer_out_value (out_csum, &ret_csum); return TRUE; } @@ -1010,14 +931,9 @@ ostree_checksum_file (GFile *f, * Since: 2017.13 */ 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_checksum_file_at (int dfd, const char *path, struct stat *stbuf, OstreeObjectType objtype, + OstreeChecksumFlags flags, char **out_checksum, GCancellable *cancellable, + GError **error) { g_return_val_if_fail (out_checksum != NULL, FALSE); @@ -1032,12 +948,11 @@ ostree_checksum_file_at (int dfd, return FALSE; } - g_autoptr(GFileInfo) file_info = _ostree_stbuf_to_gfileinfo (stbuf); + g_autoptr (GFileInfo) file_info = _ostree_stbuf_to_gfileinfo (stbuf); - const gboolean canonicalize_perms = - ((flags & OSTREE_CHECKSUM_FLAGS_CANONICAL_PERMISSIONS) != 0); + const gboolean canonicalize_perms = ((flags & OSTREE_CHECKSUM_FLAGS_CANONICAL_PERMISSIONS) != 0); - g_autoptr(GInputStream) in = NULL; + g_autoptr (GInputStream) in = NULL; if (S_ISREG (stbuf->st_mode)) { glnx_autofd int fd = -1; @@ -1056,10 +971,9 @@ ostree_checksum_file_at (int dfd, return FALSE; } - const gboolean ignore_xattrs = - ((flags & OSTREE_CHECKSUM_FLAGS_IGNORE_XATTRS) > 0); + const gboolean ignore_xattrs = ((flags & OSTREE_CHECKSUM_FLAGS_IGNORE_XATTRS) > 0); - g_autoptr(GVariant) xattrs = NULL; + g_autoptr (GVariant) xattrs = NULL; if (!ignore_xattrs && objtype == OSTREE_OBJECT_TYPE_FILE) { if (!glnx_dfd_name_get_all_xattrs (dfd, path, &xattrs, cancellable, error)) @@ -1067,25 +981,23 @@ ostree_checksum_file_at (int dfd, } g_autofree guchar *csum_bytes = NULL; - if (!ostree_checksum_file_from_input (file_info, xattrs, in, objtype, - &csum_bytes, cancellable, error)) + if (!ostree_checksum_file_from_input (file_info, xattrs, in, objtype, &csum_bytes, cancellable, + error)) return FALSE; *out_checksum = ostree_checksum_from_bytes (csum_bytes); return TRUE; } -typedef struct { - GFile *f; +typedef struct +{ + GFile *f; OstreeObjectType objtype; guchar *csum; } ChecksumFileAsyncData; static void -checksum_file_async_thread (GTask *task, - GObject *object, - gpointer datap, - GCancellable *cancellable) +checksum_file_async_thread (GTask *task, GObject *object, gpointer datap, GCancellable *cancellable) { GError *error = NULL; ChecksumFileAsyncData *data = datap; @@ -1123,14 +1035,11 @@ checksum_file_async_data_free (gpointer datap) * complete with ostree_checksum_file_async_finish(). */ void -ostree_checksum_file_async (GFile *f, - OstreeObjectType objtype, - int io_priority, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_autoptr(GTask) task = NULL; +ostree_checksum_file_async (GFile *f, OstreeObjectType objtype, int io_priority, + GCancellable *cancellable, GAsyncReadyCallback callback, + gpointer user_data) +{ + g_autoptr (GTask) task = NULL; ChecksumFileAsyncData *data; data = g_new0 (ChecksumFileAsyncData, 1); @@ -1155,10 +1064,8 @@ ostree_checksum_file_async (GFile *f, * ostree_checksum_file_async(). */ gboolean -ostree_checksum_file_async_finish (GFile *f, - GAsyncResult *result, - guchar **out_csum, - GError **error) +ostree_checksum_file_async_finish (GFile *f, GAsyncResult *result, guchar **out_csum, + GError **error) { ChecksumFileAsyncData *data; @@ -1183,15 +1090,12 @@ ostree_checksum_file_async_finish (GFile *f, * error message. */ gboolean -_ostree_compare_object_checksum (OstreeObjectType objtype, - const char *expected, - const char *actual, - GError **error) +_ostree_compare_object_checksum (OstreeObjectType objtype, const char *expected, const char *actual, + GError **error) { if (!g_str_equal (expected, actual)) return glnx_throw (error, "Corrupted %s object; checksum expected='%s' actual='%s'", - ostree_object_type_to_string (objtype), - expected, actual); + ostree_object_type_to_string (objtype), expected, actual); return TRUE; } @@ -1203,16 +1107,15 @@ _ostree_compare_object_checksum (OstreeObjectType objtype, * Returns: (transfer full) (not nullable): A new #GVariant containing %OSTREE_OBJECT_TYPE_DIR_META */ GVariant * -ostree_create_directory_metadata (GFileInfo *dir_info, - GVariant *xattrs) +ostree_create_directory_metadata (GFileInfo *dir_info, GVariant *xattrs) { GVariant *ret_metadata = NULL; - ret_metadata = g_variant_new ("(uuu@a(ayay))", - GUINT32_TO_BE (g_file_info_get_attribute_uint32 (dir_info, "unix::uid")), - GUINT32_TO_BE (g_file_info_get_attribute_uint32 (dir_info, "unix::gid")), - GUINT32_TO_BE (g_file_info_get_attribute_uint32 (dir_info, "unix::mode")), - xattrs ? xattrs : g_variant_new_array (G_VARIANT_TYPE ("(ayay)"), NULL, 0)); + ret_metadata = g_variant_new ( + "(uuu@a(ayay))", GUINT32_TO_BE (g_file_info_get_attribute_uint32 (dir_info, "unix::uid")), + GUINT32_TO_BE (g_file_info_get_attribute_uint32 (dir_info, "unix::gid")), + GUINT32_TO_BE (g_file_info_get_attribute_uint32 (dir_info, "unix::mode")), + xattrs ? xattrs : g_variant_new_array (G_VARIANT_TYPE ("(ayay)"), NULL, 0)); g_variant_ref_sink (ret_metadata); return ret_metadata; @@ -1230,11 +1133,8 @@ ostree_create_directory_metadata (GFileInfo *dir_info, * where we override existing files via tempfile+rename(). */ gboolean -_ostree_make_temporary_symlink_at (int tmp_dirfd, - const char *target, - char **out_name, - GCancellable *cancellable, - GError **error) +_ostree_make_temporary_symlink_at (int tmp_dirfd, const char *target, char **out_name, + GCancellable *cancellable, GError **error) { g_autofree char *tmpname = g_strdup ("tmplink.XXXXXX"); const int max_attempts = 128; @@ -1261,7 +1161,6 @@ _ostree_make_temporary_symlink_at (int tmp_dirfd, return TRUE; } - /** * ostree_object_type_to_string: * @objtype: an #OstreeObjectType @@ -1336,8 +1235,7 @@ ostree_object_type_from_string (const char *str) * Returns: A string containing both @checksum and a stringifed version of @objtype */ char * -ostree_object_to_string (const char *checksum, - OstreeObjectType objtype) +ostree_object_to_string (const char *checksum, OstreeObjectType objtype) { return g_strconcat (checksum, ".", ostree_object_type_to_string (objtype), NULL); } @@ -1351,9 +1249,7 @@ ostree_object_to_string (const char *checksum, * Reverse ostree_object_to_string(). */ void -ostree_object_from_string (const char *str, - gchar **out_checksum, - OstreeObjectType *out_objtype) +ostree_object_from_string (const char *str, gchar **out_checksum, OstreeObjectType *out_objtype) { const char *dot; @@ -1378,7 +1274,7 @@ ostree_hash_object_name (gconstpointer a) gint objtype_int; ostree_object_name_deserialize (variant, &checksum, &objtype); - objtype_int = (gint) objtype; + objtype_int = (gint)objtype; return g_str_hash (checksum) + g_int_hash (&objtype_int); } @@ -1390,8 +1286,7 @@ ostree_hash_object_name (gconstpointer a) * Compare two binary checksums, using memcmp(). */ int -ostree_cmp_checksum_bytes (const guchar *a, - const guchar *b) +ostree_cmp_checksum_bytes (const guchar *a, const guchar *b) { return memcmp (a, b, OSTREE_SHA256_DIGEST_LEN); } @@ -1404,11 +1299,9 @@ ostree_cmp_checksum_bytes (const guchar *a, * Returns: (transfer floating): A new floating #GVariant containing checksum string and objtype */ GVariant * -ostree_object_name_serialize (const char *checksum, - OstreeObjectType objtype) +ostree_object_name_serialize (const char *checksum, OstreeObjectType objtype) { - g_assert (objtype >= OSTREE_OBJECT_TYPE_FILE - && objtype <= OSTREE_OBJECT_TYPE_LAST); + g_assert (objtype >= OSTREE_OBJECT_TYPE_FILE && objtype <= OSTREE_OBJECT_TYPE_LAST); return g_variant_new ("(su)", checksum, (guint32)objtype); } @@ -1422,8 +1315,7 @@ ostree_object_name_serialize (const char *checksum, * only valid for the lifetime of @variant, and must not be freed. */ void -ostree_object_name_deserialize (GVariant *variant, - const char **out_checksum, +ostree_object_name_deserialize (GVariant *variant, const char **out_checksum, OstreeObjectType *out_objtype) { guint32 objtype_u32; @@ -1439,8 +1331,7 @@ ostree_object_name_deserialize (GVariant *variant, * Overwrite the contents of @buf with stringified version of @csum. */ void -ostree_checksum_b64_inplace_to_bytes (const char *checksum, - guchar *buf) +ostree_checksum_b64_inplace_to_bytes (const char *checksum, guchar *buf) { int state = 0; guint save = 0; @@ -1457,7 +1348,7 @@ ostree_checksum_b64_inplace_to_bytes (const char *checksum, } tmpbuf[43] = '='; - g_base64_decode_step (tmpbuf, sizeof (tmpbuf), (guchar *) buf, &state, &save); + g_base64_decode_step (tmpbuf, sizeof (tmpbuf), (guchar *)buf, &state, &save); } /** @@ -1469,8 +1360,7 @@ ostree_checksum_b64_inplace_to_bytes (const char *checksum, * allocating memory. Use this function in hot code paths. */ void -ostree_checksum_inplace_to_bytes (const char *checksum, - guchar *buf) +ostree_checksum_inplace_to_bytes (const char *checksum, guchar *buf) { guint i; guint j; @@ -1480,10 +1370,10 @@ ostree_checksum_inplace_to_bytes (const char *checksum, gint big, little; g_assert (checksum[j]); - g_assert (checksum[j+1]); + g_assert (checksum[j + 1]); big = g_ascii_xdigit_value (checksum[j]); - little = g_ascii_xdigit_value (checksum[j+1]); + little = g_ascii_xdigit_value (checksum[j + 1]); g_assert (big != -1); g_assert (little != -1); @@ -1496,7 +1386,8 @@ ostree_checksum_inplace_to_bytes (const char *checksum, * ostree_checksum_to_bytes: * @checksum: An ASCII checksum * - * Returns: (transfer full) (array fixed-size=32): Binary checksum from @checksum of length 32; free with g_free(). + * Returns: (transfer full) (array fixed-size=32): Binary checksum from @checksum of length 32; + * free with g_free(). */ guchar * ostree_checksum_to_bytes (const char *checksum) @@ -1517,7 +1408,7 @@ ostree_checksum_to_bytes_v (const char *checksum) { guchar result[OSTREE_SHA256_DIGEST_LEN]; ostree_checksum_inplace_to_bytes (checksum, result); - return ot_gvariant_new_bytearray ((guchar*)result, OSTREE_SHA256_DIGEST_LEN); + return ot_gvariant_new_bytearray ((guchar *)result, OSTREE_SHA256_DIGEST_LEN); } /** @@ -1544,8 +1435,7 @@ ostree_checksum_b64_to_bytes (const char *checksum) * Overwrite the contents of @buf with stringified version of @csum. */ void -ostree_checksum_inplace_from_bytes (const guchar *csum, - char *buf) +ostree_checksum_inplace_from_bytes (const guchar *csum, char *buf) { ot_bin2hex (buf, csum, OSTREE_SHA256_DIGEST_LEN); } @@ -1560,8 +1450,7 @@ ostree_checksum_inplace_from_bytes (const guchar *csum, * character is used. */ void -ostree_checksum_b64_inplace_from_bytes (const guchar *csum, - char *buf) +ostree_checksum_b64_inplace_from_bytes (const guchar *csum, char *buf) { char tmpbuf[44]; int save = 0; @@ -1574,7 +1463,7 @@ ostree_checksum_b64_inplace_from_bytes (const guchar *csum, * to replace the '/' with '_'. */ outlen = g_base64_encode_step (csum, OSTREE_SHA256_DIGEST_LEN, FALSE, tmpbuf, &state, &save); - outlen += g_base64_encode_close (FALSE, tmpbuf+outlen, &state, &save); + outlen += g_base64_encode_close (FALSE, tmpbuf + outlen, &state, &save); g_assert (outlen == 44); for (i = 0; i < sizeof (tmpbuf); i++) @@ -1601,7 +1490,7 @@ ostree_checksum_b64_inplace_from_bytes (const guchar *csum, char * ostree_checksum_from_bytes (const guchar *csum) { - char *ret = g_malloc (OSTREE_SHA256_STRING_LEN+1); + char *ret = g_malloc (OSTREE_SHA256_STRING_LEN + 1); ostree_checksum_inplace_from_bytes (csum, ret); return ret; } @@ -1641,7 +1530,8 @@ ostree_checksum_b64_from_bytes (const guchar *csum) * ostree_checksum_bytes_peek: * @bytes: #GVariant of type ay * - * Returns: (transfer none) (array fixed-size=32) (element-type guint8): Binary checksum data in @bytes; do not free. If @bytes does not have the correct length, return %NULL. + * Returns: (transfer none) (array fixed-size=32) (element-type guint8): Binary checksum data in + * @bytes; do not free. If @bytes does not have the correct length, return %NULL. */ const guchar * ostree_checksum_bytes_peek (GVariant *bytes) @@ -1664,15 +1554,14 @@ ostree_checksum_bytes_peek (GVariant *bytes) * Returns: (transfer none) (array fixed-size=32) (element-type guint8): Binary checksum data */ const guchar * -ostree_checksum_bytes_peek_validate (GVariant *bytes, - GError **error) +ostree_checksum_bytes_peek_validate (GVariant *bytes, GError **error) { const guchar *ret = ostree_checksum_bytes_peek (bytes); if (G_UNLIKELY (!ret)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Invalid checksum of length %" G_GUINT64_FORMAT - " expected 32", (guint64) g_variant_n_children (bytes)); + "Invalid checksum of length %" G_GUINT64_FORMAT " expected 32", + (guint64)g_variant_n_children (bytes)); return NULL; } return ret; @@ -1689,17 +1578,14 @@ ostree_checksum_bytes_peek_validate (GVariant *bytes, * object. */ void -_ostree_loose_path (char *buf, - const char *checksum, - OstreeObjectType objtype, - OstreeRepoMode mode) +_ostree_loose_path (char *buf, const char *checksum, OstreeObjectType objtype, OstreeRepoMode mode) { *buf = checksum[0]; buf++; *buf = checksum[1]; buf++; - snprintf (buf, _OSTREE_LOOSE_PATH_MAX - 2, "/%s.%s%s", - checksum + 2, ostree_object_type_to_string (objtype), + snprintf (buf, _OSTREE_LOOSE_PATH_MAX - 2, "/%s.%s%s", checksum + 2, + ostree_object_type_to_string (objtype), (!OSTREE_OBJECT_TYPE_IS_META (objtype) && mode == OSTREE_REPO_MODE_ARCHIVE) ? "z" : ""); } @@ -1728,7 +1614,7 @@ _ostree_stbuf_to_gfileinfo (const struct stat *stbuf) ftype = G_FILE_TYPE_REGULAR; else if (S_ISLNK (mode)) ftype = G_FILE_TYPE_SYMBOLIC_LINK; - else if (S_ISBLK (mode) || S_ISCHR(mode) || S_ISFIFO(mode)) + else if (S_ISBLK (mode) || S_ISCHR (mode) || S_ISFIFO (mode)) ftype = G_FILE_TYPE_SPECIAL; else ftype = G_FILE_TYPE_UNKNOWN; @@ -1758,10 +1644,11 @@ _ostree_stbuf_to_gfileinfo (const struct stat *stbuf) * Map GFileInfo data from @file_info onto @out_stbuf. */ void -_ostree_gfileinfo_to_stbuf (GFileInfo *file_info, - struct stat *out_stbuf) +_ostree_gfileinfo_to_stbuf (GFileInfo *file_info, struct stat *out_stbuf) { - struct stat stbuf = {0,}; + struct stat stbuf = { + 0, + }; stbuf.st_mode = g_file_info_get_attribute_uint32 (file_info, "unix::mode"); stbuf.st_uid = g_file_info_get_attribute_uint32 (file_info, "unix::uid"); stbuf.st_gid = g_file_info_get_attribute_uint32 (file_info, "unix::gid"); @@ -1789,10 +1676,13 @@ _ostree_gfileinfo_equal (GFileInfo *a, GFileInfo *b) return TRUE; #define CHECK_ONE_ATTR(type, attr, a, b) \ - do { if (g_file_info_get_attribute_##type(a, attr) != \ - g_file_info_get_attribute_##type(b, attr)) \ - return FALSE; \ - } while (0) + do \ + { \ + if (g_file_info_get_attribute_##type (a, attr) \ + != g_file_info_get_attribute_##type (b, attr)) \ + return FALSE; \ + } \ + while (0) CHECK_ONE_ATTR (uint32, "unix::uid", a, b); CHECK_ONE_ATTR (uint32, "unix::gid", a, b); @@ -1829,7 +1719,9 @@ _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) { - struct stat stbuf = { 0, }; + struct stat stbuf = { + 0, + }; stbuf.st_mode = mode; stbuf.st_uid = uid; stbuf.st_gid = gid; @@ -1845,9 +1737,7 @@ _ostree_mode_uidgid_to_gfileinfo (mode_t mode, uid_t uid, gid_t gid) * Returns: (transfer full): Relative path for a loose object */ char * -_ostree_get_relative_object_path (const char *checksum, - OstreeObjectType type, - gboolean compressed) +_ostree_get_relative_object_path (const char *checksum, OstreeObjectType type, gboolean compressed) { GString *path; @@ -1867,9 +1757,7 @@ _ostree_get_relative_object_path (const char *checksum, } static GString * -static_delta_path_base (const char *dir, - const char *from, - const char *to) +static_delta_path_base (const char *dir, const char *from, const char *to) { guint8 csum_to[OSTREE_SHA256_DIGEST_LEN]; char to_b64[44]; @@ -1907,9 +1795,7 @@ static_delta_path_base (const char *dir, } char * -_ostree_get_relative_static_delta_path (const char *from, - const char *to, - const char *target) +_ostree_get_relative_static_delta_path (const char *from, const char *to, const char *target) { GString *ret = static_delta_path_base ("deltas/", from, to); @@ -1923,23 +1809,19 @@ _ostree_get_relative_static_delta_path (const char *from, } char * -_ostree_get_relative_static_delta_superblock_path (const char *from, - const char *to) +_ostree_get_relative_static_delta_superblock_path (const char *from, const char *to) { return _ostree_get_relative_static_delta_path (from, to, "superblock"); } char * -_ostree_get_relative_static_delta_detachedmeta_path (const char *from, - const char *to) +_ostree_get_relative_static_delta_detachedmeta_path (const char *from, const char *to) { return _ostree_get_relative_static_delta_path (from, to, "meta"); } char * -_ostree_get_relative_static_delta_part_path (const char *from, - const char *to, - guint i) +_ostree_get_relative_static_delta_part_path (const char *from, const char *to, guint i) { g_autofree char *partstr = g_strdup_printf ("%u", i); return _ostree_get_relative_static_delta_path (from, to, partstr); @@ -1956,12 +1838,9 @@ _ostree_get_relative_static_delta_index_path (const char *to) } gboolean -_ostree_parse_delta_name (const char *delta_name, - char **out_from, - char **out_to, - GError **error) +_ostree_parse_delta_name (const char *delta_name, char **out_from, char **out_to, GError **error) { - g_auto(GStrv) parts = NULL; + g_auto (GStrv) parts = NULL; g_return_val_if_fail (delta_name != NULL, FALSE); parts = g_strsplit (delta_name, "-", 2); @@ -1972,8 +1851,7 @@ _ostree_parse_delta_name (const char *delta_name, if (!ostree_validate_checksum_string (parts[0] ?: "", error)) return FALSE; - if (parts[0] && parts[1] && - !ostree_validate_checksum_string (parts[1], error)) + if (parts[0] && parts[1] && !ostree_validate_checksum_string (parts[1], error)) return FALSE; *out_from = *out_to = NULL; @@ -2001,25 +1879,22 @@ _ostree_parse_delta_name (const char *delta_name, * along with extended attributes tored in @out_xattrs. */ static gboolean -file_header_parse (GVariant *metadata, - GFileInfo **out_file_info, - GVariant **out_xattrs, - GError **error) +file_header_parse (GVariant *metadata, GFileInfo **out_file_info, GVariant **out_xattrs, + GError **error) { guint32 uid, gid, mode, rdev; const char *symlink_target; - g_autoptr(GVariant) ret_xattrs = NULL; + g_autoptr (GVariant) ret_xattrs = NULL; - g_variant_get (metadata, "(uuuu&s@a(ayay))", - &uid, &gid, &mode, &rdev, - &symlink_target, &ret_xattrs); + g_variant_get (metadata, "(uuuu&s@a(ayay))", &uid, &gid, &mode, &rdev, &symlink_target, + &ret_xattrs); if (rdev != 0) return glnx_throw (error, "Corrupted archive file; invalid rdev %u", GUINT32_FROM_BE (rdev)); uid = GUINT32_FROM_BE (uid); gid = GUINT32_FROM_BE (gid); mode = GUINT32_FROM_BE (mode); - g_autoptr(GFileInfo) ret_file_info = _ostree_mode_uidgid_to_gfileinfo (mode, uid, gid); + g_autoptr (GFileInfo) ret_file_info = _ostree_mode_uidgid_to_gfileinfo (mode, uid, gid); if (S_ISREG (mode)) { @@ -2027,15 +1902,16 @@ file_header_parse (GVariant *metadata, } else if (S_ISLNK (mode)) { - g_file_info_set_attribute_byte_string (ret_file_info, "standard::symlink-target", symlink_target); + g_file_info_set_attribute_byte_string (ret_file_info, "standard::symlink-target", + symlink_target); } else { return glnx_throw (error, "Corrupted archive file; invalid mode %u", mode); } - ot_transfer_out_value(out_file_info, &ret_file_info); - ot_transfer_out_value(out_xattrs, &ret_xattrs); + ot_transfer_out_value (out_file_info, &ret_file_info); + ot_transfer_out_value (out_xattrs, &ret_xattrs); return TRUE; } @@ -2050,26 +1926,23 @@ file_header_parse (GVariant *metadata, * content. */ static gboolean -zlib_file_header_parse (GVariant *metadata, - GFileInfo **out_file_info, - GVariant **out_xattrs, - GError **error) +zlib_file_header_parse (GVariant *metadata, GFileInfo **out_file_info, GVariant **out_xattrs, + GError **error) { guint64 size; guint32 uid, gid, mode, rdev; const char *symlink_target; - g_autoptr(GVariant) ret_xattrs = NULL; + g_autoptr (GVariant) ret_xattrs = NULL; - g_variant_get (metadata, "(tuuuu&s@a(ayay))", &size, - &uid, &gid, &mode, &rdev, - &symlink_target, &ret_xattrs); + g_variant_get (metadata, "(tuuuu&s@a(ayay))", &size, &uid, &gid, &mode, &rdev, &symlink_target, + &ret_xattrs); if (rdev != 0) return glnx_throw (error, "Corrupted archive file; invalid rdev %u", GUINT32_FROM_BE (rdev)); uid = GUINT32_FROM_BE (uid); gid = GUINT32_FROM_BE (gid); mode = GUINT32_FROM_BE (mode); - g_autoptr(GFileInfo) ret_file_info = _ostree_mode_uidgid_to_gfileinfo (mode, uid, gid); + g_autoptr (GFileInfo) ret_file_info = _ostree_mode_uidgid_to_gfileinfo (mode, uid, gid); g_file_info_set_size (ret_file_info, GUINT64_FROM_BE (size)); if (S_ISREG (mode)) @@ -2078,15 +1951,16 @@ zlib_file_header_parse (GVariant *metadata, } else if (S_ISLNK (mode)) { - g_file_info_set_attribute_byte_string (ret_file_info, "standard::symlink-target", symlink_target); + g_file_info_set_attribute_byte_string (ret_file_info, "standard::symlink-target", + symlink_target); } else { return glnx_throw (error, "Corrupted archive file; invalid mode %u", mode); } - ot_transfer_out_value(out_file_info, &ret_file_info); - ot_transfer_out_value(out_xattrs, &ret_xattrs); + ot_transfer_out_value (out_file_info, &ret_file_info); + ot_transfer_out_value (out_xattrs, &ret_xattrs); return TRUE; } @@ -2098,12 +1972,10 @@ zlib_file_header_parse (GVariant *metadata, * Returns: %TRUE if @objtype represents a valid object type */ gboolean -ostree_validate_structureof_objtype (guchar objtype, - GError **error) +ostree_validate_structureof_objtype (guchar objtype, GError **error) { - OstreeObjectType objtype_v = (OstreeObjectType) objtype; - if (objtype_v < OSTREE_OBJECT_TYPE_FILE - || objtype_v > OSTREE_OBJECT_TYPE_COMMIT) + OstreeObjectType objtype_v = (OstreeObjectType)objtype; + if (objtype_v < OSTREE_OBJECT_TYPE_FILE || objtype_v > OSTREE_OBJECT_TYPE_COMMIT) return glnx_throw (error, "Invalid object type '%u'", objtype); return TRUE; } @@ -2116,8 +1988,7 @@ ostree_validate_structureof_objtype (guchar objtype, * Returns: %TRUE if @checksum is a valid binary SHA256 checksum */ gboolean -ostree_validate_structureof_csum_v (GVariant *checksum, - GError **error) +ostree_validate_structureof_csum_v (GVariant *checksum, GError **error) { return ostree_checksum_bytes_peek_validate (checksum, error) != NULL; } @@ -2130,8 +2001,7 @@ ostree_validate_structureof_csum_v (GVariant *checksum, * Returns: %TRUE if @checksum is a valid ASCII SHA256 checksum */ gboolean -ostree_validate_structureof_checksum_string (const char *checksum, - GError **error) +ostree_validate_structureof_checksum_string (const char *checksum, GError **error) { int i = 0; size_t len = strlen (checksum); @@ -2142,20 +2012,18 @@ ostree_validate_structureof_checksum_string (const char *checksum, * dump it all to the error. * https://github.com/projectatomic/rpm-ostree/issues/885 */ - g_autofree char *sanitized = quash_string_for_error_message (checksum, len, - OSTREE_SHA256_STRING_LEN); + g_autofree char *sanitized + = quash_string_for_error_message (checksum, len, OSTREE_SHA256_STRING_LEN); return glnx_throw (error, "Invalid rev %s", sanitized); } for (i = 0; i < len; i++) { - guint8 c = ((guint8*) checksum)[i]; + guint8 c = ((guint8 *)checksum)[i]; - if (!((c >= 48 && c <= 57) - || (c >= 97 && c <= 102))) + if (!((c >= 48 && c <= 57) || (c >= 97 && c <= 102))) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Invalid character '%d' in rev '%s'", + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid character '%d' in rev '%s'", c, checksum); return FALSE; } @@ -2164,9 +2032,7 @@ ostree_validate_structureof_checksum_string (const char *checksum, } static gboolean -validate_variant (GVariant *variant, - const GVariantType *variant_type, - GError **error) +validate_variant (GVariant *variant, const GVariantType *variant_type, GError **error) { if (!g_variant_is_normal_form (variant)) { @@ -2174,8 +2040,7 @@ validate_variant (GVariant *variant, } if (!g_variant_is_of_type (variant, variant_type)) { - return glnx_throw (error, "Doesn't match variant type '%s'", - (char *)variant_type); + return glnx_throw (error, "Doesn't match variant type '%s'", (char *)variant_type); } return TRUE; } @@ -2184,9 +2049,7 @@ validate_variant (GVariant *variant, * commit/dirtree/dirmeta verifiers. */ gboolean -_ostree_validate_structureof_metadata (OstreeObjectType objtype, - GVariant *metadata, - GError **error) +_ostree_validate_structureof_metadata (OstreeObjectType objtype, GVariant *metadata, GError **error) { g_assert (OSTREE_OBJECT_TYPE_IS_META (objtype)); @@ -2225,25 +2088,27 @@ _ostree_validate_structureof_metadata (OstreeObjectType objtype, * one is checking for path traversal in dirtree objects. */ gboolean -_ostree_verify_metadata_object (OstreeObjectType objtype, - const char *expected_checksum, - GVariant *metadata, - GError **error) +_ostree_verify_metadata_object (OstreeObjectType objtype, const char *expected_checksum, + GVariant *metadata, GError **error) { g_assert (expected_checksum); - g_auto(OtChecksum) hasher = { 0, }; + g_auto (OtChecksum) hasher = { + 0, + }; ot_checksum_init (&hasher); ot_checksum_update (&hasher, g_variant_get_data (metadata), g_variant_get_size (metadata)); - char actual_checksum[OSTREE_SHA256_STRING_LEN+1]; + char actual_checksum[OSTREE_SHA256_STRING_LEN + 1]; ot_checksum_get_hexdigest (&hasher, actual_checksum, sizeof (actual_checksum)); if (!_ostree_compare_object_checksum (objtype, expected_checksum, actual_checksum, error)) return FALSE; /* Add the checksum + objtype prefix here */ - { const char *error_prefix = glnx_strjoina (expected_checksum, ".", ostree_object_type_to_string (objtype)); - GLNX_AUTO_PREFIX_ERROR(error_prefix, error); + { + const char *error_prefix + = glnx_strjoina (expected_checksum, ".", ostree_object_type_to_string (objtype)); + GLNX_AUTO_PREFIX_ERROR (error_prefix, error); if (!_ostree_validate_structureof_metadata (objtype, metadata, error)) return FALSE; } @@ -2262,18 +2127,17 @@ _ostree_verify_metadata_object (OstreeObjectType objtype, * Returns: %TRUE if @commit is structurally valid */ gboolean -ostree_validate_structureof_commit (GVariant *commit, - GError **error) +ostree_validate_structureof_commit (GVariant *commit, GError **error) { if (!validate_variant (commit, OSTREE_COMMIT_GVARIANT_FORMAT, error)) return FALSE; - g_autoptr(GVariant) metadata = NULL; + g_autoptr (GVariant) metadata = NULL; g_variant_get_child (commit, 0, "@a{sv}", &metadata); g_assert (metadata != NULL); - g_autoptr(GVariantIter) metadata_iter = g_variant_iter_new (metadata); + g_autoptr (GVariantIter) metadata_iter = g_variant_iter_new (metadata); g_assert (metadata_iter != NULL); - g_autoptr(GVariant) metadata_entry = NULL; + g_autoptr (GVariant) metadata_entry = NULL; const gchar *metadata_key = NULL; while (g_variant_iter_loop (metadata_iter, "{sv}", &metadata_key, NULL)) { @@ -2281,22 +2145,22 @@ ostree_validate_structureof_commit (GVariant *commit, return glnx_throw (error, "Empty metadata key"); } - g_autoptr(GVariant) parent_csum_v = NULL; + g_autoptr (GVariant) parent_csum_v = NULL; g_variant_get_child (commit, 1, "@ay", &parent_csum_v); gsize n_elts; - (void) g_variant_get_fixed_array (parent_csum_v, &n_elts, 1); + (void)g_variant_get_fixed_array (parent_csum_v, &n_elts, 1); if (n_elts > 0) { if (!ostree_validate_structureof_csum_v (parent_csum_v, error)) return FALSE; } - g_autoptr(GVariant) content_csum_v = NULL; + g_autoptr (GVariant) content_csum_v = NULL; g_variant_get_child (commit, 6, "@ay", &content_csum_v); if (!ostree_validate_structureof_csum_v (content_csum_v, error)) return FALSE; - g_autoptr(GVariant) metadata_csum_v = NULL; + g_autoptr (GVariant) metadata_csum_v = NULL; g_variant_get_child (commit, 7, "@ay", &metadata_csum_v); if (!ostree_validate_structureof_csum_v (metadata_csum_v, error)) return FALSE; @@ -2315,21 +2179,19 @@ ostree_validate_structureof_commit (GVariant *commit, * Returns: %TRUE if @dirtree is structurally valid */ gboolean -ostree_validate_structureof_dirtree (GVariant *dirtree, - GError **error) +ostree_validate_structureof_dirtree (GVariant *dirtree, GError **error) { const char *filename; - g_autoptr(GVariant) content_csum_v = NULL; - g_autoptr(GVariant) meta_csum_v = NULL; - g_autoptr(GVariantIter) contents_iter = NULL; + g_autoptr (GVariant) content_csum_v = NULL; + g_autoptr (GVariant) meta_csum_v = NULL; + g_autoptr (GVariantIter) contents_iter = NULL; if (!validate_variant (dirtree, OSTREE_TREE_GVARIANT_FORMAT, error)) return FALSE; g_variant_get_child (dirtree, 0, "a(say)", &contents_iter); - while (g_variant_iter_loop (contents_iter, "(&s@ay)", - &filename, &content_csum_v)) + while (g_variant_iter_loop (contents_iter, "(&s@ay)", &filename, &content_csum_v)) { if (!ot_util_filename_validate (filename, error)) return FALSE; @@ -2344,8 +2206,8 @@ ostree_validate_structureof_dirtree (GVariant *dirtree, g_variant_iter_free (contents_iter); g_variant_get_child (dirtree, 1, "a(sayay)", &contents_iter); - while (g_variant_iter_loop (contents_iter, "(&s@ay@ay)", - &filename, &content_csum_v, &meta_csum_v)) + while ( + g_variant_iter_loop (contents_iter, "(&s@ay@ay)", &filename, &content_csum_v, &meta_csum_v)) { if (!ot_util_filename_validate (filename, error)) return FALSE; @@ -2364,16 +2226,14 @@ ostree_validate_structureof_dirtree (GVariant *dirtree, * bare-user-only mode. It's opt-in though for all pulls. */ gboolean -_ostree_validate_bareuseronly_mode (guint32 content_mode, - const char *checksum, - GError **error) +_ostree_validate_bareuseronly_mode (guint32 content_mode, const char *checksum, GError **error) { if (S_ISREG (content_mode)) { const guint32 invalid_modebits = ((content_mode & ~S_IFMT) & ~0775); if (invalid_modebits > 0) - return glnx_throw (error, "Content object %s: invalid mode 0%04o with bits 0%04o", - checksum, content_mode, invalid_modebits); + return glnx_throw (error, "Content object %s: invalid mode 0%04o with bits 0%04o", checksum, + content_mode, invalid_modebits); } else if (S_ISLNK (content_mode)) ; /* Nothing */ @@ -2384,11 +2244,9 @@ _ostree_validate_bareuseronly_mode (guint32 content_mode, } static gboolean -validate_stat_mode_perms (guint32 mode, - GError **error) +validate_stat_mode_perms (guint32 mode, GError **error) { - guint32 otherbits = (~S_IFMT & ~S_IRWXU & ~S_IRWXG & ~S_IRWXO & - ~S_ISUID & ~S_ISGID & ~S_ISVTX); + guint32 otherbits = (~S_IFMT & ~S_IRWXU & ~S_IRWXG & ~S_IRWXO & ~S_ISUID & ~S_ISGID & ~S_ISVTX); if (mode & otherbits) return glnx_throw (error, "Invalid mode %u; invalid bits in mode", mode); @@ -2404,8 +2262,7 @@ validate_stat_mode_perms (guint32 mode, * Returns: %TRUE if @mode represents a valid file type and permissions */ gboolean -ostree_validate_structureof_file_mode (guint32 mode, - GError **error) +ostree_validate_structureof_file_mode (guint32 mode, GError **error) { if (!(S_ISREG (mode) || S_ISLNK (mode))) return glnx_throw (error, "Invalid file metadata mode %u; not a valid file type", mode); @@ -2426,8 +2283,7 @@ ostree_validate_structureof_file_mode (guint32 mode, * Returns: %TRUE if @dirmeta is structurally valid */ gboolean -ostree_validate_structureof_dirmeta (GVariant *dirmeta, - GError **error) +ostree_validate_structureof_dirmeta (GVariant *dirmeta, GError **error) { guint32 mode; @@ -2454,9 +2310,9 @@ ostree_validate_structureof_dirmeta (GVariant *dirmeta, * if none */ gchar * -ostree_commit_get_parent (GVariant *commit_variant) +ostree_commit_get_parent (GVariant *commit_variant) { - g_autoptr(GVariant) bytes = NULL; + g_autoptr (GVariant) bytes = NULL; bytes = g_variant_get_child_value (commit_variant, 1); if (g_variant_n_children (bytes) == 0) return NULL; @@ -2471,14 +2327,13 @@ ostree_commit_get_parent (GVariant *commit_variant) * Since: 2016.3 */ guint64 -ostree_commit_get_timestamp (GVariant *commit_variant) +ostree_commit_get_timestamp (GVariant *commit_variant) { guint64 ret; g_variant_get_child (commit_variant, 5, "t", &ret); return GUINT64_FROM_BE (ret); } - /** * ostree_commit_get_content_checksum: * @commit_variant: A commit object @@ -2491,9 +2346,9 @@ ostree_commit_get_timestamp (GVariant *commit_variant) * By comparing checksums of content, it's possible to easily distinguish * cases where nothing actually changed. * - * The content checksums is simply defined as `SHA256(root dirtree_checksum || root_dirmeta_checksum)`, - * i.e. the SHA-256 of the root "dirtree" object's checksum concatenated with the - * root "dirmeta" checksum (both in binary form, not hexadecimal). + * The content checksums is simply defined as `SHA256(root dirtree_checksum || + * root_dirmeta_checksum)`, i.e. the SHA-256 of the root "dirtree" object's checksum concatenated + * with the root "dirmeta" checksum (both in binary form, not hexadecimal). * * Returns: (nullable): A SHA-256 hex string, or %NULL if @commit_variant is not well-formed * @@ -2502,11 +2357,13 @@ ostree_commit_get_timestamp (GVariant *commit_variant) gchar * ostree_commit_get_content_checksum (GVariant *commit_variant) { - g_auto(OtChecksum) checksum = { 0, }; + g_auto (OtChecksum) checksum = { + 0, + }; ot_checksum_init (&checksum); - g_autoptr(GVariant) tree_contents_csum = NULL; - g_autoptr(GVariant) tree_meta_csum = NULL; + g_autoptr (GVariant) tree_contents_csum = NULL; + g_autoptr (GVariant) tree_meta_csum = NULL; g_variant_get_child (commit_variant, 6, "@ay", &tree_contents_csum); g_variant_get_child (commit_variant, 7, "@ay", &tree_meta_csum); @@ -2520,7 +2377,7 @@ ostree_commit_get_content_checksum (GVariant *commit_variant) if (!bytes) return NULL; ot_checksum_update (&checksum, bytes, OSTREE_SHA256_DIGEST_LEN); - char hexdigest[OSTREE_SHA256_STRING_LEN+1]; + char hexdigest[OSTREE_SHA256_STRING_LEN + 1]; ot_checksum_get_hexdigest (&checksum, hexdigest, sizeof (hexdigest)); return g_strdup (hexdigest); } @@ -2542,14 +2399,12 @@ G_DEFINE_BOXED_TYPE (OstreeCommitSizesEntry, ostree_commit_sizes_entry, * Since: 2020.1 */ OstreeCommitSizesEntry * -ostree_commit_sizes_entry_new (const gchar *checksum, - OstreeObjectType objtype, - guint64 unpacked, - guint64 archived) +ostree_commit_sizes_entry_new (const gchar *checksum, OstreeObjectType objtype, guint64 unpacked, + guint64 archived) { g_return_val_if_fail (checksum == NULL || ostree_validate_checksum_string (checksum, NULL), NULL); - g_autoptr(OstreeCommitSizesEntry) entry = g_new0 (OstreeCommitSizesEntry, 1); + g_autoptr (OstreeCommitSizesEntry) entry = g_new0 (OstreeCommitSizesEntry, 1); entry->checksum = g_strdup (checksum); entry->objtype = objtype; entry->unpacked = unpacked; @@ -2572,9 +2427,7 @@ ostree_commit_sizes_entry_copy (const OstreeCommitSizesEntry *entry) { g_return_val_if_fail (entry != NULL, NULL); - return ostree_commit_sizes_entry_new (entry->checksum, - entry->objtype, - entry->unpacked, + return ostree_commit_sizes_entry_new (entry->checksum, entry->objtype, entry->unpacked, entry->archived); } @@ -2596,9 +2449,7 @@ ostree_commit_sizes_entry_free (OstreeCommitSizesEntry *entry) } static gboolean -read_sizes_entry (GVariant *entry, - OstreeCommitSizesEntry **out_sizes, - GError **error) +read_sizes_entry (GVariant *entry, OstreeCommitSizesEntry **out_sizes, GError **error) { gsize entry_size = g_variant_get_size (entry); g_return_val_if_fail (entry_size >= OSTREE_SHA256_DIGEST_LEN + 2, FALSE); @@ -2631,8 +2482,7 @@ read_sizes_entry (GVariant *entry, { objtype = *buffer; if (objtype < OSTREE_OBJECT_TYPE_FILE || objtype > OSTREE_OBJECT_TYPE_LAST) - return glnx_throw (error, "Unexpected ostree.sizes object type %u", - objtype); + return glnx_throw (error, "Unexpected ostree.sizes object type %u", objtype); buffer++; entry_size--; } @@ -2642,10 +2492,8 @@ read_sizes_entry (GVariant *entry, objtype = OSTREE_OBJECT_TYPE_FILE; } - g_autoptr(OstreeCommitSizesEntry) sizes = ostree_commit_sizes_entry_new (checksum, - objtype, - unpacked, - archived); + g_autoptr (OstreeCommitSizesEntry) sizes + = ostree_commit_sizes_entry_new (checksum, objtype, unpacked, archived); if (out_sizes != NULL) *out_sizes = g_steal_pointer (&sizes); @@ -2669,16 +2517,14 @@ read_sizes_entry (GVariant *entry, * Since: 2020.1 */ gboolean -ostree_commit_get_object_sizes (GVariant *commit_variant, - GPtrArray **out_sizes_entries, - GError **error) +ostree_commit_get_object_sizes (GVariant *commit_variant, GPtrArray **out_sizes_entries, + GError **error) { g_return_val_if_fail (commit_variant != NULL, FALSE); - g_autoptr(GVariant) metadata = g_variant_get_child_value (commit_variant, 0); - g_autoptr(GVariant) sizes_variant = - g_variant_lookup_value (metadata, "ostree.sizes", - G_VARIANT_TYPE ("a" _OSTREE_OBJECT_SIZES_ENTRY_SIGNATURE)); + g_autoptr (GVariant) metadata = g_variant_get_child_value (commit_variant, 0); + g_autoptr (GVariant) sizes_variant = g_variant_lookup_value ( + metadata, "ostree.sizes", G_VARIANT_TYPE ("a" _OSTREE_OBJECT_SIZES_ENTRY_SIGNATURE)); if (sizes_variant == NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, @@ -2686,9 +2532,9 @@ ostree_commit_get_object_sizes (GVariant *commit_variant, return FALSE; } - g_autoptr(GPtrArray) sizes_entries = - g_ptr_array_new_with_free_func ((GDestroyNotify) ostree_commit_sizes_entry_free); - g_autoptr(GVariant) entry = NULL; + g_autoptr (GPtrArray) sizes_entries + = g_ptr_array_new_with_free_func ((GDestroyNotify)ostree_commit_sizes_entry_free); + g_autoptr (GVariant) entry = NULL; GVariantIter entry_iter; g_variant_iter_init (&entry_iter, sizes_variant); while ((entry = g_variant_iter_next_value (&entry_iter))) @@ -2708,11 +2554,8 @@ ostree_commit_get_object_sizes (GVariant *commit_variant, /* Used in pull/deploy to validate we're not being downgraded */ gboolean -_ostree_compare_timestamps (const char *current_rev, - guint64 current_ts, - const char *new_rev, - guint64 new_ts, - GError **error) +_ostree_compare_timestamps (const char *current_rev, guint64 current_ts, const char *new_rev, + guint64 new_ts, GError **error) { /* Newer timestamp is OK */ if (new_ts > current_ts) @@ -2722,44 +2565,45 @@ _ostree_compare_timestamps (const char *current_rev, return TRUE; /* Looks like a downgrade, format an error message */ - g_autoptr(GDateTime) current_dt = g_date_time_new_from_unix_utc (current_ts); - g_autoptr(GDateTime) new_dt = g_date_time_new_from_unix_utc (new_ts); + g_autoptr (GDateTime) current_dt = g_date_time_new_from_unix_utc (current_ts); + g_autoptr (GDateTime) new_dt = g_date_time_new_from_unix_utc (new_ts); if (current_dt == NULL || new_dt == NULL) - return glnx_throw (error, "Upgrade target revision '%s' timestamp (%" G_GINT64_FORMAT ") or current revision '%s' timestamp (%" G_GINT64_FORMAT ") is invalid", - new_rev, new_ts, - current_rev, current_ts); + return glnx_throw (error, + "Upgrade target revision '%s' timestamp (%" G_GINT64_FORMAT + ") or current revision '%s' timestamp (%" G_GINT64_FORMAT ") is invalid", + new_rev, new_ts, current_rev, current_ts); g_autofree char *current_ts_str = g_date_time_format (current_dt, "%c"); g_autofree char *new_ts_str = g_date_time_format (new_dt, "%c"); - return glnx_throw (error, "Upgrade target revision '%s' with timestamp '%s' is chronologically older than current revision '%s' with timestamp '%s'; use --allow-downgrade to permit", - new_rev, new_ts_str, current_rev, current_ts_str); + return glnx_throw ( + error, + "Upgrade target revision '%s' with timestamp '%s' is chronologically older than current " + "revision '%s' with timestamp '%s'; use --allow-downgrade to permit", + new_rev, new_ts_str, current_rev, current_ts_str); } - #ifndef OSTREE_DISABLE_GPGME GVariant * -_ostree_detached_metadata_append_gpg_sig (GVariant *existing_metadata, - GBytes *signature_bytes) +_ostree_detached_metadata_append_gpg_sig (GVariant *existing_metadata, GBytes *signature_bytes) { GVariantDict metadata_dict; - g_autoptr(GVariant) signature_data = NULL; - g_autoptr(GVariantBuilder) signature_builder = NULL; + g_autoptr (GVariant) signature_data = NULL; + g_autoptr (GVariantBuilder) signature_builder = NULL; g_variant_dict_init (&metadata_dict, existing_metadata); - signature_data = g_variant_dict_lookup_value (&metadata_dict, - _OSTREE_METADATA_GPGSIGS_NAME, + signature_data = g_variant_dict_lookup_value (&metadata_dict, _OSTREE_METADATA_GPGSIGS_NAME, _OSTREE_METADATA_GPGSIGS_TYPE); /* signature_data may be NULL */ - signature_builder = ot_util_variant_builder_from_variant (signature_data, _OSTREE_METADATA_GPGSIGS_TYPE); + signature_builder + = ot_util_variant_builder_from_variant (signature_data, _OSTREE_METADATA_GPGSIGS_TYPE); g_variant_builder_add (signature_builder, "@ay", ot_gvariant_new_ay_bytes (signature_bytes)); - g_variant_dict_insert_value (&metadata_dict, - _OSTREE_METADATA_GPGSIGS_NAME, + g_variant_dict_insert_value (&metadata_dict, _OSTREE_METADATA_GPGSIGS_NAME, g_variant_builder_end (signature_builder)); return g_variant_ref_sink (g_variant_dict_end (&metadata_dict)); @@ -2805,5 +2649,5 @@ _ostree_get_default_sysroot_path (void) gboolean ostree_check_version (guint required_year, guint required_release) { - return OSTREE_CHECK_VERSION(required_year, required_release); + return OSTREE_CHECK_VERSION (required_year, required_release); } diff --git a/src/libostree/ostree-core.h b/src/libostree/ostree-core.h index 0d4dca8e..b18d9e16 100644 --- a/src/libostree/ostree-core.h +++ b/src/libostree/ostree-core.h @@ -21,9 +21,9 @@ #pragma once -#include #include #include +#include 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); - -_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); - -_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); - -_OSTREE_PUBLIC -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); - -_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); - -_OSTREE_PUBLIC -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); - -_OSTREE_PUBLIC -gboolean ostree_break_hardlink (int dfd, - const char *path, - gboolean skip_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); + +_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); + +_OSTREE_PUBLIC +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); + +_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); + +_OSTREE_PUBLIC +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); + +_OSTREE_PUBLIC +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); diff --git a/src/libostree/ostree-date-utils-private.h b/src/libostree/ostree-date-utils-private.h index f48a696c..f0e24327 100644 --- a/src/libostree/ostree-date-utils-private.h +++ b/src/libostree/ostree-date-utils-private.h @@ -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 diff --git a/src/libostree/ostree-date-utils.c b/src/libostree/ostree-date-utils.c index 7c078a96..07aecd3c 100644 --- a/src/libostree/ostree-date-utils.c +++ b/src/libostree/ostree-date-utils.c @@ -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); } diff --git a/src/libostree/ostree-deployment-private.h b/src/libostree/ostree-deployment-private.h index 5d16798c..2a28bffd 100644 --- a/src/libostree/ostree-deployment-private.h +++ b/src/libostree/ostree-deployment-private.h @@ -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 diff --git a/src/libostree/ostree-deployment.c b/src/libostree/ostree-deployment.c index bfd0b2e6..1480d746 100644 --- a/src/libostree/ostree-deployment.c +++ b/src/libostree/ostree-deployment.c @@ -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)); } diff --git a/src/libostree/ostree-deployment.h b/src/libostree/ostree-deployment.h index 68a0ff77..0d4a5d7b 100644 --- a/src/libostree/ostree-deployment.h +++ b/src/libostree/ostree-deployment.h @@ -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, diff --git a/src/libostree/ostree-diff.c b/src/libostree/ostree-diff.c index d6d8e98a..9d6a719f 100644 --- a/src/libostree/ostree-diff.c +++ b/src/libostree/ostree-diff.c @@ -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; diff --git a/src/libostree/ostree-diff.h b/src/libostree/ostree-diff.h index be50c638..ba77ae6f 100644 --- a/src/libostree/ostree-diff.h +++ b/src/libostree/ostree-diff.h @@ -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 diff --git a/src/libostree/ostree-dummy-enumtypes.h b/src/libostree/ostree-dummy-enumtypes.h index 6284644d..a27ea6ba 100644 --- a/src/libostree/ostree-dummy-enumtypes.h +++ b/src/libostree/ostree-dummy-enumtypes.h @@ -24,6 +24,5 @@ #include #ifndef __GI_SCANNER__ -_OSTREE_PUBLIC GType -ostree_fetcher_config_flags_get_type (void); +_OSTREE_PUBLIC GType ostree_fetcher_config_flags_get_type (void); #endif diff --git a/src/libostree/ostree-fetcher-curl.c b/src/libostree/ostree-fetcher-curl.c index 522eacfb..d12d049a 100644 --- a/src/libostree/ostree-fetcher-curl.c +++ b/src/libostree/ostree-fetcher-curl.c @@ -20,23 +20,24 @@ #include "config.h" +#include #include #include #include -#include /* 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 */ - GHashTable *sockets; /* Set */ + GHashTable *sockets; /* Set */ 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) +_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; + 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) +_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; + 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; } diff --git a/src/libostree/ostree-fetcher-soup.c b/src/libostree/ostree-fetcher-soup.c index 638a950b..dbba2f00 100644 --- a/src/libostree/ostree-fetcher-soup.c +++ b/src/libostree/ostree-fetcher-soup.c @@ -22,35 +22,37 @@ #include "config.h" -#include #include +#include #include #define LIBSOUP_USE_UNSTABLE_REQUEST_API -#include -#include #include +#include +#include #include "libglnx.h" -#include "ostree-fetcher.h" #include "ostree-fetcher-util.h" +#include "ostree-fetcher.h" #ifdef HAVE_LIBSOUP_CLIENT_CERTS #include "ostree-tls-cert-interaction-private.h" #endif #include "ostree-enumtypes.h" -#include "ostree.h" #include "ostree-repo-private.h" +#include "ostree.h" #include "otutil.h" -typedef enum { +typedef enum +{ OSTREE_FETCHER_STATE_PENDING, OSTREE_FETCHER_STATE_DOWNLOADING, OSTREE_FETCHER_STATE_COMPLETE } OstreeFetcherState; -typedef struct { - int ref_count; /* atomic */ +typedef struct +{ + int ref_count; /* atomic */ - SoupSession *session; /* not referenced */ + SoupSession *session; /* not referenced */ GMainContext *main_context; volatile gint running; GError *initialization_error; /* Any failure to load the db */ @@ -65,7 +67,7 @@ typedef struct { GHashTable *outstanding; /* Shared across threads; be sure to lock. */ - GHashTable *output_stream_set; /* set */ + GHashTable *output_stream_set; /* set */ GMutex output_stream_set_lock; /* Also protected by output_stream_set_lock. */ @@ -75,12 +77,13 @@ typedef struct { } ThreadClosure; -typedef struct { - int ref_count; /* atomic */ +typedef struct +{ + int ref_count; /* atomic */ ThreadClosure *thread_closure; 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; OstreeFetcherState state; @@ -89,14 +92,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 *request_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; @@ -104,11 +108,11 @@ typedef struct { } OstreeFetcherPendingURI; /* Used by session_thread_idle_add() */ -typedef void (*SessionThreadFunc) (ThreadClosure *thread_closure, - gpointer data); +typedef void (*SessionThreadFunc) (ThreadClosure *thread_closure, gpointer data); /* Used by session_thread_idle_add() */ -typedef struct { +typedef struct +{ ThreadClosure *thread_closure; SessionThreadFunc function; gpointer data; @@ -125,7 +129,8 @@ struct OstreeFetcher ThreadClosure *thread_closure; }; -enum { +enum +{ PROP_0, PROP_CONFIG_FLAGS }; @@ -212,16 +217,13 @@ session_thread_idle_dispatch (gpointer data) { IdleClosure *idle_closure = data; - idle_closure->function (idle_closure->thread_closure, - idle_closure->data); + idle_closure->function (idle_closure->thread_closure, idle_closure->data); return G_SOURCE_REMOVE; } static void -session_thread_idle_add (ThreadClosure *thread_closure, - SessionThreadFunc function, - gpointer data, +session_thread_idle_add (ThreadClosure *thread_closure, SessionThreadFunc function, gpointer data, GDestroyNotify notify) { IdleClosure *idle_closure; @@ -235,27 +237,22 @@ session_thread_idle_add (ThreadClosure *thread_closure, idle_closure->data = data; idle_closure->notify = notify; - g_main_context_invoke_full (thread_closure->main_context, - G_PRIORITY_DEFAULT, - session_thread_idle_dispatch, - idle_closure, /* takes ownership */ - (GDestroyNotify) idle_closure_free); + g_main_context_invoke_full (thread_closure->main_context, G_PRIORITY_DEFAULT, + session_thread_idle_dispatch, idle_closure, /* takes ownership */ + (GDestroyNotify)idle_closure_free); } static void -session_thread_add_logger (ThreadClosure *thread_closure, - gpointer data) +session_thread_add_logger (ThreadClosure *thread_closure, gpointer data) { glnx_unref_object SoupLogger *logger = NULL; logger = soup_logger_new (SOUP_LOGGER_LOG_BODY, 500); - soup_session_add_feature (thread_closure->session, - SOUP_SESSION_FEATURE (logger)); + soup_session_add_feature (thread_closure->session, SOUP_SESSION_FEATURE (logger)); } static void -session_thread_config_flags (ThreadClosure *thread_closure, - gpointer data) +session_thread_config_flags (ThreadClosure *thread_closure, gpointer data) { OstreeFetcherConfigFlags config_flags; @@ -263,15 +260,13 @@ session_thread_config_flags (ThreadClosure *thread_closure, if ((config_flags & OSTREE_FETCHER_FLAGS_TLS_PERMISSIVE) > 0) { - g_object_set (thread_closure->session, - SOUP_SESSION_SSL_STRICT, - FALSE, NULL); + g_object_set (thread_closure->session, SOUP_SESSION_SSL_STRICT, FALSE, NULL); } } static void -on_authenticate (SoupSession *session, SoupMessage *msg, SoupAuth *auth, - gboolean retrying, gpointer user_data) +on_authenticate (SoupSession *session, SoupMessage *msg, SoupAuth *auth, gboolean retrying, + gpointer user_data) { ThreadClosure *thread_closure = user_data; @@ -282,51 +277,42 @@ on_authenticate (SoupSession *session, SoupMessage *msg, SoupAuth *auth, if (retrying) { g_autofree char *s = soup_uri_to_string (uri, FALSE); - g_set_error (&thread_closure->oob_error, - G_IO_ERROR, G_IO_ERROR_PROXY_AUTH_FAILED, + g_set_error (&thread_closure->oob_error, G_IO_ERROR, G_IO_ERROR_PROXY_AUTH_FAILED, "Invalid username or password for proxy '%s'", s); } else - soup_auth_authenticate (auth, soup_uri_get_user (uri), - soup_uri_get_password (uri)); + soup_auth_authenticate (auth, soup_uri_get_user (uri), soup_uri_get_password (uri)); } } static void -session_thread_set_proxy_cb (ThreadClosure *thread_closure, - gpointer data) +session_thread_set_proxy_cb (ThreadClosure *thread_closure, gpointer data) { SoupURI *proxy_uri = data; - g_object_set (thread_closure->session, - SOUP_SESSION_PROXY_URI, - proxy_uri, NULL); + g_object_set (thread_closure->session, SOUP_SESSION_PROXY_URI, proxy_uri, NULL); /* libsoup won't necessarily pass any embedded username and password to proxy * requests, so we have to be ready to handle 407 and handle them ourselves. * See also: https://bugzilla.gnome.org/show_bug.cgi?id=772932 * */ - if (soup_uri_get_user (proxy_uri) && - soup_uri_get_password (proxy_uri)) + if (soup_uri_get_user (proxy_uri) && soup_uri_get_password (proxy_uri)) { - g_signal_connect (thread_closure->session, "authenticate", - G_CALLBACK (on_authenticate), thread_closure); + g_signal_connect (thread_closure->session, "authenticate", G_CALLBACK (on_authenticate), + thread_closure); } } static void -session_thread_set_cookie_jar_cb (ThreadClosure *thread_closure, - gpointer data) +session_thread_set_cookie_jar_cb (ThreadClosure *thread_closure, gpointer data) { SoupCookieJar *jar = data; - soup_session_add_feature (thread_closure->session, - SOUP_SESSION_FEATURE (jar)); + soup_session_add_feature (thread_closure->session, SOUP_SESSION_FEATURE (jar)); } static void -session_thread_set_headers_cb (ThreadClosure *thread_closure, - gpointer data) +session_thread_set_headers_cb (ThreadClosure *thread_closure, gpointer data) { GVariant *headers = data; @@ -336,27 +322,23 @@ session_thread_set_headers_cb (ThreadClosure *thread_closure, #ifdef HAVE_LIBSOUP_CLIENT_CERTS static void -session_thread_set_tls_interaction_cb (ThreadClosure *thread_closure, - gpointer data) +session_thread_set_tls_interaction_cb (ThreadClosure *thread_closure, gpointer data) { const char *cert_and_key_path = data; /* str\0str\0 in one malloc buf */ const char *cert_path = cert_and_key_path; const char *key_path = cert_and_key_path + strlen (cert_and_key_path) + 1; - g_autoptr(OstreeTlsCertInteraction) interaction = NULL; + g_autoptr (OstreeTlsCertInteraction) interaction = NULL; /* The GTlsInteraction instance must be created in the * session thread so it uses the correct GMainContext. */ interaction = _ostree_tls_cert_interaction_new (cert_path, key_path); - g_object_set (thread_closure->session, - SOUP_SESSION_TLS_INTERACTION, - interaction, NULL); + g_object_set (thread_closure->session, SOUP_SESSION_TLS_INTERACTION, interaction, NULL); } #endif static void -session_thread_set_tls_database_cb (ThreadClosure *thread_closure, - gpointer data) +session_thread_set_tls_database_cb (ThreadClosure *thread_closure, gpointer data) { const char *db_path = data; @@ -368,27 +350,22 @@ session_thread_set_tls_database_cb (ThreadClosure *thread_closure, tlsdb = g_tls_file_database_new (db_path, &thread_closure->initialization_error); if (tlsdb) - g_object_set (thread_closure->session, - SOUP_SESSION_TLS_DATABASE, - tlsdb, NULL); + g_object_set (thread_closure->session, SOUP_SESSION_TLS_DATABASE, tlsdb, NULL); } else { - g_object_set (thread_closure->session, - SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, - TRUE, NULL); + g_object_set (thread_closure->session, SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE, NULL); } } static void -session_thread_set_extra_user_agent_cb (ThreadClosure *thread_closure, - gpointer data) +session_thread_set_extra_user_agent_cb (ThreadClosure *thread_closure, gpointer data) { const char *extra_user_agent = data; if (extra_user_agent != NULL) { - g_autofree char *ua = - g_strdup_printf ("%s %s", OSTREE_FETCHER_USERAGENT_STRING, extra_user_agent); + g_autofree char *ua + = g_strdup_printf ("%s %s", OSTREE_FETCHER_USERAGENT_STRING, extra_user_agent); g_object_set (thread_closure->session, SOUP_SESSION_USER_AGENT, ua, NULL); } else @@ -398,12 +375,10 @@ session_thread_set_extra_user_agent_cb (ThreadClosure *thread_closure, } } -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 void -start_pending_request (ThreadClosure *thread_closure, - GTask *task) +start_pending_request (ThreadClosure *thread_closure, GTask *task) { OstreeFetcherPendingURI *pending; @@ -413,18 +388,14 @@ start_pending_request (ThreadClosure *thread_closure, cancellable = g_task_get_cancellable (task); g_hash_table_add (thread_closure->outstanding, pending_uri_ref (pending)); - soup_request_send_async (pending->request, - cancellable, - on_request_sent, - g_object_ref (task)); + soup_request_send_async (pending->request, cancellable, on_request_sent, g_object_ref (task)); } static void -create_pending_soup_request (OstreeFetcherPendingURI *pending, - GError **error) +create_pending_soup_request (OstreeFetcherPendingURI *pending, GError **error) { OstreeFetcherURI *next_mirror = NULL; - g_autoptr(OstreeFetcherURI) uri = NULL; + g_autoptr (OstreeFetcherURI) uri = NULL; g_assert (pending->mirrorlist); g_assert (pending->mirrorlist_idx < pending->mirrorlist->len); @@ -433,35 +404,36 @@ create_pending_soup_request (OstreeFetcherPendingURI *pending, if (pending->filename) uri = _ostree_fetcher_uri_new_subpath (next_mirror, pending->filename); if (!uri) - uri = (OstreeFetcherURI*)g_uri_ref ((GUri*)next_mirror); + uri = (OstreeFetcherURI *)g_uri_ref ((GUri *)next_mirror); g_clear_object (&pending->request); { - g_autofree gchar *uri_str = g_uri_to_string ((GUri*)uri); + g_autofree gchar *uri_str = g_uri_to_string ((GUri *)uri); pending->request = soup_session_request (pending->thread_closure->session, uri_str, error); } /* Add caching headers. */ if (SOUP_IS_REQUEST_HTTP (pending->request) && pending->if_none_match != NULL) { - glnx_unref_object SoupMessage *msg = soup_request_http_get_message ((SoupRequestHTTP*) pending->request); + glnx_unref_object SoupMessage *msg + = soup_request_http_get_message ((SoupRequestHTTP *)pending->request); soup_message_headers_append (msg->request_headers, "If-None-Match", pending->if_none_match); } if (SOUP_IS_REQUEST_HTTP (pending->request) && pending->if_modified_since > 0) { - glnx_unref_object SoupMessage *msg = soup_request_http_get_message ((SoupRequestHTTP*) pending->request); + glnx_unref_object SoupMessage *msg + = soup_request_http_get_message ((SoupRequestHTTP *)pending->request); - g_autoptr(GDateTime) date_time = g_date_time_new_from_unix_utc (pending->if_modified_since); + g_autoptr (GDateTime) date_time = g_date_time_new_from_unix_utc (pending->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 (msg->request_headers, "If-Modified-Since", mod_date); } } static void -session_thread_request_uri (ThreadClosure *thread_closure, - gpointer data) +session_thread_request_uri (ThreadClosure *thread_closure, gpointer data) { GTask *task = G_TASK (data); OstreeFetcherPendingURI *pending; @@ -485,16 +457,17 @@ session_thread_request_uri (ThreadClosure *thread_closure, return; } - { - g_autofree gchar *uri_str = soup_uri_to_string (soup_request_get_uri (pending->request), FALSE); - g_debug ("%s: starting request %p for URI %s, using GTask %p", - G_STRFUNC, pending->request, uri_str, task); - } + { + g_autofree gchar *uri_str = soup_uri_to_string (soup_request_get_uri (pending->request), FALSE); + g_debug ("%s: starting request %p for URI %s, using GTask %p", G_STRFUNC, pending->request, + uri_str, task); + } if (SOUP_IS_REQUEST_HTTP (pending->request) && thread_closure->extra_headers) { - glnx_unref_object SoupMessage *msg = soup_request_http_get_message ((SoupRequestHTTP*) pending->request); - g_autoptr(GVariantIter) viter = g_variant_iter_new (thread_closure->extra_headers); + glnx_unref_object SoupMessage *msg + = soup_request_http_get_message ((SoupRequestHTTP *)pending->request); + g_autoptr (GVariantIter) viter = g_variant_iter_new (thread_closure->extra_headers); const char *key; const char *value; @@ -504,14 +477,11 @@ session_thread_request_uri (ThreadClosure *thread_closure, if (pending->is_membuf) { - soup_request_send_async (pending->request, - cancellable, - on_request_sent, - g_object_ref (task)); + soup_request_send_async (pending->request, cancellable, on_request_sent, g_object_ref (task)); } else { - start_pending_request (thread_closure, task); + start_pending_request (thread_closure, task); } } @@ -519,7 +489,7 @@ static gpointer ostree_fetcher_session_thread (gpointer data) { ThreadClosure *closure = data; - g_autoptr(GMainContext) mainctx = g_main_context_ref (closure->main_context); + g_autoptr (GMainContext) mainctx = g_main_context_ref (closure->main_context); /* This becomes the GMainContext that SoupSession schedules async * callbacks and emits signals from. Make it the thread-default @@ -527,13 +497,10 @@ ostree_fetcher_session_thread (gpointer data) g_main_context_push_thread_default (mainctx); /* We retain ownership of the SoupSession reference. */ - closure->session = soup_session_async_new_with_options (SOUP_SESSION_USER_AGENT, OSTREE_FETCHER_USERAGENT_STRING, - SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE, - SOUP_SESSION_USE_THREAD_CONTEXT, TRUE, - SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_REQUESTER, - SOUP_SESSION_TIMEOUT, 60, - SOUP_SESSION_IDLE_TIMEOUT, 60, - NULL); + closure->session = soup_session_async_new_with_options ( + SOUP_SESSION_USER_AGENT, OSTREE_FETCHER_USERAGENT_STRING, SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, + TRUE, SOUP_SESSION_USE_THREAD_CONTEXT, TRUE, SOUP_SESSION_ADD_FEATURE_BY_TYPE, + SOUP_TYPE_REQUESTER, SOUP_SESSION_TIMEOUT, 60, SOUP_SESSION_IDLE_TIMEOUT, 60, NULL); if (closure->transfer_gzip) soup_session_add_feature_by_type (closure->session, SOUP_TYPE_CONTENT_DECODER); @@ -547,15 +514,14 @@ ostree_fetcher_session_thread (gpointer data) /* We download a lot of small objects in ostree, so this * helps a lot. Also matches what most modern browsers do. * - * Note since https://github.com/ostreedev/ostree/commit/f4d1334e19ce3ab2f8872b1e28da52044f559401 - * we don't do queuing in this libsoup backend, but we still - * want to override libsoup's currently conservative - * #define SOUP_SESSION_MAX_CONNS_PER_HOST_DEFAULT 2 (as of 2018-02-14). + * Note since + * https://github.com/ostreedev/ostree/commit/f4d1334e19ce3ab2f8872b1e28da52044f559401 we + * don't do queuing in this libsoup backend, but we still want to override libsoup's + * currently conservative #define SOUP_SESSION_MAX_CONNS_PER_HOST_DEFAULT 2 (as of + * 2018-02-14). */ max_conns = _OSTREE_MAX_OUTSTANDING_FETCHER_REQUESTS; - g_object_set (closure->session, - "max-conns-per-host", - max_conns, NULL); + g_object_set (closure->session, "max-conns-per-host", max_conns, NULL); } /* This model ensures we don't hit a race using g_main_loop_quit(); @@ -582,40 +548,35 @@ ostree_fetcher_session_thread (gpointer data) } static void -_ostree_fetcher_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) +_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; + 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) +_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; + 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; } } @@ -644,7 +605,7 @@ static void _ostree_fetcher_constructed (GObject *object) { OstreeFetcher *self = OSTREE_FETCHER (object); - g_autoptr(GMainContext) main_context = NULL; + g_autoptr (GMainContext) main_context = NULL; const char *http_proxy; main_context = g_main_context_new (); @@ -653,27 +614,25 @@ _ostree_fetcher_constructed (GObject *object) self->thread_closure->ref_count = 1; self->thread_closure->main_context = g_main_context_ref (main_context); self->thread_closure->running = 1; - self->thread_closure->transfer_gzip = (self->config_flags & OSTREE_FETCHER_FLAGS_TRANSFER_GZIP) != 0; + self->thread_closure->transfer_gzip + = (self->config_flags & OSTREE_FETCHER_FLAGS_TRANSFER_GZIP) != 0; - self->thread_closure->outstanding = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)pending_uri_unref); - self->thread_closure->output_stream_set = g_hash_table_new_full (NULL, NULL, - (GDestroyNotify) NULL, - (GDestroyNotify) g_object_unref); + self->thread_closure->outstanding + = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)pending_uri_unref); + self->thread_closure->output_stream_set + = g_hash_table_new_full (NULL, NULL, (GDestroyNotify)NULL, (GDestroyNotify)g_object_unref); g_mutex_init (&self->thread_closure->output_stream_set_lock); if (g_getenv ("OSTREE_DEBUG_HTTP")) { - session_thread_idle_add (self->thread_closure, - session_thread_add_logger, - NULL, (GDestroyNotify) NULL); + session_thread_idle_add (self->thread_closure, session_thread_add_logger, NULL, + (GDestroyNotify)NULL); } if (self->config_flags != 0) { - session_thread_idle_add (self->thread_closure, - session_thread_config_flags, - GUINT_TO_POINTER (self->config_flags), - (GDestroyNotify) NULL); + session_thread_idle_add (self->thread_closure, session_thread_config_flags, + GUINT_TO_POINTER (self->config_flags), (GDestroyNotify)NULL); } http_proxy = g_getenv ("http_proxy"); @@ -682,8 +641,7 @@ _ostree_fetcher_constructed (GObject *object) /* FIXME Maybe implement GInitableIface and use g_thread_try_new() * so we can try to handle thread creation errors gracefully? */ - self->session_thread = g_thread_new ("fetcher-session-thread", - ostree_fetcher_session_thread, + self->session_thread = g_thread_new ("fetcher-session-thread", ostree_fetcher_session_thread, thread_closure_ref (self->thread_closure)); G_OBJECT_CLASS (_ostree_fetcher_parent_class)->constructed (object); @@ -699,16 +657,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 @@ -717,9 +670,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; @@ -737,8 +688,7 @@ _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) { SoupURI *proxy_uri; @@ -753,16 +703,14 @@ _ostree_fetcher_set_proxy (OstreeFetcher *self, } else { - session_thread_idle_add (self->thread_closure, - session_thread_set_proxy_cb, - proxy_uri, /* takes ownership */ - (GDestroyNotify) soup_uri_free); + session_thread_idle_add (self->thread_closure, session_thread_set_proxy_cb, + proxy_uri, /* takes ownership */ + (GDestroyNotify)soup_uri_free); } } void -_ostree_fetcher_set_cookie_jar (OstreeFetcher *self, - const char *jar_path) +_ostree_fetcher_set_cookie_jar (OstreeFetcher *self, const char *jar_path) { SoupCookieJar *jar; @@ -771,18 +719,15 @@ _ostree_fetcher_set_cookie_jar (OstreeFetcher *self, jar = soup_cookie_jar_text_new (jar_path, TRUE); - session_thread_idle_add (self->thread_closure, - session_thread_set_cookie_jar_cb, - jar, /* takes ownership */ - (GDestroyNotify) g_object_unref); + session_thread_idle_add (self->thread_closure, session_thread_set_cookie_jar_cb, + jar, /* takes ownership */ + (GDestroyNotify)g_object_unref); } 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_autoptr(GString) buf = NULL; + g_autoptr (GString) buf = NULL; g_return_if_fail (OSTREE_IS_FETCHER (self)); if (cert_path) @@ -793,51 +738,38 @@ _ostree_fetcher_set_client_cert (OstreeFetcher *self, } #ifdef HAVE_LIBSOUP_CLIENT_CERTS - session_thread_idle_add (self->thread_closure, - session_thread_set_tls_interaction_cb, - g_string_free (g_steal_pointer (&buf), FALSE), - (GDestroyNotify) g_free); + session_thread_idle_add (self->thread_closure, session_thread_set_tls_interaction_cb, + g_string_free (g_steal_pointer (&buf), FALSE), (GDestroyNotify)g_free); #else g_warning ("This version of OSTree is compiled without client side certificate support"); #endif } 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)); - session_thread_idle_add (self->thread_closure, - session_thread_set_tls_database_cb, - g_strdup (tlsdb_path), - (GDestroyNotify) g_free); + session_thread_idle_add (self->thread_closure, session_thread_set_tls_database_cb, + g_strdup (tlsdb_path), (GDestroyNotify)g_free); } void -_ostree_fetcher_set_extra_headers (OstreeFetcher *self, - GVariant *extra_headers) +_ostree_fetcher_set_extra_headers (OstreeFetcher *self, GVariant *extra_headers) { - session_thread_idle_add (self->thread_closure, - session_thread_set_headers_cb, - g_variant_ref (extra_headers), - (GDestroyNotify) g_variant_unref); + session_thread_idle_add (self->thread_closure, session_thread_set_headers_cb, + g_variant_ref (extra_headers), (GDestroyNotify)g_variant_unref); } 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) { - session_thread_idle_add (self->thread_closure, - session_thread_set_extra_user_agent_cb, - g_strdup (extra_user_agent), - (GDestroyNotify) g_free); + session_thread_idle_add (self->thread_closure, session_thread_set_extra_user_agent_cb, + g_strdup (extra_user_agent), (GDestroyNotify)g_free); } static gboolean -finish_stream (OstreeFetcherPendingURI *pending, - GCancellable *cancellable, - GError **error) +finish_stream (OstreeFetcherPendingURI *pending, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; struct stat stbuf; @@ -861,8 +793,7 @@ finish_stream (OstreeFetcherPendingURI *pending, goto out; g_mutex_lock (&pending->thread_closure->output_stream_set_lock); - g_hash_table_remove (pending->thread_closure->output_stream_set, - pending->out_stream); + g_hash_table_remove (pending->thread_closure->output_stream_set, pending->out_stream); g_mutex_unlock (&pending->thread_closure->output_stream_set_lock); } @@ -890,15 +821,12 @@ finish_stream (OstreeFetcherPendingURI *pending, } ret = TRUE; - out: - (void) g_input_stream_close (pending->request_body, NULL, NULL); +out: + (void)g_input_stream_close (pending->request_body, NULL, NULL); return ret; } -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 remove_pending (OstreeFetcherPendingURI *pending) @@ -912,9 +840,7 @@ remove_pending (OstreeFetcherPendingURI *pending) } static void -on_out_splice_complete (GObject *object, - GAsyncResult *result, - gpointer user_data) +on_out_splice_complete (GObject *object, GAsyncResult *result, gpointer user_data) { GTask *task = G_TASK (user_data); OstreeFetcherPendingURI *pending; @@ -925,19 +851,14 @@ on_out_splice_complete (GObject *object, pending = g_task_get_task_data (task); cancellable = g_task_get_cancellable (task); - bytes_written = g_output_stream_splice_finish ((GOutputStream *)object, - result, - &local_error); + bytes_written = g_output_stream_splice_finish ((GOutputStream *)object, result, &local_error); if (bytes_written < 0) goto out; - g_input_stream_read_bytes_async (pending->request_body, - 8192, G_PRIORITY_DEFAULT, - cancellable, - on_stream_read, - g_object_ref (task)); + g_input_stream_read_bytes_async (pending->request_body, 8192, G_PRIORITY_DEFAULT, cancellable, + on_stream_read, g_object_ref (task)); - out: +out: if (local_error) { g_task_return_error (task, local_error); @@ -948,14 +869,12 @@ on_out_splice_complete (GObject *object, } static void -on_stream_read (GObject *object, - GAsyncResult *result, - gpointer user_data) +on_stream_read (GObject *object, GAsyncResult *result, gpointer user_data) { GTask *task = G_TASK (user_data); OstreeFetcherPendingURI *pending; GCancellable *cancellable; - g_autoptr(GBytes) bytes = NULL; + g_autoptr (GBytes) bytes = NULL; gsize bytes_read; GError *local_error = NULL; @@ -969,7 +888,8 @@ on_stream_read (GObject *object, { if (!pending->is_membuf) { - if (!_ostree_fetcher_tmpf_from_flags (pending->flags, pending->thread_closure->base_tmpdir_dfd, + if (!_ostree_fetcher_tmpf_from_flags (pending->flags, + pending->thread_closure->base_tmpdir_dfd, &pending->tmpf, &local_error)) goto out; pending->out_stream = g_unix_output_stream_new (pending->tmpf.fd, FALSE); @@ -986,7 +906,7 @@ on_stream_read (GObject *object, } /* Get a GBytes buffer */ - bytes = g_input_stream_read_bytes_finish ((GInputStream*)object, result, &local_error); + bytes = g_input_stream_read_bytes_finish ((GInputStream *)object, result, &local_error); if (!bytes) goto out; bytes_read = g_bytes_get_size (bytes); @@ -998,9 +918,10 @@ on_stream_read (GObject *object, goto out; if (pending->is_membuf) { - g_task_return_pointer (task, - g_memory_output_stream_steal_as_bytes ((GMemoryOutputStream*)pending->out_stream), - (GDestroyNotify) g_bytes_unref); + g_task_return_pointer ( + task, + g_memory_output_stream_steal_as_bytes ((GMemoryOutputStream *)pending->out_stream), + (GDestroyNotify)g_bytes_unref); } else { @@ -1019,14 +940,15 @@ on_stream_read (GObject *object, /* Verify max size */ if (pending->max_size > 0) { - if (bytes_read > pending->max_size || - (bytes_read + pending->current_size) > pending->max_size) + if (bytes_read > pending->max_size + || (bytes_read + pending->current_size) > pending->max_size) { - g_autofree char *uristr = - soup_uri_to_string (soup_request_get_uri (pending->request), FALSE); - local_error = g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED, - "URI %s exceeded maximum size of %" G_GUINT64_FORMAT " bytes", - uristr, pending->max_size); + g_autofree char *uristr + = soup_uri_to_string (soup_request_get_uri (pending->request), FALSE); + local_error + = g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED, + "URI %s exceeded maximum size of %" G_GUINT64_FORMAT " bytes", + uristr, pending->max_size); goto out; } } @@ -1037,18 +959,14 @@ 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 (pending->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)); } } - out: +out: if (local_error) { g_task_return_error (task, local_error); @@ -1059,9 +977,7 @@ on_stream_read (GObject *object, } static void -on_request_sent (GObject *object, - GAsyncResult *result, - gpointer user_data) +on_request_sent (GObject *object, GAsyncResult *result, gpointer user_data) { GTask *task = G_TASK (user_data); /* Hold a ref to the pending across this function, since we remove @@ -1072,11 +988,10 @@ on_request_sent (GObject *object, glnx_unref_object SoupMessage *msg = NULL; pending->state = OSTREE_FETCHER_STATE_COMPLETE; - pending->request_body = soup_request_send_finish ((SoupRequest*) object, - result, &local_error); + pending->request_body = soup_request_send_finish ((SoupRequest *)object, result, &local_error); - g_debug ("%s: request %p (GTask %p) finished with request_body %p and error %s", - G_STRFUNC, object, task, pending->request_body, + g_debug ("%s: request %p (GTask %p) finished with request_body %p and error %s", G_STRFUNC, + object, task, pending->request_body, (local_error != NULL) ? local_error->message : "none"); if (!pending->request_body) @@ -1085,9 +1000,9 @@ on_request_sent (GObject *object, if (SOUP_IS_REQUEST_HTTP (object)) { - msg = soup_request_http_get_message ((SoupRequestHTTP*) object); - if (msg->status_code == SOUP_STATUS_NOT_MODIFIED && - (pending->if_none_match != NULL || pending->if_modified_since > 0)) + msg = soup_request_http_get_message ((SoupRequestHTTP *)object); + if (msg->status_code == SOUP_STATUS_NOT_MODIFIED + && (pending->if_none_match != NULL || pending->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 */ @@ -1103,14 +1018,14 @@ on_request_sent (GObject *object, if (local_error != NULL) goto out; - (void) g_input_stream_close (pending->request_body, NULL, NULL); + (void)g_input_stream_close (pending->request_body, NULL, NULL); start_pending_request (pending->thread_closure, task); } else { - g_autofree char *uristring = - soup_uri_to_string (soup_request_get_uri (pending->request), FALSE); + g_autofree char *uristring + = soup_uri_to_string (soup_request_get_uri (pending->request), FALSE); GIOErrorEnum code; @@ -1137,17 +1052,15 @@ on_request_sent (GObject *object, } { - g_autofree char *errmsg = - g_strdup_printf ("Server returned status %u: %s", - msg->status_code, - soup_status_get_phrase (msg->status_code)); + g_autofree char *errmsg + = g_strdup_printf ("Server returned status %u: %s", msg->status_code, + soup_status_get_phrase (msg->status_code)); /* Let's make OOB errors be the final one since they're probably * the cause for the error here. */ if (pending->thread_closure->oob_error) { - local_error = - g_error_copy (pending->thread_closure->oob_error); + local_error = g_error_copy (pending->thread_closure->oob_error); g_prefix_error (&local_error, "%s: ", errmsg); } else @@ -1155,15 +1068,13 @@ on_request_sent (GObject *object, } if (pending->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: ", pending->mirrorlist->len); - if (pending->thread_closure->remote_name && - !((pending->flags & OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT) > 0 && - code == G_IO_ERROR_NOT_FOUND)) - _ostree_fetcher_journal_failure (pending->thread_closure->remote_name, - uristring, local_error->message); - + if (pending->thread_closure->remote_name + && !((pending->flags & OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT) > 0 + && code == G_IO_ERROR_NOT_FOUND)) + _ostree_fetcher_journal_failure (pending->thread_closure->remote_name, uristring, + local_error->message); } goto out; } @@ -1172,7 +1083,8 @@ on_request_sent (GObject *object, pending->out_etag = g_strdup (soup_message_headers_get_one (msg->response_headers, "ETag")); pending->out_last_modified = 0; - const char *last_modified_str = soup_message_headers_get_one (msg->response_headers, "Last-Modified"); + const char *last_modified_str + = soup_message_headers_get_one (msg->response_headers, "Last-Modified"); if (last_modified_str != NULL) { SoupDate *soup_date = soup_date_new_from_string (last_modified_str); @@ -1188,17 +1100,14 @@ on_request_sent (GObject *object, pending->content_length = soup_request_get_content_length (pending->request); - g_input_stream_read_bytes_async (pending->request_body, - 8192, G_PRIORITY_DEFAULT, - cancellable, - on_stream_read, - g_object_ref (task)); + g_input_stream_read_bytes_async (pending->request_body, 8192, G_PRIORITY_DEFAULT, cancellable, + on_stream_read, g_object_ref (task)); - out: +out: if (local_error) { if (pending->request_body) - (void) g_input_stream_close (pending->request_body, NULL, NULL); + (void)g_input_stream_close (pending->request_body, NULL, NULL); g_task_return_error (task, local_error); remove_pending (pending); } @@ -1208,20 +1117,13 @@ on_request_sent (GObject *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_autoptr(GTask) task = NULL; + g_autoptr (GTask) task = NULL; OstreeFetcherPendingURI *pending; g_return_if_fail (OSTREE_IS_FETCHER (self)); @@ -1242,44 +1144,32 @@ _ostree_fetcher_request_async (OstreeFetcher *self, 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, pending, (GDestroyNotify) pending_uri_unref); + g_task_set_task_data (task, pending, (GDestroyNotify)pending_uri_unref); /* We'll use the GTask priority for our own priority queue. */ g_task_set_priority (task, priority); - session_thread_idle_add (self->thread_closure, - session_thread_request_uri, - g_object_ref (task), - (GDestroyNotify) g_object_unref); + session_thread_idle_add (self->thread_closure, session_thread_request_uri, g_object_ref (task), + (GDestroyNotify)g_object_unref); } 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) { GTask *task; OstreeFetcherPendingURI *pending; @@ -1288,7 +1178,7 @@ _ostree_fetcher_request_to_tmpfile_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; pending = g_task_get_task_data (task); ret = g_task_propagate_pointer (task, error); @@ -1310,32 +1200,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; OstreeFetcherPendingURI *pending; @@ -1344,7 +1224,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; pending = g_task_get_task_data (task); ret = g_task_propagate_pointer (task, error); @@ -1365,9 +1245,8 @@ _ostree_fetcher_request_to_membuf_finish (OstreeFetcher *self, return TRUE; } - guint64 -_ostree_fetcher_bytes_transferred (OstreeFetcher *self) +_ostree_fetcher_bytes_transferred (OstreeFetcher *self) { g_return_val_if_fail (OSTREE_IS_FETCHER (self), 0); @@ -1375,12 +1254,11 @@ _ostree_fetcher_bytes_transferred (OstreeFetcher *self) guint64 ret = self->thread_closure->total_downloaded; - GLNX_HASH_TABLE_FOREACH (self->thread_closure->output_stream_set, - GFileOutputStream*, stream) + GLNX_HASH_TABLE_FOREACH (self->thread_closure->output_stream_set, GFileOutputStream *, stream) { if (G_IS_FILE_DESCRIPTOR_BASED (stream)) { - int fd = g_file_descriptor_based_get_fd ((GFileDescriptorBased*)stream); + int fd = g_file_descriptor_based_get_fd ((GFileDescriptorBased *)stream); struct stat stbuf; if (glnx_fstat (fd, &stbuf, NULL)) diff --git a/src/libostree/ostree-fetcher-soup3.c b/src/libostree/ostree-fetcher-soup3.c index b46ce34f..f6ada17a 100644 --- a/src/libostree/ostree-fetcher-soup3.c +++ b/src/libostree/ostree-fetcher-soup3.c @@ -30,15 +30,16 @@ #include #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) +_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; + 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) +_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; + 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_async (self, mirrorlist, filename, flags, - if_none_match, if_modified_since, FALSE, - max_size, priority, cancellable, +_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, 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_async (self, mirrorlist, filename, flags, - if_none_match, if_modified_since, TRUE, - max_size, priority, cancellable, - callback, 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); } 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) { diff --git a/src/libostree/ostree-fetcher-uri.c b/src/libostree/ostree-fetcher-uri.c index 722aeeeb..af300128 100644 --- a/src/libostree/ostree-fetcher-uri.c +++ b/src/libostree/ostree-fetcher-uri.c @@ -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); diff --git a/src/libostree/ostree-fetcher-util.c b/src/libostree/ostree-fetcher-util.c index ecd6bc23..b797bee7 100644 --- a/src/libostree/ostree-fetcher-util.c +++ b/src/libostree/ostree-fetcher-util.c @@ -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; diff --git a/src/libostree/ostree-fetcher-util.h b/src/libostree/ostree-fetcher-util.h index edbcd32b..c3243801 100644 --- a/src/libostree/ostree-fetcher-util.h +++ b/src/libostree/ostree-fetcher-util.h @@ -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); diff --git a/src/libostree/ostree-fetcher.h b/src/libostree/ostree-fetcher.h index 3c91762a..42ff3a17 100644 --- a/src/libostree/ostree-fetcher.h +++ b/src/libostree/ostree-fetcher.h @@ -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); - -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_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_extra_headers (OstreeFetcher *self, - GVariant *extra_headers); - -void _ostree_fetcher_set_extra_user_agent (OstreeFetcher *self, - const char *extra_user_agent); - -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); - -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); +int _ostree_fetcher_get_dfd (OstreeFetcher *fetcher); + +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_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_extra_headers (OstreeFetcher *self, GVariant *extra_headers); + +void _ostree_fetcher_set_extra_user_agent (OstreeFetcher *self, const char *extra_user_agent); + +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); + +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); G_END_DECLS diff --git a/src/libostree/ostree-gpg-verifier.c b/src/libostree/ostree-gpg-verifier.c index 8301907c..90aa4815 100644 --- a/src/libostree/ostree-gpg-verifier.c +++ b/src/libostree/ostree-gpg-verifier.c @@ -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 #include +#include -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); diff --git a/src/libostree/ostree-gpg-verifier.h b/src/libostree/ostree-gpg-verifier.h index 34329bb3..b9e54b71 100644 --- a/src/libostree/ostree-gpg-verifier.h +++ b/src/libostree/ostree-gpg-verifier.h @@ -20,17 +20,16 @@ * Author: Sjoerd Simons */ -//#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); - -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_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); - -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); - -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); + 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_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_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_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_dir_at (OstreeGpgVerifier *self, int dfd, + const char *path, GCancellable *cancellable, + GError **error); G_END_DECLS diff --git a/src/libostree/ostree-gpg-verify-result-dummy.c b/src/libostree/ostree-gpg-verify-result-dummy.c index 382b7b92..e1ff846e 100644 --- a/src/libostree/ostree-gpg-verify-result-dummy.c +++ b/src/libostree/ostree-gpg-verify-result-dummy.c @@ -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; } diff --git a/src/libostree/ostree-gpg-verify-result-private.h b/src/libostree/ostree-gpg-verify-result-private.h index 7182dacc..a6b22084 100644 --- a/src/libostree/ostree-gpg-verify-result-private.h +++ b/src/libostree/ostree-gpg-verify-result-private.h @@ -28,7 +28,8 @@ * * Private instance structure. */ -struct OstreeGpgVerifyResult { +struct OstreeGpgVerifyResult +{ GObject parent; gpgme_ctx_t context; diff --git a/src/libostree/ostree-gpg-verify-result.c b/src/libostree/ostree-gpg-verify-result.c index 3b6a7da4..4b7bd471 100644 --- a/src/libostree/ostree-gpg-verify-result.c +++ b/src/libostree/ostree-gpg-verify-result.c @@ -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_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_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_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_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_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_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_KEY_EXP_TIMESTAMP: + 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_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_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_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_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_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_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: + 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; - - 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; + child = g_variant_new_int64 (v_int64); + break; + + 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; diff --git a/src/libostree/ostree-gpg-verify-result.h b/src/libostree/ostree-gpg-verify-result.h index 05e4403b..666dc6f3 100644 --- a/src/libostree/ostree-gpg-verify-result.h +++ b/src/libostree/ostree-gpg-verify-result.h @@ -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, diff --git a/src/libostree/ostree-impl-system-generator.c b/src/libostree/ostree-impl-system-generator.c index da4654b9..8404d189 100644 --- a/src/libostree/ostree-impl-system-generator.c +++ b/src/libostree/ostree-impl-system-generator.c @@ -19,24 +19,24 @@ #include "config.h" -#include -#include #include +#include +#include #include #ifdef HAVE_LIBMOUNT #include #endif -#include -#include #include "otutil.h" +#include +#include -#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; diff --git a/src/libostree/ostree-kernel-args.c b/src/libostree/ostree-kernel-args.c index 582cab0f..d07c5ce4 100644 --- a/src/libostree/ostree-kernel-args.c +++ b/src/libostree/ostree-kernel-args.c @@ -17,18 +17,20 @@ #include "config.h" -#include "ostree-kernel-args.h" #include "libglnx.h" +#include "ostree-kernel-args.h" #include "otutil.h" #include -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); diff --git a/src/libostree/ostree-kernel-args.h b/src/libostree/ostree-kernel-args.h index 915faca2..ea37de06 100644 --- a/src/libostree/ostree-kernel-args.h +++ b/src/libostree/ostree-kernel-args.h @@ -17,10 +17,10 @@ #pragma once +#include "ostree-types.h" #include -#include #include -#include "ostree-types.h" +#include 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 diff --git a/src/libostree/ostree-libarchive-input-stream.c b/src/libostree/ostree-libarchive-input-stream.c index 426db589..b1c90429 100644 --- a/src/libostree/ostree-libarchive-input-stream.c +++ b/src/libostree/ostree-libarchive-input-stream.c @@ -20,38 +20,32 @@ #include "config.h" - +#include "ostree-libarchive-input-stream.h" #include #include -#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) - -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); +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_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; } diff --git a/src/libostree/ostree-libarchive-input-stream.h b/src/libostree/ostree-libarchive-input-stream.h index a71a6d58..8ab22038 100644 --- a/src/libostree/ostree-libarchive-input-stream.h +++ b/src/libostree/ostree-libarchive-input-stream.h @@ -21,21 +21,29 @@ #pragma once -#include #include "ostree-libarchive-private.h" +#include 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 diff --git a/src/libostree/ostree-libarchive-private.h b/src/libostree/ostree-libarchive-private.h index 4eaeaedb..02cf6d57 100644 --- a/src/libostree/ostree-libarchive-private.h +++ b/src/libostree/ostree-libarchive-private.h @@ -26,8 +26,8 @@ #include "config.h" -#include #include "otutil.h" +#include #ifdef HAVE_LIBARCHIVE #include #include @@ -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; } diff --git a/src/libostree/ostree-linuxfsutil.c b/src/libostree/ostree-linuxfsutil.c index aa389aaa..bebd5248 100644 --- a/src/libostree/ostree-linuxfsutil.c +++ b/src/libostree/ostree-linuxfsutil.c @@ -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 #include +#include /** * _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; diff --git a/src/libostree/ostree-linuxfsutil.h b/src/libostree/ostree-linuxfsutil.h index 9011c9d8..e0e07bcd 100644 --- a/src/libostree/ostree-linuxfsutil.h +++ b/src/libostree/ostree-linuxfsutil.h @@ -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); diff --git a/src/libostree/ostree-lzma-common.c b/src/libostree/ostree-lzma-common.c index d4bc71bf..40f64246 100644 --- a/src/libostree/ostree-lzma-common.c +++ b/src/libostree/ostree-lzma-common.c @@ -26,8 +26,7 @@ #include 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; } } diff --git a/src/libostree/ostree-lzma-compressor.c b/src/libostree/ostree-lzma-compressor.c index 0404d366..cefd256f 100644 --- a/src/libostree/ostree-lzma-compressor.c +++ b/src/libostree/ostree-lzma-compressor.c @@ -20,14 +20,15 @@ #include "config.h" -#include "ostree-lzma-compressor.h" #include "ostree-lzma-common.h" +#include "ostree-lzma-compressor.h" #include #include #include -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); } diff --git a/src/libostree/ostree-lzma-compressor.h b/src/libostree/ostree-lzma-compressor.h index 5f3da188..570bc33e 100644 --- a/src/libostree/ostree-lzma-compressor.h +++ b/src/libostree/ostree-lzma-compressor.h @@ -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)) - -typedef struct _OstreeLzmaCompressorClass OstreeLzmaCompressorClass; -typedef struct _OstreeLzmaCompressor OstreeLzmaCompressor; +#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; 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); diff --git a/src/libostree/ostree-lzma-decompressor.c b/src/libostree/ostree-lzma-decompressor.c index 029159ea..2ac48a32 100644 --- a/src/libostree/ostree-lzma-decompressor.c +++ b/src/libostree/ostree-lzma-decompressor.c @@ -19,14 +19,15 @@ #include "config.h" -#include "ostree-lzma-decompressor.h" #include "ostree-lzma-common.h" +#include "ostree-lzma-decompressor.h" #include #include #include -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); } diff --git a/src/libostree/ostree-lzma-decompressor.h b/src/libostree/ostree-lzma-decompressor.h index 231f2148..a60745fe 100644 --- a/src/libostree/ostree-lzma-decompressor.h +++ b/src/libostree/ostree-lzma-decompressor.h @@ -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)) - -typedef struct _OstreeLzmaDecompressorClass OstreeLzmaDecompressorClass; -typedef struct _OstreeLzmaDecompressor OstreeLzmaDecompressor; +#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; 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); diff --git a/src/libostree/ostree-metalink.c b/src/libostree/ostree-metalink.c index d028266f..449018e3 100644 --- a/src/libostree/ostree-metalink.c +++ b/src/libostree/ostree-metalink.c @@ -19,13 +19,14 @@ #include "config.h" -#include "ostree-metalink.h" #include "ostree-fetcher-util.h" +#include "ostree-metalink.h" #include #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 element found"); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "No 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 found", self->metalink->requested_file); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "No 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 elements found"); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "No 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); - - 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)) + 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)) 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); diff --git a/src/libostree/ostree-metalink.h b/src/libostree/ostree-metalink.h index 68400cdf..a4575155 100644 --- a/src/libostree/ostree-metalink.h +++ b/src/libostree/ostree-metalink.h @@ -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)) - -typedef struct OstreeMetalinkClass OstreeMetalinkClass; -typedef struct OstreeMetalink OstreeMetalink; +#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; 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 diff --git a/src/libostree/ostree-mutable-tree.c b/src/libostree/ostree-mutable-tree.c index d0002c4e..2d52e402 100644 --- a/src/libostree/ostree-mutable-tree.c +++ b/src/libostree/ostree-mutable-tree.c @@ -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); } diff --git a/src/libostree/ostree-mutable-tree.h b/src/libostree/ostree-mutable-tree.h index 384ff252..923b2cd2 100644 --- a/src/libostree/ostree-mutable-tree.h +++ b/src/libostree/ostree-mutable-tree.h @@ -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)) - -typedef struct OstreeMutableTreeClass OstreeMutableTreeClass; - -typedef struct { - gboolean in_files; - GHashTableIter iter; +#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 +{ + 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 diff --git a/src/libostree/ostree-ref.c b/src/libostree/ostree-ref.c index 5a2f44e3..149c2915 100644 --- a/src/libostree/ostree-ref.c +++ b/src/libostree/ostree-ref.c @@ -23,17 +23,17 @@ #include "config.h" #include -#include #include +#include #include #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]); diff --git a/src/libostree/ostree-ref.h b/src/libostree/ostree-ref.h index 5e5c0ed3..30f3fd34 100644 --- a/src/libostree/ostree-ref.h +++ b/src/libostree/ostree-ref.h @@ -23,8 +23,8 @@ #pragma once #include -#include #include +#include #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 diff --git a/src/libostree/ostree-remote-private.h b/src/libostree/ostree-remote-private.h index eba74305..24ada6c7 100644 --- a/src/libostree/ostree-remote-private.h +++ b/src/libostree/ostree-remote-private.h @@ -26,8 +26,8 @@ #pragma once #include -#include #include +#include #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 diff --git a/src/libostree/ostree-remote.c b/src/libostree/ostree-remote.c index 3695e0f4..73d836a2 100644 --- a/src/libostree/ostree-remote.c +++ b/src/libostree/ostree-remote.c @@ -26,13 +26,13 @@ #include "config.h" #include -#include #include +#include #include #include -#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: diff --git a/src/libostree/ostree-remote.h b/src/libostree/ostree-remote.h index 3230ff8c..066322f8 100644 --- a/src/libostree/ostree-remote.h +++ b/src/libostree/ostree-remote.h @@ -26,8 +26,8 @@ #pragma once #include -#include #include +#include #include "ostree-types.h" diff --git a/src/libostree/ostree-repo-checkout.c b/src/libostree/ostree-repo-checkout.c index a5b01356..0516ef48 100644 --- a/src/libostree/ostree-repo-checkout.c +++ b/src/libostree/ostree-repo-checkout.c @@ -21,16 +21,16 @@ #include "config.h" -#include -#include +#include "otutil.h" #include #include -#include "otutil.h" +#include +#include -#include "ostree-repo-file.h" -#include "ostree-sepolicy-private.h" #include "ostree-core-private.h" +#include "ostree-repo-file.h" #include "ostree-repo-private.h" +#include "ostree-sepolicy-private.h" #define WHITEOUT_PREFIX ".wh." #define OPAQUE_WHITEOUT_NAME ".wh..wh..opq" @@ -38,8 +38,9 @@ #define OVERLAYFS_WHITEOUT_PREFIX ".ostree-wh." /* Per-checkout call state/caching */ -typedef struct { - GString *path_buf; /* buffer for real path if filtering enabled */ +typedef struct +{ + GString *path_buf; /* buffer for real path if filtering enabled */ GString *selabel_path_buf; /* buffer for selinux path if labeling enabled; this may be the same buffer as path_buf */ } CheckoutState; @@ -52,25 +53,23 @@ checkout_state_clear (CheckoutState *state) if (state->selabel_path_buf && (state->selabel_path_buf != state->path_buf)) g_string_free (state->selabel_path_buf, TRUE); } -G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(CheckoutState, checkout_state_clear) +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (CheckoutState, checkout_state_clear) static gboolean -checkout_object_for_uncompressed_cache (OstreeRepo *self, - const char *loose_path, - GFileInfo *src_info, - GInputStream *content, - GCancellable *cancellable, - GError **error) +checkout_object_for_uncompressed_cache (OstreeRepo *self, const char *loose_path, + GFileInfo *src_info, GInputStream *content, + GCancellable *cancellable, GError **error) { /* Don't make setuid files in uncompressed cache */ guint32 file_mode = g_file_info_get_attribute_uint32 (src_info, "unix::mode"); - file_mode &= ~(S_ISUID|S_ISGID); + file_mode &= ~(S_ISUID | S_ISGID); - g_auto(GLnxTmpfile) tmpf = { 0, }; - if (!glnx_open_tmpfile_linkable_at (self->tmp_dir_fd, ".", O_WRONLY | O_CLOEXEC, - &tmpf, error)) + g_auto (GLnxTmpfile) tmpf = { + 0, + }; + if (!glnx_open_tmpfile_linkable_at (self->tmp_dir_fd, ".", O_WRONLY | O_CLOEXEC, &tmpf, error)) return FALSE; - g_autoptr(GOutputStream) temp_out = g_unix_output_stream_new (tmpf.fd, FALSE); + g_autoptr (GOutputStream) temp_out = g_unix_output_stream_new (tmpf.fd, FALSE); if (g_output_stream_splice (temp_out, content, 0, cancellable, error) < 0) return FALSE; @@ -96,47 +95,38 @@ checkout_object_for_uncompressed_cache (OstreeRepo *self, DEFAULT_DIRECTORY_MODE, cancellable, error)) return FALSE; if (!glnx_opendirat (self->repo_dir_fd, "uncompressed-objects-cache", TRUE, - &self->uncompressed_objects_dir_fd, - error)) + &self->uncompressed_objects_dir_fd, error)) return FALSE; } - if (!_ostree_repo_ensure_loose_objdir_at (self->uncompressed_objects_dir_fd, - loose_path, + if (!_ostree_repo_ensure_loose_objdir_at (self->uncompressed_objects_dir_fd, loose_path, cancellable, error)) return FALSE; if (!glnx_link_tmpfile_at (&tmpf, GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST, - self->uncompressed_objects_dir_fd, loose_path, - error)) + self->uncompressed_objects_dir_fd, loose_path, error)) return FALSE; return TRUE; } static gboolean -fsync_is_enabled (OstreeRepo *self, - OstreeRepoCheckoutAtOptions *options) +fsync_is_enabled (OstreeRepo *self, OstreeRepoCheckoutAtOptions *options) { return options->enable_fsync; } static gboolean -write_regular_file_content (OstreeRepo *self, - OstreeRepoCheckoutAtOptions *options, - int outfd, - GFileInfo *file_info, - GVariant *xattrs, - GInputStream *input, - GCancellable *cancellable, - GError **error) +write_regular_file_content (OstreeRepo *self, OstreeRepoCheckoutAtOptions *options, int outfd, + GFileInfo *file_info, GVariant *xattrs, GInputStream *input, + GCancellable *cancellable, GError **error) { const OstreeRepoCheckoutMode mode = options->mode; - g_autoptr(GOutputStream) outstream = NULL; + g_autoptr (GOutputStream) outstream = NULL; if (G_IS_FILE_DESCRIPTOR_BASED (input)) { - int infd = g_file_descriptor_based_get_fd ((GFileDescriptorBased*) input); + int infd = g_file_descriptor_based_get_fd ((GFileDescriptorBased *)input); guint64 len = g_file_info_get_size (file_info); if (glnx_regfile_copy_bytes (infd, outfd, (off_t)len) < 0) @@ -145,8 +135,7 @@ write_regular_file_content (OstreeRepo *self, else { outstream = g_unix_output_stream_new (outfd, FALSE); - if (g_output_stream_splice (outstream, input, 0, - cancellable, error) < 0) + if (g_output_stream_splice (outstream, input, 0, cancellable, error) < 0) return FALSE; if (!g_output_stream_flush (outstream, cancellable, error)) @@ -155,8 +144,10 @@ write_regular_file_content (OstreeRepo *self, if (mode != OSTREE_REPO_CHECKOUT_MODE_USER) { - if (TEMP_FAILURE_RETRY (fchown (outfd, g_file_info_get_attribute_uint32 (file_info, "unix::uid"), - g_file_info_get_attribute_uint32 (file_info, "unix::gid"))) < 0) + if (TEMP_FAILURE_RETRY (fchown (outfd, + g_file_info_get_attribute_uint32 (file_info, "unix::uid"), + g_file_info_get_attribute_uint32 (file_info, "unix::gid"))) + < 0) return glnx_throw_errno_prefix (error, "fchown"); if (xattrs) @@ -170,7 +161,7 @@ write_regular_file_content (OstreeRepo *self, /* Don't make setuid files on checkout when we're doing --user */ if (mode == OSTREE_REPO_CHECKOUT_MODE_USER) - file_mode &= ~(S_ISUID|S_ISGID); + file_mode &= ~(S_ISUID | S_ISGID); if (TEMP_FAILURE_RETRY (fchmod (outfd, file_mode)) < 0) return glnx_throw_errno_prefix (error, "fchmod"); @@ -194,20 +185,14 @@ write_regular_file_content (OstreeRepo *self, * Create a copy of a file, supporting optional union/add behavior. */ static gboolean -create_file_copy_from_input_at (OstreeRepo *repo, - OstreeRepoCheckoutAtOptions *options, - CheckoutState *state, - const char *checksum, - GFileInfo *file_info, - GVariant *xattrs, - GInputStream *input, - int destination_dfd, - const char *destination_name, - GCancellable *cancellable, - GError **error) +create_file_copy_from_input_at (OstreeRepo *repo, OstreeRepoCheckoutAtOptions *options, + CheckoutState *state, const char *checksum, GFileInfo *file_info, + GVariant *xattrs, GInputStream *input, int destination_dfd, + const char *destination_name, GCancellable *cancellable, + GError **error) { const gboolean sepolicy_enabled = options->sepolicy && !repo->disable_xattrs; - g_autoptr(GVariant) modified_xattrs = NULL; + g_autoptr (GVariant) modified_xattrs = NULL; /* If we're doing SELinux labeling, prepare it */ if (sepolicy_enabled) @@ -222,15 +207,16 @@ create_file_copy_from_input_at (OstreeRepo *repo, if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_SYMBOLIC_LINK) { - g_auto(OstreeSepolicyFsCreatecon) fscreatecon = { 0, }; + g_auto (OstreeSepolicyFsCreatecon) fscreatecon = { + 0, + }; if (sepolicy_enabled) { /* For symlinks, since we don't have O_TMPFILE, we use setfscreatecon() */ - if (!_ostree_sepolicy_preparefscreatecon (&fscreatecon, options->sepolicy, - state->selabel_path_buf->str, - g_file_info_get_attribute_uint32 (file_info, "unix::mode"), - error)) + if (!_ostree_sepolicy_preparefscreatecon ( + &fscreatecon, options->sepolicy, state->selabel_path_buf->str, + g_file_info_get_attribute_uint32 (file_info, "unix::mode"), error)) return FALSE; } @@ -282,9 +268,8 @@ create_file_copy_from_input_at (OstreeRepo *repo, return FALSE; if (S_ISLNK (dest_stbuf.st_mode)) { - g_autofree char *dest_target = - glnx_readlinkat_malloc (destination_dfd, destination_name, - cancellable, error); + g_autofree char *dest_target = glnx_readlinkat_malloc ( + destination_dfd, destination_name, cancellable, error); if (!dest_target) return FALSE; /* In theory we could also compare xattrs...but eh */ @@ -300,32 +285,35 @@ create_file_copy_from_input_at (OstreeRepo *repo, /* Process ownership and xattrs now that we made the link */ if (options->mode != OSTREE_REPO_CHECKOUT_MODE_USER) { - if (TEMP_FAILURE_RETRY (fchownat (destination_dfd, destination_name, - g_file_info_get_attribute_uint32 (file_info, "unix::uid"), - g_file_info_get_attribute_uint32 (file_info, "unix::gid"), - AT_SYMLINK_NOFOLLOW)) == -1) + if (TEMP_FAILURE_RETRY (fchownat ( + destination_dfd, destination_name, + g_file_info_get_attribute_uint32 (file_info, "unix::uid"), + g_file_info_get_attribute_uint32 (file_info, "unix::gid"), AT_SYMLINK_NOFOLLOW)) + == -1) return glnx_throw_errno_prefix (error, "fchownat"); - if (xattrs != NULL && - !glnx_dfd_name_set_all_xattrs (destination_dfd, destination_name, - xattrs, cancellable, error)) + if (xattrs != NULL + && !glnx_dfd_name_set_all_xattrs (destination_dfd, destination_name, xattrs, + cancellable, error)) return FALSE; } } else if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR) { - g_auto(GLnxTmpfile) tmpf = { 0, }; + g_auto (GLnxTmpfile) tmpf = { + 0, + }; - if (!glnx_open_tmpfile_linkable_at (destination_dfd, ".", O_WRONLY | O_CLOEXEC, - &tmpf, error)) + if (!glnx_open_tmpfile_linkable_at (destination_dfd, ".", O_WRONLY | O_CLOEXEC, &tmpf, error)) return FALSE; if (sepolicy_enabled && options->mode != OSTREE_REPO_CHECKOUT_MODE_USER) { g_autofree char *label = NULL; - if (!ostree_sepolicy_get_label (options->sepolicy, state->selabel_path_buf->str, - g_file_info_get_attribute_uint32 (file_info, "unix::mode"), - &label, cancellable, error)) + if (!ostree_sepolicy_get_label ( + options->sepolicy, state->selabel_path_buf->str, + g_file_info_get_attribute_uint32 (file_info, "unix::mode"), &label, cancellable, + error)) return FALSE; if (fsetxattr (tmpf.fd, "security.selinux", label, strlen (label), 0) < 0) @@ -379,9 +367,9 @@ create_file_copy_from_input_at (OstreeRepo *repo, flags |= OSTREE_CHECKSUM_FLAGS_CANONICAL_PERMISSIONS; g_autofree char *actual_checksum = NULL; - if (!ostree_checksum_file_at (destination_dfd, destination_name, - &dest_stbuf, OSTREE_OBJECT_TYPE_FILE, - flags, &actual_checksum, cancellable, error)) + if (!ostree_checksum_file_at (destination_dfd, destination_name, &dest_stbuf, + OSTREE_OBJECT_TYPE_FILE, flags, &actual_checksum, + cancellable, error)) return FALSE; if (g_str_equal (checksum, actual_checksum)) @@ -395,9 +383,7 @@ create_file_copy_from_input_at (OstreeRepo *repo, break; } - if (!glnx_link_tmpfile_at (&tmpf, replace_mode, - destination_dfd, destination_name, - error)) + if (!glnx_link_tmpfile_at (&tmpf, replace_mode, destination_dfd, destination_name, error)) return FALSE; } else @@ -406,7 +392,8 @@ create_file_copy_from_input_at (OstreeRepo *repo, return TRUE; } -typedef enum { +typedef enum +{ HARDLINK_RESULT_NOT_SUPPORTED, HARDLINK_RESULT_SKIP_EXISTED, HARDLINK_RESULT_LINKED @@ -418,12 +405,8 @@ typedef enum { * buffer @tmpname. */ static gboolean -hardlink_add_tmp_name (OstreeRepo *self, - int srcfd, - const char *loose_path, - char *tmpname, - GCancellable *cancellable, - GError **error) +hardlink_add_tmp_name (OstreeRepo *self, int srcfd, const char *loose_path, char *tmpname, + GCancellable *cancellable, GError **error) { const int max_attempts = 128; guint i; @@ -448,20 +431,14 @@ hardlink_add_tmp_name (OstreeRepo *self, } static gboolean -checkout_file_hardlink (OstreeRepo *self, - const char *checksum, - OstreeRepoCheckoutAtOptions *options, - const char *loose_path, - int destination_dfd, - const char *destination_name, - gboolean allow_noent, - HardlinkResult *out_result, - GCancellable *cancellable, - GError **error) +checkout_file_hardlink (OstreeRepo *self, const char *checksum, + OstreeRepoCheckoutAtOptions *options, const char *loose_path, + int destination_dfd, const char *destination_name, gboolean allow_noent, + HardlinkResult *out_result, GCancellable *cancellable, GError **error) { HardlinkResult ret_result = HARDLINK_RESULT_NOT_SUPPORTED; - int srcfd = _ostree_repo_mode_is_bare (self->mode) ? - self->objects_dir_fd : self->uncompressed_objects_dir_fd; + int srcfd = _ostree_repo_mode_is_bare (self->mode) ? self->objects_dir_fd + : self->uncompressed_objects_dir_fd; if (srcfd == -1) { @@ -487,7 +464,8 @@ checkout_file_hardlink (OstreeRepo *self, { case OSTREE_REPO_CHECKOUT_OVERWRITE_NONE: /* Just throw */ - return glnx_throw_errno_prefix (error, "Hardlinking %s to %s", loose_path, destination_name); + return glnx_throw_errno_prefix (error, "Hardlinking %s to %s", loose_path, + destination_name); case OSTREE_REPO_CHECKOUT_OVERWRITE_ADD_FILES: /* In this mode, we keep existing content. Distinguish this case though to * avoid inserting into the devino cache. @@ -511,16 +489,14 @@ checkout_file_hardlink (OstreeRepo *self, * into place. */ struct stat src_stbuf; - if (!glnx_fstatat (srcfd, loose_path, &src_stbuf, - AT_SYMLINK_NOFOLLOW, error)) + if (!glnx_fstatat (srcfd, loose_path, &src_stbuf, AT_SYMLINK_NOFOLLOW, error)) return FALSE; struct stat dest_stbuf; - if (!glnx_fstatat (destination_dfd, destination_name, &dest_stbuf, - AT_SYMLINK_NOFOLLOW, error)) + if (!glnx_fstatat (destination_dfd, destination_name, &dest_stbuf, AT_SYMLINK_NOFOLLOW, + error)) return FALSE; - gboolean is_identical = - (src_stbuf.st_dev == dest_stbuf.st_dev && - src_stbuf.st_ino == dest_stbuf.st_ino); + gboolean is_identical + = (src_stbuf.st_dev == dest_stbuf.st_dev && src_stbuf.st_ino == dest_stbuf.st_ino); if (!is_identical && (_ostree_stbuf_equal (&src_stbuf, &dest_stbuf))) { /* As a last resort, do a checksum comparison. This is the case currently @@ -536,9 +512,9 @@ checkout_file_hardlink (OstreeRepo *self, flags |= OSTREE_CHECKSUM_FLAGS_CANONICAL_PERMISSIONS; g_autofree char *actual_checksum = NULL; - if (!ostree_checksum_file_at (destination_dfd, destination_name, - &dest_stbuf, OSTREE_OBJECT_TYPE_FILE, - flags, &actual_checksum, cancellable, error)) + if (!ostree_checksum_file_at (destination_dfd, destination_name, &dest_stbuf, + OSTREE_OBJECT_TYPE_FILE, flags, &actual_checksum, + cancellable, error)) return FALSE; is_identical = g_str_equal (checksum, actual_checksum); @@ -559,16 +535,20 @@ checkout_file_hardlink (OstreeRepo *self, if (!glnx_shutil_rm_rf_at (destination_dfd, destination_name, NULL, error)) return FALSE; } - /* Rename it into place - for non-OCI this will overwrite files but not directories */ - if (!glnx_renameat (self->tmp_dir_fd, tmpname, destination_dfd, destination_name, error)) + /* Rename it into place - for non-OCI this will overwrite files but not directories + */ + if (!glnx_renameat (self->tmp_dir_fd, tmpname, destination_dfd, destination_name, + error)) return FALSE; ret_result = HARDLINK_RESULT_LINKED; } else { - g_assert_cmpint (options->overwrite_mode, ==, OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_IDENTICAL); + g_assert_cmpint (options->overwrite_mode, ==, + OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_IDENTICAL); errno = saved_errno; - return glnx_throw_errno_prefix (error, "Hardlinking %s to %s", loose_path, destination_name); + return glnx_throw_errno_prefix (error, "Hardlinking %s to %s", loose_path, + destination_name); } break; } @@ -585,19 +565,16 @@ checkout_file_hardlink (OstreeRepo *self, } static gboolean -_checkout_overlayfs_whiteout_at_no_overwrite (OstreeRepoCheckoutAtOptions *options, - int destination_dfd, - const char *destination_name, - GFileInfo *file_info, - GVariant *xattrs, - gboolean *found_exant_file, - GCancellable *cancellable, - GError **error) +_checkout_overlayfs_whiteout_at_no_overwrite (OstreeRepoCheckoutAtOptions *options, + int destination_dfd, const char *destination_name, + GFileInfo *file_info, GVariant *xattrs, + gboolean *found_exant_file, GCancellable *cancellable, + GError **error) { if (found_exant_file != NULL) *found_exant_file = FALSE; guint32 file_mode = g_file_info_get_attribute_uint32 (file_info, "unix::mode"); - if (mknodat(destination_dfd, destination_name, (file_mode & ~S_IFMT) | S_IFCHR, (dev_t)0) < 0) + if (mknodat (destination_dfd, destination_name, (file_mode & ~S_IFMT) | S_IFCHR, (dev_t)0) < 0) { if (errno == EEXIST && found_exant_file != NULL) { @@ -608,40 +585,39 @@ _checkout_overlayfs_whiteout_at_no_overwrite (OstreeRepoCheckoutAtOptions *op } if (options->mode != OSTREE_REPO_CHECKOUT_MODE_USER) { - if (xattrs != NULL && - !glnx_dfd_name_set_all_xattrs(destination_dfd, destination_name, xattrs, - cancellable, error)) - return glnx_throw_errno_prefix (error, "Setting xattrs for whiteout char device"); - - if (TEMP_FAILURE_RETRY(fchownat(destination_dfd, destination_name, - g_file_info_get_attribute_uint32 (file_info, "unix::uid"), - g_file_info_get_attribute_uint32 (file_info, "unix::gid"), - AT_SYMLINK_NOFOLLOW) < 0)) - return glnx_throw_errno_prefix (error, "fchownat"); - if (TEMP_FAILURE_RETRY (fchmodat (destination_dfd, destination_name, file_mode & ~S_IFMT, 0)) < 0) - return glnx_throw_errno_prefix (error, "fchmodat %s to 0%o", destination_name, file_mode & ~S_IFMT); + if (xattrs != NULL + && !glnx_dfd_name_set_all_xattrs (destination_dfd, destination_name, xattrs, cancellable, + error)) + return glnx_throw_errno_prefix (error, "Setting xattrs for whiteout char device"); + + if (TEMP_FAILURE_RETRY (fchownat (destination_dfd, destination_name, + g_file_info_get_attribute_uint32 (file_info, "unix::uid"), + g_file_info_get_attribute_uint32 (file_info, "unix::gid"), + AT_SYMLINK_NOFOLLOW) + < 0)) + return glnx_throw_errno_prefix (error, "fchownat"); + if (TEMP_FAILURE_RETRY (fchmodat (destination_dfd, destination_name, file_mode & ~S_IFMT, 0)) + < 0) + return glnx_throw_errno_prefix (error, "fchmodat %s to 0%o", destination_name, + file_mode & ~S_IFMT); } return TRUE; } static gboolean -_checkout_overlayfs_whiteout_at (OstreeRepo *repo, - OstreeRepoCheckoutAtOptions *options, - int destination_dfd, - const char *destination_name, - GFileInfo *file_info, - GVariant *xattrs, - GCancellable *cancellable, - GError **error) +_checkout_overlayfs_whiteout_at (OstreeRepo *repo, OstreeRepoCheckoutAtOptions *options, + int destination_dfd, const char *destination_name, + GFileInfo *file_info, GVariant *xattrs, GCancellable *cancellable, + GError **error) { gboolean found_exant_file = FALSE; - if (!_checkout_overlayfs_whiteout_at_no_overwrite(options, destination_dfd, destination_name, - file_info, xattrs,&found_exant_file, - cancellable, error)) + if (!_checkout_overlayfs_whiteout_at_no_overwrite (options, destination_dfd, destination_name, + file_info, xattrs, &found_exant_file, + cancellable, error)) return FALSE; - if (!found_exant_file) + if (!found_exant_file) return TRUE; guint32 uid = g_file_info_get_attribute_uint32 (file_info, "unix::uid"); @@ -650,60 +626,55 @@ _checkout_overlayfs_whiteout_at (OstreeRepo *repo, struct stat dest_stbuf; - switch(options->overwrite_mode) + switch (options->overwrite_mode) { - case OSTREE_REPO_CHECKOUT_OVERWRITE_NONE: + case OSTREE_REPO_CHECKOUT_OVERWRITE_NONE: + return FALSE; + case OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_FILES: + if (!ot_ensure_unlinked_at (destination_dfd, destination_name, error)) return FALSE; - case OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_FILES: - if (!ot_ensure_unlinked_at (destination_dfd, destination_name, error)) - return FALSE; - return _checkout_overlayfs_whiteout_at_no_overwrite(options, destination_dfd, destination_name, - file_info, xattrs, NULL, cancellable, error); - case OSTREE_REPO_CHECKOUT_OVERWRITE_ADD_FILES: - return TRUE; - - case OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_IDENTICAL: - if (!glnx_fstatat(destination_dfd, destination_name, &dest_stbuf, AT_SYMLINK_NOFOLLOW, - error)) - return FALSE; - if (!(repo->disable_xattrs || repo->mode == OSTREE_REPO_MODE_BARE_USER_ONLY)) - { - g_autoptr(GVariant) fs_xattrs; - if (!glnx_dfd_name_get_all_xattrs (destination_dfd, destination_name, - &fs_xattrs, cancellable, error)) - return FALSE; - if (!g_variant_equal(fs_xattrs, xattrs)) - return glnx_throw(error, "existing destination file %s xattrs don't match", - destination_name); - } - if (options->mode != OSTREE_REPO_CHECKOUT_MODE_USER) - { - if (gid != dest_stbuf.st_gid) - return glnx_throw(error, "existing destination file %s does not match gid %d", - destination_name, gid); + return _checkout_overlayfs_whiteout_at_no_overwrite ( + options, destination_dfd, destination_name, file_info, xattrs, NULL, cancellable, error); + case OSTREE_REPO_CHECKOUT_OVERWRITE_ADD_FILES: + return TRUE; + + case OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_IDENTICAL: + if (!glnx_fstatat (destination_dfd, destination_name, &dest_stbuf, AT_SYMLINK_NOFOLLOW, + error)) + return FALSE; + if (!(repo->disable_xattrs || repo->mode == OSTREE_REPO_MODE_BARE_USER_ONLY)) + { + g_autoptr (GVariant) fs_xattrs; + if (!glnx_dfd_name_get_all_xattrs (destination_dfd, destination_name, &fs_xattrs, + cancellable, error)) + return FALSE; + if (!g_variant_equal (fs_xattrs, xattrs)) + return glnx_throw (error, "existing destination file %s xattrs don't match", + destination_name); + } + if (options->mode != OSTREE_REPO_CHECKOUT_MODE_USER) + { + if (gid != dest_stbuf.st_gid) + return glnx_throw (error, "existing destination file %s does not match gid %d", + destination_name, gid); - if (uid != dest_stbuf.st_uid) - return glnx_throw(error, "existing destination file %s does not match uid %d", - destination_name, uid); + if (uid != dest_stbuf.st_uid) + return glnx_throw (error, "existing destination file %s does not match uid %d", + destination_name, uid); - if ((file_mode & ALLPERMS) != (dest_stbuf.st_mode & ALLPERMS)) - return glnx_throw(error, "existing destination file %s does not match mode %o", - destination_name, file_mode); - } - break; + if ((file_mode & ALLPERMS) != (dest_stbuf.st_mode & ALLPERMS)) + return glnx_throw (error, "existing destination file %s does not match mode %o", + destination_name, file_mode); + } + break; } - return TRUE; + return TRUE; } static gboolean -checkout_one_file_at (OstreeRepo *repo, - OstreeRepoCheckoutAtOptions *options, - CheckoutState *state, - const char *checksum, - int destination_dfd, - const char *destination_name, - GCancellable *cancellable, - GError **error) +checkout_one_file_at (OstreeRepo *repo, OstreeRepoCheckoutAtOptions *options, CheckoutState *state, + const char *checksum, int destination_dfd, const char *destination_name, + GCancellable *cancellable, GError **error) { /* Validate this up front to prevent path traversal attacks */ if (!ot_util_filename_validate (destination_name, error)) @@ -713,33 +684,37 @@ checkout_one_file_at (OstreeRepo *repo, gboolean is_bare_user_symlink = FALSE; char loose_path_buf[_OSTREE_LOOSE_PATH_MAX]; - /* FIXME - avoid the GFileInfo here */ - g_autoptr(GFileInfo) source_info = NULL; - g_autoptr(GVariant) source_xattrs = NULL; - if (!ostree_repo_load_file (repo, checksum, NULL, &source_info, &source_xattrs, - cancellable, error)) + g_autoptr (GFileInfo) source_info = NULL; + g_autoptr (GVariant) source_xattrs = NULL; + if (!ostree_repo_load_file (repo, checksum, NULL, &source_info, &source_xattrs, cancellable, + error)) return FALSE; if (options->filter) { /* use struct stat for when we can get rid of GFileInfo; though for now, we end up * packing and unpacking in the non-archive case; blehh */ - struct stat stbuf = {0,}; + struct stat stbuf = { + 0, + }; _ostree_gfileinfo_to_stbuf (source_info, &stbuf); - if (options->filter (repo, state->path_buf->str, &stbuf, options->filter_user_data) == - OSTREE_REPO_CHECKOUT_FILTER_SKIP) + if (options->filter (repo, state->path_buf->str, &stbuf, options->filter_user_data) + == OSTREE_REPO_CHECKOUT_FILTER_SKIP) return TRUE; /* Note early return */ } - const gboolean is_symlink = (g_file_info_get_file_type (source_info) == G_FILE_TYPE_SYMBOLIC_LINK); + const gboolean is_symlink + = (g_file_info_get_file_type (source_info) == G_FILE_TYPE_SYMBOLIC_LINK); const guint32 source_mode = g_file_info_get_attribute_uint32 (source_info, "unix::mode"); const gboolean is_unreadable = (!is_symlink && (source_mode & S_IRUSR) == 0); - const gboolean is_whiteout = (!is_symlink && options->process_whiteouts && - g_str_has_prefix (destination_name, WHITEOUT_PREFIX)); - const gboolean is_overlayfs_whiteout = (!is_symlink && g_str_has_prefix (destination_name, OVERLAYFS_WHITEOUT_PREFIX)); + const gboolean is_whiteout = (!is_symlink && options->process_whiteouts + && g_str_has_prefix (destination_name, WHITEOUT_PREFIX)); + const gboolean is_overlayfs_whiteout + = (!is_symlink && g_str_has_prefix (destination_name, OVERLAYFS_WHITEOUT_PREFIX)); const gboolean is_reg_zerosized = (!is_symlink && g_file_info_get_size (source_info) == 0); - const gboolean override_user_unreadable = (options->mode == OSTREE_REPO_CHECKOUT_MODE_USER && is_unreadable); + const gboolean override_user_unreadable + = (options->mode == OSTREE_REPO_CHECKOUT_MODE_USER && is_unreadable); /* First, see if it's a Docker whiteout, * https://github.com/docker/docker/blob/1a714e76a2cb9008cd19609059e9988ff1660b78/pkg/archive/whiteouts.go @@ -767,8 +742,8 @@ checkout_one_file_at (OstreeRepo *repo, g_assert (name[0] != '/'); /* Sanity */ - return _checkout_overlayfs_whiteout_at(repo, options, destination_dfd, name, - source_info, source_xattrs, cancellable, error); + return _checkout_overlayfs_whiteout_at (repo, options, destination_dfd, name, source_info, + source_xattrs, cancellable, error); } else if (is_reg_zerosized || override_user_unreadable) { @@ -791,19 +766,18 @@ checkout_one_file_at (OstreeRepo *repo, /* TODO - Hoist this up to the toplevel at least for checking out from * !parent; don't need to compute it for each file. */ - gboolean repo_is_usermode = - current_repo->mode == OSTREE_REPO_MODE_BARE_USER || - current_repo->mode == OSTREE_REPO_MODE_BARE_USER_ONLY; + gboolean repo_is_usermode = current_repo->mode == OSTREE_REPO_MODE_BARE_USER + || current_repo->mode == OSTREE_REPO_MODE_BARE_USER_ONLY; /* We're hardlinkable if the checkout mode matches the repo mode */ - gboolean is_hardlinkable = - (current_repo->mode == OSTREE_REPO_MODE_BARE - && options->mode == OSTREE_REPO_CHECKOUT_MODE_NONE) || - (repo_is_usermode && options->mode == OSTREE_REPO_CHECKOUT_MODE_USER); - gboolean current_can_cache = (options->enable_uncompressed_cache - && current_repo->enable_uncompressed_cache); - gboolean is_archive_z2_with_cache = (current_repo->mode == OSTREE_REPO_MODE_ARCHIVE - && options->mode == OSTREE_REPO_CHECKOUT_MODE_USER - && current_can_cache); + gboolean is_hardlinkable + = (current_repo->mode == OSTREE_REPO_MODE_BARE + && options->mode == OSTREE_REPO_CHECKOUT_MODE_NONE) + || (repo_is_usermode && options->mode == OSTREE_REPO_CHECKOUT_MODE_USER); + gboolean current_can_cache + = (options->enable_uncompressed_cache && current_repo->enable_uncompressed_cache); + gboolean is_archive_z2_with_cache + = (current_repo->mode == OSTREE_REPO_MODE_ARCHIVE + && options->mode == OSTREE_REPO_CHECKOUT_MODE_USER && current_can_cache); /* NOTE: bare-user symlinks are not stored as symlinks; see * https://github.com/ostreedev/ostree/commit/47c612e5a0688c3452a125655a245e8f4f01b2b0 @@ -817,22 +791,19 @@ checkout_one_file_at (OstreeRepo *repo, */ if (options->no_copy_fallback && !is_hardlinkable && !is_bare_user_symlink) return glnx_throw (error, - repo_is_usermode ? - "User repository mode requires user checkout mode to hardlink" : - "Bare repository mode cannot hardlink in user checkout mode"); + repo_is_usermode + ? "User repository mode requires user checkout mode to hardlink" + : "Bare repository mode cannot hardlink in user checkout mode"); /* But only under these conditions */ if (is_bare || is_archive_z2_with_cache) { /* Override repo mode; for archive we're looking in the cache, which is in "bare" form */ - _ostree_loose_path (loose_path_buf, checksum, OSTREE_OBJECT_TYPE_FILE, OSTREE_REPO_MODE_BARE); - if (!checkout_file_hardlink (current_repo, - checksum, - options, - loose_path_buf, - destination_dfd, destination_name, - TRUE, &hardlink_res, + _ostree_loose_path (loose_path_buf, checksum, OSTREE_OBJECT_TYPE_FILE, + OSTREE_REPO_MODE_BARE); + if (!checkout_file_hardlink (current_repo, checksum, options, loose_path_buf, + destination_dfd, destination_name, TRUE, &hardlink_res, cancellable, error)) return FALSE; @@ -841,15 +812,17 @@ checkout_one_file_at (OstreeRepo *repo, struct stat stbuf; OstreeDevIno *key; - if (TEMP_FAILURE_RETRY (fstatat (destination_dfd, destination_name, &stbuf, AT_SYMLINK_NOFOLLOW)) != 0) + if (TEMP_FAILURE_RETRY ( + fstatat (destination_dfd, destination_name, &stbuf, AT_SYMLINK_NOFOLLOW)) + != 0) return glnx_throw_errno (error); key = g_new (OstreeDevIno, 1); key->dev = stbuf.st_dev; key->ino = stbuf.st_ino; - memcpy (key->checksum, checksum, OSTREE_SHA256_STRING_LEN+1); + memcpy (key->checksum, checksum, OSTREE_SHA256_STRING_LEN + 1); - g_hash_table_add ((GHashTable*)options->devino_to_csum_cache, key); + g_hash_table_add ((GHashTable *)options->devino_to_csum_cache, key); } if (hardlink_res != HARDLINK_RESULT_NOT_SUPPORTED) @@ -863,34 +836,28 @@ checkout_one_file_at (OstreeRepo *repo, need_copy = (hardlink_res == HARDLINK_RESULT_NOT_SUPPORTED); } - const gboolean can_cache = (options->enable_uncompressed_cache - && repo->enable_uncompressed_cache); + const gboolean can_cache + = (options->enable_uncompressed_cache && repo->enable_uncompressed_cache); - g_autoptr(GInputStream) input = NULL; - g_autoptr(GVariant) xattrs = NULL; + g_autoptr (GInputStream) input = NULL; + g_autoptr (GVariant) xattrs = NULL; /* Ok, if we're archive and we didn't find an object, uncompress * it now, stick it in the cache, and then hardlink to that. */ - if (can_cache - && !is_whiteout - && !is_symlink - && !(is_reg_zerosized || override_user_unreadable) - && need_copy - && repo->mode == OSTREE_REPO_MODE_ARCHIVE + if (can_cache && !is_whiteout && !is_symlink && !(is_reg_zerosized || override_user_unreadable) + && need_copy && repo->mode == OSTREE_REPO_MODE_ARCHIVE && options->mode == OSTREE_REPO_CHECKOUT_MODE_USER) { HardlinkResult hardlink_res = HARDLINK_RESULT_NOT_SUPPORTED; - if (!ostree_repo_load_file (repo, checksum, &input, NULL, NULL, - cancellable, error)) + if (!ostree_repo_load_file (repo, checksum, &input, NULL, NULL, cancellable, error)) return FALSE; /* Overwrite any parent repo from earlier */ _ostree_loose_path (loose_path_buf, checksum, OSTREE_OBJECT_TYPE_FILE, OSTREE_REPO_MODE_BARE); - if (!checkout_object_for_uncompressed_cache (repo, loose_path_buf, - source_info, input, + if (!checkout_object_for_uncompressed_cache (repo, loose_path_buf, source_info, input, cancellable, error)) return glnx_prefix_error (error, "Unpacking loose object %s", checksum); @@ -913,19 +880,18 @@ checkout_one_file_at (OstreeRepo *repo, */ g_mutex_lock (&repo->cache_lock); { - gpointer key = GUINT_TO_POINTER ((g_ascii_xdigit_value (checksum[0]) << 4) + - g_ascii_xdigit_value (checksum[1])); + gpointer key = GUINT_TO_POINTER ((g_ascii_xdigit_value (checksum[0]) << 4) + + g_ascii_xdigit_value (checksum[1])); if (repo->updated_uncompressed_dirs == NULL) repo->updated_uncompressed_dirs = g_hash_table_new (NULL, NULL); g_hash_table_add (repo->updated_uncompressed_dirs, key); } g_mutex_unlock (&repo->cache_lock); - if (!checkout_file_hardlink (repo, checksum, options, loose_path_buf, - destination_dfd, destination_name, - FALSE, &hardlink_res, - cancellable, error)) - return glnx_prefix_error (error, "Using new cached uncompressed hardlink of %s to %s", checksum, destination_name); + if (!checkout_file_hardlink (repo, checksum, options, loose_path_buf, destination_dfd, + destination_name, FALSE, &hardlink_res, cancellable, error)) + return glnx_prefix_error (error, "Using new cached uncompressed hardlink of %s to %s", + checksum, destination_name); need_copy = (hardlink_res == HARDLINK_RESULT_NOT_SUPPORTED); } @@ -940,12 +906,11 @@ checkout_one_file_at (OstreeRepo *repo, */ if (options->no_copy_fallback) g_assert (is_bare_user_symlink || is_reg_zerosized || override_user_unreadable); - if (!ostree_repo_load_file (repo, checksum, &input, NULL, &xattrs, - cancellable, error)) + if (!ostree_repo_load_file (repo, checksum, &input, NULL, &xattrs, cancellable, error)) return FALSE; GFileInfo *copy_source_info = source_info; - g_autoptr(GFileInfo) modified_info = NULL; + g_autoptr (GFileInfo) modified_info = NULL; if (override_user_unreadable) { modified_info = g_file_info_dup (source_info); @@ -953,9 +918,9 @@ checkout_one_file_at (OstreeRepo *repo, copy_source_info = modified_info; } - if (!create_file_copy_from_input_at (repo, options, state, checksum, copy_source_info, xattrs, input, - destination_dfd, destination_name, - cancellable, error)) + if (!create_file_copy_from_input_at (repo, options, state, checksum, copy_source_info, xattrs, + input, destination_dfd, destination_name, cancellable, + error)) return glnx_prefix_error (error, "Copy checkout of %s to %s", checksum, destination_name); if (input) @@ -969,9 +934,7 @@ checkout_one_file_at (OstreeRepo *repo, } static inline void -push_path_element_once (GString *buf, - const char *name, - gboolean is_dir) +push_path_element_once (GString *buf, const char *name, gboolean is_dir) { g_string_append (buf, name); if (is_dir) @@ -979,10 +942,8 @@ push_path_element_once (GString *buf, } static inline void -push_path_element (OstreeRepoCheckoutAtOptions *options, - CheckoutState *state, - const char *name, - gboolean is_dir) +push_path_element (OstreeRepoCheckoutAtOptions *options, CheckoutState *state, const char *name, + gboolean is_dir) { if (state->path_buf) push_path_element_once (state->path_buf, name, is_dir); @@ -991,10 +952,8 @@ push_path_element (OstreeRepoCheckoutAtOptions *options, } static inline void -pop_path_element (OstreeRepoCheckoutAtOptions *options, - CheckoutState *state, - const char *name, - gboolean is_dir) +pop_path_element (OstreeRepoCheckoutAtOptions *options, CheckoutState *state, const char *name, + gboolean is_dir) { const size_t n = strlen (name) + (is_dir ? 1 : 0); if (state->path_buf) @@ -1020,35 +979,29 @@ pop_path_element (OstreeRepoCheckoutAtOptions *options, * relative @destination_name, located by @destination_parent_fd. */ static gboolean -checkout_tree_at_recurse (OstreeRepo *self, - OstreeRepoCheckoutAtOptions *options, - CheckoutState *state, - int destination_parent_fd, - const char *destination_name, - const char *dirtree_checksum, - const char *dirmeta_checksum, - GCancellable *cancellable, - GError **error) +checkout_tree_at_recurse (OstreeRepo *self, OstreeRepoCheckoutAtOptions *options, + CheckoutState *state, int destination_parent_fd, + const char *destination_name, const char *dirtree_checksum, + const char *dirmeta_checksum, GCancellable *cancellable, GError **error) { gboolean did_exist = FALSE; gboolean is_opaque_whiteout = FALSE; const gboolean sepolicy_enabled = options->sepolicy && !self->disable_xattrs; - g_autoptr(GVariant) dirtree = NULL; - g_autoptr(GVariant) dirmeta = NULL; - g_autoptr(GVariant) xattrs = NULL; - g_autoptr(GVariant) modified_xattrs = NULL; + g_autoptr (GVariant) dirtree = NULL; + g_autoptr (GVariant) dirmeta = NULL; + g_autoptr (GVariant) xattrs = NULL; + g_autoptr (GVariant) modified_xattrs = NULL; - if (!ostree_repo_load_variant (self, OSTREE_OBJECT_TYPE_DIR_TREE, - dirtree_checksum, &dirtree, error)) + if (!ostree_repo_load_variant (self, OSTREE_OBJECT_TYPE_DIR_TREE, dirtree_checksum, &dirtree, + error)) return FALSE; - if (!ostree_repo_load_variant (self, OSTREE_OBJECT_TYPE_DIR_META, - dirmeta_checksum, &dirmeta, error)) + if (!ostree_repo_load_variant (self, OSTREE_OBJECT_TYPE_DIR_META, dirmeta_checksum, &dirmeta, + error)) return FALSE; /* Parse OSTREE_OBJECT_TYPE_DIR_META */ guint32 uid, gid, mode; - g_variant_get (dirmeta, "(uuu@a(ayay))", - &uid, &gid, &mode, + g_variant_get (dirmeta, "(uuu@a(ayay))", &uid, &gid, &mode, options->mode != OSTREE_REPO_CHECKOUT_MODE_USER ? &xattrs : NULL); uid = GUINT32_FROM_BE (uid); gid = GUINT32_FROM_BE (gid); @@ -1056,7 +1009,9 @@ checkout_tree_at_recurse (OstreeRepo *self, if (options->filter) { - struct stat stbuf = { 0, }; + struct stat stbuf = { + 0, + }; stbuf.st_mode = mode; stbuf.st_uid = uid; stbuf.st_gid = gid; @@ -1067,10 +1022,10 @@ checkout_tree_at_recurse (OstreeRepo *self, if (options->process_whiteouts) { - 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; const char *fname; - g_autoptr(GVariant) contents_csum_v = NULL; + g_autoptr (GVariant) contents_csum_v = NULL; g_variant_iter_init (&viter, dir_file_contents); while (g_variant_iter_loop (&viter, "(&s@ay)", &fname, &contents_csum_v)) { @@ -1085,7 +1040,9 @@ checkout_tree_at_recurse (OstreeRepo *self, * setfscreatecon(). */ { - g_auto(OstreeSepolicyFsCreatecon) fscreatecon = { 0, }; + g_auto (OstreeSepolicyFsCreatecon) fscreatecon = { + 0, + }; /* If we're doing SELinux labeling, prepare it */ if (sepolicy_enabled) @@ -1095,8 +1052,7 @@ checkout_tree_at_recurse (OstreeRepo *self, xattrs = modified_xattrs; if (!_ostree_sepolicy_preparefscreatecon (&fscreatecon, options->sepolicy, - state->selabel_path_buf->str, - mode, error)) + state->selabel_path_buf->str, mode, error)) return FALSE; } @@ -1131,8 +1087,7 @@ checkout_tree_at_recurse (OstreeRepo *self, } glnx_autofd int destination_dfd = -1; - if (!glnx_opendirat (destination_parent_fd, destination_name, TRUE, - &destination_dfd, error)) + if (!glnx_opendirat (destination_parent_fd, destination_name, TRUE, &destination_dfd, error)) return FALSE; struct stat repo_dfd_stat; @@ -1143,7 +1098,9 @@ checkout_tree_at_recurse (OstreeRepo *self, return glnx_throw_errno (error); if (options->no_copy_fallback && repo_dfd_stat.st_dev != destination_stat.st_dev) - return glnx_throw (error, "Unable to do hardlink checkout across devices (src=%"G_GUINT64_FORMAT" destination=%"G_GUINT64_FORMAT")", + return glnx_throw (error, + "Unable to do hardlink checkout across devices (src=%" G_GUINT64_FORMAT + " destination=%" G_GUINT64_FORMAT ")", (guint64)repo_dfd_stat.st_dev, (guint64)destination_stat.st_dev); /* Set the xattrs if we created the dir */ @@ -1154,21 +1111,20 @@ checkout_tree_at_recurse (OstreeRepo *self, } /* Process files in this subdir */ - { 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; - g_autoptr(GVariant) contents_csum_v = NULL; + g_autoptr (GVariant) contents_csum_v = NULL; while (g_variant_iter_loop (&viter, "(&s@ay)", &fname, &contents_csum_v)) { push_path_element (options, state, fname, FALSE); - char tmp_checksum[OSTREE_SHA256_STRING_LEN+1]; + char tmp_checksum[OSTREE_SHA256_STRING_LEN + 1]; _ostree_checksum_inplace_from_bytes_v (contents_csum_v, tmp_checksum); - if (!checkout_one_file_at (self, options, state, - tmp_checksum, - destination_dfd, fname, + if (!checkout_one_file_at (self, options, state, tmp_checksum, destination_dfd, fname, cancellable, error)) return FALSE; @@ -1178,14 +1134,15 @@ checkout_tree_at_recurse (OstreeRepo *self, } /* 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; - g_autoptr(GVariant) subdirtree_csum_v = NULL; - g_autoptr(GVariant) subdirmeta_csum_v = NULL; + g_autoptr (GVariant) subdirtree_csum_v = NULL; + g_autoptr (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)) { /* Validate this up front to prevent path traversal attacks. Note that * we don't validate at the top of this function like we do for @@ -1198,14 +1155,13 @@ checkout_tree_at_recurse (OstreeRepo *self, push_path_element (options, state, dname, TRUE); - 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); - if (!checkout_tree_at_recurse (self, options, state, - destination_dfd, dname, - subdirtree_checksum, subdirmeta_checksum, - cancellable, error)) + if (!checkout_tree_at_recurse (self, options, state, destination_dfd, dname, + subdirtree_checksum, subdirmeta_checksum, cancellable, + error)) return FALSE; pop_path_element (options, state, dname, TRUE); @@ -1221,7 +1177,8 @@ checkout_tree_at_recurse (OstreeRepo *self, /* Silently ignore world-writable directories (plus sticky, suid bits, * etc.) when doing a checkout for bare-user-only repos, or if requested explicitly. * This is related to the logic in ostree-repo-commit.c for files. - * See also: https://github.com/ostreedev/ostree/pull/909 i.e. 0c4b3a2b6da950fd78e63f9afec602f6188f1ab0 + * See also: https://github.com/ostreedev/ostree/pull/909 i.e. + * 0c4b3a2b6da950fd78e63f9afec602f6188f1ab0 */ if (self->mode == OSTREE_REPO_MODE_BARE_USER_ONLY || options->bareuseronly_dirs) canonical_mode = (mode & 0775) | S_IFDIR; @@ -1244,7 +1201,8 @@ checkout_tree_at_recurse (OstreeRepo *self, */ if (!did_exist && !options->force_copy) { - const struct timespec times[2] = { { OSTREE_TIMESTAMP, UTIME_OMIT }, { OSTREE_TIMESTAMP, 0} }; + const struct timespec times[2] + = { { OSTREE_TIMESTAMP, UTIME_OMIT }, { OSTREE_TIMESTAMP, 0 } }; if (TEMP_FAILURE_RETRY (futimens (destination_dfd, times)) < 0) return glnx_throw_errno (error); } @@ -1260,16 +1218,13 @@ checkout_tree_at_recurse (OstreeRepo *self, /* Begin a checkout process */ static gboolean -checkout_tree_at (OstreeRepo *self, - OstreeRepoCheckoutAtOptions *options, - int destination_parent_fd, - const char *destination_name, - OstreeRepoFile *source, - GFileInfo *source_info, - GCancellable *cancellable, - GError **error) +checkout_tree_at (OstreeRepo *self, OstreeRepoCheckoutAtOptions *options, int destination_parent_fd, + const char *destination_name, OstreeRepoFile *source, GFileInfo *source_info, + GCancellable *cancellable, GError **error) { - g_auto(CheckoutState) state = { 0, }; + g_auto (CheckoutState) state = { + 0, + }; if (options->filter) state.path_buf = g_string_new ("/"); @@ -1291,21 +1246,19 @@ checkout_tree_at (OstreeRepo *self, GString *buf = g_string_new (prefix); g_assert_cmpint (buf->len, >, 0); /* Ensure it ends with / */ - if (buf->str[buf->len-1] != '/') + if (buf->str[buf->len - 1] != '/') g_string_append_c (buf, '/'); state.selabel_path_buf = buf; } } /* Uncompressed archive caches; should be considered deprecated */ - const gboolean can_cache = (options->enable_uncompressed_cache - && self->enable_uncompressed_cache); - if (can_cache - && !_ostree_repo_mode_is_bare (self->mode) - && self->uncompressed_objects_dir_fd < 0) + const gboolean can_cache + = (options->enable_uncompressed_cache && self->enable_uncompressed_cache); + if (can_cache && !_ostree_repo_mode_is_bare (self->mode) && self->uncompressed_objects_dir_fd < 0) { - self->uncompressed_objects_dir_fd = - glnx_opendirat_with_errno (self->repo_dir_fd, "uncompressed-objects-cache", TRUE); + self->uncompressed_objects_dir_fd + = glnx_opendirat_with_errno (self->repo_dir_fd, "uncompressed-objects-cache", TRUE); if (self->uncompressed_objects_dir_fd < 0 && errno != ENOENT) return glnx_throw_errno_prefix (error, "opendir(uncompressed-objects-cache)"); } @@ -1323,8 +1276,7 @@ checkout_tree_at (OstreeRepo *self, glnx_autofd int destination_dfd_owned = -1; if (!g_str_equal (destination_name, ".")) { - if (mkdirat (destination_parent_fd, destination_name, 0700) < 0 - && errno != EEXIST) + if (mkdirat (destination_parent_fd, destination_name, 0700) < 0 && errno != EEXIST) return glnx_throw_errno_prefix (error, "mkdirat"); if (!glnx_opendirat (destination_parent_fd, destination_name, TRUE, &destination_dfd_owned, error)) @@ -1334,31 +1286,26 @@ checkout_tree_at (OstreeRepo *self, /* let's just ignore filter here; I can't think of a useful case for filtering when * only checking out one path */ options->filter = NULL; - return checkout_one_file_at (self, options, &state, - ostree_repo_file_get_checksum (source), - destination_dfd, - g_file_info_get_name (source_info), - cancellable, error); + return checkout_one_file_at (self, options, &state, ostree_repo_file_get_checksum (source), + destination_dfd, g_file_info_get_name (source_info), cancellable, + error); } /* Cache any directory metadata we read during this operation; * see commit b7afe91e21143d7abb0adde440683a52712aa246 */ - g_auto(OstreeRepoMemoryCacheRef) memcache_ref; + g_auto (OstreeRepoMemoryCacheRef) memcache_ref; _ostree_repo_memory_cache_ref_init (&memcache_ref, self); g_assert_cmpint (g_file_info_get_file_type (source_info), ==, G_FILE_TYPE_DIRECTORY); const char *dirtree_checksum = ostree_repo_file_tree_get_contents_checksum (source); const char *dirmeta_checksum = ostree_repo_file_tree_get_metadata_checksum (source); - return checkout_tree_at_recurse (self, options, &state, destination_parent_fd, - destination_name, - dirtree_checksum, dirmeta_checksum, - cancellable, error); + return checkout_tree_at_recurse (self, options, &state, destination_parent_fd, destination_name, + dirtree_checksum, dirmeta_checksum, cancellable, error); } static void -canonicalize_options (OstreeRepo *self, - OstreeRepoCheckoutAtOptions *options) +canonicalize_options (OstreeRepo *self, OstreeRepoCheckoutAtOptions *options) { /* Canonicalize subpath to / */ if (!options->subpath) @@ -1386,26 +1333,22 @@ canonicalize_options (OstreeRepo *self, * files are checked out. */ gboolean -ostree_repo_checkout_tree (OstreeRepo *self, - OstreeRepoCheckoutMode mode, - OstreeRepoCheckoutOverwriteMode overwrite_mode, - GFile *destination, - OstreeRepoFile *source, - GFileInfo *source_info, - GCancellable *cancellable, - GError **error) +ostree_repo_checkout_tree (OstreeRepo *self, OstreeRepoCheckoutMode mode, + OstreeRepoCheckoutOverwriteMode overwrite_mode, GFile *destination, + OstreeRepoFile *source, GFileInfo *source_info, + GCancellable *cancellable, GError **error) { - OstreeRepoCheckoutAtOptions options = { 0, }; + OstreeRepoCheckoutAtOptions options = { + 0, + }; options.mode = mode; options.overwrite_mode = overwrite_mode; /* Backwards compatibility */ options.enable_uncompressed_cache = TRUE; canonicalize_options (self, &options); - return checkout_tree_at (self, &options, - AT_FDCWD, gs_file_get_path_cached (destination), - source, source_info, - cancellable, error); + return checkout_tree_at (self, &options, AT_FDCWD, gs_file_get_path_cached (destination), source, + source_info, cancellable, error); } /** @@ -1430,15 +1373,13 @@ ostree_repo_checkout_tree (OstreeRepo *self, * This function is deprecated. Use ostree_repo_checkout_at() instead. */ gboolean -ostree_repo_checkout_tree_at (OstreeRepo *self, - OstreeRepoCheckoutOptions *options, - int destination_dfd, - const char *destination_path, - const char *commit, - GCancellable *cancellable, - GError **error) +ostree_repo_checkout_tree_at (OstreeRepo *self, OstreeRepoCheckoutOptions *options, + int destination_dfd, const char *destination_path, const char *commit, + GCancellable *cancellable, GError **error) { - OstreeRepoCheckoutAtOptions new_opts = {0, }; + OstreeRepoCheckoutAtOptions new_opts = { + 0, + }; new_opts.mode = options->mode; new_opts.overwrite_mode = options->overwrite_mode; new_opts.enable_uncompressed_cache = options->enable_uncompressed_cache; @@ -1447,8 +1388,8 @@ ostree_repo_checkout_tree_at (OstreeRepo *self, new_opts.no_copy_fallback = options->no_copy_fallback; new_opts.subpath = options->subpath; new_opts.devino_to_csum_cache = options->devino_to_csum_cache; - return ostree_repo_checkout_at (self, &new_opts, destination_dfd, - destination_path, commit, cancellable, error); + return ostree_repo_checkout_at (self, &new_opts, destination_dfd, destination_path, commit, + cancellable, error); } /** @@ -1476,15 +1417,13 @@ ostree_repo_checkout_tree_at (OstreeRepo *self, * Since: 2016.8 */ gboolean -ostree_repo_checkout_at (OstreeRepo *self, - OstreeRepoCheckoutAtOptions *options, - int destination_dfd, - const char *destination_path, - const char *commit, - GCancellable *cancellable, - GError **error) +ostree_repo_checkout_at (OstreeRepo *self, OstreeRepoCheckoutAtOptions *options, + int destination_dfd, const char *destination_path, const char *commit, + GCancellable *cancellable, GError **error) { - OstreeRepoCheckoutAtOptions default_options = { 0, }; + OstreeRepoCheckoutAtOptions default_options = { + 0, + }; OstreeRepoCheckoutAtOptions real_options; if (!options) @@ -1501,34 +1440,31 @@ ostree_repo_checkout_at (OstreeRepo *self, g_return_val_if_fail (!(options->force_copy && options->no_copy_fallback), FALSE); g_return_val_if_fail (!options->sepolicy || options->force_copy, FALSE); /* union identical requires hardlink mode */ - g_return_val_if_fail (!(options->overwrite_mode == OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_IDENTICAL && - !options->no_copy_fallback), FALSE); + g_return_val_if_fail (!(options->overwrite_mode == OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_IDENTICAL + && !options->no_copy_fallback), + FALSE); - g_autoptr(GFile) commit_root = (GFile*) _ostree_repo_file_new_for_commit (self, commit, error); + g_autoptr (GFile) commit_root = (GFile *)_ostree_repo_file_new_for_commit (self, commit, error); if (!commit_root) return FALSE; - if (!ostree_repo_file_ensure_resolved ((OstreeRepoFile*)commit_root, error)) + if (!ostree_repo_file_ensure_resolved ((OstreeRepoFile *)commit_root, error)) return FALSE; - g_autoptr(GFile) target_dir = NULL; + g_autoptr (GFile) target_dir = NULL; if (strcmp (options->subpath, "/") != 0) target_dir = g_file_resolve_relative_path (commit_root, options->subpath); else target_dir = g_object_ref (commit_root); - g_autoptr(GFileInfo) target_info = - g_file_query_info (target_dir, OSTREE_GIO_FAST_QUERYINFO, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - cancellable, error); + g_autoptr (GFileInfo) target_info + = g_file_query_info (target_dir, OSTREE_GIO_FAST_QUERYINFO, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!target_info) return FALSE; - if (!checkout_tree_at (self, options, - destination_dfd, - destination_path, - (OstreeRepoFile*)target_dir, target_info, - cancellable, error)) + if (!checkout_tree_at (self, options, destination_dfd, destination_path, + (OstreeRepoFile *)target_dir, target_info, cancellable, error)) return FALSE; return TRUE; @@ -1558,17 +1494,15 @@ static guint devino_hash (gconstpointer a) { OstreeDevIno *a_i = (gpointer)a; - return (guint) (a_i->dev + a_i->ino); + return (guint)(a_i->dev + a_i->ino); } static int -devino_equal (gconstpointer a, - gconstpointer b) +devino_equal (gconstpointer a, gconstpointer b) { OstreeDevIno *a_i = (gpointer)a; OstreeDevIno *b_i = (gpointer)b; - return a_i->dev == b_i->dev - && a_i->ino == b_i->ino; + return a_i->dev == b_i->dev && a_i->ino == b_i->ino; } /** @@ -1587,7 +1521,7 @@ devino_equal (gconstpointer a, OstreeRepoDevInoCache * ostree_repo_devino_cache_new (void) { - return (OstreeRepoDevInoCache*) g_hash_table_new_full (devino_hash, devino_equal, g_free, NULL); + return (OstreeRepoDevInoCache *)g_hash_table_new_full (devino_hash, devino_equal, g_free, NULL); } /** @@ -1601,11 +1535,9 @@ ostree_repo_devino_cache_new (void) * cache. */ gboolean -ostree_repo_checkout_gc (OstreeRepo *self, - GCancellable *cancellable, - GError **error) +ostree_repo_checkout_gc (OstreeRepo *self, GCancellable *cancellable, GError **error) { - g_autoptr(GHashTable) to_clean_dirs = NULL; + g_autoptr (GHashTable) to_clean_dirs = NULL; g_mutex_lock (&self->cache_lock); to_clean_dirs = self->updated_uncompressed_dirs; @@ -1618,7 +1550,9 @@ ostree_repo_checkout_gc (OstreeRepo *self, GLNX_HASH_TABLE_FOREACH (to_clean_dirs, gpointer, prefix) { g_autofree char *objdir_name = g_strdup_printf ("%02x", GPOINTER_TO_UINT (prefix)); - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; if (!glnx_dirfd_iterator_init_at (self->uncompressed_objects_dir_fd, objdir_name, FALSE, &dfd_iter, error)) diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index 32119c47..5cda047c 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -22,28 +22,28 @@ #include "config.h" -#include -#include +#include #include #include #include -#include +#include #include #include -#include +#include +#include -#include "otutil.h" -#include "ostree.h" +#include "ostree-checksum-input-stream.h" #include "ostree-core-private.h" +#include "ostree-repo-file-enumerator.h" #include "ostree-repo-private.h" #include "ostree-sepolicy-private.h" -#include "ostree-repo-file-enumerator.h" -#include "ostree-checksum-input-stream.h" #include "ostree-varint.h" +#include "ostree.h" +#include "otutil.h" /* The standardized version of BTRFS_IOC_CLONE */ #ifndef FICLONE -#define FICLONE _IOW(0x94, 9, int) +#define FICLONE _IOW (0x94, 9, int) #endif /* Understanding ostree's fsync strategy @@ -97,10 +97,8 @@ commit_tmp_dfd (OstreeRepo *self) * is quite old, but Git also uses it for example. */ gboolean -_ostree_repo_ensure_loose_objdir_at (int dfd, - const char *loose_path, - GCancellable *cancellable, - GError **error) +_ostree_repo_ensure_loose_objdir_at (int dfd, const char *loose_path, GCancellable *cancellable, + GError **error) { char loose_prefix[3]; @@ -120,22 +118,16 @@ _ostree_repo_ensure_loose_objdir_at (int dfd, /* This GVariant is the header for content objects (regfiles and symlinks) */ static GVariant * -create_file_metadata (guint32 uid, - guint32 gid, - guint32 mode, - GVariant *xattrs) +create_file_metadata (guint32 uid, guint32 gid, guint32 mode, GVariant *xattrs) { GVariant *ret_metadata = NULL; - g_autoptr(GVariant) tmp_xattrs = NULL; + g_autoptr (GVariant) tmp_xattrs = NULL; if (xattrs == NULL) tmp_xattrs = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("(ayay)"), NULL, 0)); - ret_metadata = g_variant_new ("(uuu@a(ayay))", - GUINT32_TO_BE (uid), - GUINT32_TO_BE (gid), - GUINT32_TO_BE (mode), - xattrs ? xattrs : tmp_xattrs); + ret_metadata = g_variant_new ("(uuu@a(ayay))", GUINT32_TO_BE (uid), GUINT32_TO_BE (gid), + GUINT32_TO_BE (mode), xattrs ? xattrs : tmp_xattrs); g_variant_ref_sink (ret_metadata); return ret_metadata; @@ -143,19 +135,14 @@ create_file_metadata (guint32 uid, /* bare-user repositories store file metadata as a user xattr */ gboolean -_ostree_write_bareuser_metadata (int fd, - guint32 uid, - guint32 gid, - guint32 mode, - GVariant *xattrs, - GError **error) +_ostree_write_bareuser_metadata (int fd, guint32 uid, guint32 gid, guint32 mode, GVariant *xattrs, + GError **error) { - g_autoptr(GVariant) filemeta = create_file_metadata (uid, gid, mode, xattrs); + g_autoptr (GVariant) filemeta = create_file_metadata (uid, gid, mode, xattrs); - if (TEMP_FAILURE_RETRY (fsetxattr (fd, "user.ostreemeta", - (char*)g_variant_get_data (filemeta), - g_variant_get_size (filemeta), - 0)) != 0) + if (TEMP_FAILURE_RETRY (fsetxattr (fd, "user.ostreemeta", (char *)g_variant_get_data (filemeta), + g_variant_get_size (filemeta), 0)) + != 0) return glnx_throw_errno_prefix (error, "fsetxattr(user.ostreemeta)"); return TRUE; @@ -173,7 +160,7 @@ ot_security_smack_reset_dfd_name (int dfd, const char *name) char buf[PATH_MAX]; /* See glnx-xattrs.c */ snprintf (buf, sizeof (buf), "/proc/self/fd/%d/%s", dfd, name); - (void) lremovexattr (buf, XATTR_NAME_SMACK); + (void)lremovexattr (buf, XATTR_NAME_SMACK); #endif } @@ -181,32 +168,27 @@ static void ot_security_smack_reset_fd (int fd) { #ifdef WITH_SMACK - (void) fremovexattr (fd, XATTR_NAME_SMACK); + (void)fremovexattr (fd, XATTR_NAME_SMACK); #endif } /* Given an O_TMPFILE regular file, link it into place. */ gboolean -_ostree_repo_commit_tmpf_final (OstreeRepo *self, - const char *checksum, - OstreeObjectType objtype, - GLnxTmpfile *tmpf, - GCancellable *cancellable, - GError **error) +_ostree_repo_commit_tmpf_final (OstreeRepo *self, const char *checksum, OstreeObjectType objtype, + GLnxTmpfile *tmpf, GCancellable *cancellable, GError **error) { char tmpbuf[_OSTREE_LOOSE_PATH_MAX]; _ostree_loose_path (tmpbuf, checksum, objtype, self->mode); int dest_dfd = commit_dest_dfd (self); - if (!_ostree_repo_ensure_loose_objdir_at (dest_dfd, tmpbuf, - cancellable, error)) + if (!_ostree_repo_ensure_loose_objdir_at (dest_dfd, tmpbuf, cancellable, error)) return FALSE; if (!_ostree_tmpf_fsverity (self, tmpf, error)) return FALSE; - if (!glnx_link_tmpfile_at (tmpf, GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST, - dest_dfd, tmpbuf, error)) + if (!glnx_link_tmpfile_at (tmpf, GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST, dest_dfd, tmpbuf, + error)) return FALSE; /* We're done with the fd */ glnx_tmpfile_clear (tmpf); @@ -217,24 +199,18 @@ _ostree_repo_commit_tmpf_final (OstreeRepo *self, * rename it into place. */ static gboolean -commit_path_final (OstreeRepo *self, - const char *checksum, - OstreeObjectType objtype, - OtCleanupUnlinkat *tmp_path, - GCancellable *cancellable, - GError **error) +commit_path_final (OstreeRepo *self, const char *checksum, OstreeObjectType objtype, + OtCleanupUnlinkat *tmp_path, GCancellable *cancellable, GError **error) { /* The final renameat() */ char tmpbuf[_OSTREE_LOOSE_PATH_MAX]; _ostree_loose_path (tmpbuf, checksum, objtype, self->mode); int dest_dfd = commit_dest_dfd (self); - if (!_ostree_repo_ensure_loose_objdir_at (dest_dfd, tmpbuf, - cancellable, error)) + if (!_ostree_repo_ensure_loose_objdir_at (dest_dfd, tmpbuf, cancellable, error)) return FALSE; - if (renameat (tmp_path->dfd, tmp_path->path, - dest_dfd, tmpbuf) == -1) + if (renameat (tmp_path->dfd, tmp_path->path, dest_dfd, tmpbuf) == -1) { if (errno != EEXIST) return glnx_throw_errno_prefix (error, "Storing file '%s'", tmp_path->path); @@ -249,21 +225,14 @@ commit_path_final (OstreeRepo *self, return TRUE; } - /* Given either a file or symlink, apply the final metadata to it depending on * the repository mode. Note that @checksum is assumed to have been validated by * the caller. */ static gboolean -commit_loose_regfile_object (OstreeRepo *self, - const char *checksum, - GLnxTmpfile *tmpf, - guint32 uid, - guint32 gid, - guint32 mode, - GVariant *xattrs, - GCancellable *cancellable, - GError **error) +commit_loose_regfile_object (OstreeRepo *self, const char *checksum, GLnxTmpfile *tmpf, guint32 uid, + guint32 gid, guint32 mode, GVariant *xattrs, GCancellable *cancellable, + GError **error) { if (self->mode == OSTREE_REPO_MODE_BARE) { @@ -318,7 +287,8 @@ commit_loose_regfile_object (OstreeRepo *self, * to determine whether or not source files need to be compiled, * set the modification time to OSTREE_TIMESTAMP. */ - const struct timespec times[2] = { { OSTREE_TIMESTAMP, UTIME_OMIT }, { OSTREE_TIMESTAMP, 0} }; + const struct timespec times[2] + = { { OSTREE_TIMESTAMP, UTIME_OMIT }, { OSTREE_TIMESTAMP, 0 } }; if (TEMP_FAILURE_RETRY (futimens (tmpf->fd, times)) < 0) return glnx_throw_errno_prefix (error, "futimens"); } @@ -332,8 +302,8 @@ commit_loose_regfile_object (OstreeRepo *self, return glnx_throw_errno_prefix (error, "fsync"); } - if (!_ostree_repo_commit_tmpf_final (self, checksum, OSTREE_OBJECT_TYPE_FILE, - tmpf, cancellable, error)) + if (!_ostree_repo_commit_tmpf_final (self, checksum, OSTREE_OBJECT_TYPE_FILE, tmpf, cancellable, + error)) return FALSE; return TRUE; @@ -348,9 +318,7 @@ typedef struct } OstreeContentSizeCacheEntry; static OstreeContentSizeCacheEntry * -content_size_cache_entry_new (OstreeObjectType objtype, - goffset unpacked, - goffset archived) +content_size_cache_entry_new (OstreeObjectType objtype, goffset unpacked, goffset archived) { OstreeContentSizeCacheEntry *entry = g_slice_new0 (OstreeContentSizeCacheEntry); @@ -369,8 +337,7 @@ content_size_cache_entry_free (gpointer entry) } void -_ostree_repo_setup_generate_sizes (OstreeRepo *self, - OstreeRepoCommitModifier *modifier) +_ostree_repo_setup_generate_sizes (OstreeRepo *self, OstreeRepoCommitModifier *modifier) { if (modifier && modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES) { @@ -391,14 +358,12 @@ static void repo_ensure_size_entries (OstreeRepo *self) { if (G_UNLIKELY (self->object_sizes == NULL)) - self->object_sizes = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, content_size_cache_entry_free); + self->object_sizes + = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, content_size_cache_entry_free); } static gboolean -repo_has_size_entry (OstreeRepo *self, - OstreeObjectType objtype, - const gchar *checksum) +repo_has_size_entry (OstreeRepo *self, OstreeObjectType objtype, const gchar *checksum) { /* Only file, dirtree and dirmeta objects appropriate for size metadata */ if (objtype > OSTREE_OBJECT_TYPE_DIR_META) @@ -409,28 +374,23 @@ repo_has_size_entry (OstreeRepo *self, } static void -repo_store_size_entry (OstreeRepo *self, - OstreeObjectType objtype, - const gchar *checksum, - goffset unpacked, - goffset archived) +repo_store_size_entry (OstreeRepo *self, OstreeObjectType objtype, const gchar *checksum, + goffset unpacked, goffset archived) { /* Only file, dirtree and dirmeta objects appropriate for size metadata */ if (objtype > OSTREE_OBJECT_TYPE_DIR_META) return; repo_ensure_size_entries (self); - g_hash_table_replace (self->object_sizes, - g_strdup (checksum), + g_hash_table_replace (self->object_sizes, g_strdup (checksum), content_size_cache_entry_new (objtype, unpacked, archived)); } static int -compare_ascii_checksums_for_sorting (gconstpointer a_pp, - gconstpointer b_pp) +compare_ascii_checksums_for_sorting (gconstpointer a_pp, gconstpointer b_pp) { - char *a = *((char**)a_pp); - char *b = *((char**)b_pp); + char *a = *((char **)a_pp); + char *b = *((char **)b_pp); return strcmp (a, b); } @@ -439,24 +399,22 @@ compare_ascii_checksums_for_sorting (gconstpointer a_pp, * Create sizes metadata GVariant and add it to the metadata variant given. */ static GVariant * -add_size_index_to_metadata (OstreeRepo *self, - GVariant *original_metadata) +add_size_index_to_metadata (OstreeRepo *self, GVariant *original_metadata) { - g_autoptr(GVariantBuilder) builder = NULL; + g_autoptr (GVariantBuilder) builder = NULL; /* original_metadata may be NULL */ builder = ot_util_variant_builder_from_variant (original_metadata, G_VARIANT_TYPE ("a{sv}")); - if (self->object_sizes && - g_hash_table_size (self->object_sizes) > 0) + if (self->object_sizes && g_hash_table_size (self->object_sizes) > 0) { GVariantBuilder index_builder; g_variant_builder_init (&index_builder, G_VARIANT_TYPE ("a" _OSTREE_OBJECT_SIZES_ENTRY_SIGNATURE)); /* Sort the checksums so we can bsearch if desired */ - g_autoptr(GPtrArray) sorted_keys = g_ptr_array_new (); - GLNX_HASH_TABLE_FOREACH (self->object_sizes, const char*, e_checksum) + g_autoptr (GPtrArray) sorted_keys = g_ptr_array_new (); + GLNX_HASH_TABLE_FOREACH (self->object_sizes, const char *, e_checksum) g_ptr_array_add (sorted_keys, (gpointer)e_checksum); g_ptr_array_sort (sorted_keys, compare_ascii_checksums_for_sorting); @@ -464,19 +422,19 @@ add_size_index_to_metadata (OstreeRepo *self, { guint8 csum[OSTREE_SHA256_DIGEST_LEN]; const char *e_checksum = sorted_keys->pdata[i]; - g_autoptr(GString) buffer = g_string_new (NULL); + g_autoptr (GString) buffer = g_string_new (NULL); ostree_checksum_inplace_to_bytes (e_checksum, csum); - g_string_append_len (buffer, (char*)csum, sizeof (csum)); + g_string_append_len (buffer, (char *)csum, sizeof (csum)); - OstreeContentSizeCacheEntry *e_size = - g_hash_table_lookup (self->object_sizes, e_checksum); + OstreeContentSizeCacheEntry *e_size + = g_hash_table_lookup (self->object_sizes, e_checksum); _ostree_write_varuint64 (buffer, e_size->archived); _ostree_write_varuint64 (buffer, e_size->unpacked); - g_string_append_c (buffer, (gchar) e_size->objtype); + g_string_append_c (buffer, (gchar)e_size->objtype); g_variant_builder_add (&index_builder, "@ay", - ot_gvariant_new_bytearray ((guint8*)buffer->str, buffer->len)); + ot_gvariant_new_bytearray ((guint8 *)buffer->str, buffer->len)); } g_variant_builder_add (builder, "{sv}", "ostree.sizes", @@ -490,9 +448,7 @@ add_size_index_to_metadata (OstreeRepo *self, } static gboolean -throw_min_free_space_error (OstreeRepo *self, - guint64 bytes_required, - GError **error) +throw_min_free_space_error (OstreeRepo *self, guint64 bytes_required, GError **error) { const char *err_msg = NULL; g_autofree char *err_msg_owned = NULL; @@ -500,18 +456,22 @@ throw_min_free_space_error (OstreeRepo *self, if (bytes_required > 0) { g_autofree char *formatted_required = g_format_size (bytes_required); - err_msg = err_msg_owned = g_strdup_printf ("would be exceeded, at least %s requested", formatted_required); + err_msg = err_msg_owned + = g_strdup_printf ("would be exceeded, at least %s requested", formatted_required); } else - err_msg = "would be exceeded"; + err_msg = "would be exceeded"; if (self->min_free_space_mb > 0) - return glnx_throw (error, "min-free-space-size %" G_GUINT64_FORMAT "MB %s", self->min_free_space_mb, err_msg); + return glnx_throw (error, "min-free-space-size %" G_GUINT64_FORMAT "MB %s", + self->min_free_space_mb, err_msg); else - return glnx_throw (error, "min-free-space-percent '%u%%' %s", self->min_free_space_percent, err_msg); + return glnx_throw (error, "min-free-space-percent '%u%%' %s", self->min_free_space_percent, + err_msg); } -typedef struct { +typedef struct +{ gboolean initialized; GLnxTmpfile tmpf; char *expected_checksum; @@ -530,23 +490,17 @@ G_STATIC_ASSERT (sizeof (OstreeRepoBareContent) >= sizeof (OstreeRealRepoBareCon * to be used also by the dfd_iter commit path. */ gboolean -_ostree_repo_bare_content_open (OstreeRepo *self, - const char *expected_checksum, - guint64 content_len, - guint uid, - guint gid, - guint mode, - GVariant *xattrs, - OstreeRepoBareContent *out_regwrite, - GCancellable *cancellable, - GError **error) +_ostree_repo_bare_content_open (OstreeRepo *self, const char *expected_checksum, + guint64 content_len, guint uid, guint gid, guint mode, + GVariant *xattrs, OstreeRepoBareContent *out_regwrite, + GCancellable *cancellable, GError **error) { - OstreeRealRepoBareContent *real = (OstreeRealRepoBareContent*) out_regwrite; + OstreeRealRepoBareContent *real = (OstreeRealRepoBareContent *)out_regwrite; g_assert (!real->initialized); real->initialized = TRUE; g_assert (S_ISREG (mode)); - if (!glnx_open_tmpfile_linkable_at (commit_tmp_dfd (self), ".", O_WRONLY|O_CLOEXEC, - &real->tmpf, error)) + if (!glnx_open_tmpfile_linkable_at (commit_tmp_dfd (self), ".", O_WRONLY | O_CLOEXEC, &real->tmpf, + error)) return FALSE; ot_checksum_init (&real->checksum); real->expected_checksum = g_strdup (expected_checksum); @@ -558,22 +512,19 @@ _ostree_repo_bare_content_open (OstreeRepo *self, real->xattrs = xattrs ? g_variant_ref (xattrs) : NULL; /* Initialize the checksum with the header info */ - g_autoptr(GFileInfo) finfo = _ostree_mode_uidgid_to_gfileinfo (mode, uid, gid); - g_autoptr(GBytes) header = _ostree_file_header_new (finfo, xattrs); + g_autoptr (GFileInfo) finfo = _ostree_mode_uidgid_to_gfileinfo (mode, uid, gid); + g_autoptr (GBytes) header = _ostree_file_header_new (finfo, xattrs); ot_checksum_update_bytes (&real->checksum, header); return TRUE; } gboolean -_ostree_repo_bare_content_write (OstreeRepo *repo, - OstreeRepoBareContent *barewrite, - const guint8 *buf, - size_t len, - GCancellable *cancellable, - GError **error) +_ostree_repo_bare_content_write (OstreeRepo *repo, OstreeRepoBareContent *barewrite, + const guint8 *buf, size_t len, GCancellable *cancellable, + GError **error) { - OstreeRealRepoBareContent *real = (OstreeRealRepoBareContent*) barewrite; + OstreeRealRepoBareContent *real = (OstreeRealRepoBareContent *)barewrite; g_assert (real->initialized); ot_checksum_update (&real->checksum, buf, len); if (glnx_loop_write (real->tmpf.fd, buf, len) < 0) @@ -582,14 +533,11 @@ _ostree_repo_bare_content_write (OstreeRepo *repo, } gboolean -_ostree_repo_bare_content_commit (OstreeRepo *self, - OstreeRepoBareContent *barewrite, - char *checksum_buf, - size_t buflen, - GCancellable *cancellable, - GError **error) +_ostree_repo_bare_content_commit (OstreeRepo *self, OstreeRepoBareContent *barewrite, + char *checksum_buf, size_t buflen, GCancellable *cancellable, + GError **error) { - OstreeRealRepoBareContent *real = (OstreeRealRepoBareContent*) barewrite; + OstreeRealRepoBareContent *real = (OstreeRealRepoBareContent *)barewrite; g_assert (real->initialized); if ((self->min_free_space_percent > 0 || self->min_free_space_mb > 0) && self->in_transaction) @@ -615,16 +563,13 @@ _ostree_repo_bare_content_commit (OstreeRepo *self, ot_checksum_get_hexdigest (&real->checksum, checksum_buf, buflen); - if (real->expected_checksum && - !_ostree_compare_object_checksum (OSTREE_OBJECT_TYPE_FILE, - real->expected_checksum, checksum_buf, - error)) + if (real->expected_checksum + && !_ostree_compare_object_checksum (OSTREE_OBJECT_TYPE_FILE, real->expected_checksum, + checksum_buf, error)) return FALSE; - if (!commit_loose_regfile_object (self, checksum_buf, - &real->tmpf, real->uid, real->gid, - real->mode, real->xattrs, - cancellable, error)) + if (!commit_loose_regfile_object (self, checksum_buf, &real->tmpf, real->uid, real->gid, + real->mode, real->xattrs, cancellable, error)) return FALSE; /* Let's have a guarantee that after commit the object is cleaned up */ @@ -635,7 +580,7 @@ _ostree_repo_bare_content_commit (OstreeRepo *self, void _ostree_repo_bare_content_cleanup (OstreeRepoBareContent *regwrite) { - OstreeRealRepoBareContent *real = (OstreeRealRepoBareContent*) regwrite; + OstreeRealRepoBareContent *real = (OstreeRealRepoBareContent *)regwrite; if (!real->initialized) return; glnx_tmpfile_clear (&real->tmpf); @@ -650,16 +595,15 @@ _ostree_repo_bare_content_cleanup (OstreeRepoBareContent *regwrite) * and content objects in all bare-type repos. */ static gboolean -create_regular_tmpfile_linkable_with_content (OstreeRepo *self, - guint64 length, - GInputStream *input, - GLnxTmpfile *out_tmpf, - GCancellable *cancellable, +create_regular_tmpfile_linkable_with_content (OstreeRepo *self, guint64 length, GInputStream *input, + GLnxTmpfile *out_tmpf, GCancellable *cancellable, GError **error) { - g_auto(GLnxTmpfile) tmpf = { 0, }; - if (!glnx_open_tmpfile_linkable_at (commit_tmp_dfd (self), ".", O_WRONLY|O_CLOEXEC, - &tmpf, error)) + g_auto (GLnxTmpfile) tmpf = { + 0, + }; + if (!glnx_open_tmpfile_linkable_at (commit_tmp_dfd (self), ".", O_WRONLY | O_CLOEXEC, &tmpf, + error)) return FALSE; if (!glnx_try_fallocate (tmpf.fd, 0, length, error)) @@ -667,7 +611,7 @@ create_regular_tmpfile_linkable_with_content (OstreeRepo *self, if (G_IS_FILE_DESCRIPTOR_BASED (input)) { - int infd = g_file_descriptor_based_get_fd ((GFileDescriptorBased*) input); + int infd = g_file_descriptor_based_get_fd ((GFileDescriptorBased *)input); if (glnx_regfile_copy_bytes (infd, tmpf.fd, (off_t)length) < 0) return glnx_throw_errno_prefix (error, "regfile copy"); } @@ -678,17 +622,20 @@ create_regular_tmpfile_linkable_with_content (OstreeRepo *self, * e.g. 10 bytes but is actually gigabytes. * - Due to GLib bugs that pointlessly calls `poll()` on the output fd for every write */ - gsize buf_size = MIN(length, 1048576); - g_autofree gchar * buf = g_malloc(buf_size); + gsize buf_size = MIN (length, 1048576); + g_autofree gchar *buf = g_malloc (buf_size); guint64 remaining = length; while (remaining > 0) { - const gssize bytes_read = - g_input_stream_read (input, buf, MIN (remaining, buf_size), cancellable, error); + const gssize bytes_read + = g_input_stream_read (input, buf, MIN (remaining, buf_size), cancellable, error); if (bytes_read < 0) return FALSE; else if (bytes_read == 0) - return glnx_throw (error, "Unexpected EOF with %" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT " bytes remaining", remaining, length); + return glnx_throw (error, + "Unexpected EOF with %" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT + " bytes remaining", + remaining, length); if (glnx_loop_write (tmpf.fd, buf, bytes_read) < 0) return glnx_throw_errno_prefix (error, "write"); remaining -= bytes_read; @@ -698,7 +645,8 @@ create_regular_tmpfile_linkable_with_content (OstreeRepo *self, if (!glnx_fchmod (tmpf.fd, 0644, error)) return FALSE; - *out_tmpf = tmpf; tmpf.initialized = FALSE; + *out_tmpf = tmpf; + tmpf.initialized = FALSE; return TRUE; } @@ -709,17 +657,20 @@ _check_support_reflink (OstreeRepo *dest, gboolean *supported, GError **error) if (g_atomic_int_get (&dest->fs_support_reflink) == 0) { glnx_autofd int src_fd = -1; - g_auto(GLnxTmpfile) dest_tmpf = { 0, }; + g_auto (GLnxTmpfile) dest_tmpf = { + 0, + }; if (!glnx_openat_rdonly (dest->repo_dir_fd, "config", TRUE, &src_fd, error)) return FALSE; - if (!glnx_open_tmpfile_linkable_at (commit_tmp_dfd (dest), ".", O_WRONLY|O_CLOEXEC, + if (!glnx_open_tmpfile_linkable_at (commit_tmp_dfd (dest), ".", O_WRONLY | O_CLOEXEC, &dest_tmpf, error)) return FALSE; if (ioctl (dest_tmpf.fd, FICLONE, src_fd) == 0) g_atomic_int_set (&dest->fs_support_reflink, 1); - else if (errno == EOPNOTSUPP) /* Ignore other kind of errors as they might be temporary failures */ + else if (errno + == EOPNOTSUPP) /* Ignore other kind of errors as they might be temporary failures */ g_atomic_int_set (&dest->fs_support_reflink, -1); } *supported = g_atomic_int_get (&dest->fs_support_reflink) >= 0; @@ -727,12 +678,8 @@ _check_support_reflink (OstreeRepo *dest, gboolean *supported, GError **error) } static gboolean -_create_payload_link (OstreeRepo *self, - const char *checksum, - const char *payload_checksum, - GFileInfo *file_info, - GCancellable *cancellable, - GError **error) +_create_payload_link (OstreeRepo *self, const char *checksum, const char *payload_checksum, + GFileInfo *file_info, GCancellable *cancellable, GError **error) { gboolean reflinks_supported = FALSE; @@ -743,7 +690,8 @@ _create_payload_link (OstreeRepo *self, return TRUE; if (g_file_info_get_file_type (file_info) != G_FILE_TYPE_REGULAR - || !G_IN_SET(self->mode, OSTREE_REPO_MODE_BARE, OSTREE_REPO_MODE_BARE_USER, OSTREE_REPO_MODE_BARE_USER_ONLY)) + || !G_IN_SET (self->mode, OSTREE_REPO_MODE_BARE, OSTREE_REPO_MODE_BARE_USER, + OSTREE_REPO_MODE_BARE_USER_ONLY)) return TRUE; if (payload_checksum == NULL || g_file_info_get_size (file_info) < self->payload_link_threshold) @@ -751,7 +699,8 @@ _create_payload_link (OstreeRepo *self, char target_buf[_OSTREE_LOOSE_PATH_MAX + _OSTREE_PAYLOAD_LINK_PREFIX_LEN]; strcpy (target_buf, _OSTREE_PAYLOAD_LINK_PREFIX); - _ostree_loose_path (target_buf + _OSTREE_PAYLOAD_LINK_PREFIX_LEN, checksum, OSTREE_OBJECT_TYPE_FILE, self->mode); + _ostree_loose_path (target_buf + _OSTREE_PAYLOAD_LINK_PREFIX_LEN, checksum, + OSTREE_OBJECT_TYPE_FILE, self->mode); if (symlinkat (target_buf, commit_tmp_dfd (self), payload_checksum) < 0) { @@ -760,8 +709,10 @@ _create_payload_link (OstreeRepo *self, } else { - g_auto(OtCleanupUnlinkat) tmp_unlinker = { commit_tmp_dfd (self), g_strdup (payload_checksum) }; - if (!commit_path_final (self, payload_checksum, OSTREE_OBJECT_TYPE_PAYLOAD_LINK, &tmp_unlinker, cancellable, error)) + g_auto (OtCleanupUnlinkat) tmp_unlinker + = { commit_tmp_dfd (self), g_strdup (payload_checksum) }; + if (!commit_path_final (self, payload_checksum, OSTREE_OBJECT_TYPE_PAYLOAD_LINK, + &tmp_unlinker, cancellable, error)) return FALSE; } @@ -769,17 +720,14 @@ _create_payload_link (OstreeRepo *self, } static gboolean -_import_payload_link (OstreeRepo *dest_repo, - OstreeRepo *src_repo, - const char *checksum, - GCancellable *cancellable, - GError **error) +_import_payload_link (OstreeRepo *dest_repo, OstreeRepo *src_repo, const char *checksum, + GCancellable *cancellable, GError **error) { gboolean reflinks_supported = FALSE; g_autofree char *payload_checksum = NULL; - g_autoptr(GInputStream) is = NULL; + g_autoptr (GInputStream) is = NULL; glnx_unref_object OtChecksumInstream *checksum_payload = NULL; - g_autoptr(GFileInfo) file_info = NULL; + g_autoptr (GFileInfo) file_info = NULL; /* The two repositories are on different devices */ if (src_repo->device != dest_repo->device) @@ -791,7 +739,8 @@ _import_payload_link (OstreeRepo *dest_repo, if (!reflinks_supported) return TRUE; - if (!G_IN_SET(dest_repo->mode, OSTREE_REPO_MODE_BARE, OSTREE_REPO_MODE_BARE_USER, OSTREE_REPO_MODE_BARE_USER_ONLY)) + if (!G_IN_SET (dest_repo->mode, OSTREE_REPO_MODE_BARE, OSTREE_REPO_MODE_BARE_USER, + OSTREE_REPO_MODE_BARE_USER_ONLY)) return TRUE; if (!ostree_repo_load_file (src_repo, checksum, &is, &file_info, NULL, cancellable, error)) @@ -807,7 +756,7 @@ _import_payload_link (OstreeRepo *dest_repo, while (remaining) { char buf[8192]; - gssize ret = g_input_stream_read ((GInputStream *) checksum_payload, buf, + gssize ret = g_input_stream_read ((GInputStream *)checksum_payload, buf, MIN (sizeof (buf), remaining), cancellable, error); if (ret < 0) return FALSE; @@ -815,17 +764,14 @@ _import_payload_link (OstreeRepo *dest_repo, } payload_checksum = ot_checksum_instream_get_string (checksum_payload); - return _create_payload_link (dest_repo, checksum, payload_checksum, file_info, cancellable, error); + return _create_payload_link (dest_repo, checksum, payload_checksum, file_info, cancellable, + error); } static gboolean -_try_clone_from_payload_link (OstreeRepo *self, - OstreeRepo *dest_repo, - const char *payload_checksum, - GFileInfo *file_info, - GLnxTmpfile *tmpf, - GCancellable *cancellable, - GError **error) +_try_clone_from_payload_link (OstreeRepo *self, OstreeRepo *dest_repo, const char *payload_checksum, + GFileInfo *file_info, GLnxTmpfile *tmpf, GCancellable *cancellable, + GError **error) { gboolean reflinks_supported = FALSE; int dfd_searches[] = { -1, self->objects_dir_fd }; @@ -848,13 +794,14 @@ _try_clone_from_payload_link (OstreeRepo *self, char loose_path_buf[_OSTREE_LOOSE_PATH_MAX]; char loose_path_target_buf[_OSTREE_LOOSE_PATH_MAX]; char target_buf[_OSTREE_LOOSE_PATH_MAX + _OSTREE_PAYLOAD_LINK_PREFIX_LEN]; - char target_checksum[OSTREE_SHA256_STRING_LEN+1]; + char target_checksum[OSTREE_SHA256_STRING_LEN + 1]; int dfd = dfd_searches[i]; ssize_t size; if (dfd == -1) continue; - _ostree_loose_path (loose_path_buf, payload_checksum, OSTREE_OBJECT_TYPE_PAYLOAD_LINK, self->mode); + _ostree_loose_path (loose_path_buf, payload_checksum, OSTREE_OBJECT_TYPE_PAYLOAD_LINK, + self->mode); size = TEMP_FAILURE_RETRY (readlinkat (dfd, loose_path_buf, target_buf, sizeof (target_buf))); if (size < 0) @@ -867,15 +814,18 @@ _try_clone_from_payload_link (OstreeRepo *self, if (size < OSTREE_SHA256_STRING_LEN + _OSTREE_PAYLOAD_LINK_PREFIX_LEN) return glnx_throw (error, "invalid data size for %s", loose_path_buf); - sprintf (target_checksum, "%.2s%.62s", target_buf + _OSTREE_PAYLOAD_LINK_PREFIX_LEN, target_buf + _OSTREE_PAYLOAD_LINK_PREFIX_LEN + 3); + sprintf (target_checksum, "%.2s%.62s", target_buf + _OSTREE_PAYLOAD_LINK_PREFIX_LEN, + target_buf + _OSTREE_PAYLOAD_LINK_PREFIX_LEN + 3); - _ostree_loose_path (loose_path_target_buf, target_checksum, OSTREE_OBJECT_TYPE_FILE, self->mode); + _ostree_loose_path (loose_path_target_buf, target_checksum, OSTREE_OBJECT_TYPE_FILE, + self->mode); if (!ot_openat_ignore_enoent (dfd, loose_path_target_buf, &fdf, error)) return FALSE; if (fdf < 0) { - /* If the link is referring to an object that doesn't exist anymore in the repository, just unlink it. */ + /* If the link is referring to an object that doesn't exist anymore in the repository, + * just unlink it. */ if (!glnx_unlinkat (dfd, loose_path_buf, 0, error)) return FALSE; } @@ -889,7 +839,8 @@ _try_clone_from_payload_link (OstreeRepo *self, } } if (self->parent_repo) - return _try_clone_from_payload_link (self->parent_repo, dest_repo, payload_checksum, file_info, tmpf, cancellable, error); + return _try_clone_from_payload_link (self->parent_repo, dest_repo, payload_checksum, file_info, + tmpf, cancellable, error); return TRUE; } @@ -901,14 +852,9 @@ _try_clone_from_payload_link (OstreeRepo *self, * knows the checksum. */ static gboolean -write_content_object (OstreeRepo *self, - const char *expected_checksum, - GInputStream *input, - GFileInfo *file_info, - GVariant *xattrs, - guchar **out_csum, - GCancellable *cancellable, - GError **error) +write_content_object (OstreeRepo *self, const char *expected_checksum, GInputStream *input, + GFileInfo *file_info, GVariant *xattrs, guchar **out_csum, + GCancellable *cancellable, GError **error) { g_assert (expected_checksum != NULL || out_csum != NULL); @@ -918,12 +864,12 @@ write_content_object (OstreeRepo *self, return FALSE; OstreeRepoMode repo_mode = ostree_repo_get_mode (self); - if (repo_mode == OSTREE_REPO_MODE_BARE_SPLIT_XATTRS && - g_getenv ("OSTREE_EXP_WRITE_BARE_SPLIT_XATTRS") == NULL) + if (repo_mode == OSTREE_REPO_MODE_BARE_SPLIT_XATTRS + && g_getenv ("OSTREE_EXP_WRITE_BARE_SPLIT_XATTRS") == NULL) return glnx_throw (error, "Not allowed due to repo mode"); - GInputStream *file_input; /* Unowned alias */ - g_autoptr(GInputStream) file_input_owned = NULL; /* We need a temporary for bare-user symlinks */ + GInputStream *file_input; /* Unowned alias */ + g_autoptr (GInputStream) file_input_owned = NULL; /* We need a temporary for bare-user symlinks */ glnx_unref_object OtChecksumInstream *checksum_input = NULL; glnx_unref_object OtChecksumInstream *checksum_payload_input = NULL; const GFileType object_file_type = g_file_info_get_file_type (file_info); @@ -936,32 +882,34 @@ write_content_object (OstreeRepo *self, * checksum over the data we actually use. */ gboolean reflinks_supported = FALSE; - g_autoptr(GBytes) header = _ostree_file_header_new (file_info, xattrs); + g_autoptr (GBytes) header = _ostree_file_header_new (file_info, xattrs); size_t len; const guint8 *buf = g_bytes_get_data (header, &len); /* Give a null input if there's no content */ - g_autoptr(GInputStream) null_input = NULL; + g_autoptr (GInputStream) null_input = NULL; if (!input) { null_input = input = g_memory_input_stream_new_from_data ("", 0, NULL); - (void) null_input; /* quiet static analysis */ + (void)null_input; /* quiet static analysis */ } - checksum_input = ot_checksum_instream_new_with_start (input, G_CHECKSUM_SHA256, - buf, len); + checksum_input = ot_checksum_instream_new_with_start (input, G_CHECKSUM_SHA256, buf, len); if (!_check_support_reflink (self, &reflinks_supported, error)) return FALSE; - if (xattrs == NULL || !G_IN_SET(self->mode, OSTREE_REPO_MODE_BARE, OSTREE_REPO_MODE_BARE_USER, OSTREE_REPO_MODE_BARE_USER_ONLY) || object_file_type != G_FILE_TYPE_REGULAR || - !reflinks_supported) - file_input = (GInputStream*)checksum_input; + if (xattrs == NULL + || !G_IN_SET (self->mode, OSTREE_REPO_MODE_BARE, OSTREE_REPO_MODE_BARE_USER, + OSTREE_REPO_MODE_BARE_USER_ONLY) + || object_file_type != G_FILE_TYPE_REGULAR || !reflinks_supported) + file_input = (GInputStream *)checksum_input; else { /* The payload checksum-input reads from the full object checksum-input; this * means it skips the header. */ - checksum_payload_input = ot_checksum_instream_new ((GInputStream*)checksum_input, G_CHECKSUM_SHA256); - file_input = (GInputStream*)checksum_payload_input; + checksum_payload_input + = ot_checksum_instream_new ((GInputStream *)checksum_input, G_CHECKSUM_SHA256); + file_input = (GInputStream *)checksum_payload_input; } } else @@ -986,7 +934,7 @@ write_content_object (OstreeRepo *self, if (repo_mode == OSTREE_REPO_MODE_BARE_USER && object_file_type == G_FILE_TYPE_SYMBOLIC_LINK) { const char *target_str = g_file_info_get_symlink_target (file_info); - g_autoptr(GBytes) target = g_bytes_new (target_str, strlen (target_str) + 1); + g_autoptr (GBytes) target = g_bytes_new (target_str, strlen (target_str) + 1); /* Include the terminating zero so we can e.g. mmap this file */ file_input = file_input_owned = g_memory_input_stream_new_from_bytes (target); @@ -1024,44 +972,47 @@ write_content_object (OstreeRepo *self, * * We use GLnxTmpfile for regular files, and OtCleanupUnlinkat for symlinks. */ - g_auto(OtCleanupUnlinkat) tmp_unlinker = { commit_tmp_dfd (self), NULL }; - g_auto(GLnxTmpfile) tmpf = { 0, }; + g_auto (OtCleanupUnlinkat) tmp_unlinker = { commit_tmp_dfd (self), NULL }; + g_auto (GLnxTmpfile) tmpf = { + 0, + }; goffset unpacked_size = 0; /* Is it a symlink physically? */ if (phys_object_is_symlink) { /* This will not be hit for bare-user or archive */ - g_assert (self->mode == OSTREE_REPO_MODE_BARE || self->mode == OSTREE_REPO_MODE_BARE_USER_ONLY); + g_assert (self->mode == OSTREE_REPO_MODE_BARE + || self->mode == OSTREE_REPO_MODE_BARE_USER_ONLY); if (!_ostree_make_temporary_symlink_at (commit_tmp_dfd (self), g_file_info_get_symlink_target (file_info), - &tmp_unlinker.path, - cancellable, error)) + &tmp_unlinker.path, cancellable, error)) return FALSE; } else if (repo_mode != OSTREE_REPO_MODE_ARCHIVE) { - if (!create_regular_tmpfile_linkable_with_content (self, size, file_input, - &tmpf, cancellable, error)) + if (!create_regular_tmpfile_linkable_with_content (self, size, file_input, &tmpf, cancellable, + error)) return FALSE; } else { - g_autoptr(GConverter) zlib_compressor = NULL; - g_autoptr(GOutputStream) compressed_out_stream = NULL; - g_autoptr(GOutputStream) temp_out = NULL; + g_autoptr (GConverter) zlib_compressor = NULL; + g_autoptr (GOutputStream) compressed_out_stream = NULL; + g_autoptr (GOutputStream) temp_out = NULL; g_assert (repo_mode == OSTREE_REPO_MODE_ARCHIVE); - if (!glnx_open_tmpfile_linkable_at (commit_tmp_dfd (self), ".", O_WRONLY|O_CLOEXEC, - &tmpf, error)) + if (!glnx_open_tmpfile_linkable_at (commit_tmp_dfd (self), ".", O_WRONLY | O_CLOEXEC, &tmpf, + error)) return FALSE; temp_out = g_unix_output_stream_new (tmpf.fd, FALSE); - g_autoptr(GBytes) file_meta_header = _ostree_zlib_file_header_new (file_info, xattrs); + g_autoptr (GBytes) file_meta_header = _ostree_zlib_file_header_new (file_info, xattrs); gsize file_meta_len; - const guint8* file_meta_buf = g_bytes_get_data (file_meta_header, &file_meta_len); + const guint8 *file_meta_buf = g_bytes_get_data (file_meta_header, &file_meta_len); - { gsize bytes_written; + { + gsize bytes_written; if (!g_output_stream_write_all (temp_out, file_meta_buf, file_meta_len, &bytes_written, cancellable, error)) return FALSE; @@ -1069,13 +1020,14 @@ write_content_object (OstreeRepo *self, if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR) { - zlib_compressor = (GConverter*)g_zlib_compressor_new (G_ZLIB_COMPRESSOR_FORMAT_RAW, self->zlib_compression_level); + zlib_compressor = (GConverter *)g_zlib_compressor_new (G_ZLIB_COMPRESSOR_FORMAT_RAW, + self->zlib_compression_level); compressed_out_stream = g_converter_output_stream_new (temp_out, zlib_compressor); /* Don't close the base; we'll do that later */ - g_filter_output_stream_set_close_base_stream ((GFilterOutputStream*)compressed_out_stream, FALSE); + g_filter_output_stream_set_close_base_stream ( + (GFilterOutputStream *)compressed_out_stream, FALSE); - if (g_output_stream_splice (compressed_out_stream, file_input, - 0, cancellable, error) < 0) + if (g_output_stream_splice (compressed_out_stream, file_input, 0, cancellable, error) < 0) return FALSE; unpacked_size = g_file_info_get_size (file_info); @@ -1103,8 +1055,8 @@ write_content_object (OstreeRepo *self, actual_checksum = actual_checksum_owned = ot_checksum_instream_get_string (checksum_input); if (expected_checksum) { - if (!_ostree_compare_object_checksum (OSTREE_OBJECT_TYPE_FILE, expected_checksum, actual_checksum, - error)) + if (!_ostree_compare_object_checksum (OSTREE_OBJECT_TYPE_FILE, expected_checksum, + actual_checksum, error)) return FALSE; } @@ -1115,24 +1067,23 @@ write_content_object (OstreeRepo *self, g_assert (actual_checksum != NULL); /* Pacify static analysis */ /* Update size metadata if configured and entry missing */ - if (self->generate_sizes && - !repo_has_size_entry (self, OSTREE_OBJECT_TYPE_FILE, actual_checksum)) + if (self->generate_sizes && !repo_has_size_entry (self, OSTREE_OBJECT_TYPE_FILE, actual_checksum)) { struct stat stbuf; if (!glnx_fstat (tmpf.fd, &stbuf, error)) return FALSE; - repo_store_size_entry (self, OSTREE_OBJECT_TYPE_FILE, actual_checksum, - unpacked_size, stbuf.st_size); + repo_store_size_entry (self, OSTREE_OBJECT_TYPE_FILE, actual_checksum, unpacked_size, + stbuf.st_size); } /* See whether or not we have the object, now that we know the * checksum. */ gboolean have_obj; - if (!_ostree_repo_has_loose_object (self, actual_checksum, OSTREE_OBJECT_TYPE_FILE, - &have_obj, cancellable, error)) + if (!_ostree_repo_has_loose_object (self, actual_checksum, OSTREE_OBJECT_TYPE_FILE, &have_obj, + cancellable, error)) return FALSE; /* If we already have it, just update the stats. */ if (have_obj) @@ -1141,7 +1092,8 @@ write_content_object (OstreeRepo *self, self->txn.stats.content_objects_total++; g_mutex_unlock (&self->txn_lock); - if (!_create_payload_link (self, actual_checksum, actual_payload_checksum, file_info, cancellable, error)) + if (!_create_payload_link (self, actual_checksum, actual_payload_checksum, file_info, + cancellable, error)) return FALSE; if (out_csum) @@ -1168,15 +1120,16 @@ write_content_object (OstreeRepo *self, * Note, this does not apply for bare-user repos, as they store symlinks * as regular files. */ - if (G_UNLIKELY (fchownat (tmp_unlinker.dfd, tmp_unlinker.path, - uid, gid, AT_SYMLINK_NOFOLLOW) == -1)) + if (G_UNLIKELY ( + fchownat (tmp_unlinker.dfd, tmp_unlinker.path, uid, gid, AT_SYMLINK_NOFOLLOW) + == -1)) return glnx_throw_errno_prefix (error, "fchownat"); if (xattrs != NULL) { ot_security_smack_reset_dfd_name (tmp_unlinker.dfd, tmp_unlinker.path); - if (!glnx_dfd_name_set_all_xattrs (tmp_unlinker.dfd, tmp_unlinker.path, - xattrs, cancellable, error)) + if (!glnx_dfd_name_set_all_xattrs (tmp_unlinker.dfd, tmp_unlinker.path, xattrs, + cancellable, error)) return FALSE; } } @@ -1186,25 +1139,26 @@ write_content_object (OstreeRepo *self, g_assert_not_reached (); } - if (!commit_path_final (self, actual_checksum, OSTREE_OBJECT_TYPE_FILE, - &tmp_unlinker, cancellable, error)) + if (!commit_path_final (self, actual_checksum, OSTREE_OBJECT_TYPE_FILE, &tmp_unlinker, + cancellable, error)) return FALSE; } else { /* Check if a file with the same payload is present in the repository, and in case try to reflink it */ - if (actual_payload_checksum && !_try_clone_from_payload_link (self, self, actual_payload_checksum, file_info, &tmpf, cancellable, error)) + if (actual_payload_checksum + && !_try_clone_from_payload_link (self, self, actual_payload_checksum, file_info, &tmpf, + cancellable, error)) return FALSE; /* This path is for regular files */ - if (!commit_loose_regfile_object (self, actual_checksum, &tmpf, - uid, gid, mode, - xattrs, + if (!commit_loose_regfile_object (self, actual_checksum, &tmpf, uid, gid, mode, xattrs, cancellable, error)) return FALSE; - if (!_create_payload_link (self, actual_checksum, actual_payload_checksum, file_info, cancellable, error)) + if (!_create_payload_link (self, actual_checksum, actual_payload_checksum, file_info, + cancellable, error)) return FALSE; } @@ -1238,22 +1192,19 @@ write_content_object (OstreeRepo *self, * security.selinux xattr on setuid binaries and the like to live on). */ static gboolean -adopt_and_commit_regfile (OstreeRepo *self, - int dfd, - const char *name, - GFileInfo *finfo, - GVariant *xattrs, - char *out_checksum_buf, - GCancellable *cancellable, - GError **error) +adopt_and_commit_regfile (OstreeRepo *self, int dfd, const char *name, GFileInfo *finfo, + GVariant *xattrs, char *out_checksum_buf, GCancellable *cancellable, + GError **error) { g_assert (G_IN_SET (self->mode, OSTREE_REPO_MODE_BARE, OSTREE_REPO_MODE_BARE_USER_ONLY)); GLNX_AUTO_PREFIX_ERROR ("Commit regfile (adopt)", error); - g_autoptr(GBytes) header = _ostree_file_header_new (finfo, xattrs); + g_autoptr (GBytes) header = _ostree_file_header_new (finfo, xattrs); - g_auto(OtChecksum) hasher = { 0, }; + g_auto (OtChecksum) hasher = { + 0, + }; ot_checksum_init (&hasher); ot_checksum_update_bytes (&hasher, header); @@ -1268,7 +1219,7 @@ adopt_and_commit_regfile (OstreeRepo *self, * Turns out bigger block size is better; down the line we should use their * same heuristics. */ - char buf[16*1024]; + char buf[16 * 1024]; while (TRUE) { ssize_t bytes_read = read (fd, buf, sizeof (buf)); @@ -1277,10 +1228,10 @@ adopt_and_commit_regfile (OstreeRepo *self, if (bytes_read == 0) break; - ot_checksum_update (&hasher, (guint8*)buf, bytes_read); + ot_checksum_update (&hasher, (guint8 *)buf, bytes_read); } - ot_checksum_get_hexdigest (&hasher, out_checksum_buf, OSTREE_SHA256_STRING_LEN+1); + ot_checksum_get_hexdigest (&hasher, out_checksum_buf, OSTREE_SHA256_STRING_LEN + 1); const char *checksum = out_checksum_buf; /* TODO: dedup this with commit_path_final() */ @@ -1291,8 +1242,7 @@ adopt_and_commit_regfile (OstreeRepo *self, const guint64 src_inode = g_file_info_get_attribute_uint64 (finfo, "unix::inode"); int dest_dfd = commit_dest_dfd (self); - if (!_ostree_repo_ensure_loose_objdir_at (dest_dfd, loose_path, - cancellable, error)) + if (!_ostree_repo_ensure_loose_objdir_at (dest_dfd, loose_path, cancellable, error)) return FALSE; struct stat dest_stbuf; @@ -1305,9 +1255,7 @@ adopt_and_commit_regfile (OstreeRepo *self, * "If oldpath and newpath are existing hard links referring to the same file, * then rename() does nothing, and returns a success status." */ - if (errno != ENOENT - && src_dev == dest_stbuf.st_dev - && src_inode == dest_stbuf.st_ino) + if (errno != ENOENT && src_dev == dest_stbuf.st_dev && src_inode == dest_stbuf.st_ino) { if (!glnx_unlinkat (dfd, name, 0, error)) return FALSE; @@ -1337,13 +1285,8 @@ adopt_and_commit_regfile (OstreeRepo *self, /* Main driver for writing a metadata (non-content) object. */ static gboolean -write_metadata_object (OstreeRepo *self, - OstreeObjectType objtype, - const char *expected_checksum, - GBytes *buf, - guchar **out_csum, - GCancellable *cancellable, - GError **error) +write_metadata_object (OstreeRepo *self, OstreeObjectType objtype, const char *expected_checksum, + GBytes *buf, guchar **out_csum, GCancellable *cancellable, GError **error) { g_assert (expected_checksum != NULL || out_csum != NULL); @@ -1362,7 +1305,7 @@ write_metadata_object (OstreeRepo *self, * *original* sha256 to say what commit was being killed. */ const gboolean is_tombstone = (objtype == OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT); - char actual_checksum[OSTREE_SHA256_STRING_LEN+1]; + char actual_checksum[OSTREE_SHA256_STRING_LEN + 1]; if (is_tombstone) { g_assert (expected_checksum != NULL); @@ -1370,15 +1313,17 @@ write_metadata_object (OstreeRepo *self, } else { - g_auto(OtChecksum) checksum = { 0, }; + g_auto (OtChecksum) checksum = { + 0, + }; ot_checksum_init (&checksum); gsize len; - const guint8*bufdata = g_bytes_get_data (buf, &len); + const guint8 *bufdata = g_bytes_get_data (buf, &len); ot_checksum_update (&checksum, bufdata, len); ot_checksum_get_hexdigest (&checksum, actual_checksum, sizeof (actual_checksum)); gboolean have_obj; - if (!_ostree_repo_has_loose_object (self, actual_checksum, objtype, &have_obj, - cancellable, error)) + if (!_ostree_repo_has_loose_object (self, actual_checksum, objtype, &have_obj, cancellable, + error)) return FALSE; /* If we already have the object, we just need to update the tried-to-commit * stat for metadata and be done here. @@ -1386,8 +1331,7 @@ write_metadata_object (OstreeRepo *self, if (have_obj) { /* Update size metadata if needed */ - if (self->generate_sizes && - !repo_has_size_entry (self, objtype, actual_checksum)) + if (self->generate_sizes && !repo_has_size_entry (self, objtype, actual_checksum)) repo_store_size_entry (self, objtype, actual_checksum, len, len); g_mutex_lock (&self->txn_lock); @@ -1412,14 +1356,15 @@ write_metadata_object (OstreeRepo *self, const guint8 *bufp = g_bytes_get_data (buf, &len); /* Update size metadata if needed */ - if (self->generate_sizes && - !repo_has_size_entry (self, objtype, actual_checksum)) + if (self->generate_sizes && !repo_has_size_entry (self, objtype, actual_checksum)) repo_store_size_entry (self, objtype, actual_checksum, len, len); /* Write the metadata to a temporary file */ - g_auto(GLnxTmpfile) tmpf = { 0, }; - if (!glnx_open_tmpfile_linkable_at (commit_tmp_dfd (self), ".", O_WRONLY|O_CLOEXEC, - &tmpf, error)) + g_auto (GLnxTmpfile) tmpf = { + 0, + }; + if (!glnx_open_tmpfile_linkable_at (commit_tmp_dfd (self), ".", O_WRONLY | O_CLOEXEC, &tmpf, + error)) return FALSE; if (!glnx_try_fallocate (tmpf.fd, 0, len, error)) return FALSE; @@ -1429,8 +1374,7 @@ write_metadata_object (OstreeRepo *self, return FALSE; /* And commit it into place */ - if (!_ostree_repo_commit_tmpf_final (self, actual_checksum, objtype, - &tmpf, cancellable, error)) + if (!_ostree_repo_commit_tmpf_final (self, actual_checksum, objtype, &tmpf, cancellable, error)) return FALSE; if (objtype == OSTREE_OBJECT_TYPE_COMMIT) @@ -1438,11 +1382,8 @@ write_metadata_object (OstreeRepo *self, GError *local_error = NULL; /* If we are writing a commit, be sure there is no tombstone for it. We may have deleted the commit and now we are trying to pull it again. */ - if (!ostree_repo_delete_object (self, - OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT, - actual_checksum, - cancellable, - &local_error)) + if (!ostree_repo_delete_object (self, OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT, actual_checksum, + cancellable, &local_error)) { if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) g_clear_error (&local_error); @@ -1469,21 +1410,21 @@ write_metadata_object (OstreeRepo *self, * (device,inode) → checksum map. */ static gboolean -scan_one_loose_devino (OstreeRepo *self, - int object_dir_fd, - GHashTable *devino_cache, - GCancellable *cancellable, - GError **error) +scan_one_loose_devino (OstreeRepo *self, int object_dir_fd, GHashTable *devino_cache, + GCancellable *cancellable, GError **error) { - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; - if (!glnx_dirfd_iterator_init_at (object_dir_fd, ".", FALSE, - &dfd_iter, error)) + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; + if (!glnx_dirfd_iterator_init_at (object_dir_fd, ".", FALSE, &dfd_iter, error)) return FALSE; while (TRUE) { struct dirent *dent; - g_auto(GLnxDirFdIterator) child_dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) child_dfd_iter = { + 0, + }; if (!glnx_dirfd_iterator_next_dent (&dfd_iter, &dent, cancellable, error)) return FALSE; @@ -1494,8 +1435,7 @@ scan_one_loose_devino (OstreeRepo *self, if (strlen (dent->d_name) != 2) continue; - if (!glnx_dirfd_iterator_init_at (dfd_iter.fd, dent->d_name, FALSE, - &child_dfd_iter, error)) + if (!glnx_dirfd_iterator_init_at (dfd_iter.fd, dent->d_name, FALSE, &child_dfd_iter, error)) return FALSE; while (TRUE) @@ -1532,8 +1472,8 @@ scan_one_loose_devino (OstreeRepo *self, continue; struct stat stbuf; - if (!glnx_fstatat (child_dfd_iter.fd, child_dent->d_name, - &stbuf, AT_SYMLINK_NOFOLLOW, error)) + if (!glnx_fstatat (child_dfd_iter.fd, child_dent->d_name, &stbuf, AT_SYMLINK_NOFOLLOW, + error)) return FALSE; OstreeDevIno *key = g_new (OstreeDevIno, 1); @@ -1541,7 +1481,7 @@ scan_one_loose_devino (OstreeRepo *self, key->ino = stbuf.st_ino; memcpy (key->checksum, dent->d_name, 2); memcpy (key->checksum + 2, name, 62); - key->checksum[sizeof(key->checksum)-1] = '\0'; + key->checksum[sizeof (key->checksum) - 1] = '\0'; g_hash_table_add (devino_cache, key); } } @@ -1551,10 +1491,8 @@ scan_one_loose_devino (OstreeRepo *self, /* Used by ostree_repo_scan_hardlinks(); see that function for more information. */ static gboolean -scan_loose_devino (OstreeRepo *self, - GHashTable *devino_cache, - GCancellable *cancellable, - GError **error) +scan_loose_devino (OstreeRepo *self, GHashTable *devino_cache, GCancellable *cancellable, + GError **error) { if (self->parent_repo) { @@ -1562,16 +1500,14 @@ scan_loose_devino (OstreeRepo *self, return FALSE; } - if (self->mode == OSTREE_REPO_MODE_ARCHIVE && - self->uncompressed_objects_dir_fd != -1) + if (self->mode == OSTREE_REPO_MODE_ARCHIVE && self->uncompressed_objects_dir_fd != -1) { if (!scan_one_loose_devino (self, self->uncompressed_objects_dir_fd, devino_cache, cancellable, error)) return FALSE; } - if (!scan_one_loose_devino (self, self->objects_dir_fd, - devino_cache, cancellable, error)) + if (!scan_one_loose_devino (self, self->objects_dir_fd, devino_cache, cancellable, error)) return FALSE; return TRUE; @@ -1580,10 +1516,8 @@ scan_loose_devino (OstreeRepo *self, /* Loook up a (device,inode) pair in our cache, and see if it maps to a known * checksum. */ static const char * -devino_cache_lookup (OstreeRepo *self, - OstreeRepoCommitModifier *modifier, - guint32 device, - guint32 inode) +devino_cache_lookup (OstreeRepo *self, OstreeRepoCommitModifier *modifier, guint32 device, + guint32 inode) { OstreeDevIno dev_ino_key; OstreeDevIno *dev_ino_val; @@ -1629,9 +1563,7 @@ devino_cache_lookup (OstreeRepo *self, * Multithreading: This function is *not* MT safe. */ gboolean -ostree_repo_scan_hardlinks (OstreeRepo *self, - GCancellable *cancellable, - GError **error) +ostree_repo_scan_hardlinks (OstreeRepo *self, GCancellable *cancellable, GError **error) { g_assert (self != NULL); g_assert (OSTREE_IS_REPO (self)); @@ -1640,7 +1572,7 @@ ostree_repo_scan_hardlinks (OstreeRepo *self, return glnx_throw (error, "Failed to scan hardlinks, not in a transaction"); if (!self->loose_object_devino_hash) - self->loose_object_devino_hash = (GHashTable*)ostree_repo_devino_cache_new (); + self->loose_object_devino_hash = (GHashTable *)ostree_repo_devino_cache_new (); g_hash_table_remove_all (self->loose_object_devino_hash); return scan_loose_devino (self, self->loose_object_devino_hash, cancellable, error); } @@ -1673,10 +1605,8 @@ ostree_repo_scan_hardlinks (OstreeRepo *self, * active at a time. */ gboolean -ostree_repo_prepare_transaction (OstreeRepo *self, - gboolean *out_transaction_resume, - GCancellable *cancellable, - GError **error) +ostree_repo_prepare_transaction (OstreeRepo *self, gboolean *out_transaction_resume, + GCancellable *cancellable, GError **error) { g_assert (self != NULL); g_assert (OSTREE_IS_REPO (self)); @@ -1689,13 +1619,12 @@ ostree_repo_prepare_transaction (OstreeRepo *self, /* Set up to abort the transaction if we return early from this function. * We can't call _ostree_repo_auto_transaction_start() here, because that * would be a circular dependency; use the lower-level version instead. */ - g_autoptr(OstreeRepoAutoTransaction) txn = _ostree_repo_auto_transaction_new (self); + g_autoptr (OstreeRepoAutoTransaction) txn = _ostree_repo_auto_transaction_new (self); g_assert (txn != NULL); memset (&self->txn.stats, 0, sizeof (OstreeRepoTransactionStats)); - self->txn_locked = ostree_repo_lock_push (self, OSTREE_REPO_LOCK_SHARED, - cancellable, error); + self->txn_locked = ostree_repo_lock_push (self, OSTREE_REPO_LOCK_SHARED, cancellable, error); if (!self->txn_locked) return FALSE; @@ -1738,16 +1667,14 @@ ostree_repo_prepare_transaction (OstreeRepo *self, g_mutex_unlock (&self->txn_lock); gboolean ret_transaction_resume = FALSE; - if (!_ostree_repo_allocate_tmpdir (self->tmp_dir_fd, - self->stagedir_prefix, - &self->commit_stagedir, - &self->commit_stagedir_lock, - &ret_transaction_resume, - cancellable, error)) + if (!_ostree_repo_allocate_tmpdir (self->tmp_dir_fd, self->stagedir_prefix, + &self->commit_stagedir, &self->commit_stagedir_lock, + &ret_transaction_resume, cancellable, error)) return FALSE; /* Success: do not abort the transaction when returning. */ - g_clear_object (&txn->repo); (void) txn; + g_clear_object (&txn->repo); + (void)txn; if (out_transaction_resume) *out_transaction_resume = ret_transaction_resume; @@ -1756,15 +1683,15 @@ ostree_repo_prepare_transaction (OstreeRepo *self, /* Synchronize the directories holding the objects */ static gboolean -fsync_object_dirs (OstreeRepo *self, - GCancellable *cancellable, - GError **error) +fsync_object_dirs (OstreeRepo *self, GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("fsync objdirs", error); - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; if (self->disable_fsync) - return TRUE; /* No fsync? Nothing to do then. */ + return TRUE; /* No fsync? Nothing to do then. */ if (!glnx_dirfd_iterator_init_at (self->objects_dir_fd, ".", FALSE, &dfd_iter, error)) return FALSE; @@ -1782,8 +1709,7 @@ fsync_object_dirs (OstreeRepo *self, continue; glnx_autofd int target_dir_fd = -1; - if (!glnx_opendirat (self->objects_dir_fd, dent->d_name, FALSE, - &target_dir_fd, error)) + if (!glnx_opendirat (self->objects_dir_fd, dent->d_name, FALSE, &target_dir_fd, error)) return FALSE; /* This synchronizes the directory to ensure all the objects we wrote * are there. We need to do this before removing the .commitpartial @@ -1807,12 +1733,12 @@ fsync_object_dirs (OstreeRepo *self, * https://github.com/ostreedev/ostree/issues/1184 */ static gboolean -rename_pending_loose_objects (OstreeRepo *self, - GCancellable *cancellable, - GError **error) +rename_pending_loose_objects (OstreeRepo *self, GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("rename pending", error); - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; if (!glnx_dirfd_iterator_init_at (self->commit_stagedir.fd, ".", FALSE, &dfd_iter, error)) return FALSE; @@ -1833,9 +1759,10 @@ rename_pending_loose_objects (OstreeRepo *self, if (strlen (dent->d_name) != 2) continue; - g_auto(GLnxDirFdIterator) child_dfd_iter = { 0, }; - if (!glnx_dirfd_iterator_init_at (dfd_iter.fd, dent->d_name, FALSE, - &child_dfd_iter, error)) + g_auto (GLnxDirFdIterator) child_dfd_iter = { + 0, + }; + if (!glnx_dirfd_iterator_init_at (dfd_iter.fd, dent->d_name, FALSE, &child_dfd_iter, error)) return FALSE; char loose_objpath[_OSTREE_LOOSE_PATH_MAX]; @@ -1853,14 +1780,14 @@ rename_pending_loose_objects (OstreeRepo *self, if (child_dent == NULL) break; - g_strlcpy (loose_objpath + 3, child_dent->d_name, sizeof (loose_objpath)-3); + g_strlcpy (loose_objpath + 3, child_dent->d_name, sizeof (loose_objpath) - 3); if (!_ostree_repo_ensure_loose_objdir_at (self->objects_dir_fd, loose_objpath, cancellable, error)) return FALSE; - if (!glnx_renameat (child_dfd_iter.fd, loose_objpath + 3, - self->objects_dir_fd, loose_objpath, error)) + if (!glnx_renameat (child_dfd_iter.fd, loose_objpath + 3, self->objects_dir_fd, + loose_objpath, error)) return FALSE; } } @@ -1872,16 +1799,15 @@ rename_pending_loose_objects (OstreeRepo *self, * ostree_repo_prepare_transaction(). */ static gboolean -cleanup_txn_dir (OstreeRepo *self, - int dfd, - const char *path, - GCancellable *cancellable, - GError **error) +cleanup_txn_dir (OstreeRepo *self, int dfd, const char *path, GCancellable *cancellable, + GError **error) { const char *errprefix = glnx_strjoina ("Cleaning up txn dir ", path); GLNX_AUTO_PREFIX_ERROR (errprefix, error); - g_auto(GLnxLockFile) lockfile = { 0, }; + g_auto (GLnxLockFile) lockfile = { + 0, + }; gboolean did_lock; /* Try to lock, but if we don't get it, move on */ @@ -1914,14 +1840,14 @@ cleanup_txn_dir (OstreeRepo *self, * https://github.com/ostreedev/ostree/issues/713 */ static gboolean -cleanup_tmpdir (OstreeRepo *self, - GCancellable *cancellable, - GError **error) +cleanup_tmpdir (OstreeRepo *self, GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("tmpdir cleanup", error); const guint64 curtime_secs = g_get_real_time () / 1000000; - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; if (!glnx_dirfd_iterator_init_at (self->tmp_dir_fd, ".", TRUE, &dfd_iter, error)) return FALSE; @@ -1984,10 +1910,9 @@ ensure_txn_refs (OstreeRepo *self) if (self->txn.refs == NULL) self->txn.refs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); if (self->txn.collection_refs == NULL) - self->txn.collection_refs = g_hash_table_new_full (ostree_collection_ref_hash, - ostree_collection_ref_equal, - (GDestroyNotify) ostree_collection_ref_free, - g_free); + self->txn.collection_refs + = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, + (GDestroyNotify)ostree_collection_ref_free, g_free); } /** @@ -2009,11 +1934,8 @@ ensure_txn_refs (OstreeRepo *self) * Since: 2019.4 */ gboolean -ostree_repo_mark_commit_partial_reason (OstreeRepo *self, - const char *checksum, - gboolean is_partial, - OstreeRepoCommitState in_state, - GError **error) +ostree_repo_mark_commit_partial_reason (OstreeRepo *self, const char *checksum, gboolean is_partial, + OstreeRepoCommitState in_state, GError **error) { g_autofree char *commitpartial_path = _ostree_get_commitpartial_path (checksum); if (is_partial) @@ -2059,14 +1981,11 @@ ostree_repo_mark_commit_partial_reason (OstreeRepo *self, * Since: 2017.15 */ gboolean -ostree_repo_mark_commit_partial (OstreeRepo *self, - const char *checksum, - gboolean is_partial, - GError **error) +ostree_repo_mark_commit_partial (OstreeRepo *self, const char *checksum, gboolean is_partial, + GError **error) { return ostree_repo_mark_commit_partial_reason (self, checksum, is_partial, - OSTREE_REPO_COMMIT_STATE_NORMAL, - error); + OSTREE_REPO_COMMIT_STATE_NORMAL, error); } /** @@ -2082,9 +2001,7 @@ ostree_repo_mark_commit_partial (OstreeRepo *self, * Multithreading: Since v2017.15 this function is MT safe. */ void -ostree_repo_transaction_set_refspec (OstreeRepo *self, - const char *refspec, - const char *checksum) +ostree_repo_transaction_set_refspec (OstreeRepo *self, const char *refspec, const char *checksum) { g_assert (self != NULL); g_assert (OSTREE_IS_REPO (self)); @@ -2126,9 +2043,7 @@ ostree_repo_transaction_set_refspec (OstreeRepo *self, * Multithreading: Since v2017.15 this function is MT safe. */ void -ostree_repo_transaction_set_ref (OstreeRepo *self, - const char *remote, - const char *ref, +ostree_repo_transaction_set_ref (OstreeRepo *self, const char *remote, const char *ref, const char *checksum) { g_assert (self != NULL); @@ -2169,9 +2084,8 @@ ostree_repo_transaction_set_ref (OstreeRepo *self, * Since: 2018.6 */ void -ostree_repo_transaction_set_collection_ref (OstreeRepo *self, - const OstreeCollectionRef *ref, - const char *checksum) +ostree_repo_transaction_set_collection_ref (OstreeRepo *self, const OstreeCollectionRef *ref, + const char *checksum) { g_assert (self != NULL); g_assert (OSTREE_IS_REPO (self)); @@ -2184,8 +2098,8 @@ ostree_repo_transaction_set_collection_ref (OstreeRepo *self, g_mutex_lock (&self->txn_lock); ensure_txn_refs (self); - g_hash_table_replace (self->txn.collection_refs, - ostree_collection_ref_dup (ref), g_strdup (checksum)); + g_hash_table_replace (self->txn.collection_refs, ostree_collection_ref_dup (ref), + g_strdup (checksum)); g_mutex_unlock (&self->txn_lock); } @@ -2205,16 +2119,11 @@ ostree_repo_transaction_set_collection_ref (OstreeRepo *self, * Multithreading: This function is MT safe. */ gboolean -ostree_repo_set_ref_immediate (OstreeRepo *self, - const char *remote, - const char *ref, - const char *checksum, - GCancellable *cancellable, - GError **error) +ostree_repo_set_ref_immediate (OstreeRepo *self, const char *remote, const char *ref, + const char *checksum, GCancellable *cancellable, GError **error) { - const OstreeCollectionRef _ref = { NULL, (gchar *) ref }; - return _ostree_repo_write_ref (self, remote, &_ref, checksum, NULL, - cancellable, error); + const OstreeCollectionRef _ref = { NULL, (gchar *)ref }; + return _ostree_repo_write_ref (self, remote, &_ref, checksum, NULL, cancellable, error); } /** @@ -2231,16 +2140,11 @@ ostree_repo_set_ref_immediate (OstreeRepo *self, * Since: 2017.10 */ gboolean -ostree_repo_set_alias_ref_immediate (OstreeRepo *self, - const char *remote, - const char *ref, - const char *target, - GCancellable *cancellable, - GError **error) +ostree_repo_set_alias_ref_immediate (OstreeRepo *self, const char *remote, const char *ref, + const char *target, GCancellable *cancellable, GError **error) { - const OstreeCollectionRef _ref = { NULL, (gchar *) ref }; - return _ostree_repo_write_ref (self, remote, &_ref, NULL, target, - cancellable, error); + const OstreeCollectionRef _ref = { NULL, (gchar *)ref }; + return _ostree_repo_write_ref (self, remote, &_ref, NULL, target, cancellable, error); } /** @@ -2259,11 +2163,9 @@ ostree_repo_set_alias_ref_immediate (OstreeRepo *self, * Since: 2018.6 */ gboolean -ostree_repo_set_collection_ref_immediate (OstreeRepo *self, - const OstreeCollectionRef *ref, - const char *checksum, - GCancellable *cancellable, - GError **error) +ostree_repo_set_collection_ref_immediate (OstreeRepo *self, const OstreeCollectionRef *ref, + const char *checksum, GCancellable *cancellable, + GError **error) { g_assert (self != NULL); g_assert (OSTREE_IS_REPO (self)); @@ -2273,8 +2175,7 @@ ostree_repo_set_collection_ref_immediate (OstreeRepo *self, if (checksum != NULL && !ostree_validate_checksum_string (checksum, error)) return FALSE; - return _ostree_repo_write_ref (self, NULL, ref, checksum, NULL, - cancellable, error); + return _ostree_repo_write_ref (self, NULL, ref, checksum, NULL, cancellable, error); } /** @@ -2297,10 +2198,8 @@ ostree_repo_set_collection_ref_immediate (OstreeRepo *self, * active at a time. */ gboolean -ostree_repo_commit_transaction (OstreeRepo *self, - OstreeRepoTransactionStats *out_stats, - GCancellable *cancellable, - GError **error) +ostree_repo_commit_transaction (OstreeRepo *self, OstreeRepoTransactionStats *out_stats, + GCancellable *cancellable, GError **error) { g_assert (self != NULL); g_assert (OSTREE_IS_REPO (self)); @@ -2316,8 +2215,7 @@ ostree_repo_commit_transaction (OstreeRepo *self, /* FIXME: Added OSTREE_SUPPRESS_SYNCFS since valgrind in el7 doesn't know * about `syncfs`...we should delete this later. */ - if (!self->disable_fsync && - g_getenv ("OSTREE_SUPPRESS_SYNCFS") == NULL) + if (!self->disable_fsync && g_getenv ("OSTREE_SUPPRESS_SYNCFS") == NULL) { if (syncfs (self->tmp_dir_fd) < 0) return glnx_throw_errno_prefix (error, "syncfs"); @@ -2352,9 +2250,8 @@ ostree_repo_commit_transaction (OstreeRepo *self, /* Update the summary if auto-update-summary is set, because doing so was * delayed for each ref change during the transaction. */ - if (!self->txn.disable_auto_summary && - (self->txn.refs || self->txn.collection_refs) && - !_ostree_repo_maybe_regenerate_summary (self, cancellable, error)) + if (!self->txn.disable_auto_summary && (self->txn.refs || self->txn.collection_refs) + && !_ostree_repo_maybe_regenerate_summary (self, cancellable, error)) return FALSE; g_clear_pointer (&self->txn.refs, g_hash_table_destroy); @@ -2390,14 +2287,12 @@ ostree_repo_commit_transaction (OstreeRepo *self, * transaction will do nothing and return successfully. */ gboolean -ostree_repo_abort_transaction (OstreeRepo *self, - GCancellable *cancellable, - GError **error) +ostree_repo_abort_transaction (OstreeRepo *self, GCancellable *cancellable, GError **error) { g_assert (self != NULL); g_assert (OSTREE_IS_REPO (self)); - g_autoptr(GError) cleanup_error = NULL; + g_autoptr (GError) cleanup_error = NULL; /* Always ignore the cancellable to avoid the chance that, if it gets * canceled, the transaction may not be fully cleaned up. @@ -2460,32 +2355,27 @@ ostree_repo_abort_transaction (OstreeRepo *self, * computed checksum. */ gboolean -ostree_repo_write_metadata (OstreeRepo *self, - OstreeObjectType objtype, - const char *expected_checksum, - GVariant *object, - guchar **out_csum, - GCancellable *cancellable, - GError **error) +ostree_repo_write_metadata (OstreeRepo *self, OstreeObjectType objtype, + const char *expected_checksum, GVariant *object, guchar **out_csum, + GCancellable *cancellable, GError **error) { - g_autoptr(GVariant) normalized = NULL; + g_autoptr (GVariant) normalized = NULL; /* First, if we have an expected checksum, see if we already have this * object. This mirrors the same logic in ostree_repo_write_content(). */ if (expected_checksum) { gboolean have_obj; - if (!_ostree_repo_has_loose_object (self, expected_checksum, objtype, &have_obj, - cancellable, error)) + if (!_ostree_repo_has_loose_object (self, expected_checksum, objtype, &have_obj, cancellable, + error)) return FALSE; if (have_obj) { /* Update size metadata if needed */ - if (self->generate_sizes && - !repo_has_size_entry (self, objtype, expected_checksum)) + if (self->generate_sizes && !repo_has_size_entry (self, objtype, expected_checksum)) { /* Make sure we have a fully serialized object */ - g_autoptr(GVariant) trusted = g_variant_get_normal_form (object); + g_autoptr (GVariant) trusted = g_variant_get_normal_form (object); gsize size = g_variant_get_size (trusted); repo_store_size_entry (self, objtype, expected_checksum, size, size); } @@ -2508,9 +2398,9 @@ ostree_repo_write_metadata (OstreeRepo *self, if (!_ostree_validate_structureof_metadata (objtype, object, error)) return FALSE; - g_autoptr(GBytes) vdata = g_variant_get_data_as_bytes (normalized); - if (!write_metadata_object (self, objtype, expected_checksum, - vdata, out_csum, cancellable, error)) + g_autoptr (GBytes) vdata = g_variant_get_data_as_bytes (normalized); + if (!write_metadata_object (self, objtype, expected_checksum, vdata, out_csum, cancellable, + error)) return FALSE; return TRUE; @@ -2530,27 +2420,25 @@ ostree_repo_write_metadata (OstreeRepo *self, * trusted. */ gboolean -ostree_repo_write_metadata_stream_trusted (OstreeRepo *self, - OstreeObjectType objtype, - const char *checksum, - GInputStream *object_input, - guint64 length, - GCancellable *cancellable, - GError **error) +ostree_repo_write_metadata_stream_trusted (OstreeRepo *self, OstreeObjectType objtype, + const char *checksum, GInputStream *object_input, + guint64 length, GCancellable *cancellable, + GError **error) { /* This is all pretty ridiculous, but we're keeping this API for backwards * compatibility, it doesn't really need to be fast. */ - g_autoptr(GMemoryOutputStream) tmpbuf = (GMemoryOutputStream*)g_memory_output_stream_new_resizable (); - if (g_output_stream_splice ((GOutputStream*)tmpbuf, object_input, - G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, cancellable, error) < 0) + g_autoptr (GMemoryOutputStream) tmpbuf + = (GMemoryOutputStream *)g_memory_output_stream_new_resizable (); + if (g_output_stream_splice ((GOutputStream *)tmpbuf, object_input, + G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, cancellable, error) + < 0) return FALSE; - g_autoptr(GBytes) tmpb = g_memory_output_stream_steal_as_bytes (tmpbuf); + g_autoptr (GBytes) tmpb = g_memory_output_stream_steal_as_bytes (tmpbuf); - g_autoptr(GVariant) tmpv = g_variant_new_from_bytes (ostree_metadata_variant_type (objtype), - tmpb, TRUE); - return ostree_repo_write_metadata_trusted (self, objtype, checksum, tmpv, - cancellable, error); + g_autoptr (GVariant) tmpv + = g_variant_new_from_bytes (ostree_metadata_variant_type (objtype), tmpb, TRUE); + return ostree_repo_write_metadata_trusted (self, objtype, checksum, tmpv, cancellable, error); } /** @@ -2566,19 +2454,14 @@ ostree_repo_write_metadata_stream_trusted (OstreeRepo *self, * trusted. */ gboolean -ostree_repo_write_metadata_trusted (OstreeRepo *self, - OstreeObjectType type, - const char *checksum, - GVariant *variant, - GCancellable *cancellable, - GError **error) +ostree_repo_write_metadata_trusted (OstreeRepo *self, OstreeObjectType type, const char *checksum, + GVariant *variant, GCancellable *cancellable, GError **error) { - return ostree_repo_write_metadata (self, type, - checksum, variant, NULL, - cancellable, error); + return ostree_repo_write_metadata (self, type, checksum, variant, NULL, cancellable, error); } -typedef struct { +typedef struct +{ OstreeRepo *repo; OstreeObjectType objtype; char *expected_checksum; @@ -2601,18 +2484,13 @@ write_metadata_async_data_free (gpointer user_data) } static void -write_metadata_thread (GTask *task, - GObject *object, - gpointer datap, - GCancellable *cancellable) +write_metadata_thread (GTask *task, GObject *object, gpointer datap, GCancellable *cancellable) { GError *error = NULL; WriteMetadataAsyncData *data = datap; - if (!ostree_repo_write_metadata (data->repo, data->objtype, data->expected_checksum, - data->object, - &data->result_csum, - cancellable, &error)) + if (!ostree_repo_write_metadata (data->repo, data->objtype, data->expected_checksum, data->object, + &data->result_csum, cancellable, &error)) g_task_return_error (task, error); else g_task_return_pointer (task, data, NULL); @@ -2632,15 +2510,12 @@ write_metadata_thread (GTask *task, * the checksum @expected_checksum will be verified. */ void -ostree_repo_write_metadata_async (OstreeRepo *self, - OstreeObjectType objtype, - const char *expected_checksum, - GVariant *object, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +ostree_repo_write_metadata_async (OstreeRepo *self, OstreeObjectType objtype, + const char *expected_checksum, GVariant *object, + GCancellable *cancellable, GAsyncReadyCallback callback, + gpointer user_data) { - g_autoptr(GTask) task = NULL; + g_autoptr (GTask) task = NULL; WriteMetadataAsyncData *asyncdata; asyncdata = g_new0 (WriteMetadataAsyncData, 1); @@ -2666,10 +2541,8 @@ ostree_repo_write_metadata_async (OstreeRepo *self, * Complete a call to ostree_repo_write_metadata_async(). */ gboolean -ostree_repo_write_metadata_finish (OstreeRepo *self, - GAsyncResult *result, - guchar **out_csum, - GError **error) +ostree_repo_write_metadata_finish (OstreeRepo *self, GAsyncResult *result, guchar **out_csum, + GError **error) { WriteMetadataAsyncData *data; @@ -2693,20 +2566,16 @@ ostree_repo_write_metadata_finish (OstreeRepo *self, * Return its (binary) checksum in @out_csum. */ gboolean -_ostree_repo_write_directory_meta (OstreeRepo *self, - GFileInfo *file_info, - GVariant *xattrs, - guchar **out_csum, - GCancellable *cancellable, - GError **error) +_ostree_repo_write_directory_meta (OstreeRepo *self, GFileInfo *file_info, GVariant *xattrs, + guchar **out_csum, GCancellable *cancellable, GError **error) { if (g_cancellable_set_error_if_cancelled (cancellable, error)) return FALSE; - g_autoptr(GVariant) dirmeta = ostree_create_directory_metadata (file_info, xattrs); - return ostree_repo_write_metadata (self, OSTREE_OBJECT_TYPE_DIR_META, NULL, - dirmeta, out_csum, cancellable, error); + g_autoptr (GVariant) dirmeta = ostree_create_directory_metadata (file_info, xattrs); + return ostree_repo_write_metadata (self, OSTREE_OBJECT_TYPE_DIR_META, NULL, dirmeta, out_csum, + cancellable, error); } /** @@ -2725,15 +2594,11 @@ _ostree_repo_write_directory_meta (OstreeRepo *self, * disk, for example. */ gboolean -ostree_repo_write_content_trusted (OstreeRepo *self, - const char *checksum, - GInputStream *object_input, - guint64 length, - GCancellable *cancellable, - GError **error) +ostree_repo_write_content_trusted (OstreeRepo *self, const char *checksum, + GInputStream *object_input, guint64 length, + GCancellable *cancellable, GError **error) { - return ostree_repo_write_content (self, checksum, object_input, length, - NULL, cancellable, error); + return ostree_repo_write_content (self, checksum, object_input, length, NULL, cancellable, error); } /** @@ -2751,13 +2616,9 @@ ostree_repo_write_content_trusted (OstreeRepo *self, * be returned as @out_csum. */ gboolean -ostree_repo_write_content (OstreeRepo *self, - const char *expected_checksum, - GInputStream *object_input, - guint64 length, - guchar **out_csum, - GCancellable *cancellable, - GError **error) +ostree_repo_write_content (OstreeRepo *self, const char *expected_checksum, + GInputStream *object_input, guint64 length, guchar **out_csum, + GCancellable *cancellable, GError **error) { /* First, if we have an expected checksum, see if we already have this * object. This mirrors the same logic in ostree_repo_write_metadata(). @@ -2768,9 +2629,8 @@ ostree_repo_write_content (OstreeRepo *self, if (expected_checksum && !self->generate_sizes) { gboolean have_obj; - if (!_ostree_repo_has_loose_object (self, expected_checksum, - OSTREE_OBJECT_TYPE_FILE, &have_obj, - cancellable, error)) + if (!_ostree_repo_has_loose_object (self, expected_checksum, OSTREE_OBJECT_TYPE_FILE, + &have_obj, cancellable, error)) return FALSE; if (have_obj) { @@ -2781,16 +2641,14 @@ ostree_repo_write_content (OstreeRepo *self, } /* Parse the stream */ - g_autoptr(GInputStream) file_input = NULL; - g_autoptr(GVariant) xattrs = NULL; - g_autoptr(GFileInfo) file_info = NULL; - if (!ostree_content_stream_parse (FALSE, object_input, length, FALSE, - &file_input, &file_info, &xattrs, - cancellable, error)) + g_autoptr (GInputStream) file_input = NULL; + g_autoptr (GVariant) xattrs = NULL; + g_autoptr (GFileInfo) file_info = NULL; + if (!ostree_content_stream_parse (FALSE, object_input, length, FALSE, &file_input, &file_info, + &xattrs, cancellable, error)) return FALSE; - return write_content_object (self, expected_checksum, - file_input, file_info, xattrs, out_csum, + return write_content_object (self, expected_checksum, file_input, file_info, xattrs, out_csum, cancellable, error); } @@ -2818,24 +2676,16 @@ ostree_repo_write_content (OstreeRepo *self, */ _OSTREE_PUBLIC char * -ostree_repo_write_regfile_inline (OstreeRepo *self, - const char *expected_checksum, - guint32 uid, - guint32 gid, - guint32 mode, - GVariant *xattrs, - const guint8* buf, - gsize len, - GCancellable *cancellable, - GError **error) +ostree_repo_write_regfile_inline (OstreeRepo *self, const char *expected_checksum, guint32 uid, + guint32 gid, guint32 mode, GVariant *xattrs, const guint8 *buf, + gsize len, GCancellable *cancellable, GError **error) { - g_autoptr(GInputStream) memin = g_memory_input_stream_new_from_data (buf, len, NULL); - g_autoptr(GFileInfo) finfo = _ostree_mode_uidgid_to_gfileinfo (mode, uid, gid); + g_autoptr (GInputStream) memin = g_memory_input_stream_new_from_data (buf, len, NULL); + g_autoptr (GFileInfo) finfo = _ostree_mode_uidgid_to_gfileinfo (mode, uid, gid); g_file_info_set_size (finfo, len); - g_autofree guint8* csum = NULL; - if (!write_content_object (self, expected_checksum, - memin, finfo, xattrs, &csum, - cancellable, error)) + g_autofree guint8 *csum = NULL; + if (!write_content_object (self, expected_checksum, memin, finfo, xattrs, &csum, cancellable, + error)) return NULL; return ostree_checksum_from_bytes (csum); } @@ -2860,23 +2710,17 @@ ostree_repo_write_regfile_inline (OstreeRepo *self, * Since: 2021.2 */ char * -ostree_repo_write_symlink (OstreeRepo *self, - const char *expected_checksum, - guint32 uid, - guint32 gid, - GVariant *xattrs, - const char *symlink_target, - GCancellable *cancellable, - GError **error) +ostree_repo_write_symlink (OstreeRepo *self, const char *expected_checksum, guint32 uid, + guint32 gid, GVariant *xattrs, const char *symlink_target, + GCancellable *cancellable, GError **error) { g_assert (symlink_target != NULL); - g_autoptr(GFileInfo) finfo = _ostree_mode_uidgid_to_gfileinfo (S_IFLNK | 0777, uid, gid); + g_autoptr (GFileInfo) finfo = _ostree_mode_uidgid_to_gfileinfo (S_IFLNK | 0777, uid, gid); g_file_info_set_attribute_byte_string (finfo, "standard::symlink-target", symlink_target); - g_autofree guint8* csum = NULL; - if (!write_content_object (self, expected_checksum, - NULL, finfo, xattrs, &csum, - cancellable, error)) + g_autofree guint8 *csum = NULL; + if (!write_content_object (self, expected_checksum, NULL, finfo, xattrs, &csum, cancellable, + error)) return NULL; return ostree_checksum_from_bytes (csum); } @@ -2899,22 +2743,20 @@ ostree_repo_write_symlink (OstreeRepo *self, * Since: 2021.2 */ OstreeContentWriter * -ostree_repo_write_regfile (OstreeRepo *self, - const char *expected_checksum, - guint32 uid, - guint32 gid, - guint32 mode, - guint64 content_len, - GVariant *xattrs, - GError **error) +ostree_repo_write_regfile (OstreeRepo *self, const char *expected_checksum, guint32 uid, + guint32 gid, guint32 mode, guint64 content_len, GVariant *xattrs, + GError **error) { if (self->mode == OSTREE_REPO_MODE_ARCHIVE) - return glnx_null_throw (error, "Cannot currently use ostree_repo_write_regfile() on an archive mode repository"); + return glnx_null_throw ( + error, "Cannot currently use ostree_repo_write_regfile() on an archive mode repository"); - return _ostree_content_writer_new (self, expected_checksum, uid, gid, mode, content_len, xattrs, error); + return _ostree_content_writer_new (self, expected_checksum, uid, gid, mode, content_len, xattrs, + error); } -typedef struct { +typedef struct +{ OstreeRepo *repo; char *expected_checksum; GInputStream *object; @@ -2938,18 +2780,14 @@ write_content_async_data_free (gpointer user_data) } static void -write_content_thread (GTask *task, - GObject *object, - gpointer datap, - GCancellable *cancellable) +write_content_thread (GTask *task, GObject *object, gpointer datap, GCancellable *cancellable) { GError *error = NULL; WriteContentAsyncData *data = datap; - if (!ostree_repo_write_content (data->repo, data->expected_checksum, - data->object, data->file_object_length, - &data->result_csum, - cancellable, &error)) + if (!ostree_repo_write_content (data->repo, data->expected_checksum, data->object, + data->file_object_length, &data->result_csum, cancellable, + &error)) g_task_return_error (task, error); else g_task_return_pointer (task, data, NULL); @@ -2969,15 +2807,11 @@ write_content_thread (GTask *task, * checksum @expected_checksum will be verified. */ void -ostree_repo_write_content_async (OstreeRepo *self, - const char *expected_checksum, - GInputStream *object, - guint64 length, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +ostree_repo_write_content_async (OstreeRepo *self, const char *expected_checksum, + GInputStream *object, guint64 length, GCancellable *cancellable, + GAsyncReadyCallback callback, gpointer user_data) { - g_autoptr(GTask) task = NULL; + g_autoptr (GTask) task = NULL; WriteContentAsyncData *asyncdata; asyncdata = g_new0 (WriteContentAsyncData, 1); @@ -3004,10 +2838,8 @@ ostree_repo_write_content_async (OstreeRepo *self, * Completes an invocation of ostree_repo_write_content_async(). */ gboolean -ostree_repo_write_content_finish (OstreeRepo *self, - GAsyncResult *result, - guchar **out_csum, - GError **error) +ostree_repo_write_content_finish (OstreeRepo *self, GAsyncResult *result, guchar **out_csum, + GError **error) { WriteContentAsyncData *data; @@ -3029,7 +2861,7 @@ static GVariant * create_empty_gvariant_dict (void) { GVariantBuilder builder; - g_variant_builder_init (&builder, G_VARIANT_TYPE("a{sv}")); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); return g_variant_builder_end (&builder); } @@ -3054,21 +2886,15 @@ create_empty_gvariant_dict (void) * `SOURCE_DATE_EPOCH` environment flag. */ gboolean -ostree_repo_write_commit (OstreeRepo *self, - const char *parent, - const char *subject, - const char *body, - GVariant *metadata, - OstreeRepoFile *root, - char **out_commit, - GCancellable *cancellable, - GError **error) +ostree_repo_write_commit (OstreeRepo *self, const char *parent, const char *subject, + const char *body, GVariant *metadata, OstreeRepoFile *root, + char **out_commit, GCancellable *cancellable, GError **error) { gint64 timestamp = 0; const gchar *env_timestamp = g_getenv ("SOURCE_DATE_EPOCH"); if (env_timestamp == NULL) { - g_autoptr(GDateTime) now = g_date_time_new_now_utc (); + g_autoptr (GDateTime) now = g_date_time_new_now_utc (); timestamp = g_date_time_to_unix (now); } else @@ -3082,8 +2908,7 @@ ostree_repo_write_commit (OstreeRepo *self, return glnx_throw (error, "Failed to convert SOURCE_DATE_EPOCH"); } - return ostree_repo_write_commit_with_time (self, parent, subject, body, - metadata, root, timestamp, + return ostree_repo_write_commit_with_time (self, parent, subject, body, metadata, root, timestamp, out_commit, cancellable, error); } @@ -3105,40 +2930,31 @@ ostree_repo_write_commit (OstreeRepo *self, * and @root_metadata_checksum. */ gboolean -ostree_repo_write_commit_with_time (OstreeRepo *self, - const char *parent, - const char *subject, - const char *body, - GVariant *metadata, - OstreeRepoFile *root, - guint64 time, - char **out_commit, - GCancellable *cancellable, - GError **error) +ostree_repo_write_commit_with_time (OstreeRepo *self, const char *parent, const char *subject, + const char *body, GVariant *metadata, OstreeRepoFile *root, + guint64 time, char **out_commit, GCancellable *cancellable, + GError **error) { OstreeRepoFile *repo_root = OSTREE_REPO_FILE (root); /* Add sizes information to our metadata object */ - g_autoptr(GVariant) new_metadata = add_size_index_to_metadata (self, metadata); - - g_autoptr(GVariant) commit = - g_variant_new ("(@a{sv}@ay@a(say)sst@ay@ay)", - new_metadata ? new_metadata : create_empty_gvariant_dict (), - parent ? ostree_checksum_to_bytes_v (parent) : ot_gvariant_new_bytearray (NULL, 0), - g_variant_new_array (G_VARIANT_TYPE ("(say)"), NULL, 0), - subject ? subject : "", body ? body : "", - GUINT64_TO_BE (time), - ostree_checksum_to_bytes_v (ostree_repo_file_tree_get_contents_checksum (repo_root)), - ostree_checksum_to_bytes_v (ostree_repo_file_tree_get_metadata_checksum (repo_root))); + g_autoptr (GVariant) new_metadata = add_size_index_to_metadata (self, metadata); + + g_autoptr (GVariant) commit = g_variant_new ( + "(@a{sv}@ay@a(say)sst@ay@ay)", new_metadata ? new_metadata : create_empty_gvariant_dict (), + parent ? ostree_checksum_to_bytes_v (parent) : ot_gvariant_new_bytearray (NULL, 0), + g_variant_new_array (G_VARIANT_TYPE ("(say)"), NULL, 0), subject ? subject : "", + body ? body : "", GUINT64_TO_BE (time), + ostree_checksum_to_bytes_v (ostree_repo_file_tree_get_contents_checksum (repo_root)), + ostree_checksum_to_bytes_v (ostree_repo_file_tree_get_metadata_checksum (repo_root))); g_variant_ref_sink (commit); g_autofree guchar *commit_csum = NULL; - if (!ostree_repo_write_metadata (self, OSTREE_OBJECT_TYPE_COMMIT, NULL, - commit, &commit_csum, + if (!ostree_repo_write_metadata (self, OSTREE_OBJECT_TYPE_COMMIT, NULL, commit, &commit_csum, cancellable, error)) return FALSE; g_autofree char *ret_commit = ostree_checksum_from_bytes (commit_csum); - ot_transfer_out_value(out_commit, &ret_commit); + ot_transfer_out_value (out_commit, &ret_commit); return TRUE; } @@ -3146,7 +2962,8 @@ ostree_repo_write_commit_with_time (OstreeRepo *self, * ostree_repo_read_commit_detached_metadata: * @self: Repo * @checksum: ASCII SHA256 commit checksum - * @out_metadata: (out) (nullable) (transfer full): Metadata associated with commit in with format "a{sv}", or %NULL if none exists + * @out_metadata: (out) (nullable) (transfer full): Metadata associated with commit in with format + * "a{sv}", or %NULL if none exists * @cancellable: Cancellable * @error: Error * @@ -3155,11 +2972,9 @@ ostree_repo_write_commit_with_time (OstreeRepo *self, * to %NULL. */ gboolean -ostree_repo_read_commit_detached_metadata (OstreeRepo *self, - const char *checksum, - GVariant **out_metadata, - GCancellable *cancellable, - GError **error) +ostree_repo_read_commit_detached_metadata (OstreeRepo *self, const char *checksum, + GVariant **out_metadata, GCancellable *cancellable, + GError **error) { g_assert (out_metadata != NULL); @@ -3172,20 +2987,17 @@ ostree_repo_read_commit_detached_metadata (OstreeRepo *self, if (!ot_openat_ignore_enoent (self->commit_stagedir.fd, buf, &fd, error)) return FALSE; if (fd != -1) - return ot_variant_read_fd (fd, 0, G_VARIANT_TYPE ("a{sv}"), TRUE, - out_metadata, error); + return ot_variant_read_fd (fd, 0, G_VARIANT_TYPE ("a{sv}"), TRUE, out_metadata, error); } glnx_autofd int fd = -1; if (!ot_openat_ignore_enoent (self->objects_dir_fd, buf, &fd, error)) return FALSE; if (fd != -1) - return ot_variant_read_fd (fd, 0, G_VARIANT_TYPE ("a{sv}"), TRUE, - out_metadata, error); + return ot_variant_read_fd (fd, 0, G_VARIANT_TYPE ("a{sv}"), TRUE, out_metadata, error); if (self->parent_repo) - return ostree_repo_read_commit_detached_metadata (self->parent_repo, - checksum, out_metadata, + return ostree_repo_read_commit_detached_metadata (self->parent_repo, checksum, out_metadata, cancellable, error); /* Nothing found */ *out_metadata = NULL; @@ -3196,7 +3008,8 @@ ostree_repo_read_commit_detached_metadata (OstreeRepo *self, * ostree_repo_write_commit_detached_metadata: * @self: Repo * @checksum: ASCII SHA256 commit checksum - * @metadata: (nullable): Metadata to associate with commit in with format "a{sv}", or %NULL to delete + * @metadata: (nullable): Metadata to associate with commit in with format "a{sv}", or %NULL to + * delete * @cancellable: Cancellable * @error: Error * @@ -3205,11 +3018,9 @@ ostree_repo_read_commit_detached_metadata (OstreeRepo *self, * data will be deleted. */ gboolean -ostree_repo_write_commit_detached_metadata (OstreeRepo *self, - const char *checksum, - GVariant *metadata, - GCancellable *cancellable, - GError **error) +ostree_repo_write_commit_detached_metadata (OstreeRepo *self, const char *checksum, + GVariant *metadata, GCancellable *cancellable, + GError **error) { int dest_dfd; if (self->in_transaction) @@ -3217,11 +3028,10 @@ ostree_repo_write_commit_detached_metadata (OstreeRepo *self, else dest_dfd = self->objects_dir_fd; - if (!_ostree_repo_ensure_loose_objdir_at (dest_dfd, checksum, - cancellable, error)) + if (!_ostree_repo_ensure_loose_objdir_at (dest_dfd, checksum, cancellable, error)) return FALSE; - g_autoptr(GVariant) normalized = NULL; + g_autoptr (GVariant) normalized = NULL; gsize normalized_size = 0; const guint8 *data = NULL; if (metadata != NULL) @@ -3232,13 +3042,12 @@ ostree_repo_write_commit_detached_metadata (OstreeRepo *self, } if (data == NULL) - data = (guint8*)""; + data = (guint8 *)""; char pathbuf[_OSTREE_LOOSE_PATH_MAX]; _ostree_loose_path (pathbuf, checksum, OSTREE_OBJECT_TYPE_COMMIT_META, self->mode); - if (!glnx_file_replace_contents_at (dest_dfd, pathbuf, - data, normalized_size, - 0, cancellable, error)) + if (!glnx_file_replace_contents_at (dest_dfd, pathbuf, data, normalized_size, 0, cancellable, + error)) { g_prefix_error (error, "Unable to write detached metadata: "); return FALSE; @@ -3251,9 +3060,8 @@ ostree_repo_write_commit_detached_metadata (OstreeRepo *self, * content objects and subdirectories. The input hashes will be sorted */ static GVariant * -create_tree_variant_from_hashes (GHashTable *file_checksums, - GHashTable *dir_contents_checksums, - GHashTable *dir_metadata_checksums) +create_tree_variant_from_hashes (GHashTable *file_checksums, GHashTable *dir_contents_checksums, + GHashTable *dir_metadata_checksums) { GVariantBuilder files_builder; g_variant_builder_init (&files_builder, G_VARIANT_TYPE ("a(say)")); @@ -3261,12 +3069,12 @@ create_tree_variant_from_hashes (GHashTable *file_checksums, g_variant_builder_init (&dirs_builder, G_VARIANT_TYPE ("a(sayay)")); GSList *sorted_filenames = NULL; - GLNX_HASH_TABLE_FOREACH (file_checksums, const char*, name) + GLNX_HASH_TABLE_FOREACH (file_checksums, const char *, name) { /* Should have been validated earlier, but be paranoid */ g_assert (ot_util_filename_validate (name, NULL)); - sorted_filenames = g_slist_prepend (sorted_filenames, (char*)name); + sorted_filenames = g_slist_prepend (sorted_filenames, (char *)name); } sorted_filenames = g_slist_sort (sorted_filenames, (GCompareFunc)strcmp); for (GSList *iter = sorted_filenames; iter; iter = iter->next) @@ -3275,14 +3083,13 @@ create_tree_variant_from_hashes (GHashTable *file_checksums, const char *value; value = g_hash_table_lookup (file_checksums, name); - g_variant_builder_add (&files_builder, "(s@ay)", name, - ostree_checksum_to_bytes_v (value)); + g_variant_builder_add (&files_builder, "(s@ay)", name, ostree_checksum_to_bytes_v (value)); } g_slist_free (sorted_filenames); sorted_filenames = NULL; - GLNX_HASH_TABLE_FOREACH (dir_metadata_checksums, const char*, name) - sorted_filenames = g_slist_prepend (sorted_filenames, (char*)name); + GLNX_HASH_TABLE_FOREACH (dir_metadata_checksums, const char *, name) + sorted_filenames = g_slist_prepend (sorted_filenames, (char *)name); sorted_filenames = g_slist_sort (sorted_filenames, (GCompareFunc)strcmp); for (GSList *iter = sorted_filenames; iter; iter = iter->next) @@ -3299,10 +3106,9 @@ create_tree_variant_from_hashes (GHashTable *file_checksums, g_slist_free (sorted_filenames); sorted_filenames = NULL; - GVariant *serialized_tree = - g_variant_new ("(@a(say)@a(sayay))", - g_variant_builder_end (&files_builder), - g_variant_builder_end (&dirs_builder)); + GVariant *serialized_tree + = g_variant_new ("(@a(say)@a(sayay))", g_variant_builder_end (&files_builder), + g_variant_builder_end (&dirs_builder)); return g_variant_ref_sink (serialized_tree); } @@ -3311,11 +3117,9 @@ create_tree_variant_from_hashes (GHashTable *file_checksums, * will simply be another reference (with incremented refcount) to @file_info. */ OstreeRepoCommitFilterResult -_ostree_repo_commit_modifier_apply (OstreeRepo *self, - OstreeRepoCommitModifier *modifier, - const char *path, - GFileInfo *file_info, - GFileInfo **out_modified_info) +_ostree_repo_commit_modifier_apply (OstreeRepo *self, OstreeRepoCommitModifier *modifier, + const char *path, GFileInfo *file_info, + GFileInfo **out_modified_info) { gboolean canonicalize_perms = FALSE; gboolean has_filter = FALSE; @@ -3376,7 +3180,7 @@ _ostree_repo_commit_modifier_apply (OstreeRepo *self, /* Convert @path into a string */ static char * -ptrarray_path_join (GPtrArray *path) +ptrarray_path_join (GPtrArray *path) { GString *path_buf = g_string_new (""); @@ -3397,36 +3201,30 @@ ptrarray_path_join (GPtrArray *path) } static gboolean -get_final_xattrs (OstreeRepo *self, - OstreeRepoCommitModifier *modifier, - const char *relpath, - GFileInfo *file_info, - GFile *path, - int dfd, - const char *dfd_subpath, - GVariant *source_xattrs, - GVariant **out_xattrs, - gboolean *out_modified, - GCancellable *cancellable, - GError **error) +get_final_xattrs (OstreeRepo *self, OstreeRepoCommitModifier *modifier, const char *relpath, + GFileInfo *file_info, GFile *path, int dfd, const char *dfd_subpath, + GVariant *source_xattrs, GVariant **out_xattrs, gboolean *out_modified, + GCancellable *cancellable, GError **error) { /* track whether the returned xattrs differ from the file on disk */ gboolean modified = TRUE; - const gboolean skip_xattrs = (modifier && - (modifier->flags & (OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS | - OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS)) > 0) || - self->mode == OSTREE_REPO_MODE_BARE_USER_ONLY; + const gboolean skip_xattrs = (modifier + && (modifier->flags + & (OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS + | OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS)) + > 0) + || self->mode == OSTREE_REPO_MODE_BARE_USER_ONLY; /* fetch on-disk xattrs if needed & not disabled */ - g_autoptr(GVariant) original_xattrs = NULL; + g_autoptr (GVariant) original_xattrs = NULL; if (!skip_xattrs && !self->disable_xattrs) { if (source_xattrs) original_xattrs = g_variant_ref (source_xattrs); else if (path && OSTREE_IS_REPO_FILE (path)) { - if (!ostree_repo_file_get_xattrs (OSTREE_REPO_FILE (path), &original_xattrs, - cancellable, error)) + if (!ostree_repo_file_get_xattrs (OSTREE_REPO_FILE (path), &original_xattrs, cancellable, + error)) return FALSE; } else if (path) @@ -3453,11 +3251,10 @@ get_final_xattrs (OstreeRepo *self, g_assert (original_xattrs); } - g_autoptr(GVariant) ret_xattrs = NULL; + g_autoptr (GVariant) ret_xattrs = NULL; if (modifier && modifier->xattr_callback) { - ret_xattrs = modifier->xattr_callback (self, relpath, file_info, - modifier->xattr_user_data); + ret_xattrs = modifier->xattr_callback (self, relpath, file_info, modifier->xattr_user_data); } /* if callback returned NULL or didn't exist, default to on-disk state */ @@ -3479,25 +3276,23 @@ get_final_xattrs (OstreeRepo *self, } else if (label) { - g_autoptr(GVariantBuilder) builder = NULL; + g_autoptr (GVariantBuilder) builder = NULL; if (ret_xattrs) { /* drop out any existing SELinux policy from the set, so we don't end up * counting it twice in the checksum */ - GVariant* new_ret_xattrs = _ostree_filter_selinux_xattr (ret_xattrs); + GVariant *new_ret_xattrs = _ostree_filter_selinux_xattr (ret_xattrs); g_variant_unref (ret_xattrs); ret_xattrs = new_ret_xattrs; } /* ret_xattrs may be NULL */ - builder = ot_util_variant_builder_from_variant (ret_xattrs, - G_VARIANT_TYPE ("a(ayay)")); + builder = ot_util_variant_builder_from_variant (ret_xattrs, G_VARIANT_TYPE ("a(ayay)")); - g_variant_builder_add_value (builder, - g_variant_new ("(@ay@ay)", - g_variant_new_bytestring ("security.selinux"), - g_variant_new_bytestring (label))); + g_variant_builder_add_value ( + builder, g_variant_new ("(@ay@ay)", g_variant_new_bytestring ("security.selinux"), + g_variant_new_bytestring (label))); if (ret_xattrs) g_variant_unref (ret_xattrs); @@ -3516,24 +3311,19 @@ get_final_xattrs (OstreeRepo *self, return TRUE; } -static gboolean -write_directory_to_mtree_internal (OstreeRepo *self, - GFile *dir, - OstreeMutableTree *mtree, - OstreeRepoCommitModifier *modifier, - GPtrArray *path, - GCancellable *cancellable, - GError **error); -static gboolean -write_dfd_iter_to_mtree_internal (OstreeRepo *self, - GLnxDirFdIterator *src_dfd_iter, - OstreeMutableTree *mtree, - OstreeRepoCommitModifier *modifier, - GPtrArray *path, - GCancellable *cancellable, - GError **error); - -typedef enum { +static gboolean write_directory_to_mtree_internal (OstreeRepo *self, GFile *dir, + OstreeMutableTree *mtree, + OstreeRepoCommitModifier *modifier, + GPtrArray *path, GCancellable *cancellable, + GError **error); +static gboolean write_dfd_iter_to_mtree_internal (OstreeRepo *self, GLnxDirFdIterator *src_dfd_iter, + OstreeMutableTree *mtree, + OstreeRepoCommitModifier *modifier, + GPtrArray *path, GCancellable *cancellable, + GError **error); + +typedef enum +{ WRITE_DIR_CONTENT_FLAGS_NONE = 0, WRITE_DIR_CONTENT_FLAGS_CAN_ADOPT = 1, } WriteDirContentFlags; @@ -3544,17 +3334,11 @@ typedef enum { * write_directory_to_mtree_internal (dir_enum case) which will do the actual * dirmeta + dirent iteration. */ static gboolean -write_dir_entry_to_mtree_internal (OstreeRepo *self, - OstreeRepoFile *repo_dir, - GFileEnumerator *dir_enum, - GLnxDirFdIterator *dfd_iter, - WriteDirContentFlags writeflags, - GFileInfo *child_info, - OstreeMutableTree *mtree, - OstreeRepoCommitModifier *modifier, - GPtrArray *path, - GCancellable *cancellable, - GError **error) +write_dir_entry_to_mtree_internal (OstreeRepo *self, OstreeRepoFile *repo_dir, + GFileEnumerator *dir_enum, GLnxDirFdIterator *dfd_iter, + WriteDirContentFlags writeflags, GFileInfo *child_info, + OstreeMutableTree *mtree, OstreeRepoCommitModifier *modifier, + GPtrArray *path, GCancellable *cancellable, GError **error) { g_assert (dir_enum != NULL || dfd_iter != NULL); g_assert (g_file_info_get_file_type (child_info) == G_FILE_TYPE_DIRECTORY); @@ -3565,17 +3349,17 @@ write_dir_entry_to_mtree_internal (OstreeRepo *self, * more complexity in this function, and it'd mostly only be useful when * operating on local filesystems anyways. */ - const gboolean delete_after_commit = dfd_iter && modifier && - (modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CONSUME); + const gboolean delete_after_commit + = dfd_iter && modifier && (modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CONSUME); /* Build the full path which we need for callbacks */ - g_ptr_array_add (path, (char*)name); + g_ptr_array_add (path, (char *)name); g_autofree char *child_relpath = ptrarray_path_join (path); /* Call the filter */ - g_autoptr(GFileInfo) modified_info = NULL; - OstreeRepoCommitFilterResult filter_result = - _ostree_repo_commit_modifier_apply (self, modifier, child_relpath, child_info, &modified_info); + g_autoptr (GFileInfo) modified_info = NULL; + OstreeRepoCommitFilterResult filter_result = _ostree_repo_commit_modifier_apply ( + self, modifier, child_relpath, child_info, &modified_info); if (filter_result != OSTREE_REPO_COMMIT_FILTER_ALLOW) { @@ -3590,41 +3374,40 @@ write_dir_entry_to_mtree_internal (OstreeRepo *self, return TRUE; } - g_autoptr(GFile) child = NULL; + g_autoptr (GFile) child = NULL; if (dir_enum != NULL) child = g_file_enumerator_get_child (dir_enum, child_info); - g_autoptr(OstreeMutableTree) child_mtree = NULL; + g_autoptr (OstreeMutableTree) child_mtree = NULL; if (!ostree_mutable_tree_ensure_dir (mtree, name, &child_mtree, error)) return FALSE; /* Finally, recurse on the dir */ if (dir_enum != NULL) { - if (!write_directory_to_mtree_internal (self, child, child_mtree, - modifier, path, - cancellable, error)) + if (!write_directory_to_mtree_internal (self, child, child_mtree, modifier, path, cancellable, + error)) return FALSE; } else if (repo_dir) { g_assert (dir_enum != NULL); g_debug ("Adding: %s", gs_file_get_path_cached (child)); - if (!ostree_mutable_tree_replace_file (mtree, name, - ostree_repo_file_get_checksum ((OstreeRepoFile*) child), - error)) + if (!ostree_mutable_tree_replace_file ( + mtree, name, ostree_repo_file_get_checksum ((OstreeRepoFile *)child), error)) return FALSE; } else { g_assert (dfd_iter != NULL); - g_auto(GLnxDirFdIterator) child_dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) child_dfd_iter = { + 0, + }; if (!glnx_dirfd_iterator_init_at (dfd_iter->fd, name, FALSE, &child_dfd_iter, error)) return FALSE; - if (!write_dfd_iter_to_mtree_internal (self, &child_dfd_iter, child_mtree, - modifier, path, + if (!write_dfd_iter_to_mtree_internal (self, &child_dfd_iter, child_mtree, modifier, path, cancellable, error)) return FALSE; @@ -3644,17 +3427,11 @@ write_dir_entry_to_mtree_internal (OstreeRepo *self, * the mtree. */ static gboolean -write_content_to_mtree_internal (OstreeRepo *self, - OstreeRepoFile *repo_dir, - GFileEnumerator *dir_enum, - GLnxDirFdIterator *dfd_iter, - WriteDirContentFlags writeflags, - GFileInfo *child_info, - OstreeMutableTree *mtree, - OstreeRepoCommitModifier *modifier, - GPtrArray *path, - GCancellable *cancellable, - GError **error) +write_content_to_mtree_internal (OstreeRepo *self, OstreeRepoFile *repo_dir, + GFileEnumerator *dir_enum, GLnxDirFdIterator *dfd_iter, + WriteDirContentFlags writeflags, GFileInfo *child_info, + OstreeMutableTree *mtree, OstreeRepoCommitModifier *modifier, + GPtrArray *path, GCancellable *cancellable, GError **error) { g_assert (dir_enum != NULL || dfd_iter != NULL); @@ -3664,16 +3441,18 @@ write_content_to_mtree_internal (OstreeRepo *self, /* Load flags into boolean constants for ease of readability (we also need to * NULL-check modifier) */ - const gboolean canonical_permissions = self->mode == OSTREE_REPO_MODE_BARE_USER_ONLY || - (modifier && (modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS)); - const gboolean devino_canonical = modifier && - (modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_DEVINO_CANONICAL); + const gboolean canonical_permissions + = self->mode == OSTREE_REPO_MODE_BARE_USER_ONLY + || (modifier + && (modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS)); + const gboolean devino_canonical + = modifier && (modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_DEVINO_CANONICAL); /* We currently only honor the CONSUME flag in the dfd_iter case to avoid even * more complexity in this function, and it'd mostly only be useful when * operating on local filesystems anyways. */ - const gboolean delete_after_commit = dfd_iter && modifier && - (modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CONSUME); + const gboolean delete_after_commit + = dfd_iter && modifier && (modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CONSUME); /* See if we have a devino hit; this is used below in a few places. */ const char *loose_checksum = NULL; @@ -3703,7 +3482,7 @@ write_content_to_mtree_internal (OstreeRepo *self, } /* Build the full path which we need for callbacks */ - g_ptr_array_add (path, (char*)name); + g_ptr_array_add (path, (char *)name); g_autofree char *child_relpath = ptrarray_path_join (path); /* For bare-user repos we'll reload our file info from the object @@ -3712,8 +3491,8 @@ write_content_to_mtree_internal (OstreeRepo *self, * Basically we're making sure that we pick up "real" uid/gid and any xattrs * there. */ - g_autoptr(GVariant) source_xattrs = NULL; - g_autoptr(GFileInfo) source_child_info = NULL; + g_autoptr (GVariant) source_xattrs = NULL; + g_autoptr (GFileInfo) source_child_info = NULL; if (loose_checksum && self->mode == OSTREE_REPO_MODE_BARE_USER) { if (!ostree_repo_load_file (self, loose_checksum, NULL, &source_child_info, &source_xattrs, @@ -3723,9 +3502,9 @@ write_content_to_mtree_internal (OstreeRepo *self, } /* Call the filter */ - g_autoptr(GFileInfo) modified_info = NULL; - OstreeRepoCommitFilterResult filter_result = - _ostree_repo_commit_modifier_apply (self, modifier, child_relpath, child_info, &modified_info); + g_autoptr (GFileInfo) modified_info = NULL; + OstreeRepoCommitFilterResult filter_result = _ostree_repo_commit_modifier_apply ( + self, modifier, child_relpath, child_info, &modified_info); const gboolean child_info_was_modified = !_ostree_gfileinfo_equal (child_info, modified_info); if (filter_result != OSTREE_REPO_COMMIT_FILTER_ALLOW) @@ -3750,7 +3529,7 @@ write_content_to_mtree_internal (OstreeRepo *self, return glnx_throw (error, "Unsupported file type for file: '%s'", child_relpath); } - g_autoptr(GFile) child = NULL; + g_autoptr (GFile) child = NULL; if (dir_enum != NULL) child = g_file_enumerator_get_child (dir_enum, child_info); @@ -3770,13 +3549,12 @@ write_content_to_mtree_internal (OstreeRepo *self, return FALSE; } - g_autoptr(GVariant) xattrs = NULL; + g_autoptr (GVariant) xattrs = NULL; gboolean xattrs_were_modified; if (dir_enum != NULL) { - if (!get_final_xattrs (self, modifier, child_relpath, child_info, child, - -1, name, source_xattrs, &xattrs, &xattrs_were_modified, - cancellable, error)) + if (!get_final_xattrs (self, modifier, child_relpath, child_info, child, -1, name, + source_xattrs, &xattrs, &xattrs_were_modified, cancellable, error)) return FALSE; } else @@ -3786,9 +3564,8 @@ write_content_to_mtree_internal (OstreeRepo *self, */ int xattr_fd_arg = (file_input_fd != -1) ? file_input_fd : dfd_iter->fd; const char *xattr_path_arg = (file_input_fd != -1) ? NULL : name; - if (!get_final_xattrs (self, modifier, child_relpath, child_info, child, - xattr_fd_arg, xattr_path_arg, source_xattrs, - &xattrs, &xattrs_were_modified, + if (!get_final_xattrs (self, modifier, child_relpath, child_info, child, xattr_fd_arg, + xattr_path_arg, source_xattrs, &xattrs, &xattrs_were_modified, cancellable, error)) return FALSE; } @@ -3799,11 +3576,9 @@ write_content_to_mtree_internal (OstreeRepo *self, /* A big prerequisite list of conditions for whether or not we can * "adopt", i.e. just checksum and rename() into place */ - const gboolean can_adopt_basic = - file_type == G_FILE_TYPE_REGULAR - && dfd_iter != NULL - && delete_after_commit - && ((writeflags & WRITE_DIR_CONTENT_FLAGS_CAN_ADOPT) > 0); + const gboolean can_adopt_basic = file_type == G_FILE_TYPE_REGULAR && dfd_iter != NULL + && delete_after_commit + && ((writeflags & WRITE_DIR_CONTENT_FLAGS_CAN_ADOPT) > 0); gboolean can_adopt = can_adopt_basic; /* If basic prerquisites are met, check repo mode specific ones */ if (can_adopt) @@ -3826,8 +3601,7 @@ write_content_to_mtree_internal (OstreeRepo *self, /* The very fast path - we have a devino cache hit, nothing to write */ if (loose_checksum && !modified_file_meta) { - if (!ostree_mutable_tree_replace_file (mtree, name, loose_checksum, - error)) + if (!ostree_mutable_tree_replace_file (mtree, name, loose_checksum, error)) return FALSE; g_mutex_lock (&self->txn_lock); @@ -3837,9 +3611,9 @@ write_content_to_mtree_internal (OstreeRepo *self, /* Next fast path - we can "adopt" the file */ else if (can_adopt) { - char checksum[OSTREE_SHA256_STRING_LEN+1]; - if (!adopt_and_commit_regfile (self, dfd_iter->fd, name, modified_info, xattrs, - checksum, cancellable, error)) + char checksum[OSTREE_SHA256_STRING_LEN + 1]; + if (!adopt_and_commit_regfile (self, dfd_iter->fd, name, modified_info, xattrs, checksum, + cancellable, error)) return FALSE; if (!ostree_mutable_tree_replace_file (mtree, name, checksum, error)) return FALSE; @@ -3847,14 +3621,14 @@ write_content_to_mtree_internal (OstreeRepo *self, } else { - g_autoptr(GInputStream) file_input = NULL; + g_autoptr (GInputStream) file_input = NULL; if (file_type == G_FILE_TYPE_REGULAR) { if (dir_enum != NULL) { g_assert (child != NULL); - file_input = (GInputStream*)g_file_read (child, cancellable, error); + file_input = (GInputStream *)g_file_read (child, cancellable, error); if (!file_input) return FALSE; } @@ -3866,14 +3640,13 @@ write_content_to_mtree_internal (OstreeRepo *self, } g_autofree guchar *child_file_csum = NULL; - if (!write_content_object (self, NULL, file_input, modified_info, xattrs, - &child_file_csum, cancellable, error)) + if (!write_content_object (self, NULL, file_input, modified_info, xattrs, &child_file_csum, + cancellable, error)) return FALSE; - char tmp_checksum[OSTREE_SHA256_STRING_LEN+1]; + char tmp_checksum[OSTREE_SHA256_STRING_LEN + 1]; ostree_checksum_inplace_from_bytes (child_file_csum, tmp_checksum); - if (!ostree_mutable_tree_replace_file (mtree, name, tmp_checksum, - error)) + if (!ostree_mutable_tree_replace_file (mtree, name, tmp_checksum, error)) return FALSE; } @@ -3894,13 +3667,9 @@ write_content_to_mtree_internal (OstreeRepo *self, /* Handles the dirmeta for the given GFile dir and then calls * write_{dir_entry,content}_to_mtree_internal() for each directory entry. */ static gboolean -write_directory_to_mtree_internal (OstreeRepo *self, - GFile *dir, - OstreeMutableTree *mtree, - OstreeRepoCommitModifier *modifier, - GPtrArray *path, - GCancellable *cancellable, - GError **error) +write_directory_to_mtree_internal (OstreeRepo *self, GFile *dir, OstreeMutableTree *mtree, + OstreeRepoCommitModifier *modifier, GPtrArray *path, + GCancellable *cancellable, GError **error) { OstreeRepoCommitFilterResult filter_result; OstreeRepoFile *repo_dir = NULL; @@ -3911,7 +3680,7 @@ write_directory_to_mtree_internal (OstreeRepo *self, /* If the directory is already in the repository, we can try to * reuse checksums to skip checksumming. */ if (dir && OSTREE_IS_REPO_FILE (dir) && modifier == NULL) - repo_dir = (OstreeRepoFile *) dir; + repo_dir = (OstreeRepoFile *)dir; if (repo_dir) { @@ -3920,24 +3689,23 @@ write_directory_to_mtree_internal (OstreeRepo *self, /* ostree_mutable_tree_fill_from_dirtree returns FALSE if mtree isn't * empty: in which case we're responsible for merging the trees. */ - if (ostree_mutable_tree_fill_empty_from_dirtree (mtree, - ostree_repo_file_get_repo (repo_dir), - ostree_repo_file_tree_get_contents_checksum (repo_dir), - ostree_repo_file_get_checksum (repo_dir))) + if (ostree_mutable_tree_fill_empty_from_dirtree ( + mtree, ostree_repo_file_get_repo (repo_dir), + ostree_repo_file_tree_get_contents_checksum (repo_dir), + ostree_repo_file_get_checksum (repo_dir))) return TRUE; - ostree_mutable_tree_set_metadata_checksum (mtree, ostree_repo_file_tree_get_metadata_checksum (repo_dir)); + ostree_mutable_tree_set_metadata_checksum ( + mtree, ostree_repo_file_tree_get_metadata_checksum (repo_dir)); filter_result = OSTREE_REPO_COMMIT_FILTER_ALLOW; } else { - g_autoptr(GVariant) xattrs = NULL; + g_autoptr (GVariant) xattrs = NULL; - g_autoptr(GFileInfo) child_info = - g_file_query_info (dir, OSTREE_GIO_FAST_QUERYINFO, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - cancellable, error); + g_autoptr (GFileInfo) child_info = g_file_query_info ( + dir, OSTREE_GIO_FAST_QUERYINFO, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!child_info) return FALSE; @@ -3945,13 +3713,14 @@ write_directory_to_mtree_internal (OstreeRepo *self, if (modifier != NULL) relpath = ptrarray_path_join (path); - g_autoptr(GFileInfo) modified_info = NULL; - filter_result = _ostree_repo_commit_modifier_apply (self, modifier, relpath, child_info, &modified_info); + g_autoptr (GFileInfo) modified_info = NULL; + filter_result = _ostree_repo_commit_modifier_apply (self, modifier, relpath, child_info, + &modified_info); if (filter_result == OSTREE_REPO_COMMIT_FILTER_ALLOW) { - if (!get_final_xattrs (self, modifier, relpath, child_info, dir, -1, NULL, - NULL, &xattrs, NULL, cancellable, error)) + if (!get_final_xattrs (self, modifier, relpath, child_info, dir, -1, NULL, NULL, &xattrs, + NULL, cancellable, error)) return FALSE; g_autofree guchar *child_file_csum = NULL; @@ -3966,12 +3735,11 @@ write_directory_to_mtree_internal (OstreeRepo *self, if (filter_result == OSTREE_REPO_COMMIT_FILTER_ALLOW) { - g_autoptr(GFileEnumerator) dir_enum = NULL; + g_autoptr (GFileEnumerator) dir_enum = NULL; - dir_enum = g_file_enumerate_children ((GFile*)dir, OSTREE_GIO_FAST_QUERYINFO, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - cancellable, - error); + dir_enum + = g_file_enumerate_children ((GFile *)dir, OSTREE_GIO_FAST_QUERYINFO, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!dir_enum) return FALSE; @@ -3979,8 +3747,7 @@ write_directory_to_mtree_internal (OstreeRepo *self, { GFileInfo *child_info; - 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; @@ -3988,19 +3755,15 @@ write_directory_to_mtree_internal (OstreeRepo *self, if (g_file_info_get_file_type (child_info) == G_FILE_TYPE_DIRECTORY) { if (!write_dir_entry_to_mtree_internal (self, repo_dir, dir_enum, NULL, - WRITE_DIR_CONTENT_FLAGS_NONE, - child_info, - mtree, modifier, path, - cancellable, error)) + WRITE_DIR_CONTENT_FLAGS_NONE, child_info, + mtree, modifier, path, cancellable, error)) return FALSE; } else { if (!write_content_to_mtree_internal (self, repo_dir, dir_enum, NULL, - WRITE_DIR_CONTENT_FLAGS_NONE, - child_info, - mtree, modifier, path, - cancellable, error)) + WRITE_DIR_CONTENT_FLAGS_NONE, child_info, mtree, + modifier, path, cancellable, error)) return FALSE; } } @@ -4012,16 +3775,12 @@ write_directory_to_mtree_internal (OstreeRepo *self, /* Handles the dirmeta for the dir described by src_dfd_iter and then calls * write_{dir_entry,content}_to_mtree_internal() for each directory entry. */ static gboolean -write_dfd_iter_to_mtree_internal (OstreeRepo *self, - GLnxDirFdIterator *src_dfd_iter, - OstreeMutableTree *mtree, - OstreeRepoCommitModifier *modifier, - GPtrArray *path, - GCancellable *cancellable, - GError **error) +write_dfd_iter_to_mtree_internal (OstreeRepo *self, GLnxDirFdIterator *src_dfd_iter, + OstreeMutableTree *mtree, OstreeRepoCommitModifier *modifier, + GPtrArray *path, GCancellable *cancellable, GError **error) { - g_autoptr(GFileInfo) modified_info = NULL; - g_autoptr(GVariant) xattrs = NULL; + g_autoptr (GFileInfo) modified_info = NULL; + g_autoptr (GVariant) xattrs = NULL; g_autofree guchar *child_file_csum = NULL; g_autofree char *relpath = NULL; OstreeRepoCommitFilterResult filter_result; @@ -4031,11 +3790,12 @@ write_dfd_iter_to_mtree_internal (OstreeRepo *self, return FALSE; { - g_autoptr(GFileInfo) child_info = _ostree_stbuf_to_gfileinfo (&dir_stbuf); + g_autoptr (GFileInfo) child_info = _ostree_stbuf_to_gfileinfo (&dir_stbuf); if (modifier != NULL) { relpath = ptrarray_path_join (path); - filter_result = _ostree_repo_commit_modifier_apply (self, modifier, relpath, child_info, &modified_info); + filter_result = _ostree_repo_commit_modifier_apply (self, modifier, relpath, child_info, + &modified_info); } else { @@ -4046,8 +3806,8 @@ write_dfd_iter_to_mtree_internal (OstreeRepo *self, if (filter_result == OSTREE_REPO_COMMIT_FILTER_ALLOW) { - if (!get_final_xattrs (self, modifier, relpath, modified_info, NULL, src_dfd_iter->fd, - NULL, NULL, &xattrs, NULL, cancellable, error)) + if (!get_final_xattrs (self, modifier, relpath, modified_info, NULL, src_dfd_iter->fd, NULL, + NULL, &xattrs, NULL, cancellable, error)) return FALSE; if (!_ostree_repo_write_directory_meta (self, modified_info, xattrs, &child_file_csum, @@ -4081,15 +3841,13 @@ write_dfd_iter_to_mtree_internal (OstreeRepo *self, if (!glnx_fstatat (src_dfd_iter->fd, dent->d_name, &stbuf, AT_SYMLINK_NOFOLLOW, error)) return FALSE; - g_autoptr(GFileInfo) child_info = _ostree_stbuf_to_gfileinfo (&stbuf); + g_autoptr (GFileInfo) child_info = _ostree_stbuf_to_gfileinfo (&stbuf); g_file_info_set_name (child_info, dent->d_name); if (S_ISDIR (stbuf.st_mode)) { - if (!write_dir_entry_to_mtree_internal (self, NULL, NULL, src_dfd_iter, - flags, child_info, - mtree, modifier, path, - cancellable, error)) + if (!write_dir_entry_to_mtree_internal (self, NULL, NULL, src_dfd_iter, flags, child_info, + mtree, modifier, path, cancellable, error)) return FALSE; /* We handled the dir, move onto the next */ @@ -4100,21 +3858,18 @@ write_dfd_iter_to_mtree_internal (OstreeRepo *self, ; else if (S_ISLNK (stbuf.st_mode)) { - if (!ot_readlinkat_gfile_info (src_dfd_iter->fd, dent->d_name, - child_info, cancellable, error)) + if (!ot_readlinkat_gfile_info (src_dfd_iter->fd, dent->d_name, child_info, cancellable, + error)) return FALSE; } else { - return glnx_throw (error, "Not a regular file or symlink: %s", - dent->d_name); + return glnx_throw (error, "Not a regular file or symlink: %s", dent->d_name); } /* Write a content object, we handled directories above */ - if (!write_content_to_mtree_internal (self, NULL, NULL, src_dfd_iter, - flags, child_info, - mtree, modifier, path, - cancellable, error)) + if (!write_content_to_mtree_internal (self, NULL, NULL, src_dfd_iter, flags, child_info, + mtree, modifier, path, cancellable, error)) return FALSE; } @@ -4134,28 +3889,24 @@ write_dfd_iter_to_mtree_internal (OstreeRepo *self, * overlaying the resulting filesystem hierarchy into @mtree. */ gboolean -ostree_repo_write_directory_to_mtree (OstreeRepo *self, - GFile *dir, - OstreeMutableTree *mtree, - OstreeRepoCommitModifier *modifier, - GCancellable *cancellable, - GError **error) +ostree_repo_write_directory_to_mtree (OstreeRepo *self, GFile *dir, OstreeMutableTree *mtree, + OstreeRepoCommitModifier *modifier, GCancellable *cancellable, + GError **error) { /* Short cut local files */ if (g_file_is_native (dir)) { - if (!ostree_repo_write_dfd_to_mtree (self, AT_FDCWD, gs_file_get_path_cached (dir), - mtree, modifier, cancellable, error)) + if (!ostree_repo_write_dfd_to_mtree (self, AT_FDCWD, gs_file_get_path_cached (dir), mtree, + modifier, cancellable, error)) return FALSE; } else { _ostree_repo_setup_generate_sizes (self, modifier); - g_autoptr(GPtrArray) path = g_ptr_array_new (); - if (!write_directory_to_mtree_internal (self, dir, mtree, modifier, path, - cancellable, error)) + g_autoptr (GPtrArray) path = g_ptr_array_new (); + if (!write_directory_to_mtree_internal (self, dir, mtree, modifier, path, cancellable, error)) return FALSE; } @@ -4177,23 +3928,21 @@ ostree_repo_write_directory_to_mtree (OstreeRepo *self, * resulting filesystem hierarchy into @mtree. */ gboolean -ostree_repo_write_dfd_to_mtree (OstreeRepo *self, - int dfd, - const char *path, - OstreeMutableTree *mtree, - OstreeRepoCommitModifier *modifier, - GCancellable *cancellable, - GError **error) +ostree_repo_write_dfd_to_mtree (OstreeRepo *self, int dfd, const char *path, + OstreeMutableTree *mtree, OstreeRepoCommitModifier *modifier, + GCancellable *cancellable, GError **error) { _ostree_repo_setup_generate_sizes (self, modifier); - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; if (!glnx_dirfd_iterator_init_at (dfd, path, FALSE, &dfd_iter, error)) return FALSE; - g_autoptr(GPtrArray) pathbuilder = g_ptr_array_new (); - if (!write_dfd_iter_to_mtree_internal (self, &dfd_iter, mtree, modifier, pathbuilder, - cancellable, error)) + g_autoptr (GPtrArray) pathbuilder = g_ptr_array_new (); + if (!write_dfd_iter_to_mtree_internal (self, &dfd_iter, mtree, modifier, pathbuilder, cancellable, + error)) return FALSE; /* And now finally remove the toplevel; see also the handling for this flag in @@ -4201,8 +3950,8 @@ ostree_repo_write_dfd_to_mtree (OstreeRepo *self, * try to remove `.` (since we'd get EINVAL); that's what's used in * rpm-ostree. */ - const gboolean delete_after_commit = modifier && - (modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CONSUME); + const gboolean delete_after_commit + = modifier && (modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CONSUME); if (delete_after_commit && !g_str_equal (path, ".")) { if (!glnx_unlinkat (dfd, path, AT_REMOVEDIR, error)) @@ -4225,14 +3974,11 @@ ostree_repo_write_dfd_to_mtree (OstreeRepo *self, * the @mtree represented. */ gboolean -ostree_repo_write_mtree (OstreeRepo *self, - OstreeMutableTree *mtree, - GFile **out_file, - GCancellable *cancellable, - GError **error) +ostree_repo_write_mtree (OstreeRepo *self, OstreeMutableTree *mtree, GFile **out_file, + GCancellable *cancellable, GError **error) { const char *contents_checksum, *metadata_checksum; - g_autoptr(GFile) ret_file = NULL; + g_autoptr (GFile) ret_file = NULL; if (!ostree_mutable_tree_check_error (mtree, error)) return glnx_prefix_error (error, "mtree"); @@ -4248,44 +3994,44 @@ ostree_repo_write_mtree (OstreeRepo *self, } else { - g_autoptr(GHashTable) dir_metadata_checksums = NULL; - g_autoptr(GHashTable) dir_contents_checksums = NULL; - g_autoptr(GVariant) serialized_tree = NULL; + g_autoptr (GHashTable) dir_metadata_checksums = NULL; + g_autoptr (GHashTable) dir_contents_checksums = NULL; + g_autoptr (GVariant) serialized_tree = NULL; g_autofree guchar *contents_csum = NULL; - char contents_checksum_buf[OSTREE_SHA256_STRING_LEN+1]; + char contents_checksum_buf[OSTREE_SHA256_STRING_LEN + 1]; - dir_contents_checksums = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, (GDestroyNotify)g_free); - dir_metadata_checksums = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, (GDestroyNotify)g_free); + dir_contents_checksums = g_hash_table_new_full ( + g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)g_free); + dir_metadata_checksums = g_hash_table_new_full ( + g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)g_free); - GLNX_HASH_TABLE_FOREACH_KV (ostree_mutable_tree_get_subdirs (mtree), - const char*, name, OstreeMutableTree*, child_dir) + GLNX_HASH_TABLE_FOREACH_KV (ostree_mutable_tree_get_subdirs (mtree), const char *, name, + OstreeMutableTree *, child_dir) { - g_autoptr(GFile) child_file = NULL; - if (!ostree_repo_write_mtree (self, child_dir, &child_file, - cancellable, error)) + g_autoptr (GFile) child_file = NULL; + if (!ostree_repo_write_mtree (self, child_dir, &child_file, cancellable, error)) return FALSE; g_hash_table_replace (dir_contents_checksums, g_strdup (name), - g_strdup (ostree_repo_file_tree_get_contents_checksum (OSTREE_REPO_FILE (child_file)))); + g_strdup (ostree_repo_file_tree_get_contents_checksum ( + OSTREE_REPO_FILE (child_file)))); g_hash_table_replace (dir_metadata_checksums, g_strdup (name), - g_strdup (ostree_repo_file_tree_get_metadata_checksum (OSTREE_REPO_FILE (child_file)))); + g_strdup (ostree_repo_file_tree_get_metadata_checksum ( + OSTREE_REPO_FILE (child_file)))); } - serialized_tree = create_tree_variant_from_hashes (ostree_mutable_tree_get_files (mtree), - dir_contents_checksums, - dir_metadata_checksums); + serialized_tree = create_tree_variant_from_hashes ( + ostree_mutable_tree_get_files (mtree), dir_contents_checksums, dir_metadata_checksums); - if (!ostree_repo_write_metadata (self, OSTREE_OBJECT_TYPE_DIR_TREE, NULL, - serialized_tree, &contents_csum, - cancellable, error)) + if (!ostree_repo_write_metadata (self, OSTREE_OBJECT_TYPE_DIR_TREE, NULL, serialized_tree, + &contents_csum, cancellable, error)) return FALSE; ostree_checksum_inplace_from_bytes (contents_csum, contents_checksum_buf); ostree_mutable_tree_set_contents_checksum (mtree, contents_checksum_buf); - ret_file = G_FILE (_ostree_repo_file_new_root (self, contents_checksum_buf, metadata_checksum)); + ret_file + = G_FILE (_ostree_repo_file_new_root (self, contents_checksum_buf, metadata_checksum)); } if (out_file) @@ -4303,10 +4049,9 @@ ostree_repo_write_mtree (OstreeRepo *self, * Returns: (transfer full): A new commit modifier. */ OstreeRepoCommitModifier * -ostree_repo_commit_modifier_new (OstreeRepoCommitModifierFlags flags, - OstreeRepoCommitFilter commit_filter, - gpointer user_data, - GDestroyNotify destroy_notify) +ostree_repo_commit_modifier_new (OstreeRepoCommitModifierFlags flags, + OstreeRepoCommitFilter commit_filter, gpointer user_data, + GDestroyNotify destroy_notify) { OstreeRepoCommitModifier *modifier = g_new0 (OstreeRepoCommitModifier, 1); @@ -4362,10 +4107,9 @@ ostree_repo_commit_modifier_unref (OstreeRepoCommitModifier *modifier) * repository. */ void -ostree_repo_commit_modifier_set_xattr_callback (OstreeRepoCommitModifier *modifier, - OstreeRepoCommitModifierXattrCallback callback, - GDestroyNotify destroy, - gpointer user_data) +ostree_repo_commit_modifier_set_xattr_callback (OstreeRepoCommitModifier *modifier, + OstreeRepoCommitModifierXattrCallback callback, + GDestroyNotify destroy, gpointer user_data) { modifier->xattr_callback = callback; modifier->xattr_destroy = destroy; @@ -4387,8 +4131,8 @@ ostree_repo_commit_modifier_set_xattr_callback (OstreeRepoCommitModifier *modif * policy wins. */ void -ostree_repo_commit_modifier_set_sepolicy (OstreeRepoCommitModifier *modifier, - OstreeSePolicy *sepolicy) +ostree_repo_commit_modifier_set_sepolicy (OstreeRepoCommitModifier *modifier, + OstreeSePolicy *sepolicy) { g_clear_object (&modifier->sepolicy); modifier->sepolicy = sepolicy ? g_object_ref (sepolicy) : NULL; @@ -4409,13 +4153,12 @@ ostree_repo_commit_modifier_set_sepolicy (OstreeRepoCommitModifier * Since: 2020.4 */ gboolean -ostree_repo_commit_modifier_set_sepolicy_from_commit (OstreeRepoCommitModifier *modifier, - OstreeRepo *repo, - const char *rev, - GCancellable *cancellable, - GError **error) +ostree_repo_commit_modifier_set_sepolicy_from_commit (OstreeRepoCommitModifier *modifier, + OstreeRepo *repo, const char *rev, + GCancellable *cancellable, GError **error) { - g_autoptr(OstreeSePolicy) policy = ostree_sepolicy_new_from_commit (repo, rev, cancellable, error); + g_autoptr (OstreeSePolicy) policy + = ostree_sepolicy_new_from_commit (repo, rev, cancellable, error); if (!policy) return FALSE; ostree_repo_commit_modifier_set_sepolicy (modifier, policy); @@ -4441,55 +4184,50 @@ ostree_repo_commit_modifier_set_sepolicy_from_commit (OstreeRepoCommitModifier * Since: 2017.13 */ void -ostree_repo_commit_modifier_set_devino_cache (OstreeRepoCommitModifier *modifier, - OstreeRepoDevInoCache *cache) +ostree_repo_commit_modifier_set_devino_cache (OstreeRepoCommitModifier *modifier, + OstreeRepoDevInoCache *cache) { - modifier->devino_cache = g_hash_table_ref ((GHashTable*)cache); + modifier->devino_cache = g_hash_table_ref ((GHashTable *)cache); } OstreeRepoDevInoCache * ostree_repo_devino_cache_ref (OstreeRepoDevInoCache *cache) { - g_hash_table_ref ((GHashTable*)cache); + g_hash_table_ref ((GHashTable *)cache); return cache; } void ostree_repo_devino_cache_unref (OstreeRepoDevInoCache *cache) { - g_hash_table_unref ((GHashTable*)cache); + g_hash_table_unref ((GHashTable *)cache); } -G_DEFINE_BOXED_TYPE(OstreeRepoDevInoCache, ostree_repo_devino_cache, - ostree_repo_devino_cache_ref, - ostree_repo_devino_cache_unref); +G_DEFINE_BOXED_TYPE (OstreeRepoDevInoCache, ostree_repo_devino_cache, ostree_repo_devino_cache_ref, + ostree_repo_devino_cache_unref); -G_DEFINE_BOXED_TYPE(OstreeRepoCommitModifier, ostree_repo_commit_modifier, - ostree_repo_commit_modifier_ref, - ostree_repo_commit_modifier_unref); +G_DEFINE_BOXED_TYPE (OstreeRepoCommitModifier, ostree_repo_commit_modifier, + ostree_repo_commit_modifier_ref, ostree_repo_commit_modifier_unref); /* Special case between bare-user and bare-user-only, * mostly for https://github.com/flatpak/flatpak/issues/845 * see below for any more comments. */ static gboolean -import_is_bareuser_only_conversion (OstreeRepo *src_repo, - OstreeRepo *dest_repo, +import_is_bareuser_only_conversion (OstreeRepo *src_repo, OstreeRepo *dest_repo, OstreeObjectType objtype) { return src_repo->mode == OSTREE_REPO_MODE_BARE_USER - && dest_repo->mode == OSTREE_REPO_MODE_BARE_USER_ONLY - && objtype == OSTREE_OBJECT_TYPE_FILE; + && dest_repo->mode == OSTREE_REPO_MODE_BARE_USER_ONLY + && objtype == OSTREE_OBJECT_TYPE_FILE; } /* Returns TRUE if we can potentially just call link() to copy an object; * if untrusted the repos must be owned by the same uid. */ static gboolean -import_via_reflink_is_possible (OstreeRepo *src_repo, - OstreeRepo *dest_repo, - OstreeObjectType objtype, - gboolean trusted) +import_via_reflink_is_possible (OstreeRepo *src_repo, OstreeRepo *dest_repo, + OstreeObjectType objtype, gboolean trusted) { /* Untrusted pulls require matching ownership */ if (!trusted && (src_repo->owner_uid != dest_repo->owner_uid)) @@ -4497,8 +4235,7 @@ import_via_reflink_is_possible (OstreeRepo *src_repo, /* Equal modes are always compatible, and metadata * is identical between all modes. */ - if (src_repo->mode == dest_repo->mode || - OSTREE_OBJECT_TYPE_IS_META (objtype)) + if (src_repo->mode == dest_repo->mode || OSTREE_OBJECT_TYPE_IS_META (objtype)) return TRUE; /* And now a special case between bare-user and bare-user-only, * mostly for https://github.com/flatpak/flatpak/issues/845 @@ -4512,23 +4249,18 @@ import_via_reflink_is_possible (OstreeRepo *src_repo, * to @self. */ static gboolean -copy_detached_metadata (OstreeRepo *self, - OstreeRepo *source, - const char *checksum, - GCancellable *cancellable, - GError **error) +copy_detached_metadata (OstreeRepo *self, OstreeRepo *source, const char *checksum, + GCancellable *cancellable, GError **error) { - g_autoptr(GVariant) detached_meta = NULL; - if (!ostree_repo_read_commit_detached_metadata (source, - checksum, &detached_meta, - cancellable, error)) + g_autoptr (GVariant) detached_meta = NULL; + if (!ostree_repo_read_commit_detached_metadata (source, checksum, &detached_meta, cancellable, + error)) return FALSE; if (detached_meta) { - if (!ostree_repo_write_commit_detached_metadata (self, - checksum, detached_meta, - cancellable, error)) + if (!ostree_repo_write_commit_detached_metadata (self, checksum, detached_meta, cancellable, + error)) return FALSE; } @@ -4540,24 +4272,19 @@ copy_detached_metadata (OstreeRepo *self, * we're not verifying the checksum. */ static gboolean -import_one_object_direct (OstreeRepo *dest_repo, - OstreeRepo *src_repo, - const char *checksum, - OstreeObjectType objtype, - gboolean *out_was_supported, - GCancellable *cancellable, - GError **error) +import_one_object_direct (OstreeRepo *dest_repo, OstreeRepo *src_repo, const char *checksum, + OstreeObjectType objtype, gboolean *out_was_supported, + GCancellable *cancellable, GError **error) { - const char *errprefix = glnx_strjoina ("Importing ", checksum, ".", - ostree_object_type_to_string (objtype)); + const char *errprefix + = glnx_strjoina ("Importing ", checksum, ".", ostree_object_type_to_string (objtype)); GLNX_AUTO_PREFIX_ERROR (errprefix, error); char loose_path_buf[_OSTREE_LOOSE_PATH_MAX]; _ostree_loose_path (loose_path_buf, checksum, objtype, dest_repo->mode); /* hardlinks require the owner to match and to be on the same device */ - const gboolean can_hardlink = - src_repo->owner_uid == dest_repo->owner_uid && - src_repo->device == dest_repo->device; + const gboolean can_hardlink + = src_repo->owner_uid == dest_repo->owner_uid && src_repo->device == dest_repo->device; /* Find our target dfd */ int dest_dfd; @@ -4597,8 +4324,8 @@ import_one_object_direct (OstreeRepo *dest_repo, { struct stat stbuf; - if (!glnx_fstatat (src_repo->objects_dir_fd, loose_path_buf, - &stbuf, AT_SYMLINK_NOFOLLOW, error)) + if (!glnx_fstatat (src_repo->objects_dir_fd, loose_path_buf, &stbuf, AT_SYMLINK_NOFOLLOW, + error)) return FALSE; /* Let's punt for symlinks right now, it's more complicated */ @@ -4613,17 +4340,17 @@ import_one_object_direct (OstreeRepo *dest_repo, * in the future we should add flags for those things? */ glnx_autofd int src_fd = -1; - if (!glnx_openat_rdonly (src_repo->objects_dir_fd, loose_path_buf, - FALSE, &src_fd, error)) + if (!glnx_openat_rdonly (src_repo->objects_dir_fd, loose_path_buf, FALSE, &src_fd, error)) return FALSE; /* Open a tmpfile for dest */ - g_auto(GLnxTmpfile) tmp_dest = { 0, }; - if (!glnx_open_tmpfile_linkable_at (dest_dfd, ".", O_WRONLY | O_CLOEXEC, - &tmp_dest, error)) + g_auto (GLnxTmpfile) tmp_dest = { + 0, + }; + if (!glnx_open_tmpfile_linkable_at (dest_dfd, ".", O_WRONLY | O_CLOEXEC, &tmp_dest, error)) return FALSE; - if (glnx_regfile_copy_bytes (src_fd, tmp_dest.fd, (off_t) -1) < 0) + if (glnx_regfile_copy_bytes (src_fd, tmp_dest.fd, (off_t)-1) < 0) return glnx_throw_errno_prefix (error, "regfile copy"); /* Only chown for true bare repos */ @@ -4637,18 +4364,17 @@ import_one_object_direct (OstreeRepo *dest_repo, * bare-user-only. We also only do this for content * objects. */ - const gboolean src_is_bare_or_bare_user = - G_IN_SET (src_repo->mode, OSTREE_REPO_MODE_BARE, OSTREE_REPO_MODE_BARE_USER); - if (src_is_bare_or_bare_user && !OSTREE_OBJECT_TYPE_IS_META(objtype)) + const gboolean src_is_bare_or_bare_user + = G_IN_SET (src_repo->mode, OSTREE_REPO_MODE_BARE, OSTREE_REPO_MODE_BARE_USER); + if (src_is_bare_or_bare_user && !OSTREE_OBJECT_TYPE_IS_META (objtype)) { if (src_repo->mode == OSTREE_REPO_MODE_BARE) { - g_autoptr(GVariant) xattrs = NULL; + g_autoptr (GVariant) xattrs = NULL; xattrs = ostree_fs_get_all_xattrs (src_fd, cancellable, error); if (!xattrs) return FALSE; - if (!glnx_fd_set_all_xattrs (tmp_dest.fd, xattrs, - cancellable, error)) + if (!glnx_fd_set_all_xattrs (tmp_dest.fd, xattrs, cancellable, error)) return FALSE; } else if (dest_repo->mode == OSTREE_REPO_MODE_BARE_USER_ONLY) @@ -4664,14 +4390,14 @@ import_one_object_direct (OstreeRepo *dest_repo, g_assert (src_repo->mode == dest_repo->mode); /* bare-user; we just want ostree.usermeta */ - g_autoptr(GBytes) bytes = - glnx_fgetxattr_bytes (src_fd, "user.ostreemeta", error); + g_autoptr (GBytes) bytes = glnx_fgetxattr_bytes (src_fd, "user.ostreemeta", error); if (bytes == NULL) return FALSE; if (TEMP_FAILURE_RETRY (fsetxattr (tmp_dest.fd, "user.ostreemeta", - (char*)g_bytes_get_data (bytes, NULL), - g_bytes_get_size (bytes), 0)) != 0) + (char *)g_bytes_get_data (bytes, NULL), + g_bytes_get_size (bytes), 0)) + != 0) return glnx_throw_errno_prefix (error, "fsetxattr"); } } @@ -4687,11 +4413,11 @@ import_one_object_direct (OstreeRepo *dest_repo, struct timespec ts[2]; ts[0] = stbuf.st_atim; ts[1] = stbuf.st_mtim; - (void) futimens (tmp_dest.fd, ts); + (void)futimens (tmp_dest.fd, ts); } - if (!_ostree_repo_commit_tmpf_final (dest_repo, checksum, objtype, - &tmp_dest, cancellable, error)) + if (!_ostree_repo_commit_tmpf_final (dest_repo, checksum, objtype, &tmp_dest, cancellable, + error)) return FALSE; } @@ -4713,13 +4439,9 @@ import_one_object_direct (OstreeRepo *dest_repo, * with flags; may make this public API later. */ gboolean -_ostree_repo_import_object (OstreeRepo *self, - OstreeRepo *source, - OstreeObjectType objtype, - const char *checksum, - OstreeRepoImportFlags flags, - GCancellable *cancellable, - GError **error) +_ostree_repo_import_object (OstreeRepo *self, OstreeRepo *source, OstreeObjectType objtype, + const char *checksum, OstreeRepoImportFlags flags, + GCancellable *cancellable, GError **error) { const gboolean trusted = (flags & _OSTREE_REPO_IMPORT_FLAGS_TRUSTED) > 0; /* Implements OSTREE_REPO_PULL_FLAGS_BAREUSERONLY_FILES which was designed for flatpak */ @@ -4727,8 +4449,8 @@ _ostree_repo_import_object (OstreeRepo *self, /* A special case between bare-user and bare-user-only, * mostly for https://github.com/flatpak/flatpak/issues/845 */ - const gboolean is_bareuseronly_conversion = - import_is_bareuser_only_conversion (source, self, objtype); + const gboolean is_bareuseronly_conversion + = import_is_bareuser_only_conversion (source, self, objtype); gboolean try_direct = TRUE; /* If we need to do bareuseronly verification, or we're potentially doing a @@ -4737,10 +4459,8 @@ _ostree_repo_import_object (OstreeRepo *self, */ if ((verify_bareuseronly || is_bareuseronly_conversion) && !OSTREE_OBJECT_TYPE_IS_META (objtype)) { - g_autoptr(GFileInfo) src_finfo = NULL; - if (!ostree_repo_load_file (source, checksum, - NULL, &src_finfo, NULL, - cancellable, error)) + g_autoptr (GFileInfo) src_finfo = NULL; + if (!ostree_repo_load_file (source, checksum, NULL, &src_finfo, NULL, cancellable, error)) return FALSE; if (verify_bareuseronly) @@ -4778,14 +4498,12 @@ _ostree_repo_import_object (OstreeRepo *self, */ if (!trusted) { - if (!ostree_repo_fsck_object (source, objtype, checksum, - cancellable, error)) + if (!ostree_repo_fsck_object (source, objtype, checksum, cancellable, error)) return FALSE; } gboolean direct_was_supported = FALSE; - if (!import_one_object_direct (self, source, checksum, objtype, - &direct_was_supported, + if (!import_one_object_direct (self, source, checksum, objtype, &direct_was_supported, cancellable, error)) return FALSE; @@ -4801,8 +4519,7 @@ _ostree_repo_import_object (OstreeRepo *self, /* First, do we have the object already? */ gboolean has_object; - if (!ostree_repo_has_object (self, objtype, checksum, &has_object, - cancellable, error)) + if (!ostree_repo_has_object (self, objtype, checksum, &has_object, cancellable, error)) return FALSE; /* If we have it, we're done */ if (has_object) @@ -4818,7 +4535,7 @@ _ostree_repo_import_object (OstreeRepo *self, if (OSTREE_OBJECT_TYPE_IS_META (objtype)) { /* Metadata object */ - g_autoptr(GVariant) variant = NULL; + g_autoptr (GVariant) variant = NULL; if (objtype == OSTREE_OBJECT_TYPE_COMMIT) { @@ -4827,34 +4544,28 @@ _ostree_repo_import_object (OstreeRepo *self, return FALSE; } - if (!ostree_repo_load_variant (source, objtype, checksum, - &variant, error)) + if (!ostree_repo_load_variant (source, objtype, checksum, &variant, error)) return FALSE; /* Note this one also now verifies structure in the !trusted case */ g_autofree guchar *real_csum = NULL; - if (!ostree_repo_write_metadata (self, objtype, - checksum, variant, - trusted ? NULL : &real_csum, - cancellable, error)) + if (!ostree_repo_write_metadata (self, objtype, checksum, variant, + trusted ? NULL : &real_csum, cancellable, error)) return FALSE; } else { /* Content object */ guint64 length; - g_autoptr(GInputStream) object_stream = NULL; + g_autoptr (GInputStream) object_stream = NULL; - if (!ostree_repo_load_object_stream (source, objtype, checksum, - &object_stream, &length, + if (!ostree_repo_load_object_stream (source, objtype, checksum, &object_stream, &length, cancellable, error)) return FALSE; g_autofree guchar *real_csum = NULL; - if (!ostree_repo_write_content (self, checksum, - object_stream, length, - trusted ? NULL : &real_csum, - cancellable, error)) + if (!ostree_repo_write_content (self, checksum, object_stream, length, + trusted ? NULL : &real_csum, cancellable, error)) return FALSE; } @@ -4873,17 +4584,13 @@ ostree_repo_transaction_stats_free (OstreeRepoTransactionStats *stats) return g_free (stats); } -G_DEFINE_BOXED_TYPE(OstreeRepoTransactionStats, ostree_repo_transaction_stats, - ostree_repo_transaction_stats_copy, - ostree_repo_transaction_stats_free); - +G_DEFINE_BOXED_TYPE (OstreeRepoTransactionStats, ostree_repo_transaction_stats, + ostree_repo_transaction_stats_copy, ostree_repo_transaction_stats_free); gboolean -_ostree_repo_transaction_write_repo_metadata (OstreeRepo *self, - GVariant *additional_metadata, - char **out_checksum, - GCancellable *cancellable, - GError **error) +_ostree_repo_transaction_write_repo_metadata (OstreeRepo *self, GVariant *additional_metadata, + char **out_checksum, GCancellable *cancellable, + GError **error) { g_assert (self != NULL); g_assert (OSTREE_IS_REPO (self)); @@ -4893,49 +4600,46 @@ _ostree_repo_transaction_write_repo_metadata (OstreeRepo *self, if (collection_id == NULL) return glnx_throw (error, "Repository must have collection ID to write repo metadata"); - OstreeCollectionRef collection_ref = { (gchar *) collection_id, - (gchar *) OSTREE_REPO_METADATA_REF }; + OstreeCollectionRef collection_ref + = { (gchar *)collection_id, (gchar *)OSTREE_REPO_METADATA_REF }; g_autofree char *old_checksum = NULL; - if (!ostree_repo_resolve_rev (self, OSTREE_REPO_METADATA_REF, TRUE, - &old_checksum, error)) + if (!ostree_repo_resolve_rev (self, OSTREE_REPO_METADATA_REF, TRUE, &old_checksum, error)) return FALSE; /* Add bindings to the commit metadata. */ - g_autoptr(GVariantDict) metadata_dict = g_variant_dict_new (additional_metadata); - g_variant_dict_insert (metadata_dict, OSTREE_COMMIT_META_KEY_COLLECTION_BINDING, - "s", collection_ref.collection_id); - g_variant_dict_insert_value (metadata_dict, OSTREE_COMMIT_META_KEY_REF_BINDING, - g_variant_new_strv ((const gchar * const *) &collection_ref.ref_name, 1)); - g_autoptr(GVariant) metadata = g_variant_dict_end (metadata_dict); + g_autoptr (GVariantDict) metadata_dict = g_variant_dict_new (additional_metadata); + g_variant_dict_insert (metadata_dict, OSTREE_COMMIT_META_KEY_COLLECTION_BINDING, "s", + collection_ref.collection_id); + g_variant_dict_insert_value ( + metadata_dict, OSTREE_COMMIT_META_KEY_REF_BINDING, + g_variant_new_strv ((const gchar *const *)&collection_ref.ref_name, 1)); + g_autoptr (GVariant) metadata = g_variant_dict_end (metadata_dict); /* Set up an empty mtree. */ - g_autoptr(OstreeMutableTree) mtree = ostree_mutable_tree_new (); + g_autoptr (OstreeMutableTree) mtree = ostree_mutable_tree_new (); glnx_unref_object GFileInfo *fi = g_file_info_new (); g_file_info_set_attribute_uint32 (fi, "unix::uid", 0); g_file_info_set_attribute_uint32 (fi, "unix::gid", 0); g_file_info_set_attribute_uint32 (fi, "unix::mode", (0755 | S_IFDIR)); - g_autoptr(GVariant) dirmeta = ostree_create_directory_metadata (fi, NULL /* xattrs */); + g_autoptr (GVariant) dirmeta = ostree_create_directory_metadata (fi, NULL /* xattrs */); g_autofree guchar *csum_raw = NULL; - if (!ostree_repo_write_metadata (self, OSTREE_OBJECT_TYPE_DIR_META, NULL, - dirmeta, &csum_raw, cancellable, error)) + if (!ostree_repo_write_metadata (self, OSTREE_OBJECT_TYPE_DIR_META, NULL, dirmeta, &csum_raw, + cancellable, error)) return FALSE; g_autofree char *csum = ostree_checksum_from_bytes (csum_raw); ostree_mutable_tree_set_metadata_checksum (mtree, csum); - g_autoptr(OstreeRepoFile) repo_file = NULL; - if (!ostree_repo_write_mtree (self, mtree, (GFile **) &repo_file, cancellable, error)) + g_autoptr (OstreeRepoFile) repo_file = NULL; + if (!ostree_repo_write_mtree (self, mtree, (GFile **)&repo_file, cancellable, error)) return FALSE; g_autofree gchar *new_checksum = NULL; - if (!ostree_repo_write_commit (self, old_checksum, - NULL /* subject */, NULL /* body */, - metadata, repo_file, - &new_checksum, - cancellable, error)) + if (!ostree_repo_write_commit (self, old_checksum, NULL /* subject */, NULL /* body */, metadata, + repo_file, &new_checksum, cancellable, error)) return FALSE; ostree_repo_transaction_set_collection_ref (self, &collection_ref, new_checksum); diff --git a/src/libostree/ostree-repo-deprecated.h b/src/libostree/ostree-repo-deprecated.h index 780c764c..8704410d 100644 --- a/src/libostree/ostree-repo-deprecated.h +++ b/src/libostree/ostree-repo-deprecated.h @@ -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 diff --git a/src/libostree/ostree-repo-file-enumerator.c b/src/libostree/ostree-repo-file-enumerator.c index 502fe6c4..35dd7638 100644 --- a/src/libostree/ostree-repo-file-enumerator.c +++ b/src/libostree/ostree-repo-file-enumerator.c @@ -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; } diff --git a/src/libostree/ostree-repo-file-enumerator.h b/src/libostree/ostree-repo-file-enumerator.h index 8404d24c..a67ac9d0 100644 --- a/src/libostree/ostree-repo-file-enumerator.h +++ b/src/libostree/ostree-repo-file-enumerator.h @@ -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)) - -typedef struct _OstreeRepoFileEnumerator OstreeRepoFileEnumerator; -typedef struct _OstreeRepoFileEnumeratorClass 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; 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 diff --git a/src/libostree/ostree-repo-file.c b/src/libostree/ostree-repo-file.c index de606b0a..f33bc6b6 100644 --- a/src/libostree/ostree-repo-file.c +++ b/src/libostree/ostree-repo-file.c @@ -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); } diff --git a/src/libostree/ostree-repo-file.h b/src/libostree/ostree-repo-file.h index bfe2ab04..309e2964 100644 --- a/src/libostree/ostree-repo-file.h +++ b/src/libostree/ostree-repo-file.h @@ -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)) - -typedef struct _OstreeRepoFileClass 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; 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 diff --git a/src/libostree/ostree-repo-finder-avahi-parser.c b/src/libostree/ostree-repo-finder-avahi-parser.c index 8eb1ce4c..dfa8d173 100644 --- a/src/libostree/ostree-repo-finder-avahi-parser.c +++ b/src/libostree/ostree-repo-finder-avahi-parser.c @@ -25,23 +25,19 @@ #include "config.h" #include -#include #include +#include #include #include #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); diff --git a/src/libostree/ostree-repo-finder-avahi-private.h b/src/libostree/ostree-repo-finder-avahi-private.h index f44677eb..47d3a876 100644 --- a/src/libostree/ostree-repo-finder-avahi-private.h +++ b/src/libostree/ostree-repo-finder-avahi-private.h @@ -24,8 +24,8 @@ #include #include -#include #include +#include G_BEGIN_DECLS diff --git a/src/libostree/ostree-repo-finder-avahi.c b/src/libostree/ostree-repo-finder-avahi.c index 7555df6e..680ac0b7 100644 --- a/src/libostree/ostree-repo-finder-avahi.c +++ b/src/libostree/ostree-repo-finder-avahi.c @@ -37,25 +37,25 @@ #include #include #include -#endif /* HAVE_AVAHI */ +#endif /* HAVE_AVAHI */ #include -#include #include +#include #include #include "ostree-autocleanups.h" -#include "ostree-repo-finder.h" #include "ostree-repo-finder-avahi.h" +#include "ostree-repo-finder.h" #ifdef HAVE_AVAHI #include "ostree-bloom-private.h" #include "ostree-remote-private.h" +#include "ostree-repo-finder-avahi-private.h" #include "ostree-repo-private.h" #include "ostree-repo.h" -#include "ostree-repo-finder-avahi-private.h" #include "otutil.h" -#endif /* HAVE_AVAHI */ +#endif /* HAVE_AVAHI */ /** * SECTION:ostree-repo-finder-avahi @@ -107,7 +107,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (AvahiServiceBrowser, avahi_service_browser_free) G_DEFINE_AUTOPTR_CLEANUP_FUNC (AvahiServiceResolver, avahi_service_resolver_free) /* FIXME: Register this with IANA? https://tools.ietf.org/html/rfc6335#section-5.2 */ -const gchar * const OSTREE_AVAHI_SERVICE_TYPE = "_ostree_repo._tcp"; +const gchar *const OSTREE_AVAHI_SERVICE_TYPE = "_ostree_repo._tcp"; static const gchar * ostree_avahi_client_state_to_string (AvahiClientState state) @@ -166,7 +166,7 @@ ostree_avahi_browser_event_to_string (AvahiBrowserEvent event) typedef struct { gchar *uri; - OstreeRemote *keyring_remote; /* (owned) */ + OstreeRemote *keyring_remote; /* (owned) */ } UriAndKeyring; static void @@ -180,10 +180,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); @@ -201,13 +200,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). */ @@ -215,7 +213,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); @@ -261,8 +260,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeAvahiService, ostree_avahi_service_free) * (See https://en.wikipedia.org/wiki/IPv6_address#Link-local_addresses_and_zone_indices and * https://github.com/lathiat/avahi/issues/110.) */ static gchar * -address_to_string (const AvahiAddress *address, - AvahiIfIndex interface) +address_to_string (const AvahiAddress *address, AvahiIfIndex interface) { char address_string[AVAHI_ADDRESS_STR_MAX]; @@ -271,8 +269,7 @@ address_to_string (const AvahiAddress *address, switch (address->proto) { case AVAHI_PROTO_INET6: - if (IN6_IS_ADDR_LINKLOCAL (address->data.data) || - IN6_IS_ADDR_LOOPBACK (address->data.data)) + if (IN6_IS_ADDR_LINKLOCAL (address->data.data) || IN6_IS_ADDR_LOOPBACK (address->data.data)) return g_strdup_printf ("%s%%%d", address_string, interface); /* else fall through */ case AVAHI_PROTO_INET: @@ -283,14 +280,10 @@ address_to_string (const AvahiAddress *address, } static OstreeAvahiService * -ostree_avahi_service_new (const gchar *name, - const gchar *domain, - const AvahiAddress *address, - AvahiIfIndex interface, - guint16 port, - AvahiStringList *txt) +ostree_avahi_service_new (const gchar *name, const gchar *domain, const AvahiAddress *address, + AvahiIfIndex interface, guint16 port, AvahiStringList *txt) { - g_autoptr(OstreeAvahiService) service = NULL; + g_autoptr (OstreeAvahiService) service = NULL; g_return_val_if_fail (name != NULL, NULL); g_return_val_if_fail (domain != NULL, NULL); @@ -328,12 +321,11 @@ str_is_lowercase (const gchar *str) * is of the wrong type or is not in normal form, %NULL is returned. @key must * be lowercase in order to match reliably. */ static GVariant * -_ostree_txt_records_lookup_variant (GHashTable *attributes, - const gchar *key, +_ostree_txt_records_lookup_variant (GHashTable *attributes, const gchar *key, const GVariantType *value_type) { GBytes *value; - g_autoptr(GVariant) variant = NULL; + g_autoptr (GVariant) variant = NULL; g_return_val_if_fail (attributes != NULL, NULL); g_return_val_if_fail (str_is_lowercase (key), NULL); @@ -360,8 +352,7 @@ _ostree_txt_records_lookup_variant (GHashTable *attributes, /* Bloom hash function family for #OstreeCollectionRef, parameterised by @k. */ static guint64 -ostree_collection_ref_bloom_hash (gconstpointer element, - guint8 k) +ostree_collection_ref_bloom_hash (gconstpointer element, guint8 k) { const OstreeCollectionRef *ref = element; @@ -373,18 +364,17 @@ ostree_collection_ref_bloom_hash (gconstpointer element, * %NULL-terminated. If there is an error decoding the bloom filter (invalid * type, zero length, unknown hash function), %NULL will be returned. */ static GPtrArray * -bloom_refs_intersection (GVariant *bloom_encoded, - const OstreeCollectionRef * const *refs) +bloom_refs_intersection (GVariant *bloom_encoded, const OstreeCollectionRef *const *refs) { - g_autoptr(OstreeBloom) bloom = NULL; - g_autoptr(GVariant) bloom_variant = NULL; + g_autoptr (OstreeBloom) bloom = NULL; + g_autoptr (GVariant) bloom_variant = NULL; guint8 k, hash_id; OstreeBloomHashFunc hash_func; const guint8 *bloom_bytes; gsize n_bloom_bytes; - g_autoptr(GBytes) bytes = NULL; + g_autoptr (GBytes) bytes = NULL; gsize i; - g_autoptr(GPtrArray) possible_refs = NULL; /* (element-type OstreeCollectionRef) */ + g_autoptr (GPtrArray) possible_refs = NULL; /* (element-type OstreeCollectionRef) */ g_variant_get (bloom_encoded, "(yy@ay)", &k, &hash_id, &bloom_variant); @@ -409,7 +399,7 @@ bloom_refs_intersection (GVariant *bloom_encoded, for (i = 0; refs[i] != NULL; i++) { if (ostree_bloom_maybe_contains (bloom, refs[i])) - g_ptr_array_add (possible_refs, (gpointer) refs[i]); + g_ptr_array_add (possible_refs, (gpointer)refs[i]); } return g_steal_pointer (&possible_refs); @@ -422,19 +412,17 @@ bloom_refs_intersection (GVariant *bloom_encoded, * The @summary_map is validated as it’s iterated over; on error, @error will be * set and @refs_and_checksums will be left in an undefined state. */ static gboolean -fill_refs_and_checksums_from_summary_map (GVariantIter *summary_map, - const gchar *collection_id, - GHashTable *refs_and_checksums /* (element-type OstreeCollectionRef utf8) */, - GError **error) +fill_refs_and_checksums_from_summary_map ( + GVariantIter *summary_map, const gchar *collection_id, + GHashTable *refs_and_checksums /* (element-type OstreeCollectionRef utf8) */, GError **error) { g_autofree gchar *ref_name = NULL; - g_autoptr(GVariant) checksum_variant = NULL; + g_autoptr (GVariant) checksum_variant = NULL; - while (g_variant_iter_loop (summary_map, "(s(t@aya{sv}))", - (gpointer *) &ref_name, NULL, - (gpointer *) &checksum_variant, NULL)) + while (g_variant_iter_loop (summary_map, "(s(t@aya{sv}))", (gpointer *)&ref_name, NULL, + (gpointer *)&checksum_variant, NULL)) { - const OstreeCollectionRef ref = { (gchar *) collection_id, ref_name }; + const OstreeCollectionRef ref = { (gchar *)collection_id, ref_name }; if (!ostree_validate_rev (ref_name, error)) return FALSE; @@ -445,8 +433,7 @@ fill_refs_and_checksums_from_summary_map (GVariantIter *summary_map, { g_autofree gchar *checksum_string = ostree_checksum_from_bytes_v (checksum_variant); - g_hash_table_replace (refs_and_checksums, - ostree_collection_ref_dup (&ref), + g_hash_table_replace (refs_and_checksums, ostree_collection_ref_dup (&ref), g_steal_pointer (&checksum_string)); } } @@ -461,16 +448,16 @@ fill_refs_and_checksums_from_summary_map (GVariantIter *summary_map, * The @summary is validated as it’s explored; on error, @error will be * set and @refs_and_checksums will be left in an undefined state. */ static gboolean -fill_refs_and_checksums_from_summary (GVariant *summary, - GHashTable *refs_and_checksums /* (element-type OstreeCollectionRef utf8) */, - GError **error) +fill_refs_and_checksums_from_summary ( + GVariant *summary, GHashTable *refs_and_checksums /* (element-type OstreeCollectionRef utf8) */, + GError **error) { - g_autoptr(GVariant) ref_map_v = NULL; - g_autoptr(GVariant) additional_metadata_v = NULL; - g_autoptr(GVariantIter) ref_map = NULL; - g_auto(GVariantDict) additional_metadata = OT_VARIANT_BUILDER_INITIALIZER; + g_autoptr (GVariant) ref_map_v = NULL; + g_autoptr (GVariant) additional_metadata_v = NULL; + g_autoptr (GVariantIter) ref_map = NULL; + g_auto (GVariantDict) additional_metadata = OT_VARIANT_BUILDER_INITIALIZER; const gchar *collection_id; - g_autoptr(GVariantIter) collection_map = NULL; + g_autoptr (GVariantIter) collection_map = NULL; ref_map_v = g_variant_get_child_value (summary, 0); additional_metadata_v = g_variant_get_child_value (summary, 1); @@ -482,24 +469,28 @@ fill_refs_and_checksums_from_summary (GVariant *summary, * ref map), use that to start matching against the queried refs. Otherwise, * it might specify all its refs in a collection-map; or the summary format is * old and unsuitable for P2P redistribution and we should bail. */ - if (g_variant_dict_lookup (&additional_metadata, OSTREE_SUMMARY_COLLECTION_ID, "&s", &collection_id)) + if (g_variant_dict_lookup (&additional_metadata, OSTREE_SUMMARY_COLLECTION_ID, "&s", + &collection_id)) { if (!ostree_validate_collection_id (collection_id, error)) return FALSE; - if (!fill_refs_and_checksums_from_summary_map (ref_map, collection_id, refs_and_checksums, error)) + if (!fill_refs_and_checksums_from_summary_map (ref_map, collection_id, refs_and_checksums, + error)) return FALSE; } g_clear_pointer (&ref_map, g_variant_iter_free); /* Repeat for the other collections listed in the summary. */ - if (g_variant_dict_lookup (&additional_metadata, OSTREE_SUMMARY_COLLECTION_MAP, "a{sa(s(taya{sv}))}", &collection_map)) + if (g_variant_dict_lookup (&additional_metadata, OSTREE_SUMMARY_COLLECTION_MAP, + "a{sa(s(taya{sv}))}", &collection_map)) { while (g_variant_iter_loop (collection_map, "{sa(s(taya{sv}))}", &collection_id, &ref_map)) { if (!ostree_validate_collection_id (collection_id, error)) return FALSE; - if (!fill_refs_and_checksums_from_summary_map (ref_map, collection_id, refs_and_checksums, error)) + if (!fill_refs_and_checksums_from_summary_map (ref_map, collection_id, refs_and_checksums, + error)) return FALSE; } } @@ -508,9 +499,7 @@ fill_refs_and_checksums_from_summary (GVariant *summary, } static gboolean -remove_null_checksum_refs_cb (gpointer key, - gpointer value, - gpointer user_data) +remove_null_checksum_refs_cb (gpointer key, gpointer value, gpointer user_data) { const char *checksum = value; @@ -526,24 +515,23 @@ remove_null_checksum_refs_cb (gpointer key, * set and %FALSE will be returned. If the intersection of the summary file refs * and the keys in @supported_ref_to_checksum is empty, an error is set. */ static gboolean -get_refs_and_checksums_from_summary (GBytes *summary_bytes, - GHashTable *supported_ref_to_checksum /* (element-type OstreeCollectionRef utf8) */, - OstreeRemote *remote, - GError **error) +get_refs_and_checksums_from_summary ( + GBytes *summary_bytes, + GHashTable *supported_ref_to_checksum /* (element-type OstreeCollectionRef utf8) */, + OstreeRemote *remote, GError **error) { - g_autoptr(GVariant) summary = g_variant_ref_sink (g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, summary_bytes, FALSE)); + g_autoptr (GVariant) summary = g_variant_ref_sink ( + g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, summary_bytes, FALSE)); guint removed_refs; if (!g_variant_is_normal_form (summary)) { - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Not normal form"); + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Not normal form"); return FALSE; } if (!g_variant_is_of_type (summary, OSTREE_SUMMARY_GVARIANT_FORMAT)) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Doesn't match variant type '%s'", + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Doesn't match variant type '%s'", (char *)OSTREE_SUMMARY_GVARIANT_FORMAT); return FALSE; } @@ -551,10 +539,12 @@ get_refs_and_checksums_from_summary (GBytes *summary_bytes, if (!fill_refs_and_checksums_from_summary (summary, supported_ref_to_checksum, error)) return FALSE; - removed_refs = g_hash_table_foreach_remove (supported_ref_to_checksum, remove_null_checksum_refs_cb, NULL); + removed_refs + = g_hash_table_foreach_remove (supported_ref_to_checksum, remove_null_checksum_refs_cb, NULL); if (removed_refs > 0) - g_debug ("Removed %d refs from the list resolved from ‘%s’ (possibly bloom filter false positives)", - removed_refs, remote->name); + g_debug ( + "Removed %d refs from the list resolved from ‘%s’ (possibly bloom filter false positives)", + removed_refs, remote->name); /* If none of the refs had a non-%NULL checksum set, we can discard this peer. */ if (g_hash_table_size (supported_ref_to_checksum) == 0) @@ -571,21 +561,14 @@ get_refs_and_checksums_from_summary (GBytes *summary_bytes, * @out_summary_bytes. This will return %TRUE and set @out_summary_bytes to %NULL * if the summary file does not exist. */ static gboolean -fetch_summary_from_remote (OstreeRepo *repo, - OstreeRemote *remote, - GBytes **out_summary_bytes, - GCancellable *cancellable, - GError **error) +fetch_summary_from_remote (OstreeRepo *repo, OstreeRemote *remote, GBytes **out_summary_bytes, + GCancellable *cancellable, GError **error) { - g_autoptr(GBytes) summary_bytes = NULL; + g_autoptr (GBytes) summary_bytes = NULL; gboolean remote_already_existed = _ostree_repo_add_remote (repo, remote); - gboolean success = ostree_repo_remote_fetch_summary_with_options (repo, - remote->name, - NULL /* options */, - &summary_bytes, - NULL /* signature */, - cancellable, - error); + gboolean success = ostree_repo_remote_fetch_summary_with_options ( + repo, remote->name, NULL /* options */, &summary_bytes, NULL /* signature */, cancellable, + error); if (!remote_already_existed) _ostree_repo_remove_remote (repo, remote); @@ -597,7 +580,7 @@ fetch_summary_from_remote (OstreeRepo *repo, *out_summary_bytes = g_steal_pointer (&summary_bytes); return TRUE; } -#endif /* HAVE_AVAHI */ +#endif /* HAVE_AVAHI */ struct _OstreeRepoFinderAvahi { @@ -609,7 +592,7 @@ struct _OstreeRepoFinderAvahi /* Note: There is a ref-count loop here: each #GTask has a reference to the * #OstreeRepoFinderAvahi, and we have to keep a reference to the #GTask. */ - GPtrArray *resolve_tasks; /* (element-type (owned) GTask) */ + GPtrArray *resolve_tasks; /* (element-type (owned) GTask) */ AvahiGLibPoll *poll; AvahiClient *client; @@ -627,18 +610,20 @@ struct _OstreeRepoFinderAvahi * could end up with more than one resolver if the same name is advertised to * us over multiple interfaces or protocols (for example, IPv4 and IPv6). * Resolve all of them just in case one doesn’t work. */ - GHashTable *resolvers; /* (element-type (owned) utf8 (owned) GPtrArray (element-type (owned) AvahiServiceResolver)) */ + GHashTable *resolvers; /* (element-type (owned) utf8 (owned) GPtrArray (element-type (owned) + AvahiServiceResolver)) */ /* Array of #OstreeAvahiService instances representing all the services which * we currently think are valid. */ - GPtrArray *found_services; /* (element-type (owned OstreeAvahiService) */ -#endif /* HAVE_AVAHI */ + GPtrArray *found_services; /* (element-type (owned OstreeAvahiService) */ +#endif /* HAVE_AVAHI */ }; static void ostree_repo_finder_avahi_iface_init (OstreeRepoFinderInterface *iface); G_DEFINE_TYPE_WITH_CODE (OstreeRepoFinderAvahi, ostree_repo_finder_avahi, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (OSTREE_TYPE_REPO_FINDER, ostree_repo_finder_avahi_iface_init)) + G_IMPLEMENT_INTERFACE (OSTREE_TYPE_REPO_FINDER, + ostree_repo_finder_avahi_iface_init)) #ifdef HAVE_AVAHI @@ -646,29 +631,23 @@ G_DEFINE_TYPE_WITH_CODE (OstreeRepoFinderAvahi, ostree_repo_finder_avahi, G_TYPE * @supported_ref_to_checksum hash table, given the existing refs in it as keys. * See get_refs_and_checksums_from_summary() for more details. */ static gboolean -get_checksums (OstreeRepoFinderAvahi *finder, - OstreeRepo *repo, - OstreeRemote *remote, - GHashTable *supported_ref_to_checksum /* (element-type OstreeCollectionRef utf8) */, - GError **error) +get_checksums (OstreeRepoFinderAvahi *finder, OstreeRepo *repo, OstreeRemote *remote, + GHashTable *supported_ref_to_checksum /* (element-type OstreeCollectionRef utf8) */, + GError **error) { - g_autoptr(GBytes) summary_bytes = NULL; + g_autoptr (GBytes) summary_bytes = NULL; - if (!fetch_summary_from_remote (repo, - remote, - &summary_bytes, - finder->avahi_cancellable, - error)) + if (!fetch_summary_from_remote (repo, remote, &summary_bytes, finder->avahi_cancellable, error)) return FALSE; if (summary_bytes == NULL) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "No summary file found on server"); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "No summary file found on server"); return FALSE; } - return get_refs_and_checksums_from_summary (summary_bytes, supported_ref_to_checksum, remote, error); + return get_refs_and_checksums_from_summary (summary_bytes, supported_ref_to_checksum, remote, + error); } /* Build some #OstreeRepoFinderResults out of the given #OstreeAvahiService by @@ -690,27 +669,25 @@ get_checksums (OstreeRepoFinderAvahi *finder, * hosted on the peer this is. Big endian. */ static void -ostree_avahi_service_build_repo_finder_result (OstreeAvahiService *service, - OstreeRepoFinderAvahi *finder, - OstreeRepo *parent_repo, - gint priority, - const OstreeCollectionRef * const *refs, - GPtrArray *results, - GCancellable *cancellable) +ostree_avahi_service_build_repo_finder_result (OstreeAvahiService *service, + OstreeRepoFinderAvahi *finder, + OstreeRepo *parent_repo, gint priority, + const OstreeCollectionRef *const *refs, + GPtrArray *results, GCancellable *cancellable) { - g_autoptr(GHashTable) attributes = NULL; - g_autoptr(GVariant) version = NULL; - g_autoptr(GVariant) bloom = NULL; - g_autoptr(GVariant) summary_timestamp = NULL; - g_autoptr(GVariant) repo_index = NULL; + g_autoptr (GHashTable) attributes = NULL; + g_autoptr (GVariant) version = NULL; + g_autoptr (GVariant) bloom = NULL; + g_autoptr (GVariant) summary_timestamp = NULL; + g_autoptr (GVariant) repo_index = NULL; g_autofree gchar *repo_path = NULL; - g_autoptr(GPtrArray) possible_refs = NULL; /* (element-type OstreeCollectionRef) */ + g_autoptr (GPtrArray) possible_refs = NULL; /* (element-type OstreeCollectionRef) */ GUri *_uri = NULL; g_autofree gchar *uri = NULL; - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; 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; UriAndKeyring *repo; @@ -741,7 +718,8 @@ ostree_avahi_service_build_repo_finder_result (OstreeAvahiService possible_refs = bloom_refs_intersection (bloom, refs); if (possible_refs == NULL) { - g_debug ("Wrong k parameter or hash id in rb (refs bloom) attribute in TXT record. Ignoring."); + g_debug ( + "Wrong k parameter or hash id in rb (refs bloom) attribute in TXT record. Ignoring."); return; } if (possible_refs->len == 0) @@ -770,28 +748,28 @@ ostree_avahi_service_build_repo_finder_result (OstreeAvahiService /* Create a new result for each keyring needed by @possible_refs. Typically, * there will be a separate keyring per collection, but some might be shared. */ 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); - _uri = g_uri_build (G_URI_FLAGS_ENCODED, "http", NULL, service->address, service->port, repo_path, NULL, NULL); + _uri = g_uri_build (G_URI_FLAGS_ENCODED, "http", NULL, service->address, service->port, repo_path, + NULL, NULL); uri = g_uri_to_string (_uri); g_uri_unref (_uri); for (i = 0; i < possible_refs->len; i++) { const OstreeCollectionRef *ref = g_ptr_array_index (possible_refs, i); - g_autoptr(UriAndKeyring) resolved_repo = NULL; - g_autoptr(OstreeRemote) keyring_remote = NULL; + g_autoptr (UriAndKeyring) resolved_repo = 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, - ref->collection_id, + keyring_remote = ostree_repo_resolve_keyring_for_collection (parent_repo, ref->collection_id, cancellable, &error); if (keyring_remote == NULL) { g_debug ("Ignoring ref (%s, %s) on host ‘%s’ due to missing keyring: %s", - ref->collection_id, refs[i]->ref_name, service->address, - error->message); + ref->collection_id, refs[i]->ref_name, service->address, error->message); g_clear_error (&error); continue; } @@ -808,23 +786,23 @@ ostree_avahi_service_build_repo_finder_result (OstreeAvahiService 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 */); } /* Add a placeholder to @supported_ref_to_checksum for this ref. It will * be filled out by the get_checksums() call below. */ - g_hash_table_insert (supported_ref_to_checksum, (gpointer) ref, NULL); + g_hash_table_insert (supported_ref_to_checksum, (gpointer)ref, NULL); } /* Aggregate the results. */ g_hash_table_iter_init (&iter, repo_to_refs); - 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. */ @@ -847,16 +825,17 @@ ostree_avahi_service_build_repo_finder_result (OstreeAvahiService continue; } - g_ptr_array_add (results, ostree_repo_finder_result_new (remote, OSTREE_REPO_FINDER (finder), - priority, supported_ref_to_checksum, NULL, - GUINT64_FROM_BE (g_variant_get_uint64 (summary_timestamp)))); + g_ptr_array_add (results, + ostree_repo_finder_result_new ( + remote, OSTREE_REPO_FINDER (finder), priority, supported_ref_to_checksum, + NULL, GUINT64_FROM_BE (g_variant_get_uint64 (summary_timestamp)))); } } typedef struct { - OstreeCollectionRef **refs; /* (owned) (array zero-terminated=1) */ - OstreeRepo *parent_repo; /* (owned) */ + OstreeCollectionRef **refs; /* (owned) (array zero-terminated=1) */ + OstreeRepo *parent_repo; /* (owned) */ } ResolveData; static void @@ -870,10 +849,9 @@ resolve_data_free (ResolveData *data) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ResolveData, resolve_data_free) static ResolveData * -resolve_data_new (const OstreeCollectionRef * const *refs, - OstreeRepo *parent_repo) +resolve_data_new (const OstreeCollectionRef *const *refs, OstreeRepo *parent_repo) { - g_autoptr(ResolveData) data = NULL; + g_autoptr (ResolveData) data = NULL; data = g_new0 (ResolveData, 1); data->refs = ostree_collection_ref_dupv (refs); @@ -882,27 +860,20 @@ resolve_data_new (const OstreeCollectionRef * const *refs, return g_steal_pointer (&data); } -static void -fail_all_pending_tasks (OstreeRepoFinderAvahi *self, - GQuark domain, - gint code, - const gchar *format, - ...) G_GNUC_PRINTF(4, 5); +static void fail_all_pending_tasks (OstreeRepoFinderAvahi *self, GQuark domain, gint code, + const gchar *format, ...) G_GNUC_PRINTF (4, 5); /* Executed in @self->avahi_context. * * Return the given error from all the pending resolve tasks in * self->resolve_tasks. */ static void -fail_all_pending_tasks (OstreeRepoFinderAvahi *self, - GQuark domain, - gint code, - const gchar *format, +fail_all_pending_tasks (OstreeRepoFinderAvahi *self, GQuark domain, gint code, const gchar *format, ...) { gsize i; va_list args; - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; g_assert (g_main_context_is_owner (self->avahi_context)); @@ -920,11 +891,10 @@ fail_all_pending_tasks (OstreeRepoFinderAvahi *self, } 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); } @@ -938,8 +908,9 @@ static void complete_all_pending_tasks (OstreeRepoFinderAvahi *self) { gsize i; - const gint priority = 60; /* arbitrarily chosen */ - g_autoptr(GPtrArray) results_for_tasks = g_ptr_array_new_full (self->resolve_tasks->len, (GDestroyNotify)g_ptr_array_unref); + const gint priority = 60; /* arbitrarily chosen */ + g_autoptr (GPtrArray) results_for_tasks + = g_ptr_array_new_full (self->resolve_tasks->len, (GDestroyNotify)g_ptr_array_unref); gboolean cancelled = FALSE; g_assert (g_main_context_is_owner (self->avahi_context)); @@ -947,24 +918,23 @@ complete_all_pending_tasks (OstreeRepoFinderAvahi *self) for (i = 0; i < self->resolve_tasks->len; i++) { - g_autoptr(GPtrArray) results = NULL; + g_autoptr (GPtrArray) results = NULL; GTask *task; ResolveData *data; - const OstreeCollectionRef * const *refs; + const OstreeCollectionRef *const *refs; gsize j; task = G_TASK (g_ptr_array_index (self->resolve_tasks, i)); data = g_task_get_task_data (task); - refs = (const OstreeCollectionRef * const *) data->refs; - results = g_ptr_array_new_with_free_func ((GDestroyNotify) ostree_repo_finder_result_free); + refs = (const OstreeCollectionRef *const *)data->refs; + results = g_ptr_array_new_with_free_func ((GDestroyNotify)ostree_repo_finder_result_free); for (j = 0; j < self->found_services->len; j++) { OstreeAvahiService *service = g_ptr_array_index (self->found_services, j); - ostree_avahi_service_build_repo_finder_result (service, self, data->parent_repo, - priority, refs, results, - self->avahi_cancellable); + ostree_avahi_service_build_repo_finder_result (service, self, data->parent_repo, priority, + refs, results, self->avahi_cancellable); if (g_cancellable_is_cancelled (self->avahi_cancellable)) { cancelled = TRUE; @@ -986,9 +956,8 @@ complete_all_pending_tasks (OstreeRepoFinderAvahi *self) g_ptr_array_sort (results, results_compare_cb); - g_task_return_pointer (task, - g_ptr_array_ref (results), - (GDestroyNotify) g_ptr_array_unref); + g_task_return_pointer (task, g_ptr_array_ref (results), + (GDestroyNotify)g_ptr_array_unref); } g_ptr_array_set_size (self->resolve_tasks, 0); @@ -1008,41 +977,34 @@ maybe_complete_all_pending_tasks (OstreeRepoFinderAvahi *self) g_debug ("%s: client_state: %s, browser_failed: %u, cancelled: %u, " "browser_all_for_now: %u, n_resolvers: %u", G_STRFUNC, ostree_avahi_client_state_to_string (self->client_state), - self->browser_failed, - g_cancellable_is_cancelled (self->avahi_cancellable), + self->browser_failed, g_cancellable_is_cancelled (self->avahi_cancellable), self->browser_all_for_now, g_hash_table_size (self->resolvers)); if (self->client_state == AVAHI_CLIENT_FAILURE) - fail_all_pending_tasks (self, G_IO_ERROR, G_IO_ERROR_FAILED, - "Avahi client error: %s", + fail_all_pending_tasks (self, G_IO_ERROR, G_IO_ERROR_FAILED, "Avahi client error: %s", avahi_strerror (avahi_client_errno (self->client))); else if (self->browser_failed) - fail_all_pending_tasks (self, G_IO_ERROR, G_IO_ERROR_FAILED, - "Avahi browser error: %s", + fail_all_pending_tasks (self, G_IO_ERROR, G_IO_ERROR_FAILED, "Avahi browser error: %s", avahi_strerror (avahi_client_errno (self->client))); else if (g_cancellable_is_cancelled (self->avahi_cancellable)) fail_all_pending_tasks (self, G_IO_ERROR, G_IO_ERROR_CANCELLED, "Avahi service resolution cancelled."); - else if (self->browser_all_for_now && - g_hash_table_size (self->resolvers) == 0) + else if (self->browser_all_for_now && g_hash_table_size (self->resolvers) == 0) complete_all_pending_tasks (self); } /* Executed in @self->avahi_context. */ static void -client_cb (AvahiClient *client, - AvahiClientState state, - void *finder_ptr) +client_cb (AvahiClient *client, AvahiClientState state, void *finder_ptr) { /* Completing the pending tasks might drop the final reference to @self. */ - g_autoptr(OstreeRepoFinderAvahi) self = g_object_ref (finder_ptr); + g_autoptr (OstreeRepoFinderAvahi) self = g_object_ref (finder_ptr); /* self->client will be NULL if client_cb() is called from * ostree_repo_finder_avahi_start(). */ g_assert (self->client == NULL || g_main_context_is_owner (self->avahi_context)); - g_debug ("%s: Entered state ‘%s’.", - G_STRFUNC, ostree_avahi_client_state_to_string (state)); + g_debug ("%s: Entered state ‘%s’.", G_STRFUNC, ostree_avahi_client_state_to_string (state)); /* We only care about entering and leaving %AVAHI_CLIENT_FAILURE. */ self->client_state = state; @@ -1052,29 +1014,20 @@ client_cb (AvahiClient *client, /* Executed in @self->avahi_context. */ static void -resolve_cb (AvahiServiceResolver *resolver, - AvahiIfIndex interface, - AvahiProtocol protocol, - AvahiResolverEvent event, - const char *name, - const char *type, - const char *domain, - const char *host_name, - const AvahiAddress *address, - uint16_t port, - AvahiStringList *txt, - AvahiLookupResultFlags flags, - void *finder_ptr) +resolve_cb (AvahiServiceResolver *resolver, AvahiIfIndex interface, AvahiProtocol protocol, + AvahiResolverEvent event, const char *name, const char *type, const char *domain, + const char *host_name, const AvahiAddress *address, uint16_t port, AvahiStringList *txt, + AvahiLookupResultFlags flags, void *finder_ptr) { /* Completing the pending tasks might drop the final reference to @self. */ - g_autoptr(OstreeRepoFinderAvahi) self = g_object_ref (finder_ptr); - g_autoptr(OstreeAvahiService) service = NULL; + g_autoptr (OstreeRepoFinderAvahi) self = g_object_ref (finder_ptr); + g_autoptr (OstreeAvahiService) service = NULL; GPtrArray *resolvers; g_assert (g_main_context_is_owner (self->avahi_context)); - g_debug ("%s: Resolve event ‘%s’ for name ‘%s’.", - G_STRFUNC, ostree_avahi_resolver_event_to_string (event), name); + g_debug ("%s: Resolve event ‘%s’ for name ‘%s’.", G_STRFUNC, + ostree_avahi_resolver_event_to_string (event), name); /* Track the resolvers active for this @name. There may be several, * as @name might appear to us over several interfaces or protocols. Most @@ -1100,8 +1053,7 @@ resolve_cb (AvahiServiceResolver *resolver, switch (event) { case AVAHI_RESOLVER_FOUND: - service = ostree_avahi_service_new (name, domain, address, interface, - port, txt); + service = ostree_avahi_service_new (name, domain, address, interface, port, txt); g_ptr_array_add (self->found_services, g_steal_pointer (&service)); break; case AVAHI_RESOLVER_FAILURE: @@ -1116,28 +1068,16 @@ resolve_cb (AvahiServiceResolver *resolver, /* Executed in @self->avahi_context. */ static void -browse_new (OstreeRepoFinderAvahi *self, - AvahiIfIndex interface, - AvahiProtocol protocol, - const gchar *name, - const gchar *type, - const gchar *domain) +browse_new (OstreeRepoFinderAvahi *self, AvahiIfIndex interface, AvahiProtocol protocol, + const gchar *name, const gchar *type, const gchar *domain) { - g_autoptr(AvahiServiceResolver) resolver = NULL; - GPtrArray *resolvers; /* (element-type AvahiServiceResolver) */ + g_autoptr (AvahiServiceResolver) resolver = NULL; + GPtrArray *resolvers; /* (element-type AvahiServiceResolver) */ g_assert (g_main_context_is_owner (self->avahi_context)); - resolver = avahi_service_resolver_new (self->client, - interface, - protocol, - name, - type, - domain, - AVAHI_PROTO_UNSPEC, - 0, - resolve_cb, - self); + resolver = avahi_service_resolver_new (self->client, interface, protocol, name, type, domain, + AVAHI_PROTO_UNSPEC, 0, resolve_cb, self); if (resolver == NULL) { g_warning ("Failed to resolve service ‘%s’: %s", name, @@ -1146,15 +1086,15 @@ browse_new (OstreeRepoFinderAvahi *self, } g_debug ("Found name service %s on the network; type: %s, domain: %s, " - "protocol: %u, interface: %u", name, type, domain, protocol, - interface); + "protocol: %u, interface: %u", + name, type, domain, protocol, interface); /* Start a resolver for this (interface, protocol, name, type, domain) * combination. */ resolvers = g_hash_table_lookup (self->resolvers, name); if (resolvers == NULL) { - resolvers = g_ptr_array_new_with_free_func ((GDestroyNotify) avahi_service_resolver_free); + resolvers = g_ptr_array_new_with_free_func ((GDestroyNotify)avahi_service_resolver_free); g_hash_table_insert (self->resolvers, g_strdup (name), resolvers); } @@ -1163,8 +1103,7 @@ browse_new (OstreeRepoFinderAvahi *self, /* Executed in @self->avahi_context. Caller must call maybe_complete_all_pending_tasks(). */ static void -browse_remove (OstreeRepoFinderAvahi *self, - const char *name) +browse_remove (OstreeRepoFinderAvahi *self, const char *name) { gsize i; gboolean removed = FALSE; @@ -1190,23 +1129,17 @@ browse_remove (OstreeRepoFinderAvahi *self, /* Executed in @self->avahi_context. */ static void -browse_cb (AvahiServiceBrowser *browser, - AvahiIfIndex interface, - AvahiProtocol protocol, - AvahiBrowserEvent event, - const char *name, - const char *type, - const char *domain, - AvahiLookupResultFlags flags, - void *finder_ptr) +browse_cb (AvahiServiceBrowser *browser, AvahiIfIndex interface, AvahiProtocol protocol, + AvahiBrowserEvent event, const char *name, const char *type, const char *domain, + AvahiLookupResultFlags flags, void *finder_ptr) { /* Completing the pending tasks might drop the final reference to @self. */ - g_autoptr(OstreeRepoFinderAvahi) self = g_object_ref (finder_ptr); + g_autoptr (OstreeRepoFinderAvahi) self = g_object_ref (finder_ptr); g_assert (g_main_context_is_owner (self->avahi_context)); - g_debug ("%s: Browse event ‘%s’ for name ‘%s’.", - G_STRFUNC, ostree_avahi_browser_event_to_string (event), name); + g_debug ("%s: Browse event ‘%s’ for name ‘%s’.", G_STRFUNC, + ostree_avahi_browser_event_to_string (event), name); self->browser_failed = FALSE; @@ -1242,18 +1175,16 @@ browse_cb (AvahiServiceBrowser *browser, } static gboolean add_resolve_task_cb (gpointer user_data); -#endif /* HAVE_AVAHI */ +#endif /* HAVE_AVAHI */ static void -ostree_repo_finder_avahi_resolve_async (OstreeRepoFinder *finder, - const OstreeCollectionRef * const *refs, - OstreeRepo *parent_repo, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +ostree_repo_finder_avahi_resolve_async (OstreeRepoFinder *finder, + const OstreeCollectionRef *const *refs, + OstreeRepo *parent_repo, GCancellable *cancellable, + GAsyncReadyCallback callback, gpointer user_data) { OstreeRepoFinderAvahi *self = OSTREE_REPO_FINDER_AVAHI (finder); - g_autoptr(GTask) task = NULL; + g_autoptr (GTask) task = NULL; g_debug ("%s: Starting resolving", G_STRFUNC); @@ -1261,14 +1192,15 @@ ostree_repo_finder_avahi_resolve_async (OstreeRepoFinder *finde g_task_set_source_tag (task, ostree_repo_finder_avahi_resolve_async); #ifdef HAVE_AVAHI - g_task_set_task_data (task, resolve_data_new (refs, parent_repo), (GDestroyNotify) resolve_data_free); + g_task_set_task_data (task, resolve_data_new (refs, parent_repo), + (GDestroyNotify)resolve_data_free); /* Move @task to the @avahi_context where it can be processed. */ g_main_context_invoke (self->avahi_context, add_resolve_task_cb, g_steal_pointer (&task)); #else /* if !HAVE_AVAHI */ g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Avahi support was not compiled in to libostree"); -#endif /* !HAVE_AVAHI */ +#endif /* !HAVE_AVAHI */ } #ifdef HAVE_AVAHI @@ -1276,7 +1208,7 @@ ostree_repo_finder_avahi_resolve_async (OstreeRepoFinder *finde static gboolean add_resolve_task_cb (gpointer user_data) { - g_autoptr(GTask) task = G_TASK (user_data); + g_autoptr (GTask) task = G_TASK (user_data); OstreeRepoFinderAvahi *self = g_task_get_source_object (task); g_assert (g_main_context_is_owner (self->avahi_context)); @@ -1289,12 +1221,11 @@ add_resolve_task_cb (gpointer user_data) return G_SOURCE_REMOVE; } -#endif /* HAVE_AVAHI */ +#endif /* HAVE_AVAHI */ static GPtrArray * -ostree_repo_finder_avahi_resolve_finish (OstreeRepoFinder *finder, - GAsyncResult *result, - GError **error) +ostree_repo_finder_avahi_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); @@ -1318,7 +1249,7 @@ ostree_repo_finder_avahi_dispose (GObject *obj) g_clear_pointer (&self->found_services, g_ptr_array_unref); g_clear_pointer (&self->resolvers, g_hash_table_unref); g_clear_object (&self->avahi_cancellable); -#endif /* HAVE_AVAHI */ +#endif /* HAVE_AVAHI */ /* Chain up. */ G_OBJECT_CLASS (ostree_repo_finder_avahi_parent_class)->dispose (obj); @@ -1343,12 +1274,13 @@ static void ostree_repo_finder_avahi_init (OstreeRepoFinderAvahi *self) { #ifdef HAVE_AVAHI - self->resolve_tasks = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); + self->resolve_tasks = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref); self->avahi_cancellable = g_cancellable_new (); self->client_state = AVAHI_CLIENT_S_REGISTERING; - self->resolvers = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_ptr_array_unref); - self->found_services = g_ptr_array_new_with_free_func ((GDestroyNotify) ostree_avahi_service_free); -#endif /* HAVE_AVAHI */ + self->resolvers + = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_ptr_array_unref); + self->found_services = g_ptr_array_new_with_free_func ((GDestroyNotify)ostree_avahi_service_free); +#endif /* HAVE_AVAHI */ } /** @@ -1372,7 +1304,7 @@ ostree_repo_finder_avahi_init (OstreeRepoFinderAvahi *self) OstreeRepoFinderAvahi * ostree_repo_finder_avahi_new (GMainContext *context) { - g_autoptr(OstreeRepoFinderAvahi) finder = NULL; + g_autoptr (OstreeRepoFinderAvahi) finder = NULL; finder = g_object_new (OSTREE_TYPE_REPO_FINDER_AVAHI, NULL); @@ -1389,7 +1321,7 @@ ostree_repo_finder_avahi_new (GMainContext *context) * *also* use Avahi API itself. */ avahi_set_allocator (avahi_glib_allocator ()); finder->poll = avahi_glib_poll_new (finder->avahi_context, G_PRIORITY_DEFAULT); -#endif /* HAVE_AVAHI */ +#endif /* HAVE_AVAHI */ return g_steal_pointer (&finder); } @@ -1419,15 +1351,14 @@ ostree_repo_finder_avahi_new (GMainContext *context) * Since: 2018.6 */ void -ostree_repo_finder_avahi_start (OstreeRepoFinderAvahi *self, - GError **error) +ostree_repo_finder_avahi_start (OstreeRepoFinderAvahi *self, GError **error) { g_return_if_fail (OSTREE_IS_REPO_FINDER_AVAHI (self)); g_return_if_fail (error == NULL || *error == NULL); #ifdef HAVE_AVAHI - g_autoptr(AvahiClient) client = NULL; - g_autoptr(AvahiServiceBrowser) browser = NULL; + g_autoptr (AvahiClient) client = NULL; + g_autoptr (AvahiServiceBrowser) browser = NULL; int failure = 0; if (g_cancellable_set_error_if_cancelled (self->avahi_cancellable, error)) @@ -1435,37 +1366,27 @@ ostree_repo_finder_avahi_start (OstreeRepoFinderAvahi *self, g_assert (self->client == NULL); - client = avahi_client_new (avahi_glib_poll_get (self->poll), 0, - client_cb, self, &failure); + client = avahi_client_new (avahi_glib_poll_get (self->poll), 0, client_cb, self, &failure); if (client == NULL) { if (failure == AVAHI_ERR_NO_DAEMON) - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "Avahi daemon is not running: %s", + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Avahi daemon is not running: %s", avahi_strerror (failure)); else - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Failed to create finder client: %s", + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to create finder client: %s", avahi_strerror (failure)); return; } /* Query for the OSTree DNS-SD service on the local network. */ - browser = avahi_service_browser_new (client, - AVAHI_IF_UNSPEC, - AVAHI_PROTO_UNSPEC, - OSTREE_AVAHI_SERVICE_TYPE, - NULL, - 0, - browse_cb, - self); + browser = avahi_service_browser_new (client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, + OSTREE_AVAHI_SERVICE_TYPE, NULL, 0, browse_cb, self); if (browser == NULL) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Failed to create service browser: %s", + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to create service browser: %s", avahi_strerror (avahi_client_errno (client))); return; } @@ -1476,12 +1397,12 @@ ostree_repo_finder_avahi_start (OstreeRepoFinderAvahi *self, #else /* if !HAVE_AVAHI */ g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Avahi support was not compiled in to libostree"); -#endif /* !HAVE_AVAHI */ +#endif /* !HAVE_AVAHI */ } #ifdef HAVE_AVAHI static gboolean stop_cb (gpointer user_data); -#endif /* HAVE_AVAHI */ +#endif /* HAVE_AVAHI */ /** * ostree_repo_finder_avahi_stop: @@ -1509,14 +1430,14 @@ ostree_repo_finder_avahi_stop (OstreeRepoFinderAvahi *self) return; g_main_context_invoke (self->avahi_context, stop_cb, g_object_ref (self)); -#endif /* HAVE_AVAHI */ +#endif /* HAVE_AVAHI */ } #ifdef HAVE_AVAHI static gboolean stop_cb (gpointer user_data) { - g_autoptr(OstreeRepoFinderAvahi) self = OSTREE_REPO_FINDER_AVAHI (user_data); + g_autoptr (OstreeRepoFinderAvahi) self = OSTREE_REPO_FINDER_AVAHI (user_data); g_cancellable_cancel (self->avahi_cancellable); maybe_complete_all_pending_tasks (self); @@ -1527,4 +1448,4 @@ stop_cb (gpointer user_data) return G_SOURCE_REMOVE; } -#endif /* HAVE_AVAHI */ +#endif /* HAVE_AVAHI */ diff --git a/src/libostree/ostree-repo-finder-avahi.h b/src/libostree/ostree-repo-finder-avahi.h index 92b15f22..3885df6e 100644 --- a/src/libostree/ostree-repo-finder-avahi.h +++ b/src/libostree/ostree-repo-finder-avahi.h @@ -23,8 +23,8 @@ #pragma once #include -#include #include +#include #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 diff --git a/src/libostree/ostree-repo-finder-config.c b/src/libostree/ostree-repo-finder-config.c index 9cee8a98..a907dc3d 100644 --- a/src/libostree/ostree-repo-finder-config.c +++ b/src/libostree/ostree-repo-finder-config.c @@ -24,16 +24,16 @@ #include #include -#include #include +#include #include #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); diff --git a/src/libostree/ostree-repo-finder-config.h b/src/libostree/ostree-repo-finder-config.h index 2ba10418..4570e5f4 100644 --- a/src/libostree/ostree-repo-finder-config.h +++ b/src/libostree/ostree-repo-finder-config.h @@ -23,8 +23,8 @@ #pragma once #include -#include #include +#include #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 diff --git a/src/libostree/ostree-repo-finder-mount.c b/src/libostree/ostree-repo-finder-mount.c index 628c53c0..19583090 100644 --- a/src/libostree/ostree-repo-finder-mount.c +++ b/src/libostree/ostree-repo-finder-mount.c @@ -24,16 +24,16 @@ #include #include -#include #include +#include #include #include #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/**/ ObjectList; +typedef GList /**/ 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); } diff --git a/src/libostree/ostree-repo-finder-mount.h b/src/libostree/ostree-repo-finder-mount.h index d0403388..1ba7851a 100644 --- a/src/libostree/ostree-repo-finder-mount.h +++ b/src/libostree/ostree-repo-finder-mount.h @@ -23,8 +23,8 @@ #pragma once #include -#include #include +#include #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 diff --git a/src/libostree/ostree-repo-finder-override.c b/src/libostree/ostree-repo-finder-override.c index c2af9fc3..29308a99 100644 --- a/src/libostree/ostree-repo-finder-override.c +++ b/src/libostree/ostree-repo-finder-override.c @@ -24,16 +24,16 @@ #include #include -#include #include +#include #include #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); diff --git a/src/libostree/ostree-repo-finder-override.h b/src/libostree/ostree-repo-finder-override.h index 1e18a8f3..978dc508 100644 --- a/src/libostree/ostree-repo-finder-override.h +++ b/src/libostree/ostree-repo-finder-override.h @@ -23,8 +23,8 @@ #pragma once #include -#include #include +#include #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 diff --git a/src/libostree/ostree-repo-finder.c b/src/libostree/ostree-repo-finder.c index aff6d6c5..2f1af1c1 100644 --- a/src/libostree/ostree-repo-finder.c +++ b/src/libostree/ostree-repo-finder.c @@ -23,8 +23,8 @@ #include "config.h" #include -#include #include +#include #include #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); } diff --git a/src/libostree/ostree-repo-finder.h b/src/libostree/ostree-repo-finder.h index 0737b85e..f5878480 100644 --- a/src/libostree/ostree-repo-finder.h +++ b/src/libostree/ostree-repo-finder.h @@ -23,8 +23,8 @@ #pragma once #include -#include #include +#include #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); diff --git a/src/libostree/ostree-repo-libarchive.c b/src/libostree/ostree-repo-libarchive.c index 89cae2c1..d0f46883 100644 --- a/src/libostree/ostree-repo-libarchive.c +++ b/src/libostree/ostree-repo-libarchive.c @@ -21,15 +21,15 @@ #include "config.h" -#include "otutil.h" -#include "ostree.h" #include "ostree-core-private.h" #include "ostree-repo-private.h" +#include "ostree.h" +#include "otutil.h" #ifdef HAVE_LIBARCHIVE +#include "ostree-libarchive-input-stream.h" #include #include -#include "ostree-libarchive-input-stream.h" #endif #include "otutil.h" @@ -39,16 +39,13 @@ #define DEFAULT_DIRMODE (0755 | S_IFDIR) static void -propagate_libarchive_error (GError **error, - struct archive *a) +propagate_libarchive_error (GError **error, struct archive *a) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "%s", archive_error_string (a)); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s", archive_error_string (a)); } static const char * -path_relative (const char *src, - GError **error) +path_relative (const char *src, GError **error) { /* One issue here is that some archives almost record the pathname as just a * string and don't need to actually encode parent/child relationships in the @@ -92,8 +89,7 @@ path_relative (const char *src, } static char * -path_relative_ostree (const char *path, - GError **error) +path_relative_ostree (const char *path, GError **error) { path = path_relative (path, error); if (path == NULL) @@ -106,8 +102,7 @@ path_relative_ostree (const char *path, } static void -append_path_component (char **path_builder, - const char *component) +append_path_component (char **path_builder, const char *component) { g_autofree char *s = g_steal_pointer (path_builder); *path_builder = g_build_filename (s ?: "/", component, NULL); @@ -127,8 +122,7 @@ squash_trailing_slashes (char *path) * Yes, this hack will work even if it's a hardlink to a symlink. */ static void -read_archive_entry_stat (struct archive_entry *entry, - struct stat *stbuf) +read_archive_entry_stat (struct archive_entry *entry, struct stat *stbuf) { const struct stat *st = archive_entry_stat (entry); @@ -144,57 +138,44 @@ file_info_from_archive_entry (struct archive_entry *entry) struct stat stbuf; read_archive_entry_stat (entry, &stbuf); - g_autoptr(GFileInfo) info = _ostree_stbuf_to_gfileinfo (&stbuf); + g_autoptr (GFileInfo) info = _ostree_stbuf_to_gfileinfo (&stbuf); if (S_ISLNK (stbuf.st_mode)) { const char *target = archive_entry_symlink (entry); if (target != NULL) - g_file_info_set_attribute_byte_string (info, "standard::symlink-target", - target); + g_file_info_set_attribute_byte_string (info, "standard::symlink-target", target); } return g_steal_pointer (&info); } static gboolean -builder_add_label (GVariantBuilder *builder, - OstreeSePolicy *sepolicy, - const char *path, - mode_t mode, - GCancellable *cancellable, - GError **error) +builder_add_label (GVariantBuilder *builder, OstreeSePolicy *sepolicy, const char *path, + mode_t mode, GCancellable *cancellable, GError **error) { g_autofree char *label = NULL; if (!sepolicy) return TRUE; - if (!ostree_sepolicy_get_label (sepolicy, path, mode, &label, - cancellable, error)) + if (!ostree_sepolicy_get_label (sepolicy, path, mode, &label, cancellable, error)) return FALSE; if (label) - g_variant_builder_add (builder, "(@ay@ay)", - g_variant_new_bytestring ("security.selinux"), + g_variant_builder_add (builder, "(@ay@ay)", g_variant_new_bytestring ("security.selinux"), g_variant_new_bytestring (label)); return TRUE; } - /* Like ostree_mutable_tree_ensure_dir(), but also creates and sets dirmeta if * the dir has to be created. */ static gboolean -mtree_ensure_dir_with_meta (OstreeRepo *repo, - OstreeMutableTree *parent, - const char *name, - GFileInfo *file_info, - GVariant *xattrs, - gboolean error_if_exist, /* XXX: remove if not needed */ - OstreeMutableTree **out_dir, - GCancellable *cancellable, - GError **error) +mtree_ensure_dir_with_meta (OstreeRepo *repo, OstreeMutableTree *parent, const char *name, + GFileInfo *file_info, GVariant *xattrs, + gboolean error_if_exist, /* XXX: remove if not needed */ + OstreeMutableTree **out_dir, GCancellable *cancellable, GError **error) { - g_autoptr(OstreeMutableTree) dir = NULL; + g_autoptr (OstreeMutableTree) dir = NULL; g_autofree guchar *csum_raw = NULL; g_autofree char *csum = NULL; @@ -204,8 +185,8 @@ mtree_ensure_dir_with_meta (OstreeRepo *repo, { if (error_if_exist) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Directory \"%s\" already exists", name); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Directory \"%s\" already exists", + name); return FALSE; } } @@ -221,8 +202,7 @@ mtree_ensure_dir_with_meta (OstreeRepo *repo, return FALSE; } - if (!_ostree_repo_write_directory_meta (repo, file_info, xattrs, - &csum_raw, cancellable, error)) + if (!_ostree_repo_write_directory_meta (repo, file_info, xattrs, &csum_raw, cancellable, error)) return FALSE; csum = ostree_checksum_from_bytes (csum_raw); @@ -235,26 +215,26 @@ mtree_ensure_dir_with_meta (OstreeRepo *repo, return TRUE; } -typedef struct { - OstreeRepo *repo; +typedef struct +{ + OstreeRepo *repo; OstreeRepoImportArchiveOptions *opts; - OstreeMutableTree *root; - struct archive *archive; - struct archive_entry *entry; - GHashTable *deferred_hardlinks; - OstreeRepoCommitModifier *modifier; + OstreeMutableTree *root; + struct archive *archive; + struct archive_entry *entry; + GHashTable *deferred_hardlinks; + OstreeRepoCommitModifier *modifier; } OstreeRepoArchiveImportContext; -typedef struct { - OstreeMutableTree *parent; - char *path; - guint64 size; +typedef struct +{ + OstreeMutableTree *parent; + char *path; + guint64 size; } DeferredHardlink; -static inline char* -aic_get_final_path (OstreeRepoArchiveImportContext *ctx, - const char *path, - GError **error) +static inline char * +aic_get_final_path (OstreeRepoArchiveImportContext *ctx, const char *path, GError **error) { if (ctx->opts->translate_pathname) { @@ -272,9 +252,8 @@ aic_get_final_path (OstreeRepoArchiveImportContext *ctx, return g_strdup (path_relative (path, error)); } -static inline char* -aic_get_final_entry_pathname (OstreeRepoArchiveImportContext *ctx, - GError **error) +static inline char * +aic_get_final_entry_pathname (OstreeRepoArchiveImportContext *ctx, GError **error) { const char *pathname = archive_entry_pathname (ctx->entry); g_autofree char *final = aic_get_final_path (ctx, pathname, error); @@ -286,7 +265,7 @@ aic_get_final_entry_pathname (OstreeRepoArchiveImportContext *ctx, return g_steal_pointer (&final); } -static inline char* +static inline char * aic_get_final_entry_hardlink (OstreeRepoArchiveImportContext *ctx) { GError *local_error = NULL; @@ -306,11 +285,10 @@ aic_get_final_entry_hardlink (OstreeRepoArchiveImportContext *ctx) } static OstreeRepoCommitFilterResult -aic_apply_modifier_filter (OstreeRepoArchiveImportContext *ctx, - const char *relpath, - GFileInfo **out_file_info) +aic_apply_modifier_filter (OstreeRepoArchiveImportContext *ctx, const char *relpath, + GFileInfo **out_file_info) { - g_autoptr(GFileInfo) file_info = NULL; + g_autoptr (GFileInfo) file_info = NULL; g_autofree char *abspath = NULL; const char *cb_path = NULL; @@ -325,48 +303,40 @@ aic_apply_modifier_filter (OstreeRepoArchiveImportContext *ctx, file_info = file_info_from_archive_entry (ctx->entry); - return _ostree_repo_commit_modifier_apply (ctx->repo, ctx->modifier, cb_path, - file_info, out_file_info); + return _ostree_repo_commit_modifier_apply (ctx->repo, ctx->modifier, cb_path, file_info, + out_file_info); } static gboolean aic_ensure_parent_dir_with_file_info (OstreeRepoArchiveImportContext *ctx, - OstreeMutableTree *parent, - const char *fullpath, - GFileInfo *file_info, - OstreeMutableTree **out_dir, - GCancellable *cancellable, - GError **error) + OstreeMutableTree *parent, const char *fullpath, + GFileInfo *file_info, OstreeMutableTree **out_dir, + GCancellable *cancellable, GError **error) { const char *name = glnx_basename (fullpath); - g_auto(GVariantBuilder) xattrs_builder; - g_autoptr(GVariant) xattrs = NULL; + g_auto (GVariantBuilder) xattrs_builder; + g_autoptr (GVariant) xattrs = NULL; /* is this the root directory itself? transform into empty string */ if (name[0] == '/' && name[1] == '\0') name++; - g_variant_builder_init (&xattrs_builder, (GVariantType*)"a(ayay)"); + g_variant_builder_init (&xattrs_builder, (GVariantType *)"a(ayay)"); if (ctx->modifier && ctx->modifier->sepolicy) - if (!builder_add_label (&xattrs_builder, ctx->modifier->sepolicy, fullpath, - DEFAULT_DIRMODE, cancellable, error)) + if (!builder_add_label (&xattrs_builder, ctx->modifier->sepolicy, fullpath, DEFAULT_DIRMODE, + cancellable, error)) return FALSE; xattrs = g_variant_ref_sink (g_variant_builder_end (&xattrs_builder)); - return mtree_ensure_dir_with_meta (ctx->repo, parent, name, file_info, - xattrs, - FALSE /* error_if_exist */, out_dir, - cancellable, error); + return mtree_ensure_dir_with_meta (ctx->repo, parent, name, file_info, xattrs, + FALSE /* error_if_exist */, out_dir, cancellable, error); } static gboolean -aic_ensure_parent_dir (OstreeRepoArchiveImportContext *ctx, - OstreeMutableTree *parent, - const char *fullpath, - OstreeMutableTree **out_dir, - GCancellable *cancellable, - GError **error) +aic_ensure_parent_dir (OstreeRepoArchiveImportContext *ctx, OstreeMutableTree *parent, + const char *fullpath, OstreeMutableTree **out_dir, GCancellable *cancellable, + GError **error) { GLNX_AUTO_PREFIX_ERROR ("ostree-tar: Failed to create parent", error); /* Who should own the parent dir? Since it's not in the archive, it's up to @@ -382,31 +352,27 @@ aic_ensure_parent_dir (OstreeRepoArchiveImportContext *ctx, g_file_info_set_attribute_uint32 (file_info, "unix::gid", gid); g_file_info_set_attribute_uint32 (file_info, "unix::mode", DEFAULT_DIRMODE); - return aic_ensure_parent_dir_with_file_info (ctx, parent, fullpath, file_info, - out_dir, cancellable, error); + return aic_ensure_parent_dir_with_file_info (ctx, parent, fullpath, file_info, out_dir, + cancellable, error); } static gboolean -aic_create_parent_dirs (OstreeRepoArchiveImportContext *ctx, - GPtrArray *components, - OstreeMutableTree **out_subdir, - GCancellable *cancellable, - GError **error) +aic_create_parent_dirs (OstreeRepoArchiveImportContext *ctx, GPtrArray *components, + OstreeMutableTree **out_subdir, GCancellable *cancellable, GError **error) { g_autofree char *fullpath = NULL; - g_autoptr(OstreeMutableTree) dir = NULL; + g_autoptr (OstreeMutableTree) dir = NULL; /* start with the root itself */ if (!aic_ensure_parent_dir (ctx, ctx->root, "/", &dir, cancellable, error)) return FALSE; - for (guint i = 0; i < components->len-1; i++) + for (guint i = 0; i < components->len - 1; i++) { - glnx_unref_object OstreeMutableTree *subdir = NULL; + glnx_unref_object OstreeMutableTree *subdir = NULL; append_path_component (&fullpath, components->pdata[i]); - if (!aic_ensure_parent_dir (ctx, dir, fullpath, &subdir, - cancellable, error)) + if (!aic_ensure_parent_dir (ctx, dir, fullpath, &subdir, cancellable, error)) return FALSE; g_set_object (&dir, subdir); @@ -417,13 +383,10 @@ aic_create_parent_dirs (OstreeRepoArchiveImportContext *ctx, } static gboolean -aic_get_parent_dir (OstreeRepoArchiveImportContext *ctx, - const char *path, - OstreeMutableTree **out_dir, - GCancellable *cancellable, - GError **error) +aic_get_parent_dir (OstreeRepoArchiveImportContext *ctx, const char *path, + OstreeMutableTree **out_dir, GCancellable *cancellable, GError **error) { - g_autoptr(GPtrArray) components = NULL; + g_autoptr (GPtrArray) components = NULL; if (!ot_util_path_split_validate (path, &components, error)) return FALSE; @@ -442,28 +405,23 @@ aic_get_parent_dir (OstreeRepoArchiveImportContext *ctx, if (ctx->opts->autocreate_parents) { g_clear_error (error); - return aic_create_parent_dirs (ctx, components, out_dir, - cancellable, error); + return aic_create_parent_dirs (ctx, components, out_dir, cancellable, error); } return FALSE; } static gboolean -aic_get_xattrs (OstreeRepoArchiveImportContext *ctx, - const char *path, - GFileInfo *file_info, - GVariant **out_xattrs, - GCancellable *cancellable, - GError **error) +aic_get_xattrs (OstreeRepoArchiveImportContext *ctx, const char *path, GFileInfo *file_info, + GVariant **out_xattrs, GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("ostree-tar: Failed to get xattrs", error); g_autofree char *abspath = g_build_filename ("/", path, NULL); - g_autoptr(GVariant) xattrs = NULL; + g_autoptr (GVariant) xattrs = NULL; const char *cb_path = abspath; - gboolean no_xattrs = ctx->modifier && - ctx->modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS; + gboolean no_xattrs + = ctx->modifier && ctx->modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS; if (!no_xattrs && archive_entry_xattr_count (ctx->entry) > 0) { @@ -471,18 +429,14 @@ aic_get_xattrs (OstreeRepoArchiveImportContext *ctx, const void *value; size_t size; - g_autoptr(GVariantBuilder) builder = - ot_util_variant_builder_from_variant (xattrs, - G_VARIANT_TYPE ("a(ayay)")); + g_autoptr (GVariantBuilder) builder + = ot_util_variant_builder_from_variant (xattrs, G_VARIANT_TYPE ("a(ayay)")); archive_entry_xattr_reset (ctx->entry); - while (archive_entry_xattr_next ( - ctx->entry, &name, &value, &size) == ARCHIVE_OK) + while (archive_entry_xattr_next (ctx->entry, &name, &value, &size) == ARCHIVE_OK) { - g_variant_builder_add (builder, "(@ay@ay)", - g_variant_new_bytestring (name), - g_variant_new_fixed_array (G_VARIANT_TYPE("y"), - value, size, 1)); + g_variant_builder_add (builder, "(@ay@ay)", g_variant_new_bytestring (name), + g_variant_new_fixed_array (G_VARIANT_TYPE ("y"), value, size, 1)); } xattrs = g_variant_builder_end (builder); @@ -503,12 +457,10 @@ aic_get_xattrs (OstreeRepoArchiveImportContext *ctx, if (ctx->modifier && ctx->modifier->sepolicy) { mode_t mode = g_file_info_get_attribute_uint32 (file_info, "unix::mode"); - g_autoptr(GVariantBuilder) builder = - ot_util_variant_builder_from_variant (xattrs, G_VARIANT_TYPE - ("a(ayay)")); + g_autoptr (GVariantBuilder) builder + = ot_util_variant_builder_from_variant (xattrs, G_VARIANT_TYPE ("a(ayay)")); - if (!builder_add_label (builder, ctx->modifier->sepolicy, abspath, mode, - cancellable, error)) + if (!builder_add_label (builder, ctx->modifier->sepolicy, abspath, mode, cancellable, error)) return FALSE; if (xattrs) @@ -525,35 +477,26 @@ aic_get_xattrs (OstreeRepoArchiveImportContext *ctx, /* XXX: add option in ctx->opts to disallow already existing dirs? see * error_if_exist */ static gboolean -aic_handle_dir (OstreeRepoArchiveImportContext *ctx, - OstreeMutableTree *parent, - const char *path, - GFileInfo *fi, - GCancellable *cancellable, - GError **error) +aic_handle_dir (OstreeRepoArchiveImportContext *ctx, OstreeMutableTree *parent, const char *path, + GFileInfo *fi, GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("ostree-tar: Failed to handle directory", error); const char *name = glnx_basename (path); - g_autoptr(GVariant) xattrs = NULL; + g_autoptr (GVariant) xattrs = NULL; if (!aic_get_xattrs (ctx, path, fi, &xattrs, cancellable, error)) return FALSE; return mtree_ensure_dir_with_meta (ctx->repo, parent, name, fi, xattrs, - FALSE /* error_if_exist */, NULL, - cancellable, error); + FALSE /* error_if_exist */, NULL, cancellable, error); } static gboolean -aic_write_file (OstreeRepoArchiveImportContext *ctx, - GFileInfo *fi, - GVariant *xattrs, - char **out_csum, - GCancellable *cancellable, - GError **error) +aic_write_file (OstreeRepoArchiveImportContext *ctx, GFileInfo *fi, GVariant *xattrs, + char **out_csum, GCancellable *cancellable, GError **error) { - g_autoptr(GInputStream) archive_stream = NULL; - g_autoptr(GInputStream) file_object_input = NULL; + g_autoptr (GInputStream) archive_stream = NULL; + g_autoptr (GInputStream) file_object_input = NULL; guint64 length; g_autofree guchar *csum_raw = NULL; @@ -561,13 +504,12 @@ aic_write_file (OstreeRepoArchiveImportContext *ctx, if (g_file_info_get_file_type (fi) == G_FILE_TYPE_REGULAR) archive_stream = _ostree_libarchive_input_stream_new (ctx->archive); - if (!ostree_raw_file_to_content_stream (archive_stream, fi, xattrs, - &file_object_input, &length, + if (!ostree_raw_file_to_content_stream (archive_stream, fi, xattrs, &file_object_input, &length, cancellable, error)) return FALSE; - if (!ostree_repo_write_content (ctx->repo, NULL, file_object_input, length, - &csum_raw, cancellable, error)) + if (!ostree_repo_write_content (ctx->repo, NULL, file_object_input, length, &csum_raw, + cancellable, error)) return FALSE; *out_csum = ostree_checksum_from_bytes (csum_raw); @@ -575,16 +517,12 @@ aic_write_file (OstreeRepoArchiveImportContext *ctx, } static gboolean -aic_import_file (OstreeRepoArchiveImportContext *ctx, - OstreeMutableTree *parent, - const char *path, - GFileInfo *fi, - GCancellable *cancellable, - GError **error) +aic_import_file (OstreeRepoArchiveImportContext *ctx, OstreeMutableTree *parent, const char *path, + GFileInfo *fi, GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("ostree-tar: Failed to import file", error); const char *name = glnx_basename (path); - g_autoptr(GVariant) xattrs = NULL; + g_autoptr (GVariant) xattrs = NULL; g_autofree char *csum = NULL; if (!aic_get_xattrs (ctx, path, fi, &xattrs, cancellable, error)) @@ -600,9 +538,8 @@ aic_import_file (OstreeRepoArchiveImportContext *ctx, } static void -aic_add_deferred_hardlink (OstreeRepoArchiveImportContext *ctx, - const char *hardlink, - DeferredHardlink *dh) +aic_add_deferred_hardlink (OstreeRepoArchiveImportContext *ctx, const char *hardlink, + DeferredHardlink *dh) { gboolean new_slist; GSList *slist; @@ -617,11 +554,8 @@ aic_add_deferred_hardlink (OstreeRepoArchiveImportContext *ctx, } static void -aic_defer_hardlink (OstreeRepoArchiveImportContext *ctx, - OstreeMutableTree *parent, - const char *path, - guint64 size, - const char *hardlink) +aic_defer_hardlink (OstreeRepoArchiveImportContext *ctx, OstreeMutableTree *parent, + const char *path, guint64 size, const char *hardlink) { DeferredHardlink *dh = g_slice_new (DeferredHardlink); dh->parent = g_object_ref (parent); @@ -632,12 +566,8 @@ aic_defer_hardlink (OstreeRepoArchiveImportContext *ctx, } static gboolean -aic_handle_file (OstreeRepoArchiveImportContext *ctx, - OstreeMutableTree *parent, - const char *path, - GFileInfo *fi, - GCancellable *cancellable, - GError **error) +aic_handle_file (OstreeRepoArchiveImportContext *ctx, OstreeMutableTree *parent, const char *path, + GFileInfo *fi, GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("ostree-tar: Failed to handle file", error); /* The wonderful world of hardlinks and archives. We have to be very careful @@ -667,12 +597,8 @@ aic_handle_file (OstreeRepoArchiveImportContext *ctx, } static gboolean -aic_handle_entry (OstreeRepoArchiveImportContext *ctx, - OstreeMutableTree *parent, - const char *path, - GFileInfo *fi, - GCancellable *cancellable, - GError **error) +aic_handle_entry (OstreeRepoArchiveImportContext *ctx, OstreeMutableTree *parent, const char *path, + GFileInfo *fi, GCancellable *cancellable, GError **error) { switch (g_file_info_get_file_type (fi)) { @@ -686,28 +612,24 @@ aic_handle_entry (OstreeRepoArchiveImportContext *ctx, return TRUE; else { - return glnx_throw (error, "Unsupported file type for path \"%s\"", - path); + return glnx_throw (error, "Unsupported file type for path \"%s\"", path); } } } static gboolean -aic_import_entry (OstreeRepoArchiveImportContext *ctx, - GCancellable *cancellable, - GError **error) +aic_import_entry (OstreeRepoArchiveImportContext *ctx, GCancellable *cancellable, GError **error) { g_autofree char *path = aic_get_final_entry_pathname (ctx, error); if (path == NULL) return FALSE; - g_autoptr(GFileInfo) fi = NULL; - if (aic_apply_modifier_filter (ctx, path, &fi) - == OSTREE_REPO_COMMIT_FILTER_SKIP) + g_autoptr (GFileInfo) fi = NULL; + if (aic_apply_modifier_filter (ctx, path, &fi) == OSTREE_REPO_COMMIT_FILTER_SKIP) return TRUE; - g_autoptr(OstreeMutableTree) parent = NULL; + g_autoptr (OstreeMutableTree) parent = NULL; if (!aic_get_parent_dir (ctx, path, &parent, cancellable, error)) return FALSE; @@ -715,16 +637,14 @@ aic_import_entry (OstreeRepoArchiveImportContext *ctx, } static gboolean -aic_import_from_hardlink (OstreeRepoArchiveImportContext *ctx, - const char *target, - DeferredHardlink *dh, - GError **error) +aic_import_from_hardlink (OstreeRepoArchiveImportContext *ctx, const char *target, + DeferredHardlink *dh, GError **error) { g_autofree char *csum = NULL; const char *name = glnx_basename (target); const char *name_dh = glnx_basename (dh->path); - g_autoptr(GPtrArray) components = NULL; - g_autoptr(OstreeMutableTree) parent = NULL; + g_autoptr (GPtrArray) components = NULL; + g_autoptr (OstreeMutableTree) parent = NULL; if (!ostree_mutable_tree_lookup (dh->parent, name_dh, &csum, NULL, error)) return FALSE; @@ -744,16 +664,14 @@ aic_import_from_hardlink (OstreeRepoArchiveImportContext *ctx, } static gboolean -aic_lookup_file_csum (OstreeRepoArchiveImportContext *ctx, - const char *target, - char **out_csum, - GError **error) +aic_lookup_file_csum (OstreeRepoArchiveImportContext *ctx, const char *target, char **out_csum, + GError **error) { g_autofree char *csum = NULL; const char *name = glnx_basename (target); - g_autoptr(OstreeMutableTree) parent = NULL; - g_autoptr(OstreeMutableTree) subdir = NULL; - g_autoptr(GPtrArray) components = NULL; + g_autoptr (OstreeMutableTree) parent = NULL; + g_autoptr (OstreeMutableTree) subdir = NULL; + g_autoptr (GPtrArray) components = NULL; if (!ot_util_path_split_validate (target, &components, error)) return FALSE; @@ -768,7 +686,8 @@ aic_lookup_file_csum (OstreeRepoArchiveImportContext *ctx, { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Expected hardlink file target at \"%s\" but found a " - "directory", target); + "directory", + target); return FALSE; } @@ -777,17 +696,15 @@ aic_lookup_file_csum (OstreeRepoArchiveImportContext *ctx, } static gboolean -aic_import_deferred_hardlinks_for (OstreeRepoArchiveImportContext *ctx, - const char *target, - GSList *hardlinks, - GError **error) +aic_import_deferred_hardlinks_for (OstreeRepoArchiveImportContext *ctx, const char *target, + GSList *hardlinks, GError **error) { GSList *payload = hardlinks; g_autofree char *csum = NULL; /* find node with the payload, if any (if none, then they're all hardlinks to * a zero sized target, and there's no rewrite required) */ - while (payload && ((DeferredHardlink*)payload->data)->size == 0) + while (payload && ((DeferredHardlink *)payload->data)->size == 0) payload = g_slist_next (payload); /* rewrite the target so it points to the csum of the payload hardlink */ @@ -815,11 +732,10 @@ aic_import_deferred_hardlinks_for (OstreeRepoArchiveImportContext *ctx, } static gboolean -aic_import_deferred_hardlinks (OstreeRepoArchiveImportContext *ctx, - GCancellable *cancellable, - GError **error) +aic_import_deferred_hardlinks (OstreeRepoArchiveImportContext *ctx, GCancellable *cancellable, + GError **error) { - GLNX_HASH_TABLE_FOREACH_KV (ctx->deferred_hardlinks, const char*, target, GSList*, links) + GLNX_HASH_TABLE_FOREACH_KV (ctx->deferred_hardlinks, const char *, target, GSList *, links) { if (!aic_import_deferred_hardlinks_for (ctx, target, links, error)) return glnx_prefix_error (error, "ostree-tar: Processing deferred hardlink %s", target); @@ -858,29 +774,23 @@ deferred_hardlinks_list_free (void *data) * file structure to @mtree. */ gboolean -ostree_repo_import_archive_to_mtree (OstreeRepo *self, - OstreeRepoImportArchiveOptions *opts, - void *archive, - OstreeMutableTree *mtree, - OstreeRepoCommitModifier *modifier, - GCancellable *cancellable, - GError **error) +ostree_repo_import_archive_to_mtree (OstreeRepo *self, OstreeRepoImportArchiveOptions *opts, + void *archive, OstreeMutableTree *mtree, + OstreeRepoCommitModifier *modifier, GCancellable *cancellable, + GError **error) { #ifdef HAVE_LIBARCHIVE gboolean ret = FALSE; struct archive *a = archive; - g_autoptr(GHashTable) deferred_hardlinks = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, - deferred_hardlinks_list_free); - - OstreeRepoArchiveImportContext aictx = { - .repo = self, - .opts = opts, - .root = mtree, - .archive = archive, - .deferred_hardlinks = deferred_hardlinks, - .modifier = modifier - }; + g_autoptr (GHashTable) deferred_hardlinks + = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, deferred_hardlinks_list_free); + + OstreeRepoArchiveImportContext aictx = { .repo = self, + .opts = opts, + .root = mtree, + .archive = archive, + .deferred_hardlinks = deferred_hardlinks, + .modifier = modifier }; _ostree_repo_setup_generate_sizes (self, modifier); @@ -910,29 +820,24 @@ ostree_repo_import_archive_to_mtree (OstreeRepo *self, * useful primarily when importing Docker image layers, which can * just be metadata. */ - if (opts->autocreate_parents && - ostree_mutable_tree_get_metadata_checksum (mtree) == NULL) + if (opts->autocreate_parents && ostree_mutable_tree_get_metadata_checksum (mtree) == NULL) { /* _ostree_stbuf_to_gfileinfo() only looks at these fields, * but we use it to ensure it sets all of the relevant GFileInfo * properties. */ - struct stat stbuf = { .st_mode = DEFAULT_DIRMODE, - .st_uid = 0, - .st_gid = 0 }; - g_autoptr(GFileInfo) fi = _ostree_stbuf_to_gfileinfo (&stbuf); + struct stat stbuf = { .st_mode = DEFAULT_DIRMODE, .st_uid = 0, .st_gid = 0 }; + g_autoptr (GFileInfo) fi = _ostree_stbuf_to_gfileinfo (&stbuf); - g_autoptr(GFileInfo) mfi = NULL; - (void)_ostree_repo_commit_modifier_apply (self, modifier, "/", - fi, &mfi); + g_autoptr (GFileInfo) mfi = NULL; + (void)_ostree_repo_commit_modifier_apply (self, modifier, "/", fi, &mfi); - if (!aic_ensure_parent_dir_with_file_info (&aictx, mtree, "/", mfi, NULL, - cancellable, error)) + if (!aic_ensure_parent_dir_with_file_info (&aictx, mtree, "/", mfi, NULL, cancellable, error)) goto out; } ret = TRUE; - out: +out: return ret; #else g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, @@ -943,20 +848,19 @@ ostree_repo_import_archive_to_mtree (OstreeRepo *self, #ifdef HAVE_LIBARCHIVE static gboolean -write_archive_to_mtree (OstreeRepo *self, - OtAutoArchiveRead *archive, - OstreeMutableTree *mtree, - OstreeRepoCommitModifier *modifier, - gboolean autocreate_parents, - GCancellable *cancellable, - GError **error) +write_archive_to_mtree (OstreeRepo *self, OtAutoArchiveRead *archive, OstreeMutableTree *mtree, + OstreeRepoCommitModifier *modifier, gboolean autocreate_parents, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; - OstreeRepoImportArchiveOptions opts = { 0, }; + OstreeRepoImportArchiveOptions opts = { + 0, + }; opts.autocreate_parents = !!autocreate_parents; - if (!ostree_repo_import_archive_to_mtree (self, &opts, archive, mtree, modifier, cancellable, error)) + if (!ostree_repo_import_archive_to_mtree (self, &opts, archive, mtree, modifier, cancellable, + error)) goto out; if (archive_read_close (archive) != ARCHIVE_OK) @@ -966,7 +870,7 @@ write_archive_to_mtree (OstreeRepo *self, } ret = TRUE; - out: +out: (void)archive_read_close (archive); return ret; } @@ -986,18 +890,15 @@ write_archive_to_mtree (OstreeRepo *self, * file structure to @mtree. */ gboolean -ostree_repo_write_archive_to_mtree (OstreeRepo *self, - GFile *archive, - OstreeMutableTree *mtree, - OstreeRepoCommitModifier *modifier, - gboolean autocreate_parents, - GCancellable *cancellable, - GError **error) +ostree_repo_write_archive_to_mtree (OstreeRepo *self, GFile *archive, OstreeMutableTree *mtree, + OstreeRepoCommitModifier *modifier, gboolean autocreate_parents, + GCancellable *cancellable, GError **error) { #ifdef HAVE_LIBARCHIVE - g_autoptr(OtAutoArchiveRead) a = ot_open_archive_read (gs_file_get_path_cached (archive), error); + g_autoptr (OtAutoArchiveRead) a = ot_open_archive_read (gs_file_get_path_cached (archive), error); if (a) - return write_archive_to_mtree (self, a, mtree, modifier, autocreate_parents, cancellable, error); + return write_archive_to_mtree (self, a, mtree, modifier, autocreate_parents, cancellable, + error); return FALSE; #else @@ -1021,18 +922,16 @@ ostree_repo_write_archive_to_mtree (OstreeRepo *self, * its file structure to @mtree. */ gboolean -ostree_repo_write_archive_to_mtree_from_fd (OstreeRepo *self, - int fd, - OstreeMutableTree *mtree, - OstreeRepoCommitModifier *modifier, - gboolean autocreate_parents, - GCancellable *cancellable, - GError **error) +ostree_repo_write_archive_to_mtree_from_fd (OstreeRepo *self, int fd, OstreeMutableTree *mtree, + OstreeRepoCommitModifier *modifier, + gboolean autocreate_parents, GCancellable *cancellable, + GError **error) { #ifdef HAVE_LIBARCHIVE - g_autoptr(OtAutoArchiveRead) a = ot_open_archive_read_fd (fd, error); + g_autoptr (OtAutoArchiveRead) a = ot_open_archive_read_fd (fd, error); if (a) - return write_archive_to_mtree (self, a, mtree, modifier, autocreate_parents, cancellable, error); + return write_archive_to_mtree (self, a, mtree, modifier, autocreate_parents, cancellable, + error); return FALSE; #else @@ -1045,17 +944,13 @@ ostree_repo_write_archive_to_mtree_from_fd (OstreeRepo *self, #ifdef HAVE_LIBARCHIVE static gboolean -file_to_archive_entry_common (GFile *root, - OstreeRepoExportArchiveOptions *opts, - GFile *path, - GFileInfo *file_info, - struct archive_entry *entry, - GError **error) +file_to_archive_entry_common (GFile *root, OstreeRepoExportArchiveOptions *opts, GFile *path, + GFileInfo *file_info, struct archive_entry *entry, GError **error) { gboolean ret = FALSE; g_autofree char *pathstr = g_file_get_relative_path (root, path); - g_autoptr(GVariant) xattrs = NULL; - time_t ts = (time_t) opts->timestamp_secs; + g_autoptr (GVariant) xattrs = NULL; + time_t ts = (time_t)opts->timestamp_secs; if (opts->path_prefix && opts->path_prefix[0]) { @@ -1077,7 +972,7 @@ file_to_archive_entry_common (GFile *root, archive_entry_set_gid (entry, g_file_info_get_attribute_uint32 (file_info, "unix::gid")); archive_entry_set_mode (entry, g_file_info_get_attribute_uint32 (file_info, "unix::mode")); - if (!ostree_repo_file_get_xattrs ((OstreeRepoFile*)path, &xattrs, NULL, error)) + if (!ostree_repo_file_get_xattrs ((OstreeRepoFile *)path, &xattrs, NULL, error)) goto out; if (!opts->disable_xattrs) @@ -1087,28 +982,25 @@ file_to_archive_entry_common (GFile *root, n = g_variant_n_children (xattrs); for (i = 0; i < n; i++) { - const guint8* name; - g_autoptr(GVariant) value = NULL; - const guint8* value_data; + const guint8 *name; + g_autoptr (GVariant) value = NULL; + const guint8 *value_data; gsize value_len; g_variant_get_child (xattrs, i, "(^&ay@ay)", &name, &value); value_data = g_variant_get_fixed_array (value, &value_len, 1); - archive_entry_xattr_add_entry (entry, (char*)name, - (char*) value_data, value_len); + archive_entry_xattr_add_entry (entry, (char *)name, (char *)value_data, value_len); } } ret = TRUE; - out: +out: return ret; } static gboolean -write_header_free_entry (struct archive *a, - struct archive_entry **entryp, - GError **error) +write_header_free_entry (struct archive *a, struct archive_entry **entryp, GError **error) { struct archive_entry *entry = *entryp; gboolean ret = FALSE; @@ -1120,28 +1012,23 @@ write_header_free_entry (struct archive *a, } ret = TRUE; - out: +out: archive_entry_free (entry); *entryp = NULL; return ret; } static gboolean -write_directory_to_libarchive_recurse (OstreeRepo *self, - OstreeRepoExportArchiveOptions *opts, - GFile *root, - GFile *dir, - struct archive *a, - GCancellable *cancellable, - GError **error) +write_directory_to_libarchive_recurse (OstreeRepo *self, OstreeRepoExportArchiveOptions *opts, + GFile *root, GFile *dir, struct archive *a, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; - g_autoptr(GFileInfo) dir_info = NULL; - g_autoptr(GFileEnumerator) dir_enum = NULL; + g_autoptr (GFileInfo) dir_info = NULL; + g_autoptr (GFileEnumerator) dir_enum = NULL; struct archive_entry *entry = NULL; - dir_info = g_file_query_info (dir, OSTREE_GIO_FAST_QUERYINFO, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + dir_info = g_file_query_info (dir, OSTREE_GIO_FAST_QUERYINFO, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!dir_info) goto out; @@ -1153,8 +1040,7 @@ write_directory_to_libarchive_recurse (OstreeRepo *self, goto out; dir_enum = g_file_enumerate_children (dir, 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; @@ -1163,8 +1049,7 @@ write_directory_to_libarchive_recurse (OstreeRepo *self, GFileInfo *file_info; GFile *path; - if (!g_file_enumerator_iterate (dir_enum, &file_info, &path, - cancellable, error)) + if (!g_file_enumerator_iterate (dir_enum, &file_info, &path, cancellable, error)) goto out; if (file_info == NULL) break; @@ -1172,8 +1057,8 @@ write_directory_to_libarchive_recurse (OstreeRepo *self, /* First, handle directories recursively */ if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY) { - if (!write_directory_to_libarchive_recurse (self, opts, root, path, a, - cancellable, error)) + if (!write_directory_to_libarchive_recurse (self, opts, root, path, a, cancellable, + error)) goto out; /* Go to the next entry */ @@ -1198,11 +1083,11 @@ write_directory_to_libarchive_recurse (OstreeRepo *self, case G_FILE_TYPE_REGULAR: { guint8 buf[8192]; - g_autoptr(GInputStream) file_in = NULL; - g_autoptr(GFileInfo) regular_file_info = NULL; + g_autoptr (GInputStream) file_in = NULL; + g_autoptr (GFileInfo) regular_file_info = NULL; const char *checksum; - checksum = ostree_repo_file_get_checksum ((OstreeRepoFile*)path); + checksum = ostree_repo_file_get_checksum ((OstreeRepoFile *)path); if (!ostree_repo_load_file (self, checksum, &file_in, ®ular_file_info, NULL, cancellable, error)) @@ -1218,18 +1103,22 @@ write_directory_to_libarchive_recurse (OstreeRepo *self, while (TRUE) { - gssize bytes_read = g_input_stream_read (file_in, buf, sizeof (buf), - cancellable, error); + gssize bytes_read + = g_input_stream_read (file_in, buf, sizeof (buf), cancellable, error); if (bytes_read < 0) goto out; if (bytes_read == 0) break; - { ssize_t r = archive_write_data (a, buf, bytes_read); + { + ssize_t r = archive_write_data (a, buf, bytes_read); if (r != bytes_read) { propagate_libarchive_error (error, a); - g_prefix_error (error, "Failed to write %" G_GUINT64_FORMAT " bytes (code %" G_GUINT64_FORMAT"): ", (guint64)bytes_read, (guint64)r); + g_prefix_error (error, + "Failed to write %" G_GUINT64_FORMAT + " bytes (code %" G_GUINT64_FORMAT "): ", + (guint64)bytes_read, (guint64)r); goto out; } } @@ -1251,7 +1140,7 @@ write_directory_to_libarchive_recurse (OstreeRepo *self, } ret = TRUE; - out: +out: if (entry) archive_entry_free (entry); return ret; @@ -1263,7 +1152,8 @@ write_directory_to_libarchive_recurse (OstreeRepo *self, * @self: An #OstreeRepo * @opts: Options controlling conversion * @root: An #OstreeRepoFile for the base directory - * @archive: A `struct archive`, but specified as void to avoid a dependency on the libarchive headers + * @archive: A `struct archive`, but specified as void to avoid a dependency on the libarchive + * headers * @cancellable: Cancellable * @error: Error * @@ -1271,23 +1161,20 @@ write_directory_to_libarchive_recurse (OstreeRepo *self, * file structure to @mtree. */ gboolean -ostree_repo_export_tree_to_archive (OstreeRepo *self, - OstreeRepoExportArchiveOptions *opts, - OstreeRepoFile *root, - void *archive, - GCancellable *cancellable, - GError **error) +ostree_repo_export_tree_to_archive (OstreeRepo *self, OstreeRepoExportArchiveOptions *opts, + OstreeRepoFile *root, void *archive, GCancellable *cancellable, + GError **error) { #ifdef HAVE_LIBARCHIVE gboolean ret = FALSE; struct archive *a = archive; - if (!write_directory_to_libarchive_recurse (self, opts, (GFile*)root, (GFile*)root, - a, cancellable, error)) + if (!write_directory_to_libarchive_recurse (self, opts, (GFile *)root, (GFile *)root, a, + cancellable, error)) goto out; ret = TRUE; - out: +out: return ret; #else g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, diff --git a/src/libostree/ostree-repo-os.c b/src/libostree/ostree-repo-os.c index 85b37561..ef150c27 100644 --- a/src/libostree/ostree-repo-os.c +++ b/src/libostree/ostree-repo-os.c @@ -17,16 +17,16 @@ #include "config.h" -#include -#include -#include -#include -#include #include "libglnx.h" -#include "ostree.h" #include "ostree-core-private.h" #include "ostree-repo-os.h" +#include "ostree.h" #include "otutil.h" +#include +#include +#include +#include +#include /** * ostree_commit_metadata_for_bootable: @@ -38,13 +38,12 @@ */ _OSTREE_PUBLIC gboolean -ostree_commit_metadata_for_bootable (GFile *root, GVariantDict *dict, GCancellable *cancellable, GError **error) +ostree_commit_metadata_for_bootable (GFile *root, GVariantDict *dict, GCancellable *cancellable, + GError **error) { - g_autoptr(GFile) modules = g_file_resolve_relative_path (root, "usr/lib/modules"); - g_autoptr(GFileEnumerator) dir_enum - = g_file_enumerate_children (modules, OSTREE_GIO_FAST_QUERYINFO, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - cancellable, error); + g_autoptr (GFile) modules = g_file_resolve_relative_path (root, "usr/lib/modules"); + g_autoptr (GFileEnumerator) dir_enum = g_file_enumerate_children ( + modules, OSTREE_GIO_FAST_QUERYINFO, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!dir_enum) return glnx_prefix_error (error, "Opening usr/lib/modules"); @@ -53,15 +52,14 @@ ostree_commit_metadata_for_bootable (GFile *root, GVariantDict *dict, GCancellab { GFileInfo *child_info; GFile *child_path; - if (!g_file_enumerator_iterate (dir_enum, &child_info, &child_path, - cancellable, error)) + if (!g_file_enumerator_iterate (dir_enum, &child_info, &child_path, cancellable, error)) return FALSE; if (child_info == NULL) break; if (g_file_info_get_file_type (child_info) != G_FILE_TYPE_DIRECTORY) continue; - g_autoptr(GFile) kernel_path = g_file_resolve_relative_path (child_path, "vmlinuz"); + g_autoptr (GFile) kernel_path = g_file_resolve_relative_path (child_path, "vmlinuz"); if (!g_file_query_exists (kernel_path, NULL)) continue; diff --git a/src/libostree/ostree-repo-os.h b/src/libostree/ostree-repo-os.h index 30c54c1a..28963eeb 100644 --- a/src/libostree/ostree-repo-os.h +++ b/src/libostree/ostree-repo-os.h @@ -17,9 +17,9 @@ #pragma once -#include #include #include +#include G_BEGIN_DECLS @@ -39,7 +39,7 @@ G_BEGIN_DECLS #define OSTREE_METADATA_KEY_LINUX "ostree.linux" _OSTREE_PUBLIC -gboolean -ostree_commit_metadata_for_bootable (GFile *root, GVariantDict *dict, GCancellable *cancellable, GError **error); +gboolean ostree_commit_metadata_for_bootable (GFile *root, GVariantDict *dict, + GCancellable *cancellable, GError **error); G_END_DECLS diff --git a/src/libostree/ostree-repo-private.h b/src/libostree/ostree-repo-private.h index 5f21807e..f3865854 100644 --- a/src/libostree/ostree-repo-private.h +++ b/src/libostree/ostree-repo-private.h @@ -19,12 +19,12 @@ #pragma once -#include #include "config.h" -#include "otutil.h" #include "ostree-ref.h" -#include "ostree-repo.h" #include "ostree-remote-private.h" +#include "ostree-repo.h" +#include "otutil.h" +#include G_BEGIN_DECLS @@ -65,13 +65,15 @@ G_BEGIN_DECLS #define OSTREE_COMMIT_TIMESTAMP "ostree.commit.timestamp" #define OSTREE_COMMIT_VERSION "ostree.commit.version" -typedef enum { +typedef enum +{ OSTREE_REPO_TEST_ERROR_PRE_COMMIT = (1 << 0), OSTREE_REPO_TEST_ERROR_INVALID_CACHE = (1 << 1), } OstreeRepoTestErrorFlags; -struct OstreeRepoCommitModifier { - gint refcount; /* atomic */ +struct OstreeRepoCommitModifier +{ + gint refcount; /* atomic */ OstreeRepoCommitModifierFlags flags; OstreeRepoCommitFilter filter; @@ -87,16 +89,18 @@ struct OstreeRepoCommitModifier { GHashTable *devino_cache; }; -typedef enum { +typedef enum +{ OSTREE_REPO_SYSROOT_KIND_UNKNOWN, - OSTREE_REPO_SYSROOT_KIND_NO, /* Not a system repo */ - OSTREE_REPO_SYSROOT_KIND_VIA_SYSROOT, /* Constructed via ostree_sysroot_get_repo() */ + OSTREE_REPO_SYSROOT_KIND_NO, /* Not a system repo */ + OSTREE_REPO_SYSROOT_KIND_VIA_SYSROOT, /* Constructed via ostree_sysroot_get_repo() */ OSTREE_REPO_SYSROOT_KIND_IS_SYSROOT_OSTREE, /* We match /ostree/repo */ } OstreeRepoSysrootKind; -typedef struct { - GHashTable *refs; /* (element-type utf8 utf8) */ - GHashTable *collection_refs; /* (element-type OstreeCollectionRef utf8) */ +typedef struct +{ + GHashTable *refs; /* (element-type utf8 utf8) */ + GHashTable *collection_refs; /* (element-type OstreeCollectionRef utf8) */ OstreeRepoTransactionStats stats; /* Implementation of min-free-space-percent */ gulong blocksize; @@ -104,21 +108,24 @@ typedef struct { gboolean disable_auto_summary; } OstreeRepoTxn; -typedef struct { - GMutex mutex; /* All other members should only be accessed with this held */ - int fd; /* The open file or flock file descriptor */ - guint shared; /* Number of shared locks curently held */ - guint exclusive; /* Number of exclusive locks currently held */ +typedef struct +{ + GMutex mutex; /* All other members should only be accessed with this held */ + int fd; /* The open file or flock file descriptor */ + guint shared; /* Number of shared locks curently held */ + guint exclusive; /* Number of exclusive locks currently held */ } OstreeRepoLock; -typedef enum { +typedef enum +{ _OSTREE_FEATURE_NO, _OSTREE_FEATURE_MAYBE, _OSTREE_FEATURE_YES, } _OstreeFeatureSupport; /* Possible values for the sysroot.bootloader configuration variable */ -typedef enum { +typedef enum +{ CFG_SYSROOT_BOOTLOADER_OPT_AUTO = 0, CFG_SYSROOT_BOOTLOADER_OPT_NONE, CFG_SYSROOT_BOOTLOADER_OPT_GRUB2, @@ -129,16 +136,9 @@ typedef enum { /* Non-exhaustive */ } OstreeCfgSysrootBootloaderOpt; -static const char* const CFG_SYSROOT_BOOTLOADER_OPTS_STR[] = { +static const char *const CFG_SYSROOT_BOOTLOADER_OPTS_STR[] = { /* This must be kept in the same order as the enum */ - "auto", - "none", - "grub2", - "syslinux", - "uboot", - "zipl", - "aboot", - NULL, + "auto", "none", "grub2", "syslinux", "uboot", "zipl", "aboot", NULL, }; /** @@ -146,7 +146,8 @@ static const char* const CFG_SYSROOT_BOOTLOADER_OPTS_STR[] = { * * Private instance structure. */ -struct OstreeRepo { +struct OstreeRepo +{ GObject parent; char *stagedir_prefix; @@ -158,10 +159,10 @@ struct OstreeRepo { */ GFile *repodir_fdrel; GFile *repodir; /* May be %NULL if we were opened via ostree_repo_open_at() */ - int repo_dir_fd; - int tmp_dir_fd; - int cache_dir_fd; - char *cache_dir; + int repo_dir_fd; + int tmp_dir_fd; + int cache_dir_fd; + char *cache_dir; int objects_dir_fd; int uncompressed_objects_dir_fd; GFile *sysroot_dir; @@ -205,9 +206,9 @@ struct OstreeRepo { /* Cache the repo's device/inode to use for comparisons elsewhere */ dev_t device; ino_t inode; - uid_t owner_uid; /* Cache of repo's owner uid */ + uid_t owner_uid; /* Cache of repo's owner uid */ guint min_free_space_percent; /* See the min-free-space-percent config option */ - guint64 min_free_space_mb; /* See the min-free-space-size config option */ + guint64 min_free_space_mb; /* See the min-free-space-size config option */ guint64 reserved_blocks; gboolean cleanup_stagedir; @@ -227,16 +228,18 @@ struct OstreeRepo { gint fs_support_reflink; /* The underlying filesystem has support for ioctl (FICLONE..) */ gchar **repo_finders; OstreeCfgSysrootBootloaderOpt bootloader; /* Configure which bootloader to use. */ - GHashTable *bls_append_values; /* Parsed key-values from bls-append-except-default key in config. */ + GHashTable + *bls_append_values; /* Parsed key-values from bls-append-except-default key in config. */ gboolean enable_bootprefix; /* If true, prepend bootloader entries with /boot */ OstreeRepo *parent_repo; }; -typedef struct { +typedef struct +{ dev_t dev; ino_t ino; - char checksum[OSTREE_SHA256_STRING_LEN+1]; + char checksum[OSTREE_SHA256_STRING_LEN + 1]; } OstreeDevIno; /* A MemoryCacheRef is an in-memory cache of objects (currently just DIRMETA). This can @@ -244,292 +247,163 @@ typedef struct { * the primary use case is ostree_repo_checkout_at() avoiding lots of duplicate dirmeta * lookups. */ -typedef struct { +typedef struct +{ OstreeRepo *repo; } OstreeRepoMemoryCacheRef; +void _ostree_repo_memory_cache_ref_init (OstreeRepoMemoryCacheRef *state, OstreeRepo *repo); -void -_ostree_repo_memory_cache_ref_init (OstreeRepoMemoryCacheRef *state, - OstreeRepo *repo); - -void -_ostree_repo_memory_cache_ref_destroy (OstreeRepoMemoryCacheRef *state); -G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(OstreeRepoMemoryCacheRef, _ostree_repo_memory_cache_ref_destroy) +void _ostree_repo_memory_cache_ref_destroy (OstreeRepoMemoryCacheRef *state); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (OstreeRepoMemoryCacheRef, _ostree_repo_memory_cache_ref_destroy) #define OSTREE_REPO_TMPDIR_STAGING "staging-" -gboolean -_ostree_repo_allocate_tmpdir (int tmpdir_dfd, - const char *tmpdir_prefix, - GLnxTmpDir *tmpdir_out, - GLnxLockFile *file_lock_out, - gboolean * reusing_dir_out, - GCancellable *cancellable, - GError **error); - -gboolean -_ostree_repo_has_staging_prefix (const char *filename); - -gboolean -_ostree_repo_try_lock_tmpdir (int tmpdir_dfd, - const char *tmpdir_name, - GLnxLockFile *file_lock_out, - gboolean *out_did_lock, - GError **error); - -gboolean -_ostree_repo_ensure_loose_objdir_at (int dfd, - const char *loose_path, - GCancellable *cancellable, - GError **error); - -GFile * -_ostree_repo_get_commit_metadata_loose_path (OstreeRepo *self, - const char *checksum); - -gboolean -_ostree_repo_has_loose_object (OstreeRepo *self, - const char *checksum, - OstreeObjectType objtype, - gboolean *out_is_stored, - GCancellable *cancellable, - GError **error); - -gboolean -_ostree_write_bareuser_metadata (int fd, - guint32 uid, - guint32 gid, - guint32 mode, - GVariant *xattrs, - GError **error); - -gboolean -_ostree_repo_write_directory_meta (OstreeRepo *self, - GFileInfo *file_info, - GVariant *xattrs, - guchar **out_csum, - GCancellable *cancellable, - GError **error); -gboolean -_ostree_repo_update_refs (OstreeRepo *self, - GHashTable *refs, - GCancellable *cancellable, - GError **error); - -gboolean -_ostree_repo_update_collection_refs (OstreeRepo *self, - GHashTable *refs, - GCancellable *cancellable, - GError **error); - -gboolean -_ostree_repo_file_replace_contents (OstreeRepo *self, - int dfd, - const char *path, - const guint8 *buf, - gsize len, - GCancellable *cancellable, - GError **error); - -gboolean -_ostree_repo_write_ref (OstreeRepo *self, - const char *remote, - const OstreeCollectionRef *ref, - const char *rev, - const char *alias, - GCancellable *cancellable, - GError **error); - -OstreeRepoFile * -_ostree_repo_file_new_for_commit (OstreeRepo *repo, - const char *commit, - GError **error); - -OstreeRepoFile * -_ostree_repo_file_new_root (OstreeRepo *repo, - const char *contents_checksum, - const char *metadata_checksum); - -gboolean -_ostree_repo_traverse_dirtree_internal (OstreeRepo *repo, - const char *dirtree_checksum, - int recursion_depth, - GHashTable *inout_reachable, - GHashTable *inout_content_names, - GCancellable *cancellable, - GError **error); - -OstreeRepoCommitFilterResult -_ostree_repo_commit_modifier_apply (OstreeRepo *self, - OstreeRepoCommitModifier *modifier, - const char *path, - GFileInfo *file_info, - GFileInfo **out_modified_info); - -void -_ostree_repo_setup_generate_sizes (OstreeRepo *self, - OstreeRepoCommitModifier *modifier); - -gboolean -_ostree_repo_remote_name_is_file (const char *remote_name); +gboolean _ostree_repo_allocate_tmpdir (int tmpdir_dfd, const char *tmpdir_prefix, + GLnxTmpDir *tmpdir_out, GLnxLockFile *file_lock_out, + gboolean *reusing_dir_out, GCancellable *cancellable, + GError **error); + +gboolean _ostree_repo_has_staging_prefix (const char *filename); + +gboolean _ostree_repo_try_lock_tmpdir (int tmpdir_dfd, const char *tmpdir_name, + GLnxLockFile *file_lock_out, gboolean *out_did_lock, + GError **error); + +gboolean _ostree_repo_ensure_loose_objdir_at (int dfd, const char *loose_path, + GCancellable *cancellable, GError **error); + +GFile *_ostree_repo_get_commit_metadata_loose_path (OstreeRepo *self, const char *checksum); + +gboolean _ostree_repo_has_loose_object (OstreeRepo *self, const char *checksum, + OstreeObjectType objtype, gboolean *out_is_stored, + GCancellable *cancellable, GError **error); + +gboolean _ostree_write_bareuser_metadata (int fd, guint32 uid, guint32 gid, guint32 mode, + GVariant *xattrs, GError **error); + +gboolean _ostree_repo_write_directory_meta (OstreeRepo *self, GFileInfo *file_info, + GVariant *xattrs, guchar **out_csum, + GCancellable *cancellable, GError **error); +gboolean _ostree_repo_update_refs (OstreeRepo *self, GHashTable *refs, GCancellable *cancellable, + GError **error); + +gboolean _ostree_repo_update_collection_refs (OstreeRepo *self, GHashTable *refs, + GCancellable *cancellable, GError **error); + +gboolean _ostree_repo_file_replace_contents (OstreeRepo *self, int dfd, const char *path, + const guint8 *buf, gsize len, + GCancellable *cancellable, GError **error); + +gboolean _ostree_repo_write_ref (OstreeRepo *self, const char *remote, + const OstreeCollectionRef *ref, const char *rev, const char *alias, + GCancellable *cancellable, GError **error); + +OstreeRepoFile *_ostree_repo_file_new_for_commit (OstreeRepo *repo, const char *commit, + GError **error); + +OstreeRepoFile *_ostree_repo_file_new_root (OstreeRepo *repo, const char *contents_checksum, + const char *metadata_checksum); + +gboolean _ostree_repo_traverse_dirtree_internal (OstreeRepo *repo, const char *dirtree_checksum, + int recursion_depth, GHashTable *inout_reachable, + GHashTable *inout_content_names, + GCancellable *cancellable, GError **error); + +OstreeRepoCommitFilterResult _ostree_repo_commit_modifier_apply (OstreeRepo *self, + OstreeRepoCommitModifier *modifier, + const char *path, + GFileInfo *file_info, + GFileInfo **out_modified_info); + +void _ostree_repo_setup_generate_sizes (OstreeRepo *self, OstreeRepoCommitModifier *modifier); + +gboolean _ostree_repo_remote_name_is_file (const char *remote_name); #ifndef OSTREE_DISABLE_GPGME -OstreeGpgVerifyResult * -_ostree_repo_gpg_verify_with_metadata (OstreeRepo *self, - GBytes *signed_data, - GVariant *metadata, - const char *remote_name, - GFile *keyringdir, - GFile *extra_keyring, - GCancellable *cancellable, - GError **error); - -OstreeGpgVerifyResult * -_ostree_repo_verify_commit_internal (OstreeRepo *self, - const char *commit_checksum, - const char *remote_name, - GFile *keyringdir, - GFile *extra_keyring, - GCancellable *cancellable, - GError **error); +OstreeGpgVerifyResult *_ostree_repo_gpg_verify_with_metadata ( + OstreeRepo *self, GBytes *signed_data, GVariant *metadata, const char *remote_name, + GFile *keyringdir, GFile *extra_keyring, GCancellable *cancellable, GError **error); + +OstreeGpgVerifyResult *_ostree_repo_verify_commit_internal ( + OstreeRepo *self, const char *commit_checksum, const char *remote_name, GFile *keyringdir, + GFile *extra_keyring, GCancellable *cancellable, GError **error); #endif /* OSTREE_DISABLE_GPGME */ -typedef enum { +typedef enum +{ _OSTREE_REPO_IMPORT_FLAGS_NONE = 0, _OSTREE_REPO_IMPORT_FLAGS_TRUSTED = (1 << 0), _OSTREE_REPO_IMPORT_FLAGS_VERIFY_BAREUSERONLY = (1 << 1), } OstreeRepoImportFlags; -gboolean -_ostree_repo_import_object (OstreeRepo *self, - OstreeRepo *source, - OstreeObjectType objtype, - const char *checksum, - OstreeRepoImportFlags flags, - GCancellable *cancellable, - GError **error); - -gboolean -_ostree_repo_commit_tmpf_final (OstreeRepo *self, - const char *checksum, - OstreeObjectType objtype, - GLnxTmpfile *tmpf, - GCancellable *cancellable, - GError **error); - -typedef struct { +gboolean _ostree_repo_import_object (OstreeRepo *self, OstreeRepo *source, OstreeObjectType objtype, + const char *checksum, OstreeRepoImportFlags flags, + GCancellable *cancellable, GError **error); + +gboolean _ostree_repo_commit_tmpf_final (OstreeRepo *self, const char *checksum, + OstreeObjectType objtype, GLnxTmpfile *tmpf, + GCancellable *cancellable, GError **error); + +typedef struct +{ gboolean initialized; gpointer opaque0[10]; guint opaque1[10]; } OstreeRepoBareContent; void _ostree_repo_bare_content_cleanup (OstreeRepoBareContent *regwrite); -G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(OstreeRepoBareContent, _ostree_repo_bare_content_cleanup) - -gboolean -_ostree_repo_bare_content_open (OstreeRepo *self, - const char *checksum, - guint64 content_len, - guint uid, - guint gid, - guint mode, - GVariant *xattrs, - OstreeRepoBareContent *out_regwrite, - GCancellable *cancellable, - GError **error); - -gboolean -_ostree_repo_bare_content_write (OstreeRepo *repo, - OstreeRepoBareContent *barewrite, - const guint8 *buf, - size_t len, - GCancellable *cancellable, - GError **error); - -gboolean -_ostree_repo_bare_content_commit (OstreeRepo *self, - OstreeRepoBareContent *barewrite, - char *checksum_buf, - size_t buflen, - GCancellable *cancellable, - GError **error); - -OstreeContentWriter * -_ostree_content_writer_new (OstreeRepo *repo, - const char *checksum, - guint uid, - guint gid, - guint mode, - guint64 content_len, - GVariant *xattrs, - GError **error); - -gboolean -_ostree_repo_load_file_bare (OstreeRepo *self, - const char *checksum, - int *out_fd, - struct stat *out_stbuf, - char **out_symlink, - GVariant **out_xattrs, - GCancellable *cancellable, - GError **error); - -gboolean -_ostree_repo_update_mtime (OstreeRepo *self, - GError **error); - -gboolean -_ostree_repo_add_remote (OstreeRepo *self, - OstreeRemote *remote); -gboolean -_ostree_repo_remove_remote (OstreeRepo *self, - OstreeRemote *remote); -OstreeRemote * -_ostree_repo_get_remote (OstreeRepo *self, - const char *name, - GError **error); -OstreeRemote * -_ostree_repo_get_remote_inherited (OstreeRepo *self, - const char *name, - GError **error); - -gboolean -_ostree_repo_maybe_regenerate_summary (OstreeRepo *self, - GCancellable *cancellable, - GError **error); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (OstreeRepoBareContent, _ostree_repo_bare_content_cleanup) + +gboolean _ostree_repo_bare_content_open (OstreeRepo *self, const char *checksum, + guint64 content_len, guint uid, guint gid, guint mode, + GVariant *xattrs, OstreeRepoBareContent *out_regwrite, + GCancellable *cancellable, GError **error); + +gboolean _ostree_repo_bare_content_write (OstreeRepo *repo, OstreeRepoBareContent *barewrite, + const guint8 *buf, size_t len, GCancellable *cancellable, + GError **error); + +gboolean _ostree_repo_bare_content_commit (OstreeRepo *self, OstreeRepoBareContent *barewrite, + char *checksum_buf, size_t buflen, + GCancellable *cancellable, GError **error); + +OstreeContentWriter *_ostree_content_writer_new (OstreeRepo *repo, const char *checksum, guint uid, + guint gid, guint mode, guint64 content_len, + GVariant *xattrs, GError **error); + +gboolean _ostree_repo_load_file_bare (OstreeRepo *self, const char *checksum, int *out_fd, + struct stat *out_stbuf, char **out_symlink, + GVariant **out_xattrs, GCancellable *cancellable, + GError **error); + +gboolean _ostree_repo_update_mtime (OstreeRepo *self, GError **error); +gboolean _ostree_repo_add_remote (OstreeRepo *self, OstreeRemote *remote); +gboolean _ostree_repo_remove_remote (OstreeRepo *self, OstreeRemote *remote); +OstreeRemote *_ostree_repo_get_remote (OstreeRepo *self, const char *name, GError **error); +OstreeRemote *_ostree_repo_get_remote_inherited (OstreeRepo *self, const char *name, + GError **error); + +gboolean _ostree_repo_maybe_regenerate_summary (OstreeRepo *self, GCancellable *cancellable, + GError **error); gboolean _ostree_repo_parse_fsverity_config (OstreeRepo *self, GError **error); -gboolean -_ostree_tmpf_fsverity_core (GLnxTmpfile *tmpf, - _OstreeFeatureSupport fsverity_requested, - gboolean *supported, - GError **error); - -gboolean -_ostree_tmpf_fsverity (OstreeRepo *self, - GLnxTmpfile *tmpf, - GError **error); - -gboolean -_ostree_repo_verify_bindings (const char *collection_id, - const char *ref_name, - GVariant *commit, - GError **error); - -GHashTable * -ostree_repo_list_objects_set (OstreeRepo *self, - OstreeRepoListObjectsFlags flags, - GCancellable *cancellable, - GError **error); - -gboolean -_ostree_repo_transaction_write_repo_metadata (OstreeRepo *self, - GVariant *additional_metadata, - char **out_checksum, - GCancellable *cancellable, - GError **error); +gboolean _ostree_tmpf_fsverity_core (GLnxTmpfile *tmpf, _OstreeFeatureSupport fsverity_requested, + gboolean *supported, GError **error); + +gboolean _ostree_tmpf_fsverity (OstreeRepo *self, GLnxTmpfile *tmpf, GError **error); + +gboolean _ostree_repo_verify_bindings (const char *collection_id, const char *ref_name, + GVariant *commit, GError **error); + +GHashTable *ostree_repo_list_objects_set (OstreeRepo *self, OstreeRepoListObjectsFlags flags, + GCancellable *cancellable, GError **error); + +gboolean _ostree_repo_transaction_write_repo_metadata (OstreeRepo *self, + GVariant *additional_metadata, + char **out_checksum, + GCancellable *cancellable, GError **error); /** * OstreeRepoAutoTransaction: @@ -547,26 +421,18 @@ typedef struct } OstreeRepoAutoTransaction; OstreeRepoAutoTransaction * -_ostree_repo_auto_transaction_start (OstreeRepo *repo, - GCancellable *cancellable, - GError **error); +_ostree_repo_auto_transaction_start (OstreeRepo *repo, GCancellable *cancellable, GError **error); -gboolean -_ostree_repo_auto_transaction_abort (OstreeRepoAutoTransaction *txn, - GCancellable *cancellable, - GError **error); +gboolean _ostree_repo_auto_transaction_abort (OstreeRepoAutoTransaction *txn, + GCancellable *cancellable, GError **error); -gboolean -_ostree_repo_auto_transaction_commit (OstreeRepoAutoTransaction *txn, - OstreeRepoTransactionStats *out_stats, - GCancellable *cancellable, - GError **error); +gboolean _ostree_repo_auto_transaction_commit (OstreeRepoAutoTransaction *txn, + OstreeRepoTransactionStats *out_stats, + GCancellable *cancellable, GError **error); -OstreeRepoAutoTransaction * -_ostree_repo_auto_transaction_ref (OstreeRepoAutoTransaction *txn); +OstreeRepoAutoTransaction *_ostree_repo_auto_transaction_ref (OstreeRepoAutoTransaction *txn); -void -_ostree_repo_auto_transaction_unref (OstreeRepoAutoTransaction *txn); +void _ostree_repo_auto_transaction_unref (OstreeRepoAutoTransaction *txn); GType _ostree_repo_auto_transaction_get_type (void); diff --git a/src/libostree/ostree-repo-prune.c b/src/libostree/ostree-repo-prune.c index 9394c621..58178599 100644 --- a/src/libostree/ostree-repo-prune.c +++ b/src/libostree/ostree-repo-prune.c @@ -21,12 +21,13 @@ #include "config.h" +#include "ostree-autocleanups.h" #include "ostree-core-private.h" #include "ostree-repo-private.h" -#include "ostree-autocleanups.h" #include "otutil.h" -typedef struct { +typedef struct +{ OstreeRepo *repo; GHashTable *reachable; guint n_reachable_meta; @@ -37,11 +38,8 @@ typedef struct { } OtPruneData; static gboolean -maybe_prune_loose_object (OtPruneData *data, - OstreeRepoPruneFlags flags, - GVariant *key, - GCancellable *cancellable, - GError **error) +maybe_prune_loose_object (OtPruneData *data, OstreeRepoPruneFlags flags, GVariant *key, + GCancellable *cancellable, GError **error) { gboolean reachable = FALSE; const char *checksum; @@ -59,11 +57,10 @@ maybe_prune_loose_object (OtPruneData *data, { guint64 storage_size = 0; - g_debug ("Pruning unneeded object %s.%s", checksum, - ostree_object_type_to_string (objtype)); + g_debug ("Pruning unneeded object %s.%s", checksum, ostree_object_type_to_string (objtype)); - if (!ostree_repo_query_object_storage_size (data->repo, objtype, checksum, - &storage_size, cancellable, error)) + if (!ostree_repo_query_object_storage_size (data->repo, objtype, checksum, &storage_size, + cancellable, error)) return FALSE; data->freed_bytes += storage_size; @@ -74,26 +71,31 @@ maybe_prune_loose_object (OtPruneData *data, { ssize_t size; char loose_path_buf[_OSTREE_LOOSE_PATH_MAX]; - char target_checksum[OSTREE_SHA256_STRING_LEN+1]; + char target_checksum[OSTREE_SHA256_STRING_LEN + 1]; char target_buf[_OSTREE_LOOSE_PATH_MAX + _OSTREE_PAYLOAD_LINK_PREFIX_LEN]; - _ostree_loose_path (loose_path_buf, checksum, OSTREE_OBJECT_TYPE_PAYLOAD_LINK, data->repo->mode); - size = readlinkat (data->repo->objects_dir_fd, loose_path_buf, target_buf, sizeof (target_buf)); + _ostree_loose_path (loose_path_buf, checksum, OSTREE_OBJECT_TYPE_PAYLOAD_LINK, + data->repo->mode); + size = readlinkat (data->repo->objects_dir_fd, loose_path_buf, target_buf, + sizeof (target_buf)); if (size < 0) return glnx_throw_errno_prefix (error, "readlinkat"); if (size < OSTREE_SHA256_STRING_LEN + _OSTREE_PAYLOAD_LINK_PREFIX_LEN) return glnx_throw (error, "invalid data size for %s", loose_path_buf); - sprintf (target_checksum, "%.2s%.62s", target_buf + _OSTREE_PAYLOAD_LINK_PREFIX_LEN, target_buf + _OSTREE_PAYLOAD_LINK_PREFIX_LEN + 3); + sprintf (target_checksum, "%.2s%.62s", target_buf + _OSTREE_PAYLOAD_LINK_PREFIX_LEN, + target_buf + _OSTREE_PAYLOAD_LINK_PREFIX_LEN + 3); - g_autoptr(GVariant) target_key = ostree_object_name_serialize (target_checksum, OSTREE_OBJECT_TYPE_FILE); + g_autoptr (GVariant) target_key + = ostree_object_name_serialize (target_checksum, OSTREE_OBJECT_TYPE_FILE); if (g_hash_table_lookup_extended (data->reachable, target_key, NULL, NULL)) { guint64 target_storage_size = 0; - if (!ostree_repo_query_object_storage_size (data->repo, OSTREE_OBJECT_TYPE_FILE, target_checksum, - &target_storage_size, cancellable, error)) + if (!ostree_repo_query_object_storage_size (data->repo, OSTREE_OBJECT_TYPE_FILE, + target_checksum, &target_storage_size, + cancellable, error)) return FALSE; reachable = target_storage_size >= data->repo->payload_link_threshold; @@ -107,10 +109,8 @@ maybe_prune_loose_object (OtPruneData *data, return FALSE; } - if (!ostree_repo_delete_object (data->repo, objtype, checksum, - cancellable, error)) + if (!ostree_repo_delete_object (data->repo, objtype, checksum, cancellable, error)) return FALSE; - } if (OSTREE_OBJECT_TYPE_IS_META (objtype)) @@ -119,17 +119,16 @@ maybe_prune_loose_object (OtPruneData *data, data->n_unreachable_content++; } - exit: +exit: if (reachable) { - g_debug ("Keeping needed object %s.%s", checksum, - ostree_object_type_to_string (objtype)); + g_debug ("Keeping needed object %s.%s", checksum, ostree_object_type_to_string (objtype)); if (OSTREE_OBJECT_TYPE_IS_META (objtype)) data->n_reachable_meta++; else data->n_reachable_content++; } - if (commit_only && (objtype != OSTREE_OBJECT_TYPE_COMMIT)) + if (commit_only && (objtype != OSTREE_OBJECT_TYPE_COMMIT)) { g_debug ("Keeping object (not commit) %s.%s", checksum, ostree_object_type_to_string (objtype)); @@ -138,17 +137,17 @@ maybe_prune_loose_object (OtPruneData *data, } static gboolean -_ostree_repo_prune_tmp (OstreeRepo *self, - GCancellable *cancellable, - GError **error) +_ostree_repo_prune_tmp (OstreeRepo *self, GCancellable *cancellable, GError **error) { if (self->cache_dir_fd == -1) return TRUE; - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; gboolean exists; - if (!ot_dfd_iter_init_allow_noent (self->cache_dir_fd, _OSTREE_SUMMARY_CACHE_DIR, - &dfd_iter, &exists, error)) + if (!ot_dfd_iter_init_allow_noent (self->cache_dir_fd, _OSTREE_SUMMARY_CACHE_DIR, &dfd_iter, + &exists, error)) return FALSE; /* Note early return */ if (!exists) @@ -204,18 +203,16 @@ _ostree_repo_prune_tmp (OstreeRepo *self, * Locking: exclusive */ gboolean -ostree_repo_prune_static_deltas (OstreeRepo *self, const char *commit, - GCancellable *cancellable, - GError **error) +ostree_repo_prune_static_deltas (OstreeRepo *self, const char *commit, GCancellable *cancellable, + GError **error) { - g_autoptr(OstreeRepoAutoLock) lock = - ostree_repo_auto_lock_push (self, OSTREE_REPO_LOCK_EXCLUSIVE, cancellable, error); + g_autoptr (OstreeRepoAutoLock) lock + = ostree_repo_auto_lock_push (self, OSTREE_REPO_LOCK_EXCLUSIVE, cancellable, error); if (!lock) return FALSE; - g_autoptr(GPtrArray) deltas = NULL; - if (!ostree_repo_list_static_delta_names (self, &deltas, - cancellable, error)) + g_autoptr (GPtrArray) deltas = NULL; + if (!ostree_repo_list_static_delta_names (self, &deltas, cancellable, error)) return FALSE; for (guint i = 0; i < deltas->len; i++) @@ -243,8 +240,7 @@ ostree_repo_prune_static_deltas (OstreeRepo *self, const char *commit, else { gboolean have_commit; - if (!ostree_repo_has_object (self, OSTREE_OBJECT_TYPE_COMMIT, - to, &have_commit, + if (!ostree_repo_has_object (self, OSTREE_OBJECT_TYPE_COMMIT, to, &have_commit, cancellable, error)) return FALSE; @@ -254,8 +250,7 @@ ostree_repo_prune_static_deltas (OstreeRepo *self, const char *commit, g_debug ("Trying to prune static delta %s", deltaname); g_autofree char *deltadir = _ostree_get_relative_static_delta_path (from, to, NULL); - if (!glnx_shutil_rm_rf_at (self->repo_dir_fd, deltadir, - cancellable, error)) + if (!glnx_shutil_rm_rf_at (self->repo_dir_fd, deltadir, cancellable, error)) return FALSE; } @@ -263,26 +258,23 @@ ostree_repo_prune_static_deltas (OstreeRepo *self, const char *commit, } static gboolean -repo_prune_internal (OstreeRepo *self, - GHashTable *objects, - OstreeRepoPruneOptions *options, - gint *out_objects_total, - gint *out_objects_pruned, - guint64 *out_pruned_object_size_total, - GCancellable *cancellable, - GError **error) +repo_prune_internal (OstreeRepo *self, GHashTable *objects, OstreeRepoPruneOptions *options, + gint *out_objects_total, gint *out_objects_pruned, + guint64 *out_pruned_object_size_total, GCancellable *cancellable, + GError **error) { - OtPruneData data = { 0, }; + OtPruneData data = { + 0, + }; data.repo = self; /* We unref this when we're done */ - g_autoptr(GHashTable) reachable_owned = g_hash_table_ref (options->reachable); + g_autoptr (GHashTable) reachable_owned = g_hash_table_ref (options->reachable); data.reachable = reachable_owned; - GLNX_HASH_TABLE_FOREACH (objects, GVariant*, serialized_key) + GLNX_HASH_TABLE_FOREACH (objects, GVariant *, serialized_key) { - if (!maybe_prune_loose_object (&data, options->flags, serialized_key, - cancellable, error)) + if (!maybe_prune_loose_object (&data, options->flags, serialized_key, cancellable, error)) return FALSE; } @@ -292,53 +284,49 @@ repo_prune_internal (OstreeRepo *self, if (!_ostree_repo_prune_tmp (self, cancellable, error)) return FALSE; - *out_objects_total = (data.n_reachable_meta + data.n_unreachable_meta + - data.n_reachable_content + data.n_unreachable_content); + *out_objects_total = (data.n_reachable_meta + data.n_unreachable_meta + data.n_reachable_content + + data.n_unreachable_content); *out_objects_pruned = (data.n_unreachable_meta + data.n_unreachable_content); *out_pruned_object_size_total = data.freed_bytes; return TRUE; } static gboolean -traverse_reachable_internal (OstreeRepo *self, - OstreeRepoCommitTraverseFlags flags, - guint depth, - GHashTable *reachable, - GCancellable *cancellable, - GError **error) +traverse_reachable_internal (OstreeRepo *self, OstreeRepoCommitTraverseFlags flags, guint depth, + GHashTable *reachable, GCancellable *cancellable, GError **error) { - g_autoptr(OstreeRepoAutoLock) lock = - ostree_repo_auto_lock_push (self, OSTREE_REPO_LOCK_SHARED, cancellable, error); + g_autoptr (OstreeRepoAutoLock) lock + = ostree_repo_auto_lock_push (self, OSTREE_REPO_LOCK_SHARED, cancellable, error); if (!lock) return FALSE; /* Ignoring collections. */ - g_autoptr(GHashTable) all_refs = NULL; /* (element-type utf8 utf8) */ + g_autoptr (GHashTable) all_refs = NULL; /* (element-type utf8 utf8) */ - if (!ostree_repo_list_refs (self, NULL, &all_refs, - cancellable, error)) + if (!ostree_repo_list_refs (self, NULL, &all_refs, cancellable, error)) return FALSE; - GLNX_HASH_TABLE_FOREACH_V (all_refs, const char*, checksum) + GLNX_HASH_TABLE_FOREACH_V (all_refs, const char *, checksum) { g_debug ("Finding objects to keep for commit %s", checksum); - if (!ostree_repo_traverse_commit_with_flags (self, flags, checksum, depth, reachable, - NULL, cancellable, error)) + if (!ostree_repo_traverse_commit_with_flags (self, flags, checksum, depth, reachable, NULL, + cancellable, error)) return FALSE; } /* Using collections. */ - g_autoptr(GHashTable) all_collection_refs = NULL; /* (element-type OstreeChecksumRef utf8) */ + g_autoptr (GHashTable) all_collection_refs = NULL; /* (element-type OstreeChecksumRef utf8) */ if (!ostree_repo_list_collection_refs (self, NULL, &all_collection_refs, - OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES, cancellable, error)) + OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES, cancellable, + error)) return FALSE; - GLNX_HASH_TABLE_FOREACH_V (all_collection_refs, const char*, checksum) + GLNX_HASH_TABLE_FOREACH_V (all_collection_refs, const char *, checksum) { g_debug ("Finding objects to keep for commit %s", checksum); - if (!ostree_repo_traverse_commit_with_flags (self, flags, checksum, depth, reachable, - NULL, cancellable, error)) + if (!ostree_repo_traverse_commit_with_flags (self, flags, checksum, depth, reachable, NULL, + cancellable, error)) return FALSE; } @@ -359,15 +347,10 @@ traverse_reachable_internal (OstreeRepo *self, * Since: 2018.6 */ gboolean -ostree_repo_traverse_reachable_refs (OstreeRepo *self, - guint depth, - GHashTable *reachable, - GCancellable *cancellable, - GError **error) +ostree_repo_traverse_reachable_refs (OstreeRepo *self, guint depth, GHashTable *reachable, + GCancellable *cancellable, GError **error) { - return traverse_reachable_internal (self, - OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE, - depth, reachable, + return traverse_reachable_internal (self, OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE, depth, reachable, cancellable, error); } @@ -399,25 +382,20 @@ ostree_repo_traverse_reachable_refs (OstreeRepo *self, * Locking: exclusive */ gboolean -ostree_repo_prune (OstreeRepo *self, - OstreeRepoPruneFlags flags, - gint depth, - gint *out_objects_total, - gint *out_objects_pruned, - guint64 *out_pruned_object_size_total, - GCancellable *cancellable, - GError **error) +ostree_repo_prune (OstreeRepo *self, OstreeRepoPruneFlags flags, gint depth, + gint *out_objects_total, gint *out_objects_pruned, + guint64 *out_pruned_object_size_total, GCancellable *cancellable, GError **error) { - g_autoptr(OstreeRepoAutoLock) lock = - ostree_repo_auto_lock_push (self, OSTREE_REPO_LOCK_EXCLUSIVE, cancellable, error); + g_autoptr (OstreeRepoAutoLock) lock + = ostree_repo_auto_lock_push (self, OSTREE_REPO_LOCK_EXCLUSIVE, cancellable, error); if (!lock) return FALSE; - g_autoptr(GHashTable) objects = NULL; + g_autoptr (GHashTable) objects = NULL; gboolean refs_only = flags & OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY; gboolean commit_only = flags & OSTREE_REPO_PRUNE_FLAGS_COMMIT_ONLY; - g_autoptr(GHashTable) reachable = ostree_repo_traverse_new_reachable (); + g_autoptr (GHashTable) reachable = ostree_repo_traverse_new_reachable (); /* This original prune API has fixed logic for traversing refs or all commits * combined with actually deleting content. The newer backend API just does @@ -430,9 +408,7 @@ ostree_repo_prune (OstreeRepo *self, if (refs_only) { - if (!traverse_reachable_internal (self, traverse_flags, - depth, reachable, - cancellable, error)) + if (!traverse_reachable_internal (self, traverse_flags, depth, reachable, cancellable, error)) return FALSE; } @@ -443,8 +419,9 @@ ostree_repo_prune (OstreeRepo *self, } else { - objects = ostree_repo_list_objects_set (self, OSTREE_REPO_LIST_OBJECTS_ALL | OSTREE_REPO_LIST_OBJECTS_NO_PARENTS, - cancellable, error); + objects = ostree_repo_list_objects_set ( + self, OSTREE_REPO_LIST_OBJECTS_ALL | OSTREE_REPO_LIST_OBJECTS_NO_PARENTS, cancellable, + error); } if (!objects) @@ -452,7 +429,7 @@ ostree_repo_prune (OstreeRepo *self, if (!refs_only) { - GLNX_HASH_TABLE_FOREACH (objects, GVariant*, serialized_key) + GLNX_HASH_TABLE_FOREACH (objects, GVariant *, serialized_key) { const char *checksum; OstreeObjectType objtype; @@ -463,15 +440,15 @@ ostree_repo_prune (OstreeRepo *self, continue; g_debug ("Finding objects to keep for commit %s", checksum); - if (!ostree_repo_traverse_commit_with_flags (self, traverse_flags, checksum, depth, reachable, - NULL, cancellable, error)) + if (!ostree_repo_traverse_commit_with_flags (self, traverse_flags, checksum, depth, + reachable, NULL, cancellable, error)) return FALSE; } } - { OstreeRepoPruneOptions opts = { flags, reachable }; - return repo_prune_internal (self, objects, &opts, - out_objects_total, out_objects_pruned, + { + OstreeRepoPruneOptions opts = { flags, reachable }; + return repo_prune_internal (self, objects, &opts, out_objects_total, out_objects_pruned, out_pruned_object_size_total, cancellable, error); } } @@ -503,20 +480,17 @@ ostree_repo_prune (OstreeRepo *self, * Since: 2017.1 */ gboolean -ostree_repo_prune_from_reachable (OstreeRepo *self, - OstreeRepoPruneOptions *options, - gint *out_objects_total, - gint *out_objects_pruned, - guint64 *out_pruned_object_size_total, - GCancellable *cancellable, - GError **error) +ostree_repo_prune_from_reachable (OstreeRepo *self, OstreeRepoPruneOptions *options, + gint *out_objects_total, gint *out_objects_pruned, + guint64 *out_pruned_object_size_total, GCancellable *cancellable, + GError **error) { - g_autoptr(OstreeRepoAutoLock) lock = - ostree_repo_auto_lock_push (self, OSTREE_REPO_LOCK_EXCLUSIVE, cancellable, error); + g_autoptr (OstreeRepoAutoLock) lock + = ostree_repo_auto_lock_push (self, OSTREE_REPO_LOCK_EXCLUSIVE, cancellable, error); if (!lock) return FALSE; - g_autoptr(GHashTable) objects = NULL; + g_autoptr (GHashTable) objects = NULL; OstreeRepoPruneFlags flags = options->flags; gboolean commit_only = (flags & OSTREE_REPO_PRUNE_FLAGS_COMMIT_ONLY) > 0; if (commit_only) @@ -526,14 +500,13 @@ ostree_repo_prune_from_reachable (OstreeRepo *self, } else { - objects = - ostree_repo_list_objects_set (self, OSTREE_REPO_LIST_OBJECTS_ALL | OSTREE_REPO_LIST_OBJECTS_NO_PARENTS, - cancellable, error); + objects = ostree_repo_list_objects_set ( + self, OSTREE_REPO_LIST_OBJECTS_ALL | OSTREE_REPO_LIST_OBJECTS_NO_PARENTS, cancellable, + error); } if (!objects) return FALSE; - return repo_prune_internal (self, objects, options, out_objects_total, - out_objects_pruned, out_pruned_object_size_total, - cancellable, error); + return repo_prune_internal (self, objects, options, out_objects_total, out_objects_pruned, + out_pruned_object_size_total, cancellable, error); } diff --git a/src/libostree/ostree-repo-pull-private.h b/src/libostree/ostree-repo-pull-private.h index 6ee7ba02..982cf1b5 100644 --- a/src/libostree/ostree-repo-pull-private.h +++ b/src/libostree/ostree-repo-pull-private.h @@ -19,159 +19,148 @@ #pragma once -#include "ostree-repo-private.h" #include "ostree-fetcher-util.h" #include "ostree-remote-private.h" +#include "ostree-repo-private.h" G_BEGIN_DECLS -typedef enum { +typedef enum +{ OSTREE_FETCHER_SECURITY_STATE_CA_PINNED, OSTREE_FETCHER_SECURITY_STATE_TLS, OSTREE_FETCHER_SECURITY_STATE_INSECURE, } OstreeFetcherSecurityState; -typedef struct { - OstreeRepo *repo; - int tmpdir_dfd; +typedef struct +{ + OstreeRepo *repo; + int tmpdir_dfd; OstreeRepoPullFlags flags; - char *remote_name; - char *remote_refspec_name; + char *remote_name; + char *remote_refspec_name; OstreeRepoMode remote_mode; OstreeFetcher *fetcher; OstreeFetcherSecurityState fetcher_security_state; - GPtrArray *meta_mirrorlist; /* List of base URIs for fetching metadata */ - GPtrArray *content_mirrorlist; /* List of base URIs for fetching content */ - OstreeRepo *remote_repo_local; - GPtrArray *localcache_repos; /* Array */ + GPtrArray *meta_mirrorlist; /* List of base URIs for fetching metadata */ + GPtrArray *content_mirrorlist; /* List of base URIs for fetching content */ + OstreeRepo *remote_repo_local; + GPtrArray *localcache_repos; /* Array */ - GMainContext *main_context; + GMainContext *main_context; GCancellable *cancellable; OstreeAsyncProgress *progress; - GVariant *extra_headers; - char *append_user_agent; + GVariant *extra_headers; + char *append_user_agent; - gboolean dry_run; - gboolean dry_run_emitted_progress; - gboolean legacy_transaction_resuming; - guint n_network_retries; - enum { + gboolean dry_run; + gboolean dry_run_emitted_progress; + gboolean legacy_transaction_resuming; + guint n_network_retries; + enum + { OSTREE_PULL_PHASE_FETCHING_REFS, OSTREE_PULL_PHASE_FETCHING_OBJECTS - } phase; - gint n_scanned_metadata; - - gboolean gpg_verify; - gboolean gpg_verify_summary; - gboolean require_static_deltas; - gboolean disable_static_deltas; - gboolean has_tombstone_commits; - gboolean disable_verify_bindings; - - GBytes *summary_data; - char *summary_etag; - guint64 summary_last_modified; /* seconds since the epoch */ - GBytes *summary_data_sig; - char *summary_sig_etag; - guint64 summary_sig_last_modified; /* seconds since the epoch */ - GVariant *summary; - GHashTable *summary_deltas_checksums; /* Filled from summary and delta indexes */ - gboolean summary_has_deltas; /* True if the summary existed and had a delta index */ - gboolean has_indexed_deltas; - GHashTable *ref_original_commits; /* Maps checksum to commit, used by timestamp checks */ - GHashTable *verified_commits; /* Set of commits that have been verified */ - GHashTable *signapi_verified_commits; /* Map of commits that have been signapi verified */ - GHashTable *ref_keyring_map; /* Maps OstreeCollectionRef to keyring remote name */ - GPtrArray *static_delta_superblocks; - GHashTable *expected_commit_sizes; /* Maps commit checksum to known size */ - GHashTable *commit_to_depth; /* Maps parent commit checksum maximum depth */ - GHashTable *scanned_metadata; /* Maps object name to itself */ - GHashTable *fetched_detached_metadata; /* Map */ - GHashTable *requested_metadata; /* Maps object name to itself */ - GHashTable *requested_content; /* Maps checksum to itself */ - GHashTable *requested_fallback_content; /* Maps checksum to itself */ - GHashTable *pending_fetch_metadata; /* Map */ - GHashTable *pending_fetch_content; /* Map */ - GHashTable *pending_fetch_delta_indexes; /* Set */ - GHashTable *pending_fetch_delta_superblocks; /* Set */ - GHashTable *pending_fetch_deltaparts; /* Set */ - guint n_outstanding_metadata_fetches; - guint n_outstanding_metadata_write_requests; - guint n_outstanding_content_fetches; - guint n_outstanding_content_write_requests; - guint n_outstanding_deltapart_fetches; - guint n_outstanding_deltapart_write_requests; - guint n_total_deltaparts; - guint n_total_delta_fallbacks; - guint64 fetched_deltapart_size; /* How much of the delta we have now */ - guint64 total_deltapart_size; - guint64 total_deltapart_usize; - gint n_requested_metadata; - gint n_requested_content; - guint n_fetched_deltaparts; - guint n_fetched_deltapart_fallbacks; - guint n_fetched_metadata; - guint n_fetched_content; + } phase; + gint n_scanned_metadata; + + gboolean gpg_verify; + gboolean gpg_verify_summary; + gboolean require_static_deltas; + gboolean disable_static_deltas; + gboolean has_tombstone_commits; + gboolean disable_verify_bindings; + + GBytes *summary_data; + char *summary_etag; + guint64 summary_last_modified; /* seconds since the epoch */ + GBytes *summary_data_sig; + char *summary_sig_etag; + guint64 summary_sig_last_modified; /* seconds since the epoch */ + GVariant *summary; + GHashTable *summary_deltas_checksums; /* Filled from summary and delta indexes */ + gboolean summary_has_deltas; /* True if the summary existed and had a delta index */ + gboolean has_indexed_deltas; + GHashTable *ref_original_commits; /* Maps checksum to commit, used by timestamp checks */ + GHashTable *verified_commits; /* Set of commits that have been verified */ + GHashTable *signapi_verified_commits; /* Map of commits that have been + signapi verified */ + GHashTable *ref_keyring_map; /* Maps OstreeCollectionRef to keyring remote name */ + GPtrArray *static_delta_superblocks; + GHashTable *expected_commit_sizes; /* Maps commit checksum to known size */ + GHashTable *commit_to_depth; /* Maps parent commit checksum maximum depth */ + GHashTable *scanned_metadata; /* Maps object name to itself */ + GHashTable *fetched_detached_metadata; /* Map */ + GHashTable *requested_metadata; /* Maps object name to itself */ + GHashTable *requested_content; /* Maps checksum to itself */ + GHashTable *requested_fallback_content; /* Maps checksum to itself */ + GHashTable *pending_fetch_metadata; /* Map */ + GHashTable *pending_fetch_content; /* Map */ + GHashTable *pending_fetch_delta_indexes; /* Set */ + GHashTable *pending_fetch_delta_superblocks; /* Set */ + GHashTable *pending_fetch_deltaparts; /* Set */ + guint n_outstanding_metadata_fetches; + guint n_outstanding_metadata_write_requests; + guint n_outstanding_content_fetches; + guint n_outstanding_content_write_requests; + guint n_outstanding_deltapart_fetches; + guint n_outstanding_deltapart_write_requests; + guint n_total_deltaparts; + guint n_total_delta_fallbacks; + guint64 fetched_deltapart_size; /* How much of the delta we have now */ + guint64 total_deltapart_size; + guint64 total_deltapart_usize; + gint n_requested_metadata; + gint n_requested_content; + guint n_fetched_deltaparts; + guint n_fetched_deltapart_fallbacks; + guint n_fetched_metadata; + guint n_fetched_content; /* Objects imported via hardlink/reflink/copying or --localcache-repo*/ - guint n_imported_metadata; - guint n_imported_content; - - gboolean timestamp_check; /* Verify commit timestamps */ - char *timestamp_check_from_rev; - int maxdepth; - guint64 max_metadata_size; - guint64 start_time; - - gboolean is_mirror; - gboolean trusted_http_direct; - gboolean is_commit_only; + guint n_imported_metadata; + guint n_imported_content; + + gboolean timestamp_check; /* Verify commit timestamps */ + char *timestamp_check_from_rev; + int maxdepth; + guint64 max_metadata_size; + guint64 start_time; + + gboolean is_mirror; + gboolean trusted_http_direct; + gboolean is_commit_only; OstreeRepoImportFlags importflags; - GPtrArray *signapi_commit_verifiers; - GPtrArray *signapi_summary_verifiers; + GPtrArray *signapi_commit_verifiers; + GPtrArray *signapi_summary_verifiers; - GPtrArray *dirs; + GPtrArray *dirs; - gboolean have_previous_bytes; - guint64 previous_bytes_sec; - guint64 previous_total_downloaded; + gboolean have_previous_bytes; + guint64 previous_bytes_sec; + guint64 previous_total_downloaded; - GError *cached_async_error; - GError **async_error; - gboolean caught_error; + GError *cached_async_error; + GError **async_error; + gboolean caught_error; GQueue scan_object_queue; GSource *idle_src; } OtPullData; -gboolean -_signapi_init_for_remote (OstreeRepo *repo, - const char *remote_name, - GPtrArray **out_commit_verifiers, - GPtrArray **out_summary_verifiers, - GError **error); -gboolean -_sign_verify_for_remote (GPtrArray *signers, - GBytes *signed_data, - GVariant *metadata, - char **out_success_message, - GError **error); - -gboolean -_verify_unwritten_commit (OtPullData *pull_data, - const char *checksum, - GVariant *commit, - GVariant *detached_metadata, - const OstreeCollectionRef *ref, - GCancellable *cancellable, - GError **error); - -gboolean -_process_gpg_verify_result (OtPullData *pull_data, - const char *checksum, - OstreeGpgVerifyResult *result, - GError **error); +gboolean _signapi_init_for_remote (OstreeRepo *repo, const char *remote_name, + GPtrArray **out_commit_verifiers, + GPtrArray **out_summary_verifiers, GError **error); +gboolean _sign_verify_for_remote (GPtrArray *signers, GBytes *signed_data, GVariant *metadata, + char **out_success_message, GError **error); + +gboolean _verify_unwritten_commit (OtPullData *pull_data, const char *checksum, GVariant *commit, + GVariant *detached_metadata, const OstreeCollectionRef *ref, + GCancellable *cancellable, GError **error); + +gboolean _process_gpg_verify_result (OtPullData *pull_data, const char *checksum, + OstreeGpgVerifyResult *result, GError **error); G_END_DECLS diff --git a/src/libostree/ostree-repo-pull-verify.c b/src/libostree/ostree-repo-pull-verify.c index 658367fa..9f4d2145 100644 --- a/src/libostree/ostree-repo-pull-verify.c +++ b/src/libostree/ostree-repo-pull-verify.c @@ -21,16 +21,16 @@ #include "config.h" #include "libglnx.h" +#include "ostree-repo-private.h" +#include "ostree-repo-pull-private.h" #include "ostree.h" #include "otutil.h" -#include "ostree-repo-pull-private.h" -#include "ostree-repo-private.h" #include "ostree-core-private.h" -#include "ostree-repo-static-delta-private.h" -#include "ostree-metalink.h" #include "ostree-fetcher-util.h" +#include "ostree-metalink.h" #include "ostree-remote-private.h" +#include "ostree-repo-static-delta-private.h" #include "ot-fs-utils.h" #include @@ -42,14 +42,11 @@ #include "ostree-sign.h" static gboolean -get_signapi_remote_option (OstreeRepo *repo, - OstreeSign *sign, - const char *remote_name, - const char *keysuffix, - char **out_value, - GError **error) +get_signapi_remote_option (OstreeRepo *repo, OstreeSign *sign, const char *remote_name, + const char *keysuffix, char **out_value, GError **error) { - g_autofree char *key = g_strdup_printf ("verification-%s-%s", ostree_sign_get_name (sign), keysuffix); + g_autofree char *key + = g_strdup_printf ("verification-%s-%s", ostree_sign_get_name (sign), keysuffix); return ostree_repo_get_remote_option (repo, remote_name, key, NULL, out_value, error); } @@ -66,11 +63,8 @@ get_signapi_remote_option (OstreeRepo *repo, * Returns: %TRUE if no configuration or any key loaded. * */ static gboolean -_signapi_load_public_keys (OstreeSign *sign, - OstreeRepo *repo, - const gchar *remote_name, - gboolean required, - GError **error) +_signapi_load_public_keys (OstreeSign *sign, OstreeRepo *repo, const gchar *remote_name, + gboolean required, GError **error) { g_autofree gchar *pk_ascii = NULL; g_autofree gchar *pk_file = NULL; @@ -83,7 +77,7 @@ _signapi_load_public_keys (OstreeSign *sign, return FALSE; /* return TRUE if there is no configuration for remote */ - if ((pk_file == NULL) &&(pk_ascii == NULL)) + if ((pk_file == NULL) && (pk_ascii == NULL)) { /* It is expected what remote may have verification file as * a part of configuration. Hence there is not a lot of sense @@ -95,7 +89,8 @@ _signapi_load_public_keys (OstreeSign *sign, * specific for signature type. */ if (required) - return glnx_throw (error, "No keys found for required signapi type %s", ostree_sign_get_name (sign)); + return glnx_throw (error, "No keys found for required signapi type %s", + ostree_sign_get_name (sign)); return TRUE; } @@ -121,7 +116,7 @@ _signapi_load_public_keys (OstreeSign *sign, if (pk_ascii != NULL) { g_autoptr (GError) local_error = NULL; - g_autoptr (GVariant) pk = g_variant_new_string(pk_ascii); + g_autoptr (GVariant) pk = g_variant_new_string (pk_ascii); /* Add inlined public key */ if (loaded_from_file) @@ -144,10 +139,11 @@ _signapi_load_public_keys (OstreeSign *sign, } static gboolean -string_is_gkeyfile_truthy (const char *value, - gboolean *out_truth) +string_is_gkeyfile_truthy (const char *value, gboolean *out_truth) { - /* See https://gitlab.gnome.org/GNOME/glib/-/blob/20fb5bf868added5aec53c013ae85ec78ba2eedc/glib/gkeyfile.c#L4528 */ + /* See + * https://gitlab.gnome.org/GNOME/glib/-/blob/20fb5bf868added5aec53c013ae85ec78ba2eedc/glib/gkeyfile.c#L4528 + */ if (g_str_equal (value, "true") || g_str_equal (value, "1")) { *out_truth = TRUE; @@ -162,18 +158,13 @@ string_is_gkeyfile_truthy (const char *value, } static gboolean -verifiers_from_config (OstreeRepo *repo, - const char *remote_name, - const char *key, - GPtrArray **out_verifiers, - GError **error) +verifiers_from_config (OstreeRepo *repo, const char *remote_name, const char *key, + GPtrArray **out_verifiers, GError **error) { - g_autoptr(GPtrArray) verifiers = NULL; + g_autoptr (GPtrArray) verifiers = NULL; g_autofree char *raw_value = NULL; - if (!ostree_repo_get_remote_option (repo, remote_name, - key, NULL, - &raw_value, error)) + if (!ostree_repo_get_remote_option (repo, remote_name, key, NULL, &raw_value, error)) return FALSE; if (raw_value == NULL || g_str_equal (raw_value, "")) { @@ -204,12 +195,10 @@ verifiers_from_config (OstreeRepo *repo, else { /* If the value isn't "truthy", then it must be an explicit list */ - g_auto(GStrv) sign_types = NULL; - if (!ostree_repo_get_remote_list_option (repo, remote_name, - key, &sign_types, - error)) + g_auto (GStrv) sign_types = NULL; + if (!ostree_repo_get_remote_list_option (repo, remote_name, key, &sign_types, error)) return FALSE; - verifiers = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); + verifiers = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref); for (char **iter = sign_types; iter && *iter; iter++) { const char *sign_type = *iter; @@ -233,14 +222,12 @@ verifiers_from_config (OstreeRepo *repo, * the resulting verifier list will be NULL. */ gboolean -_signapi_init_for_remote (OstreeRepo *repo, - const char *remote_name, - GPtrArray **out_commit_verifiers, - GPtrArray **out_summary_verifiers, - GError **error) +_signapi_init_for_remote (OstreeRepo *repo, const char *remote_name, + GPtrArray **out_commit_verifiers, GPtrArray **out_summary_verifiers, + GError **error) { - g_autoptr(GPtrArray) commit_verifiers = NULL; - g_autoptr(GPtrArray) summary_verifiers = NULL; + g_autoptr (GPtrArray) commit_verifiers = NULL; + g_autoptr (GPtrArray) summary_verifiers = NULL; if (!verifiers_from_config (repo, remote_name, "sign-verify", &commit_verifiers, error)) return FALSE; @@ -256,11 +243,8 @@ _signapi_init_for_remote (OstreeRepo *repo, * by at least one. */ gboolean -_sign_verify_for_remote (GPtrArray *verifiers, - GBytes *signed_data, - GVariant *metadata, - char **out_success_message, - GError **error) +_sign_verify_for_remote (GPtrArray *verifiers, GBytes *signed_data, GVariant *metadata, + char **out_success_message, GError **error) { guint n_invalid_signatures = 0; g_autoptr (GError) last_sig_error = NULL; @@ -274,9 +258,9 @@ _sign_verify_for_remote (GPtrArray *verifiers, { OstreeSign *sign = verifiers->pdata[i]; const gchar *signature_key = ostree_sign_metadata_key (sign); - GVariantType *signature_format = (GVariantType *) ostree_sign_metadata_format (sign); - g_autoptr (GVariant) signatures = - g_variant_lookup_value (metadata, signature_key, signature_format); + GVariantType *signature_format = (GVariantType *)ostree_sign_metadata_format (sign); + g_autoptr (GVariant) signatures + = g_variant_lookup_value (metadata, signature_key, signature_format); /* If not found signatures for requested signature subsystem */ if (!signatures) @@ -285,12 +269,9 @@ _sign_verify_for_remote (GPtrArray *verifiers, found_sig = TRUE; g_autofree char *success_message = NULL; - /* Return true if any signature fit to pre-loaded public keys. - * If no keys configured -- then system configuration will be used */ - if (!ostree_sign_data_verify (sign, - signed_data, - signatures, - &success_message, + /* Return true if any signature fit to pre-loaded public keys. + * If no keys configured -- then system configuration will be used */ + if (!ostree_sign_data_verify (sign, signed_data, signatures, &success_message, last_sig_error ? NULL : &last_sig_error)) { n_invalid_signatures++; @@ -308,32 +289,26 @@ _sign_verify_for_remote (GPtrArray *verifiers, g_assert (last_sig_error); g_propagate_error (error, g_steal_pointer (&last_sig_error)); if (n_invalid_signatures > 1) - glnx_prefix_error (error, "(%d other invalid signatures)", n_invalid_signatures-1); + glnx_prefix_error (error, "(%d other invalid signatures)", n_invalid_signatures - 1); return FALSE; } - #ifndef OSTREE_DISABLE_GPGME gboolean -_process_gpg_verify_result (OtPullData *pull_data, - const char *checksum, - OstreeGpgVerifyResult *result, - GError **error) +_process_gpg_verify_result (OtPullData *pull_data, const char *checksum, + OstreeGpgVerifyResult *result, GError **error) { const char *error_prefix = glnx_strjoina ("Commit ", checksum); - GLNX_AUTO_PREFIX_ERROR(error_prefix, error); + GLNX_AUTO_PREFIX_ERROR (error_prefix, error); if (result == NULL) return FALSE; /* Allow callers to output the results immediately. */ - g_signal_emit_by_name (pull_data->repo, - "gpg-verify-result", - checksum, result); + g_signal_emit_by_name (pull_data->repo, "gpg-verify-result", checksum, result); if (!ostree_gpg_verify_result_require_valid_signature (result, error)) return FALSE; - /* We now check both *before* writing the commit, and after. Because the * behavior used to be only verifiying after writing, we need to handle * the case of "written but not verified". But we also don't want to check @@ -350,7 +325,9 @@ validate_metadata_size (const char *prefix, GBytes *buf, GError **error) { gsize len = g_bytes_get_size (buf); if (len > OSTREE_MAX_METADATA_SIZE) - return glnx_throw (error, "%s is %" G_GUINT64_FORMAT " bytes, exceeding maximum %" G_GUINT64_FORMAT, prefix, (guint64)len, (guint64)OSTREE_MAX_METADATA_SIZE); + return glnx_throw (error, + "%s is %" G_GUINT64_FORMAT " bytes, exceeding maximum %" G_GUINT64_FORMAT, + prefix, (guint64)len, (guint64)OSTREE_MAX_METADATA_SIZE); return TRUE; } @@ -369,13 +346,10 @@ validate_metadata_size (const char *prefix, GBytes *buf, GError **error) * both enabled, then both must find at least one valid signature. */ gboolean -ostree_repo_signature_verify_commit_data (OstreeRepo *self, - const char *remote_name, - GBytes *commit_data, - GBytes *commit_metadata, - OstreeRepoVerifyFlags flags, - char **out_results, - GError **error) +ostree_repo_signature_verify_commit_data (OstreeRepo *self, const char *remote_name, + GBytes *commit_data, GBytes *commit_metadata, + OstreeRepoVerifyFlags flags, char **out_results, + GError **error) { g_assert (self); g_assert (remote_name); @@ -394,20 +368,20 @@ ostree_repo_signature_verify_commit_data (OstreeRepo *self, return glnx_throw (error, "Can't verify commit without detached metadata"); if (!validate_metadata_size ("Commit metadata", commit_metadata, error)) return FALSE; - g_autoptr(GVariant) commit_metadata_v = g_variant_new_from_bytes (G_VARIANT_TYPE_VARDICT, commit_metadata, FALSE); + g_autoptr (GVariant) commit_metadata_v + = g_variant_new_from_bytes (G_VARIANT_TYPE_VARDICT, commit_metadata, FALSE); - g_autoptr(GString) results_buf = g_string_new (""); + g_autoptr (GString) results_buf = g_string_new (""); gboolean verified = FALSE; if (gpg) { - if (!ostree_repo_remote_get_gpg_verify (self, remote_name, - &gpg, error)) + if (!ostree_repo_remote_get_gpg_verify (self, remote_name, &gpg, error)) return FALSE; } /* TODO - we could cache this in the repo */ - g_autoptr(GPtrArray) signapi_verifiers = NULL; + g_autoptr (GPtrArray) signapi_verifiers = NULL; if (signapi) { if (!_signapi_init_for_remote (self, remote_name, &signapi_verifiers, NULL, error)) @@ -415,16 +389,16 @@ ostree_repo_signature_verify_commit_data (OstreeRepo *self, } if (!(gpg || signapi_verifiers)) - return glnx_throw (error, "Cannot verify commit for remote %s; GPG verification disabled, and no signapi verifiers configured", remote_name); + return glnx_throw (error, + "Cannot verify commit for remote %s; GPG verification disabled, and no " + "signapi verifiers configured", + remote_name); #ifndef OSTREE_DISABLE_GPGME if (gpg) { - g_autoptr(OstreeGpgVerifyResult) result = - _ostree_repo_gpg_verify_with_metadata (self, commit_data, - commit_metadata_v, - remote_name, - NULL, NULL, NULL, error); + g_autoptr (OstreeGpgVerifyResult) result = _ostree_repo_gpg_verify_with_metadata ( + self, commit_data, commit_metadata_v, remote_name, NULL, NULL, NULL, error); if (!result) return FALSE; if (!ostree_gpg_verify_result_require_valid_signature (result, error)) @@ -434,8 +408,8 @@ ostree_repo_signature_verify_commit_data (OstreeRepo *self, g_assert_cmpuint (n_signatures, >, 0); for (guint jj = 0; jj < n_signatures; jj++) { - ostree_gpg_verify_result_describe (result, jj, results_buf, "GPG: ", - OSTREE_GPG_SIGNATURE_FORMAT_DEFAULT); + ostree_gpg_verify_result_describe (result, jj, results_buf, + "GPG: ", OSTREE_GPG_SIGNATURE_FORMAT_DEFAULT); } verified = TRUE; } @@ -444,7 +418,8 @@ ostree_repo_signature_verify_commit_data (OstreeRepo *self, if (signapi_verifiers) { g_autofree char *success_message = NULL; - if (!_sign_verify_for_remote (signapi_verifiers, commit_data, commit_metadata_v, &success_message, error)) + if (!_sign_verify_for_remote (signapi_verifiers, commit_data, commit_metadata_v, + &success_message, error)) return glnx_prefix_error (error, "Can't verify commit"); if (verified) g_string_append_c (results_buf, '\n'); @@ -460,20 +435,17 @@ ostree_repo_signature_verify_commit_data (OstreeRepo *self, } gboolean -_verify_unwritten_commit (OtPullData *pull_data, - const char *checksum, - GVariant *commit, - GVariant *detached_metadata, - const OstreeCollectionRef *ref, - GCancellable *cancellable, - GError **error) +_verify_unwritten_commit (OtPullData *pull_data, const char *checksum, GVariant *commit, + GVariant *detached_metadata, const OstreeCollectionRef *ref, + GCancellable *cancellable, GError **error) { /* Shouldn't happen, but see comment in process_gpg_verify_result() */ if ((!pull_data->gpg_verify || g_hash_table_contains (pull_data->verified_commits, checksum)) - && (!pull_data->signapi_commit_verifiers || g_hash_table_contains (pull_data->signapi_verified_commits, checksum))) + && (!pull_data->signapi_commit_verifiers + || g_hash_table_contains (pull_data->signapi_verified_commits, checksum))) return TRUE; - g_autoptr(GBytes) signed_data = g_variant_get_data_as_bytes (commit); + g_autoptr (GBytes) signed_data = g_variant_get_data_as_bytes (commit); #ifndef OSTREE_DISABLE_GPGME if (pull_data->gpg_verify) @@ -485,11 +457,9 @@ _verify_unwritten_commit (OtPullData *pull_data, if (keyring_remote == NULL) keyring_remote = pull_data->remote_name; - g_autoptr(OstreeGpgVerifyResult) result = - _ostree_repo_gpg_verify_with_metadata (pull_data->repo, signed_data, - detached_metadata, - keyring_remote, - NULL, NULL, cancellable, error); + g_autoptr (OstreeGpgVerifyResult) result + = _ostree_repo_gpg_verify_with_metadata (pull_data->repo, signed_data, detached_metadata, + keyring_remote, NULL, NULL, cancellable, error); if (!_process_gpg_verify_result (pull_data, checksum, result, error)) return FALSE; } @@ -502,12 +472,14 @@ _verify_unwritten_commit (OtPullData *pull_data, return glnx_throw (error, "Can't verify commit without detached metadata"); g_autofree char *success_message = NULL; - if (!_sign_verify_for_remote (pull_data->signapi_commit_verifiers, signed_data, detached_metadata, &success_message, error)) + if (!_sign_verify_for_remote (pull_data->signapi_commit_verifiers, signed_data, + detached_metadata, &success_message, error)) return glnx_prefix_error (error, "Can't verify commit"); /* Mark the commit as verified to avoid double verification * see process_verify_result () for rationale */ - g_hash_table_insert (pull_data->signapi_verified_commits, g_strdup (checksum), g_steal_pointer (&success_message)); + g_hash_table_insert (pull_data->signapi_verified_commits, g_strdup (checksum), + g_steal_pointer (&success_message)); } return TRUE; diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c index 77aa452e..7c0598a8 100644 --- a/src/libostree/ostree-repo-pull.c +++ b/src/libostree/ostree-repo-pull.c @@ -26,22 +26,22 @@ #include "config.h" #include "libglnx.h" +#include "ostree-repo-pull-private.h" #include "ostree.h" #include "otutil.h" -#include "ostree-repo-pull-private.h" #ifdef HAVE_LIBCURL_OR_LIBSOUP #include "ostree-core-private.h" -#include "ostree-repo-static-delta-private.h" #include "ostree-metalink.h" +#include "ostree-repo-static-delta-private.h" -#include "ostree-repo-finder.h" #include "ostree-repo-finder-config.h" #include "ostree-repo-finder-mount.h" +#include "ostree-repo-finder.h" #ifdef HAVE_AVAHI #include "ostree-repo-finder-avahi.h" -#endif /* HAVE_AVAHI */ +#endif /* HAVE_AVAHI */ #include #include @@ -50,9 +50,10 @@ #include #endif -#define OSTREE_MESSAGE_FETCH_COMPLETE_ID SD_ID128_MAKE(75,ba,3d,eb,0a,f0,41,a9,a4,62,72,ff,85,d9,e7,3e) +#define OSTREE_MESSAGE_FETCH_COMPLETE_ID \ + SD_ID128_MAKE (75, ba, 3d, eb, 0a, f0, 41, a9, a4, 62, 72, ff, 85, d9, e7, 3e) -#define OSTREE_REPO_PULL_CONTENT_PRIORITY (OSTREE_FETCHER_DEFAULT_PRIORITY) +#define OSTREE_REPO_PULL_CONTENT_PRIORITY (OSTREE_FETCHER_DEFAULT_PRIORITY) #define OSTREE_REPO_PULL_METADATA_PRIORITY (OSTREE_REPO_PULL_CONTENT_PRIORITY - 100) /* Arbitrarily chosen number of retries for all download operations when they @@ -61,23 +62,25 @@ * `n-network-retries` pull option. */ #define DEFAULT_N_NETWORK_RETRIES 5 -typedef struct { - OtPullData *pull_data; - GVariant *object; - char *path; - gboolean is_detached_meta; +typedef struct +{ + OtPullData *pull_data; + GVariant *object; + char *path; + gboolean is_detached_meta; /* Only relevant when is_detached_meta is TRUE. Controls * whether to fetch the primary object after fetching its * detached metadata (no need if it's already stored). */ - gboolean object_is_stored; + gboolean object_is_stored; - OstreeCollectionRef *requested_ref; /* (nullable) */ + OstreeCollectionRef *requested_ref; /* (nullable) */ guint n_retries_remaining; } FetchObjectData; -typedef struct { - OtPullData *pull_data; +typedef struct +{ + OtPullData *pull_data; GVariant *objects; char *expected_checksum; char *from_revision; @@ -87,27 +90,30 @@ typedef struct { guint n_retries_remaining; } FetchStaticDeltaData; -typedef struct { +typedef struct +{ guchar csum[OSTREE_SHA256_DIGEST_LEN]; char *path; OstreeObjectType objtype; - guint recursion_depth; /* NB: not used anymore, though might be nice to print */ - OstreeCollectionRef *requested_ref; /* (nullable) */ + guint recursion_depth; /* NB: not used anymore, though might be nice to print */ + OstreeCollectionRef *requested_ref; /* (nullable) */ } ScanObjectQueueData; -typedef struct { +typedef struct +{ OtPullData *pull_data; char *from_revision; char *to_revision; - OstreeCollectionRef *requested_ref; /* (nullable) */ + OstreeCollectionRef *requested_ref; /* (nullable) */ guint n_retries_remaining; } FetchDeltaSuperData; -typedef struct { +typedef struct +{ OtPullData *pull_data; char *from_revision; char *to_revision; - OstreeCollectionRef *requested_ref; /* (nullable) */ + OstreeCollectionRef *requested_ref; /* (nullable) */ guint n_retries_remaining; } FetchDeltaIndexData; @@ -119,53 +125,38 @@ variant_or_null_unref (gpointer data) } static void start_fetch (OtPullData *pull_data, FetchObjectData *fetch); -static void start_fetch_deltapart (OtPullData *pull_data, - FetchStaticDeltaData *fetch); -static void start_fetch_delta_superblock (OtPullData *pull_data, - FetchDeltaSuperData *fetch_data); -static void start_fetch_delta_index (OtPullData *pull_data, - FetchDeltaIndexData *fetch_data); +static void start_fetch_deltapart (OtPullData *pull_data, FetchStaticDeltaData *fetch); +static void start_fetch_delta_superblock (OtPullData *pull_data, FetchDeltaSuperData *fetch_data); +static void start_fetch_delta_index (OtPullData *pull_data, FetchDeltaIndexData *fetch_data); static gboolean fetcher_queue_is_full (OtPullData *pull_data); -static void queue_scan_one_metadata_object (OtPullData *pull_data, - const char *csum, - OstreeObjectType objtype, - const char *path, - guint recursion_depth, - const OstreeCollectionRef *ref); - -static void queue_scan_one_metadata_object_s (OtPullData *pull_data, - ScanObjectQueueData *scan_data); -static void queue_scan_one_metadata_object_c (OtPullData *pull_data, - const guchar *csum, - OstreeObjectType objtype, - const char *path, - guint recursion_depth, +static void queue_scan_one_metadata_object (OtPullData *pull_data, const char *csum, + OstreeObjectType objtype, const char *path, + guint recursion_depth, const OstreeCollectionRef *ref); + +static void queue_scan_one_metadata_object_s (OtPullData *pull_data, + ScanObjectQueueData *scan_data); +static void queue_scan_one_metadata_object_c (OtPullData *pull_data, const guchar *csum, + OstreeObjectType objtype, const char *path, + guint recursion_depth, const OstreeCollectionRef *ref); -static void enqueue_one_object_request_s (OtPullData *pull_data, - FetchObjectData *fetch_data); -static void enqueue_one_static_delta_index_request_s (OtPullData *pull_data, +static void enqueue_one_object_request_s (OtPullData *pull_data, FetchObjectData *fetch_data); +static void enqueue_one_static_delta_index_request_s (OtPullData *pull_data, FetchDeltaIndexData *fetch_data); -static void enqueue_one_static_delta_superblock_request_s (OtPullData *pull_data, +static void enqueue_one_static_delta_superblock_request_s (OtPullData *pull_data, FetchDeltaSuperData *fetch_data); -static void enqueue_one_static_delta_part_request_s (OtPullData *pull_data, +static void enqueue_one_static_delta_part_request_s (OtPullData *pull_data, FetchStaticDeltaData *fetch_data); static void ensure_idle_queued (OtPullData *pull_data); -static gboolean scan_one_metadata_object (OtPullData *pull_data, - const char *checksum, - OstreeObjectType objtype, - const char *path, - guint recursion_depth, - const OstreeCollectionRef *ref, - GCancellable *cancellable, - GError **error); +static gboolean scan_one_metadata_object (OtPullData *pull_data, const char *checksum, + OstreeObjectType objtype, const char *path, + guint recursion_depth, const OstreeCollectionRef *ref, + GCancellable *cancellable, GError **error); static void scan_object_queue_data_free (ScanObjectQueueData *scan_data); -static gboolean initiate_delta_request (OtPullData *pull_data, - const OstreeCollectionRef *ref, - const char *to_revision, - const char *delta_from_revision, - GError **error); +static gboolean initiate_delta_request (OtPullData *pull_data, const OstreeCollectionRef *ref, + const char *to_revision, const char *delta_from_revision, + GError **error); static gboolean update_progress (gpointer user_data) @@ -181,63 +172,51 @@ update_progress (gpointer user_data) pull_data = user_data; - if (! pull_data->progress) + if (!pull_data->progress) return FALSE; /* In dry run, we only emit progress once metadata is done */ if (pull_data->dry_run && pull_data->n_outstanding_metadata_fetches > 0) return TRUE; - outstanding_writes = pull_data->n_outstanding_content_write_requests + - pull_data->n_outstanding_metadata_write_requests + - pull_data->n_outstanding_deltapart_write_requests; - outstanding_fetches = pull_data->n_outstanding_content_fetches + - pull_data->n_outstanding_metadata_fetches + - pull_data->n_outstanding_deltapart_fetches; + outstanding_writes = pull_data->n_outstanding_content_write_requests + + pull_data->n_outstanding_metadata_write_requests + + pull_data->n_outstanding_deltapart_write_requests; + outstanding_fetches = pull_data->n_outstanding_content_fetches + + pull_data->n_outstanding_metadata_fetches + + pull_data->n_outstanding_deltapart_fetches; bytes_transferred = _ostree_fetcher_bytes_transferred (pull_data->fetcher); fetched = pull_data->n_fetched_metadata + pull_data->n_fetched_content; requested = pull_data->n_requested_metadata + pull_data->n_requested_content; n_scanned_metadata = pull_data->n_scanned_metadata; start_time = pull_data->start_time; - ostree_async_progress_set (pull_data->progress, - "outstanding-fetches", "u", outstanding_fetches, - "outstanding-writes", "u", outstanding_writes, - "fetched", "u", fetched, - "requested", "u", requested, - "scanning", "u", g_queue_is_empty (&pull_data->scan_object_queue) ? 0 : 1, - "caught-error", "b", pull_data->caught_error, - "scanned-metadata", "u", n_scanned_metadata, - "bytes-transferred", "t", bytes_transferred, - "start-time", "t", start_time, - /* We use these status keys even though we now also - * use these values for filesystem-local pulls. - */ - "metadata-fetched-localcache", "u", pull_data->n_imported_metadata, - "content-fetched-localcache", "u", pull_data->n_imported_content, - /* Deltas */ - "fetched-delta-parts", - "u", pull_data->n_fetched_deltaparts, - "total-delta-parts", - "u", pull_data->n_total_deltaparts, - "fetched-delta-fallbacks", - "u", pull_data->n_fetched_deltapart_fallbacks, - "total-delta-fallbacks", - "u", pull_data->n_total_delta_fallbacks, - "fetched-delta-part-size", - "t", pull_data->fetched_deltapart_size, - "total-delta-part-size", - "t", pull_data->total_deltapart_size, - "total-delta-part-usize", - "t", pull_data->total_deltapart_usize, - "total-delta-superblocks", - "u", pull_data->static_delta_superblocks->len, - /* We fetch metadata before content. These allow us to report metadata fetch progress specifically. */ - "outstanding-metadata-fetches", "u", pull_data->n_outstanding_metadata_fetches, - "metadata-fetched", "u", pull_data->n_fetched_metadata, - /* Overall status. */ - "status", "s", "", - NULL); + ostree_async_progress_set ( + pull_data->progress, "outstanding-fetches", "u", outstanding_fetches, "outstanding-writes", + "u", outstanding_writes, "fetched", "u", fetched, "requested", "u", requested, "scanning", + "u", g_queue_is_empty (&pull_data->scan_object_queue) ? 0 : 1, "caught-error", "b", + pull_data->caught_error, "scanned-metadata", "u", n_scanned_metadata, "bytes-transferred", + "t", bytes_transferred, "start-time", "t", start_time, + /* We use these status keys even though we now also + * use these values for filesystem-local pulls. + */ + "metadata-fetched-localcache", "u", pull_data->n_imported_metadata, + "content-fetched-localcache", "u", pull_data->n_imported_content, + /* Deltas */ + "fetched-delta-parts", "u", pull_data->n_fetched_deltaparts, "total-delta-parts", "u", + pull_data->n_total_deltaparts, "fetched-delta-fallbacks", "u", + pull_data->n_fetched_deltapart_fallbacks, "total-delta-fallbacks", "u", + pull_data->n_total_delta_fallbacks, "fetched-delta-part-size", "t", + pull_data->fetched_deltapart_size, "total-delta-part-size", "t", + pull_data->total_deltapart_size, "total-delta-part-usize", "t", + pull_data->total_deltapart_usize, "total-delta-superblocks", "u", + pull_data->static_delta_superblocks->len, + /* We fetch metadata before content. These allow us to report metadata fetch progress + specifically. */ + "outstanding-metadata-fetches", "u", pull_data->n_outstanding_metadata_fetches, + "metadata-fetched", "u", pull_data->n_fetched_metadata, + /* Overall status. */ + "status", "s", "", NULL); if (pull_data->dry_run) pull_data->dry_run_emitted_progress = TRUE; @@ -247,14 +226,14 @@ update_progress (gpointer user_data) /* The core logic function for whether we should continue the main loop */ static gboolean -pull_termination_condition (OtPullData *pull_data) +pull_termination_condition (OtPullData *pull_data) { - gboolean current_fetch_idle = (pull_data->n_outstanding_metadata_fetches == 0 && - pull_data->n_outstanding_content_fetches == 0 && - pull_data->n_outstanding_deltapart_fetches == 0); - gboolean current_write_idle = (pull_data->n_outstanding_metadata_write_requests == 0 && - pull_data->n_outstanding_content_write_requests == 0 && - pull_data->n_outstanding_deltapart_write_requests == 0 ); + gboolean current_fetch_idle = (pull_data->n_outstanding_metadata_fetches == 0 + && pull_data->n_outstanding_content_fetches == 0 + && pull_data->n_outstanding_deltapart_fetches == 0); + gboolean current_write_idle = (pull_data->n_outstanding_metadata_write_requests == 0 + && pull_data->n_outstanding_content_write_requests == 0 + && pull_data->n_outstanding_deltapart_write_requests == 0); gboolean current_scan_idle = g_queue_is_empty (&pull_data->scan_object_queue); gboolean current_idle = current_fetch_idle && current_write_idle && current_scan_idle; @@ -275,8 +254,7 @@ pull_termination_condition (OtPullData *pull_data) * requests as appropriate. */ static void -check_outstanding_requests_handle_error (OtPullData *pull_data, - GError **errorp) +check_outstanding_requests_handle_error (OtPullData *pull_data, GError **errorp) { g_assert (errorp); @@ -301,7 +279,7 @@ check_outstanding_requests_handle_error (OtPullData *pull_data, */ if (pull_data->caught_error) { - g_queue_foreach (&pull_data->scan_object_queue, (GFunc) scan_object_queue_data_free, NULL); + g_queue_foreach (&pull_data->scan_object_queue, (GFunc)scan_object_queue_data_free, NULL); g_queue_clear (&pull_data->scan_object_queue); g_hash_table_remove_all (pull_data->pending_fetch_metadata); g_hash_table_remove_all (pull_data->pending_fetch_delta_indexes); @@ -323,8 +301,7 @@ check_outstanding_requests_handle_error (OtPullData *pull_data, /* Try filling the queue with metadata we need to fetch */ g_hash_table_iter_init (&hiter, pull_data->pending_fetch_metadata); - while (!fetcher_queue_is_full (pull_data) && - g_hash_table_iter_next (&hiter, &key, &value)) + while (!fetcher_queue_is_full (pull_data) && g_hash_table_iter_next (&hiter, &key, &value)) { GVariant *objname = key; FetchObjectData *fetch = value; @@ -340,8 +317,7 @@ check_outstanding_requests_handle_error (OtPullData *pull_data, /* Next, process delta index requests */ g_hash_table_iter_init (&hiter, pull_data->pending_fetch_delta_indexes); - while (!fetcher_queue_is_full (pull_data) && - g_hash_table_iter_next (&hiter, &key, &value)) + while (!fetcher_queue_is_full (pull_data) && g_hash_table_iter_next (&hiter, &key, &value)) { FetchDeltaIndexData *fetch = key; g_hash_table_iter_steal (&hiter); @@ -350,8 +326,7 @@ check_outstanding_requests_handle_error (OtPullData *pull_data, /* Next, process delta superblock requests */ g_hash_table_iter_init (&hiter, pull_data->pending_fetch_delta_superblocks); - while (!fetcher_queue_is_full (pull_data) && - g_hash_table_iter_next (&hiter, &key, &value)) + while (!fetcher_queue_is_full (pull_data) && g_hash_table_iter_next (&hiter, &key, &value)) { FetchDeltaSuperData *fetch = key; g_hash_table_iter_steal (&hiter); @@ -360,8 +335,7 @@ check_outstanding_requests_handle_error (OtPullData *pull_data, /* Now, process deltapart requests */ g_hash_table_iter_init (&hiter, pull_data->pending_fetch_deltaparts); - while (!fetcher_queue_is_full (pull_data) && - g_hash_table_iter_next (&hiter, &key, &value)) + while (!fetcher_queue_is_full (pull_data) && g_hash_table_iter_next (&hiter, &key, &value)) { FetchStaticDeltaData *fetch = key; g_hash_table_iter_steal (&hiter); @@ -371,8 +345,7 @@ check_outstanding_requests_handle_error (OtPullData *pull_data, /* Next, fill the queue with content */ g_hash_table_iter_init (&hiter, pull_data->pending_fetch_content); - while (!fetcher_queue_is_full (pull_data) && - g_hash_table_iter_next (&hiter, &key, &value)) + while (!fetcher_queue_is_full (pull_data) && g_hash_table_iter_next (&hiter, &key, &value)) { char *checksum = key; FetchObjectData *fetch = value; @@ -400,19 +373,16 @@ check_outstanding_requests_handle_error (OtPullData *pull_data, static gboolean fetcher_queue_is_full (OtPullData *pull_data) { - const gboolean fetch_full = - ((pull_data->n_outstanding_metadata_fetches + - pull_data->n_outstanding_content_fetches + - pull_data->n_outstanding_deltapart_fetches) == - _OSTREE_MAX_OUTSTANDING_FETCHER_REQUESTS); - const gboolean deltas_full = - (pull_data->n_outstanding_deltapart_fetches == - _OSTREE_MAX_OUTSTANDING_DELTAPART_REQUESTS); - const gboolean writes_full = - ((pull_data->n_outstanding_metadata_write_requests + - pull_data->n_outstanding_content_write_requests + - pull_data->n_outstanding_deltapart_write_requests) >= - _OSTREE_MAX_OUTSTANDING_WRITE_REQUESTS); + const gboolean fetch_full + = ((pull_data->n_outstanding_metadata_fetches + pull_data->n_outstanding_content_fetches + + pull_data->n_outstanding_deltapart_fetches) + == _OSTREE_MAX_OUTSTANDING_FETCHER_REQUESTS); + const gboolean deltas_full + = (pull_data->n_outstanding_deltapart_fetches == _OSTREE_MAX_OUTSTANDING_DELTAPART_REQUESTS); + const gboolean writes_full = ((pull_data->n_outstanding_metadata_write_requests + + pull_data->n_outstanding_content_write_requests + + pull_data->n_outstanding_deltapart_write_requests) + >= _OSTREE_MAX_OUTSTANDING_WRITE_REQUESTS); return fetch_full || deltas_full || writes_full; } @@ -435,7 +405,7 @@ idle_worker (gpointer user_data) { OtPullData *pull_data = user_data; ScanObjectQueueData *scan_data; - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; scan_data = g_queue_pop_head (&pull_data->scan_object_queue); if (!scan_data) @@ -444,11 +414,11 @@ idle_worker (gpointer user_data) return G_SOURCE_REMOVE; } - char checksum[OSTREE_SHA256_STRING_LEN+1]; + char checksum[OSTREE_SHA256_STRING_LEN + 1]; ostree_checksum_inplace_from_bytes (scan_data->csum, checksum); - scan_one_metadata_object (pull_data, checksum, scan_data->objtype, - scan_data->path, scan_data->recursion_depth, - scan_data->requested_ref, pull_data->cancellable, &error); + scan_one_metadata_object (pull_data, checksum, scan_data->objtype, scan_data->path, + scan_data->recursion_depth, scan_data->requested_ref, + pull_data->cancellable, &error); /* No need to retry scan tasks, since they’re local. */ check_outstanding_requests_handle_error (pull_data, &error); @@ -477,28 +447,23 @@ ensure_idle_queued (OtPullData *pull_data) g_source_unref (idle_src); } -typedef struct { - OtPullData *pull_data; - GInputStream *result_stream; +typedef struct +{ + OtPullData *pull_data; + GInputStream *result_stream; } OstreeFetchUriSyncData; static gboolean -fetch_mirrored_uri_contents_utf8_sync (OstreeFetcher *fetcher, - GPtrArray *mirrorlist, - const char *filename, - guint n_network_retries, - char **out_contents, - GCancellable *cancellable, - GError **error) +fetch_mirrored_uri_contents_utf8_sync (OstreeFetcher *fetcher, GPtrArray *mirrorlist, + const char *filename, guint n_network_retries, + char **out_contents, GCancellable *cancellable, + GError **error) { - g_autoptr(GBytes) bytes = NULL; - if (!_ostree_fetcher_mirrored_request_to_membuf (fetcher, mirrorlist, - filename, OSTREE_FETCHER_REQUEST_NUL_TERMINATION, - NULL, 0, - n_network_retries, - &bytes, NULL, NULL, NULL, - OSTREE_MAX_METADATA_SIZE, - cancellable, error)) + g_autoptr (GBytes) bytes = NULL; + if (!_ostree_fetcher_mirrored_request_to_membuf (fetcher, mirrorlist, filename, + OSTREE_FETCHER_REQUEST_NUL_TERMINATION, NULL, 0, + n_network_retries, &bytes, NULL, NULL, NULL, + OSTREE_MAX_METADATA_SIZE, cancellable, error)) return FALSE; gsize len; @@ -512,34 +477,23 @@ fetch_mirrored_uri_contents_utf8_sync (OstreeFetcher *fetcher, } static gboolean -fetch_uri_contents_utf8_sync (OstreeFetcher *fetcher, - OstreeFetcherURI *uri, - guint n_network_retries, - char **out_contents, - GCancellable *cancellable, - GError **error) +fetch_uri_contents_utf8_sync (OstreeFetcher *fetcher, OstreeFetcherURI *uri, + guint n_network_retries, char **out_contents, + 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 fetch_mirrored_uri_contents_utf8_sync (fetcher, mirrorlist, - NULL, n_network_retries, - out_contents, - cancellable, error); + return fetch_mirrored_uri_contents_utf8_sync (fetcher, mirrorlist, NULL, n_network_retries, + out_contents, cancellable, error); } -static void -enqueue_one_object_request (OtPullData *pull_data, - const char *checksum, - OstreeObjectType objtype, - const char *path, - gboolean is_detached_meta, - gboolean object_is_stored, - const OstreeCollectionRef *ref); +static void enqueue_one_object_request (OtPullData *pull_data, const char *checksum, + OstreeObjectType objtype, const char *path, + gboolean is_detached_meta, gboolean object_is_stored, + const OstreeCollectionRef *ref); static gboolean -matches_pull_dir (const char *current_file, - const char *pull_dir, - gboolean current_file_is_dir) +matches_pull_dir (const char *current_file, const char *pull_dir, gboolean current_file_is_dir) { const char *rest; @@ -577,11 +531,8 @@ matches_pull_dir (const char *current_file, return FALSE; } - static gboolean -pull_matches_subdir (OtPullData *pull_data, - const char *path, - const char *basename, +pull_matches_subdir (OtPullData *pull_data, const char *path, const char *basename, gboolean basename_is_dir) { if (pull_data->dirs == NULL) @@ -599,28 +550,26 @@ pull_matches_subdir (OtPullData *pull_data, return FALSE; } -typedef struct { +typedef struct +{ OtPullData *pull_data; OstreeRepo *src_repo; - char checksum[OSTREE_SHA256_STRING_LEN+1]; + char checksum[OSTREE_SHA256_STRING_LEN + 1]; } ImportLocalAsyncData; /* Asynchronously import a single content object. @src_repo is either * pull_data->remote_repo_local or one of pull_data->localcache_repos. */ static void -async_import_in_thread (GTask *task, - gpointer source, - gpointer task_data, - GCancellable *cancellable) +async_import_in_thread (GTask *task, gpointer source, gpointer task_data, GCancellable *cancellable) { ImportLocalAsyncData *iataskdata = task_data; OtPullData *pull_data = iataskdata->pull_data; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; /* pull_data->importflags was set up in the pull option processing */ - if (!_ostree_repo_import_object (pull_data->repo, iataskdata->src_repo, - OSTREE_OBJECT_TYPE_FILE, iataskdata->checksum, - pull_data->importflags, cancellable, &local_error)) + if (!_ostree_repo_import_object (pull_data->repo, iataskdata->src_repo, OSTREE_OBJECT_TYPE_FILE, + iataskdata->checksum, pull_data->importflags, cancellable, + &local_error)) g_task_return_error (task, g_steal_pointer (&local_error)); else g_task_return_boolean (task, TRUE); @@ -634,18 +583,15 @@ async_import_in_thread (GTask *task, * OSTREE_REPO_PULL_FLAGS_BAREUSERONLY_FILES flag. */ static void -async_import_one_local_content_object (OtPullData *pull_data, - OstreeRepo *src_repo, - const char *checksum, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +async_import_one_local_content_object (OtPullData *pull_data, OstreeRepo *src_repo, + const char *checksum, GCancellable *cancellable, + GAsyncReadyCallback callback, gpointer user_data) { ImportLocalAsyncData *iataskdata = g_new0 (ImportLocalAsyncData, 1); iataskdata->pull_data = pull_data; iataskdata->src_repo = src_repo; memcpy (iataskdata->checksum, checksum, OSTREE_SHA256_STRING_LEN); - g_autoptr(GTask) task = g_task_new (pull_data->repo, cancellable, callback, user_data); + g_autoptr (GTask) task = g_task_new (pull_data->repo, cancellable, callback, user_data); g_task_set_source_tag (task, async_import_one_local_content_object); g_task_set_task_data (task, iataskdata, g_free); pull_data->n_outstanding_content_write_requests++; @@ -653,27 +599,24 @@ async_import_one_local_content_object (OtPullData *pull_data, } static gboolean -async_import_one_local_content_object_finish (OtPullData *pull_data, - GAsyncResult *result, +async_import_one_local_content_object_finish (OtPullData *pull_data, GAsyncResult *result, GError **error) { g_return_val_if_fail (g_task_is_valid (result, pull_data->repo), FALSE); - return g_task_propagate_boolean ((GTask*)result, error); + return g_task_propagate_boolean ((GTask *)result, error); } static void -on_local_object_imported (GObject *object, - GAsyncResult *result, - gpointer user_data) +on_local_object_imported (GObject *object, GAsyncResult *result, gpointer user_data) { OtPullData *pull_data = user_data; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; if (!async_import_one_local_content_object_finish (pull_data, result, error)) goto out; - out: +out: pull_data->n_imported_content++; g_assert_cmpint (pull_data->n_outstanding_content_write_requests, >, 0); pull_data->n_outstanding_content_write_requests--; @@ -682,26 +625,22 @@ on_local_object_imported (GObject *object, } static gboolean -scan_dirtree_object (OtPullData *pull_data, - const char *checksum, - const char *path, - int recursion_depth, - GCancellable *cancellable, - GError **error) +scan_dirtree_object (OtPullData *pull_data, const char *checksum, const char *path, + int recursion_depth, GCancellable *cancellable, GError **error) { - g_autoptr(GVariant) tree = NULL; - if (!ostree_repo_load_variant (pull_data->repo, OSTREE_OBJECT_TYPE_DIR_TREE, checksum, - &tree, error)) + g_autoptr (GVariant) tree = NULL; + if (!ostree_repo_load_variant (pull_data->repo, OSTREE_OBJECT_TYPE_DIR_TREE, checksum, &tree, + error)) return FALSE; /* PARSE OSTREE_SERIALIZED_TREE_VARIANT */ - g_autoptr(GVariant) files_variant = g_variant_get_child_value (tree, 0); + g_autoptr (GVariant) files_variant = g_variant_get_child_value (tree, 0); const guint n = g_variant_n_children (files_variant); for (guint i = 0; i < n; i++) { const char *filename; gboolean file_is_stored; - g_autoptr(GVariant) csum = NULL; + g_autoptr (GVariant) csum = NULL; g_autofree char *file_checksum = NULL; g_variant_get_child (files_variant, i, "(&s@ay)", &filename, &csum); @@ -739,8 +678,7 @@ scan_dirtree_object (OtPullData *pull_data, { async_import_one_local_content_object (pull_data, pull_data->remote_repo_local, file_checksum, cancellable, - on_local_object_imported, - pull_data); + on_local_object_imported, pull_data); g_hash_table_add (pull_data->requested_content, g_steal_pointer (&file_checksum)); /* Note early loop continue */ continue; @@ -760,8 +698,9 @@ scan_dirtree_object (OtPullData *pull_data, return FALSE; if (!localcache_repo_has_obj) continue; - async_import_one_local_content_object (pull_data, localcache_repo, file_checksum, cancellable, - on_local_object_imported, pull_data); + async_import_one_local_content_object (pull_data, localcache_repo, file_checksum, + cancellable, on_local_object_imported, + pull_data); g_hash_table_add (pull_data->requested_content, g_steal_pointer (&file_checksum)); did_import_from_cache_repo = TRUE; break; @@ -772,19 +711,19 @@ scan_dirtree_object (OtPullData *pull_data, /* Not available locally, queue a HTTP request */ g_hash_table_add (pull_data->requested_content, file_checksum); - enqueue_one_object_request (pull_data, file_checksum, OSTREE_OBJECT_TYPE_FILE, path, FALSE, FALSE, NULL); - file_checksum = NULL; /* Transfer ownership */ + enqueue_one_object_request (pull_data, file_checksum, OSTREE_OBJECT_TYPE_FILE, path, FALSE, + FALSE, NULL); + file_checksum = NULL; /* Transfer ownership */ } - g_autoptr(GVariant) dirs_variant = g_variant_get_child_value (tree, 1); + g_autoptr (GVariant) dirs_variant = g_variant_get_child_value (tree, 1); const guint m = g_variant_n_children (dirs_variant); for (guint i = 0; i < m; i++) { const char *dirname = NULL; - g_autoptr(GVariant) tree_csum = NULL; - g_autoptr(GVariant) meta_csum = NULL; - g_variant_get_child (dirs_variant, i, "(&s@ay@ay)", - &dirname, &tree_csum, &meta_csum); + g_autoptr (GVariant) tree_csum = NULL; + g_autoptr (GVariant) meta_csum = NULL; + g_variant_get_child (dirs_variant, i, "(&s@ay@ay)", &dirname, &tree_csum, &meta_csum); /* See comment above for files */ if (!ot_util_filename_validate (dirname, error)) @@ -802,10 +741,10 @@ scan_dirtree_object (OtPullData *pull_data, return FALSE; g_autofree char *subpath = g_strconcat (path, dirname, "/", NULL); - queue_scan_one_metadata_object_c (pull_data, tree_csum_bytes, - OSTREE_OBJECT_TYPE_DIR_TREE, subpath, recursion_depth + 1, NULL); - queue_scan_one_metadata_object_c (pull_data, meta_csum_bytes, - OSTREE_OBJECT_TYPE_DIR_META, subpath, recursion_depth + 1, NULL); + queue_scan_one_metadata_object_c (pull_data, tree_csum_bytes, OSTREE_OBJECT_TYPE_DIR_TREE, + subpath, recursion_depth + 1, NULL); + queue_scan_one_metadata_object_c (pull_data, meta_csum_bytes, OSTREE_OBJECT_TYPE_DIR_META, + subpath, recursion_depth + 1, NULL); } return TRUE; @@ -813,29 +752,23 @@ scan_dirtree_object (OtPullData *pull_data, /* Given a @ref, fetch its contents (should be a SHA256 ASCII string) */ static gboolean -fetch_ref_contents (OtPullData *pull_data, - const char *main_collection_id, - const OstreeCollectionRef *ref, - char **out_contents, - GCancellable *cancellable, - GError **error) +fetch_ref_contents (OtPullData *pull_data, const char *main_collection_id, + const OstreeCollectionRef *ref, char **out_contents, GCancellable *cancellable, + GError **error) { g_autofree char *ret_contents = NULL; if (pull_data->remote_repo_local != NULL && ref->collection_id != NULL) { - if (!ostree_repo_resolve_collection_ref (pull_data->remote_repo_local, - ref, FALSE, - OSTREE_REPO_RESOLVE_REV_EXT_NONE, - &ret_contents, cancellable, error)) + if (!ostree_repo_resolve_collection_ref (pull_data->remote_repo_local, ref, FALSE, + OSTREE_REPO_RESOLVE_REV_EXT_NONE, &ret_contents, + cancellable, error)) return FALSE; } else if (pull_data->remote_repo_local != NULL) { - if (!ostree_repo_resolve_rev_ext (pull_data->remote_repo_local, - ref->ref_name, FALSE, - OSTREE_REPO_RESOLVE_REV_EXT_NONE, - &ret_contents, error)) + if (!ostree_repo_resolve_rev_ext (pull_data->remote_repo_local, ref->ref_name, FALSE, + OSTREE_REPO_RESOLVE_REV_EXT_NONE, &ret_contents, error)) return FALSE; } else @@ -847,11 +780,9 @@ fetch_ref_contents (OtPullData *pull_data, else filename = g_build_filename ("refs", "mirrors", ref->collection_id, ref->ref_name, NULL); - if (!fetch_mirrored_uri_contents_utf8_sync (pull_data->fetcher, - pull_data->meta_mirrorlist, + if (!fetch_mirrored_uri_contents_utf8_sync (pull_data->fetcher, pull_data->meta_mirrorlist, filename, pull_data->n_network_retries, - &ret_contents, - cancellable, error)) + &ret_contents, cancellable, error)) return FALSE; g_strchomp (ret_contents); @@ -861,28 +792,26 @@ fetch_ref_contents (OtPullData *pull_data, if (!ostree_validate_checksum_string (ret_contents, error)) return glnx_prefix_error (error, "Fetching checksum for ref (%s, %s)", - ref->collection_id ?: "(empty)", - ref->ref_name); + ref->collection_id ?: "(empty)", ref->ref_name); ot_transfer_out_value (out_contents, &ret_contents); return TRUE; } static gboolean -lookup_commit_checksum_and_collection_from_summary (OtPullData *pull_data, - const OstreeCollectionRef *ref, - char **out_checksum, - gsize *out_size, - char **out_collection_id, - GError **error) +lookup_commit_checksum_and_collection_from_summary (OtPullData *pull_data, + const OstreeCollectionRef *ref, + char **out_checksum, gsize *out_size, + char **out_collection_id, GError **error) { - g_autoptr(GVariant) additional_metadata = g_variant_get_child_value (pull_data->summary, 1); + g_autoptr (GVariant) additional_metadata = g_variant_get_child_value (pull_data->summary, 1); const gchar *main_collection_id; - if (!g_variant_lookup (additional_metadata, OSTREE_SUMMARY_COLLECTION_ID, "&s", &main_collection_id)) + if (!g_variant_lookup (additional_metadata, OSTREE_SUMMARY_COLLECTION_ID, "&s", + &main_collection_id)) main_collection_id = NULL; - g_autoptr(GVariant) refs = NULL; + g_autoptr (GVariant) refs = NULL; const gchar *resolved_collection_id = NULL; if (ref->collection_id == NULL || g_strcmp0 (ref->collection_id, main_collection_id) == 0) @@ -892,12 +821,13 @@ lookup_commit_checksum_and_collection_from_summary (OtPullData * } else if (ref->collection_id != NULL) { - g_autoptr(GVariant) collection_map = NULL; + g_autoptr (GVariant) collection_map = NULL; collection_map = g_variant_lookup_value (additional_metadata, OSTREE_SUMMARY_COLLECTION_MAP, G_VARIANT_TYPE ("a{sa(s(taya{sv}))}")); if (collection_map != NULL) - refs = g_variant_lookup_value (collection_map, ref->collection_id, G_VARIANT_TYPE ("a(s(taya{sv}))")); + refs = g_variant_lookup_value (collection_map, ref->collection_id, + G_VARIANT_TYPE ("a(s(taya{sv}))")); resolved_collection_id = ref->collection_id; } @@ -905,19 +835,20 @@ lookup_commit_checksum_and_collection_from_summary (OtPullData * if (refs == NULL || !ot_variant_bsearch_str (refs, ref->ref_name, &i)) { if (ref->collection_id != NULL) - return glnx_throw (error, "No such branch (%s, %s) in repository summary", ref->collection_id, ref->ref_name); + return glnx_throw (error, "No such branch (%s, %s) in repository summary", + ref->collection_id, ref->ref_name); else return glnx_throw (error, "No such branch '%s' in repository summary", ref->ref_name); } - g_autoptr(GVariant) refdata = g_variant_get_child_value (refs, i); - g_autoptr(GVariant) reftargetdata = g_variant_get_child_value (refdata, 1); + g_autoptr (GVariant) refdata = g_variant_get_child_value (refs, i); + g_autoptr (GVariant) reftargetdata = g_variant_get_child_value (refdata, 1); guint64 commit_size; - g_autoptr(GVariant) commit_csum_v = NULL; + g_autoptr (GVariant) commit_csum_v = NULL; g_variant_get (reftargetdata, "(t@ay@a{sv})", &commit_size, &commit_csum_v, NULL); - if (resolved_collection_id != NULL && - !ostree_validate_collection_id (resolved_collection_id, error)) + if (resolved_collection_id != NULL + && !ostree_validate_collection_id (resolved_collection_id, error)) return FALSE; if (!ostree_validate_structureof_csum_v (commit_csum_v, error)) return FALSE; @@ -939,13 +870,11 @@ fetch_object_data_free (FetchObjectData *fetch_data) } static void -content_fetch_on_write_complete (GObject *object, - GAsyncResult *result, - gpointer user_data) +content_fetch_on_write_complete (GObject *object, GAsyncResult *result, gpointer user_data) { FetchObjectData *fetch_data = user_data; OtPullData *pull_data = fetch_data->pull_data; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; OstreeObjectType objtype; const char *expected_checksum; @@ -953,8 +882,7 @@ content_fetch_on_write_complete (GObject *object, g_autofree char *checksum = NULL; g_autofree char *checksum_obj = NULL; - if (!ostree_repo_write_content_finish ((OstreeRepo*)object, result, - &csum, error)) + if (!ostree_repo_write_content_finish ((OstreeRepo *)object, result, &csum, error)) goto out; checksum = ostree_checksum_from_bytes (csum); @@ -972,7 +900,7 @@ content_fetch_on_write_complete (GObject *object, /* Was this a delta fallback? */ if (g_hash_table_remove (pull_data->requested_fallback_content, expected_checksum)) pull_data->n_fetched_deltapart_fallbacks++; - out: +out: pull_data->n_outstanding_content_write_requests--; /* No retries for local writes. */ check_outstanding_requests_handle_error (pull_data, &local_error); @@ -980,23 +908,23 @@ content_fetch_on_write_complete (GObject *object, } static void -content_fetch_on_complete (GObject *object, - GAsyncResult *result, - gpointer user_data) +content_fetch_on_complete (GObject *object, GAsyncResult *result, gpointer user_data) { OstreeFetcher *fetcher = (OstreeFetcher *)object; FetchObjectData *fetch_data = user_data; OtPullData *pull_data = fetch_data->pull_data; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; GCancellable *cancellable = NULL; guint64 length; - g_auto(GLnxTmpfile) tmpf = { 0, }; - g_autoptr(GInputStream) tmpf_input = NULL; - g_autoptr(GFileInfo) file_info = NULL; - g_autoptr(GVariant) xattrs = NULL; - g_autoptr(GInputStream) file_in = NULL; - g_autoptr(GInputStream) object_input = NULL; + g_auto (GLnxTmpfile) tmpf = { + 0, + }; + g_autoptr (GInputStream) tmpf_input = NULL; + g_autoptr (GFileInfo) file_info = NULL; + g_autoptr (GVariant) xattrs = NULL; + g_autoptr (GInputStream) file_in = NULL; + g_autoptr (GInputStream) object_input = NULL; const char *checksum; g_autofree char *checksum_obj = NULL; OstreeObjectType objtype; @@ -1011,8 +939,8 @@ content_fetch_on_complete (GObject *object, checksum_obj = ostree_object_to_string (checksum, objtype); g_debug ("fetch of %s complete", checksum_obj); - const gboolean verifying_bareuseronly = - (pull_data->importflags & _OSTREE_REPO_IMPORT_FLAGS_VERIFY_BAREUSERONLY) > 0; + const gboolean verifying_bareuseronly + = (pull_data->importflags & _OSTREE_REPO_IMPORT_FLAGS_VERIFY_BAREUSERONLY) > 0; /* See comments where we set this variable; this is implementing * the --trusted-http/OSTREE_REPO_PULL_FLAGS_TRUSTED_HTTP flags. @@ -1020,8 +948,8 @@ content_fetch_on_complete (GObject *object, if (pull_data->trusted_http_direct) { g_assert (!verifying_bareuseronly); - if (!_ostree_repo_commit_tmpf_final (pull_data->repo, checksum, objtype, - &tmpf, cancellable, error)) + if (!_ostree_repo_commit_tmpf_final (pull_data->repo, checksum, objtype, &tmpf, cancellable, + error)) goto out; pull_data->n_fetched_content++; } @@ -1034,9 +962,8 @@ content_fetch_on_complete (GObject *object, tmpf_input = g_unix_input_stream_new (g_steal_fd (&tmpf.fd), TRUE); /* If it appears corrupted, we'll delete it below */ - if (!ostree_content_stream_parse (TRUE, tmpf_input, stbuf.st_size, FALSE, - &file_in, &file_info, &xattrs, - cancellable, error)) + if (!ostree_content_stream_parse (TRUE, tmpf_input, stbuf.st_size, FALSE, &file_in, + &file_info, &xattrs, cancellable, error)) { g_prefix_error (error, "Parsing %s: ", checksum_obj); goto out; @@ -1048,20 +975,17 @@ content_fetch_on_complete (GObject *object, goto out; } - if (!ostree_raw_file_to_content_stream (file_in, file_info, xattrs, - &object_input, &length, + if (!ostree_raw_file_to_content_stream (file_in, file_info, xattrs, &object_input, &length, cancellable, error)) goto out; pull_data->n_outstanding_content_write_requests++; - ostree_repo_write_content_async (pull_data->repo, checksum, - object_input, length, - cancellable, + ostree_repo_write_content_async (pull_data->repo, checksum, object_input, length, cancellable, content_fetch_on_write_complete, fetch_data); free_fetch_data = FALSE; } - out: +out: g_assert (pull_data->n_outstanding_content_fetches > 0); pull_data->n_outstanding_content_fetches--; @@ -1075,13 +999,11 @@ content_fetch_on_complete (GObject *object, } static void -on_metadata_written (GObject *object, - GAsyncResult *result, - gpointer user_data) +on_metadata_written (GObject *object, GAsyncResult *result, gpointer user_data) { FetchObjectData *fetch_data = user_data; OtPullData *pull_data = fetch_data->pull_data; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; const char *expected_checksum; OstreeObjectType objtype; @@ -1089,8 +1011,7 @@ on_metadata_written (GObject *object, g_autofree guchar *csum = NULL; g_autofree char *stringified_object = NULL; - if (!ostree_repo_write_metadata_finish ((OstreeRepo*)object, result, - &csum, error)) + if (!ostree_repo_write_metadata_finish ((OstreeRepo *)object, result, &csum, error)) goto out; checksum = ostree_checksum_from_bytes (csum); @@ -1109,9 +1030,10 @@ on_metadata_written (GObject *object, goto out; } - queue_scan_one_metadata_object_c (pull_data, csum, objtype, fetch_data->path, 0, fetch_data->requested_ref); + queue_scan_one_metadata_object_c (pull_data, csum, objtype, fetch_data->path, 0, + fetch_data->requested_ref); - out: +out: g_assert (pull_data->n_outstanding_metadata_write_requests > 0); pull_data->n_outstanding_metadata_write_requests--; fetch_object_data_free (fetch_data); @@ -1121,8 +1043,7 @@ on_metadata_written (GObject *object, } static gboolean -is_parent_commit (OtPullData *pull_data, - const char *checksum) +is_parent_commit (OtPullData *pull_data, const char *checksum) { /* FIXME: Only parent commits are added to the commit_to_depth table, * so if the checksum isn't in the table then a new commit chain is @@ -1133,19 +1054,19 @@ is_parent_commit (OtPullData *pull_data, } static void -meta_fetch_on_complete (GObject *object, - GAsyncResult *result, - gpointer user_data) +meta_fetch_on_complete (GObject *object, GAsyncResult *result, gpointer user_data) { OstreeFetcher *fetcher = (OstreeFetcher *)object; FetchObjectData *fetch_data = user_data; OtPullData *pull_data = fetch_data->pull_data; - g_autoptr(GVariant) metadata = NULL; - g_auto(GLnxTmpfile) tmpf = { 0, }; + g_autoptr (GVariant) metadata = NULL; + g_auto (GLnxTmpfile) tmpf = { + 0, + }; const char *checksum; g_autofree char *checksum_obj = NULL; OstreeObjectType objtype; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; gboolean free_fetch_data = TRUE; @@ -1168,9 +1089,11 @@ meta_fetch_on_complete (GObject *object, g_hash_table_insert (pull_data->fetched_detached_metadata, g_strdup (checksum), NULL); if (!fetch_data->object_is_stored) - enqueue_one_object_request (pull_data, checksum, objtype, fetch_data->path, FALSE, FALSE, fetch_data->requested_ref); + enqueue_one_object_request (pull_data, checksum, objtype, fetch_data->path, FALSE, + FALSE, fetch_data->requested_ref); else - queue_scan_one_metadata_object (pull_data, checksum, objtype, fetch_data->path, 0, fetch_data->requested_ref); + queue_scan_one_metadata_object (pull_data, checksum, objtype, fetch_data->path, 0, + fetch_data->requested_ref); } /* When traversing parents, do not fail on a missing commit. @@ -1178,17 +1101,17 @@ meta_fetch_on_complete (GObject *object, * dangling parent reference. This logic should match the * local case in scan_one_metadata_object. */ - else if (objtype == OSTREE_OBJECT_TYPE_COMMIT && - pull_data->maxdepth != 0 && - is_parent_commit (pull_data, checksum)) + else if (objtype == OSTREE_OBJECT_TYPE_COMMIT && pull_data->maxdepth != 0 + && is_parent_commit (pull_data, checksum)) { g_clear_error (&local_error); - /* If the remote repo supports tombstone commits, check if the commit was intentionally - deleted. */ + /* If the remote repo supports tombstone commits, check if the commit was + intentionally deleted. */ if (pull_data->has_tombstone_commits) { - enqueue_one_object_request (pull_data, checksum, OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT, - fetch_data->path, FALSE, FALSE, NULL); + enqueue_one_object_request (pull_data, checksum, + OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT, fetch_data->path, + FALSE, FALSE, NULL); } } } @@ -1202,25 +1125,27 @@ meta_fetch_on_complete (GObject *object, if (fetch_data->is_detached_meta) { - if (!ot_variant_read_fd (tmpf.fd, 0, G_VARIANT_TYPE ("a{sv}"), - FALSE, &metadata, error)) + if (!ot_variant_read_fd (tmpf.fd, 0, G_VARIANT_TYPE ("a{sv}"), FALSE, &metadata, error)) goto out; if (!ostree_repo_write_commit_detached_metadata (pull_data->repo, checksum, metadata, pull_data->cancellable, error)) goto out; - g_hash_table_insert (pull_data->fetched_detached_metadata, g_strdup (checksum), g_steal_pointer (&metadata)); + g_hash_table_insert (pull_data->fetched_detached_metadata, g_strdup (checksum), + g_steal_pointer (&metadata)); if (!fetch_data->object_is_stored) - enqueue_one_object_request (pull_data, checksum, objtype, fetch_data->path, FALSE, FALSE, fetch_data->requested_ref); + enqueue_one_object_request (pull_data, checksum, objtype, fetch_data->path, FALSE, FALSE, + fetch_data->requested_ref); else - queue_scan_one_metadata_object (pull_data, checksum, objtype, fetch_data->path, 0, fetch_data->requested_ref); + queue_scan_one_metadata_object (pull_data, checksum, objtype, fetch_data->path, 0, + fetch_data->requested_ref); } else { - if (!ot_variant_read_fd (tmpf.fd, 0, ostree_metadata_variant_type (objtype), - FALSE, &metadata, error)) + if (!ot_variant_read_fd (tmpf.fd, 0, ostree_metadata_variant_type (objtype), FALSE, &metadata, + error)) goto out; /* Compute checksum and verify structure now. Note this is a recent change @@ -1244,7 +1169,8 @@ meta_fetch_on_complete (GObject *object, * to look up from the disk state as well, or insert the on-disk * metadata into this hash. */ - GVariant *detached_data = g_hash_table_lookup (pull_data->fetched_detached_metadata, checksum); + GVariant *detached_data + = g_hash_table_lookup (pull_data->fetched_detached_metadata, checksum); if (!_verify_unwritten_commit (pull_data, checksum, metadata, detached_data, fetch_data->requested_ref, pull_data->cancellable, error)) goto out; @@ -1260,13 +1186,12 @@ meta_fetch_on_complete (GObject *object, * fetch path does for trusted commits. */ ostree_repo_write_metadata_async (pull_data->repo, objtype, NULL, metadata, - pull_data->cancellable, - on_metadata_written, fetch_data); + pull_data->cancellable, on_metadata_written, fetch_data); pull_data->n_outstanding_metadata_write_requests++; free_fetch_data = FALSE; } - out: +out: g_assert (pull_data->n_outstanding_metadata_fetches > 0); pull_data->n_outstanding_metadata_fetches--; @@ -1283,7 +1208,7 @@ meta_fetch_on_complete (GObject *object, } static void -fetch_static_delta_data_free (gpointer data) +fetch_static_delta_data_free (gpointer data) { FetchStaticDeltaData *fetch_data = data; g_free (fetch_data->expected_checksum); @@ -1294,13 +1219,11 @@ fetch_static_delta_data_free (gpointer data) } static void -on_static_delta_written (GObject *object, - GAsyncResult *result, - gpointer user_data) +on_static_delta_written (GObject *object, GAsyncResult *result, gpointer user_data) { FetchStaticDeltaData *fetch_data = user_data; OtPullData *pull_data = fetch_data->pull_data; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; g_debug ("execute static delta part %s complete", fetch_data->expected_checksum); @@ -1308,7 +1231,7 @@ on_static_delta_written (GObject *object, if (!_ostree_static_delta_part_execute_finish (pull_data->repo, result, error)) goto out; - out: +out: g_assert (pull_data->n_outstanding_deltapart_write_requests > 0); pull_data->n_outstanding_deltapart_write_requests--; /* No need to retry on failure to write locally. */ @@ -1318,17 +1241,17 @@ on_static_delta_written (GObject *object, } static void -static_deltapart_fetch_on_complete (GObject *object, - GAsyncResult *result, - gpointer user_data) +static_deltapart_fetch_on_complete (GObject *object, GAsyncResult *result, gpointer user_data) { OstreeFetcher *fetcher = (OstreeFetcher *)object; FetchStaticDeltaData *fetch_data = user_data; OtPullData *pull_data = fetch_data->pull_data; - g_auto(GLnxTmpfile) tmpf = { 0, }; - g_autoptr(GInputStream) in = NULL; - g_autoptr(GVariant) part = NULL; - g_autoptr(GError) local_error = NULL; + g_auto (GLnxTmpfile) tmpf = { + 0, + }; + g_autoptr (GInputStream) in = NULL; + g_autoptr (GVariant) part = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; gboolean free_fetch_data = TRUE; @@ -1341,20 +1264,17 @@ static_deltapart_fetch_on_complete (GObject *object, in = g_unix_input_stream_new (g_steal_fd (&tmpf.fd), TRUE); /* TODO - make async */ - if (!_ostree_static_delta_part_open (in, NULL, 0, fetch_data->expected_checksum, - &part, pull_data->cancellable, error)) + if (!_ostree_static_delta_part_open (in, NULL, 0, fetch_data->expected_checksum, &part, + pull_data->cancellable, error)) goto out; - _ostree_static_delta_part_execute_async (pull_data->repo, - fetch_data->objects, - part, - pull_data->cancellable, - on_static_delta_written, + _ostree_static_delta_part_execute_async (pull_data->repo, fetch_data->objects, part, + pull_data->cancellable, on_static_delta_written, fetch_data); pull_data->n_outstanding_deltapart_write_requests++; free_fetch_data = FALSE; - out: +out: g_assert (pull_data->n_outstanding_deltapart_fetches > 0); pull_data->n_outstanding_deltapart_fetches--; @@ -1371,21 +1291,19 @@ static_deltapart_fetch_on_complete (GObject *object, } static gboolean -commitstate_is_partial (OtPullData *pull_data, - OstreeRepoCommitState commitstate) +commitstate_is_partial (OtPullData *pull_data, OstreeRepoCommitState commitstate) { return pull_data->legacy_transaction_resuming - || (commitstate & OSTREE_REPO_COMMIT_STATE_PARTIAL) > 0; + || (commitstate & OSTREE_REPO_COMMIT_STATE_PARTIAL) > 0; } -#endif /* HAVE_LIBCURL_OR_LIBSOUP */ +#endif /* HAVE_LIBCURL_OR_LIBSOUP */ /* Reads the collection-id of a given remote from the repo * configuration. */ static char * -get_real_remote_repo_collection_id (OstreeRepo *repo, - const gchar *remote_name) +get_real_remote_repo_collection_id (OstreeRepo *repo, const gchar *remote_name) { /* remote_name == NULL can happen for pull-local */ if (!remote_name) @@ -1393,9 +1311,8 @@ get_real_remote_repo_collection_id (OstreeRepo *repo, g_autofree gchar *remote_collection_id = NULL; if (!ostree_repo_get_remote_option (repo, remote_name, "collection-id", NULL, - &remote_collection_id, NULL) || - (remote_collection_id == NULL) || - (remote_collection_id[0] == '\0')) + &remote_collection_id, NULL) + || (remote_collection_id == NULL) || (remote_collection_id[0] == '\0')) return NULL; return g_steal_pointer (&remote_collection_id); @@ -1413,25 +1330,22 @@ get_remote_repo_collection_id (OtPullData *pull_data) { if (pull_data->remote_repo_local != NULL) { - const char *remote_collection_id = - ostree_repo_get_collection_id (pull_data->remote_repo_local); - if ((remote_collection_id == NULL) || - (remote_collection_id[0] == '\0')) + const char *remote_collection_id + = ostree_repo_get_collection_id (pull_data->remote_repo_local); + if ((remote_collection_id == NULL) || (remote_collection_id[0] == '\0')) return NULL; return g_strdup (remote_collection_id); } - return get_real_remote_repo_collection_id (pull_data->repo, - pull_data->remote_name); + return get_real_remote_repo_collection_id (pull_data->repo, pull_data->remote_name); } -#endif /* HAVE_LIBCURL_OR_LIBSOUP */ +#endif /* HAVE_LIBCURL_OR_LIBSOUP */ /* Check whether the given remote exists, has a `collection-id` key set, and it * equals @collection_id. If so, return %TRUE. Otherwise, %FALSE. */ static gboolean -check_remote_matches_collection_id (OstreeRepo *repo, - const gchar *remote_name, +check_remote_matches_collection_id (OstreeRepo *repo, const gchar *remote_name, const gchar *collection_id) { g_autofree gchar *remote_collection_id = NULL; @@ -1466,15 +1380,13 @@ check_remote_matches_collection_id (OstreeRepo *repo, * Since: 2018.6 */ OstreeRemote * -ostree_repo_resolve_keyring_for_collection (OstreeRepo *self, - const gchar *collection_id, - GCancellable *cancellable, - GError **error) +ostree_repo_resolve_keyring_for_collection (OstreeRepo *self, const gchar *collection_id, + GCancellable *cancellable, GError **error) { #ifndef OSTREE_DISABLE_GPGME gsize i; - g_auto(GStrv) remotes = NULL; - g_autoptr(OstreeRemote) keyring_remote = NULL; + g_auto (GStrv) remotes = NULL; + g_autoptr (OstreeRemote) keyring_remote = NULL; g_return_val_if_fail (OSTREE_IS_REPO (self), NULL); g_return_val_if_fail (ostree_validate_collection_id (collection_id, NULL), NULL); @@ -1486,29 +1398,29 @@ ostree_repo_resolve_keyring_for_collection (OstreeRepo *self, for (i = 0; remotes != NULL && remotes[i] != NULL; i++) { - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; if (!check_remote_matches_collection_id (self, remotes[i], collection_id)) continue; if (keyring_remote == NULL) { - g_debug ("%s: Found match for collection ‘%s’ in remote ‘%s’.", - G_STRFUNC, collection_id, remotes[i]); + g_debug ("%s: Found match for collection ‘%s’ in remote ‘%s’.", G_STRFUNC, collection_id, + remotes[i]); keyring_remote = _ostree_repo_get_remote_inherited (self, remotes[i], &local_error); if (keyring_remote == NULL) { - g_debug ("%s: Error loading remote ‘%s’: %s", - G_STRFUNC, remotes[i], local_error->message); + g_debug ("%s: Error loading remote ‘%s’: %s", G_STRFUNC, remotes[i], + local_error->message); continue; } - if (g_strcmp0 (keyring_remote->keyring, "") == 0 || - g_strcmp0 (keyring_remote->keyring, "/dev/null") == 0) + if (g_strcmp0 (keyring_remote->keyring, "") == 0 + || g_strcmp0 (keyring_remote->keyring, "/dev/null") == 0) { - g_debug ("%s: Ignoring remote ‘%s’ as it has no keyring configured.", - G_STRFUNC, remotes[i]); + g_debug ("%s: Ignoring remote ‘%s’ as it has no keyring configured.", G_STRFUNC, + remotes[i]); g_clear_object (&keyring_remote); continue; } @@ -1519,8 +1431,7 @@ ostree_repo_resolve_keyring_for_collection (OstreeRepo *self, { g_debug ("%s: Duplicate keyring for collection ‘%s’ in remote ‘%s’." "Keyring will be loaded from remote ‘%s’.", - G_STRFUNC, collection_id, remotes[i], - keyring_remote->name); + G_STRFUNC, collection_id, remotes[i], keyring_remote->name); } } @@ -1529,14 +1440,12 @@ ostree_repo_resolve_keyring_for_collection (OstreeRepo *self, else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "No keyring found configured locally for collection ‘%s’", - collection_id); + "No keyring found configured locally for collection ‘%s’", collection_id); return NULL; } #else 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 NULL; #endif /* OSTREE_DISABLE_GPGME */ } @@ -1547,17 +1456,12 @@ ostree_repo_resolve_keyring_for_collection (OstreeRepo *self, * more things to fetch. */ static gboolean -scan_commit_object (OtPullData *pull_data, - const char *checksum, - guint recursion_depth, - const OstreeCollectionRef *ref, - GCancellable *cancellable, - GError **error) +scan_commit_object (OtPullData *pull_data, const char *checksum, guint recursion_depth, + const OstreeCollectionRef *ref, GCancellable *cancellable, GError **error) { gpointer depthp; gint depth; - if (g_hash_table_lookup_extended (pull_data->commit_to_depth, checksum, - NULL, &depthp)) + if (g_hash_table_lookup_extended (pull_data->commit_to_depth, checksum, NULL, &depthp)) { depth = GPOINTER_TO_INT (depthp); } @@ -1570,10 +1474,9 @@ scan_commit_object (OtPullData *pull_data, /* See comment in process_verify_result() - we now gpg check before writing, * but also ensure we've done it here if not already. */ - if (pull_data->gpg_verify && - !g_hash_table_contains (pull_data->verified_commits, checksum)) + if (pull_data->gpg_verify && !g_hash_table_contains (pull_data->verified_commits, checksum)) { - g_autoptr(OstreeGpgVerifyResult) result = NULL; + g_autoptr (OstreeGpgVerifyResult) result = NULL; const char *keyring_remote = NULL; if (ref != NULL) @@ -1581,20 +1484,17 @@ scan_commit_object (OtPullData *pull_data, if (keyring_remote == NULL) keyring_remote = pull_data->remote_name; - result = ostree_repo_verify_commit_for_remote (pull_data->repo, - checksum, - keyring_remote, - cancellable, - error); + result = ostree_repo_verify_commit_for_remote (pull_data->repo, checksum, keyring_remote, + cancellable, error); if (!_process_gpg_verify_result (pull_data, checksum, result, error)) return FALSE; } #endif /* OSTREE_DISABLE_GPGME */ - if (pull_data->signapi_commit_verifiers && - !g_hash_table_contains (pull_data->signapi_verified_commits, checksum)) + if (pull_data->signapi_commit_verifiers + && !g_hash_table_contains (pull_data->signapi_verified_commits, checksum)) { - g_autoptr(GError) last_verification_error = NULL; + g_autoptr (GError) last_verification_error = NULL; gboolean found_any_signature = FALSE; gboolean found_valid_signature = FALSE; g_autofree char *success_message = NULL; @@ -1606,17 +1506,14 @@ scan_commit_object (OtPullData *pull_data, found_any_signature = TRUE; /* Set return to true if any sign fit */ - if (ostree_sign_commit_verify (sign, - pull_data->repo, - checksum, - &success_message, - cancellable, - last_verification_error ? NULL : &last_verification_error)) + if (ostree_sign_commit_verify (sign, pull_data->repo, checksum, &success_message, + cancellable, + last_verification_error ? NULL : &last_verification_error)) { found_valid_signature = TRUE; break; } - } + } if (!found_any_signature) return glnx_throw (error, "No signatures found for commit %s", checksum); @@ -1628,7 +1525,8 @@ scan_commit_object (OtPullData *pull_data, return glnx_prefix_error (error, "Can't verify commit %s", checksum); } g_assert (success_message); - g_hash_table_insert (pull_data->signapi_verified_commits, g_strdup (checksum), g_steal_pointer (&success_message)); + g_hash_table_insert (pull_data->signapi_verified_commits, g_strdup (checksum), + g_steal_pointer (&success_message)); } /* If we found a legacy transaction flag, assume we have to scan. @@ -1636,7 +1534,7 @@ scan_commit_object (OtPullData *pull_data, * https://github.com/ostreedev/ostree/issues/543 */ OstreeRepoCommitState commitstate; - g_autoptr(GVariant) commit = NULL; + g_autoptr (GVariant) commit = NULL; if (!ostree_repo_load_commit (pull_data->repo, checksum, &commit, &commitstate, error)) return FALSE; @@ -1648,8 +1546,7 @@ scan_commit_object (OtPullData *pull_data, */ g_autofree char *remote_collection_id = NULL; remote_collection_id = get_remote_repo_collection_id (pull_data); - if (!_ostree_repo_verify_bindings (remote_collection_id, - (ref != NULL) ? ref->ref_name : NULL, + if (!_ostree_repo_verify_bindings (remote_collection_id, (ref != NULL) ? ref->ref_name : NULL, commit, error)) return glnx_prefix_error (error, "Commit %s", checksum); } @@ -1661,15 +1558,14 @@ scan_commit_object (OtPullData *pull_data, g_assert (ref); g_assert_cmpint (recursion_depth, ==, 0); const char *orig_rev = NULL; - if (!g_hash_table_lookup_extended (pull_data->ref_original_commits, - ref, NULL, (void**)&orig_rev)) + if (!g_hash_table_lookup_extended (pull_data->ref_original_commits, ref, NULL, + (void **)&orig_rev)) g_assert_not_reached (); - g_autoptr(GVariant) orig_commit = NULL; + g_autoptr (GVariant) orig_commit = NULL; if (orig_rev) { - if (!ostree_repo_load_commit (pull_data->repo, orig_rev, - &orig_commit, NULL, error)) + if (!ostree_repo_load_commit (pull_data->repo, orig_rev, &orig_commit, NULL, error)) return glnx_prefix_error (error, "Reading %s for timestamp-check", ref->ref_name); guint64 orig_ts = ostree_commit_get_timestamp (orig_commit); @@ -1679,14 +1575,15 @@ scan_commit_object (OtPullData *pull_data, } if (pull_data->timestamp_check_from_rev) { - g_autoptr(GVariant) timestamp_commit = NULL; + g_autoptr (GVariant) timestamp_commit = NULL; if (!ostree_repo_load_commit (pull_data->repo, pull_data->timestamp_check_from_rev, ×tamp_commit, NULL, error)) return glnx_prefix_error (error, "Reading %s for timestamp-check-from-rev", pull_data->timestamp_check_from_rev); guint64 ts = ostree_commit_get_timestamp (timestamp_commit); - if (!_ostree_compare_timestamps (pull_data->timestamp_check_from_rev, ts, checksum, new_ts, error)) + if (!_ostree_compare_timestamps (pull_data->timestamp_check_from_rev, ts, checksum, new_ts, + error)) return FALSE; } @@ -1694,7 +1591,7 @@ scan_commit_object (OtPullData *pull_data, gboolean is_partial = commitstate_is_partial (pull_data, commitstate); /* PARSE OSTREE_SERIALIZED_COMMIT_VARIANT */ - g_autoptr(GVariant) parent_csum = NULL; + g_autoptr (GVariant) parent_csum = NULL; const guchar *parent_csum_bytes = NULL; g_variant_get_child (commit, 1, "@ay", &parent_csum); if (g_variant_n_children (parent_csum) > 0) @@ -1706,17 +1603,14 @@ scan_commit_object (OtPullData *pull_data, if (parent_csum_bytes != NULL && (pull_data->maxdepth == -1 || depth > 0)) { - char parent_checksum[OSTREE_SHA256_STRING_LEN+1]; + char parent_checksum[OSTREE_SHA256_STRING_LEN + 1]; ostree_checksum_inplace_from_bytes (parent_csum_bytes, parent_checksum); int parent_depth = (depth > 0) ? depth - 1 : -1; g_hash_table_insert (pull_data->commit_to_depth, g_strdup (parent_checksum), GINT_TO_POINTER (parent_depth)); - queue_scan_one_metadata_object_c (pull_data, parent_csum_bytes, - OSTREE_OBJECT_TYPE_COMMIT, - NULL, - recursion_depth + 1, - NULL); + queue_scan_one_metadata_object_c (pull_data, parent_csum_bytes, OSTREE_OBJECT_TYPE_COMMIT, + NULL, recursion_depth + 1, NULL); } /* We only recurse to looking whether we need dirtree/dirmeta @@ -1725,8 +1619,8 @@ scan_commit_object (OtPullData *pull_data, */ if (is_partial && !pull_data->is_commit_only) { - g_autoptr(GVariant) tree_contents_csum = NULL; - g_autoptr(GVariant) tree_meta_csum = NULL; + g_autoptr (GVariant) tree_contents_csum = NULL; + g_autoptr (GVariant) tree_meta_csum = NULL; const guchar *tree_contents_csum_bytes; const guchar *tree_meta_csum_bytes; @@ -1742,21 +1636,20 @@ scan_commit_object (OtPullData *pull_data, return FALSE; queue_scan_one_metadata_object_c (pull_data, tree_contents_csum_bytes, - OSTREE_OBJECT_TYPE_DIR_TREE, "/", recursion_depth + 1, NULL); + OSTREE_OBJECT_TYPE_DIR_TREE, "/", recursion_depth + 1, + NULL); queue_scan_one_metadata_object_c (pull_data, tree_meta_csum_bytes, - OSTREE_OBJECT_TYPE_DIR_META, NULL, recursion_depth + 1, NULL); + OSTREE_OBJECT_TYPE_DIR_META, NULL, recursion_depth + 1, + NULL); } return TRUE; } static void -queue_scan_one_metadata_object (OtPullData *pull_data, - const char *csum, - OstreeObjectType objtype, - const char *path, - guint recursion_depth, +queue_scan_one_metadata_object (OtPullData *pull_data, const char *csum, OstreeObjectType objtype, + const char *path, guint recursion_depth, const OstreeCollectionRef *ref) { guchar buf[OSTREE_SHA256_DIGEST_LEN]; @@ -1765,19 +1658,15 @@ queue_scan_one_metadata_object (OtPullData *pull_data, } static void -queue_scan_one_metadata_object_s (OtPullData *pull_data, - ScanObjectQueueData *scan_data) +queue_scan_one_metadata_object_s (OtPullData *pull_data, ScanObjectQueueData *scan_data) { g_queue_push_tail (&pull_data->scan_object_queue, scan_data); ensure_idle_queued (pull_data); } static void -queue_scan_one_metadata_object_c (OtPullData *pull_data, - const guchar *csum, - OstreeObjectType objtype, - const char *path, - guint recursion_depth, +queue_scan_one_metadata_object_c (OtPullData *pull_data, const guchar *csum, + OstreeObjectType objtype, const char *path, guint recursion_depth, const OstreeCollectionRef *ref) { ScanObjectQueueData *scan_data = g_new0 (ScanObjectQueueData, 1); @@ -1796,16 +1685,11 @@ queue_scan_one_metadata_object_c (OtPullData *pull_data, * execution of this function. */ static gboolean -scan_one_metadata_object (OtPullData *pull_data, - const char *checksum, - OstreeObjectType objtype, - const char *path, - guint recursion_depth, - const OstreeCollectionRef *ref, - GCancellable *cancellable, - GError **error) +scan_one_metadata_object (OtPullData *pull_data, const char *checksum, OstreeObjectType objtype, + const char *path, guint recursion_depth, const OstreeCollectionRef *ref, + GCancellable *cancellable, GError **error) { - g_autoptr(GVariant) object = ostree_object_name_serialize (checksum, objtype); + g_autoptr (GVariant) object = ostree_object_name_serialize (checksum, objtype); /* It may happen that we've already looked at this object (think shared * dirtree subtrees), if that's the case, we're done */ @@ -1815,8 +1699,7 @@ scan_one_metadata_object (OtPullData *pull_data, gboolean is_requested = g_hash_table_lookup (pull_data->requested_metadata, object) != NULL; /* Determine if we already have the object */ gboolean is_stored; - if (!ostree_repo_has_object (pull_data->repo, objtype, checksum, &is_stored, - cancellable, error)) + if (!ostree_repo_has_object (pull_data->repo, objtype, checksum, &is_stored, cancellable, error)) return FALSE; /* Are we pulling an object we don't have from a local repo? */ @@ -1829,10 +1712,9 @@ scan_one_metadata_object (OtPullData *pull_data, return FALSE; } - g_autoptr(GError) local_error = NULL; - if (!_ostree_repo_import_object (pull_data->repo, pull_data->remote_repo_local, - objtype, checksum, pull_data->importflags, - cancellable, &local_error)) + g_autoptr (GError) local_error = NULL; + if (!_ostree_repo_import_object (pull_data->repo, pull_data->remote_repo_local, objtype, + checksum, pull_data->importflags, cancellable, &local_error)) { /* When traversing parents, do not fail on a missing commit. * We may be pulling from a partial repository that ends in a @@ -1841,10 +1723,9 @@ scan_one_metadata_object (OtPullData *pull_data, * * Note early return. */ - if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND) && - objtype == OSTREE_OBJECT_TYPE_COMMIT && - pull_data->maxdepth != 0 && - is_parent_commit (pull_data, checksum)) + if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND) + && objtype == OSTREE_OBJECT_TYPE_COMMIT && pull_data->maxdepth != 0 + && is_parent_commit (pull_data, checksum)) { g_clear_error (&local_error); @@ -1854,9 +1735,8 @@ scan_one_metadata_object (OtPullData *pull_data, if (pull_data->has_tombstone_commits) { if (!_ostree_repo_import_object (pull_data->repo, pull_data->remote_repo_local, - OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT, - checksum, pull_data->importflags, - cancellable, error)) + OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT, checksum, + pull_data->importflags, cancellable, error)) return FALSE; } @@ -1886,8 +1766,8 @@ scan_one_metadata_object (OtPullData *pull_data, OstreeRepo *refd_repo = pull_data->localcache_repos->pdata[i]; gboolean localcache_repo_has_obj; - if (!ostree_repo_has_object (refd_repo, objtype, checksum, - &localcache_repo_has_obj, cancellable, error)) + if (!ostree_repo_has_object (refd_repo, objtype, checksum, &localcache_repo_has_obj, + cancellable, error)) return FALSE; if (!localcache_repo_has_obj) continue; @@ -1897,9 +1777,8 @@ scan_one_metadata_object (OtPullData *pull_data, if (!ostree_repo_mark_commit_partial (pull_data->repo, checksum, TRUE, error)) return FALSE; } - if (!_ostree_repo_import_object (pull_data->repo, refd_repo, - objtype, checksum, pull_data->importflags, - cancellable, error)) + if (!_ostree_repo_import_object (pull_data->repo, refd_repo, objtype, checksum, + pull_data->importflags, cancellable, error)) return FALSE; /* See comment above */ if (objtype == OSTREE_OBJECT_TYPE_COMMIT) @@ -1918,7 +1797,8 @@ scan_one_metadata_object (OtPullData *pull_data, g_hash_table_add (pull_data->requested_metadata, g_variant_ref (object)); do_fetch_detached = (objtype == OSTREE_OBJECT_TYPE_COMMIT); - enqueue_one_object_request (pull_data, checksum, objtype, path, do_fetch_detached, FALSE, ref); + enqueue_one_object_request (pull_data, checksum, objtype, path, do_fetch_detached, FALSE, + ref); } else if (is_stored && objtype == OSTREE_OBJECT_TYPE_COMMIT) { @@ -1939,8 +1819,8 @@ scan_one_metadata_object (OtPullData *pull_data, } else if (is_stored && objtype == OSTREE_OBJECT_TYPE_DIR_TREE) { - if (!scan_dirtree_object (pull_data, checksum, path, recursion_depth, - pull_data->cancellable, error)) + if (!scan_dirtree_object (pull_data, checksum, path, recursion_depth, pull_data->cancellable, + error)) return glnx_prefix_error (error, "Validating dirtree %s (%s)", checksum, path); g_hash_table_add (pull_data->scanned_metadata, g_variant_ref (object)); @@ -1951,8 +1831,7 @@ scan_one_metadata_object (OtPullData *pull_data, } static void -enqueue_one_object_request_s (OtPullData *pull_data, - FetchObjectData *fetch_data) +enqueue_one_object_request_s (OtPullData *pull_data, FetchObjectData *fetch_data) { const char *checksum; OstreeObjectType objtype; @@ -1963,13 +1842,13 @@ enqueue_one_object_request_s (OtPullData *pull_data, /* Are too many requests are in flight? */ if (fetcher_queue_is_full (pull_data)) { - g_debug ("queuing fetch of %s.%s%s", checksum, - ostree_object_type_to_string (objtype), + g_debug ("queuing fetch of %s.%s%s", checksum, ostree_object_type_to_string (objtype), fetch_data->is_detached_meta ? " (detached)" : ""); if (is_meta) { - g_hash_table_insert (pull_data->pending_fetch_metadata, g_variant_ref (fetch_data->object), fetch_data); + g_hash_table_insert (pull_data->pending_fetch_metadata, + g_variant_ref (fetch_data->object), fetch_data); } else { @@ -1983,12 +1862,8 @@ enqueue_one_object_request_s (OtPullData *pull_data, } static void -enqueue_one_object_request (OtPullData *pull_data, - const char *checksum, - OstreeObjectType objtype, - const char *path, - gboolean is_detached_meta, - gboolean object_is_stored, +enqueue_one_object_request (OtPullData *pull_data, const char *checksum, OstreeObjectType objtype, + const char *path, gboolean is_detached_meta, gboolean object_is_stored, const OstreeCollectionRef *ref) { FetchObjectData *fetch_data; @@ -2011,8 +1886,7 @@ enqueue_one_object_request (OtPullData *pull_data, } static void -start_fetch (OtPullData *pull_data, - FetchObjectData *fetch) +start_fetch (OtPullData *pull_data, FetchObjectData *fetch) { g_autofree char *obj_subpath = NULL; guint64 *expected_max_size_p; @@ -2023,8 +1897,7 @@ start_fetch (OtPullData *pull_data, ostree_object_name_deserialize (fetch->object, &expected_checksum, &objtype); - g_debug ("starting fetch of %s.%s%s", expected_checksum, - ostree_object_type_to_string (objtype), + g_debug ("starting fetch of %s.%s%s", expected_checksum, ostree_object_type_to_string (objtype), fetch->is_detached_meta ? " (detached)" : ""); gboolean is_meta = OSTREE_OBJECT_TYPE_IS_META (objtype); @@ -2038,7 +1911,8 @@ start_fetch (OtPullData *pull_data, if (fetch->is_detached_meta) { char buf[_OSTREE_LOOSE_PATH_MAX]; - _ostree_loose_path (buf, expected_checksum, OSTREE_OBJECT_TYPE_COMMIT_META, pull_data->remote_mode); + _ostree_loose_path (buf, expected_checksum, OSTREE_OBJECT_TYPE_COMMIT_META, + pull_data->remote_mode); obj_subpath = g_build_filename ("objects", buf, NULL); mirrorlist = pull_data->meta_mirrorlist; flags |= OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT; @@ -2052,7 +1926,10 @@ start_fetch (OtPullData *pull_data, /* We may have determined maximum sizes from the summary file content; if so, * honor it. Otherwise, metadata has a baseline max size. */ - expected_max_size_p = fetch->is_detached_meta ? NULL : g_hash_table_lookup (pull_data->expected_commit_sizes, expected_checksum); + expected_max_size_p + = fetch->is_detached_meta + ? NULL + : g_hash_table_lookup (pull_data->expected_commit_sizes, expected_checksum); if (expected_max_size_p) expected_max_size = *expected_max_size_p; else if (OSTREE_OBJECT_TYPE_IS_META (objtype)) @@ -2062,33 +1939,27 @@ start_fetch (OtPullData *pull_data, if (!is_meta && pull_data->trusted_http_direct) flags |= OSTREE_FETCHER_REQUEST_LINKABLE; - _ostree_fetcher_request_to_tmpfile (pull_data->fetcher, mirrorlist, - obj_subpath, flags, NULL, 0, expected_max_size, - is_meta ? OSTREE_REPO_PULL_METADATA_PRIORITY - : OSTREE_REPO_PULL_CONTENT_PRIORITY, - pull_data->cancellable, - is_meta ? meta_fetch_on_complete : content_fetch_on_complete, fetch); + _ostree_fetcher_request_to_tmpfile ( + pull_data->fetcher, mirrorlist, obj_subpath, flags, NULL, 0, expected_max_size, + is_meta ? OSTREE_REPO_PULL_METADATA_PRIORITY : OSTREE_REPO_PULL_CONTENT_PRIORITY, + pull_data->cancellable, is_meta ? meta_fetch_on_complete : content_fetch_on_complete, fetch); } /* Deprecated: code should load options from the `summary` file rather than * downloading the remote’s `config` file, to save on network round trips. */ static gboolean -load_remote_repo_config (OtPullData *pull_data, - GKeyFile **out_keyfile, - GCancellable *cancellable, - GError **error) +load_remote_repo_config (OtPullData *pull_data, GKeyFile **out_keyfile, GCancellable *cancellable, + GError **error) { g_autofree char *contents = NULL; - if (!fetch_mirrored_uri_contents_utf8_sync (pull_data->fetcher, - pull_data->meta_mirrorlist, - "config", pull_data->n_network_retries, - &contents, cancellable, error)) + if (!fetch_mirrored_uri_contents_utf8_sync (pull_data->fetcher, pull_data->meta_mirrorlist, + "config", pull_data->n_network_retries, &contents, + cancellable, error)) return FALSE; - g_autoptr(GKeyFile) ret_keyfile = g_key_file_new (); - if (!g_key_file_load_from_data (ret_keyfile, contents, strlen (contents), - 0, error)) + g_autoptr (GKeyFile) ret_keyfile = g_key_file_new (); + if (!g_key_file_load_from_data (ret_keyfile, contents, strlen (contents), 0, error)) return glnx_prefix_error (error, "Parsing config"); ot_transfer_out_value (out_keyfile, &ret_keyfile); @@ -2096,18 +1967,16 @@ load_remote_repo_config (OtPullData *pull_data, } static gboolean -process_one_static_delta_fallback (OtPullData *pull_data, - gboolean delta_byteswap, - GVariant *fallback_object, - GCancellable *cancellable, - GError **error) +process_one_static_delta_fallback (OtPullData *pull_data, gboolean delta_byteswap, + GVariant *fallback_object, GCancellable *cancellable, + GError **error) { guint8 objtype_y; - g_autoptr(GVariant) csum_v = NULL; + g_autoptr (GVariant) csum_v = NULL; guint64 compressed_size, uncompressed_size; - g_variant_get (fallback_object, "(y@aytt)", - &objtype_y, &csum_v, &compressed_size, &uncompressed_size); + g_variant_get (fallback_object, "(y@aytt)", &objtype_y, &csum_v, &compressed_size, + &uncompressed_size); if (!ostree_validate_structureof_objtype (objtype_y, error)) return FALSE; @@ -2125,9 +1994,7 @@ process_one_static_delta_fallback (OtPullData *pull_data, g_autofree char *checksum = ostree_checksum_from_bytes_v (csum_v); gboolean is_stored; - if (!ostree_repo_has_object (pull_data->repo, objtype, checksum, - &is_stored, - cancellable, error)) + if (!ostree_repo_has_object (pull_data->repo, objtype, checksum, &is_stored, cancellable, error)) return FALSE; if (is_stored) @@ -2152,8 +2019,9 @@ process_one_static_delta_fallback (OtPullData *pull_data, * for it as logically part of the delta fetch. */ g_hash_table_add (pull_data->requested_fallback_content, g_strdup (checksum)); - enqueue_one_object_request (pull_data, checksum, OSTREE_OBJECT_TYPE_FILE, NULL, FALSE, FALSE, NULL); - checksum = NULL; /* We transferred ownership to the requested_content hash */ + enqueue_one_object_request (pull_data, checksum, OSTREE_OBJECT_TYPE_FILE, NULL, FALSE, + FALSE, NULL); + checksum = NULL; /* We transferred ownership to the requested_content hash */ } } } @@ -2162,13 +2030,11 @@ process_one_static_delta_fallback (OtPullData *pull_data, } static void -enqueue_one_static_delta_part_request_s (OtPullData *pull_data, - FetchStaticDeltaData *fetch_data) +enqueue_one_static_delta_part_request_s (OtPullData *pull_data, FetchStaticDeltaData *fetch_data) { if (fetcher_queue_is_full (pull_data)) { - g_debug ("queuing fetch of static delta %s-%s part %u", - fetch_data->from_revision ?: "empty", + g_debug ("queuing fetch of static delta %s-%s part %u", fetch_data->from_revision ?: "empty", fetch_data->to_revision, fetch_data->i); g_hash_table_add (pull_data->pending_fetch_deltaparts, fetch_data); @@ -2180,37 +2046,31 @@ enqueue_one_static_delta_part_request_s (OtPullData *pull_data, } static void -start_fetch_deltapart (OtPullData *pull_data, - FetchStaticDeltaData *fetch) +start_fetch_deltapart (OtPullData *pull_data, FetchStaticDeltaData *fetch) { - g_autofree char *deltapart_path = _ostree_get_relative_static_delta_part_path (fetch->from_revision, fetch->to_revision, fetch->i); + g_autofree char *deltapart_path = _ostree_get_relative_static_delta_part_path ( + fetch->from_revision, fetch->to_revision, fetch->i); g_debug ("starting fetch of deltapart %s", deltapart_path); pull_data->n_outstanding_deltapart_fetches++; - g_assert_cmpint (pull_data->n_outstanding_deltapart_fetches, <=, _OSTREE_MAX_OUTSTANDING_DELTAPART_REQUESTS); - _ostree_fetcher_request_to_tmpfile (pull_data->fetcher, - pull_data->content_mirrorlist, + g_assert_cmpint (pull_data->n_outstanding_deltapart_fetches, <=, + _OSTREE_MAX_OUTSTANDING_DELTAPART_REQUESTS); + _ostree_fetcher_request_to_tmpfile (pull_data->fetcher, pull_data->content_mirrorlist, deltapart_path, 0, NULL, 0, fetch->size, - OSTREE_FETCHER_DEFAULT_PRIORITY, - pull_data->cancellable, - static_deltapart_fetch_on_complete, - fetch); + OSTREE_FETCHER_DEFAULT_PRIORITY, pull_data->cancellable, + static_deltapart_fetch_on_complete, fetch); } static gboolean -process_one_static_delta (OtPullData *pull_data, - const char *from_revision, - const char *to_revision, - GVariant *delta_superblock, - const OstreeCollectionRef *ref, - GCancellable *cancellable, - GError **error) +process_one_static_delta (OtPullData *pull_data, const char *from_revision, const char *to_revision, + GVariant *delta_superblock, const OstreeCollectionRef *ref, + GCancellable *cancellable, GError **error) { gboolean delta_byteswap = _ostree_delta_needs_byteswap (delta_superblock); /* Parsing OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT */ - g_autoptr(GVariant) metadata = g_variant_get_child_value (delta_superblock, 0); - g_autoptr(GVariant) headers = g_variant_get_child_value (delta_superblock, 6); - g_autoptr(GVariant) fallback_objects = g_variant_get_child_value (delta_superblock, 7); + g_autoptr (GVariant) metadata = g_variant_get_child_value (delta_superblock, 0); + g_autoptr (GVariant) headers = g_variant_get_child_value (delta_superblock, 6); + g_autoptr (GVariant) fallback_objects = g_variant_get_child_value (delta_superblock, 7); /* Gather free space so we can do a check below */ struct statvfs stvfsbuf; @@ -2221,11 +2081,9 @@ process_one_static_delta (OtPullData *pull_data, guint n = g_variant_n_children (fallback_objects); for (guint i = 0; i < n; i++) { - g_autoptr(GVariant) fallback_object = - g_variant_get_child_value (fallback_objects, i); + g_autoptr (GVariant) fallback_object = g_variant_get_child_value (fallback_objects, i); - if (!process_one_static_delta_fallback (pull_data, delta_byteswap, - fallback_object, + if (!process_one_static_delta_fallback (pull_data, delta_byteswap, fallback_object, cancellable, error)) return FALSE; } @@ -2233,7 +2091,7 @@ process_one_static_delta (OtPullData *pull_data, /* Write the to-commit object */ if (!pull_data->dry_run) { - g_autoptr(GVariant) to_csum_v = g_variant_get_child_value (delta_superblock, 3); + g_autoptr (GVariant) to_csum_v = g_variant_get_child_value (delta_superblock, 3); if (!ostree_validate_structureof_csum_v (to_csum_v, error)) return FALSE; g_autofree char *to_checksum = ostree_checksum_from_bytes_v (to_csum_v); @@ -2245,36 +2103,36 @@ process_one_static_delta (OtPullData *pull_data, if (!have_to_commit) { - g_autoptr(GVariant) to_commit = g_variant_get_child_value (delta_superblock, 4); - g_autofree char *detached_path = _ostree_get_relative_static_delta_path (from_revision, to_revision, "commitmeta"); - g_autoptr(GVariant) detached_data = g_variant_lookup_value (metadata, detached_path, G_VARIANT_TYPE("a{sv}")); + g_autoptr (GVariant) to_commit = g_variant_get_child_value (delta_superblock, 4); + g_autofree char *detached_path + = _ostree_get_relative_static_delta_path (from_revision, to_revision, "commitmeta"); + g_autoptr (GVariant) detached_data + = g_variant_lookup_value (metadata, detached_path, G_VARIANT_TYPE ("a{sv}")); - if (!_verify_unwritten_commit (pull_data, to_revision, to_commit, detached_data, - ref, cancellable, error)) + if (!_verify_unwritten_commit (pull_data, to_revision, to_commit, detached_data, ref, + cancellable, error)) return FALSE; if (!ostree_repo_mark_commit_partial (pull_data->repo, to_revision, TRUE, error)) return FALSE; - if (detached_data && !ostree_repo_write_commit_detached_metadata (pull_data->repo, - to_revision, - detached_data, - cancellable, - error)) + if (detached_data + && !ostree_repo_write_commit_detached_metadata (pull_data->repo, to_revision, + detached_data, cancellable, error)) return FALSE; FetchObjectData *fetch_data = g_new0 (FetchObjectData, 1); fetch_data->pull_data = pull_data; - fetch_data->object = ostree_object_name_serialize (to_checksum, OSTREE_OBJECT_TYPE_COMMIT); + fetch_data->object + = ostree_object_name_serialize (to_checksum, OSTREE_OBJECT_TYPE_COMMIT); fetch_data->is_detached_meta = FALSE; fetch_data->object_is_stored = FALSE; fetch_data->requested_ref = (ref != NULL) ? ostree_collection_ref_dup (ref) : NULL; fetch_data->n_retries_remaining = pull_data->n_network_retries; ostree_repo_write_metadata_async (pull_data->repo, OSTREE_OBJECT_TYPE_COMMIT, to_checksum, - to_commit, - pull_data->cancellable, - on_metadata_written, fetch_data); + to_commit, pull_data->cancellable, on_metadata_written, + fetch_data); pull_data->n_outstanding_metadata_write_requests++; } } @@ -2286,10 +2144,10 @@ process_one_static_delta (OtPullData *pull_data, { gboolean have_all = FALSE; - g_autoptr(GVariant) header = g_variant_get_child_value (headers, i); - g_autoptr(GVariant) csum_v = NULL; - g_autoptr(GVariant) objects = NULL; - g_autoptr(GBytes) inline_part_bytes = NULL; + g_autoptr (GVariant) header = g_variant_get_child_value (headers, i); + g_autoptr (GVariant) csum_v = NULL; + g_autoptr (GVariant) objects = NULL; + g_autoptr (GBytes) inline_part_bytes = NULL; guint32 version; guint64 size, usize; g_variant_get (header, "(u@aytt@ay)", &version, &csum_v, &size, &usize, &objects); @@ -2304,9 +2162,7 @@ process_one_static_delta (OtPullData *pull_data, if (!csum) return FALSE; - if (!_ostree_repo_static_delta_part_have_all_objects (pull_data->repo, - objects, - &have_all, + if (!_ostree_repo_static_delta_part_have_all_objects (pull_data->repo, objects, &have_all, cancellable, error)) return FALSE; @@ -2315,18 +2171,19 @@ process_one_static_delta (OtPullData *pull_data, if (have_all) { - g_debug ("Have all objects from static delta %s-%s part %u", - from_revision ?: "empty", to_revision, - i); + g_debug ("Have all objects from static delta %s-%s part %u", from_revision ?: "empty", + to_revision, i); pull_data->fetched_deltapart_size += size; pull_data->n_fetched_deltaparts++; continue; } - g_autofree char *deltapart_path = _ostree_get_relative_static_delta_part_path (from_revision, to_revision, i); + g_autofree char *deltapart_path + = _ostree_get_relative_static_delta_part_path (from_revision, to_revision, i); - { g_autoptr(GVariant) part_datav = - g_variant_lookup_value (metadata, deltapart_path, G_VARIANT_TYPE ("(yay)")); + { + g_autoptr (GVariant) part_datav + = g_variant_lookup_value (metadata, deltapart_path, G_VARIANT_TYPE ("(yay)")); if (part_datav) inline_part_bytes = g_variant_get_data_as_bytes (part_datav); @@ -2347,25 +2204,21 @@ process_one_static_delta (OtPullData *pull_data, if (inline_part_bytes != NULL) { - g_autoptr(GInputStream) memin = g_memory_input_stream_new_from_bytes (inline_part_bytes); - g_autoptr(GVariant) inline_delta_part = NULL; + g_autoptr (GInputStream) memin = g_memory_input_stream_new_from_bytes (inline_part_bytes); + g_autoptr (GVariant) inline_delta_part = NULL; /* For inline parts we are relying on per-commit GPG, so don't bother checksumming. */ if (!_ostree_static_delta_part_open (memin, inline_part_bytes, - OSTREE_STATIC_DELTA_OPEN_FLAGS_SKIP_CHECKSUM, - NULL, &inline_delta_part, - cancellable, error)) + OSTREE_STATIC_DELTA_OPEN_FLAGS_SKIP_CHECKSUM, NULL, + &inline_delta_part, cancellable, error)) { fetch_static_delta_data_free (fetch_data); return FALSE; } - _ostree_static_delta_part_execute_async (pull_data->repo, - fetch_data->objects, - inline_delta_part, - pull_data->cancellable, - on_static_delta_written, - fetch_data); + _ostree_static_delta_part_execute_async (pull_data->repo, fetch_data->objects, + inline_delta_part, pull_data->cancellable, + on_static_delta_written, fetch_data); pull_data->n_outstanding_deltapart_write_requests++; } else @@ -2383,7 +2236,8 @@ process_one_static_delta (OtPullData *pull_data, if (delta_required_blocks > stvfsbuf.f_bfree) { g_autofree char *formatted_required = g_format_size (pull_data->total_deltapart_usize); - g_autofree char *formatted_avail = g_format_size (((guint64)stvfsbuf.f_bsize) * stvfsbuf.f_bfree); + g_autofree char *formatted_avail + = g_format_size (((guint64)stvfsbuf.f_bsize) * stvfsbuf.f_bfree); return glnx_throw (error, "Delta requires %s free space, but only %s available", formatted_required, formatted_avail); } @@ -2406,14 +2260,16 @@ process_one_static_delta (OtPullData *pull_data, * There is a %NULL → @to_revision delta, also known as * a "from scratch" delta. */ -typedef struct { - enum { +typedef struct +{ + enum + { DELTA_SEARCH_RESULT_UNCHANGED, DELTA_SEARCH_RESULT_NO_MATCH, DELTA_SEARCH_RESULT_FROM, DELTA_SEARCH_RESULT_SCRATCH, } result; - char from_revision[OSTREE_SHA256_STRING_LEN+1]; + char from_revision[OSTREE_SHA256_STRING_LEN + 1]; } DeltaSearchResult; /* Loop over the static delta data we got from the summary, @@ -2421,14 +2277,12 @@ typedef struct { * See the enum in `DeltaSearchResult` for available result types. */ static gboolean -get_best_static_delta_start_for (OtPullData *pull_data, - const char *to_revision, - DeltaSearchResult *out_result, - GCancellable *cancellable, - GError **error) +get_best_static_delta_start_for (OtPullData *pull_data, const char *to_revision, + DeltaSearchResult *out_result, GCancellable *cancellable, + GError **error) { /* Array of possible from checksums */ - g_autoptr(GPtrArray) candidates = g_ptr_array_new_with_free_func (g_free); + g_autoptr (GPtrArray) candidates = g_ptr_array_new_with_free_func (g_free); const char *newest_candidate = NULL; guint64 newest_candidate_timestamp = 0; @@ -2439,27 +2293,25 @@ get_best_static_delta_start_for (OtPullData *pull_data, /* First, do we already have this commit completely downloaded? */ gboolean have_to_rev; - if (!ostree_repo_has_object (pull_data->repo, OSTREE_OBJECT_TYPE_COMMIT, - to_revision, &have_to_rev, - cancellable, error)) + if (!ostree_repo_has_object (pull_data->repo, OSTREE_OBJECT_TYPE_COMMIT, to_revision, + &have_to_rev, cancellable, error)) return FALSE; if (have_to_rev) { OstreeRepoCommitState to_rev_state; - if (!ostree_repo_load_commit (pull_data->repo, to_revision, - NULL, &to_rev_state, error)) + if (!ostree_repo_load_commit (pull_data->repo, to_revision, NULL, &to_rev_state, error)) return FALSE; - if (!(commitstate_is_partial(pull_data, to_rev_state))) + if (!(commitstate_is_partial (pull_data, to_rev_state))) { /* We already have this commit, we're done! */ out_result->result = DELTA_SEARCH_RESULT_UNCHANGED; - return TRUE; /* Early return */ + return TRUE; /* Early return */ } } /* Loop over all deltas known from the summary file, * finding ones which go to to_revision */ - GLNX_HASH_TABLE_FOREACH (pull_data->summary_deltas_checksums, const char*, delta_name) + GLNX_HASH_TABLE_FOREACH (pull_data->summary_deltas_checksums, const char *, delta_name) { g_autofree char *cur_from_rev = NULL; g_autofree char *cur_to_rev = NULL; @@ -2491,21 +2343,19 @@ get_best_static_delta_start_for (OtPullData *pull_data, { const char *candidate = candidates->pdata[i]; guint64 candidate_ts = 0; - g_autoptr(GVariant) commit = NULL; + g_autoptr (GVariant) commit = NULL; OstreeRepoCommitState state; gboolean have_candidate; /* Do we have this commit at all? If not, skip it */ - if (!ostree_repo_has_object (pull_data->repo, OSTREE_OBJECT_TYPE_COMMIT, - candidate, &have_candidate, - NULL, error)) + if (!ostree_repo_has_object (pull_data->repo, OSTREE_OBJECT_TYPE_COMMIT, candidate, + &have_candidate, NULL, error)) return FALSE; if (!have_candidate) continue; /* Load it */ - if (!ostree_repo_load_commit (pull_data->repo, candidate, - &commit, &state, error)) + if (!ostree_repo_load_commit (pull_data->repo, candidate, &commit, &state, error)) return FALSE; /* Ignore partial commits, we can't use them */ @@ -2514,8 +2364,7 @@ get_best_static_delta_start_for (OtPullData *pull_data, /* Is it newer? */ candidate_ts = ostree_commit_get_timestamp (commit); - if (newest_candidate == NULL || - candidate_ts > newest_candidate_timestamp) + if (newest_candidate == NULL || candidate_ts > newest_candidate_timestamp) { newest_candidate = candidate; newest_candidate_timestamp = candidate_ts; @@ -2525,7 +2374,7 @@ get_best_static_delta_start_for (OtPullData *pull_data, if (newest_candidate) { out_result->result = DELTA_SEARCH_RESULT_FROM; - memcpy (out_result->from_revision, newest_candidate, OSTREE_SHA256_STRING_LEN+1); + memcpy (out_result->from_revision, newest_candidate, OSTREE_SHA256_STRING_LEN + 1); } return TRUE; } @@ -2551,34 +2400,26 @@ fetch_delta_index_data_free (FetchDeltaIndexData *fetch_data) } static void -set_required_deltas_error (GError **error, - const char *from_revision, - const char *to_revision) +set_required_deltas_error (GError **error, const char *from_revision, const char *to_revision) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Static deltas required, but none found for %s to %s", - from_revision, to_revision); + "Static deltas required, but none found for %s to %s", from_revision, to_revision); } static void -on_superblock_fetched (GObject *src, - GAsyncResult *res, - gpointer data) +on_superblock_fetched (GObject *src, GAsyncResult *res, gpointer data) { FetchDeltaSuperData *fetch_data = data; OtPullData *pull_data = fetch_data->pull_data; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; - g_autoptr(GBytes) delta_superblock_data = NULL; + g_autoptr (GBytes) delta_superblock_data = NULL; const char *from_revision = fetch_data->from_revision; const char *to_revision = fetch_data->to_revision; - if (!_ostree_fetcher_request_to_membuf_finish ((OstreeFetcher*)src, - res, - &delta_superblock_data, - NULL, NULL, NULL, - error)) + if (!_ostree_fetcher_request_to_membuf_finish ((OstreeFetcher *)src, res, &delta_superblock_data, + NULL, NULL, NULL, error)) { if (!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) goto out; @@ -2590,13 +2431,16 @@ on_superblock_fetched (GObject *src, goto out; } - queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, 0, fetch_data->requested_ref); + queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, 0, + fetch_data->requested_ref); } else { - g_autoptr(GVariant) delta_superblock = NULL; - g_autofree gchar *delta = g_strconcat (from_revision ?: "", from_revision ? "-" : "", to_revision, NULL); - const guchar *expected_summary_digest = g_hash_table_lookup (pull_data->summary_deltas_checksums, delta); + g_autoptr (GVariant) delta_superblock = NULL; + g_autofree gchar *delta + = g_strconcat (from_revision ?: "", from_revision ? "-" : "", to_revision, NULL); + const guchar *expected_summary_digest + = g_hash_table_lookup (pull_data->summary_deltas_checksums, delta); guint8 actual_summary_digest[OSTREE_SHA256_DIGEST_LEN]; ot_checksum_bytes (delta_superblock_data, actual_summary_digest); @@ -2609,27 +2453,31 @@ on_superblock_fetched (GObject *src, if (pull_data->gpg_verify_summary && !expected_summary_digest) { g_set_error (error, OSTREE_GPG_ERROR, OSTREE_GPG_ERROR_NO_SIGNATURE, - "GPG verification enabled, but no summary signatures found (use gpg-verify-summary=false in remote config to disable)"); + "GPG verification enabled, but no summary signatures found (use " + "gpg-verify-summary=false in remote config to disable)"); goto out; } #endif /* OSTREE_DISABLE_GPGME */ - if (expected_summary_digest && memcmp (expected_summary_digest, actual_summary_digest, sizeof (actual_summary_digest))) + if (expected_summary_digest + && memcmp (expected_summary_digest, actual_summary_digest, + sizeof (actual_summary_digest))) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid checksum for static delta %s", delta); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid checksum for static delta %s", + delta); goto out; } - delta_superblock = g_variant_ref_sink (g_variant_new_from_bytes ((GVariantType*)OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT, - delta_superblock_data, FALSE)); + delta_superblock = g_variant_ref_sink (g_variant_new_from_bytes ( + (GVariantType *)OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT, delta_superblock_data, FALSE)); g_ptr_array_add (pull_data->static_delta_superblocks, g_variant_ref (delta_superblock)); - if (!process_one_static_delta (pull_data, from_revision, to_revision, delta_superblock, fetch_data->requested_ref, - pull_data->cancellable, error)) + if (!process_one_static_delta (pull_data, from_revision, to_revision, delta_superblock, + fetch_data->requested_ref, pull_data->cancellable, error)) goto out; } - out: +out: g_assert (pull_data->n_outstanding_metadata_fetches > 0); pull_data->n_outstanding_metadata_fetches--; @@ -2645,37 +2493,29 @@ on_superblock_fetched (GObject *src, } static void -start_fetch_delta_superblock (OtPullData *pull_data, - FetchDeltaSuperData *fetch_data) +start_fetch_delta_superblock (OtPullData *pull_data, FetchDeltaSuperData *fetch_data) { - g_autofree char *delta_name = - _ostree_get_relative_static_delta_superblock_path (fetch_data->from_revision, - fetch_data->to_revision); + g_autofree char *delta_name = _ostree_get_relative_static_delta_superblock_path ( + fetch_data->from_revision, fetch_data->to_revision); g_debug ("starting fetch of delta superblock %s", delta_name); - _ostree_fetcher_request_to_membuf (pull_data->fetcher, - pull_data->content_mirrorlist, - delta_name, OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, - NULL, 0, - OSTREE_MAX_METADATA_SIZE, - 0, pull_data->cancellable, - on_superblock_fetched, - g_steal_pointer (&fetch_data)); + _ostree_fetcher_request_to_membuf (pull_data->fetcher, pull_data->content_mirrorlist, delta_name, + OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, NULL, 0, + OSTREE_MAX_METADATA_SIZE, 0, pull_data->cancellable, + on_superblock_fetched, g_steal_pointer (&fetch_data)); pull_data->n_outstanding_metadata_fetches++; pull_data->n_requested_metadata++; } static void -enqueue_one_static_delta_superblock_request_s (OtPullData *pull_data, +enqueue_one_static_delta_superblock_request_s (OtPullData *pull_data, FetchDeltaSuperData *fetch_data) { if (fetcher_queue_is_full (pull_data)) { g_debug ("queuing fetch of static delta superblock %s-%s", - fetch_data->from_revision ?: "empty", - fetch_data->to_revision); + fetch_data->from_revision ?: "empty", fetch_data->to_revision); - g_hash_table_add (pull_data->pending_fetch_delta_superblocks, - g_steal_pointer (&fetch_data)); + g_hash_table_add (pull_data->pending_fetch_delta_superblocks, g_steal_pointer (&fetch_data)); } else { @@ -2685,12 +2525,11 @@ enqueue_one_static_delta_superblock_request_s (OtPullData *pull_data, /* Start a request for a static delta */ static void -enqueue_one_static_delta_superblock_request (OtPullData *pull_data, - const char *from_revision, - const char *to_revision, +enqueue_one_static_delta_superblock_request (OtPullData *pull_data, const char *from_revision, + const char *to_revision, const OstreeCollectionRef *ref) { - FetchDeltaSuperData *fdata = g_new0(FetchDeltaSuperData, 1); + FetchDeltaSuperData *fdata = g_new0 (FetchDeltaSuperData, 1); fdata->pull_data = pull_data; fdata->from_revision = g_strdup (from_revision); fdata->to_revision = g_strdup (to_revision); @@ -2701,8 +2540,7 @@ enqueue_one_static_delta_superblock_request (OtPullData *pull_dat } static gboolean -validate_variant_is_csum (GVariant *csum, - GError **error) +validate_variant_is_csum (GVariant *csum, GError **error) { if (!g_variant_is_of_type (csum, G_VARIANT_TYPE ("ay"))) return glnx_throw (error, "Invalid checksum variant of type '%s', expected 'ay'", @@ -2712,9 +2550,7 @@ validate_variant_is_csum (GVariant *csum, } static gboolean -collect_available_deltas_for_pull (OtPullData *pull_data, - GVariant *deltas, - GError **error) +collect_available_deltas_for_pull (OtPullData *pull_data, GVariant *deltas, GError **error) { gsize n; @@ -2722,8 +2558,8 @@ collect_available_deltas_for_pull (OtPullData *pull_data, for (gsize i = 0; i < n; i++) { const char *delta; - g_autoptr(GVariant) csum_v = NULL; - g_autoptr(GVariant) ref = g_variant_get_child_value (deltas, i); + g_autoptr (GVariant) csum_v = NULL; + g_autoptr (GVariant) ref = g_variant_get_child_value (deltas, i); g_variant_get_child (ref, 0, "&s", &delta); g_variant_get_child (ref, 1, "v", &csum_v); @@ -2733,57 +2569,50 @@ collect_available_deltas_for_pull (OtPullData *pull_data, guchar *csum_data = g_malloc (OSTREE_SHA256_DIGEST_LEN); memcpy (csum_data, ostree_checksum_bytes_peek (csum_v), 32); - g_hash_table_insert (pull_data->summary_deltas_checksums, - g_strdup (delta), - csum_data); + g_hash_table_insert (pull_data->summary_deltas_checksums, g_strdup (delta), csum_data); } return TRUE; } static void -on_delta_index_fetched (GObject *src, - GAsyncResult *res, - gpointer data) +on_delta_index_fetched (GObject *src, GAsyncResult *res, gpointer data) { FetchDeltaIndexData *fetch_data = data; OtPullData *pull_data = fetch_data->pull_data; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; - g_autoptr(GBytes) delta_index_data = NULL; + g_autoptr (GBytes) delta_index_data = NULL; const char *from_revision = fetch_data->from_revision; const char *to_revision = fetch_data->to_revision; - if (!_ostree_fetcher_request_to_membuf_finish ((OstreeFetcher*)src, - res, - &delta_index_data, - NULL, NULL, NULL, - error)) + if (!_ostree_fetcher_request_to_membuf_finish ((OstreeFetcher *)src, res, &delta_index_data, NULL, + NULL, NULL, error)) { if (!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) goto out; g_clear_error (&local_error); - /* below call to initiate_delta_request() will fail finding the delta and fall back to commit */ + /* below call to initiate_delta_request() will fail finding the delta and fall back to commit + */ } else { - g_autoptr(GVariant) delta_index = g_variant_ref_sink (g_variant_new_from_bytes (G_VARIANT_TYPE_VARDICT, delta_index_data, FALSE)); - g_autoptr(GVariant) deltas = g_variant_lookup_value (delta_index, OSTREE_SUMMARY_STATIC_DELTAS, G_VARIANT_TYPE ("a{sv}")); + g_autoptr (GVariant) delta_index = g_variant_ref_sink ( + g_variant_new_from_bytes (G_VARIANT_TYPE_VARDICT, delta_index_data, FALSE)); + g_autoptr (GVariant) deltas = g_variant_lookup_value ( + delta_index, OSTREE_SUMMARY_STATIC_DELTAS, G_VARIANT_TYPE ("a{sv}")); if (!collect_available_deltas_for_pull (pull_data, deltas, error)) goto out; } - if (!initiate_delta_request (pull_data, - fetch_data->requested_ref, - to_revision, - from_revision, + if (!initiate_delta_request (pull_data, fetch_data->requested_ref, to_revision, from_revision, &local_error)) goto out; - out: +out: g_assert (pull_data->n_outstanding_metadata_fetches > 0); pull_data->n_outstanding_metadata_fetches--; @@ -2799,35 +2628,27 @@ on_delta_index_fetched (GObject *src, } static void -start_fetch_delta_index (OtPullData *pull_data, - FetchDeltaIndexData *fetch_data) +start_fetch_delta_index (OtPullData *pull_data, FetchDeltaIndexData *fetch_data) { - g_autofree char *delta_name = - _ostree_get_relative_static_delta_index_path (fetch_data->to_revision); + g_autofree char *delta_name + = _ostree_get_relative_static_delta_index_path (fetch_data->to_revision); g_debug ("starting fetch of delta index %s", delta_name); - _ostree_fetcher_request_to_membuf (pull_data->fetcher, - pull_data->content_mirrorlist, - delta_name, OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, - NULL, 0, - OSTREE_MAX_METADATA_SIZE, - 0, pull_data->cancellable, - on_delta_index_fetched, - g_steal_pointer (&fetch_data)); + _ostree_fetcher_request_to_membuf (pull_data->fetcher, pull_data->content_mirrorlist, delta_name, + OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, NULL, 0, + OSTREE_MAX_METADATA_SIZE, 0, pull_data->cancellable, + on_delta_index_fetched, g_steal_pointer (&fetch_data)); pull_data->n_outstanding_metadata_fetches++; pull_data->n_requested_metadata++; } static void -enqueue_one_static_delta_index_request_s (OtPullData *pull_data, - FetchDeltaIndexData *fetch_data) +enqueue_one_static_delta_index_request_s (OtPullData *pull_data, FetchDeltaIndexData *fetch_data) { if (fetcher_queue_is_full (pull_data)) { - g_debug ("queuing fetch of static delta index to %s", - fetch_data->to_revision); + g_debug ("queuing fetch of static delta index to %s", fetch_data->to_revision); - g_hash_table_add (pull_data->pending_fetch_delta_indexes, - g_steal_pointer (&fetch_data)); + g_hash_table_add (pull_data->pending_fetch_delta_indexes, g_steal_pointer (&fetch_data)); } else { @@ -2837,12 +2658,10 @@ enqueue_one_static_delta_index_request_s (OtPullData *pull_data, /* Start a request for a static delta index */ static void -enqueue_one_static_delta_index_request (OtPullData *pull_data, - const char *to_revision, - const char *from_revision, - const OstreeCollectionRef *ref) +enqueue_one_static_delta_index_request (OtPullData *pull_data, const char *to_revision, + const char *from_revision, const OstreeCollectionRef *ref) { - FetchDeltaIndexData *fdata = g_new0(FetchDeltaIndexData, 1); + FetchDeltaIndexData *fdata = g_new0 (FetchDeltaIndexData, 1); fdata->pull_data = pull_data; fdata->from_revision = g_strdup (from_revision); fdata->to_revision = g_strdup (to_revision); @@ -2853,42 +2672,34 @@ enqueue_one_static_delta_index_request (OtPullData *pull_data, } static gboolean -_ostree_repo_verify_summary (OstreeRepo *self, - const char *name, - gboolean gpg_verify_summary, - GPtrArray *signapi_summary_verifiers, - GBytes *summary, - GBytes *signatures, - GCancellable *cancellable, - GError **error) +_ostree_repo_verify_summary (OstreeRepo *self, const char *name, gboolean gpg_verify_summary, + GPtrArray *signapi_summary_verifiers, GBytes *summary, + GBytes *signatures, GCancellable *cancellable, GError **error) { if (gpg_verify_summary) { if (summary == NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "GPG verification enabled, but no summary found (check that the configured URL in remote config is correct)"); + "GPG verification enabled, but no summary found (check that the configured " + "URL in remote config is correct)"); return FALSE; } if (signatures == NULL) { g_set_error (error, OSTREE_GPG_ERROR, OSTREE_GPG_ERROR_NO_SIGNATURE, - "GPG verification enabled, but no summary signatures found (use gpg-verify-summary=false in remote config to disable)"); + "GPG verification enabled, but no summary signatures found (use " + "gpg-verify-summary=false in remote config to disable)"); return FALSE; } /* Verify any summary signatures. */ if (summary != NULL && signatures != NULL) { - g_autoptr(OstreeGpgVerifyResult) result = NULL; - - result = ostree_repo_verify_summary (self, - name, - summary, - signatures, - cancellable, - error); + g_autoptr (OstreeGpgVerifyResult) result = NULL; + + result = ostree_repo_verify_summary (self, name, summary, signatures, cancellable, error); if (!ostree_gpg_verify_result_require_valid_signature (result, error)) return FALSE; } @@ -2899,26 +2710,29 @@ _ostree_repo_verify_summary (OstreeRepo *self, if (summary == NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "Signature verification enabled, but no summary found (check that the configured URL in remote config is correct)"); + "Signature verification enabled, but no summary found (check that the " + "configured URL in remote config is correct)"); return FALSE; } if (signatures == NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "Signature verification enabled, but no summary signatures found (use sign-verify-summary=false in remote config to disable)"); + "Signature verification enabled, but no summary signatures found (use " + "sign-verify-summary=false in remote config to disable)"); return FALSE; } /* Verify any summary signatures. */ if (summary != NULL && signatures != NULL) { - g_autoptr(GVariant) sig_variant = NULL; + g_autoptr (GVariant) sig_variant = NULL; - sig_variant = g_variant_new_from_bytes (OSTREE_SUMMARY_SIG_GVARIANT_FORMAT, - signatures, FALSE); + sig_variant + = g_variant_new_from_bytes (OSTREE_SUMMARY_SIG_GVARIANT_FORMAT, signatures, FALSE); - if (!_sign_verify_for_remote (signapi_summary_verifiers, summary, sig_variant, NULL, error)) + if (!_sign_verify_for_remote (signapi_summary_verifiers, summary, sig_variant, NULL, + error)) return FALSE; } } @@ -2927,11 +2741,9 @@ _ostree_repo_verify_summary (OstreeRepo *self, } static void -_ostree_repo_load_cache_summary_properties (OstreeRepo *self, - const char *filename, - const char *extension, - char **out_etag, - guint64 *out_last_modified) +_ostree_repo_load_cache_summary_properties (OstreeRepo *self, const char *filename, + const char *extension, char **out_etag, + guint64 *out_last_modified) { const char *file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", filename, extension); glnx_autofd int fd = -1; @@ -2944,7 +2756,7 @@ _ostree_repo_load_cache_summary_properties (OstreeRepo *self, if (out_etag != NULL) { - g_autoptr(GBytes) etag_bytes = glnx_fgetxattr_bytes (fd, "user.etag", NULL); + g_autoptr (GBytes) etag_bytes = glnx_fgetxattr_bytes (fd, "user.etag", NULL); if (etag_bytes != NULL) { const guint8 *buf; @@ -2965,7 +2777,7 @@ _ostree_repo_load_cache_summary_properties (OstreeRepo *self, /* Nul-terminate and return */ if (buf_len > 0) - *out_etag = g_strndup ((const char *) buf, buf_len); + *out_etag = g_strndup ((const char *)buf, buf_len); else *out_etag = NULL; } @@ -2985,16 +2797,12 @@ _ostree_repo_load_cache_summary_properties (OstreeRepo *self, } static gboolean -_ostree_repo_load_cache_summary_file (OstreeRepo *self, - const char *filename, - const char *extension, - GBytes **out_data, - GCancellable *cancellable, - GError **error) +_ostree_repo_load_cache_summary_file (OstreeRepo *self, const char *filename, const char *extension, + GBytes **out_data, GCancellable *cancellable, GError **error) { const char *file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", filename, extension); glnx_autofd int fd = -1; - g_autoptr(GBytes) data = NULL; + g_autoptr (GBytes) data = NULL; *out_data = NULL; @@ -3013,44 +2821,39 @@ _ostree_repo_load_cache_summary_file (OstreeRepo *self, if (!data) return FALSE; - *out_data =g_steal_pointer (&data); + *out_data = g_steal_pointer (&data); return TRUE; } /* Load the summary from the cache if the provided .sig file is the same as the cached version. */ static gboolean -_ostree_repo_load_cache_summary_if_same_sig (OstreeRepo *self, - const char *remote, - GBytes *summary_sig, - GBytes **out_summary, - GCancellable *cancellable, - GError **error) +_ostree_repo_load_cache_summary_if_same_sig (OstreeRepo *self, const char *remote, + GBytes *summary_sig, GBytes **out_summary, + GCancellable *cancellable, GError **error) { - g_autoptr(GBytes) old_sig_contents = NULL; + g_autoptr (GBytes) old_sig_contents = NULL; *out_summary = NULL; - if (!_ostree_repo_load_cache_summary_file (self, remote, ".sig", - &old_sig_contents, - cancellable, error)) + if (!_ostree_repo_load_cache_summary_file (self, remote, ".sig", &old_sig_contents, cancellable, + error)) return FALSE; - if (old_sig_contents != NULL && - g_bytes_compare (old_sig_contents, summary_sig) == 0) + if (old_sig_contents != NULL && g_bytes_compare (old_sig_contents, summary_sig) == 0) { - g_autoptr(GBytes) summary_data = NULL; + g_autoptr (GBytes) summary_data = NULL; - if (!_ostree_repo_load_cache_summary_file (self, remote, NULL, - &summary_data, - cancellable, error)) + if (!_ostree_repo_load_cache_summary_file (self, remote, NULL, &summary_data, cancellable, + error)) return FALSE; if (summary_data == NULL) { /* Cached signature without cached summary, remove the signature */ - const char *summary_cache_sig_file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", remote, ".sig"); - (void) unlinkat (self->cache_dir_fd, summary_cache_sig_file, 0); + const char *summary_cache_sig_file + = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", remote, ".sig"); + (void)unlinkat (self->cache_dir_fd, summary_cache_sig_file, 0); } else *out_summary = g_steal_pointer (&summary_data); @@ -3060,17 +2863,14 @@ _ostree_repo_load_cache_summary_if_same_sig (OstreeRepo *self, } static void -store_file_cache_properties (int dir_fd, - const char *filename, - const char *etag, - guint64 last_modified) +store_file_cache_properties (int dir_fd, const char *filename, const char *etag, + guint64 last_modified) { glnx_autofd int fd = -1; - struct timespec time_vals[] = - { - { .tv_sec = last_modified, .tv_nsec = UTIME_OMIT }, /* access, leave unchanged */ - { .tv_sec = last_modified, .tv_nsec = 0 }, /* modification */ - }; + struct timespec time_vals[] = { + { .tv_sec = last_modified, .tv_nsec = UTIME_OMIT }, /* access, leave unchanged */ + { .tv_sec = last_modified, .tv_nsec = 0 }, /* modification */ + }; if (!glnx_openat_rdonly (dir_fd, filename, TRUE, &fd, NULL)) return; @@ -3085,14 +2885,9 @@ store_file_cache_properties (int dir_fd, } static gboolean -_ostree_repo_save_cache_summary_file (OstreeRepo *self, - const char *filename, - const char *extension, - GBytes *data, - const char *etag, - guint64 last_modified, - GCancellable *cancellable, - GError **error) +_ostree_repo_save_cache_summary_file (OstreeRepo *self, const char *filename, const char *extension, + GBytes *data, const char *etag, guint64 last_modified, + GCancellable *cancellable, GError **error) { const char *file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", filename, extension); glnx_autofd int fd = -1; @@ -3100,15 +2895,14 @@ _ostree_repo_save_cache_summary_file (OstreeRepo *self, if (self->cache_dir_fd == -1) return TRUE; - if (!glnx_shutil_mkdir_p_at (self->cache_dir_fd, _OSTREE_SUMMARY_CACHE_DIR, DEFAULT_DIRECTORY_MODE, cancellable, error)) + if (!glnx_shutil_mkdir_p_at (self->cache_dir_fd, _OSTREE_SUMMARY_CACHE_DIR, + DEFAULT_DIRECTORY_MODE, cancellable, error)) return FALSE; - if (!glnx_file_replace_contents_at (self->cache_dir_fd, - file, - g_bytes_get_data (data, NULL), - g_bytes_get_size (data), - self->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : GLNX_FILE_REPLACE_DATASYNC_NEW, - cancellable, error)) + if (!glnx_file_replace_contents_at ( + self->cache_dir_fd, file, g_bytes_get_data (data, NULL), g_bytes_get_size (data), + self->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : GLNX_FILE_REPLACE_DATASYNC_NEW, + cancellable, error)) return FALSE; /* Store the caching properties. This is non-fatal on failure. */ @@ -3119,40 +2913,27 @@ _ostree_repo_save_cache_summary_file (OstreeRepo *self, /* Replace the current summary+signature with new versions */ static gboolean -_ostree_repo_cache_summary (OstreeRepo *self, - const char *remote, - GBytes *summary, - const char *summary_etag, - guint64 summary_last_modified, - GBytes *summary_sig, - const char *summary_sig_etag, - guint64 summary_sig_last_modified, - GCancellable *cancellable, - GError **error) +_ostree_repo_cache_summary (OstreeRepo *self, const char *remote, GBytes *summary, + const char *summary_etag, guint64 summary_last_modified, + GBytes *summary_sig, const char *summary_sig_etag, + guint64 summary_sig_last_modified, GCancellable *cancellable, + GError **error) { - if (!_ostree_repo_save_cache_summary_file (self, remote, NULL, - summary, - summary_etag, summary_last_modified, - cancellable, error)) + if (!_ostree_repo_save_cache_summary_file (self, remote, NULL, summary, summary_etag, + summary_last_modified, cancellable, error)) return FALSE; - if (!_ostree_repo_save_cache_summary_file (self, remote, ".sig", - summary_sig, - summary_sig_etag, summary_sig_last_modified, - cancellable, error)) + if (!_ostree_repo_save_cache_summary_file (self, remote, ".sig", summary_sig, summary_sig_etag, + summary_sig_last_modified, cancellable, error)) return FALSE; return TRUE; } static OstreeFetcher * -_ostree_repo_remote_new_fetcher (OstreeRepo *self, - const char *remote_name, - gboolean gzip, - GVariant *extra_headers, - const char *append_user_agent, - OstreeFetcherSecurityState *out_state, - GError **error) +_ostree_repo_remote_new_fetcher (OstreeRepo *self, const char *remote_name, gboolean gzip, + GVariant *extra_headers, const char *append_user_agent, + OstreeFetcherSecurityState *out_state, GError **error) { OstreeFetcher *fetcher = NULL; OstreeFetcherConfigFlags fetcher_flags = 0; @@ -3163,8 +2944,7 @@ _ostree_repo_remote_new_fetcher (OstreeRepo *self, g_return_val_if_fail (OSTREE_IS_REPO (self), NULL); g_return_val_if_fail (remote_name != NULL, NULL); - if (!ostree_repo_get_remote_boolean_option (self, remote_name, - "tls-permissive", FALSE, + if (!ostree_repo_get_remote_boolean_option (self, remote_name, "tls-permissive", FALSE, &tls_permissive, error)) goto out; @@ -3177,15 +2957,15 @@ _ostree_repo_remote_new_fetcher (OstreeRepo *self, if (gzip) fetcher_flags |= OSTREE_FETCHER_FLAGS_TRANSFER_GZIP; - { gboolean http2_default = TRUE; + { + gboolean http2_default = TRUE; #ifndef BUILDOPT_HTTP2 http2_default = FALSE; #endif gboolean http2; - if (!ostree_repo_get_remote_boolean_option (self, remote_name, - "http2", http2_default, - &http2, error)) + if (!ostree_repo_get_remote_boolean_option (self, remote_name, "http2", http2_default, &http2, + error)) goto out; if (!http2) fetcher_flags |= OSTREE_FETCHER_FLAGS_DISABLE_HTTP2; @@ -3197,12 +2977,10 @@ _ostree_repo_remote_new_fetcher (OstreeRepo *self, g_autofree char *tls_client_cert_path = NULL; g_autofree char *tls_client_key_path = NULL; - if (!ostree_repo_get_remote_option (self, remote_name, - "tls-client-cert-path", NULL, + if (!ostree_repo_get_remote_option (self, remote_name, "tls-client-cert-path", NULL, &tls_client_cert_path, error)) goto out; - if (!ostree_repo_get_remote_option (self, remote_name, - "tls-client-key-path", NULL, + if (!ostree_repo_get_remote_option (self, remote_name, "tls-client-key-path", NULL, &tls_client_key_path, error)) goto out; @@ -3223,9 +3001,8 @@ _ostree_repo_remote_new_fetcher (OstreeRepo *self, { g_autofree char *tls_ca_path = NULL; - if (!ostree_repo_get_remote_option (self, remote_name, - "tls-ca-path", NULL, - &tls_ca_path, error)) + if (!ostree_repo_get_remote_option (self, remote_name, "tls-ca-path", NULL, &tls_ca_path, + error)) goto out; if (tls_ca_path != NULL) @@ -3241,9 +3018,7 @@ _ostree_repo_remote_new_fetcher (OstreeRepo *self, { g_autofree char *http_proxy = NULL; - if (!ostree_repo_get_remote_option (self, remote_name, - "proxy", NULL, - &http_proxy, error)) + if (!ostree_repo_get_remote_option (self, remote_name, "proxy", NULL, &http_proxy, error)) goto out; if (http_proxy != NULL && http_proxy[0] != '\0') @@ -3256,9 +3031,9 @@ _ostree_repo_remote_new_fetcher (OstreeRepo *self, /* TODO; port away from this; a bit hard since both libsoup and libcurl * expect a file. Doing ot_fdrel_to_gfile() works for now though. */ - GFile*repo_path = ostree_repo_get_path (self); - g_autofree char *jar_path = - g_build_filename (gs_file_get_path_cached (repo_path), cookie_file, NULL); + GFile *repo_path = ostree_repo_get_path (self); + g_autofree char *jar_path + = g_build_filename (gs_file_get_path_cached (repo_path), cookie_file, NULL); if (g_file_test (jar_path, G_FILE_TEST_IS_REGULAR)) _ostree_fetcher_set_cookie_jar (fetcher, jar_path); @@ -3282,20 +3057,13 @@ out: } static gboolean -_ostree_preload_metadata_file (OstreeRepo *self, - OstreeFetcher *fetcher, - GPtrArray *mirrorlist, - const char *filename, - gboolean is_metalink, - const char *if_none_match, - guint64 if_modified_since, - guint n_network_retries, - GBytes **out_bytes, - gboolean *out_not_modified, - char **out_etag, - guint64 *out_last_modified, - GCancellable *cancellable, - GError **error) +_ostree_preload_metadata_file (OstreeRepo *self, OstreeFetcher *fetcher, GPtrArray *mirrorlist, + const char *filename, gboolean is_metalink, + const char *if_none_match, guint64 if_modified_since, + guint n_network_retries, GBytes **out_bytes, + gboolean *out_not_modified, char **out_etag, + guint64 *out_last_modified, GCancellable *cancellable, + GError **error) { if (is_metalink) { @@ -3303,13 +3071,10 @@ _ostree_preload_metadata_file (OstreeRepo *self, /* the metalink uri is buried in the mirrorlist as the first (and only) * element */ - g_autoptr(OstreeMetalink) metalink = - _ostree_metalink_new (fetcher, filename, - OSTREE_MAX_METADATA_SIZE, - mirrorlist->pdata[0], n_network_retries); + g_autoptr (OstreeMetalink) metalink = _ostree_metalink_new ( + fetcher, filename, OSTREE_MAX_METADATA_SIZE, mirrorlist->pdata[0], n_network_retries); - _ostree_metalink_request_sync (metalink, NULL, out_bytes, - cancellable, &local_error); + _ostree_metalink_request_sync (metalink, NULL, out_bytes, cancellable, &local_error); if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { @@ -3326,46 +3091,38 @@ _ostree_preload_metadata_file (OstreeRepo *self, } else { - return _ostree_fetcher_mirrored_request_to_membuf (fetcher, mirrorlist, filename, - OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, - if_none_match, if_modified_since, - n_network_retries, - out_bytes, out_not_modified, out_etag, out_last_modified, - OSTREE_MAX_METADATA_SIZE, - cancellable, error); + return _ostree_fetcher_mirrored_request_to_membuf ( + fetcher, mirrorlist, filename, OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, if_none_match, + if_modified_since, n_network_retries, out_bytes, out_not_modified, out_etag, + out_last_modified, OSTREE_MAX_METADATA_SIZE, cancellable, error); } } static gboolean -fetch_mirrorlist (OstreeFetcher *fetcher, - const char *mirrorlist_url, - guint n_network_retries, - GPtrArray **out_mirrorlist, - GCancellable *cancellable, - GError **error) +fetch_mirrorlist (OstreeFetcher *fetcher, const char *mirrorlist_url, guint n_network_retries, + GPtrArray **out_mirrorlist, GCancellable *cancellable, GError **error) { - g_autoptr(GPtrArray) ret_mirrorlist = - g_ptr_array_new_with_free_func ((GDestroyNotify) _ostree_fetcher_uri_free); + g_autoptr (GPtrArray) ret_mirrorlist + = g_ptr_array_new_with_free_func ((GDestroyNotify)_ostree_fetcher_uri_free); - g_autoptr(OstreeFetcherURI) mirrorlist = _ostree_fetcher_uri_parse (mirrorlist_url, error); + g_autoptr (OstreeFetcherURI) mirrorlist = _ostree_fetcher_uri_parse (mirrorlist_url, error); if (!mirrorlist) return FALSE; g_autofree char *contents = NULL; - if (!fetch_uri_contents_utf8_sync (fetcher, mirrorlist, n_network_retries, - &contents, cancellable, error)) - return glnx_prefix_error (error, "While fetching mirrorlist '%s'", - mirrorlist_url); + if (!fetch_uri_contents_utf8_sync (fetcher, mirrorlist, n_network_retries, &contents, cancellable, + error)) + return glnx_prefix_error (error, "While fetching mirrorlist '%s'", mirrorlist_url); /* go through each mirror in mirrorlist and do a quick sanity check that it * works so that we don't waste the fetcher's time when it goes through them * */ - g_auto(GStrv) lines = g_strsplit (contents, "\n", -1); + g_auto (GStrv) lines = g_strsplit (contents, "\n", -1); g_debug ("Scanning mirrorlist from '%s'", mirrorlist_url); for (char **iter = lines; iter && *iter; iter++) { const char *mirror_uri_str = *iter; - g_autoptr(OstreeFetcherURI) mirror_uri = NULL; + g_autoptr (OstreeFetcherURI) mirror_uri = NULL; g_autofree char *scheme = NULL; /* let's be nice and support empty lines and comments */ @@ -3397,15 +3154,16 @@ fetch_mirrorlist (OstreeFetcher *fetcher, if (ret_mirrorlist->len == 0) { GError *local_error = NULL; - g_autoptr(OstreeFetcherURI) config_uri = _ostree_fetcher_uri_new_subpath (mirror_uri, "config"); + g_autoptr (OstreeFetcherURI) config_uri + = _ostree_fetcher_uri_new_subpath (mirror_uri, "config"); - if (fetch_uri_contents_utf8_sync (fetcher, config_uri, n_network_retries, - NULL, cancellable, &local_error)) + if (fetch_uri_contents_utf8_sync (fetcher, config_uri, n_network_retries, NULL, + cancellable, &local_error)) g_ptr_array_add (ret_mirrorlist, g_steal_pointer (&mirror_uri)); else { - g_debug ("Failed to fetch config from mirror '%s': %s", - mirror_uri_str, local_error->message); + g_debug ("Failed to fetch config from mirror '%s': %s", mirror_uri_str, + local_error->message); g_clear_error (&local_error); } } @@ -3416,22 +3174,17 @@ fetch_mirrorlist (OstreeFetcher *fetcher, } if (ret_mirrorlist->len == 0) - return glnx_throw (error, "No valid mirrors were found in mirrorlist '%s'", - mirrorlist_url); + return glnx_throw (error, "No valid mirrors were found in mirrorlist '%s'", mirrorlist_url); *out_mirrorlist = g_steal_pointer (&ret_mirrorlist); return TRUE; } static gboolean -compute_effective_mirrorlist (OstreeRepo *self, - const char *remote_name_or_baseurl, - const char *url_override, - OstreeFetcher *fetcher, - guint n_network_retries, - GPtrArray **out_mirrorlist, - GCancellable *cancellable, - GError **error) +compute_effective_mirrorlist (OstreeRepo *self, const char *remote_name_or_baseurl, + const char *url_override, OstreeFetcher *fetcher, + guint n_network_retries, GPtrArray **out_mirrorlist, + GCancellable *cancellable, GError **error) { g_autofree char *baseurl = NULL; @@ -3442,16 +3195,13 @@ compute_effective_mirrorlist (OstreeRepo *self, if (g_str_has_prefix (baseurl, "mirrorlist=")) { - if (!fetch_mirrorlist (fetcher, - baseurl + strlen ("mirrorlist="), - n_network_retries, - out_mirrorlist, - cancellable, error)) + if (!fetch_mirrorlist (fetcher, baseurl + strlen ("mirrorlist="), n_network_retries, + out_mirrorlist, cancellable, error)) return FALSE; } else { - g_autoptr(OstreeFetcherURI) baseuri = _ostree_fetcher_uri_parse (baseurl, error); + g_autoptr (OstreeFetcherURI) baseuri = _ostree_fetcher_uri_parse (baseurl, error); if (!baseuri) return FALSE; @@ -3459,8 +3209,7 @@ compute_effective_mirrorlist (OstreeRepo *self, if (!_ostree_fetcher_uri_validate (baseuri, error)) return FALSE; - *out_mirrorlist = - g_ptr_array_new_with_free_func ((GDestroyNotify) _ostree_fetcher_uri_free); + *out_mirrorlist = g_ptr_array_new_with_free_func ((GDestroyNotify)_ostree_fetcher_uri_free); g_ptr_array_add (*out_mirrorlist, g_steal_pointer (&baseuri)); } return TRUE; @@ -3470,15 +3219,12 @@ compute_effective_mirrorlist (OstreeRepo *self, * any options specific to this pull (such as extra headers). */ static gboolean -reinitialize_fetcher (OtPullData *pull_data, const char *remote_name, - GError **error) +reinitialize_fetcher (OtPullData *pull_data, const char *remote_name, GError **error) { g_clear_object (&pull_data->fetcher); - pull_data->fetcher = _ostree_repo_remote_new_fetcher (pull_data->repo, remote_name, FALSE, - pull_data->extra_headers, - pull_data->append_user_agent, - &pull_data->fetcher_security_state, - error); + pull_data->fetcher = _ostree_repo_remote_new_fetcher ( + pull_data->repo, remote_name, FALSE, pull_data->extra_headers, pull_data->append_user_agent, + &pull_data->fetcher_security_state, error); if (pull_data->fetcher == NULL) return FALSE; @@ -3486,17 +3232,14 @@ reinitialize_fetcher (OtPullData *pull_data, const char *remote_name, } static gboolean -initiate_delta_request (OtPullData *pull_data, - const OstreeCollectionRef *ref, - const char *to_revision, - const char *delta_from_revision, - GError **error) +initiate_delta_request (OtPullData *pull_data, const OstreeCollectionRef *ref, + const char *to_revision, const char *delta_from_revision, GError **error) { DeltaSearchResult deltares; /* Look for a delta to @to_revision in the summary data */ - if (!get_best_static_delta_start_for (pull_data, to_revision, &deltares, - pull_data->cancellable, error)) + if (!get_best_static_delta_start_for (pull_data, to_revision, &deltares, pull_data->cancellable, + error)) return FALSE; switch (deltares.result) @@ -3509,11 +3252,13 @@ initiate_delta_request (OtPullData *pull_data, return FALSE; } else /* No deltas, fall back to object fetches. */ - queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, 0, ref); + queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, + 0, ref); } break; case DELTA_SEARCH_RESULT_FROM: - enqueue_one_static_delta_superblock_request (pull_data, deltares.from_revision, to_revision, ref); + enqueue_one_static_delta_superblock_request (pull_data, deltares.from_revision, to_revision, + ref); break; case DELTA_SEARCH_RESULT_SCRATCH: { @@ -3522,7 +3267,8 @@ initiate_delta_request (OtPullData *pull_data, * commits out of date; so doing an object pull is likely more * bandwidth efficient. */ if (delta_from_revision != NULL) - queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, 0, ref); + queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, + 0, ref); else enqueue_one_static_delta_superblock_request (pull_data, NULL, to_revision, ref); } @@ -3537,7 +3283,8 @@ initiate_delta_request (OtPullData *pull_data, if (pull_data->require_static_deltas) break; else - queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, 0, ref); + queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, + 0, ref); } } @@ -3556,17 +3303,16 @@ initiate_delta_request (OtPullData *pull_data, * `disable_static_deltas` and `require_static_deltas`. */ static gboolean -initiate_request (OtPullData *pull_data, - const OstreeCollectionRef *ref, - const char *to_revision, - GError **error) +initiate_request (OtPullData *pull_data, const OstreeCollectionRef *ref, const char *to_revision, + GError **error) { g_autofree char *delta_from_revision = NULL; /* Are deltas disabled? OK, just start an object fetch and be done */ if (pull_data->disable_static_deltas) { - queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, 0, ref); + queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, 0, + ref); return TRUE; } @@ -3577,8 +3323,7 @@ initiate_request (OtPullData *pull_data, g_autofree char *refspec = NULL; if (pull_data->remote_name != NULL) refspec = g_strdup_printf ("%s:%s", pull_data->remote_name, ref->ref_name); - if (!ostree_repo_resolve_rev (pull_data->repo, - refspec ?: ref->ref_name, TRUE, + if (!ostree_repo_resolve_rev (pull_data->repo, refspec ?: ref->ref_name, TRUE, &delta_from_revision, error)) return FALSE; } @@ -3622,9 +3367,11 @@ initiate_request (OtPullData *pull_data, * delta. */ if (delta_from_revision && g_str_equal (delta_from_revision, to_revision)) - queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, 0, ref); + queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, 0, + ref); else - enqueue_one_static_delta_superblock_request (pull_data, delta_from_revision ?: NULL, to_revision, ref); + enqueue_one_static_delta_superblock_request (pull_data, delta_from_revision ?: NULL, + to_revision, ref); } else { @@ -3638,10 +3385,11 @@ initiate_request (OtPullData *pull_data, } static gboolean -all_requested_refs_have_commit (GHashTable *requested_refs /* (element-type OstreeCollectionRef utf8) */) +all_requested_refs_have_commit ( + GHashTable *requested_refs /* (element-type OstreeCollectionRef utf8) */) { - GLNX_HASH_TABLE_FOREACH_KV (requested_refs, const OstreeCollectionRef*, ref, - const char*, override_commitid) + GLNX_HASH_TABLE_FOREACH_KV (requested_refs, const OstreeCollectionRef *, ref, const char *, + override_commitid) { /* Note: "" override means whatever is latest */ if (override_commitid == NULL || *override_commitid == 0) @@ -3686,15 +3434,21 @@ all_requested_refs_have_commit (GHashTable *requested_refs /* (element-type Ostr * * `disable-static-deltas` (`b`): Do not use static deltas * * `require-static-deltas` (`b`): Require static deltas * * `override-commit-ids` (`as`): Array of specific commit IDs to fetch for refs - * * `timestamp-check` (`b`): Verify commit timestamps are newer than current (when pulling via ref); Since: 2017.11 - * * `timestamp-check-from-rev` (`s`): Verify that all fetched commit timestamps are newer than timestamp of given rev; Since: 2020.4 - * * `max-metadata-size` (`t`): Restrict metadata objects to a maximum number of bytes; 0 to disable. Since: 2018.9 + * * `timestamp-check` (`b`): Verify commit timestamps are newer than current (when pulling via + * ref); Since: 2017.11 + * * `timestamp-check-from-rev` (`s`): Verify that all fetched commit timestamps are newer than + * timestamp of given rev; Since: 2020.4 + * * `max-metadata-size` (`t`): Restrict metadata objects to a maximum number of bytes; 0 to + * disable. Since: 2018.9 * * `dry-run` (`b`): Only print information on what will be downloaded (requires static deltas) * * `override-url` (`s`): Fetch objects from this URL if remote specifies no metalink in options - * * `inherit-transaction` (`b`): Don't initiate, finish or abort a transaction, useful to do multiple pulls in one transaction. + * * `inherit-transaction` (`b`): Don't initiate, finish or abort a transaction, useful to do + * multiple pulls in one transaction. * * `http-headers` (`a(ss)`): Additional headers to add to all HTTP requests - * * `update-frequency` (`u`): Frequency to call the async progress callback in milliseconds, if any; only values higher than 0 are valid - * * `localcache-repos` (`as`): File paths for local repos to use as caches when doing remote fetches + * * `update-frequency` (`u`): Frequency to call the async progress callback in milliseconds, if + * any; only values higher than 0 are valid + * * `localcache-repos` (`as`): File paths for local repos to use as caches when doing remote + * fetches * * `append-user-agent` (`s`): Additional string to append to the user agent * * `n-network-retries` (`u`): Number of times to retry each download on receiving * a transient network error, such as a socket timeout; default is 5, 0 @@ -3719,24 +3473,24 @@ all_requested_refs_have_commit (GHashTable *requested_refs /* (element-type Ostr * Since: 2020.9 */ gboolean -ostree_repo_pull_with_options (OstreeRepo *self, - const char *remote_name_or_baseurl, - GVariant *options, - OstreeAsyncProgress *progress, - GCancellable *cancellable, - GError **error) +ostree_repo_pull_with_options (OstreeRepo *self, const char *remote_name_or_baseurl, + GVariant *options, OstreeAsyncProgress *progress, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; - g_autoptr(GBytes) bytes_summary = NULL; + g_autoptr (GBytes) bytes_summary = NULL; gboolean summary_not_modified = FALSE; g_autofree char *summary_etag = NULL; guint64 summary_last_modified = 0; g_autofree char *metalink_url_str = NULL; - g_autoptr(GHashTable) requested_refs_to_fetch = NULL; /* (element-type OstreeCollectionRef utf8) */ - g_autoptr(GHashTable) commits_to_fetch = NULL; + g_autoptr (GHashTable) requested_refs_to_fetch + = NULL; /* (element-type OstreeCollectionRef utf8) */ + g_autoptr (GHashTable) commits_to_fetch = NULL; g_autofree char *remote_mode_str = NULL; - g_autoptr(OstreeMetalink) metalink = NULL; - OtPullData pull_data_real = { 0, }; + g_autoptr (OstreeMetalink) metalink = NULL; + OtPullData pull_data_real = { + 0, + }; OtPullData *pull_data = &pull_data_real; GKeyFile *remote_config = NULL; char **configured_branches = NULL; @@ -3747,9 +3501,9 @@ ostree_repo_pull_with_options (OstreeRepo *self, const char *dir_to_pull = NULL; g_autofree char **dirs_to_pull = NULL; g_autofree char **refs_to_fetch = NULL; - g_autoptr(GVariantIter) collection_refs_iter = NULL; + g_autoptr (GVariantIter) collection_refs_iter = NULL; g_autofree char **override_commit_ids = NULL; - g_autoptr(GSource) update_timeout = NULL; + g_autoptr (GSource) update_timeout = NULL; gboolean opt_per_object_fsync = FALSE; gboolean opt_gpg_verify_set = FALSE; gboolean opt_gpg_verify_summary_set = FALSE; @@ -3763,17 +3517,20 @@ ostree_repo_pull_with_options (OstreeRepo *self, const char *url_override = NULL; gboolean inherit_transaction = FALSE; gboolean require_summary_for_mirror = FALSE; - g_autoptr(GHashTable) updated_requested_refs_to_fetch = NULL; /* (element-type OstreeCollectionRef utf8) */ + g_autoptr (GHashTable) updated_requested_refs_to_fetch + = NULL; /* (element-type OstreeCollectionRef utf8) */ gsize i; g_autofree char **opt_localcache_repos = NULL; - g_autoptr(GVariantIter) ref_keyring_map_iter = NULL; - g_autoptr(GVariant) summary_bytes_v = NULL; - g_autoptr(GVariant) summary_sig_bytes_v = NULL; + g_autoptr (GVariantIter) ref_keyring_map_iter = NULL; + g_autoptr (GVariant) summary_bytes_v = NULL; + g_autoptr (GVariant) summary_sig_bytes_v = NULL; /* If refs or collection-refs has exactly one value, this will point to that * value, otherwise NULL. Used for logging. */ const char *the_ref_to_fetch = NULL; - OstreeRepoTransactionStats tstats = { 0, }; + OstreeRepoTransactionStats tstats = { + 0, + }; gboolean remote_mode_loaded = FALSE; /* Default */ @@ -3782,43 +3539,47 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (options) { int flags_i = OSTREE_REPO_PULL_FLAGS_NONE; - (void) g_variant_lookup (options, "refs", "^a&s", &refs_to_fetch); - opt_collection_refs_set = - g_variant_lookup (options, "collection-refs", "a(sss)", &collection_refs_iter); - (void) g_variant_lookup (options, "flags", "i", &flags_i); + (void)g_variant_lookup (options, "refs", "^a&s", &refs_to_fetch); + opt_collection_refs_set + = g_variant_lookup (options, "collection-refs", "a(sss)", &collection_refs_iter); + (void)g_variant_lookup (options, "flags", "i", &flags_i); /* Reduce risk of issues if enum happens to be 64 bit for some reason */ flags = flags_i; - (void) g_variant_lookup (options, "subdir", "&s", &dir_to_pull); - (void) g_variant_lookup (options, "subdirs", "^a&s", &dirs_to_pull); - (void) g_variant_lookup (options, "override-remote-name", "s", &pull_data->remote_refspec_name); - opt_gpg_verify_set = - g_variant_lookup (options, "gpg-verify", "b", &pull_data->gpg_verify); - opt_gpg_verify_summary_set = - g_variant_lookup (options, "gpg-verify-summary", "b", &pull_data->gpg_verify_summary); + (void)g_variant_lookup (options, "subdir", "&s", &dir_to_pull); + (void)g_variant_lookup (options, "subdirs", "^a&s", &dirs_to_pull); + (void)g_variant_lookup (options, "override-remote-name", "s", + &pull_data->remote_refspec_name); + opt_gpg_verify_set = g_variant_lookup (options, "gpg-verify", "b", &pull_data->gpg_verify); + opt_gpg_verify_summary_set + = g_variant_lookup (options, "gpg-verify-summary", "b", &pull_data->gpg_verify_summary); g_variant_lookup (options, "disable-sign-verify", "b", &disable_sign_verify); g_variant_lookup (options, "disable-sign-verify-summary", "b", &disable_sign_verify_summary); - (void) g_variant_lookup (options, "depth", "i", &pull_data->maxdepth); - (void) g_variant_lookup (options, "disable-static-deltas", "b", &pull_data->disable_static_deltas); - (void) g_variant_lookup (options, "require-static-deltas", "b", &pull_data->require_static_deltas); - (void) g_variant_lookup (options, "override-commit-ids", "^a&s", &override_commit_ids); - (void) g_variant_lookup (options, "dry-run", "b", &pull_data->dry_run); - (void) g_variant_lookup (options, "per-object-fsync", "b", &opt_per_object_fsync); - (void) g_variant_lookup (options, "override-url", "&s", &url_override); - (void) g_variant_lookup (options, "inherit-transaction", "b", &inherit_transaction); - (void) g_variant_lookup (options, "http-headers", "@a(ss)", &pull_data->extra_headers); - (void) g_variant_lookup (options, "update-frequency", "u", &update_frequency); - (void) g_variant_lookup (options, "localcache-repos", "^a&s", &opt_localcache_repos); - (void) g_variant_lookup (options, "timestamp-check", "b", &pull_data->timestamp_check); - (void) g_variant_lookup (options, "timestamp-check-from-rev", "s", &pull_data->timestamp_check_from_rev); - (void) g_variant_lookup (options, "max-metadata-size", "t", &pull_data->max_metadata_size); - (void) g_variant_lookup (options, "append-user-agent", "s", &pull_data->append_user_agent); - opt_n_network_retries_set = - g_variant_lookup (options, "n-network-retries", "u", &pull_data->n_network_retries); - opt_ref_keyring_map_set = - g_variant_lookup (options, "ref-keyring-map", "a(sss)", &ref_keyring_map_iter); - (void) g_variant_lookup (options, "summary-bytes", "@ay", &summary_bytes_v); - (void) g_variant_lookup (options, "summary-sig-bytes", "@ay", &summary_sig_bytes_v); - (void) g_variant_lookup (options, "disable-verify-bindings", "b", &pull_data->disable_verify_bindings); + (void)g_variant_lookup (options, "depth", "i", &pull_data->maxdepth); + (void)g_variant_lookup (options, "disable-static-deltas", "b", + &pull_data->disable_static_deltas); + (void)g_variant_lookup (options, "require-static-deltas", "b", + &pull_data->require_static_deltas); + (void)g_variant_lookup (options, "override-commit-ids", "^a&s", &override_commit_ids); + (void)g_variant_lookup (options, "dry-run", "b", &pull_data->dry_run); + (void)g_variant_lookup (options, "per-object-fsync", "b", &opt_per_object_fsync); + (void)g_variant_lookup (options, "override-url", "&s", &url_override); + (void)g_variant_lookup (options, "inherit-transaction", "b", &inherit_transaction); + (void)g_variant_lookup (options, "http-headers", "@a(ss)", &pull_data->extra_headers); + (void)g_variant_lookup (options, "update-frequency", "u", &update_frequency); + (void)g_variant_lookup (options, "localcache-repos", "^a&s", &opt_localcache_repos); + (void)g_variant_lookup (options, "timestamp-check", "b", &pull_data->timestamp_check); + (void)g_variant_lookup (options, "timestamp-check-from-rev", "s", + &pull_data->timestamp_check_from_rev); + (void)g_variant_lookup (options, "max-metadata-size", "t", &pull_data->max_metadata_size); + (void)g_variant_lookup (options, "append-user-agent", "s", &pull_data->append_user_agent); + opt_n_network_retries_set + = g_variant_lookup (options, "n-network-retries", "u", &pull_data->n_network_retries); + opt_ref_keyring_map_set + = g_variant_lookup (options, "ref-keyring-map", "a(sss)", &ref_keyring_map_iter); + (void)g_variant_lookup (options, "summary-bytes", "@ay", &summary_bytes_v); + (void)g_variant_lookup (options, "summary-sig-bytes", "@ay", &summary_sig_bytes_v); + (void)g_variant_lookup (options, "disable-verify-bindings", "b", + &pull_data->disable_verify_bindings); if (pull_data->remote_refspec_name != NULL) pull_data->remote_name = g_strdup (pull_data->remote_refspec_name); @@ -3827,21 +3588,21 @@ ostree_repo_pull_with_options (OstreeRepo *self, #ifdef OSTREE_DISABLE_GPGME /* Explicitly fail here if gpg verification is requested and we have no GPG support */ if (pull_data->gpg_verify || pull_data->gpg_verify_summary) - { + { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, - "'%s': GPG feature is disabled at build time", - __FUNCTION__); + "'%s': GPG feature is disabled at build time", __FUNCTION__); goto out; - } + } #endif g_return_val_if_fail (OSTREE_IS_REPO (self), FALSE); g_return_val_if_fail (pull_data->maxdepth >= -1, FALSE); g_return_val_if_fail (!pull_data->timestamp_check || pull_data->maxdepth == 0, FALSE); - g_return_val_if_fail (!opt_collection_refs_set || - (refs_to_fetch == NULL && override_commit_ids == NULL), FALSE); + g_return_val_if_fail ( + !opt_collection_refs_set || (refs_to_fetch == NULL && override_commit_ids == NULL), FALSE); if (refs_to_fetch && override_commit_ids) - g_return_val_if_fail (g_strv_length (refs_to_fetch) == g_strv_length (override_commit_ids), FALSE); + g_return_val_if_fail (g_strv_length (refs_to_fetch) == g_strv_length (override_commit_ids), + FALSE); if (dir_to_pull) g_return_val_if_fail (dir_to_pull[0] == '/', FALSE); @@ -3849,7 +3610,8 @@ ostree_repo_pull_with_options (OstreeRepo *self, for (i = 0; dirs_to_pull != NULL && dirs_to_pull[i] != NULL; i++) g_return_val_if_fail (dirs_to_pull[i][0] == '/', FALSE); - g_return_val_if_fail (!(pull_data->disable_static_deltas && pull_data->require_static_deltas), FALSE); + g_return_val_if_fail (!(pull_data->disable_static_deltas && pull_data->require_static_deltas), + FALSE); /* We only do dry runs with static deltas, because we don't really have any * in-advance information for bare fetches. @@ -3888,43 +3650,43 @@ ostree_repo_pull_with_options (OstreeRepo *self, pull_data->repo = self; pull_data->progress = progress; - pull_data->expected_commit_sizes = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, - (GDestroyNotify)g_free); - pull_data->commit_to_depth = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, - NULL); - pull_data->summary_deltas_checksums = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, - (GDestroyNotify)g_free); - pull_data->ref_original_commits = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, - (GDestroyNotify)NULL, - (GDestroyNotify)g_free); - pull_data->verified_commits = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, NULL); - pull_data->signapi_verified_commits = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, NULL); - pull_data->ref_keyring_map = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, - (GDestroyNotify)ostree_collection_ref_free, (GDestroyNotify)g_free); + pull_data->expected_commit_sizes = g_hash_table_new_full ( + g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)g_free); + pull_data->commit_to_depth + = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, NULL); + pull_data->summary_deltas_checksums = g_hash_table_new_full ( + g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)g_free); + pull_data->ref_original_commits + = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, + (GDestroyNotify)NULL, (GDestroyNotify)g_free); + pull_data->verified_commits + = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, NULL); + pull_data->signapi_verified_commits + = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, NULL); + pull_data->ref_keyring_map + = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, + (GDestroyNotify)ostree_collection_ref_free, (GDestroyNotify)g_free); pull_data->scanned_metadata = g_hash_table_new_full (ostree_hash_object_name, g_variant_equal, (GDestroyNotify)g_variant_unref, NULL); - pull_data->fetched_detached_metadata = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, (GDestroyNotify)variant_or_null_unref); - pull_data->requested_content = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, NULL); - pull_data->requested_fallback_content = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, NULL); + pull_data->fetched_detached_metadata = g_hash_table_new_full ( + g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)variant_or_null_unref); + pull_data->requested_content + = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, NULL); + pull_data->requested_fallback_content + = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, NULL); pull_data->requested_metadata = g_hash_table_new_full (ostree_hash_object_name, g_variant_equal, (GDestroyNotify)g_variant_unref, NULL); - pull_data->pending_fetch_content = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, - (GDestroyNotify)fetch_object_data_free); - pull_data->pending_fetch_metadata = g_hash_table_new_full (ostree_hash_object_name, g_variant_equal, - (GDestroyNotify)g_variant_unref, - (GDestroyNotify)fetch_object_data_free); - pull_data->pending_fetch_delta_indexes = g_hash_table_new_full (NULL, NULL, (GDestroyNotify) fetch_delta_index_data_free, NULL); - pull_data->pending_fetch_delta_superblocks = g_hash_table_new_full (NULL, NULL, (GDestroyNotify) fetch_delta_super_data_free, NULL); - pull_data->pending_fetch_deltaparts = g_hash_table_new_full (NULL, NULL, (GDestroyNotify)fetch_static_delta_data_free, NULL); + pull_data->pending_fetch_content = g_hash_table_new_full ( + g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)fetch_object_data_free); + pull_data->pending_fetch_metadata = g_hash_table_new_full ( + ostree_hash_object_name, g_variant_equal, (GDestroyNotify)g_variant_unref, + (GDestroyNotify)fetch_object_data_free); + pull_data->pending_fetch_delta_indexes + = g_hash_table_new_full (NULL, NULL, (GDestroyNotify)fetch_delta_index_data_free, NULL); + pull_data->pending_fetch_delta_superblocks + = g_hash_table_new_full (NULL, NULL, (GDestroyNotify)fetch_delta_super_data_free, NULL); + pull_data->pending_fetch_deltaparts + = g_hash_table_new_full (NULL, NULL, (GDestroyNotify)fetch_static_delta_data_free, NULL); if (opt_localcache_repos && *opt_localcache_repos) { @@ -3932,8 +3694,8 @@ ostree_repo_pull_with_options (OstreeRepo *self, for (char **it = opt_localcache_repos; it && *it; it++) { const char *localcache_path = *it; - g_autoptr(GFile) localcache_file = g_file_new_for_path (localcache_path); - g_autoptr(OstreeRepo) cacherepo = ostree_repo_new (localcache_file); + g_autoptr (GFile) localcache_file = g_file_new_for_path (localcache_path); + g_autoptr (OstreeRepo) cacherepo = ostree_repo_new (localcache_file); if (!ostree_repo_open (cacherepo, cancellable, error)) goto out; g_ptr_array_add (pull_data->localcache_repos, g_steal_pointer (&cacherepo)); @@ -3962,10 +3724,8 @@ ostree_repo_pull_with_options (OstreeRepo *self, /* For compatibility with pull-local, don't gpg verify local * pulls by default. */ - if ((pull_data->gpg_verify || - pull_data->gpg_verify_summary - ) && - pull_data->remote_name == NULL) + if ((pull_data->gpg_verify || pull_data->gpg_verify_summary) + && pull_data->remote_name == NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Must specify remote name to enable gpg verification"); @@ -3995,23 +3755,19 @@ ostree_repo_pull_with_options (OstreeRepo *self, /* NOTE: If changing this, see the matching implementation in * ostree-sysroot-upgrader.c */ - if (!ostree_repo_get_remote_option (self, pull_data->remote_name, - "unconfigured-state", NULL, - &unconfigured_state, - error)) + if (!ostree_repo_get_remote_option (self, pull_data->remote_name, "unconfigured-state", NULL, + &unconfigured_state, error)) goto out; if (unconfigured_state) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "remote unconfigured-state: %s", unconfigured_state); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "remote unconfigured-state: %s", + unconfigured_state); goto out; } - if (!ostree_repo_get_remote_option (self, pull_data->remote_name, - "custom-backend", NULL, - &custom_backend, - error)) + if (!ostree_repo_get_remote_option (self, pull_data->remote_name, "custom-backend", NULL, + &custom_backend, error)) goto out; if (custom_backend) @@ -4027,8 +3783,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, { if (!_signapi_init_for_remote (pull_data->repo, pull_data->remote_name, &pull_data->signapi_commit_verifiers, - &pull_data->signapi_summary_verifiers, - error)) + &pull_data->signapi_summary_verifiers, error)) goto out; } @@ -4038,32 +3793,28 @@ ostree_repo_pull_with_options (OstreeRepo *self, goto out; pull_data->tmpdir_dfd = pull_data->repo->tmp_dir_fd; - requested_refs_to_fetch = g_hash_table_new_full (ostree_collection_ref_hash, - ostree_collection_ref_equal, - (GDestroyNotify) ostree_collection_ref_free, - g_free); + requested_refs_to_fetch + = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, + (GDestroyNotify)ostree_collection_ref_free, g_free); commits_to_fetch = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - if (!ostree_repo_get_remote_option (self, - remote_name_or_baseurl, "metalink", - NULL, &metalink_url_str, error)) + if (!ostree_repo_get_remote_option (self, remote_name_or_baseurl, "metalink", NULL, + &metalink_url_str, error)) goto out; if (!metalink_url_str) { - if (!compute_effective_mirrorlist (self, remote_name_or_baseurl, - url_override, - pull_data->fetcher, - pull_data->n_network_retries, - &pull_data->meta_mirrorlist, - cancellable, error)) + if (!compute_effective_mirrorlist (self, remote_name_or_baseurl, url_override, + pull_data->fetcher, pull_data->n_network_retries, + &pull_data->meta_mirrorlist, cancellable, error)) goto out; } else { - g_autoptr(GBytes) summary_bytes = NULL; - g_autoptr(OstreeFetcherURI) metalink_uri = _ostree_fetcher_uri_parse (metalink_url_str, error); - g_autoptr(OstreeFetcherURI) target_uri = NULL; + g_autoptr (GBytes) summary_bytes = NULL; + g_autoptr (OstreeFetcherURI) metalink_uri + = _ostree_fetcher_uri_parse (metalink_url_str, error); + g_autoptr (OstreeFetcherURI) target_uri = NULL; if (!metalink_uri) goto out; @@ -4072,15 +3823,11 @@ ostree_repo_pull_with_options (OstreeRepo *self, * re-downloads here. Would require additional support for caching the * metalink file or mirror list. */ - metalink = _ostree_metalink_new (pull_data->fetcher, "summary", - OSTREE_MAX_METADATA_SIZE, metalink_uri, - pull_data->n_network_retries); + metalink = _ostree_metalink_new (pull_data->fetcher, "summary", OSTREE_MAX_METADATA_SIZE, + metalink_uri, pull_data->n_network_retries); - if (! _ostree_metalink_request_sync (metalink, - &target_uri, - &summary_bytes, - cancellable, - error)) + if (!_ostree_metalink_request_sync (metalink, &target_uri, &summary_bytes, cancellable, + error)) goto out; /* XXX: would be interesting to implement metalink as another source of @@ -4089,14 +3836,15 @@ ostree_repo_pull_with_options (OstreeRepo *self, { g_autofree char *path = _ostree_fetcher_uri_get_path (target_uri); g_autofree char *basepath = g_path_get_dirname (path); - g_autoptr(OstreeFetcherURI) new_target_uri = _ostree_fetcher_uri_new_path (target_uri, basepath); - pull_data->meta_mirrorlist = - g_ptr_array_new_with_free_func ((GDestroyNotify) _ostree_fetcher_uri_free); + g_autoptr (OstreeFetcherURI) new_target_uri + = _ostree_fetcher_uri_new_path (target_uri, basepath); + pull_data->meta_mirrorlist + = g_ptr_array_new_with_free_func ((GDestroyNotify)_ostree_fetcher_uri_free); g_ptr_array_add (pull_data->meta_mirrorlist, g_steal_pointer (&new_target_uri)); } - pull_data->summary = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, - summary_bytes, FALSE); + pull_data->summary + = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, summary_bytes, FALSE); } { @@ -4104,31 +3852,25 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (metalink_url_str == NULL && url_override != NULL) contenturl = g_strdup (url_override); - else if (!ostree_repo_get_remote_option (self, remote_name_or_baseurl, - "contenturl", NULL, + else if (!ostree_repo_get_remote_option (self, remote_name_or_baseurl, "contenturl", NULL, &contenturl, error)) goto out; if (contenturl == NULL) { - pull_data->content_mirrorlist = - g_ptr_array_ref (pull_data->meta_mirrorlist); + pull_data->content_mirrorlist = g_ptr_array_ref (pull_data->meta_mirrorlist); } else { - if (!compute_effective_mirrorlist (self, remote_name_or_baseurl, - contenturl, - pull_data->fetcher, - pull_data->n_network_retries, - &pull_data->content_mirrorlist, - cancellable, error)) + if (!compute_effective_mirrorlist (self, remote_name_or_baseurl, contenturl, + pull_data->fetcher, pull_data->n_network_retries, + &pull_data->content_mirrorlist, cancellable, error)) goto out; } } /* FIXME: Do we want an analogue of this which supports collection IDs? */ - if (!ostree_repo_get_remote_list_option (self, - remote_name_or_baseurl, "branches", + if (!ostree_repo_get_remote_list_option (self, remote_name_or_baseurl, "branches", &configured_branches, error)) goto out; @@ -4146,7 +3888,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (g_str_equal (first_scheme, "file") && !pull_data->require_static_deltas) { g_autofree char *uri = _ostree_fetcher_uri_to_string (first_uri); - g_autoptr(GFile) remote_repo_path = g_file_new_for_uri (uri); + g_autoptr (GFile) remote_repo_path = g_file_new_for_uri (uri); pull_data->remote_repo_local = ostree_repo_new (remote_repo_path); if (!ostree_repo_open (pull_data->remote_repo_local, cancellable, error)) goto out; @@ -4185,16 +3927,17 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (flags & OSTREE_REPO_PULL_FLAGS_TRUSTED_HTTP) pull_data->importflags |= _OSTREE_REPO_IMPORT_FLAGS_TRUSTED; - const gboolean verifying_bareuseronly = - (pull_data->importflags & _OSTREE_REPO_IMPORT_FLAGS_VERIFY_BAREUSERONLY) > 0; + const gboolean verifying_bareuseronly + = (pull_data->importflags & _OSTREE_REPO_IMPORT_FLAGS_VERIFY_BAREUSERONLY) > 0; /* If we're mirroring and writing into an archive repo, and both checksum and * bareuseronly are turned off, we can directly copy the content rather than * paying the cost of exploding it, checksumming, and re-gzip. */ - const gboolean mirroring_into_archive = - pull_data->is_mirror && pull_data->repo->mode == OSTREE_REPO_MODE_ARCHIVE; - const gboolean import_trusted = !verifying_bareuseronly && - (pull_data->importflags & _OSTREE_REPO_IMPORT_FLAGS_TRUSTED) > 0; + const gboolean mirroring_into_archive + = pull_data->is_mirror && pull_data->repo->mode == OSTREE_REPO_MODE_ARCHIVE; + const gboolean import_trusted + = !verifying_bareuseronly + && (pull_data->importflags & _OSTREE_REPO_IMPORT_FLAGS_TRUSTED) > 0; pull_data->trusted_http_direct = mirroring_into_archive && import_trusted; } @@ -4225,7 +3968,8 @@ ostree_repo_pull_with_options (OstreeRepo *self, { const gchar *collection_id, *ref_name, *checksum; - while (g_variant_iter_loop (collection_refs_iter, "(&s&s&s)", &collection_id, &ref_name, &checksum)) + while (g_variant_iter_loop (collection_refs_iter, "(&s&s&s)", &collection_id, &ref_name, + &checksum)) { if (!ostree_validate_rev (ref_name, error)) goto out; @@ -4270,22 +4014,24 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (!(branches_iter && *branches_iter)) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "No configured branches for remote %s", remote_name_or_baseurl); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "No configured branches for remote %s", + remote_name_or_baseurl); goto out; } - for (;branches_iter && *branches_iter; branches_iter++) + for (; branches_iter && *branches_iter; branches_iter++) { const char *branch = *branches_iter; - g_hash_table_insert (requested_refs_to_fetch, - ostree_collection_ref_new (NULL, branch), NULL); + g_hash_table_insert (requested_refs_to_fetch, ostree_collection_ref_new (NULL, branch), + NULL); } } /* Deltas are necessary when mirroring or resolving a requested ref to a commit. * We try to avoid loading the potentially large summary if it is not needed. */ - need_summary = require_summary_for_mirror || !all_requested_refs_have_commit (requested_refs_to_fetch) || summary_sig_bytes_v != NULL; + need_summary = require_summary_for_mirror + || !all_requested_refs_have_commit (requested_refs_to_fetch) + || summary_sig_bytes_v != NULL; /* If we don't have indexed deltas, we need the summary for deltas, so check * the config file for support. @@ -4302,20 +4048,21 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (!pull_data->has_indexed_deltas) need_summary = TRUE; - } + } - pull_data->static_delta_superblocks = g_ptr_array_new_with_free_func ((GDestroyNotify)g_variant_unref); + pull_data->static_delta_superblocks + = g_ptr_array_new_with_free_func ((GDestroyNotify)g_variant_unref); if (need_summary) { - g_autoptr(GBytes) bytes_sig = NULL; + g_autoptr (GBytes) bytes_sig = NULL; gboolean summary_sig_not_modified = FALSE; g_autofree char *summary_sig_etag = NULL; guint64 summary_sig_last_modified = 0; gsize n; - g_autoptr(GVariant) refs = NULL; - g_autoptr(GVariant) deltas = NULL; - g_autoptr(GVariant) additional_metadata = NULL; + g_autoptr (GVariant) refs = NULL; + g_autoptr (GVariant) deltas = NULL; + g_autoptr (GVariant) additional_metadata = NULL; gboolean summary_from_cache = FALSE; gboolean tombstone_commits = FALSE; @@ -4346,19 +4093,17 @@ ostree_repo_pull_with_options (OstreeRepo *self, * Last-Modified from the on-disk cache (if it exists) to reduce the * download size if nothing’s changed. */ _ostree_repo_load_cache_summary_properties (self, remote_name_or_baseurl, ".sig", - &summary_sig_if_none_match, &summary_sig_if_modified_since); + &summary_sig_if_none_match, + &summary_sig_if_modified_since); g_clear_pointer (&summary_sig_etag, g_free); summary_sig_last_modified = 0; - if (!_ostree_fetcher_mirrored_request_to_membuf (pull_data->fetcher, - pull_data->meta_mirrorlist, - "summary.sig", OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, - summary_sig_if_none_match, summary_sig_if_modified_since, - pull_data->n_network_retries, - &bytes_sig, - &summary_sig_not_modified, &summary_sig_etag, &summary_sig_last_modified, - OSTREE_MAX_METADATA_SIZE, - cancellable, error)) + if (!_ostree_fetcher_mirrored_request_to_membuf ( + pull_data->fetcher, pull_data->meta_mirrorlist, "summary.sig", + OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, summary_sig_if_none_match, + summary_sig_if_modified_since, pull_data->n_network_retries, &bytes_sig, + &summary_sig_not_modified, &summary_sig_etag, &summary_sig_last_modified, + OSTREE_MAX_METADATA_SIZE, cancellable, error)) goto out; /* The server returned HTTP status 304 Not Modified, so we’re clear to @@ -4369,28 +4114,19 @@ ostree_repo_pull_with_options (OstreeRepo *self, g_clear_pointer (&bytes_sig, g_bytes_unref); g_clear_pointer (&bytes_summary, g_bytes_unref); if (!_ostree_repo_load_cache_summary_file (self, remote_name_or_baseurl, ".sig", - &bytes_sig, - cancellable, error)) + &bytes_sig, cancellable, error)) goto out; - if (!bytes_summary && - !pull_data->remote_repo_local && - !_ostree_repo_load_cache_summary_file (self, remote_name_or_baseurl, NULL, - &bytes_summary, - cancellable, error)) + if (!bytes_summary && !pull_data->remote_repo_local + && !_ostree_repo_load_cache_summary_file (self, remote_name_or_baseurl, NULL, + &bytes_summary, cancellable, error)) goto out; } } - if (bytes_sig && - !bytes_summary && - !pull_data->remote_repo_local && - !_ostree_repo_load_cache_summary_if_same_sig (self, - remote_name_or_baseurl, - bytes_sig, - &bytes_summary, - cancellable, - error)) + if (bytes_sig && !bytes_summary && !pull_data->remote_repo_local + && !_ostree_repo_load_cache_summary_if_same_sig (self, remote_name_or_baseurl, bytes_sig, + &bytes_summary, cancellable, error)) goto out; if (bytes_summary && !summary_bytes_v) @@ -4405,20 +4141,18 @@ ostree_repo_pull_with_options (OstreeRepo *self, guint64 summary_if_modified_since = 0; _ostree_repo_load_cache_summary_properties (self, remote_name_or_baseurl, NULL, - &summary_if_none_match, &summary_if_modified_since); + &summary_if_none_match, + &summary_if_modified_since); g_clear_pointer (&summary_etag, g_free); summary_last_modified = 0; - if (!_ostree_fetcher_mirrored_request_to_membuf (pull_data->fetcher, - pull_data->meta_mirrorlist, - "summary", OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, - summary_if_none_match, summary_if_modified_since, - pull_data->n_network_retries, - &bytes_summary, - &summary_not_modified, &summary_etag, &summary_last_modified, - OSTREE_MAX_METADATA_SIZE, - cancellable, error)) + if (!_ostree_fetcher_mirrored_request_to_membuf ( + pull_data->fetcher, pull_data->meta_mirrorlist, "summary", + OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, summary_if_none_match, + summary_if_modified_since, pull_data->n_network_retries, &bytes_summary, + &summary_not_modified, &summary_etag, &summary_last_modified, + OSTREE_MAX_METADATA_SIZE, cancellable, error)) goto out; /* The server returned HTTP status 304 Not Modified, so we’re clear to @@ -4427,8 +4161,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, { g_clear_pointer (&bytes_summary, g_bytes_unref); if (!_ostree_repo_load_cache_summary_file (self, remote_name_or_baseurl, NULL, - &bytes_summary, - cancellable, error)) + &bytes_summary, cancellable, error)) goto out; } } @@ -4437,7 +4170,8 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (!bytes_summary && pull_data->gpg_verify_summary) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "GPG verification enabled, but no summary found (use gpg-verify-summary=false in remote config to disable)"); + "GPG verification enabled, but no summary found (use " + "gpg-verify-summary=false in remote config to disable)"); goto out; } #endif /* OSTREE_DISABLE_GPGME */ @@ -4445,7 +4179,8 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (!bytes_summary && require_summary_for_mirror) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Fetching all refs was requested in mirror mode, but remote repository does not have a summary"); + "Fetching all refs was requested in mirror mode, but remote repository " + "does not have a summary"); goto out; } @@ -4453,18 +4188,18 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (!bytes_sig && pull_data->gpg_verify_summary) { g_set_error (error, OSTREE_GPG_ERROR, OSTREE_GPG_ERROR_NO_SIGNATURE, - "GPG verification enabled, but no summary.sig found (use gpg-verify-summary=false in remote config to disable)"); + "GPG verification enabled, but no summary.sig found (use " + "gpg-verify-summary=false in remote config to disable)"); goto out; } if (pull_data->gpg_verify_summary && bytes_summary && bytes_sig) { - g_autoptr(OstreeGpgVerifyResult) result = NULL; - g_autoptr(GError) temp_error = NULL; + g_autoptr (OstreeGpgVerifyResult) result = NULL; + g_autoptr (GError) temp_error = NULL; - result = ostree_repo_verify_summary (self, pull_data->remote_name, - bytes_summary, bytes_sig, - cancellable, &temp_error); + result = ostree_repo_verify_summary (self, pull_data->remote_name, bytes_summary, + bytes_sig, cancellable, &temp_error); if (!ostree_gpg_verify_result_require_valid_signature (result, &temp_error)) { if (summary_from_cache) @@ -4488,22 +4223,16 @@ ostree_repo_pull_with_options (OstreeRepo *self, g_clear_pointer (&bytes_summary, g_bytes_unref); g_clear_pointer (&summary_etag, g_free); summary_last_modified = 0; - if (!_ostree_fetcher_mirrored_request_to_membuf (pull_data->fetcher, - pull_data->meta_mirrorlist, - "summary", - OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, - NULL, 0, /* no cache headers */ - pull_data->n_network_retries, - &bytes_summary, - &summary_not_modified, &summary_etag, &summary_last_modified, - OSTREE_MAX_METADATA_SIZE, - cancellable, error)) + if (!_ostree_fetcher_mirrored_request_to_membuf ( + pull_data->fetcher, pull_data->meta_mirrorlist, "summary", + OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, NULL, 0, /* no cache headers */ + pull_data->n_network_retries, &bytes_summary, &summary_not_modified, + &summary_etag, &summary_last_modified, OSTREE_MAX_METADATA_SIZE, + cancellable, error)) goto out; - g_autoptr(OstreeGpgVerifyResult) retry = - ostree_repo_verify_summary (self, pull_data->remote_name, - bytes_summary, bytes_sig, - cancellable, error); + g_autoptr (OstreeGpgVerifyResult) retry = ostree_repo_verify_summary ( + self, pull_data->remote_name, bytes_summary, bytes_sig, cancellable, error); if (!ostree_gpg_verify_result_require_valid_signature (retry, error)) goto out; } @@ -4521,19 +4250,21 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (!bytes_sig && pull_data->signapi_summary_verifiers) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Signatures verification enabled, but no summary.sig found (use sign-verify-summary=false in remote config to disable)"); + "Signatures verification enabled, but no summary.sig found (use " + "sign-verify-summary=false in remote config to disable)"); goto out; } if (bytes_summary && bytes_sig) { - g_autoptr(GVariant) signatures = NULL; - g_autoptr(GError) temp_error = NULL; + g_autoptr (GVariant) signatures = NULL; + g_autoptr (GError) temp_error = NULL; - signatures = g_variant_new_from_bytes (OSTREE_SUMMARY_SIG_GVARIANT_FORMAT, - bytes_sig, FALSE); + signatures + = g_variant_new_from_bytes (OSTREE_SUMMARY_SIG_GVARIANT_FORMAT, bytes_sig, FALSE); g_assert (pull_data->signapi_summary_verifiers); - if (!_sign_verify_for_remote (pull_data->signapi_summary_verifiers, bytes_summary, signatures, NULL, &temp_error)) + if (!_sign_verify_for_remote (pull_data->signapi_summary_verifiers, bytes_summary, + signatures, NULL, &temp_error)) { if (summary_from_cache) { @@ -4556,19 +4287,17 @@ ostree_repo_pull_with_options (OstreeRepo *self, g_clear_pointer (&bytes_summary, g_bytes_unref); g_clear_pointer (&summary_etag, g_free); summary_last_modified = 0; - if (!_ostree_fetcher_mirrored_request_to_membuf (pull_data->fetcher, - pull_data->meta_mirrorlist, - "summary", - OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, - NULL, 0, /* no cache headers */ - pull_data->n_network_retries, - &bytes_summary, - &summary_not_modified, &summary_etag, &summary_last_modified, - OSTREE_MAX_METADATA_SIZE, - cancellable, error)) + if (!_ostree_fetcher_mirrored_request_to_membuf ( + pull_data->fetcher, pull_data->meta_mirrorlist, "summary", + OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, NULL, + 0, /* no cache headers */ + pull_data->n_network_retries, &bytes_summary, &summary_not_modified, + &summary_etag, &summary_last_modified, OSTREE_MAX_METADATA_SIZE, + cancellable, error)) goto out; - if (!_sign_verify_for_remote (pull_data->signapi_summary_verifiers, bytes_summary, signatures, NULL, error)) + if (!_sign_verify_for_remote (pull_data->signapi_summary_verifiers, + bytes_summary, signatures, NULL, error)) goto out; } else @@ -4585,18 +4314,17 @@ ostree_repo_pull_with_options (OstreeRepo *self, pull_data->summary_data = g_bytes_ref (bytes_summary); pull_data->summary_etag = g_strdup (summary_etag); pull_data->summary_last_modified = summary_last_modified; - pull_data->summary = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, bytes_summary, FALSE); + pull_data->summary + = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, bytes_summary, FALSE); if (!g_variant_is_normal_form (pull_data->summary)) { - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Not normal form"); + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Not normal form"); goto out; } if (!g_variant_is_of_type (pull_data->summary, OSTREE_SUMMARY_GVARIANT_FORMAT)) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Doesn't match variant type '%s'", + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Doesn't match variant type '%s'", (char *)OSTREE_SUMMARY_GVARIANT_FORMAT); goto out; } @@ -4611,15 +4339,10 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (!summary_from_cache && bytes_summary && bytes_sig && summary_sig_bytes_v == NULL) { - if (!pull_data->remote_repo_local && - !_ostree_repo_cache_summary (self, - remote_name_or_baseurl, - bytes_summary, - summary_etag, summary_last_modified, - bytes_sig, - summary_sig_etag, summary_sig_last_modified, - cancellable, - error)) + if (!pull_data->remote_repo_local + && !_ostree_repo_cache_summary ( + self, remote_name_or_baseurl, bytes_summary, summary_etag, summary_last_modified, + bytes_sig, summary_sig_etag, summary_sig_last_modified, cancellable, error)) goto out; } @@ -4627,7 +4350,8 @@ ostree_repo_pull_with_options (OstreeRepo *self, { additional_metadata = g_variant_get_child_value (pull_data->summary, 1); - if (!g_variant_lookup (additional_metadata, OSTREE_SUMMARY_COLLECTION_ID, "&s", &main_collection_id)) + if (!g_variant_lookup (additional_metadata, OSTREE_SUMMARY_COLLECTION_ID, "&s", + &main_collection_id)) main_collection_id = NULL; else if (!ostree_validate_collection_id (main_collection_id, error)) goto out; @@ -4636,7 +4360,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, for (i = 0, n = g_variant_n_children (refs); i < n; i++) { const char *refname; - g_autoptr(GVariant) ref = g_variant_get_child_value (refs, i); + g_autoptr (GVariant) ref = g_variant_get_child_value (refs, i); g_variant_get_child (ref, 0, "&s", &refname); @@ -4646,21 +4370,25 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (pull_data->is_mirror && !refs_to_fetch && !opt_collection_refs_set) { g_hash_table_insert (requested_refs_to_fetch, - ostree_collection_ref_new (main_collection_id, refname), NULL); + ostree_collection_ref_new (main_collection_id, refname), + NULL); } } - g_autoptr(GVariant) collection_map = NULL; - collection_map = g_variant_lookup_value (additional_metadata, OSTREE_SUMMARY_COLLECTION_MAP, G_VARIANT_TYPE ("a{sa(s(taya{sv}))}")); + g_autoptr (GVariant) collection_map = NULL; + collection_map + = g_variant_lookup_value (additional_metadata, OSTREE_SUMMARY_COLLECTION_MAP, + G_VARIANT_TYPE ("a{sa(s(taya{sv}))}")); if (collection_map != NULL) { GVariantIter collection_map_iter; const char *collection_id; - g_autoptr(GVariant) collection_refs = NULL; + g_autoptr (GVariant) collection_refs = NULL; g_variant_iter_init (&collection_map_iter, collection_map); - while (g_variant_iter_loop (&collection_map_iter, "{&s@a(s(taya{sv}))}", &collection_id, &collection_refs)) + while (g_variant_iter_loop (&collection_map_iter, "{&s@a(s(taya{sv}))}", + &collection_id, &collection_refs)) { if (!ostree_validate_collection_id (collection_id, error)) goto out; @@ -4668,7 +4396,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, for (i = 0, n = g_variant_n_children (collection_refs); i < n; i++) { const char *refname; - g_autoptr(GVariant) ref = g_variant_get_child_value (collection_refs, i); + g_autoptr (GVariant) ref = g_variant_get_child_value (collection_refs, i); g_variant_get_child (ref, 0, "&s", &refname); @@ -4678,23 +4406,27 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (pull_data->is_mirror && !refs_to_fetch && !opt_collection_refs_set) { g_hash_table_insert (requested_refs_to_fetch, - ostree_collection_ref_new (collection_id, refname), NULL); + ostree_collection_ref_new (collection_id, refname), + NULL); } } } } - deltas = g_variant_lookup_value (additional_metadata, OSTREE_SUMMARY_STATIC_DELTAS, G_VARIANT_TYPE ("a{sv}")); + deltas = g_variant_lookup_value (additional_metadata, OSTREE_SUMMARY_STATIC_DELTAS, + G_VARIANT_TYPE ("a{sv}")); pull_data->summary_has_deltas = deltas != NULL && g_variant_n_children (deltas) > 0; if (!collect_available_deltas_for_pull (pull_data, deltas, error)) goto out; - g_variant_lookup (additional_metadata, OSTREE_SUMMARY_INDEXED_DELTAS, "b", &pull_data->has_indexed_deltas); + g_variant_lookup (additional_metadata, OSTREE_SUMMARY_INDEXED_DELTAS, "b", + &pull_data->has_indexed_deltas); } - if (pull_data->summary && - g_variant_lookup (additional_metadata, OSTREE_SUMMARY_MODE, "s", &remote_mode_str) && - g_variant_lookup (additional_metadata, OSTREE_SUMMARY_TOMBSTONE_COMMITS, "b", &tombstone_commits)) + if (pull_data->summary + && g_variant_lookup (additional_metadata, OSTREE_SUMMARY_MODE, "s", &remote_mode_str) + && g_variant_lookup (additional_metadata, OSTREE_SUMMARY_TOMBSTONE_COMMITS, "b", + &tombstone_commits)) { if (!ostree_repo_mode_from_string (remote_mode_str, &pull_data->remote_mode, error)) goto out; @@ -4703,58 +4435,59 @@ ostree_repo_pull_with_options (OstreeRepo *self, } } - if (pull_data->require_static_deltas && !pull_data->has_indexed_deltas && !pull_data->summary_has_deltas) + if (pull_data->require_static_deltas && !pull_data->has_indexed_deltas + && !pull_data->summary_has_deltas) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "Fetch configured to require static deltas, but no summary deltas or delta index found"); + g_set_error ( + error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, + "Fetch configured to require static deltas, but no summary deltas or delta index found"); goto out; } if (remote_mode_loaded && pull_data->remote_repo_local == NULL) - { - /* Fall-back path which loads the necessary config from the remote’s - * `config` file (unless we already read it above). Doing so is deprecated since it means an - * additional round trip to the remote for each pull. No need to do - * it for local pulls. */ - if (remote_config == NULL && - !load_remote_repo_config (pull_data, &remote_config, cancellable, error)) - goto out; + { + /* Fall-back path which loads the necessary config from the remote’s + * `config` file (unless we already read it above). Doing so is deprecated since it means an + * additional round trip to the remote for each pull. No need to do + * it for local pulls. */ + if (remote_config == NULL + && !load_remote_repo_config (pull_data, &remote_config, cancellable, error)) + goto out; - g_clear_pointer (&remote_mode_str, g_free); - if (!ot_keyfile_get_value_with_default (remote_config, "core", "mode", "bare", - &remote_mode_str, error)) - goto out; + g_clear_pointer (&remote_mode_str, g_free); + if (!ot_keyfile_get_value_with_default (remote_config, "core", "mode", "bare", + &remote_mode_str, error)) + goto out; - if (!ostree_repo_mode_from_string (remote_mode_str, &pull_data->remote_mode, error)) - goto out; + if (!ostree_repo_mode_from_string (remote_mode_str, &pull_data->remote_mode, error)) + goto out; - if (!ot_keyfile_get_boolean_with_default (remote_config, "core", "tombstone-commits", FALSE, - &pull_data->has_tombstone_commits, error)) - goto out; + if (!ot_keyfile_get_boolean_with_default (remote_config, "core", "tombstone-commits", FALSE, + &pull_data->has_tombstone_commits, error)) + goto out; - remote_mode_loaded = TRUE; - } + remote_mode_loaded = TRUE; + } - if (remote_mode_loaded && pull_data->remote_repo_local == NULL && pull_data->remote_mode != OSTREE_REPO_MODE_ARCHIVE) + if (remote_mode_loaded && pull_data->remote_repo_local == NULL + && pull_data->remote_mode != OSTREE_REPO_MODE_ARCHIVE) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Can't pull from archives with mode \"%s\"", - remote_mode_str); + "Can't pull from archives with mode \"%s\"", remote_mode_str); goto out; } /* Resolve the checksum for each ref. This has to be done into a new hash table, * since we can’t modify the keys of @requested_refs_to_fetch while iterating * over it, and we need to ensure the collection IDs are resolved too. */ - updated_requested_refs_to_fetch = g_hash_table_new_full (ostree_collection_ref_hash, - ostree_collection_ref_equal, - (GDestroyNotify) ostree_collection_ref_free, - g_free); - GLNX_HASH_TABLE_FOREACH_KV (requested_refs_to_fetch, const OstreeCollectionRef*, ref, - const char*, override_commitid) + updated_requested_refs_to_fetch + = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, + (GDestroyNotify)ostree_collection_ref_free, g_free); + GLNX_HASH_TABLE_FOREACH_KV (requested_refs_to_fetch, const OstreeCollectionRef *, ref, + const char *, override_commitid) { g_autofree char *checksum = NULL; - g_autoptr(OstreeCollectionRef) ref_with_collection = NULL; + g_autoptr (OstreeCollectionRef) ref_with_collection = NULL; /* Support specifying "" for an override commitid */ if (override_commitid && *override_commitid) @@ -4770,18 +4503,21 @@ ostree_repo_pull_with_options (OstreeRepo *self, guint64 *malloced_size; g_autofree gchar *collection_id = NULL; - if (!lookup_commit_checksum_and_collection_from_summary (pull_data, ref, &checksum, &commit_size, &collection_id, error)) + if (!lookup_commit_checksum_and_collection_from_summary ( + pull_data, ref, &checksum, &commit_size, &collection_id, error)) goto out; ref_with_collection = ostree_collection_ref_new (collection_id, ref->ref_name); malloced_size = g_new0 (guint64, 1); *malloced_size = commit_size; - g_hash_table_insert (pull_data->expected_commit_sizes, g_strdup (checksum), malloced_size); + g_hash_table_insert (pull_data->expected_commit_sizes, g_strdup (checksum), + malloced_size); } else { - if (!fetch_ref_contents (pull_data, main_collection_id, ref, &checksum, cancellable, error)) + if (!fetch_ref_contents (pull_data, main_collection_id, ref, &checksum, cancellable, + error)) goto out; ref_with_collection = ostree_collection_ref_dup (ref); @@ -4806,14 +4542,13 @@ ostree_repo_pull_with_options (OstreeRepo *self, g_steal_pointer (&from_rev)); } - g_hash_table_replace (updated_requested_refs_to_fetch, - g_steal_pointer (&ref_with_collection), + g_hash_table_replace (updated_requested_refs_to_fetch, g_steal_pointer (&ref_with_collection), g_steal_pointer (&checksum)); } /* Resolve refs to a checksum if necessary */ - if (pull_data->timestamp_check_from_rev && - !ostree_validate_checksum_string (pull_data->timestamp_check_from_rev, NULL)) + if (pull_data->timestamp_check_from_rev + && !ostree_validate_checksum_string (pull_data->timestamp_check_from_rev, NULL)) { g_autofree char *from_rev = NULL; if (!ostree_repo_resolve_rev (pull_data->repo, pull_data->timestamp_check_from_rev, FALSE, @@ -4827,8 +4562,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, requested_refs_to_fetch = g_steal_pointer (&updated_requested_refs_to_fetch); if (g_hash_table_size (requested_refs_to_fetch) == 1) { - GLNX_HASH_TABLE_FOREACH (requested_refs_to_fetch, - const OstreeCollectionRef *, ref) + GLNX_HASH_TABLE_FOREACH (requested_refs_to_fetch, const OstreeCollectionRef *, ref) { the_ref_to_fetch = ref->ref_name; break; @@ -4839,9 +4573,10 @@ ostree_repo_pull_with_options (OstreeRepo *self, { const gchar *collection_id, *ref_name, *keyring_remote_name; - while (g_variant_iter_loop (ref_keyring_map_iter, "(&s&s&s)", &collection_id, &ref_name, &keyring_remote_name)) + while (g_variant_iter_loop (ref_keyring_map_iter, "(&s&s&s)", &collection_id, &ref_name, + &keyring_remote_name)) { - g_autoptr(OstreeCollectionRef) c_r = NULL; + g_autoptr (OstreeCollectionRef) c_r = NULL; if (!ostree_validate_collection_id (collection_id, error)) goto out; @@ -4853,8 +4588,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, c_r = ostree_collection_ref_new (collection_id, ref_name); if (!g_hash_table_contains (requested_refs_to_fetch, c_r)) continue; - g_hash_table_insert (pull_data->ref_keyring_map, - g_steal_pointer (&c_r), + g_hash_table_insert (pull_data->ref_keyring_map, g_steal_pointer (&c_r), g_strdup (keyring_remote_name)); } } @@ -4880,24 +4614,24 @@ ostree_repo_pull_with_options (OstreeRepo *self, goto out; pull_data->legacy_transaction_resuming = FALSE; - if (!inherit_transaction && - !ostree_repo_prepare_transaction (pull_data->repo, &pull_data->legacy_transaction_resuming, - cancellable, error)) + if (!inherit_transaction + && !ostree_repo_prepare_transaction (pull_data->repo, &pull_data->legacy_transaction_resuming, + cancellable, error)) goto out; if (pull_data->legacy_transaction_resuming) g_debug ("resuming legacy transaction"); /* Initiate requests for explicit commit revisions */ - GLNX_HASH_TABLE_FOREACH_V (commits_to_fetch, const char*, commit) + GLNX_HASH_TABLE_FOREACH_V (commits_to_fetch, const char *, commit) { if (!initiate_request (pull_data, NULL, commit, error)) goto out; } /* Initiate requests for refs */ - GLNX_HASH_TABLE_FOREACH_KV (requested_refs_to_fetch, const OstreeCollectionRef*, ref, - const char*, to_revision) + GLNX_HASH_TABLE_FOREACH_KV (requested_refs_to_fetch, const OstreeCollectionRef *, ref, + const char *, to_revision) { if (!initiate_request (pull_data, ref, to_revision, error)) goto out; @@ -4934,8 +4668,8 @@ ostree_repo_pull_with_options (OstreeRepo *self, g_assert_cmpint (pull_data->n_outstanding_content_fetches, ==, 0); g_assert_cmpint (pull_data->n_outstanding_content_write_requests, ==, 0); - GLNX_HASH_TABLE_FOREACH_KV (requested_refs_to_fetch, const OstreeCollectionRef*, ref, - const char*, checksum) + GLNX_HASH_TABLE_FOREACH_KV (requested_refs_to_fetch, const OstreeCollectionRef *, ref, + const char *, checksum) { g_autofree char *remote_ref = NULL; g_autofree char *original_rev = NULL; @@ -4954,46 +4688,44 @@ ostree_repo_pull_with_options (OstreeRepo *self, else { if (pull_data->is_mirror) - ostree_repo_transaction_set_collection_ref (pull_data->repo, - ref, checksum); + ostree_repo_transaction_set_collection_ref (pull_data->repo, ref, checksum); else - ostree_repo_transaction_set_ref (pull_data->repo, - pull_data->remote_refspec_name ?: pull_data->remote_name, - ref->ref_name, checksum); + ostree_repo_transaction_set_ref ( + pull_data->repo, pull_data->remote_refspec_name ?: pull_data->remote_name, + ref->ref_name, checksum); } } - if (pull_data->is_mirror && pull_data->summary_data && - !refs_to_fetch && !opt_collection_refs_set && !configured_branches) + if (pull_data->is_mirror && pull_data->summary_data && !refs_to_fetch && !opt_collection_refs_set + && !configured_branches) { - GLnxFileReplaceFlags replaceflag = - pull_data->repo->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : 0; + GLnxFileReplaceFlags replaceflag + = pull_data->repo->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : 0; gsize len; const guint8 *buf = g_bytes_get_data (pull_data->summary_data, &len); - if (!glnx_file_replace_contents_at (pull_data->repo->repo_dir_fd, "summary", - buf, len, replaceflag, - cancellable, error)) + if (!glnx_file_replace_contents_at (pull_data->repo->repo_dir_fd, "summary", buf, len, + replaceflag, cancellable, error)) goto out; - store_file_cache_properties (pull_data->repo->repo_dir_fd, "summary", - pull_data->summary_etag, pull_data->summary_last_modified); + store_file_cache_properties (pull_data->repo->repo_dir_fd, "summary", pull_data->summary_etag, + pull_data->summary_last_modified); if (pull_data->summary_data_sig) { buf = g_bytes_get_data (pull_data->summary_data_sig, &len); - if (!glnx_file_replace_contents_at (pull_data->repo->repo_dir_fd, "summary.sig", - buf, len, replaceflag, - cancellable, error)) + if (!glnx_file_replace_contents_at (pull_data->repo->repo_dir_fd, "summary.sig", buf, len, + replaceflag, cancellable, error)) goto out; store_file_cache_properties (pull_data->repo->repo_dir_fd, "summary.sig", - pull_data->summary_sig_etag, pull_data->summary_sig_last_modified); + pull_data->summary_sig_etag, + pull_data->summary_sig_last_modified); } } - if (!inherit_transaction && - !ostree_repo_commit_transaction (pull_data->repo, &tstats, cancellable, error)) + if (!inherit_transaction + && !ostree_repo_commit_transaction (pull_data->repo, &tstats, cancellable, error)) goto out; end_time = g_get_monotonic_time (); @@ -5001,7 +4733,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, bytes_transferred = _ostree_fetcher_bytes_transferred (pull_data->fetcher); if (pull_data->progress) { - g_autoptr(GString) buf = g_string_new (""); + g_autoptr (GString) buf = g_string_new (""); /* Ensure the rest of the progress keys are set appropriately. */ update_progress (pull_data); @@ -5017,10 +4749,9 @@ ostree_repo_pull_with_options (OstreeRepo *self, else g_string_append_printf (buf, "%u metadata, %u content objects fetched", pull_data->n_fetched_metadata, pull_data->n_fetched_content); - if (!pull_data->remote_repo_local && - (pull_data->n_imported_metadata || pull_data->n_imported_content)) - g_string_append_printf (buf, " (%u meta, %u content local)", - pull_data->n_imported_metadata, + if (!pull_data->remote_repo_local + && (pull_data->n_imported_metadata || pull_data->n_imported_content)) + g_string_append_printf (buf, " (%u meta, %u content local)", pull_data->n_imported_metadata, pull_data->n_imported_content); if (bytes_transferred > 0) @@ -5031,9 +4762,8 @@ ostree_repo_pull_with_options (OstreeRepo *self, else shift = 1024; g_string_append_printf (buf, "; %" G_GUINT64_FORMAT " %s transferred in %u seconds", - (guint64)(bytes_transferred / shift), - shift == 1 ? "B" : "KiB", - (guint) ((end_time - pull_data->start_time) / G_USEC_PER_SEC)); + (guint64)(bytes_transferred / shift), shift == 1 ? "B" : "KiB", + (guint)((end_time - pull_data->start_time) / G_USEC_PER_SEC)); } if (!inherit_transaction) { @@ -5047,13 +4777,14 @@ ostree_repo_pull_with_options (OstreeRepo *self, #ifdef HAVE_LIBSYSTEMD if (bytes_transferred > 0 && pull_data->remote_name) { - g_autoptr(GString) msg = g_string_new (""); + g_autoptr (GString) msg = g_string_new (""); if (the_ref_to_fetch) g_string_append_printf (msg, "libostree pull from '%s' for %s complete", pull_data->remote_name, the_ref_to_fetch); else g_string_append_printf (msg, "libostree pull from '%s' for %u refs complete", - pull_data->remote_name, g_hash_table_size (requested_refs_to_fetch)); + pull_data->remote_name, + g_hash_table_size (requested_refs_to_fetch)); const char *gpg_verify_state; #ifndef OSTREE_DISABLE_GPGME @@ -5097,13 +4828,12 @@ ostree_repo_pull_with_options (OstreeRepo *self, g_string_append (msg, "\n"); if (pull_data->n_fetched_deltaparts > 0) - g_string_append_printf (msg, "delta: parts: %u loose: %u", - pull_data->n_fetched_deltaparts, + g_string_append_printf (msg, "delta: parts: %u loose: %u", pull_data->n_fetched_deltaparts, pull_data->n_fetched_metadata + pull_data->n_fetched_content); else g_string_append_printf (msg, "non-delta: meta: %u content: %u", pull_data->n_fetched_metadata, pull_data->n_fetched_content); - const guint n_seconds = (guint) ((end_time - pull_data->start_time) / G_USEC_PER_SEC); + const guint n_seconds = (guint)((end_time - pull_data->start_time) / G_USEC_PER_SEC); g_autofree char *formatted_xferred = g_format_size (bytes_transferred); g_string_append_printf (msg, "\ntransfer: secs: %u size: %s", n_seconds, formatted_xferred); if (pull_data->signapi_commit_verifiers) @@ -5111,34 +4841,31 @@ ostree_repo_pull_with_options (OstreeRepo *self, g_assert_cmpuint (g_hash_table_size (pull_data->signapi_verified_commits), >, 0); } - ot_journal_send ("MESSAGE=%s", msg->str, - "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(OSTREE_MESSAGE_FETCH_COMPLETE_ID), - "OSTREE_REMOTE=%s", pull_data->remote_name, - "OSTREE_SIGN=%s", sign_verify_state, - "OSTREE_GPG=%s", gpg_verify_state, - "OSTREE_SECONDS=%u", n_seconds, - "OSTREE_XFER_SIZE=%s", formatted_xferred, - NULL); + ot_journal_send ("MESSAGE=%s", msg->str, "MESSAGE_ID=" SD_ID128_FORMAT_STR, + SD_ID128_FORMAT_VAL (OSTREE_MESSAGE_FETCH_COMPLETE_ID), "OSTREE_REMOTE=%s", + pull_data->remote_name, "OSTREE_SIGN=%s", sign_verify_state, "OSTREE_GPG=%s", + gpg_verify_state, "OSTREE_SECONDS=%u", n_seconds, "OSTREE_XFER_SIZE=%s", + formatted_xferred, NULL); } #endif /* iterate over commits fetched and delete any commitpartial files */ if (pull_data->dirs == NULL && !pull_data->is_commit_only) { - GLNX_HASH_TABLE_FOREACH_V (requested_refs_to_fetch, const char*, checksum) + GLNX_HASH_TABLE_FOREACH_V (requested_refs_to_fetch, const char *, checksum) { if (!ostree_repo_mark_commit_partial (pull_data->repo, checksum, FALSE, error)) goto out; } - GLNX_HASH_TABLE_FOREACH_V (commits_to_fetch, const char*, commit) + GLNX_HASH_TABLE_FOREACH_V (commits_to_fetch, const char *, commit) { if (!ostree_repo_mark_commit_partial (pull_data->repo, commit, FALSE, error)) goto out; } /* and finally any parent commits we might also have pulled because of depth>0 */ - GLNX_HASH_TABLE_FOREACH (pull_data->commit_to_depth, const char*, commit) + GLNX_HASH_TABLE_FOREACH (pull_data->commit_to_depth, const char *, commit) { if (!ostree_repo_mark_commit_partial (pull_data->repo, commit, FALSE, error)) goto out; @@ -5146,7 +4873,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, } ret = TRUE; - out: +out: /* This is pretty ugly - we have two error locations, because we * have a mix of synchronous and async code. Mixing them gets messy * as we need to avoid overwriting errors. @@ -5198,7 +4925,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, g_clear_pointer (&pull_data->pending_fetch_delta_indexes, g_hash_table_unref); g_clear_pointer (&pull_data->pending_fetch_delta_superblocks, g_hash_table_unref); g_clear_pointer (&pull_data->pending_fetch_deltaparts, g_hash_table_unref); - g_queue_foreach (&pull_data->scan_object_queue, (GFunc) scan_object_queue_data_free, NULL); + g_queue_foreach (&pull_data->scan_object_queue, (GFunc)scan_object_queue_data_free, NULL); g_queue_clear (&pull_data->scan_object_queue); g_clear_pointer (&pull_data->idle_src, g_source_destroy); g_clear_pointer (&pull_data->dirs, g_ptr_array_unref); @@ -5212,11 +4939,12 @@ ostree_repo_pull_with_options (OstreeRepo *self, * have refs pointing to this commit. */ typedef struct { - gchar *checksum; /* always set */ - guint64 commit_size; /* always set */ - guint64 timestamp; /* 0 for unknown */ + gchar *checksum; /* always set */ + guint64 commit_size; /* always set */ + guint64 timestamp; /* 0 for unknown */ GVariant *additional_metadata; - GArray *refs; /* (element-type gsize), indexes to refs which point to this commit on at least one remote */ + GArray *refs; /* (element-type gsize), indexes to refs which point to this commit on at least one + remote */ } CommitMetadata; static void @@ -5231,18 +4959,17 @@ commit_metadata_free (CommitMetadata *info) G_DEFINE_AUTOPTR_CLEANUP_FUNC (CommitMetadata, commit_metadata_free) static CommitMetadata * -commit_metadata_new (const gchar *checksum, - guint64 commit_size, - guint64 timestamp, - GVariant *additional_metadata) +commit_metadata_new (const gchar *checksum, guint64 commit_size, guint64 timestamp, + GVariant *additional_metadata) { - g_autoptr(CommitMetadata) info = NULL; + g_autoptr (CommitMetadata) info = NULL; info = g_new0 (CommitMetadata, 1); info->checksum = g_strdup (checksum); info->commit_size = commit_size; info->timestamp = timestamp; - info->additional_metadata = (additional_metadata != NULL) ? g_variant_ref (additional_metadata) : NULL; + info->additional_metadata + = (additional_metadata != NULL) ? g_variant_ref (additional_metadata) : NULL; info->refs = g_array_new (FALSE, FALSE, sizeof (gsize)); return g_steal_pointer (&info); @@ -5254,9 +4981,9 @@ commit_metadata_new (const gchar *checksum, * there. */ typedef struct { - gsize width; /* pointers */ - gsize height; /* pointers */ - gconstpointer pointers[]; /* n_pointers = width * height */ + gsize width; /* pointers */ + gsize height; /* pointers */ + gconstpointer pointers[]; /* n_pointers = width * height */ } PointerTable; static void @@ -5269,14 +4996,14 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (PointerTable, pointer_table_free) /* Both dimensions are in numbers of pointers. */ static PointerTable * -pointer_table_new (gsize width, - gsize height) +pointer_table_new (gsize width, gsize height) { - g_autoptr(PointerTable) table = NULL; + g_autoptr (PointerTable) table = NULL; g_return_val_if_fail (width > 0, NULL); g_return_val_if_fail (height > 0, NULL); - g_return_val_if_fail (width <= (G_MAXSIZE - sizeof (PointerTable)) / sizeof (gconstpointer) / height, NULL); + g_return_val_if_fail ( + width <= (G_MAXSIZE - sizeof (PointerTable)) / sizeof (gconstpointer) / height, NULL); table = g_malloc0 (sizeof (PointerTable) + sizeof (gconstpointer) * width * height); table->width = width; @@ -5286,9 +5013,7 @@ pointer_table_new (gsize width, } static gconstpointer -pointer_table_get (const PointerTable *table, - gsize x, - gsize y) +pointer_table_get (const PointerTable *table, gsize x, gsize y) { g_return_val_if_fail (table != NULL, FALSE); g_return_val_if_fail (x < table->width, FALSE); @@ -5298,10 +5023,7 @@ pointer_table_get (const PointerTable *table, } static void -pointer_table_set (PointerTable *table, - gsize x, - gsize y, - gconstpointer value) +pointer_table_set (PointerTable *table, gsize x, gsize y, gconstpointer value) { g_return_if_fail (table != NULL); g_return_if_fail (x < table->width); @@ -5314,15 +5036,14 @@ pointer_table_set (PointerTable *table, 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; @@ -5382,19 +5103,18 @@ find_remotes_data_free (FindRemotesData *data) G_DEFINE_AUTOPTR_CLEANUP_FUNC (FindRemotesData, find_remotes_data_free) static FindRemotesData * -find_remotes_data_new (const OstreeCollectionRef * const *refs, - GVariant *options, - OstreeAsyncProgress *progress, - OstreeRepoFinder *default_finder_avahi, - guint n_network_retries) +find_remotes_data_new (const OstreeCollectionRef *const *refs, GVariant *options, + OstreeAsyncProgress *progress, OstreeRepoFinder *default_finder_avahi, + guint n_network_retries) { - g_autoptr(FindRemotesData) data = NULL; + g_autoptr (FindRemotesData) data = NULL; data = g_new0 (FindRemotesData, 1); data->refs = ostree_collection_ref_dupv (refs); data->options = (options != NULL) ? g_variant_ref (options) : NULL; data->progress = (progress != NULL) ? g_object_ref (progress) : NULL; - data->default_finder_avahi = (default_finder_avahi != NULL) ? g_object_ref (default_finder_avahi) : NULL; + data->default_finder_avahi + = (default_finder_avahi != NULL) ? g_object_ref (default_finder_avahi) : NULL; data->n_network_retries = n_network_retries; return g_steal_pointer (&data); @@ -5403,7 +5123,7 @@ find_remotes_data_new (const OstreeCollectionRef * const *refs, static gchar * uint64_secs_to_iso8601 (guint64 secs) { - g_autoptr(GDateTime) dt = g_date_time_new_from_unix_utc (secs); + g_autoptr (GDateTime) dt = g_date_time_new_from_unix_utc (secs); if (dt != NULL) return g_date_time_format (dt, "%FT%TZ"); @@ -5412,11 +5132,10 @@ uint64_secs_to_iso8601 (guint64 secs) } 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); } @@ -5430,9 +5149,7 @@ repo_finder_result_free0 (OstreeRepoFinderResult *result) ostree_repo_finder_result_free (result); } -static void find_remotes_cb (GObject *obj, - GAsyncResult *result, - gpointer user_data); +static void find_remotes_cb (GObject *obj, GAsyncResult *result, gpointer user_data); /** * ostree_repo_find_remotes_async: @@ -5491,38 +5208,36 @@ static void find_remotes_cb (GObject *obj, * Since: 2018.6 */ void -ostree_repo_find_remotes_async (OstreeRepo *self, - const OstreeCollectionRef * const *refs, - GVariant *options, - OstreeRepoFinder **finders, - OstreeAsyncProgress *progress, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +ostree_repo_find_remotes_async (OstreeRepo *self, const OstreeCollectionRef *const *refs, + GVariant *options, OstreeRepoFinder **finders, + OstreeAsyncProgress *progress, GCancellable *cancellable, + GAsyncReadyCallback callback, gpointer user_data) { - g_autoptr(GTask) task = NULL; - g_autoptr(FindRemotesData) data = NULL; - OstreeRepoFinder *default_finders[4] = { NULL, }; - g_autoptr(OstreeRepoFinder) finder_config = NULL; - g_autoptr(OstreeRepoFinder) finder_mount = NULL; - g_autoptr(OstreeRepoFinder) finder_avahi = NULL; + g_autoptr (GTask) task = NULL; + g_autoptr (FindRemotesData) data = NULL; + OstreeRepoFinder *default_finders[4] = { + NULL, + }; + g_autoptr (OstreeRepoFinder) finder_config = NULL; + g_autoptr (OstreeRepoFinder) finder_mount = NULL; + g_autoptr (OstreeRepoFinder) finder_avahi = NULL; g_autofree char **override_commit_ids = NULL; guint n_network_retries = DEFAULT_N_NETWORK_RETRIES; g_return_if_fail (OSTREE_IS_REPO (self)); g_return_if_fail (is_valid_collection_ref_array (refs)); - g_return_if_fail (options == NULL || - g_variant_is_of_type (options, G_VARIANT_TYPE_VARDICT)); + g_return_if_fail (options == NULL || g_variant_is_of_type (options, G_VARIANT_TYPE_VARDICT)); g_return_if_fail (finders == NULL || is_valid_finder_array (finders)); g_return_if_fail (progress == NULL || OSTREE_IS_ASYNC_PROGRESS (progress)); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); if (options) { - (void) g_variant_lookup (options, "override-commit-ids", "^a&s", &override_commit_ids); - g_return_if_fail (override_commit_ids == NULL || g_strv_length ((gchar **) refs) == g_strv_length (override_commit_ids)); + (void)g_variant_lookup (options, "override-commit-ids", "^a&s", &override_commit_ids); + g_return_if_fail (override_commit_ids == NULL + || g_strv_length ((gchar **)refs) == g_strv_length (override_commit_ids)); - (void) g_variant_lookup (options, "n-network-retries", "u", &n_network_retries); + (void)g_variant_lookup (options, "n-network-retries", "u", &n_network_retries); } /* Set up a task for the whole operation. */ @@ -5536,22 +5251,25 @@ ostree_repo_find_remotes_async (OstreeRepo *self, #ifdef HAVE_AVAHI guint avahi_index; GMainContext *context = g_main_context_get_thread_default (); - g_autoptr(GError) local_error = NULL; -#endif /* HAVE_AVAHI */ + g_autoptr (GError) local_error = NULL; +#endif /* HAVE_AVAHI */ - if (g_strv_contains ((const char * const *)self->repo_finders, "config")) - default_finders[finder_index++] = finder_config = OSTREE_REPO_FINDER (ostree_repo_finder_config_new ()); + if (g_strv_contains ((const char *const *)self->repo_finders, "config")) + default_finders[finder_index++] = finder_config + = OSTREE_REPO_FINDER (ostree_repo_finder_config_new ()); - if (g_strv_contains ((const char * const *)self->repo_finders, "mount")) - default_finders[finder_index++] = finder_mount = OSTREE_REPO_FINDER (ostree_repo_finder_mount_new (NULL)); + if (g_strv_contains ((const char *const *)self->repo_finders, "mount")) + default_finders[finder_index++] = finder_mount + = OSTREE_REPO_FINDER (ostree_repo_finder_mount_new (NULL)); #ifdef HAVE_AVAHI - if (g_strv_contains ((const char * const *)self->repo_finders, "lan")) + if (g_strv_contains ((const char *const *)self->repo_finders, "lan")) { avahi_index = finder_index; - default_finders[finder_index++] = finder_avahi = OSTREE_REPO_FINDER (ostree_repo_finder_avahi_new (context)); + default_finders[finder_index++] = finder_avahi + = OSTREE_REPO_FINDER (ostree_repo_finder_avahi_new (context)); } -#endif /* HAVE_AVAHI */ +#endif /* HAVE_AVAHI */ /* self->repo_finders is guaranteed to be non-empty */ g_assert (default_finders != NULL); @@ -5560,8 +5278,7 @@ ostree_repo_find_remotes_async (OstreeRepo *self, #ifdef HAVE_AVAHI if (finder_avahi != NULL) { - ostree_repo_finder_avahi_start (OSTREE_REPO_FINDER_AVAHI (finder_avahi), - &local_error); + ostree_repo_finder_avahi_start (OSTREE_REPO_FINDER_AVAHI (finder_avahi), &local_error); if (local_error != NULL) { @@ -5575,7 +5292,8 @@ ostree_repo_find_remotes_async (OstreeRepo *self, * would cause client code to abort if a warning were emitted. */ if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) - g_debug ("Avahi finder failed under normal operation; removing it: %s", local_error->message); + g_debug ("Avahi finder failed under normal operation; removing it: %s", + local_error->message); else g_warning ("Avahi finder failed abnormally; removing it: %s", local_error->message); @@ -5583,34 +5301,32 @@ ostree_repo_find_remotes_async (OstreeRepo *self, g_clear_object (&finder_avahi); } } -#endif /* HAVE_AVAHI */ +#endif /* HAVE_AVAHI */ } /* We need to keep a pointer to the default Avahi finder so we can stop it * again after the operation, which happens implicitly by dropping the final * ref. */ data = find_remotes_data_new (refs, options, progress, finder_avahi, n_network_retries); - g_task_set_task_data (task, g_steal_pointer (&data), (GDestroyNotify) find_remotes_data_free); + g_task_set_task_data (task, g_steal_pointer (&data), (GDestroyNotify)find_remotes_data_free); /* Asynchronously resolve all possible remotes for the given refs. */ - ostree_repo_finder_resolve_all_async (finders, refs, self, cancellable, - find_remotes_cb, g_steal_pointer (&task)); + ostree_repo_finder_resolve_all_async (finders, refs, self, cancellable, find_remotes_cb, + g_steal_pointer (&task)); } /* Find the first instance of (@collection_id, @ref_name) in @refs and return * its index; or return %FALSE if nothing’s found. */ static gboolean -collection_refv_contains (const OstreeCollectionRef * const *refs, - const gchar *collection_id, - const gchar *ref_name, - gsize *out_index) +collection_refv_contains (const OstreeCollectionRef *const *refs, const gchar *collection_id, + const gchar *ref_name, gsize *out_index) { gsize i; for (i = 0; refs[i] != NULL; i++) { - if (g_str_equal (refs[i]->collection_id, collection_id) && - g_str_equal (refs[i]->ref_name, ref_name)) + if (g_str_equal (refs[i]->collection_id, collection_id) + && g_str_equal (refs[i]->ref_name, ref_name)) { *out_index = i; return TRUE; @@ -5625,26 +5341,23 @@ collection_refv_contains (const OstreeCollectionRef * const *refs, * points to into @refs_and_remotes_table at (@ref_index, @result_index). * @ref_index is the ref’s index in @refs. */ static gboolean -find_remotes_process_refs (OstreeRepo *self, - const OstreeCollectionRef * const *refs, - OstreeRepoFinderResult *result, - gsize result_index, - const gchar *summary_collection_id, - GVariant *summary_refs, - GHashTable *commit_metadatas, - PointerTable *refs_and_remotes_table) +find_remotes_process_refs (OstreeRepo *self, const OstreeCollectionRef *const *refs, + OstreeRepoFinderResult *result, gsize result_index, + const gchar *summary_collection_id, GVariant *summary_refs, + GHashTable *commit_metadatas, PointerTable *refs_and_remotes_table) { gsize j, n; for (j = 0, n = g_variant_n_children (summary_refs); j < n; j++) { const guchar *csum_bytes; - g_autoptr(GVariant) ref_v = NULL, csum_v = NULL, commit_metadata_v = NULL, stored_commit_v = NULL; + g_autoptr (GVariant) ref_v = NULL, csum_v = NULL, commit_metadata_v = NULL, + stored_commit_v = NULL; guint64 commit_size, commit_timestamp; gchar tmp_checksum[OSTREE_SHA256_STRING_LEN + 1]; gsize ref_index; - g_autoptr(GDateTime) dt = NULL; - g_autoptr(GError) error = NULL; + g_autoptr (GDateTime) dt = NULL; + g_autoptr (GError) error = NULL; const gchar *ref_name; CommitMetadata *commit_metadata; @@ -5654,8 +5367,8 @@ find_remotes_process_refs (OstreeRepo *self, if (!ostree_validate_rev (ref_name, &error)) { - g_debug ("%s: Summary for result ‘%s’ contained invalid ref name ‘%s’: %s", - G_STRFUNC, result->remote->name, ref_name, error->message); + g_debug ("%s: Summary for result ‘%s’ contained invalid ref name ‘%s’: %s", G_STRFUNC, + result->remote->name, ref_name, error->message); return FALSE; } @@ -5665,8 +5378,8 @@ find_remotes_process_refs (OstreeRepo *self, csum_bytes = ostree_checksum_bytes_peek_validate (csum_v, &error); if (csum_bytes == NULL) { - g_debug ("%s: Summary for result ‘%s’ contained invalid ref checksum: %s", - G_STRFUNC, result->remote->name, error->message); + g_debug ("%s: Summary for result ‘%s’ contained invalid ref checksum: %s", G_STRFUNC, + result->remote->name, error->message); return FALSE; } @@ -5682,7 +5395,7 @@ find_remotes_process_refs (OstreeRepo *self, /* Check the additional metadata. */ if (!g_variant_lookup (commit_metadata_v, OSTREE_COMMIT_TIMESTAMP, "t", &commit_timestamp)) - commit_timestamp = 0; /* unknown */ + commit_timestamp = 0; /* unknown */ else commit_timestamp = GUINT64_FROM_BE (commit_timestamp); @@ -5690,7 +5403,8 @@ find_remotes_process_refs (OstreeRepo *self, if (dt == NULL) { - g_debug ("%s: Summary for result ‘%s’ contained commit timestamp %" G_GUINT64_FORMAT " which is too far in the future. Resetting to 0.", + g_debug ("%s: Summary for result ‘%s’ contained commit timestamp %" G_GUINT64_FORMAT + " which is too far in the future. Resetting to 0.", G_STRFUNC, result->remote->name, commit_timestamp); commit_timestamp = 0; } @@ -5700,11 +5414,11 @@ find_remotes_process_refs (OstreeRepo *self, if (commit_metadata == NULL) { - commit_metadata = commit_metadata_new (tmp_checksum, commit_size, - (stored_commit_v != NULL) ? ostree_commit_get_timestamp (stored_commit_v) : 0, - NULL); + commit_metadata = commit_metadata_new ( + tmp_checksum, commit_size, + (stored_commit_v != NULL) ? ostree_commit_get_timestamp (stored_commit_v) : 0, NULL); g_hash_table_insert (commit_metadatas, commit_metadata->checksum, - commit_metadata /* transfer */); + commit_metadata /* transfer */); } /* Update the metadata if possible. */ @@ -5714,59 +5428,63 @@ find_remotes_process_refs (OstreeRepo *self, } else if (commit_timestamp != 0 && commit_metadata->timestamp != commit_timestamp) { - g_debug ("%s: Summary for result ‘%s’ contained commit timestamp %" G_GUINT64_FORMAT " which did not match existing timestamp %" G_GUINT64_FORMAT ". Ignoring.", + g_debug ("%s: Summary for result ‘%s’ contained commit timestamp %" G_GUINT64_FORMAT + " which did not match existing timestamp %" G_GUINT64_FORMAT ". Ignoring.", G_STRFUNC, result->remote->name, commit_timestamp, commit_metadata->timestamp); return FALSE; } if (commit_size != commit_metadata->commit_size) { - g_debug ("%s: Summary for result ‘%s’ contained commit size %" G_GUINT64_FORMAT "B which did not match existing size %" G_GUINT64_FORMAT "B. Ignoring.", + g_debug ("%s: Summary for result ‘%s’ contained commit size %" G_GUINT64_FORMAT + "B which did not match existing size %" G_GUINT64_FORMAT "B. Ignoring.", G_STRFUNC, result->remote->name, commit_size, commit_metadata->commit_size); return FALSE; } - pointer_table_set (refs_and_remotes_table, ref_index, result_index, commit_metadata->checksum); + pointer_table_set (refs_and_remotes_table, ref_index, result_index, + commit_metadata->checksum); g_array_append_val (commit_metadata->refs, ref_index); - g_debug ("%s: Remote ‘%s’ lists ref ‘%s’ mapping to commit ‘%s’.", - G_STRFUNC, result->remote->name, ref_name, commit_metadata->checksum); + g_debug ("%s: Remote ‘%s’ lists ref ‘%s’ mapping to commit ‘%s’.", G_STRFUNC, + result->remote->name, ref_name, commit_metadata->checksum); } return TRUE; } static void -find_remotes_cb (GObject *obj, - GAsyncResult *async_result, - gpointer user_data) +find_remotes_cb (GObject *obj, GAsyncResult *async_result, gpointer user_data) { OstreeRepo *self; - g_autoptr(GTask) task = NULL; + g_autoptr (GTask) task = NULL; GCancellable *cancellable; const FindRemotesData *data; - const OstreeCollectionRef * const *refs; + const OstreeCollectionRef *const *refs; /* FIXME: We currently do nothing with @progress. Comment out to assuage -Wunused-variable */ /* OstreeAsyncProgress *progress; */ - g_autoptr(GError) error = NULL; - g_autoptr(GPtrArray) results = NULL; /* (element-type OstreeRepoFinderResult) */ + g_autoptr (GError) error = NULL; + g_autoptr (GPtrArray) results = NULL; /* (element-type OstreeRepoFinderResult) */ gsize i; - g_autoptr(PointerTable) refs_and_remotes_table = NULL; /* (element-type commit-checksum) */ - g_autoptr(GHashTable) commit_metadatas = NULL; /* (element-type commit-checksum CommitMetadata) */ - g_autoptr(OstreeFetcher) fetcher = NULL; - g_autofree const gchar **ref_to_latest_commit = NULL; /* indexed as @refs; (element-type commit-checksum) */ - g_autofree guint64 *ref_to_latest_timestamp = NULL; /* indexed as @refs; (element-type commit-timestamp) */ + g_autoptr (PointerTable) refs_and_remotes_table = NULL; /* (element-type commit-checksum) */ + g_autoptr (GHashTable) commit_metadatas + = NULL; /* (element-type commit-checksum CommitMetadata) */ + g_autoptr (OstreeFetcher) fetcher = NULL; + g_autofree const gchar **ref_to_latest_commit + = NULL; /* indexed as @refs; (element-type commit-checksum) */ + g_autofree guint64 *ref_to_latest_timestamp + = NULL; /* indexed as @refs; (element-type commit-timestamp) */ gsize n_refs; g_autofree char **override_commit_ids = NULL; - g_autoptr(GPtrArray) remotes_to_remove = NULL; /* (element-type OstreeRemote) */ - g_autoptr(GPtrArray) final_results = NULL; /* (element-type OstreeRepoFinderResult) */ + g_autoptr (GPtrArray) remotes_to_remove = NULL; /* (element-type OstreeRemote) */ + g_autoptr (GPtrArray) final_results = NULL; /* (element-type OstreeRepoFinderResult) */ task = G_TASK (user_data); self = OSTREE_REPO (g_task_get_source_object (task)); cancellable = g_task_get_cancellable (task); data = g_task_get_task_data (task); - refs = (const OstreeCollectionRef * const *) data->refs; + refs = (const OstreeCollectionRef *const *)data->refs; /* progress = data->progress; */ /* Finish finding the remotes. */ @@ -5780,7 +5498,7 @@ find_remotes_cb (GObject *obj, if (results->len == 0) { - 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); return; } @@ -5788,11 +5506,11 @@ find_remotes_cb (GObject *obj, * clearing them to %NULL. We cannot remove them from the array, as that messes * up iteration and stored array indices. Accordingly, we need the free function * to be %NULL-safe. */ - g_ptr_array_set_free_func (results, (GDestroyNotify) repo_finder_result_free0); + g_ptr_array_set_free_func (results, (GDestroyNotify)repo_finder_result_free0); if (data->options) { - (void) g_variant_lookup (data->options, "override-commit-ids", "^a&s", &override_commit_ids); + (void)g_variant_lookup (data->options, "override-commit-ids", "^a&s", &override_commit_ids); } /* FIXME: In future, we also want to pull static delta superblocks in this @@ -5801,14 +5519,15 @@ find_remotes_cb (GObject *obj, * disable-static-deltas option first. */ /* Each key must be a pointer to the #CommitMetadata.checksum field of its value. */ - commit_metadatas = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) commit_metadata_free); + commit_metadatas + = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify)commit_metadata_free); /* X dimension is an index into @refs. Y dimension is an index into @results. * Each cell stores the commit checksum which that ref resolves to on that * remote, or %NULL if the remote doesn’t have that ref. */ - n_refs = g_strv_length ((gchar **) refs); /* it’s not a GStrv, but this works */ + n_refs = g_strv_length ((gchar **)refs); /* it’s not a GStrv, but this works */ refs_and_remotes_table = pointer_table_new (n_refs, results->len); - remotes_to_remove = g_ptr_array_new_with_free_func ((GDestroyNotify) ostree_remote_unref); + remotes_to_remove = g_ptr_array_new_with_free_func ((GDestroyNotify)ostree_remote_unref); /* Fetch and validate the summary file for each result. */ /* FIXME: All these downloads could be parallelised; that requires the @@ -5816,13 +5535,13 @@ find_remotes_cb (GObject *obj, for (i = 0; i < results->len; i++) { OstreeRepoFinderResult *result = g_ptr_array_index (results, i); - g_autoptr(GBytes) summary_bytes = NULL; - g_autoptr(GVariant) summary_v = NULL; + g_autoptr (GBytes) summary_bytes = NULL; + g_autoptr (GVariant) summary_v = NULL; guint64 summary_last_modified; - g_autoptr(GVariant) summary_refs = NULL; - g_autoptr(GVariant) additional_metadata_v = NULL; + g_autoptr (GVariant) summary_refs = NULL; + g_autoptr (GVariant) additional_metadata_v = NULL; g_autofree gchar *summary_collection_id = NULL; - g_autoptr(GVariantIter) summary_collection_map = NULL; + g_autoptr (GVariantIter) summary_collection_map = NULL; gboolean invalid_result = FALSE; /* Add the remote to our internal list of remotes, so other libostree @@ -5830,41 +5549,36 @@ find_remotes_cb (GObject *obj, if (!_ostree_repo_add_remote (self, result->remote)) g_ptr_array_add (remotes_to_remove, ostree_remote_ref (result->remote)); - g_debug ("%s: Fetching summary for remote ‘%s’ with keyring ‘%s’.", - G_STRFUNC, result->remote->name, result->remote->keyring); + g_debug ("%s: Fetching summary for remote ‘%s’ with keyring ‘%s’.", G_STRFUNC, + result->remote->name, result->remote->keyring); /* Download the summary. This will load from the cache if possible. */ - ostree_repo_remote_fetch_summary_with_options (self, - result->remote->name, - NULL, /* no options */ - &summary_bytes, - NULL, - cancellable, - &error); + ostree_repo_remote_fetch_summary_with_options (self, result->remote->name, + NULL, /* no options */ + &summary_bytes, NULL, cancellable, &error); if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) goto error; else if (error != NULL) { - g_debug ("%s: Failed to download summary for result ‘%s’. Ignoring. %s", - G_STRFUNC, result->remote->name, error->message); + g_debug ("%s: Failed to download summary for result ‘%s’. Ignoring. %s", G_STRFUNC, + result->remote->name, error->message); g_clear_pointer (&g_ptr_array_index (results, i), ostree_repo_finder_result_free); g_clear_error (&error); continue; } else if (summary_bytes == NULL) { - g_debug ("%s: Failed to download summary for result ‘%s’. Ignoring. %s", - G_STRFUNC, result->remote->name, - "No summary file exists on server"); + g_debug ("%s: Failed to download summary for result ‘%s’. Ignoring. %s", G_STRFUNC, + result->remote->name, "No summary file exists on server"); g_clear_pointer (&g_ptr_array_index (results, i), ostree_repo_finder_result_free); continue; } /* Check the metadata in the summary file, especially whether it contains * all the @refs we are interested in. */ - summary_v = g_variant_ref_sink (g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, - summary_bytes, FALSE)); + summary_v = g_variant_ref_sink ( + g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, summary_bytes, FALSE)); /* Check the summary’s additional metadata and set up @commit_metadata * and @refs_and_remotes_table with the refs listed in the summary file, @@ -5872,33 +5586,37 @@ find_remotes_cb (GObject *obj, * intersection with @refs. */ additional_metadata_v = g_variant_get_child_value (summary_v, 1); - if (g_variant_lookup (additional_metadata_v, OSTREE_SUMMARY_COLLECTION_ID, "s", &summary_collection_id)) + if (g_variant_lookup (additional_metadata_v, OSTREE_SUMMARY_COLLECTION_ID, "s", + &summary_collection_id)) { summary_refs = g_variant_get_child_value (summary_v, 0); - if (!find_remotes_process_refs (self, refs, result, i, summary_collection_id, summary_refs, - commit_metadatas, refs_and_remotes_table)) + if (!find_remotes_process_refs (self, refs, result, i, summary_collection_id, + summary_refs, commit_metadatas, refs_and_remotes_table)) { g_clear_pointer (&g_ptr_array_index (results, i), ostree_repo_finder_result_free); continue; } } - if (!g_variant_lookup (additional_metadata_v, OSTREE_SUMMARY_COLLECTION_MAP, "a{sa(s(taya{sv}))}", &summary_collection_map)) + if (!g_variant_lookup (additional_metadata_v, OSTREE_SUMMARY_COLLECTION_MAP, + "a{sa(s(taya{sv}))}", &summary_collection_map)) summary_collection_map = NULL; - while (summary_collection_map != NULL && - g_variant_iter_loop (summary_collection_map, "{s@a(s(taya{sv}))}", &summary_collection_id, &summary_refs)) + while (summary_collection_map != NULL + && g_variant_iter_loop (summary_collection_map, "{s@a(s(taya{sv}))}", + &summary_collection_id, &summary_refs)) { /* Exclude refs that don't use the associated keyring if this is a * dynamic remote, by comparing against the collection ID of the * remote this one inherits from */ - if (result->remote->refspec_name != NULL && - !check_remote_matches_collection_id (self, result->remote->refspec_name, summary_collection_id)) + if (result->remote->refspec_name != NULL + && !check_remote_matches_collection_id (self, result->remote->refspec_name, + summary_collection_id)) continue; - if (!find_remotes_process_refs (self, refs, result, i, summary_collection_id, summary_refs, - commit_metadatas, refs_and_remotes_table)) + if (!find_remotes_process_refs (self, refs, result, i, summary_collection_id, + summary_refs, commit_metadatas, refs_and_remotes_table)) { g_clear_pointer (&g_ptr_array_index (results, i), ostree_repo_finder_result_free); invalid_result = TRUE; @@ -5910,7 +5628,8 @@ find_remotes_cb (GObject *obj, continue; /* Check the summary timestamp. */ - if (!g_variant_lookup (additional_metadata_v, OSTREE_SUMMARY_LAST_MODIFIED, "t", &summary_last_modified)) + if (!g_variant_lookup (additional_metadata_v, OSTREE_SUMMARY_LAST_MODIFIED, "t", + &summary_last_modified)) summary_last_modified = 0; else summary_last_modified = GUINT64_FROM_BE (summary_last_modified); @@ -5927,21 +5646,22 @@ find_remotes_cb (GObject *obj, * the commit metadata from the remotes. The ‘most recent commits’ are the * set of head commits pointed to by the refs we just resolved from the * summary files. */ - GLNX_HASH_TABLE_FOREACH_V (commit_metadatas, CommitMetadata*, commit_metadata) + GLNX_HASH_TABLE_FOREACH_V (commit_metadatas, CommitMetadata *, commit_metadata) { char buf[_OSTREE_LOOSE_PATH_MAX]; g_autofree gchar *commit_filename = NULL; - g_autoptr(GPtrArray) mirrorlist = NULL; /* (element-type OstreeFetcherURI) */ - g_autoptr(GBytes) commit_bytes = NULL; - g_autoptr(GVariant) commit_v = NULL; + g_autoptr (GPtrArray) mirrorlist = NULL; /* (element-type OstreeFetcherURI) */ + g_autoptr (GBytes) commit_bytes = NULL; + g_autoptr (GVariant) commit_v = NULL; guint64 commit_timestamp; - g_autoptr(GDateTime) dt = NULL; + g_autoptr (GDateTime) dt = NULL; /* Already complete? */ if (commit_metadata->timestamp != 0) continue; - _ostree_loose_path (buf, commit_metadata->checksum, OSTREE_OBJECT_TYPE_COMMIT, OSTREE_REPO_MODE_ARCHIVE); + _ostree_loose_path (buf, commit_metadata->checksum, OSTREE_OBJECT_TYPE_COMMIT, + OSTREE_REPO_MODE_ARCHIVE); commit_filename = g_build_filename ("objects", buf, NULL); /* For each of the remotes whose summary files contain this ref, try @@ -5960,52 +5680,44 @@ find_remotes_cb (GObject *obj, if (result == NULL) continue; - if (pointer_table_get (refs_and_remotes_table, ref_index, j) != commit_metadata->checksum) + if (pointer_table_get (refs_and_remotes_table, ref_index, j) + != commit_metadata->checksum) continue; g_autofree gchar *uri = NULL; - g_autoptr(OstreeFetcherURI) fetcher_uri = NULL; + g_autoptr (OstreeFetcherURI) fetcher_uri = NULL; - if (!ostree_repo_remote_get_url (self, result->remote->name, - &uri, &error)) + if (!ostree_repo_remote_get_url (self, result->remote->name, &uri, &error)) goto error; fetcher_uri = _ostree_fetcher_uri_parse (uri, &error); if (fetcher_uri == NULL) goto error; - fetcher = _ostree_repo_remote_new_fetcher (self, result->remote->name, - TRUE, NULL, NULL, NULL, &error); + fetcher = _ostree_repo_remote_new_fetcher (self, result->remote->name, TRUE, NULL, + NULL, NULL, &error); if (fetcher == NULL) goto error; - g_debug ("%s: Fetching metadata for commit ‘%s’ from remote ‘%s’.", - G_STRFUNC, commit_metadata->checksum, result->remote->name); + g_debug ("%s: Fetching metadata for commit ‘%s’ from remote ‘%s’.", G_STRFUNC, + commit_metadata->checksum, result->remote->name); /* FIXME: Support remotes which have contenturl, mirrorlist, etc. */ - mirrorlist = g_ptr_array_new_with_free_func ((GDestroyNotify) _ostree_fetcher_uri_free); + mirrorlist + = g_ptr_array_new_with_free_func ((GDestroyNotify)_ostree_fetcher_uri_free); g_ptr_array_add (mirrorlist, g_steal_pointer (&fetcher_uri)); - if (!_ostree_fetcher_mirrored_request_to_membuf (fetcher, - mirrorlist, - commit_filename, - OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, - NULL, 0, - data->n_network_retries, - &commit_bytes, - NULL, NULL, NULL, - 0, /* no maximum size */ - cancellable, - &error)) + if (!_ostree_fetcher_mirrored_request_to_membuf ( + fetcher, mirrorlist, commit_filename, OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, + NULL, 0, data->n_network_retries, &commit_bytes, NULL, NULL, NULL, + 0, /* no maximum size */ + cancellable, &error)) goto error; - g_autoptr(OstreeGpgVerifyResult) verify_result = NULL; + g_autoptr (OstreeGpgVerifyResult) verify_result = NULL; - verify_result = ostree_repo_verify_commit_for_remote (self, - commit_metadata->checksum, - result->remote->name, - cancellable, - &error); + verify_result = ostree_repo_verify_commit_for_remote ( + self, commit_metadata->checksum, result->remote->name, cancellable, &error); if (verify_result == NULL) { g_prefix_error (&error, "Commit %s: ", commit_metadata->checksum); @@ -6028,21 +5740,21 @@ find_remotes_cb (GObject *obj, if (commit_bytes == NULL) { - g_set_error (&error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Metadata not found for commit ‘%s’", commit_metadata->checksum); + g_set_error (&error, G_IO_ERROR, G_IO_ERROR_FAILED, "Metadata not found for commit ‘%s’", + commit_metadata->checksum); goto error; } /* Parse the commit metadata. */ - commit_v = g_variant_new_from_bytes (OSTREE_COMMIT_GVARIANT_FORMAT, - commit_bytes, FALSE); + commit_v = g_variant_new_from_bytes (OSTREE_COMMIT_GVARIANT_FORMAT, commit_bytes, FALSE); g_variant_get_child (commit_v, 5, "t", &commit_timestamp); commit_timestamp = GUINT64_FROM_BE (commit_timestamp); dt = g_date_time_new_from_unix_utc (commit_timestamp); if (dt == NULL) { - g_debug ("%s: Commit ‘%s’ metadata contained timestamp %" G_GUINT64_FORMAT " which is too far in the future. Resetting to 0.", + g_debug ("%s: Commit ‘%s’ metadata contained timestamp %" G_GUINT64_FORMAT + " which is too far in the future. Resetting to 0.", G_STRFUNC, commit_metadata->checksum, commit_timestamp); commit_timestamp = 0; } @@ -6075,8 +5787,8 @@ find_remotes_cb (GObject *obj, if (override_commit_ids) { - g_debug ("%s: Using specified commit ‘%s’ for ref (%s, %s).", - G_STRFUNC, override_commit_ids[i], refs[i]->collection_id, refs[i]->ref_name); + g_debug ("%s: Using specified commit ‘%s’ for ref (%s, %s).", G_STRFUNC, + override_commit_ids[i], refs[i]->collection_id, refs[i]->ref_name); continue; } @@ -6093,8 +5805,8 @@ find_remotes_cb (GObject *obj, candidate_commit_metadata = g_hash_table_lookup (commit_metadatas, candidate_checksum); g_assert (candidate_commit_metadata != NULL); - if (latest_commit_metadata == NULL || - candidate_commit_metadata->timestamp > latest_commit_metadata->timestamp) + if (latest_commit_metadata == NULL + || candidate_commit_metadata->timestamp > latest_commit_metadata->timestamp) { latest_checksum = candidate_checksum; latest_commit_metadata = candidate_commit_metadata; @@ -6113,27 +5825,31 @@ find_remotes_cb (GObject *obj, if (latest_commit_metadata != NULL) { latest_commit_timestamp_str = uint64_secs_to_iso8601 (latest_commit_metadata->timestamp); - g_debug ("%s: Latest commit for ref (%s, %s) across all remotes is ‘%s’ with timestamp %s.", - G_STRFUNC, refs[i]->collection_id, refs[i]->ref_name, - latest_checksum, latest_commit_timestamp_str); + g_debug ( + "%s: Latest commit for ref (%s, %s) across all remotes is ‘%s’ with timestamp %s.", + G_STRFUNC, refs[i]->collection_id, refs[i]->ref_name, latest_checksum, + latest_commit_timestamp_str); } else { - g_debug ("%s: Latest commit for ref (%s, %s) is unknown due to failure to download metadata.", - G_STRFUNC, refs[i]->collection_id, refs[i]->ref_name); + g_debug ( + "%s: Latest commit for ref (%s, %s) is unknown due to failure to download metadata.", + G_STRFUNC, refs[i]->collection_id, refs[i]->ref_name); } } /* Recombine @commit_metadatas and @results so that each * #OstreeRepoFinderResult.refs lists the refs for which that remote has the * latest commits (i.e. it’s not out of date compared to some other remote). */ - final_results = g_ptr_array_new_with_free_func ((GDestroyNotify) ostree_repo_finder_result_free); + final_results = g_ptr_array_new_with_free_func ((GDestroyNotify)ostree_repo_finder_result_free); for (i = 0; i < results->len; i++) { OstreeRepoFinderResult *result = g_ptr_array_index (results, i); - g_autoptr(GHashTable) validated_ref_to_checksum = NULL; /* (element-type OstreeCollectionRef utf8) */ - g_autoptr(GHashTable) validated_ref_to_timestamp = NULL; /* (element-type OstreeCollectionRef guint64) */ + g_autoptr (GHashTable) validated_ref_to_checksum + = NULL; /* (element-type OstreeCollectionRef utf8) */ + g_autoptr (GHashTable) validated_ref_to_timestamp + = NULL; /* (element-type OstreeCollectionRef guint64) */ gsize j, n_latest_refs; /* Previous error processing this result? */ @@ -6142,15 +5858,13 @@ find_remotes_cb (GObject *obj, /* Map of refs to checksums provided by this result. The checksums should * be %NULL for each ref unless this result provides the latest checksum. */ - validated_ref_to_checksum = g_hash_table_new_full (ostree_collection_ref_hash, - ostree_collection_ref_equal, - (GDestroyNotify) ostree_collection_ref_free, - g_free); - - validated_ref_to_timestamp = g_hash_table_new_full (ostree_collection_ref_hash, - ostree_collection_ref_equal, - (GDestroyNotify) ostree_collection_ref_free, - g_free); + validated_ref_to_checksum + = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, + (GDestroyNotify)ostree_collection_ref_free, g_free); + + validated_ref_to_timestamp + = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, + (GDestroyNotify)ostree_collection_ref_free, g_free); if (override_commit_ids) { for (j = 0; refs[j] != NULL; j++) @@ -6218,7 +5932,7 @@ find_remotes_cb (GObject *obj, _ostree_repo_remove_remote (self, remote); } - g_task_return_pointer (task, g_steal_pointer (&final_results), (GDestroyNotify) g_ptr_array_unref); + g_task_return_pointer (task, g_steal_pointer (&final_results), (GDestroyNotify)g_ptr_array_unref); return; @@ -6248,11 +5962,9 @@ error: * Since: 2018.6 */ OstreeRepoFinderResult ** -ostree_repo_find_remotes_finish (OstreeRepo *self, - GAsyncResult *result, - GError **error) +ostree_repo_find_remotes_finish (OstreeRepo *self, GAsyncResult *result, GError **error) { - g_autoptr(GPtrArray) results = NULL; + g_autoptr (GPtrArray) results = NULL; g_return_val_if_fail (OSTREE_IS_REPO (self), NULL); g_return_val_if_fail (g_task_is_valid (result, self), NULL); @@ -6263,20 +5975,18 @@ ostree_repo_find_remotes_finish (OstreeRepo *self, if (results != NULL) { - g_ptr_array_add (results, NULL); /* NULL terminator */ - return (OstreeRepoFinderResult **) g_ptr_array_free (g_steal_pointer (&results), FALSE); + g_ptr_array_add (results, NULL); /* NULL terminator */ + return (OstreeRepoFinderResult **)g_ptr_array_free (g_steal_pointer (&results), FALSE); } else return NULL; } static void -copy_option (GVariantDict *master_options, - GVariantDict *slave_options, - const gchar *key, +copy_option (GVariantDict *master_options, GVariantDict *slave_options, const gchar *key, const GVariantType *expected_type) { - g_autoptr(GVariant) option_v = g_variant_dict_lookup_value (master_options, key, expected_type); + g_autoptr (GVariant) option_v = g_variant_dict_lookup_value (master_options, key, expected_type); if (option_v != NULL) g_variant_dict_insert_value (slave_options, key, option_v); } @@ -6339,13 +6049,10 @@ copy_option (GVariantDict *master_options, * Since: 2018.6 */ void -ostree_repo_pull_from_remotes_async (OstreeRepo *self, - const OstreeRepoFinderResult * const *results, - GVariant *options, - OstreeAsyncProgress *progress, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +ostree_repo_pull_from_remotes_async (OstreeRepo *self, const OstreeRepoFinderResult *const *results, + GVariant *options, OstreeAsyncProgress *progress, + GCancellable *cancellable, GAsyncReadyCallback callback, + gpointer user_data) { g_return_if_fail (OSTREE_IS_REPO (self)); g_return_if_fail (results != NULL && results[0] != NULL); @@ -6353,12 +6060,12 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, g_return_if_fail (progress == NULL || OSTREE_IS_ASYNC_PROGRESS (progress)); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); - g_autoptr(GTask) task = NULL; - g_autoptr(GHashTable) refs_pulled = NULL; /* (element-type OstreeCollectionRef gboolean) */ + g_autoptr (GTask) task = NULL; + g_autoptr (GHashTable) refs_pulled = NULL; /* (element-type OstreeCollectionRef gboolean) */ gsize i, j; - g_autoptr(GString) refs_unpulled_string = NULL; - g_autoptr(GError) local_error = NULL; - g_auto(GVariantDict) options_dict = OT_VARIANT_BUILDER_INITIALIZER; + g_autoptr (GString) refs_unpulled_string = NULL; + g_autoptr (GError) local_error = NULL; + g_auto (GVariantDict) options_dict = OT_VARIANT_BUILDER_INITIALIZER; OstreeRepoPullFlags flags; gboolean inherit_transaction; @@ -6368,8 +6075,8 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, /* Keep track of the set of refs we’ve pulled already. Value is %TRUE if the * ref has been pulled; %FALSE if it has not. */ - refs_pulled = g_hash_table_new_full (ostree_collection_ref_hash, - ostree_collection_ref_equal, NULL, NULL); + refs_pulled + = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, NULL, NULL); g_variant_dict_init (&options_dict, options); @@ -6379,8 +6086,8 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, inherit_transaction = FALSE; /* Run all the local pull operations in a single overall transaction. */ - if (!inherit_transaction && - !ostree_repo_prepare_transaction (self, NULL, cancellable, &local_error)) + if (!inherit_transaction + && !ostree_repo_prepare_transaction (self, NULL, cancellable, &local_error)) { g_task_return_error (task, g_steal_pointer (&local_error)); return; @@ -6396,31 +6103,30 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, { const OstreeRepoFinderResult *result = results[i]; - g_autoptr(GString) refs_to_pull_str = NULL; - g_autoptr(GPtrArray) refs_to_pull = NULL; /* (element-type OstreeCollectionRef) */ - g_auto(GVariantBuilder) refs_to_pull_builder = OT_VARIANT_BUILDER_INITIALIZER; - g_auto(GVariantDict) local_options_dict = OT_VARIANT_BUILDER_INITIALIZER; - g_autoptr(GVariant) local_options = NULL; + g_autoptr (GString) refs_to_pull_str = NULL; + g_autoptr (GPtrArray) refs_to_pull = NULL; /* (element-type OstreeCollectionRef) */ + g_auto (GVariantBuilder) refs_to_pull_builder = OT_VARIANT_BUILDER_INITIALIZER; + g_auto (GVariantDict) local_options_dict = OT_VARIANT_BUILDER_INITIALIZER; + g_autoptr (GVariant) local_options = NULL; gboolean remove_remote; refs_to_pull = g_ptr_array_new_with_free_func (NULL); refs_to_pull_str = g_string_new (""); g_variant_builder_init (&refs_to_pull_builder, G_VARIANT_TYPE ("a(sss)")); - GLNX_HASH_TABLE_FOREACH_KV (result->ref_to_checksum, const OstreeCollectionRef*, ref, - const char*, checksum) + GLNX_HASH_TABLE_FOREACH_KV (result->ref_to_checksum, const OstreeCollectionRef *, ref, + const char *, checksum) { - if (checksum != NULL && - !GPOINTER_TO_INT (g_hash_table_lookup (refs_pulled, ref))) + if (checksum != NULL && !GPOINTER_TO_INT (g_hash_table_lookup (refs_pulled, ref))) { - g_ptr_array_add (refs_to_pull, (gpointer) ref); - g_variant_builder_add (&refs_to_pull_builder, "(sss)", - ref->collection_id, ref->ref_name, checksum); + g_ptr_array_add (refs_to_pull, (gpointer)ref); + g_variant_builder_add (&refs_to_pull_builder, "(sss)", ref->collection_id, + ref->ref_name, checksum); if (refs_to_pull_str->len > 0) g_string_append (refs_to_pull_str, ", "); - g_string_append_printf (refs_to_pull_str, "(%s, %s)", - ref->collection_id, ref->ref_name); + g_string_append_printf (refs_to_pull_str, "(%s, %s)", ref->collection_id, + ref->ref_name); } } @@ -6435,14 +6141,15 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, /* NULL terminators. */ g_ptr_array_add (refs_to_pull, NULL); - g_debug ("Pulling from remote ‘%s’: %s", - result->remote->name, refs_to_pull_str->str); + g_debug ("Pulling from remote ‘%s’: %s", result->remote->name, refs_to_pull_str->str); /* Set up the pull options. */ g_variant_dict_init (&local_options_dict, NULL); - g_variant_dict_insert (&local_options_dict, "flags", "i", OSTREE_REPO_PULL_FLAGS_UNTRUSTED | flags); - g_variant_dict_insert_value (&local_options_dict, "collection-refs", g_variant_builder_end (&refs_to_pull_builder)); + g_variant_dict_insert (&local_options_dict, "flags", "i", + OSTREE_REPO_PULL_FLAGS_UNTRUSTED | flags); + g_variant_dict_insert_value (&local_options_dict, "collection-refs", + g_variant_builder_end (&refs_to_pull_builder)); #ifndef OSTREE_DISABLE_GPGME g_variant_dict_insert (&local_options_dict, "gpg-verify", "b", TRUE); #else @@ -6453,22 +6160,25 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, g_variant_dict_insert (&local_options_dict, "sign-verify-summary", "b", FALSE); g_variant_dict_insert (&local_options_dict, "inherit-transaction", "b", TRUE); if (result->remote->refspec_name != NULL) - g_variant_dict_insert (&local_options_dict, "override-remote-name", "s", result->remote->refspec_name); + g_variant_dict_insert (&local_options_dict, "override-remote-name", "s", + result->remote->refspec_name); copy_option (&options_dict, &local_options_dict, "depth", G_VARIANT_TYPE ("i")); - copy_option (&options_dict, &local_options_dict, "disable-static-deltas", G_VARIANT_TYPE ("b")); + copy_option (&options_dict, &local_options_dict, "disable-static-deltas", + G_VARIANT_TYPE ("b")); copy_option (&options_dict, &local_options_dict, "http-headers", G_VARIANT_TYPE ("a(ss)")); copy_option (&options_dict, &local_options_dict, "subdirs", G_VARIANT_TYPE ("as")); copy_option (&options_dict, &local_options_dict, "update-frequency", G_VARIANT_TYPE ("u")); copy_option (&options_dict, &local_options_dict, "append-user-agent", G_VARIANT_TYPE ("s")); copy_option (&options_dict, &local_options_dict, "n-network-retries", G_VARIANT_TYPE ("u")); - copy_option (&options_dict, &local_options_dict, "ref-keyring-map", G_VARIANT_TYPE ("a(sss)")); + copy_option (&options_dict, &local_options_dict, "ref-keyring-map", + G_VARIANT_TYPE ("a(sss)")); local_options = g_variant_dict_end (&local_options_dict); /* FIXME: We do nothing useful with @progress at the moment. */ remove_remote = !_ostree_repo_add_remote (self, result->remote); - ostree_repo_pull_with_options (self, result->remote->name, local_options, - progress, cancellable, &local_error); + ostree_repo_pull_with_options (self, result->remote->name, local_options, progress, + cancellable, &local_error); if (remove_remote) _ostree_repo_remove_remote (self, result->remote); @@ -6486,8 +6196,7 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, if (local_error != NULL) { - g_debug ("Failed to pull refs from ‘%s’: %s", - result->remote->name, local_error->message); + g_debug ("Failed to pull refs from ‘%s’: %s", result->remote->name, local_error->message); g_clear_error (&local_error); continue; } @@ -6498,16 +6207,16 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, } /* Commit the transaction. */ - if (!inherit_transaction && - !ostree_repo_commit_transaction (self, NULL, cancellable, &local_error)) + if (!inherit_transaction + && !ostree_repo_commit_transaction (self, NULL, cancellable, &local_error)) { g_task_return_error (task, g_steal_pointer (&local_error)); return; } /* Any refs left un-downloaded? If so, we’ve failed. */ - GLNX_HASH_TABLE_FOREACH_KV (refs_pulled, const OstreeCollectionRef*, ref, - gpointer, is_pulled_pointer) + GLNX_HASH_TABLE_FOREACH_KV (refs_pulled, const OstreeCollectionRef *, ref, gpointer, + is_pulled_pointer) { gboolean is_pulled = GPOINTER_TO_INT (is_pulled_pointer); @@ -6519,8 +6228,7 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, else g_string_append (refs_unpulled_string, ", "); - g_string_append_printf (refs_unpulled_string, "(%s, %s)", - ref->collection_id, ref->ref_name); + g_string_append_printf (refs_unpulled_string, "(%s, %s)", ref->collection_id, ref->ref_name); } if (refs_unpulled_string != NULL) @@ -6547,13 +6255,12 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, * Since: 2018.6 */ gboolean -ostree_repo_pull_from_remotes_finish (OstreeRepo *self, - GAsyncResult *result, - GError **error) +ostree_repo_pull_from_remotes_finish (OstreeRepo *self, GAsyncResult *result, GError **error) { g_return_val_if_fail (OSTREE_IS_REPO (self), FALSE); g_return_val_if_fail (g_task_is_valid (result, self), FALSE); - g_return_val_if_fail (g_async_result_is_tagged (result, ostree_repo_pull_from_remotes_async), FALSE); + g_return_val_if_fail (g_async_result_is_tagged (result, ostree_repo_pull_from_remotes_async), + FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); return g_task_propagate_boolean (G_TASK (result), error); @@ -6585,25 +6292,22 @@ ostree_repo_pull_from_remotes_finish (OstreeRepo *self, * Since: 2016.6 */ gboolean -ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, - const char *name, - GVariant *options, - GBytes **out_summary, - GBytes **out_signatures, - GCancellable *cancellable, - GError **error) +ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, const char *name, + GVariant *options, GBytes **out_summary, + GBytes **out_signatures, GCancellable *cancellable, + GError **error) { g_autofree char *metalink_url_string = NULL; - g_autoptr(GBytes) summary = NULL; - g_autoptr(GBytes) signatures = NULL; + g_autoptr (GBytes) summary = NULL; + g_autoptr (GBytes) signatures = NULL; gboolean gpg_verify_summary; - g_autoptr(GPtrArray) signapi_summary_verifiers = NULL; + g_autoptr (GPtrArray) signapi_summary_verifiers = NULL; gboolean summary_is_from_cache = FALSE; - g_autoptr(OstreeFetcher) fetcher = NULL; - g_autoptr(GMainContextPopDefault) mainctx = NULL; + g_autoptr (OstreeFetcher) fetcher = NULL; + g_autoptr (GMainContextPopDefault) mainctx = NULL; const char *url_override = NULL; - g_autoptr(GVariant) extra_headers = NULL; - g_autoptr(GPtrArray) mirrorlist = NULL; + g_autoptr (GVariant) extra_headers = NULL; + g_autoptr (GPtrArray) mirrorlist = NULL; const char *append_user_agent = NULL; guint n_network_retries = DEFAULT_N_NETWORK_RETRIES; gboolean summary_sig_not_modified = FALSE; @@ -6620,44 +6324,40 @@ ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, g_return_val_if_fail (OSTREE_REPO (self), FALSE); g_return_val_if_fail (name != NULL, FALSE); - if (!ostree_repo_get_remote_option (self, name, "metalink", NULL, - &metalink_url_string, error)) + if (!ostree_repo_get_remote_option (self, name, "metalink", NULL, &metalink_url_string, error)) return FALSE; if (options) { - (void) g_variant_lookup (options, "override-url", "&s", &url_override); - (void) g_variant_lookup (options, "http-headers", "@a(ss)", &extra_headers); - (void) g_variant_lookup (options, "append-user-agent", "&s", &append_user_agent); - (void) g_variant_lookup (options, "n-network-retries", "u", &n_network_retries); + (void)g_variant_lookup (options, "override-url", "&s", &url_override); + (void)g_variant_lookup (options, "http-headers", "@a(ss)", &extra_headers); + (void)g_variant_lookup (options, "append-user-agent", "&s", &append_user_agent); + (void)g_variant_lookup (options, "n-network-retries", "u", &n_network_retries); } if (!ostree_repo_remote_get_gpg_verify_summary (self, name, &gpg_verify_summary, error)) return FALSE; - if (!_signapi_init_for_remote (self, name, NULL, - &signapi_summary_verifiers, - error)) + if (!_signapi_init_for_remote (self, name, NULL, &signapi_summary_verifiers, error)) return FALSE; mainctx = _ostree_main_context_new_default (); - fetcher = _ostree_repo_remote_new_fetcher (self, name, TRUE, extra_headers, append_user_agent, NULL, error); + fetcher = _ostree_repo_remote_new_fetcher (self, name, TRUE, extra_headers, append_user_agent, + NULL, error); if (fetcher == NULL) return FALSE; if (metalink_url_string) { - g_autoptr(OstreeFetcherURI) uri = _ostree_fetcher_uri_parse (metalink_url_string, error); + g_autoptr (OstreeFetcherURI) uri = _ostree_fetcher_uri_parse (metalink_url_string, error); if (!uri) return FALSE; - mirrorlist = - g_ptr_array_new_with_free_func ((GDestroyNotify) _ostree_fetcher_uri_free); + mirrorlist = g_ptr_array_new_with_free_func ((GDestroyNotify)_ostree_fetcher_uri_free); g_ptr_array_add (mirrorlist, g_steal_pointer (&uri)); } - else if (!compute_effective_mirrorlist (self, name, url_override, - fetcher, n_network_retries, + else if (!compute_effective_mirrorlist (self, name, url_override, fetcher, n_network_retries, &mirrorlist, cancellable, error)) return FALSE; @@ -6666,22 +6366,16 @@ ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, * much benefit since summary.sig is typically 590B in size (vs a 0B HTTP 304 * response). But if a repository has multiple keys, the signature file will * grow and this optimisation may be useful. */ - _ostree_repo_load_cache_summary_properties (self, name, ".sig", - &summary_sig_if_none_match, &summary_sig_if_modified_since); - _ostree_repo_load_cache_summary_properties (self, name, NULL, - &summary_if_none_match, &summary_if_modified_since); - - if (!_ostree_preload_metadata_file (self, - fetcher, - mirrorlist, - "summary.sig", - metalink_url_string ? TRUE : FALSE, - summary_sig_if_none_match, summary_sig_if_modified_since, - n_network_retries, - &signatures, - &summary_sig_not_modified, &summary_sig_etag, &summary_sig_last_modified, - cancellable, - error)) + _ostree_repo_load_cache_summary_properties (self, name, ".sig", &summary_sig_if_none_match, + &summary_sig_if_modified_since); + _ostree_repo_load_cache_summary_properties (self, name, NULL, &summary_if_none_match, + &summary_if_modified_since); + + if (!_ostree_preload_metadata_file (self, fetcher, mirrorlist, "summary.sig", + metalink_url_string ? TRUE : FALSE, summary_sig_if_none_match, + summary_sig_if_modified_since, n_network_retries, &signatures, + &summary_sig_not_modified, &summary_sig_etag, + &summary_sig_last_modified, cancellable, error)) return FALSE; /* The server returned HTTP status 304 Not Modified, so we’re clear to @@ -6691,26 +6385,19 @@ ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, { g_clear_pointer (&signatures, g_bytes_unref); g_clear_pointer (&summary, g_bytes_unref); - if (!_ostree_repo_load_cache_summary_file (self, name, ".sig", - &signatures, - cancellable, error)) + if (!_ostree_repo_load_cache_summary_file (self, name, ".sig", &signatures, cancellable, + error)) return FALSE; - if (!summary && - !_ostree_repo_load_cache_summary_file (self, name, NULL, - &summary, - cancellable, error)) + if (!summary + && !_ostree_repo_load_cache_summary_file (self, name, NULL, &summary, cancellable, error)) return FALSE; } if (signatures && !summary) { - if (!_ostree_repo_load_cache_summary_if_same_sig (self, - name, - signatures, - &summary, - cancellable, - error)) + if (!_ostree_repo_load_cache_summary_if_same_sig (self, name, signatures, &summary, + cancellable, error)) return FALSE; } @@ -6718,17 +6405,10 @@ ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, summary_is_from_cache = TRUE; else { - if (!_ostree_preload_metadata_file (self, - fetcher, - mirrorlist, - "summary", - metalink_url_string ? TRUE : FALSE, - summary_if_none_match, summary_if_modified_since, - n_network_retries, - &summary, - &summary_not_modified, &summary_etag, &summary_last_modified, - cancellable, - error)) + if (!_ostree_preload_metadata_file ( + self, fetcher, mirrorlist, "summary", metalink_url_string ? TRUE : FALSE, + summary_if_none_match, summary_if_modified_since, n_network_retries, &summary, + &summary_not_modified, &summary_etag, &summary_last_modified, cancellable, error)) return FALSE; /* The server returned HTTP status 304 Not Modified, so we’re clear to @@ -6737,31 +6417,23 @@ ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, if (summary_not_modified) { g_clear_pointer (&summary, g_bytes_unref); - if (!_ostree_repo_load_cache_summary_file (self, name, NULL, - &summary, - cancellable, error)) + if (!_ostree_repo_load_cache_summary_file (self, name, NULL, &summary, cancellable, + error)) return FALSE; } } - if (!_ostree_repo_verify_summary (self, name, - gpg_verify_summary, signapi_summary_verifiers, - summary, signatures, - cancellable, error)) - return FALSE; + if (!_ostree_repo_verify_summary (self, name, gpg_verify_summary, signapi_summary_verifiers, + summary, signatures, cancellable, error)) + return FALSE; if (!summary_is_from_cache && summary && signatures) { - g_autoptr(GError) temp_error = NULL; + g_autoptr (GError) temp_error = NULL; - if (!_ostree_repo_cache_summary (self, - name, - summary, - summary_etag, summary_last_modified, - signatures, - summary_sig_etag, summary_sig_last_modified, - cancellable, - &temp_error)) + if (!_ostree_repo_cache_summary (self, name, summary, summary_etag, summary_last_modified, + signatures, summary_sig_etag, summary_sig_last_modified, + cancellable, &temp_error)) { if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED)) g_debug ("No permissions to save summary cache"); @@ -6785,55 +6457,46 @@ ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, #else /* HAVE_LIBCURL_OR_LIBSOUP */ gboolean -ostree_repo_pull_with_options (OstreeRepo *self, - const char *remote_name_or_baseurl, - GVariant *options, - OstreeAsyncProgress *progress, - GCancellable *cancellable, - GError **error) +ostree_repo_pull_with_options (OstreeRepo *self, const char *remote_name_or_baseurl, + GVariant *options, OstreeAsyncProgress *progress, + GCancellable *cancellable, GError **error) { - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, - "This version of ostree was built without libsoup or libcurl, and cannot fetch over HTTP"); + g_set_error_literal ( + error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, + "This version of ostree was built without libsoup or libcurl, and cannot fetch over HTTP"); return FALSE; } gboolean -ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, - const char *name, - GVariant *options, - GBytes **out_summary, - GBytes **out_signatures, - GCancellable *cancellable, - GError **error) +ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, const char *name, + GVariant *options, GBytes **out_summary, + GBytes **out_signatures, GCancellable *cancellable, + GError **error) { - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, - "This version of ostree was built without libsoup or libcurl, and cannot fetch over HTTP"); + g_set_error_literal ( + error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, + "This version of ostree was built without libsoup or libcurl, and cannot fetch over HTTP"); return FALSE; } void -ostree_repo_find_remotes_async (OstreeRepo *self, - const OstreeCollectionRef * const *refs, - GVariant *options, - OstreeRepoFinder **finders, - OstreeAsyncProgress *progress, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +ostree_repo_find_remotes_async (OstreeRepo *self, const OstreeCollectionRef *const *refs, + GVariant *options, OstreeRepoFinder **finders, + OstreeAsyncProgress *progress, GCancellable *cancellable, + GAsyncReadyCallback callback, gpointer user_data) { g_return_if_fail (OSTREE_IS_REPO (self)); - g_task_report_new_error (self, callback, user_data, ostree_repo_find_remotes_async, - G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, - "This version of ostree was built without libsoup or libcurl, and cannot fetch over HTTP"); + g_task_report_new_error ( + self, callback, user_data, ostree_repo_find_remotes_async, G_IO_ERROR, + G_IO_ERROR_NOT_SUPPORTED, + "This version of ostree was built without libsoup or libcurl, and cannot fetch over HTTP"); } OstreeRepoFinderResult ** -ostree_repo_find_remotes_finish (OstreeRepo *self, - GAsyncResult *result, - GError **error) +ostree_repo_find_remotes_finish (OstreeRepo *self, GAsyncResult *result, GError **error) { - g_autoptr(GPtrArray) results = NULL; + g_autoptr (GPtrArray) results = NULL; g_return_val_if_fail (OSTREE_IS_REPO (self), NULL); g_return_val_if_fail (g_task_is_valid (result, self), NULL); @@ -6846,31 +6509,28 @@ ostree_repo_find_remotes_finish (OstreeRepo *self, } void -ostree_repo_pull_from_remotes_async (OstreeRepo *self, - const OstreeRepoFinderResult * const *results, - GVariant *options, - OstreeAsyncProgress *progress, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +ostree_repo_pull_from_remotes_async (OstreeRepo *self, const OstreeRepoFinderResult *const *results, + GVariant *options, OstreeAsyncProgress *progress, + GCancellable *cancellable, GAsyncReadyCallback callback, + gpointer user_data) { g_return_if_fail (OSTREE_IS_REPO (self)); - g_task_report_new_error (self, callback, user_data, ostree_repo_find_remotes_async, - G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, - "This version of ostree was built without libsoup or libcurl, and cannot fetch over HTTP"); + g_task_report_new_error ( + self, callback, user_data, ostree_repo_find_remotes_async, G_IO_ERROR, + G_IO_ERROR_NOT_SUPPORTED, + "This version of ostree was built without libsoup or libcurl, and cannot fetch over HTTP"); } gboolean -ostree_repo_pull_from_remotes_finish (OstreeRepo *self, - GAsyncResult *result, - GError **error) +ostree_repo_pull_from_remotes_finish (OstreeRepo *self, GAsyncResult *result, GError **error) { gboolean success; g_return_val_if_fail (OSTREE_IS_REPO (self), FALSE); g_return_val_if_fail (g_task_is_valid (result, self), FALSE); - g_return_val_if_fail (g_async_result_is_tagged (result, ostree_repo_pull_from_remotes_async), FALSE); + g_return_val_if_fail (g_async_result_is_tagged (result, ostree_repo_pull_from_remotes_async), + FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); success = g_task_propagate_boolean (G_TASK (result), error); diff --git a/src/libostree/ostree-repo-refs.c b/src/libostree/ostree-repo-refs.c index 9ac2cc09..548a1fcb 100644 --- a/src/libostree/ostree-repo-refs.c +++ b/src/libostree/ostree-repo-refs.c @@ -21,20 +21,15 @@ #include "ostree-core-private.h" #include "ostree-repo-private.h" -#include "otutil.h" #include "ot-fs-utils.h" +#include "otutil.h" /* This is polymorphic in @collection_id: if non-%NULL, @refs will be treated as of * type OstreeCollectionRef ↦ checksum. Otherwise, it will be treated as of type * refspec ↦ checksum. */ static gboolean -add_ref_to_set (const char *remote, - const char *collection_id, - int base_fd, - const char *path, - GHashTable *refs, - GCancellable *cancellable, - GError **error) +add_ref_to_set (const char *remote, const char *collection_id, int base_fd, const char *path, + GHashTable *refs, GCancellable *cancellable, GError **error) { if (remote != NULL && collection_id != NULL) return glnx_throw (error, "Cannot process both a remote and a collection ID"); @@ -48,7 +43,7 @@ add_ref_to_set (const char *remote, if (collection_id == NULL) { - g_autoptr(GString) refname = g_string_new (""); + g_autoptr (GString) refname = g_string_new (""); if (remote) { g_string_append (refname, remote); @@ -66,12 +61,8 @@ add_ref_to_set (const char *remote, } static gboolean -write_checksum_file_at (OstreeRepo *self, - int dfd, - const char *name, - const char *sha256, - GCancellable *cancellable, - GError **error) +write_checksum_file_at (OstreeRepo *self, int dfd, const char *name, const char *sha256, + GCancellable *cancellable, GError **error) { if (!ostree_validate_checksum_string (sha256, error)) return FALSE; @@ -96,18 +87,18 @@ write_checksum_file_at (OstreeRepo *self, { size_t l = strlen (sha256); char *bufnl = alloca (l + 2); - g_autoptr(GError) temp_error = NULL; + g_autoptr (GError) temp_error = NULL; memcpy (bufnl, sha256, l); bufnl[l] = '\n'; - bufnl[l+1] = '\0'; + bufnl[l + 1] = '\0'; - if (!_ostree_repo_file_replace_contents (self, dfd, name, (guint8*)bufnl, l + 1, - cancellable, &temp_error)) + if (!_ostree_repo_file_replace_contents (self, dfd, name, (guint8 *)bufnl, l + 1, cancellable, + &temp_error)) { if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY)) { - g_autoptr(GHashTable) refs = NULL; + g_autoptr (GHashTable) refs = NULL; GHashTableIter hashiter; gpointer hashkey, hashvalue; @@ -123,13 +114,14 @@ write_checksum_file_at (OstreeRepo *self, while ((g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue))) { if (strcmp (name, (char *)hashkey) != 0) - return glnx_throw (error, "Conflict: %s exists under %s when attempting write", (char*)hashkey, name); + return glnx_throw (error, "Conflict: %s exists under %s when attempting write", + (char *)hashkey, name); } if (!glnx_shutil_rm_rf_at (dfd, name, cancellable, error)) return FALSE; - if (!_ostree_repo_file_replace_contents (self, dfd, name, (guint8*)bufnl, l + 1, + if (!_ostree_repo_file_replace_contents (self, dfd, name, (guint8 *)bufnl, l + 1, cancellable, error)) return FALSE; } @@ -145,12 +137,11 @@ write_checksum_file_at (OstreeRepo *self, } static gboolean -find_ref_in_remotes (OstreeRepo *self, - const char *rev, - int *out_fd, - GError **error) +find_ref_in_remotes (OstreeRepo *self, const char *rev, int *out_fd, GError **error) { - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; glnx_autofd int ret_fd = -1; if (!glnx_dirfd_iterator_init_at (self->repo_dir_fd, "refs/remotes", TRUE, &dfd_iter, error)) @@ -179,44 +170,32 @@ find_ref_in_remotes (OstreeRepo *self, break; } - *out_fd = ret_fd; ret_fd = -1; + *out_fd = ret_fd; + ret_fd = -1; return TRUE; } -static gboolean -resolve_refspec (OstreeRepo *self, - const char *remote, - const char *ref, - gboolean allow_noent, - gboolean fallback_remote, - char **out_rev, - GError **error); +static gboolean resolve_refspec (OstreeRepo *self, const char *remote, const char *ref, + gboolean allow_noent, gboolean fallback_remote, char **out_rev, + GError **error); static gboolean -resolve_refspec_fallback (OstreeRepo *self, - const char *remote, - const char *ref, - gboolean allow_noent, - gboolean fallback_remote, - char **out_rev, - GCancellable *cancellable, - GError **error) +resolve_refspec_fallback (OstreeRepo *self, const char *remote, const char *ref, + gboolean allow_noent, gboolean fallback_remote, char **out_rev, + GCancellable *cancellable, GError **error) { g_autofree char *ret_rev = NULL; if (self->parent_repo) { - if (!resolve_refspec (self->parent_repo, remote, ref, allow_noent, - fallback_remote, &ret_rev, error)) + if (!resolve_refspec (self->parent_repo, remote, ref, allow_noent, fallback_remote, &ret_rev, + error)) return FALSE; } else if (!allow_noent) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "Refspec '%s%s%s' not found", - remote ? remote : "", - remote ? ":" : "", - ref); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Refspec '%s%s%s' not found", + remote ? remote : "", remote ? ":" : "", ref); return FALSE; } @@ -225,15 +204,10 @@ resolve_refspec_fallback (OstreeRepo *self, } static gboolean -resolve_refspec (OstreeRepo *self, - const char *remote, - const char *ref, - gboolean allow_noent, - gboolean fallback_remote, - char **out_rev, - GError **error) +resolve_refspec (OstreeRepo *self, const char *remote, const char *ref, gboolean allow_noent, + gboolean fallback_remote, char **out_rev, GError **error) { - __attribute__((unused)) GCancellable *cancellable = NULL; + __attribute__ ((unused)) GCancellable *cancellable = NULL; g_autofree char *ret_rev = NULL; glnx_autofd int target_fd = -1; @@ -309,8 +283,8 @@ resolve_refspec (OstreeRepo *self, } else { - if (!resolve_refspec_fallback (self, remote, ref, allow_noent, fallback_remote, - &ret_rev, cancellable, error)) + if (!resolve_refspec_fallback (self, remote, ref, allow_noent, fallback_remote, &ret_rev, + cancellable, error)) return FALSE; } @@ -329,10 +303,8 @@ resolve_refspec (OstreeRepo *self, * of a valid checksum it will return that checksum in the parameter @full_checksum */ static gboolean -ostree_repo_resolve_partial_checksum (OstreeRepo *self, - const char *refspec, - char **full_checksum, - GError **error) +ostree_repo_resolve_partial_checksum (OstreeRepo *self, const char *refspec, char **full_checksum, + GError **error) { static const char hexchars[] = "0123456789abcdef"; g_autofree char *ret_rev = NULL; @@ -348,7 +320,7 @@ ostree_repo_resolve_partial_checksum (OstreeRepo *self, /* this looks through all objects and adds them to the ref_list if: a) they are a commit object AND b) the obj checksum starts with the partual checksum defined by "refspec" */ - g_autoptr(GHashTable) ref_list = NULL; + g_autoptr (GHashTable) ref_list = NULL; if (!ostree_repo_list_commit_objects_starting_with (self, refspec, &ref_list, NULL, error)) return FALSE; @@ -359,7 +331,7 @@ ostree_repo_resolve_partial_checksum (OstreeRepo *self, GVariant *first_commit = NULL; g_hash_table_iter_init (&hashiter, ref_list); if (g_hash_table_iter_next (&hashiter, &key, &value)) - first_commit = (GVariant*) key; + first_commit = (GVariant *)key; OstreeObjectType objtype; const char *checksum = NULL; @@ -382,12 +354,8 @@ ostree_repo_resolve_partial_checksum (OstreeRepo *self, } static gboolean -_ostree_repo_resolve_rev_internal (OstreeRepo *self, - const char *refspec, - gboolean allow_noent, - gboolean fallback_remote, - char **out_rev, - GError **error) +_ostree_repo_resolve_rev_internal (OstreeRepo *self, const char *refspec, gboolean allow_noent, + gboolean fallback_remote, char **out_rev, GError **error) { g_autofree char *ret_rev = NULL; @@ -409,16 +377,16 @@ _ostree_repo_resolve_rev_internal (OstreeRepo *self, { g_autofree char *parent_refspec = NULL; g_autofree char *parent_rev = NULL; - g_autoptr(GVariant) commit = NULL; + g_autoptr (GVariant) commit = NULL; parent_refspec = g_strdup (refspec); - parent_refspec[strlen(parent_refspec) - 1] = '\0'; + parent_refspec[strlen (parent_refspec) - 1] = '\0'; if (!ostree_repo_resolve_rev (self, parent_refspec, allow_noent, &parent_rev, error)) return FALSE; - if (!ostree_repo_load_variant (self, OSTREE_OBJECT_TYPE_COMMIT, parent_rev, - &commit, error)) + if (!ostree_repo_load_variant (self, OSTREE_OBJECT_TYPE_COMMIT, parent_rev, &commit, + error)) return FALSE; if (!(ret_rev = ostree_commit_get_parent (commit))) @@ -432,8 +400,7 @@ _ostree_repo_resolve_rev_internal (OstreeRepo *self, if (!ostree_parse_refspec (refspec, &remote, &ref, error)) return FALSE; - if (!resolve_refspec (self, remote, ref, allow_noent, - fallback_remote, &ret_rev, error)) + if (!resolve_refspec (self, remote, ref, allow_noent, fallback_remote, &ret_rev, error)) return FALSE; } } @@ -447,7 +414,8 @@ _ostree_repo_resolve_rev_internal (OstreeRepo *self, * @self: Repo * @refspec: A refspec * @allow_noent: Do not throw an error if refspec does not exist - * @out_rev: (out) (nullable) (transfer full): A checksum,or %NULL if @allow_noent is true and it does not exist + * @out_rev: (out) (nullable) (transfer full): A checksum,or %NULL if @allow_noent is true and it + * does not exist * @error: Error * * Look up the given refspec, returning the checksum it references in @@ -455,11 +423,8 @@ _ostree_repo_resolve_rev_internal (OstreeRepo *self, * find the given refspec in local. */ gboolean -ostree_repo_resolve_rev (OstreeRepo *self, - const char *refspec, - gboolean allow_noent, - char **out_rev, - GError **error) +ostree_repo_resolve_rev (OstreeRepo *self, const char *refspec, gboolean allow_noent, + char **out_rev, GError **error) { return _ostree_repo_resolve_rev_internal (self, refspec, allow_noent, TRUE, out_rev, error); } @@ -470,7 +435,8 @@ ostree_repo_resolve_rev (OstreeRepo *self, * @refspec: A refspec * @allow_noent: Do not throw an error if refspec does not exist * @flags: Options controlling behavior - * @out_rev: (out) (nullable) (transfer full): A checksum,or %NULL if @allow_noent is true and it does not exist + * @out_rev: (out) (nullable) (transfer full): A checksum,or %NULL if @allow_noent is true and it + * does not exist * @error: Error * * Look up the given refspec, returning the checksum it references in @@ -484,12 +450,8 @@ ostree_repo_resolve_rev (OstreeRepo *self, * Since: 2016.7 */ gboolean -ostree_repo_resolve_rev_ext (OstreeRepo *self, - const char *refspec, - gboolean allow_noent, - OstreeRepoResolveRevExtFlags flags, - char **out_rev, - GError **error) +ostree_repo_resolve_rev_ext (OstreeRepo *self, const char *refspec, gboolean allow_noent, + OstreeRepoResolveRevExtFlags flags, char **out_rev, GError **error) { return _ostree_repo_resolve_rev_internal (self, refspec, allow_noent, FALSE, out_rev, error); } @@ -522,13 +484,9 @@ ostree_repo_resolve_rev_ext (OstreeRepo *self, * Since: 2018.6 */ gboolean -ostree_repo_resolve_collection_ref (OstreeRepo *self, - const OstreeCollectionRef *ref, - gboolean allow_noent, - OstreeRepoResolveRevExtFlags flags, - char **out_rev, - GCancellable *cancellable, - GError **error) +ostree_repo_resolve_collection_ref (OstreeRepo *self, const OstreeCollectionRef *ref, + gboolean allow_noent, OstreeRepoResolveRevExtFlags flags, + char **out_rev, GCancellable *cancellable, GError **error) { g_autofree char *ret_contents = NULL; @@ -547,29 +505,29 @@ ostree_repo_resolve_collection_ref (OstreeRepo *self, { const char *repo_collection_id = ostree_repo_get_collection_id (self); /* If the collection ID doesn't match it's a remote ref */ - if (!(flags & OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY) || - repo_collection_id == NULL || - g_strcmp0 (repo_collection_id, ref->collection_id) == 0) + if (!(flags & OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY) || repo_collection_id == NULL + || g_strcmp0 (repo_collection_id, ref->collection_id) == 0) { ret_contents = g_strdup (g_hash_table_lookup (self->txn.collection_refs, ref)); } - } + } g_mutex_unlock (&self->txn_lock); } /* Check for the ref on disk in the repo */ if (ret_contents == NULL) { - g_autoptr(GHashTable) refs = NULL; /* (element-type OstreeCollectionRef utf8) */ + g_autoptr (GHashTable) refs = NULL; /* (element-type OstreeCollectionRef utf8) */ OstreeRepoListRefsExtFlags list_refs_flags; if (flags & OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY) - list_refs_flags = OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES | OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_MIRRORS; + list_refs_flags + = OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES | OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_MIRRORS; else list_refs_flags = OSTREE_REPO_LIST_REFS_EXT_NONE; - if (!ostree_repo_list_collection_refs (self, ref->collection_id, &refs, - list_refs_flags, cancellable, error)) + if (!ostree_repo_list_collection_refs (self, ref->collection_id, &refs, list_refs_flags, + cancellable, error)) return FALSE; ret_contents = g_strdup (g_hash_table_lookup (refs, ref)); @@ -578,20 +536,14 @@ ostree_repo_resolve_collection_ref (OstreeRepo *self, /* Check for the ref in the parent repo */ if (ret_contents == NULL && self->parent_repo != NULL) { - if (!ostree_repo_resolve_collection_ref (self->parent_repo, - ref, - TRUE, - flags, - &ret_contents, - cancellable, - error)) + if (!ostree_repo_resolve_collection_ref (self->parent_repo, ref, TRUE, flags, &ret_contents, + cancellable, error)) return FALSE; } if (ret_contents == NULL && !allow_noent) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "Collection–ref (%s, %s) not found", + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Collection–ref (%s, %s) not found", ref->collection_id, ref->ref_name); return FALSE; } @@ -602,19 +554,14 @@ ostree_repo_resolve_collection_ref (OstreeRepo *self, } static gboolean -enumerate_refs_recurse (OstreeRepo *repo, - const char *remote, - OstreeRepoListRefsExtFlags flags, - const char *collection_id, - int base_dfd, - GString *base_path, - int child_dfd, - const char *path, - GHashTable *refs, - GCancellable *cancellable, - GError **error) +enumerate_refs_recurse (OstreeRepo *repo, const char *remote, OstreeRepoListRefsExtFlags flags, + const char *collection_id, int base_dfd, GString *base_path, int child_dfd, + const char *path, GHashTable *refs, GCancellable *cancellable, + GError **error) { - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; const gboolean aliases_only = (flags & OSTREE_REPO_LIST_REFS_EXT_ALIASES) > 0; if (!glnx_dirfd_iterator_init_at (child_dfd, path, FALSE, &dfd_iter, error)) @@ -645,16 +592,15 @@ enumerate_refs_recurse (OstreeRepo *repo, g_string_append_c (base_path, '/'); if (!enumerate_refs_recurse (repo, remote, flags, collection_id, base_dfd, base_path, - dfd_iter.fd, dent->d_name, - refs, cancellable, error)) + dfd_iter.fd, dent->d_name, refs, cancellable, error)) return FALSE; } else { if (aliases_only && dent->d_type == DT_LNK) { - g_autofree char *target = glnx_readlinkat_malloc (base_dfd, base_path->str, - cancellable, error); + g_autofree char *target + = glnx_readlinkat_malloc (base_dfd, base_path->str, cancellable, error); const char *resolved_target = target; if (!target) return FALSE; @@ -677,20 +623,18 @@ enumerate_refs_recurse (OstreeRepo *repo, } static gboolean -_ostree_repo_list_refs_internal (OstreeRepo *self, - gboolean cut_prefix, - OstreeRepoListRefsExtFlags flags, - const char *refspec_prefix, - GHashTable **out_all_refs, - GCancellable *cancellable, - GError **error) +_ostree_repo_list_refs_internal (OstreeRepo *self, gboolean cut_prefix, + OstreeRepoListRefsExtFlags flags, const char *refspec_prefix, + GHashTable **out_all_refs, GCancellable *cancellable, + GError **error) { GLNX_AUTO_PREFIX_ERROR ("Listing refs", error); g_autofree char *remote = NULL; g_autofree char *ref_prefix = NULL; - g_autoptr(GHashTable) ret_all_refs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + g_autoptr (GHashTable) ret_all_refs + = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); if (refspec_prefix) { struct stat stbuf; @@ -698,8 +642,7 @@ _ostree_repo_list_refs_internal (OstreeRepo *self, const char *path; /* special-case ":" and ":.", which ostree_parse_refspec won't like */ - if (g_str_has_suffix (refspec_prefix, ":") || - g_str_has_suffix (refspec_prefix, ":.")) + if (g_str_has_suffix (refspec_prefix, ":") || g_str_has_suffix (refspec_prefix, ":.")) { const char *colon = strrchr (refspec_prefix, ':'); g_autofree char *r = g_strndup (refspec_prefix, colon - refspec_prefix); @@ -734,16 +677,17 @@ _ostree_repo_list_refs_internal (OstreeRepo *self, if (S_ISDIR (stbuf.st_mode)) { glnx_autofd int base_fd = -1; - g_autoptr(GString) base_path = g_string_new (""); + g_autoptr (GString) base_path = g_string_new (""); if (!cut_prefix) g_string_printf (base_path, "%s/", ref_prefix); - if (!glnx_opendirat (self->repo_dir_fd, cut_prefix ? path : prefix_path, TRUE, &base_fd, error)) + if (!glnx_opendirat (self->repo_dir_fd, cut_prefix ? path : prefix_path, TRUE, + &base_fd, error)) return FALSE; - if (!enumerate_refs_recurse (self, remote, flags, NULL, base_fd, base_path, - base_fd, cut_prefix ? "." : ref_prefix, - ret_all_refs, cancellable, error)) + if (!enumerate_refs_recurse (self, remote, flags, NULL, base_fd, base_path, base_fd, + cut_prefix ? "." : ref_prefix, ret_all_refs, cancellable, + error)) return FALSE; } else @@ -753,31 +697,33 @@ _ostree_repo_list_refs_internal (OstreeRepo *self, if (!glnx_opendirat (self->repo_dir_fd, prefix_path, TRUE, &prefix_dfd, error)) return FALSE; - if (!add_ref_to_set (remote, NULL, prefix_dfd, ref_prefix, ret_all_refs, - cancellable, error)) + if (!add_ref_to_set (remote, NULL, prefix_dfd, ref_prefix, ret_all_refs, cancellable, + error)) return FALSE; } } } else { - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; - g_autoptr(GString) base_path = g_string_new (""); + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; + g_autoptr (GString) base_path = g_string_new (""); glnx_autofd int refs_heads_dfd = -1; if (!glnx_opendirat (self->repo_dir_fd, "refs/heads", TRUE, &refs_heads_dfd, error)) return FALSE; if (!enumerate_refs_recurse (self, NULL, flags, NULL, refs_heads_dfd, base_path, - refs_heads_dfd, ".", - ret_all_refs, cancellable, error)) + refs_heads_dfd, ".", ret_all_refs, cancellable, error)) return FALSE; if (!(flags & OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES)) { g_string_truncate (base_path, 0); - if (!glnx_dirfd_iterator_init_at (self->repo_dir_fd, "refs/remotes", TRUE, &dfd_iter, error)) + if (!glnx_dirfd_iterator_init_at (self->repo_dir_fd, "refs/remotes", TRUE, &dfd_iter, + error)) return FALSE; while (TRUE) @@ -785,7 +731,8 @@ _ostree_repo_list_refs_internal (OstreeRepo *self, struct dirent *dent; glnx_autofd int remote_dfd = -1; - 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) break; @@ -797,9 +744,7 @@ _ostree_repo_list_refs_internal (OstreeRepo *self, return FALSE; if (!enumerate_refs_recurse (self, dent->d_name, flags, NULL, remote_dfd, base_path, - remote_dfd, ".", - ret_all_refs, - cancellable, error)) + remote_dfd, ".", ret_all_refs, cancellable, error)) return FALSE; } } @@ -827,16 +772,11 @@ _ostree_repo_list_refs_internal (OstreeRepo *self, * removed as a prefix from the hash table keys. */ gboolean -ostree_repo_list_refs (OstreeRepo *self, - const char *refspec_prefix, - GHashTable **out_all_refs, - GCancellable *cancellable, - GError **error) +ostree_repo_list_refs (OstreeRepo *self, const char *refspec_prefix, GHashTable **out_all_refs, + GCancellable *cancellable, GError **error) { - return _ostree_repo_list_refs_internal (self, TRUE, - OSTREE_REPO_LIST_REFS_EXT_NONE, - refspec_prefix, out_all_refs, - cancellable, error); + return _ostree_repo_list_refs_internal (self, TRUE, OSTREE_REPO_LIST_REFS_EXT_NONE, + refspec_prefix, out_all_refs, cancellable, error); } /** @@ -860,15 +800,11 @@ ostree_repo_list_refs (OstreeRepo *self, * Since: 2016.4 */ gboolean -ostree_repo_list_refs_ext (OstreeRepo *self, - const char *refspec_prefix, - GHashTable **out_all_refs, - OstreeRepoListRefsExtFlags flags, - GCancellable *cancellable, - GError **error) +ostree_repo_list_refs_ext (OstreeRepo *self, const char *refspec_prefix, GHashTable **out_all_refs, + OstreeRepoListRefsExtFlags flags, GCancellable *cancellable, + GError **error) { - return _ostree_repo_list_refs_internal (self, FALSE, flags, - refspec_prefix, out_all_refs, + return _ostree_repo_list_refs_internal (self, FALSE, flags, refspec_prefix, out_all_refs, cancellable, error); } @@ -883,18 +819,14 @@ ostree_repo_list_refs_ext (OstreeRepo *self, * */ gboolean -ostree_repo_remote_list_refs (OstreeRepo *self, - const char *remote_name, - GHashTable **out_all_refs, - GCancellable *cancellable, - GError **error) +ostree_repo_remote_list_refs (OstreeRepo *self, const char *remote_name, GHashTable **out_all_refs, + GCancellable *cancellable, GError **error) { - g_autoptr(GBytes) summary_bytes = NULL; - g_autoptr(GHashTable) ret_all_refs = NULL; + g_autoptr (GBytes) summary_bytes = NULL; + g_autoptr (GHashTable) ret_all_refs = NULL; - if (!ostree_repo_remote_fetch_summary (self, remote_name, - &summary_bytes, NULL, - cancellable, error)) + if (!ostree_repo_remote_fetch_summary (self, remote_name, &summary_bytes, NULL, cancellable, + error)) return FALSE; if (summary_bytes == NULL) @@ -903,14 +835,13 @@ ostree_repo_remote_list_refs (OstreeRepo *self, } else { - g_autoptr(GVariant) summary = NULL; - g_autoptr(GVariant) ref_map = NULL; + g_autoptr (GVariant) summary = NULL; + g_autoptr (GVariant) ref_map = NULL; GVariantIter iter; GVariant *child; ret_all_refs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - summary = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, - summary_bytes, FALSE); + summary = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, summary_bytes, FALSE); ref_map = g_variant_get_child_value (summary, 0); @@ -918,8 +849,8 @@ ostree_repo_remote_list_refs (OstreeRepo *self, while ((child = g_variant_iter_next_value (&iter)) != NULL) { const char *ref_name = NULL; - g_autoptr(GVariant) csum_v = NULL; - char tmp_checksum[OSTREE_SHA256_STRING_LEN+1]; + g_autoptr (GVariant) csum_v = NULL; + char tmp_checksum[OSTREE_SHA256_STRING_LEN + 1]; g_variant_get_child (child, 0, "&s", &ref_name); @@ -933,9 +864,7 @@ ostree_repo_remote_list_refs (OstreeRepo *self, ostree_checksum_inplace_from_bytes (csum_bytes, tmp_checksum); - g_hash_table_insert (ret_all_refs, - g_strdup (ref_name), - g_strdup (tmp_checksum)); + g_hash_table_insert (ret_all_refs, g_strdup (ref_name), g_strdup (tmp_checksum)); } g_variant_unref (child); @@ -947,19 +876,17 @@ ostree_repo_remote_list_refs (OstreeRepo *self, } static gboolean -remote_list_collection_refs_process_refs (OstreeRepo *self, - const gchar *remote_name, - const gchar *summary_collection_id, - GVariant *summary_refs, - GHashTable *ret_all_refs, - GError **error) +remote_list_collection_refs_process_refs (OstreeRepo *self, const gchar *remote_name, + const gchar *summary_collection_id, + GVariant *summary_refs, GHashTable *ret_all_refs, + GError **error) { gsize j, n; for (j = 0, n = g_variant_n_children (summary_refs); j < n; j++) { const guchar *csum_bytes; - g_autoptr(GVariant) ref_v = NULL, csum_v = NULL; + g_autoptr (GVariant) ref_v = NULL, csum_v = NULL; gchar tmp_checksum[OSTREE_SHA256_STRING_LEN + 1]; const gchar *ref_name; @@ -1006,58 +933,53 @@ remote_list_collection_refs_process_refs (OstreeRepo *self, * Since: 2018.6 */ gboolean -ostree_repo_remote_list_collection_refs (OstreeRepo *self, - const char *remote_name, - GHashTable **out_all_refs, - GCancellable *cancellable, - GError **error) +ostree_repo_remote_list_collection_refs (OstreeRepo *self, const char *remote_name, + GHashTable **out_all_refs, GCancellable *cancellable, + GError **error) { - g_autoptr(GBytes) summary_bytes = NULL; - g_autoptr(GHashTable) ret_all_refs = NULL; /* (element-type OstreeCollectionRef utf8) */ - g_autoptr(GVariant) summary_v = NULL; - g_autoptr(GVariant) additional_metadata_v = NULL; - g_autoptr(GVariant) summary_refs = NULL; + g_autoptr (GBytes) summary_bytes = NULL; + g_autoptr (GHashTable) ret_all_refs = NULL; /* (element-type OstreeCollectionRef utf8) */ + g_autoptr (GVariant) summary_v = NULL; + g_autoptr (GVariant) additional_metadata_v = NULL; + g_autoptr (GVariant) summary_refs = NULL; const char *summary_collection_id; - g_autoptr(GVariantIter) summary_collection_map = NULL; + g_autoptr (GVariantIter) summary_collection_map = NULL; - if (!ostree_repo_remote_fetch_summary (self, remote_name, - &summary_bytes, NULL, - cancellable, error)) + if (!ostree_repo_remote_fetch_summary (self, remote_name, &summary_bytes, NULL, cancellable, + error)) return FALSE; if (summary_bytes == NULL) return glnx_throw (error, "Remote refs not available; server has no summary file"); - ret_all_refs = g_hash_table_new_full (ostree_collection_ref_hash, - ostree_collection_ref_equal, - (GDestroyNotify) ostree_collection_ref_free, - g_free); + ret_all_refs = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, + (GDestroyNotify)ostree_collection_ref_free, g_free); - summary_v = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, - summary_bytes, FALSE); + summary_v = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, summary_bytes, FALSE); additional_metadata_v = g_variant_get_child_value (summary_v, 1); /* List the refs in the main map. */ - if (!g_variant_lookup (additional_metadata_v, OSTREE_SUMMARY_COLLECTION_ID, "&s", &summary_collection_id)) + if (!g_variant_lookup (additional_metadata_v, OSTREE_SUMMARY_COLLECTION_ID, "&s", + &summary_collection_id)) summary_collection_id = NULL; summary_refs = g_variant_get_child_value (summary_v, 0); - if (!remote_list_collection_refs_process_refs (self, remote_name, - summary_collection_id, summary_refs, - ret_all_refs, error)) + if (!remote_list_collection_refs_process_refs (self, remote_name, summary_collection_id, + summary_refs, ret_all_refs, error)) return FALSE; /* List the refs in the collection map. */ - if (!g_variant_lookup (additional_metadata_v, OSTREE_SUMMARY_COLLECTION_MAP, "a{sa(s(taya{sv}))}", &summary_collection_map)) + if (!g_variant_lookup (additional_metadata_v, OSTREE_SUMMARY_COLLECTION_MAP, "a{sa(s(taya{sv}))}", + &summary_collection_map)) summary_collection_map = NULL; - while (summary_collection_map != NULL && - g_variant_iter_loop (summary_collection_map, "{&s@a(s(taya{sv}))}", &summary_collection_id, &summary_refs)) + while (summary_collection_map != NULL + && g_variant_iter_loop (summary_collection_map, "{&s@a(s(taya{sv}))}", + &summary_collection_id, &summary_refs)) { - if (!remote_list_collection_refs_process_refs (self, remote_name, - summary_collection_id, summary_refs, - ret_all_refs, error)) + if (!remote_list_collection_refs_process_refs (self, remote_name, summary_collection_id, + summary_refs, ret_all_refs, error)) return FALSE; } @@ -1066,13 +988,12 @@ ostree_repo_remote_list_collection_refs (OstreeRepo *self, } static char * -relative_symlink_to (const char *relpath, - const char *target) +relative_symlink_to (const char *relpath, const char *target) { g_assert (*relpath); g_assert (*target && *target != '/'); - g_autoptr(GString) buf = g_string_new (""); + g_autoptr (GString) buf = g_string_new (""); while (TRUE) { @@ -1090,13 +1011,9 @@ relative_symlink_to (const char *relpath, /* May specify @rev or @alias */ gboolean -_ostree_repo_write_ref (OstreeRepo *self, - const char *remote, - const OstreeCollectionRef *ref, - const char *rev, - const char *alias, - GCancellable *cancellable, - GError **error) +_ostree_repo_write_ref (OstreeRepo *self, const char *remote, const OstreeCollectionRef *ref, + const char *rev, const char *alias, GCancellable *cancellable, + GError **error) { glnx_autofd int dfd = -1; @@ -1110,11 +1027,11 @@ _ostree_repo_write_ref (OstreeRepo *self, if (!ostree_validate_rev (ref->ref_name, error)) return FALSE; - if (remote == NULL && - (ref->collection_id == NULL || g_strcmp0 (ref->collection_id, ostree_repo_get_collection_id (self)) == 0)) + if (remote == NULL + && (ref->collection_id == NULL + || g_strcmp0 (ref->collection_id, ostree_repo_get_collection_id (self)) == 0)) { - if (!glnx_opendirat (self->repo_dir_fd, "refs/heads", TRUE, - &dfd, error)) + if (!glnx_opendirat (self->repo_dir_fd, "refs/heads", TRUE, &dfd, error)) return FALSE; } else if (remote == NULL && ref->collection_id != NULL) @@ -1122,14 +1039,15 @@ _ostree_repo_write_ref (OstreeRepo *self, glnx_autofd int refs_mirrors_dfd = -1; /* refs/mirrors might not exist in older repositories, so create it. */ - if (!glnx_shutil_mkdir_p_at_open (self->repo_dir_fd, "refs/mirrors", 0777, - &refs_mirrors_dfd, cancellable, error)) + if (!glnx_shutil_mkdir_p_at_open (self->repo_dir_fd, "refs/mirrors", 0777, &refs_mirrors_dfd, + cancellable, error)) return FALSE; if (rev != NULL) { /* Ensure we have a dir for the collection */ - if (!glnx_shutil_mkdir_p_at (refs_mirrors_dfd, ref->collection_id, 0777, cancellable, error)) + if (!glnx_shutil_mkdir_p_at (refs_mirrors_dfd, ref->collection_id, 0777, cancellable, + error)) return FALSE; } @@ -1141,8 +1059,7 @@ _ostree_repo_write_ref (OstreeRepo *self, { glnx_autofd int refs_remotes_dfd = -1; - if (!glnx_opendirat (self->repo_dir_fd, "refs/remotes", TRUE, - &refs_remotes_dfd, error)) + if (!glnx_opendirat (self->repo_dir_fd, "refs/remotes", TRUE, &refs_remotes_dfd, error)) return FALSE; if (rev != NULL) @@ -1185,8 +1102,8 @@ _ostree_repo_write_ref (OstreeRepo *self, g_autofree char *reltarget = relative_symlink_to (ref->ref_name, alias); g_autofree char *tmplink = NULL; - if (!_ostree_make_temporary_symlink_at (self->tmp_dir_fd, reltarget, - &tmplink, cancellable, error)) + if (!_ostree_make_temporary_symlink_at (self->tmp_dir_fd, reltarget, &tmplink, cancellable, + error)) return FALSE; if (!glnx_renameat (self->tmp_dir_fd, tmplink, dfd, ref->ref_name, error)) return FALSE; @@ -1204,12 +1121,10 @@ _ostree_repo_write_ref (OstreeRepo *self, } gboolean -_ostree_repo_update_refs (OstreeRepo *self, - GHashTable *refs, /* (element-type utf8 utf8) */ - GCancellable *cancellable, - GError **error) +_ostree_repo_update_refs (OstreeRepo *self, GHashTable *refs, /* (element-type utf8 utf8) */ + GCancellable *cancellable, GError **error) { - GLNX_HASH_TABLE_FOREACH_KV (refs, const char*, refspec, const char*, rev) + GLNX_HASH_TABLE_FOREACH_KV (refs, const char *, refspec, const char *, rev) { g_autofree char *remote = NULL; g_autofree char *ref_name = NULL; @@ -1217,8 +1132,7 @@ _ostree_repo_update_refs (OstreeRepo *self, return FALSE; const OstreeCollectionRef ref = { NULL, ref_name }; - if (!_ostree_repo_write_ref (self, remote, &ref, rev, NULL, - cancellable, error)) + if (!_ostree_repo_write_ref (self, remote, &ref, rev, NULL, cancellable, error)) return FALSE; } @@ -1226,10 +1140,9 @@ _ostree_repo_update_refs (OstreeRepo *self, } gboolean -_ostree_repo_update_collection_refs (OstreeRepo *self, - GHashTable *refs, /* (element-type OstreeCollectionRef utf8) */ - GCancellable *cancellable, - GError **error) +_ostree_repo_update_collection_refs (OstreeRepo *self, + GHashTable *refs, /* (element-type OstreeCollectionRef utf8) */ + GCancellable *cancellable, GError **error) { GHashTableIter hash_iter; gpointer key, value; @@ -1240,8 +1153,7 @@ _ostree_repo_update_collection_refs (OstreeRepo *self, const OstreeCollectionRef *ref = key; const char *rev = value; - if (!_ostree_repo_write_ref (self, NULL, ref, rev, NULL, - cancellable, error)) + if (!_ostree_repo_write_ref (self, NULL, ref, rev, NULL, cancellable, error)) return FALSE; } @@ -1277,12 +1189,9 @@ _ostree_repo_update_collection_refs (OstreeRepo *self, * Since: 2018.6 */ gboolean -ostree_repo_list_collection_refs (OstreeRepo *self, - const char *match_collection_id, - GHashTable **out_all_refs, - OstreeRepoListRefsExtFlags flags, - GCancellable *cancellable, - GError **error) +ostree_repo_list_collection_refs (OstreeRepo *self, const char *match_collection_id, + GHashTable **out_all_refs, OstreeRepoListRefsExtFlags flags, + GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("Listing refs", error); @@ -1293,36 +1202,32 @@ ostree_repo_list_collection_refs (OstreeRepo *self, if (match_collection_id != NULL && !ostree_validate_collection_id (match_collection_id, error)) return FALSE; - g_autoptr(GPtrArray) refs_dirs = g_ptr_array_new (); + g_autoptr (GPtrArray) refs_dirs = g_ptr_array_new (); if (!(flags & OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_MIRRORS)) g_ptr_array_add (refs_dirs, "refs/mirrors"); if (!(flags & OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES)) g_ptr_array_add (refs_dirs, "refs/remotes"); g_ptr_array_add (refs_dirs, NULL); - g_autoptr(GHashTable) ret_all_refs = NULL; + g_autoptr (GHashTable) ret_all_refs = NULL; - ret_all_refs = g_hash_table_new_full (ostree_collection_ref_hash, - ostree_collection_ref_equal, - (GDestroyNotify) ostree_collection_ref_free, - g_free); + ret_all_refs = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, + (GDestroyNotify)ostree_collection_ref_free, g_free); - g_autoptr(GString) base_path = g_string_new (""); + g_autoptr (GString) base_path = g_string_new (""); const gchar *main_collection_id = ostree_repo_get_collection_id (self); - if (main_collection_id != NULL && - (match_collection_id == NULL || g_strcmp0 (match_collection_id, main_collection_id) == 0)) + if (main_collection_id != NULL + && (match_collection_id == NULL || g_strcmp0 (match_collection_id, main_collection_id) == 0)) { glnx_autofd int refs_heads_dfd = -1; if (!glnx_opendirat (self->repo_dir_fd, "refs/heads", TRUE, &refs_heads_dfd, error)) return FALSE; - if (!enumerate_refs_recurse (self, NULL, flags, - main_collection_id, refs_heads_dfd, base_path, - refs_heads_dfd, ".", - ret_all_refs, cancellable, error)) + if (!enumerate_refs_recurse (self, NULL, flags, main_collection_id, refs_heads_dfd, base_path, + refs_heads_dfd, ".", ret_all_refs, cancellable, error)) return FALSE; } @@ -1332,10 +1237,12 @@ ostree_repo_list_collection_refs (OstreeRepo *self, { const char *refs_dir = *iter; gboolean refs_dir_exists = FALSE; - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; - if (!ot_dfd_iter_init_allow_noent (self->repo_dir_fd, refs_dir, - &dfd_iter, &refs_dir_exists, error)) + if (!ot_dfd_iter_init_allow_noent (self->repo_dir_fd, refs_dir, &dfd_iter, &refs_dir_exists, + error)) return FALSE; while (refs_dir_exists) @@ -1362,18 +1269,20 @@ ostree_repo_list_collection_refs (OstreeRepo *self, } else /* refs_dir = "refs/remotes" */ { - g_autoptr(GError) local_error = NULL; - if (!ostree_repo_get_remote_option (self, dent->d_name, "collection-id", - NULL, &remote_collection_id, &local_error) || - !ostree_validate_collection_id (remote_collection_id, &local_error)) + g_autoptr (GError) local_error = NULL; + if (!ostree_repo_get_remote_option (self, dent->d_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", + g_debug ("Ignoring remote ‘%s’ due to no valid collection ID being configured " + "for it: %s", dent->d_name, local_error->message); g_clear_error (&local_error); continue; } - if (match_collection_id != NULL && g_strcmp0 (match_collection_id, remote_collection_id) != 0) + if (match_collection_id != NULL + && g_strcmp0 (match_collection_id, remote_collection_id) != 0) continue; else current_collection_id = remote_collection_id; @@ -1382,11 +1291,8 @@ ostree_repo_list_collection_refs (OstreeRepo *self, if (!glnx_opendirat (dfd_iter.fd, dent->d_name, TRUE, &subdir_fd, error)) return FALSE; - if (!enumerate_refs_recurse (self, NULL, flags, - current_collection_id, subdir_fd, base_path, - subdir_fd, ".", - ret_all_refs, - cancellable, error)) + if (!enumerate_refs_recurse (self, NULL, flags, current_collection_id, subdir_fd, + base_path, subdir_fd, ".", ret_all_refs, cancellable, error)) return FALSE; } } diff --git a/src/libostree/ostree-repo-static-delta-compilation-analysis.c b/src/libostree/ostree-repo-static-delta-compilation-analysis.c index ee3103d7..a98181c2 100644 --- a/src/libostree/ostree-repo-static-delta-compilation-analysis.c +++ b/src/libostree/ostree-repo-static-delta-compilation-analysis.c @@ -19,17 +19,17 @@ #include "config.h" -#include #include +#include #include "ostree-core-private.h" -#include "ostree-repo-private.h" +#include "ostree-diff.h" #include "ostree-lzma-compressor.h" +#include "ostree-repo-private.h" #include "ostree-repo-static-delta-private.h" -#include "ostree-diff.h" #include "ostree-rollsum.h" -#include "otutil.h" #include "ostree-varint.h" +#include "otutil.h" void _ostree_delta_content_sizenames_free (gpointer v) @@ -41,19 +41,16 @@ _ostree_delta_content_sizenames_free (gpointer v) } static gboolean -build_content_sizenames_recurse (OstreeRepo *repo, - OstreeRepoCommitTraverseIter *iter, - GHashTable *sizenames_map, - GHashTable *include_only_objects, - GCancellable *cancellable, - GError **error) +build_content_sizenames_recurse (OstreeRepo *repo, OstreeRepoCommitTraverseIter *iter, + GHashTable *sizenames_map, GHashTable *include_only_objects, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; while (TRUE) { - OstreeRepoCommitIterResult iterres = - ostree_repo_commit_traverse_iter_next (iter, cancellable, error); + OstreeRepoCommitIterResult iterres + = ostree_repo_commit_traverse_iter_next (iter, cancellable, error); if (iterres == OSTREE_REPO_COMMIT_ITER_RESULT_ERROR) goto out; @@ -73,11 +70,9 @@ build_content_sizenames_recurse (OstreeRepo *repo, csizenames = g_hash_table_lookup (sizenames_map, checksum); if (!csizenames) { - g_autoptr(GFileInfo) finfo = NULL; + g_autoptr (GFileInfo) finfo = NULL; - if (!ostree_repo_load_file (repo, checksum, - NULL, &finfo, NULL, - cancellable, error)) + if (!ostree_repo_load_file (repo, checksum, NULL, &finfo, NULL, cancellable, error)) goto out; if (g_file_info_get_file_type (finfo) != G_FILE_TYPE_REGULAR) @@ -98,24 +93,22 @@ build_content_sizenames_recurse (OstreeRepo *repo, char *name; char *content_checksum; char *meta_checksum; - g_autoptr(GVariant) dirtree = NULL; - ostree_cleanup_repo_commit_traverse_iter - OstreeRepoCommitTraverseIter subiter = { 0, }; + g_autoptr (GVariant) dirtree = NULL; + ostree_cleanup_repo_commit_traverse_iter OstreeRepoCommitTraverseIter subiter = { + 0, + }; ostree_repo_commit_traverse_iter_get_dir (iter, &name, &content_checksum, &meta_checksum); - if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_DIR_TREE, - content_checksum, &dirtree, - error)) + if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_DIR_TREE, content_checksum, + &dirtree, error)) goto out; - if (!ostree_repo_commit_traverse_iter_init_dirtree (&subiter, repo, dirtree, - OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE, - error)) + if (!ostree_repo_commit_traverse_iter_init_dirtree ( + &subiter, repo, dirtree, OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE, error)) goto out; - if (!build_content_sizenames_recurse (repo, &subiter, - sizenames_map, include_only_objects, + if (!build_content_sizenames_recurse (repo, &subiter, sizenames_map, include_only_objects, cancellable, error)) goto out; } @@ -123,16 +116,15 @@ build_content_sizenames_recurse (OstreeRepo *repo, g_assert_not_reached (); } ret = TRUE; - out: +out: return ret; } static int -compare_sizenames (const void *a, - const void *b) +compare_sizenames (const void *a, const void *b) { - OstreeDeltaContentSizeNames *sn_a = *(OstreeDeltaContentSizeNames**)(void*)a; - OstreeDeltaContentSizeNames *sn_b = *(OstreeDeltaContentSizeNames**)(void*)b; + OstreeDeltaContentSizeNames *sn_a = *(OstreeDeltaContentSizeNames **)(void *)a; + OstreeDeltaContentSizeNames *sn_b = *(OstreeDeltaContentSizeNames **)(void *)b; return sn_a->size - sn_b->size; } @@ -142,31 +134,29 @@ compare_sizenames (const void *a, * for regular file content. */ static gboolean -build_content_sizenames_filtered (OstreeRepo *repo, - GVariant *commit, - GHashTable *include_only_objects, - GPtrArray **out_sizenames, - GCancellable *cancellable, - GError **error) +build_content_sizenames_filtered (OstreeRepo *repo, GVariant *commit, + GHashTable *include_only_objects, GPtrArray **out_sizenames, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; - g_autoptr(GPtrArray) ret_sizenames = - g_ptr_array_new_with_free_func (_ostree_delta_content_sizenames_free); - g_autoptr(GHashTable) sizenames_map = - g_hash_table_new_full (g_str_hash, g_str_equal, NULL, _ostree_delta_content_sizenames_free); - ostree_cleanup_repo_commit_traverse_iter - OstreeRepoCommitTraverseIter iter = { 0, }; + g_autoptr (GPtrArray) ret_sizenames + = g_ptr_array_new_with_free_func (_ostree_delta_content_sizenames_free); + g_autoptr (GHashTable) sizenames_map + = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, _ostree_delta_content_sizenames_free); + ostree_cleanup_repo_commit_traverse_iter OstreeRepoCommitTraverseIter iter = { + 0, + }; if (!ostree_repo_commit_traverse_iter_init_commit (&iter, repo, commit, - OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE, - error)) + OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE, error)) goto out; if (!build_content_sizenames_recurse (repo, &iter, sizenames_map, include_only_objects, cancellable, error)) goto out; - { GHashTableIter hashiter; + { + GHashTableIter hashiter; gpointer hkey, hvalue; g_hash_table_iter_init (&hashiter, sizenames_map); @@ -182,14 +172,12 @@ build_content_sizenames_filtered (OstreeRepo *repo, ret = TRUE; if (out_sizenames) *out_sizenames = g_steal_pointer (&ret_sizenames); - out: +out: return ret; } static gboolean -string_array_nonempty_intersection (GPtrArray *a, - GPtrArray *b, - gboolean fuzzy) +string_array_nonempty_intersection (GPtrArray *a, GPtrArray *b, gboolean fuzzy) { guint i; for (i = 0; i < a->len; i++) @@ -238,7 +226,7 @@ sizename_is_delta_candidate (OstreeDeltaContentSizeNames *sizename) const char *dot = strrchr (name, '.'); if (!dot) continue; - const char *extension = dot+1; + const char *extension = dot + 1; /* Don't add .gz here, see above */ if (g_str_equal (extension, "xz") || g_str_equal (extension, "bz2")) return FALSE; @@ -262,31 +250,25 @@ sizename_is_delta_candidate (OstreeDeltaContentSizeNames *sizename) * a cost for each one, then pick the best. */ gboolean -_ostree_delta_compute_similar_objects (OstreeRepo *repo, - GVariant *from_commit, - GVariant *to_commit, - GHashTable *new_reachable_regfile_content, - guint similarity_percent_threshold, - GHashTable **out_modified_regfile_content, - GCancellable *cancellable, - GError **error) +_ostree_delta_compute_similar_objects (OstreeRepo *repo, GVariant *from_commit, GVariant *to_commit, + GHashTable *new_reachable_regfile_content, + guint similarity_percent_threshold, + GHashTable **out_modified_regfile_content, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; - g_autoptr(GHashTable) ret_modified_regfile_content = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - g_autoptr(GPtrArray) from_sizes = NULL; - g_autoptr(GPtrArray) to_sizes = NULL; + g_autoptr (GHashTable) ret_modified_regfile_content + = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + g_autoptr (GPtrArray) from_sizes = NULL; + g_autoptr (GPtrArray) to_sizes = NULL; guint i, j; guint lower; guint upper; - if (!build_content_sizenames_filtered (repo, from_commit, NULL, - &from_sizes, - cancellable, error)) + if (!build_content_sizenames_filtered (repo, from_commit, NULL, &from_sizes, cancellable, error)) goto out; - if (!build_content_sizenames_filtered (repo, to_commit, new_reachable_regfile_content, - &to_sizes, + if (!build_content_sizenames_filtered (repo, to_commit, new_reachable_regfile_content, &to_sizes, cancellable, error)) goto out; @@ -303,10 +285,10 @@ _ostree_delta_compute_similar_objects (OstreeRepo *repo, int fuzzy; gboolean found = FALSE; OstreeDeltaContentSizeNames *to_sizenames = to_sizes->pdata[i]; - const guint64 min_threshold = to_sizenames->size * - (1.0-similarity_percent_threshold/100.0); - const guint64 max_threshold = to_sizenames->size * - (1.0+similarity_percent_threshold/100.0); + const guint64 min_threshold + = to_sizenames->size * (1.0 - similarity_percent_threshold / 100.0); + const guint64 max_threshold + = to_sizenames->size * (1.0 + similarity_percent_threshold / 100.0); if (!sizename_is_delta_candidate (to_sizenames)) continue; @@ -329,15 +311,13 @@ _ostree_delta_compute_similar_objects (OstreeRepo *repo, break; if (!string_array_nonempty_intersection (from_sizenames->basenames, - to_sizenames->basenames, - fuzzy == 1)) + to_sizenames->basenames, fuzzy == 1)) { continue; } /* Only one candidate right now */ - g_hash_table_insert (ret_modified_regfile_content, - g_strdup (to_sizenames->checksum), + g_hash_table_insert (ret_modified_regfile_content, g_strdup (to_sizenames->checksum), g_strdup (from_sizenames->checksum)); found = TRUE; break; @@ -348,6 +328,6 @@ _ostree_delta_compute_similar_objects (OstreeRepo *repo, ret = TRUE; if (out_modified_regfile_content) *out_modified_regfile_content = g_steal_pointer (&ret_modified_regfile_content); - out: +out: return ret; } diff --git a/src/libostree/ostree-repo-static-delta-compilation.c b/src/libostree/ostree-repo-static-delta-compilation.c index 1f536903..4239bc83 100644 --- a/src/libostree/ostree-repo-static-delta-compilation.c +++ b/src/libostree/ostree-repo-static-delta-compilation.c @@ -19,32 +19,34 @@ #include "config.h" +#include #include #include -#include +#include "bsdiff/bsdiff.h" +#include "libglnx.h" +#include "ostree-autocleanups.h" #include "ostree-core-private.h" -#include "ostree-repo-private.h" +#include "ostree-diff.h" #include "ostree-lzma-compressor.h" +#include "ostree-repo-private.h" #include "ostree-repo-static-delta-private.h" -#include "ostree-diff.h" #include "ostree-rollsum.h" -#include "otutil.h" -#include "libglnx.h" -#include "ostree-varint.h" -#include "bsdiff/bsdiff.h" -#include "ostree-autocleanups.h" #include "ostree-sign.h" +#include "ostree-varint.h" +#include "otutil.h" #define CONTENT_SIZE_SIMILARITY_THRESHOLD_PERCENT (30) -typedef enum { +typedef enum +{ DELTAOPT_FLAG_NONE = (1 << 0), DELTAOPT_FLAG_DISABLE_BSDIFF = (1 << 1), DELTAOPT_FLAG_VERBOSE = (1 << 2) } DeltaOpts; -typedef struct { +typedef struct +{ guint64 compressed_size; guint64 uncompressed_size; GPtrArray *objects; @@ -58,7 +60,8 @@ typedef struct { GVariant *header; } OstreeStaticDeltaPartBuilder; -typedef struct { +typedef struct +{ GPtrArray *parts; GPtrArray *fallback_objects; guint64 loose_compressed_size; @@ -76,15 +79,13 @@ typedef struct { /* Get an input stream for a GVariant */ static GInputStream * -variant_to_inputstream (GVariant *variant) +variant_to_inputstream (GVariant *variant) { - GMemoryInputStream *ret = (GMemoryInputStream*) - g_memory_input_stream_new_from_data (g_variant_get_data (variant), - g_variant_get_size (variant), - NULL); - g_object_set_data_full ((GObject*)ret, "ot-variant-data", - g_variant_ref (variant), (GDestroyNotify) g_variant_unref); - return (GInputStream*)ret; + GMemoryInputStream *ret = (GMemoryInputStream *)g_memory_input_stream_new_from_data ( + g_variant_get_data (variant), g_variant_get_size (variant), NULL); + g_object_set_data_full ((GObject *)ret, "ot-variant-data", g_variant_ref (variant), + (GDestroyNotify)g_variant_unref); + return (GInputStream *)ret; } static GBytes * @@ -102,7 +103,7 @@ objtype_checksum_array_new (GPtrArray *objects) guint8 objtype_v; ostree_object_name_deserialize (serialized_key, &checksum, &objtype); - objtype_v = (guint8) objtype; + objtype_v = (guint8)objtype; ostree_checksum_inplace_to_bytes (checksum, csum); @@ -134,7 +135,7 @@ ostree_static_delta_part_builder_unref (OstreeStaticDeltaPartBuilder *part_build static guint mode_chunk_hash (const void *vp) { - GVariant *v = (GVariant*)vp; + GVariant *v = (GVariant *)vp; guint uid, gid, mode; g_variant_get (v, "(uuu)", &uid, &gid, &mode); return uid + gid + mode; @@ -143,8 +144,8 @@ mode_chunk_hash (const void *vp) static gboolean mode_chunk_equals (const void *one, const void *two) { - GVariant *v1 = (GVariant*)one; - GVariant *v2 = (GVariant*)two; + GVariant *v1 = (GVariant *)one; + GVariant *v2 = (GVariant *)two; guint uid1, gid1, mode1; guint uid2, gid2, mode2; @@ -169,20 +170,19 @@ bufhash (const void *b, gsize len) static guint xattr_chunk_hash (const void *vp) { - GVariant *v = (GVariant*)vp; + GVariant *v = (GVariant *)vp; gsize n = g_variant_n_children (v); guint i; guint32 h = 5381; for (i = 0; i < n; i++) { - const guint8* name; - const guint8* value_data; - g_autoptr(GVariant) value = NULL; + const guint8 *name; + const guint8 *value_data; + g_autoptr (GVariant) value = NULL; gsize value_len; - g_variant_get_child (v, i, "(^&ay@ay)", - &name, &value); + g_variant_get_child (v, i, "(^&ay@ay)", &name, &value); value_data = g_variant_get_fixed_array (value, &value_len, 1); h += g_str_hash (name); @@ -195,8 +195,8 @@ xattr_chunk_hash (const void *vp) static gboolean xattr_chunk_equals (const void *one, const void *two) { - GVariant *v1 = (GVariant*)one; - GVariant *v2 = (GVariant*)two; + GVariant *v1 = (GVariant *)one; + GVariant *v2 = (GVariant *)two; gsize l1 = g_variant_get_size (v1); gsize l2 = g_variant_get_size (v2); @@ -214,19 +214,19 @@ finish_part (OstreeStaticDeltaBuilder *builder, GError **error) { OstreeStaticDeltaPartBuilder *part_builder = builder->parts->pdata[builder->parts->len - 1]; g_autofree guchar *part_checksum = NULL; - g_autoptr(GBytes) objtype_checksum_array = NULL; - g_autoptr(GBytes) checksum_bytes = NULL; - g_autoptr(GOutputStream) part_temp_outstream = NULL; - g_autoptr(GInputStream) part_in = NULL; - g_autoptr(GInputStream) part_payload_in = NULL; - g_autoptr(GMemoryOutputStream) part_payload_out = NULL; - g_autoptr(GConverterOutputStream) part_payload_compressor = NULL; - g_autoptr(GConverter) compressor = NULL; - g_autoptr(GVariant) delta_part_content = NULL; - g_autoptr(GVariant) delta_part = NULL; - g_autoptr(GVariant) delta_part_header = NULL; - g_auto(GVariantBuilder) mode_builder = OT_VARIANT_BUILDER_INITIALIZER; - g_auto(GVariantBuilder) xattr_builder = OT_VARIANT_BUILDER_INITIALIZER; + g_autoptr (GBytes) objtype_checksum_array = NULL; + g_autoptr (GBytes) checksum_bytes = NULL; + g_autoptr (GOutputStream) part_temp_outstream = NULL; + g_autoptr (GInputStream) part_in = NULL; + g_autoptr (GInputStream) part_payload_in = NULL; + g_autoptr (GMemoryOutputStream) part_payload_out = NULL; + g_autoptr (GConverterOutputStream) part_payload_compressor = NULL; + g_autoptr (GConverter) compressor = NULL; + g_autoptr (GVariant) delta_part_content = NULL; + g_autoptr (GVariant) delta_part = NULL; + g_autoptr (GVariant) delta_part_header = NULL; + g_auto (GVariantBuilder) mode_builder = OT_VARIANT_BUILDER_INITIALIZER; + g_auto (GVariantBuilder) xattr_builder = OT_VARIANT_BUILDER_INITIALIZER; guint8 compression_type_char; g_variant_builder_init (&mode_builder, G_VARIANT_TYPE ("a(uuu)")); @@ -240,37 +240,39 @@ finish_part (OstreeStaticDeltaBuilder *builder, GError **error) g_variant_builder_add_value (&xattr_builder, part_builder->xattrs->pdata[j]); { - g_autoptr(GBytes) payload_b = g_string_free_to_bytes (g_steal_pointer (&part_builder->payload)); - g_autoptr(GBytes) operations_b = g_string_free_to_bytes (g_steal_pointer (&part_builder->operations)); + g_autoptr (GBytes) payload_b + = g_string_free_to_bytes (g_steal_pointer (&part_builder->payload)); + g_autoptr (GBytes) operations_b + = g_string_free_to_bytes (g_steal_pointer (&part_builder->operations)); - delta_part_content = g_variant_new ("(a(uuu)aa(ayay)@ay@ay)", - &mode_builder, &xattr_builder, + delta_part_content = g_variant_new ("(a(uuu)aa(ayay)@ay@ay)", &mode_builder, &xattr_builder, ot_gvariant_new_ay_bytes (payload_b), ot_gvariant_new_ay_bytes (operations_b)); g_variant_ref_sink (delta_part_content); } /* Hardcode xz for now */ - compressor = (GConverter*)_ostree_lzma_compressor_new (NULL); + compressor = (GConverter *)_ostree_lzma_compressor_new (NULL); compression_type_char = 'x'; part_payload_in = variant_to_inputstream (delta_part_content); - part_payload_out = (GMemoryOutputStream*)g_memory_output_stream_new (NULL, 0, g_realloc, g_free); - part_payload_compressor = (GConverterOutputStream*)g_converter_output_stream_new ((GOutputStream*)part_payload_out, compressor); + part_payload_out = (GMemoryOutputStream *)g_memory_output_stream_new (NULL, 0, g_realloc, g_free); + part_payload_compressor = (GConverterOutputStream *)g_converter_output_stream_new ( + (GOutputStream *)part_payload_out, compressor); { - gssize n_bytes_written = g_output_stream_splice ((GOutputStream*)part_payload_compressor, part_payload_in, - G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET | G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE, - NULL, error); + gssize n_bytes_written = g_output_stream_splice ( + (GOutputStream *)part_payload_compressor, part_payload_in, + G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET | G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE, NULL, error); if (n_bytes_written < 0) return FALSE; } g_clear_pointer (&delta_part_content, g_variant_unref); - { g_autoptr(GBytes) payload = g_memory_output_stream_steal_as_bytes (part_payload_out); - delta_part = g_variant_ref_sink (g_variant_new ("(y@ay)", - compression_type_char, - ot_gvariant_new_ay_bytes (payload))); + { + g_autoptr (GBytes) payload = g_memory_output_stream_steal_as_bytes (part_payload_out); + delta_part = g_variant_ref_sink ( + g_variant_new ("(y@ay)", compression_type_char, ot_gvariant_new_ay_bytes (payload))); } if (!glnx_open_tmpfile_linkable_at (builder->parts_dfd, ".", O_RDWR | O_CLOEXEC, @@ -280,19 +282,17 @@ finish_part (OstreeStaticDeltaBuilder *builder, GError **error) part_temp_outstream = g_unix_output_stream_new (part_builder->part_tmpf.fd, FALSE); part_in = variant_to_inputstream (delta_part); - if (!ot_gio_splice_get_checksum (part_temp_outstream, part_in, - &part_checksum, - NULL, error)) + if (!ot_gio_splice_get_checksum (part_temp_outstream, part_in, &part_checksum, NULL, error)) return FALSE; checksum_bytes = g_bytes_new (part_checksum, OSTREE_SHA256_DIGEST_LEN); objtype_checksum_array = objtype_checksum_array_new (part_builder->objects); - delta_part_header = g_variant_new ("(u@aytt@ay)", - maybe_swap_endian_u32 (builder->swap_endian, OSTREE_DELTAPART_VERSION), - ot_gvariant_new_ay_bytes (checksum_bytes), - maybe_swap_endian_u64 (builder->swap_endian, (guint64) g_variant_get_size (delta_part)), - maybe_swap_endian_u64 (builder->swap_endian, part_builder->uncompressed_size), - ot_gvariant_new_ay_bytes (objtype_checksum_array)); + delta_part_header = g_variant_new ( + "(u@aytt@ay)", maybe_swap_endian_u32 (builder->swap_endian, OSTREE_DELTAPART_VERSION), + ot_gvariant_new_ay_bytes (checksum_bytes), + maybe_swap_endian_u64 (builder->swap_endian, (guint64)g_variant_get_size (delta_part)), + maybe_swap_endian_u64 (builder->swap_endian, part_builder->uncompressed_size), + ot_gvariant_new_ay_bytes (objtype_checksum_array)); g_variant_ref_sink (delta_part_header); part_builder->header = g_variant_ref (delta_part_header); @@ -300,9 +300,9 @@ finish_part (OstreeStaticDeltaBuilder *builder, GError **error) if (builder->delta_opts & DELTAOPT_FLAG_VERBOSE) { - g_printerr ("part %u n:%u compressed:%" G_GUINT64_FORMAT " uncompressed:%" G_GUINT64_FORMAT "\n", - builder->parts->len, part_builder->objects->len, - part_builder->compressed_size, + g_printerr ("part %u n:%u compressed:%" G_GUINT64_FORMAT " uncompressed:%" G_GUINT64_FORMAT + "\n", + builder->parts->len, part_builder->objects->len, part_builder->compressed_size, part_builder->uncompressed_size); } @@ -334,8 +334,7 @@ allocate_part (OstreeStaticDeltaBuilder *builder, GError **error) } static gsize -allocate_part_buffer_space (OstreeStaticDeltaPartBuilder *current_part, - guint len) +allocate_part_buffer_space (OstreeStaticDeltaPartBuilder *current_part, guint len) { gsize empty_space; gsize old_len; @@ -347,7 +346,8 @@ allocate_part_buffer_space (OstreeStaticDeltaPartBuilder *current_part, { gsize origlen; origlen = current_part->payload->len; - g_string_set_size (current_part->payload, current_part->payload->allocated_len + (len - empty_space)); + g_string_set_size (current_part->payload, + current_part->payload->allocated_len + (len - empty_space)); current_part->payload->len = origlen; } @@ -355,10 +355,8 @@ allocate_part_buffer_space (OstreeStaticDeltaPartBuilder *current_part, } static gsize -write_unique_variant_chunk (OstreeStaticDeltaPartBuilder *current_part, - GHashTable *hash, - GPtrArray *ordered, - GVariant *key) +write_unique_variant_chunk (OstreeStaticDeltaPartBuilder *current_part, GHashTable *hash, + GPtrArray *ordered, GVariant *key) { gpointer target_offsetp; gsize offset; @@ -375,10 +373,8 @@ write_unique_variant_chunk (OstreeStaticDeltaPartBuilder *current_part, } static gboolean -splice_stream_to_payload (OstreeStaticDeltaPartBuilder *current_part, - GInputStream *istream, - GCancellable *cancellable, - GError **error) +splice_stream_to_payload (OstreeStaticDeltaPartBuilder *current_part, GInputStream *istream, + GCancellable *cancellable, GError **error) { while (TRUE) { @@ -388,9 +384,7 @@ splice_stream_to_payload (OstreeStaticDeltaPartBuilder *current_part, gsize bytes_read; if (!g_input_stream_read_all (istream, current_part->payload->str + current_part->payload->len, - readlen, - &bytes_read, - cancellable, error)) + readlen, &bytes_read, cancellable, error)) return FALSE; if (bytes_read == 0) break; @@ -402,69 +396,50 @@ splice_stream_to_payload (OstreeStaticDeltaPartBuilder *current_part, } static void -write_content_mode_xattrs (OstreeRepo *repo, - OstreeStaticDeltaPartBuilder *current_part, - GFileInfo *content_finfo, - GVariant *content_xattrs, - gsize *out_mode_offset, - gsize *out_xattr_offset) +write_content_mode_xattrs (OstreeRepo *repo, OstreeStaticDeltaPartBuilder *current_part, + GFileInfo *content_finfo, GVariant *content_xattrs, + gsize *out_mode_offset, gsize *out_xattr_offset) { - guint32 uid = - g_file_info_get_attribute_uint32 (content_finfo, "unix::uid"); - guint32 gid = - g_file_info_get_attribute_uint32 (content_finfo, "unix::gid"); - guint32 mode = - g_file_info_get_attribute_uint32 (content_finfo, "unix::mode"); - g_autoptr(GVariant) modev - = g_variant_ref_sink (g_variant_new ("(uuu)", - GUINT32_TO_BE (uid), - GUINT32_TO_BE (gid), - GUINT32_TO_BE (mode))); - - *out_mode_offset = write_unique_variant_chunk (current_part, - current_part->mode_set, - current_part->modes, - modev); - *out_xattr_offset = write_unique_variant_chunk (current_part, - current_part->xattr_set, - current_part->xattrs, - content_xattrs); + guint32 uid = g_file_info_get_attribute_uint32 (content_finfo, "unix::uid"); + guint32 gid = g_file_info_get_attribute_uint32 (content_finfo, "unix::gid"); + guint32 mode = g_file_info_get_attribute_uint32 (content_finfo, "unix::mode"); + g_autoptr (GVariant) modev = g_variant_ref_sink ( + g_variant_new ("(uuu)", GUINT32_TO_BE (uid), GUINT32_TO_BE (gid), GUINT32_TO_BE (mode))); + + *out_mode_offset = write_unique_variant_chunk (current_part, current_part->mode_set, + current_part->modes, modev); + *out_xattr_offset = write_unique_variant_chunk (current_part, current_part->xattr_set, + current_part->xattrs, content_xattrs); } static gboolean -process_one_object (OstreeRepo *repo, - OstreeStaticDeltaBuilder *builder, - OstreeStaticDeltaPartBuilder **current_part_val, - const char *checksum, - OstreeObjectType objtype, - GCancellable *cancellable, - GError **error) +process_one_object (OstreeRepo *repo, OstreeStaticDeltaBuilder *builder, + OstreeStaticDeltaPartBuilder **current_part_val, const char *checksum, + OstreeObjectType objtype, GCancellable *cancellable, GError **error) { OstreeStaticDeltaPartBuilder *current_part = *current_part_val; - g_autoptr(GFileInfo) content_finfo = NULL; - g_autoptr(GVariant) content_xattrs = NULL; + g_autoptr (GFileInfo) content_finfo = NULL; + g_autoptr (GVariant) content_xattrs = NULL; guint64 content_size; - g_autoptr(GInputStream) content_stream = NULL; + g_autoptr (GInputStream) content_stream = NULL; if (OSTREE_OBJECT_TYPE_IS_META (objtype)) { - if (!ostree_repo_load_object_stream (repo, objtype, checksum, - &content_stream, &content_size, + if (!ostree_repo_load_object_stream (repo, objtype, checksum, &content_stream, &content_size, cancellable, error)) return FALSE; } else { - if (!ostree_repo_load_file (repo, checksum, &content_stream, - &content_finfo, &content_xattrs, + if (!ostree_repo_load_file (repo, checksum, &content_stream, &content_finfo, &content_xattrs, cancellable, error)) return FALSE; content_size = g_file_info_get_size (content_finfo); } /* Check to see if this delta is maximum size */ - if (current_part->objects->len > 0 && - current_part->payload->len + content_size > builder->max_chunk_size_bytes) + if (current_part->objects->len > 0 + && current_part->payload->len + content_size > builder->max_chunk_size_bytes) { current_part = allocate_part (builder, error); if (current_part == NULL) @@ -473,8 +448,7 @@ process_one_object (OstreeRepo *repo, } guint64 compressed_size; - if (!ostree_repo_query_object_storage_size (repo, objtype, checksum, - &compressed_size, + if (!ostree_repo_query_object_storage_size (repo, objtype, checksum, &compressed_size, cancellable, error)) return FALSE; builder->loose_compressed_size += compressed_size; @@ -489,11 +463,11 @@ process_one_object (OstreeRepo *repo, object_payload_start = current_part->payload->len; - if (!splice_stream_to_payload (current_part, content_stream, - cancellable, error)) + if (!splice_stream_to_payload (current_part, content_stream, cancellable, error)) return FALSE; - g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_OPEN_SPLICE_AND_CLOSE); + g_string_append_c (current_part->operations, + (gchar)OSTREE_STATIC_DELTA_OP_OPEN_SPLICE_AND_CLOSE); _ostree_write_varuint64 (current_part->operations, content_size); _ostree_write_varuint64 (current_part->operations, object_payload_start); } @@ -502,15 +476,14 @@ process_one_object (OstreeRepo *repo, gsize mode_offset, xattr_offset, content_offset; guint32 mode = g_file_info_get_attribute_uint32 (content_finfo, "unix::mode"); - write_content_mode_xattrs (repo, current_part, content_finfo, content_xattrs, - &mode_offset, &xattr_offset); + write_content_mode_xattrs (repo, current_part, content_finfo, content_xattrs, &mode_offset, + &xattr_offset); if (S_ISLNK (mode)) { g_assert (content_stream == NULL); const char *target = g_file_info_get_symlink_target (content_finfo); - content_stream = - g_memory_input_stream_new_from_data (target, strlen (target), NULL); + content_stream = g_memory_input_stream_new_from_data (target, strlen (target), NULL); content_size = strlen (target); } else @@ -519,11 +492,11 @@ process_one_object (OstreeRepo *repo, } content_offset = current_part->payload->len; - if (!splice_stream_to_payload (current_part, content_stream, - cancellable, error)) + if (!splice_stream_to_payload (current_part, content_stream, cancellable, error)) return FALSE; - g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_OPEN_SPLICE_AND_CLOSE); + g_string_append_c (current_part->operations, + (gchar)OSTREE_STATIC_DELTA_OP_OPEN_SPLICE_AND_CLOSE); _ostree_write_varuint64 (current_part->operations, mode_offset); _ostree_write_varuint64 (current_part->operations, xattr_offset); _ostree_write_varuint64 (current_part->operations, content_size); @@ -533,17 +506,19 @@ process_one_object (OstreeRepo *repo, return TRUE; } -typedef struct { +typedef struct +{ char *from_checksum; } ContentBsdiff; -typedef struct { +typedef struct +{ char *from_checksum; OstreeRollsumMatches *matches; } ContentRollsum; static void -content_rollsums_free (ContentRollsum *rollsum) +content_rollsums_free (ContentRollsum *rollsum) { g_free (rollsum->from_checksum); _ostree_rollsum_matches_free (rollsum->matches); @@ -551,7 +526,7 @@ content_rollsums_free (ContentRollsum *rollsum) } static void -content_bsdiffs_free (ContentBsdiff *bsdiff) +content_bsdiffs_free (ContentBsdiff *bsdiff) { g_free (bsdiff->from_checksum); g_free (bsdiff); @@ -561,16 +536,12 @@ content_bsdiffs_free (ContentBsdiff *bsdiff) that's mmap()'d and suitable for seeking. */ static gboolean -get_unpacked_unlinked_content (OstreeRepo *repo, - const char *checksum, - GBytes **out_content, - GCancellable *cancellable, - GError **error) +get_unpacked_unlinked_content (OstreeRepo *repo, const char *checksum, GBytes **out_content, + GCancellable *cancellable, GError **error) { - g_autoptr(GInputStream) istream = NULL; + g_autoptr (GInputStream) istream = NULL; - if (!ostree_repo_load_file (repo, checksum, &istream, NULL, NULL, - cancellable, error)) + if (!ostree_repo_load_file (repo, checksum, &istream, NULL, NULL, cancellable, error)) return FALSE; *out_content = ot_map_anonymous_tmpfile_from_content (istream, cancellable, error); @@ -580,23 +551,15 @@ get_unpacked_unlinked_content (OstreeRepo *repo, } static gboolean -try_content_bsdiff (OstreeRepo *repo, - const char *from, - const char *to, - ContentBsdiff **out_bsdiff, - guint64 max_bsdiff_size_bytes, - GCancellable *cancellable, - GError **error) +try_content_bsdiff (OstreeRepo *repo, const char *from, const char *to, ContentBsdiff **out_bsdiff, + guint64 max_bsdiff_size_bytes, GCancellable *cancellable, GError **error) { - - g_autoptr(GFileInfo) from_finfo = NULL; - if (!ostree_repo_load_file (repo, from, NULL, &from_finfo, NULL, - cancellable, error)) + g_autoptr (GFileInfo) from_finfo = NULL; + if (!ostree_repo_load_file (repo, from, NULL, &from_finfo, NULL, cancellable, error)) return FALSE; - g_autoptr(GFileInfo) to_finfo = NULL; - if (!ostree_repo_load_file (repo, to, NULL, &to_finfo, NULL, - cancellable, error)) + g_autoptr (GFileInfo) to_finfo = NULL; + if (!ostree_repo_load_file (repo, to, NULL, &to_finfo, NULL, cancellable, error)) return FALSE; *out_bsdiff = NULL; @@ -613,29 +576,24 @@ try_content_bsdiff (OstreeRepo *repo, } static gboolean -try_content_rollsum (OstreeRepo *repo, - DeltaOpts opts, - const char *from, - const char *to, - ContentRollsum **out_rollsum, - GCancellable *cancellable, - GError **error) +try_content_rollsum (OstreeRepo *repo, DeltaOpts opts, const char *from, const char *to, + ContentRollsum **out_rollsum, GCancellable *cancellable, GError **error) { *out_rollsum = NULL; /* Load the content objects, splice them to uncompressed temporary files that * we can just mmap() and seek around in conveniently. */ - g_autoptr(GBytes) tmp_from = NULL; + g_autoptr (GBytes) tmp_from = NULL; if (!get_unpacked_unlinked_content (repo, from, &tmp_from, cancellable, error)) return FALSE; - g_autoptr(GBytes) tmp_to = NULL; + g_autoptr (GBytes) tmp_to = NULL; if (!get_unpacked_unlinked_content (repo, to, &tmp_to, cancellable, error)) return FALSE; - g_autoptr(OstreeRollsumMatches) matches = _ostree_compute_rollsum_matches (tmp_from, tmp_to); + g_autoptr (OstreeRollsumMatches) matches = _ostree_compute_rollsum_matches (tmp_from, tmp_to); - const guint match_ratio = (matches->bufmatches*100)/matches->total; + const guint match_ratio = (matches->bufmatches * 100) / matches->total; /* Only proceed if the file contains (arbitrary) more than 50% of * the previous chunks. @@ -645,10 +603,9 @@ try_content_rollsum (OstreeRepo *repo, if (opts & DELTAOPT_FLAG_VERBOSE) { - g_printerr ("rollsum for %s -> %s; crcs=%u bufs=%u total=%u matchsize=%llu\n", - from, to, matches->crcmatches, - matches->bufmatches, - matches->total, (unsigned long long)matches->match_size); + g_printerr ("rollsum for %s -> %s; crcs=%u bufs=%u total=%u matchsize=%llu\n", from, to, + matches->crcmatches, matches->bufmatches, matches->total, + (unsigned long long)matches->match_size); } ContentRollsum *ret_rollsum = g_new0 (ContentRollsum, 1); @@ -666,47 +623,37 @@ struct bzdiff_opaque_s }; static int -bzdiff_write (struct bsdiff_stream* stream, const void* buffer, int size) +bzdiff_write (struct bsdiff_stream *stream, const void *buffer, int size) { struct bzdiff_opaque_s *op = stream->opaque; - if (!g_output_stream_write (op->out, - buffer, - size, - op->cancellable, - op->error)) + if (!g_output_stream_write (op->out, buffer, size, op->cancellable, op->error)) return -1; return 0; } static void -append_payload_chunk_and_write (OstreeStaticDeltaPartBuilder *current_part, - const guint8 *buf, - guint64 offset) +append_payload_chunk_and_write (OstreeStaticDeltaPartBuilder *current_part, const guint8 *buf, + guint64 offset) { guint64 payload_start; payload_start = current_part->payload->len; - g_string_append_len (current_part->payload, (char*)buf, offset); + g_string_append_len (current_part->payload, (char *)buf, offset); g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_WRITE); _ostree_write_varuint64 (current_part->operations, offset); _ostree_write_varuint64 (current_part->operations, payload_start); } static gboolean -process_one_rollsum (OstreeRepo *repo, - OstreeStaticDeltaBuilder *builder, - OstreeStaticDeltaPartBuilder **current_part_val, - const char *to_checksum, - ContentRollsum *rollsum, - GCancellable *cancellable, - GError **error) +process_one_rollsum (OstreeRepo *repo, OstreeStaticDeltaBuilder *builder, + OstreeStaticDeltaPartBuilder **current_part_val, const char *to_checksum, + ContentRollsum *rollsum, GCancellable *cancellable, GError **error) { OstreeStaticDeltaPartBuilder *current_part = *current_part_val; /* Check to see if this delta has gone over maximum size */ - if (current_part->objects->len > 0 && - current_part->payload->len > builder->max_chunk_size_bytes) + if (current_part->objects->len > 0 && current_part->payload->len > builder->max_chunk_size_bytes) { current_part = allocate_part (builder, error); if (current_part == NULL) @@ -714,46 +661,47 @@ process_one_rollsum (OstreeRepo *repo, *current_part_val = current_part; } - g_autoptr(GBytes) tmp_to = NULL; - if (!get_unpacked_unlinked_content (repo, to_checksum, &tmp_to, - cancellable, error)) + g_autoptr (GBytes) tmp_to = NULL; + if (!get_unpacked_unlinked_content (repo, to_checksum, &tmp_to, cancellable, error)) return FALSE; gsize tmp_to_len; const guint8 *tmp_to_buf = g_bytes_get_data (tmp_to, &tmp_to_len); - g_autoptr(GFileInfo) content_finfo = NULL; - g_autoptr(GVariant) content_xattrs = NULL; - if (!ostree_repo_load_file (repo, to_checksum, NULL, - &content_finfo, &content_xattrs, - cancellable, error)) + g_autoptr (GFileInfo) content_finfo = NULL; + g_autoptr (GVariant) content_xattrs = NULL; + if (!ostree_repo_load_file (repo, to_checksum, NULL, &content_finfo, &content_xattrs, cancellable, + error)) return FALSE; guint64 content_size = g_file_info_get_size (content_finfo); g_assert_cmpint (tmp_to_len, ==, content_size); current_part->uncompressed_size += content_size; - g_ptr_array_add (current_part->objects, ostree_object_name_serialize (to_checksum, OSTREE_OBJECT_TYPE_FILE)); + g_ptr_array_add (current_part->objects, + ostree_object_name_serialize (to_checksum, OSTREE_OBJECT_TYPE_FILE)); - { gsize mode_offset, xattr_offset, from_csum_offset; + { + gsize mode_offset, xattr_offset, from_csum_offset; gboolean reading_payload = TRUE; guchar source_csum[OSTREE_SHA256_DIGEST_LEN]; guint i; - write_content_mode_xattrs (repo, current_part, content_finfo, content_xattrs, - &mode_offset, &xattr_offset); + write_content_mode_xattrs (repo, current_part, content_finfo, content_xattrs, &mode_offset, + &xattr_offset); /* Write the origin checksum */ ostree_checksum_inplace_to_bytes (rollsum->from_checksum, source_csum); from_csum_offset = current_part->payload->len; - g_string_append_len (current_part->payload, (char*)source_csum, sizeof (source_csum)); + g_string_append_len (current_part->payload, (char *)source_csum, sizeof (source_csum)); g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_OPEN); _ostree_write_varuint64 (current_part->operations, mode_offset); _ostree_write_varuint64 (current_part->operations, xattr_offset); _ostree_write_varuint64 (current_part->operations, content_size); - { guint64 writing_offset = 0; + { + guint64 writing_offset = 0; guint64 offset = 0, to_start = 0, from_start = 0; GPtrArray *matchlist = rollsum->matches->matches; @@ -771,7 +719,8 @@ process_one_rollsum (OstreeRepo *repo, { if (!reading_payload) { - g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_UNSET_READ_SOURCE); + g_string_append_c (current_part->operations, + (gchar)OSTREE_STATIC_DELTA_OP_UNSET_READ_SOURCE); reading_payload = TRUE; } @@ -782,7 +731,8 @@ process_one_rollsum (OstreeRepo *repo, if (reading_payload) { - g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_SET_READ_SOURCE); + g_string_append_c (current_part->operations, + (gchar)OSTREE_STATIC_DELTA_OP_SET_READ_SOURCE); _ostree_write_varuint64 (current_part->operations, from_csum_offset); reading_payload = FALSE; } @@ -794,7 +744,8 @@ process_one_rollsum (OstreeRepo *repo, } if (!reading_payload) - g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_UNSET_READ_SOURCE); + g_string_append_c (current_part->operations, + (gchar)OSTREE_STATIC_DELTA_OP_UNSET_READ_SOURCE); const guint64 remainder = tmp_to_len - writing_offset; if (remainder > 0) @@ -804,7 +755,6 @@ process_one_rollsum (OstreeRepo *repo, g_assert_cmpint (writing_offset, ==, content_size); } - g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_CLOSE); } @@ -812,19 +762,14 @@ process_one_rollsum (OstreeRepo *repo, } static gboolean -process_one_bsdiff (OstreeRepo *repo, - OstreeStaticDeltaBuilder *builder, - OstreeStaticDeltaPartBuilder **current_part_val, - const char *to_checksum, - ContentBsdiff *bsdiff_content, - GCancellable *cancellable, - GError **error) +process_one_bsdiff (OstreeRepo *repo, OstreeStaticDeltaBuilder *builder, + OstreeStaticDeltaPartBuilder **current_part_val, const char *to_checksum, + ContentBsdiff *bsdiff_content, GCancellable *cancellable, GError **error) { OstreeStaticDeltaPartBuilder *current_part = *current_part_val; /* Check to see if this delta has gone over maximum size */ - if (current_part->objects->len > 0 && - current_part->payload->len > builder->max_chunk_size_bytes) + if (current_part->objects->len > 0 && current_part->payload->len > builder->max_chunk_size_bytes) { current_part = allocate_part (builder, error); if (current_part == NULL) @@ -832,13 +777,12 @@ process_one_bsdiff (OstreeRepo *repo, *current_part_val = current_part; } - g_autoptr(GBytes) tmp_from = NULL; - if (!get_unpacked_unlinked_content (repo, bsdiff_content->from_checksum, &tmp_from, - cancellable, error)) + g_autoptr (GBytes) tmp_from = NULL; + if (!get_unpacked_unlinked_content (repo, bsdiff_content->from_checksum, &tmp_from, cancellable, + error)) return FALSE; - g_autoptr(GBytes) tmp_to = NULL; - if (!get_unpacked_unlinked_content (repo, to_checksum, &tmp_to, - cancellable, error)) + g_autoptr (GBytes) tmp_to = NULL; + if (!get_unpacked_unlinked_content (repo, to_checksum, &tmp_to, cancellable, error)) return FALSE; gsize tmp_to_len; @@ -846,31 +790,32 @@ process_one_bsdiff (OstreeRepo *repo, gsize tmp_from_len; const guint8 *tmp_from_buf = g_bytes_get_data (tmp_from, &tmp_from_len); - g_autoptr(GFileInfo) content_finfo = NULL; - g_autoptr(GVariant) content_xattrs = NULL; - if (!ostree_repo_load_file (repo, to_checksum, NULL, - &content_finfo, &content_xattrs, - cancellable, error)) + g_autoptr (GFileInfo) content_finfo = NULL; + g_autoptr (GVariant) content_xattrs = NULL; + if (!ostree_repo_load_file (repo, to_checksum, NULL, &content_finfo, &content_xattrs, cancellable, + error)) return FALSE; const guint64 content_size = g_file_info_get_size (content_finfo); g_assert_cmpint (tmp_to_len, ==, content_size); current_part->uncompressed_size += content_size; - g_ptr_array_add (current_part->objects, ostree_object_name_serialize (to_checksum, OSTREE_OBJECT_TYPE_FILE)); + g_ptr_array_add (current_part->objects, + ostree_object_name_serialize (to_checksum, OSTREE_OBJECT_TYPE_FILE)); - { gsize mode_offset, xattr_offset; + { + gsize mode_offset, xattr_offset; guchar source_csum[OSTREE_SHA256_DIGEST_LEN]; - write_content_mode_xattrs (repo, current_part, content_finfo, content_xattrs, - &mode_offset, &xattr_offset); + write_content_mode_xattrs (repo, current_part, content_finfo, content_xattrs, &mode_offset, + &xattr_offset); /* Write the origin checksum */ ostree_checksum_inplace_to_bytes (bsdiff_content->from_checksum, source_csum); g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_SET_READ_SOURCE); _ostree_write_varuint64 (current_part->operations, current_part->payload->len); - g_string_append_len (current_part->payload, (char*)source_csum, sizeof (source_csum)); + g_string_append_len (current_part->payload, (char *)source_csum, sizeof (source_csum)); g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_OPEN); _ostree_write_varuint64 (current_part->operations, mode_offset); @@ -882,7 +827,7 @@ process_one_bsdiff (OstreeRepo *repo, struct bzdiff_opaque_s op; const gchar *payload; gssize payload_size; - g_autoptr(GOutputStream) out = g_memory_output_stream_new_resizable (); + g_autoptr (GOutputStream) out = g_memory_output_stream_new_resizable (); stream.malloc = malloc; stream.free = free; stream.write = bzdiff_write; @@ -925,17 +870,13 @@ process_one_bsdiff (OstreeRepo *repo, } static gboolean -check_object_world_readable (OstreeRepo *repo, - const char *checksum, - gboolean *out_readable, - GCancellable *cancellable, - GError **error) +check_object_world_readable (OstreeRepo *repo, const char *checksum, gboolean *out_readable, + GCancellable *cancellable, GError **error) { - g_autoptr(GFileInfo) finfo = NULL; + g_autoptr (GFileInfo) finfo = NULL; guint32 mode; - if (!ostree_repo_load_file (repo, checksum, NULL, &finfo, NULL, - cancellable, error)) + if (!ostree_repo_load_file (repo, checksum, NULL, &finfo, NULL, cancellable, error)) return FALSE; mode = g_file_info_get_attribute_uint32 (finfo, "unix::mode"); @@ -944,54 +885,44 @@ check_object_world_readable (OstreeRepo *repo, } static gboolean -generate_delta_lowlatency (OstreeRepo *repo, - const char *from, - const char *to, - DeltaOpts opts, - OstreeStaticDeltaBuilder *builder, - GCancellable *cancellable, - GError **error) +generate_delta_lowlatency (OstreeRepo *repo, const char *from, const char *to, DeltaOpts opts, + OstreeStaticDeltaBuilder *builder, GCancellable *cancellable, + GError **error) { GHashTableIter hashiter; gpointer key, value; OstreeStaticDeltaPartBuilder *current_part = NULL; - g_autoptr(GFile) root_from = NULL; - g_autoptr(GVariant) from_commit = NULL; - g_autoptr(GFile) root_to = NULL; - g_autoptr(GVariant) to_commit = NULL; - g_autoptr(GHashTable) to_reachable_objects = NULL; - g_autoptr(GHashTable) from_reachable_objects = NULL; - g_autoptr(GHashTable) new_reachable_metadata = NULL; - g_autoptr(GHashTable) new_reachable_regfile_content = NULL; - g_autoptr(GHashTable) new_reachable_symlink_content = NULL; - g_autoptr(GHashTable) modified_regfile_content = NULL; - g_autoptr(GHashTable) rollsum_optimized_content_objects = NULL; - g_autoptr(GHashTable) bsdiff_optimized_content_objects = NULL; + g_autoptr (GFile) root_from = NULL; + g_autoptr (GVariant) from_commit = NULL; + g_autoptr (GFile) root_to = NULL; + g_autoptr (GVariant) to_commit = NULL; + g_autoptr (GHashTable) to_reachable_objects = NULL; + g_autoptr (GHashTable) from_reachable_objects = NULL; + g_autoptr (GHashTable) new_reachable_metadata = NULL; + g_autoptr (GHashTable) new_reachable_regfile_content = NULL; + g_autoptr (GHashTable) new_reachable_symlink_content = NULL; + g_autoptr (GHashTable) modified_regfile_content = NULL; + g_autoptr (GHashTable) rollsum_optimized_content_objects = NULL; + g_autoptr (GHashTable) bsdiff_optimized_content_objects = NULL; if (from != NULL) { - if (!ostree_repo_read_commit (repo, from, &root_from, NULL, - cancellable, error)) + if (!ostree_repo_read_commit (repo, from, &root_from, NULL, cancellable, error)) return FALSE; - if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, from, - &from_commit, error)) + if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, from, &from_commit, error)) return FALSE; - if (!ostree_repo_traverse_commit (repo, from, 0, &from_reachable_objects, - cancellable, error)) + if (!ostree_repo_traverse_commit (repo, from, 0, &from_reachable_objects, cancellable, error)) return FALSE; } - if (!ostree_repo_read_commit (repo, to, &root_to, NULL, - cancellable, error)) + if (!ostree_repo_read_commit (repo, to, &root_to, NULL, cancellable, error)) return FALSE; - if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, to, - &to_commit, error)) + if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, to, &to_commit, error)) return FALSE; - if (!ostree_repo_traverse_commit (repo, to, 0, &to_reachable_objects, - cancellable, error)) + if (!ostree_repo_traverse_commit (repo, to, 0, &to_reachable_objects, cancellable, error)) return FALSE; new_reachable_metadata = ostree_repo_traverse_new_reachable (); @@ -1014,11 +945,10 @@ generate_delta_lowlatency (OstreeRepo *repo, g_hash_table_add (new_reachable_metadata, g_variant_ref (serialized_key)); else { - g_autoptr(GFileInfo) finfo = NULL; + g_autoptr (GFileInfo) finfo = NULL; GFileType ftype; - if (!ostree_repo_load_file (repo, checksum, NULL, &finfo, NULL, - cancellable, error)) + if (!ostree_repo_load_file (repo, checksum, NULL, &finfo, NULL, cancellable, error)) return FALSE; ftype = g_file_info_get_file_type (finfo); @@ -1036,8 +966,7 @@ generate_delta_lowlatency (OstreeRepo *repo, if (!_ostree_delta_compute_similar_objects (repo, from_commit, to_commit, new_reachable_regfile_content, CONTENT_SIZE_SIMILARITY_THRESHOLD_PERCENT, - &modified_regfile_content, - cancellable, error)) + &modified_regfile_content, cancellable, error)) return FALSE; } else @@ -1053,17 +982,16 @@ generate_delta_lowlatency (OstreeRepo *repo, } /* We already ship the to commit in the superblock, don't ship it twice */ - { g_autoptr(GVariant) commit = ostree_object_name_serialize (to, OSTREE_OBJECT_TYPE_COMMIT); + { + g_autoptr (GVariant) commit = ostree_object_name_serialize (to, OSTREE_OBJECT_TYPE_COMMIT); g_hash_table_remove (new_reachable_metadata, commit); } - rollsum_optimized_content_objects = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, - (GDestroyNotify) content_rollsums_free); + rollsum_optimized_content_objects = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, + (GDestroyNotify)content_rollsums_free); - bsdiff_optimized_content_objects = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, - (GDestroyNotify) content_bsdiffs_free); + bsdiff_optimized_content_objects = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, + (GDestroyNotify)content_bsdiffs_free); g_hash_table_iter_init (&hashiter, modified_regfile_content); while (g_hash_table_iter_next (&hashiter, &key, &value)) @@ -1080,13 +1008,14 @@ generate_delta_lowlatency (OstreeRepo *repo, * when the client is trying to update a bare-user repository with a * bare repository defined as its parent. */ - if (!check_object_world_readable (repo, from_checksum, &from_world_readable, cancellable, error)) + if (!check_object_world_readable (repo, from_checksum, &from_world_readable, cancellable, + error)) return FALSE; if (!from_world_readable) continue; - if (!try_content_rollsum (repo, opts, from_checksum, to_checksum, - &rollsum, cancellable, error)) + if (!try_content_rollsum (repo, opts, from_checksum, to_checksum, &rollsum, cancellable, + error)) return FALSE; if (rollsum) @@ -1098,9 +1027,8 @@ generate_delta_lowlatency (OstreeRepo *repo, if (!(opts & DELTAOPT_FLAG_DISABLE_BSDIFF)) { - if (!try_content_bsdiff (repo, from_checksum, to_checksum, - &bsdiff, builder->max_bsdiff_size_bytes, - cancellable, error)) + if (!try_content_bsdiff (repo, from_checksum, to_checksum, &bsdiff, + builder->max_bsdiff_size_bytes, cancellable, error)) return FALSE; if (bsdiff) @@ -1129,9 +1057,7 @@ generate_delta_lowlatency (OstreeRepo *repo, ostree_object_name_deserialize (serialized_key, &checksum, &objtype); - if (!process_one_object (repo, builder, ¤t_part, - checksum, objtype, - cancellable, error)) + if (!process_one_object (repo, builder, ¤t_part, checksum, objtype, cancellable, error)) return FALSE; } @@ -1143,9 +1069,8 @@ generate_delta_lowlatency (OstreeRepo *repo, const char *checksum = key; ContentRollsum *rollsum = value; - if (!process_one_rollsum (repo, builder, ¤t_part, - checksum, rollsum, - cancellable, error)) + if (!process_one_rollsum (repo, builder, ¤t_part, checksum, rollsum, cancellable, + error)) return FALSE; builder->n_rollsum++; @@ -1163,13 +1088,11 @@ generate_delta_lowlatency (OstreeRepo *repo, const char *checksum = key; ContentBsdiff *bsdiff = value; - if (opts & DELTAOPT_FLAG_VERBOSE && - (mod == 0 || builder->n_bsdiff % mod == 0)) + if (opts & DELTAOPT_FLAG_VERBOSE && (mod == 0 || builder->n_bsdiff % mod == 0)) g_printerr ("processing bsdiff: [%u/%u]\n", builder->n_bsdiff, n_bsdiff); - if (!process_one_bsdiff (repo, builder, ¤t_part, - checksum, bsdiff, - cancellable, error)) + if (!process_one_bsdiff (repo, builder, ¤t_part, checksum, bsdiff, cancellable, + error)) return FALSE; builder->n_bsdiff++; @@ -1187,16 +1110,15 @@ generate_delta_lowlatency (OstreeRepo *repo, gboolean fallback = FALSE; /* Skip content objects we rollsum'd or bsdiff'ed */ - if (g_hash_table_contains (rollsum_optimized_content_objects, checksum) || - g_hash_table_contains (bsdiff_optimized_content_objects, checksum)) + if (g_hash_table_contains (rollsum_optimized_content_objects, checksum) + || g_hash_table_contains (bsdiff_optimized_content_objects, checksum)) continue; - if (!ostree_repo_load_object_stream (repo, OSTREE_OBJECT_TYPE_FILE, checksum, - NULL, &uncompressed_size, - cancellable, error)) + if (!ostree_repo_load_object_stream (repo, OSTREE_OBJECT_TYPE_FILE, checksum, NULL, + &uncompressed_size, cancellable, error)) return FALSE; - if (builder->min_fallback_size_bytes > 0 && - uncompressed_size > builder->min_fallback_size_bytes) + if (builder->min_fallback_size_bytes > 0 + && uncompressed_size > builder->min_fallback_size_bytes) fallback = TRUE; if (fallback) @@ -1220,12 +1142,11 @@ generate_delta_lowlatency (OstreeRepo *repo, const char *checksum = key; /* Skip content objects we rollsum'd */ - if (g_hash_table_contains (rollsum_optimized_content_objects, checksum) || - g_hash_table_contains (bsdiff_optimized_content_objects, checksum)) + if (g_hash_table_contains (rollsum_optimized_content_objects, checksum) + || g_hash_table_contains (bsdiff_optimized_content_objects, checksum)) continue; - if (!process_one_object (repo, builder, ¤t_part, - checksum, OSTREE_OBJECT_TYPE_FILE, + if (!process_one_object (repo, builder, ¤t_part, checksum, OSTREE_OBJECT_TYPE_FILE, cancellable, error)) return FALSE; } @@ -1236,8 +1157,7 @@ generate_delta_lowlatency (OstreeRepo *repo, { const char *checksum = key; - if (!process_one_object (repo, builder, ¤t_part, - checksum, OSTREE_OBJECT_TYPE_FILE, + if (!process_one_object (repo, builder, ¤t_part, checksum, OSTREE_OBJECT_TYPE_FILE, cancellable, error)) return FALSE; } @@ -1249,14 +1169,11 @@ generate_delta_lowlatency (OstreeRepo *repo, } static gboolean -get_fallback_headers (OstreeRepo *self, - OstreeStaticDeltaBuilder *builder, - GVariant **out_headers, - GCancellable *cancellable, - GError **error) +get_fallback_headers (OstreeRepo *self, OstreeStaticDeltaBuilder *builder, GVariant **out_headers, + GCancellable *cancellable, GError **error) { - g_autoptr(GVariantBuilder) fallback_builder = - g_variant_builder_new (G_VARIANT_TYPE ("a" OSTREE_STATIC_DELTA_FALLBACK_FORMAT)); + g_autoptr (GVariantBuilder) fallback_builder + = g_variant_builder_new (G_VARIANT_TYPE ("a" OSTREE_STATIC_DELTA_FALLBACK_FORMAT)); for (guint i = 0; i < builder->fallback_objects->len; i++) { @@ -1270,38 +1187,32 @@ get_fallback_headers (OstreeRepo *self, if (OSTREE_OBJECT_TYPE_IS_META (objtype)) { - if (!ostree_repo_load_object_stream (self, objtype, checksum, - NULL, &uncompressed_size, + if (!ostree_repo_load_object_stream (self, objtype, checksum, NULL, &uncompressed_size, cancellable, error)) return FALSE; compressed_size = uncompressed_size; } else { - if (!ostree_repo_query_object_storage_size (self, OSTREE_OBJECT_TYPE_FILE, - checksum, - &compressed_size, - cancellable, error)) + if (!ostree_repo_query_object_storage_size (self, OSTREE_OBJECT_TYPE_FILE, checksum, + &compressed_size, cancellable, error)) return FALSE; - g_autoptr(GFileInfo) file_info = NULL; - if (!ostree_repo_load_file (self, checksum, - NULL, &file_info, NULL, - cancellable, error)) + g_autoptr (GFileInfo) file_info = NULL; + if (!ostree_repo_load_file (self, checksum, NULL, &file_info, NULL, cancellable, error)) return FALSE; uncompressed_size = g_file_info_get_size (file_info); } - g_variant_builder_add_value (fallback_builder, - g_variant_new ("(y@aytt)", - objtype, - ostree_checksum_to_bytes_v (checksum), - maybe_swap_endian_u64 (builder->swap_endian, compressed_size), - maybe_swap_endian_u64 (builder->swap_endian, uncompressed_size))); + g_variant_builder_add_value ( + fallback_builder, + g_variant_new ("(y@aytt)", objtype, ostree_checksum_to_bytes_v (checksum), + maybe_swap_endian_u64 (builder->swap_endian, compressed_size), + maybe_swap_endian_u64 (builder->swap_endian, uncompressed_size))); } - g_autoptr(GVariant) ret_headers = g_variant_ref_sink (g_variant_builder_end (fallback_builder)); + g_autoptr (GVariant) ret_headers = g_variant_ref_sink (g_variant_builder_end (fallback_builder)); ot_transfer_out_value (out_headers, &ret_headers); return TRUE; } @@ -1324,7 +1235,8 @@ get_fallback_headers (OstreeRepo *self, * * The @params argument should be an a{sv}. The following attributes * are known: - * - min-fallback-size: u: Minimum uncompressed size in megabytes to use fallback, 0 to disable fallbacks + * - min-fallback-size: u: Minimum uncompressed size in megabytes to use fallback, 0 to disable + * fallbacks * - max-chunk-size: u: Maximum size in megabytes of a delta part * - max-bsdiff-size: u: Maximum size in megabytes to consider bsdiff compression * for input files @@ -1332,22 +1244,21 @@ get_fallback_headers (OstreeRepo *self, * - bsdiff-enabled: b: Enable bsdiff compression. Default TRUE. * - inline-parts: b: Put part data in header, to get a single file delta. Default FALSE. * - verbose: b: Print diagnostic messages. Default FALSE. - * - endianness: b: Deltas use host byte order by default; this option allows choosing (G_BIG_ENDIAN or G_LITTLE_ENDIAN) - * - filename: ^ay: Save delta superblock to this filename (bytestring), and parts in the same directory. Default saves to repository. + * - endianness: b: Deltas use host byte order by default; this option allows choosing + * (G_BIG_ENDIAN or G_LITTLE_ENDIAN) + * - filename: ^ay: Save delta superblock to this filename (bytestring), and parts in the same + * directory. Default saves to repository. * - sign-name: ^ay: Signature type to use (bytestring). * - sign-key-ids: ^as: NULL-terminated array of keys used to sign delta superblock. */ gboolean -ostree_repo_static_delta_generate (OstreeRepo *self, - OstreeStaticDeltaGenerateOpt opt, - const char *from, - const char *to, - GVariant *metadata, - GVariant *params, - GCancellable *cancellable, - GError **error) +ostree_repo_static_delta_generate (OstreeRepo *self, OstreeStaticDeltaGenerateOpt opt, + const char *from, const char *to, GVariant *metadata, + GVariant *params, GCancellable *cancellable, GError **error) { - OstreeStaticDeltaBuilder builder = { 0, }; + OstreeStaticDeltaBuilder builder = { + 0, + }; guint i; guint min_fallback_size; guint max_bsdiff_size; @@ -1355,19 +1266,23 @@ ostree_repo_static_delta_generate (OstreeRepo *self, DeltaOpts delta_opts = DELTAOPT_FLAG_NONE; guint64 total_compressed_size = 0; guint64 total_uncompressed_size = 0; - g_autoptr(GVariantBuilder) part_headers = NULL; - g_autoptr(GPtrArray) part_temp_paths = NULL; - g_autoptr(GVariant) to_commit = NULL; + g_autoptr (GVariantBuilder) part_headers = NULL; + g_autoptr (GPtrArray) part_temp_paths = NULL; + g_autoptr (GVariant) to_commit = NULL; const char *opt_filename; g_autofree char *descriptor_name = NULL; glnx_autofd int descriptor_dfd = -1; - g_autoptr(GVariant) fallback_headers = NULL; - g_autoptr(GVariant) detached = NULL; + g_autoptr (GVariant) fallback_headers = NULL; + g_autoptr (GVariant) detached = NULL; gboolean inline_parts; guint endianness = G_BYTE_ORDER; - g_autoptr(GPtrArray) builder_parts = g_ptr_array_new_with_free_func ((GDestroyNotify)ostree_static_delta_part_builder_unref); - g_autoptr(GPtrArray) builder_fallback_objects = g_ptr_array_new_with_free_func ((GDestroyNotify)g_variant_unref); - g_auto(GLnxTmpfile) descriptor_tmpf = { 0, }; + g_autoptr (GPtrArray) builder_parts + = g_ptr_array_new_with_free_func ((GDestroyNotify)ostree_static_delta_part_builder_unref); + g_autoptr (GPtrArray) builder_fallback_objects + = g_ptr_array_new_with_free_func ((GDestroyNotify)g_variant_unref); + g_auto (GLnxTmpfile) descriptor_tmpf = { + 0, + }; const char *opt_sign_name; const char **opt_key_ids; @@ -1382,7 +1297,7 @@ ostree_repo_static_delta_generate (OstreeRepo *self, max_chunk_size = 32; builder.max_chunk_size_bytes = ((guint64)max_chunk_size) * 1000 * 1000; - (void) g_variant_lookup (params, "endianness", "u", &endianness); + (void)g_variant_lookup (params, "endianness", "u", &endianness); if (!(endianness == G_BIG_ENDIAN || endianness == G_LITTLE_ENDIAN)) return glnx_throw (error, "Invalid endianness parameter"); @@ -1390,14 +1305,16 @@ ostree_repo_static_delta_generate (OstreeRepo *self, builder.parts = builder_parts; builder.fallback_objects = builder_fallback_objects; - { gboolean use_bsdiff; + { + gboolean use_bsdiff; if (!g_variant_lookup (params, "bsdiff-enabled", "b", &use_bsdiff)) use_bsdiff = TRUE; if (!use_bsdiff) delta_opts |= DELTAOPT_FLAG_DISABLE_BSDIFF; } - { gboolean verbose; + { + gboolean verbose; if (!g_variant_lookup (params, "verbose", "b", &verbose)) verbose = FALSE; if (verbose) @@ -1420,8 +1337,7 @@ ostree_repo_static_delta_generate (OstreeRepo *self, if (!g_variant_lookup (params, "sign-key-ids", "^a&s", &opt_key_ids)) opt_key_ids = NULL; - if (!ostree_repo_load_variant (self, OSTREE_OBJECT_TYPE_COMMIT, to, - &to_commit, error)) + if (!ostree_repo_load_variant (self, OSTREE_OBJECT_TYPE_COMMIT, to, &to_commit, error)) return FALSE; builder.delta_opts = delta_opts; @@ -1437,11 +1353,13 @@ ostree_repo_static_delta_generate (OstreeRepo *self, } else { - g_autofree char *descriptor_relpath = _ostree_get_relative_static_delta_superblock_path (from, to); + g_autofree char *descriptor_relpath + = _ostree_get_relative_static_delta_superblock_path (from, to); g_autofree char *dnbuf = g_strdup (descriptor_relpath); const char *dn = dirname (dnbuf); - if (!glnx_shutil_mkdir_p_at (self->repo_dir_fd, dn, DEFAULT_DIRECTORY_MODE, cancellable, error)) + if (!glnx_shutil_mkdir_p_at (self->repo_dir_fd, dn, DEFAULT_DIRECTORY_MODE, cancellable, + error)) return FALSE; if (!glnx_opendirat (self->repo_dir_fd, dn, TRUE, &descriptor_dfd, error)) return FALSE; @@ -1451,17 +1369,15 @@ ostree_repo_static_delta_generate (OstreeRepo *self, builder.parts_dfd = descriptor_dfd; /* Ignore optimization flags */ - if (!generate_delta_lowlatency (self, from, to, delta_opts, &builder, - cancellable, error)) + if (!generate_delta_lowlatency (self, from, to, delta_opts, &builder, cancellable, error)) return FALSE; - if (!glnx_open_tmpfile_linkable_at (descriptor_dfd, ".", O_RDWR | O_CLOEXEC, - &descriptor_tmpf, error)) + if (!glnx_open_tmpfile_linkable_at (descriptor_dfd, ".", O_RDWR | O_CLOEXEC, &descriptor_tmpf, + error)) return FALSE; - g_autoptr(OtVariantBuilder) descriptor_builder = - ot_variant_builder_new (G_VARIANT_TYPE (OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT), - descriptor_tmpf.fd); + g_autoptr (OtVariantBuilder) descriptor_builder = ot_variant_builder_new ( + G_VARIANT_TYPE (OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT), descriptor_tmpf.fd); g_assert (descriptor_builder != NULL); /* Open the metadata dict */ @@ -1486,7 +1402,8 @@ ostree_repo_static_delta_generate (OstreeRepo *self, } } - { guint8 endianness_char; + { + guint8 endianness_char; switch (endianness) { @@ -1499,7 +1416,8 @@ ostree_repo_static_delta_generate (OstreeRepo *self, default: g_assert_not_reached (); } - if (!ot_variant_builder_add (descriptor_builder, error, "{sv}", "ostree.endianness", g_variant_new_byte (endianness_char))) + if (!ot_variant_builder_add (descriptor_builder, error, "{sv}", "ostree.endianness", + g_variant_new_byte (endianness_char))) return FALSE; } @@ -1515,12 +1433,14 @@ ostree_repo_static_delta_generate (OstreeRepo *self, lseek (part_builder->part_tmpf.fd, 0, SEEK_SET); - if (!ot_variant_builder_open (descriptor_builder, G_VARIANT_TYPE ("{sv}"), error) || - !ot_variant_builder_add (descriptor_builder, error, "s", part_relpath) || - !ot_variant_builder_open (descriptor_builder, G_VARIANT_TYPE ("v"), error) || - !ot_variant_builder_add_from_fd (descriptor_builder, G_VARIANT_TYPE ("(yay)"), part_builder->part_tmpf.fd, part_builder->compressed_size, error) || - !ot_variant_builder_close (descriptor_builder, error) || - !ot_variant_builder_close (descriptor_builder, error)) + if (!ot_variant_builder_open (descriptor_builder, G_VARIANT_TYPE ("{sv}"), error) + || !ot_variant_builder_add (descriptor_builder, error, "s", part_relpath) + || !ot_variant_builder_open (descriptor_builder, G_VARIANT_TYPE ("v"), error) + || !ot_variant_builder_add_from_fd (descriptor_builder, G_VARIANT_TYPE ("(yay)"), + part_builder->part_tmpf.fd, + part_builder->compressed_size, error) + || !ot_variant_builder_close (descriptor_builder, error) + || !ot_variant_builder_close (descriptor_builder, error)) return FALSE; } else @@ -1541,8 +1461,7 @@ ostree_repo_static_delta_generate (OstreeRepo *self, total_uncompressed_size += part_builder->uncompressed_size; } - if (!get_fallback_headers (self, &builder, &fallback_headers, - cancellable, error)) + if (!get_fallback_headers (self, &builder, &fallback_headers, cancellable, error)) return FALSE; if (!ostree_repo_read_commit_detached_metadata (self, to, &detached, cancellable, error)) @@ -1550,7 +1469,8 @@ ostree_repo_static_delta_generate (OstreeRepo *self, if (detached) { - g_autofree char *detached_key = _ostree_get_relative_static_delta_path (from, to, "commitmeta"); + g_autofree char *detached_key + = _ostree_get_relative_static_delta_path (from, to, "commitmeta"); if (!ot_variant_builder_add (descriptor_builder, error, "{sv}", detached_key, detached)) return FALSE; } @@ -1562,26 +1482,20 @@ ostree_repo_static_delta_generate (OstreeRepo *self, /* Generate OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT */ { GDateTime *now = g_date_time_new_now_utc (); - /* floating */ GVariant *from_csum_v = - from ? ostree_checksum_to_bytes_v (from) : ot_gvariant_new_bytearray ((guchar *)"", 0); - /* floating */ GVariant *to_csum_v = - ostree_checksum_to_bytes_v (to); - + /* floating */ GVariant *from_csum_v + = from ? ostree_checksum_to_bytes_v (from) : ot_gvariant_new_bytearray ((guchar *)"", 0); + /* floating */ GVariant *to_csum_v = ostree_checksum_to_bytes_v (to); if (!ot_variant_builder_add (descriptor_builder, error, "t", - GUINT64_TO_BE (g_date_time_to_unix (now))) || - !ot_variant_builder_add_value (descriptor_builder, - from_csum_v, error) || - !ot_variant_builder_add_value (descriptor_builder, - to_csum_v, error) || - !ot_variant_builder_add_value (descriptor_builder, - to_commit, error) || - !ot_variant_builder_add_value (descriptor_builder, - ot_gvariant_new_bytearray ((guchar*)"", 0), error) || - !ot_variant_builder_add_value (descriptor_builder, - g_variant_builder_end (part_headers), error) || - !ot_variant_builder_add_value (descriptor_builder, - fallback_headers, error)) + GUINT64_TO_BE (g_date_time_to_unix (now))) + || !ot_variant_builder_add_value (descriptor_builder, from_csum_v, error) + || !ot_variant_builder_add_value (descriptor_builder, to_csum_v, error) + || !ot_variant_builder_add_value (descriptor_builder, to_commit, error) + || !ot_variant_builder_add_value (descriptor_builder, + ot_gvariant_new_bytearray ((guchar *)"", 0), error) + || !ot_variant_builder_add_value (descriptor_builder, g_variant_builder_end (part_headers), + error) + || !ot_variant_builder_add_value (descriptor_builder, fallback_headers, error)) return FALSE; if (!ot_variant_builder_end (descriptor_builder, error)) @@ -1592,23 +1506,23 @@ ostree_repo_static_delta_generate (OstreeRepo *self, if (delta_opts & DELTAOPT_FLAG_VERBOSE) { - g_printerr ("uncompressed=%" G_GUINT64_FORMAT " compressed=%" G_GUINT64_FORMAT " loose=%" G_GUINT64_FORMAT "\n", - total_uncompressed_size, - total_compressed_size, - builder.loose_compressed_size); - g_printerr ("rollsum=%u objects, %" G_GUINT64_FORMAT " bytes\n", - builder.n_rollsum, + g_printerr ("uncompressed=%" G_GUINT64_FORMAT " compressed=%" G_GUINT64_FORMAT + " loose=%" G_GUINT64_FORMAT "\n", + total_uncompressed_size, total_compressed_size, builder.loose_compressed_size); + g_printerr ("rollsum=%u objects, %" G_GUINT64_FORMAT " bytes\n", builder.n_rollsum, builder.rollsum_size); g_printerr ("bsdiff=%u objects\n", builder.n_bsdiff); } if (opt_sign_name != NULL && opt_key_ids != NULL) { - g_autoptr(GBytes) tmpdata = NULL; - g_autoptr(OstreeSign) sign = NULL; + g_autoptr (GBytes) tmpdata = NULL; + g_autoptr (OstreeSign) sign = NULL; const gchar *signature_key = NULL; - g_autoptr(GVariantBuilder) signature_builder = NULL; - g_auto(GLnxTmpfile) descriptor_sign_tmpf = { 0, }; + g_autoptr (GVariantBuilder) signature_builder = NULL; + g_auto (GLnxTmpfile) descriptor_sign_tmpf = { + 0, + }; lseek (descriptor_tmpf.fd, 0, SEEK_SET); tmpdata = glnx_fd_readall_bytes (descriptor_tmpf.fd, cancellable, error); @@ -1627,38 +1541,38 @@ ostree_repo_static_delta_generate (OstreeRepo *self, for (const char **iter = opt_key_ids; iter && *iter; iter++) { const char *keyid = *iter; - g_autoptr(GVariant) secret_key = NULL; - g_autoptr(GBytes) signature_bytes = NULL; + g_autoptr (GVariant) secret_key = NULL; + g_autoptr (GBytes) signature_bytes = NULL; secret_key = g_variant_new_string (keyid); if (!ostree_sign_set_sk (sign, secret_key, error)) - return FALSE; + return FALSE; - if (!ostree_sign_data (sign, tmpdata, &signature_bytes, - NULL, error)) + if (!ostree_sign_data (sign, tmpdata, &signature_bytes, NULL, error)) return FALSE; - g_variant_builder_add (signature_builder, "@ay", ot_gvariant_new_ay_bytes (signature_bytes)); + g_variant_builder_add (signature_builder, "@ay", + ot_gvariant_new_ay_bytes (signature_bytes)); } if (!glnx_open_tmpfile_linkable_at (descriptor_dfd, ".", O_WRONLY | O_CLOEXEC, &descriptor_sign_tmpf, error)) return FALSE; - g_autoptr(OtVariantBuilder) descriptor_sign_builder = - ot_variant_builder_new (G_VARIANT_TYPE (OSTREE_STATIC_DELTA_SIGNED_FORMAT), - descriptor_sign_tmpf.fd); + g_autoptr (OtVariantBuilder) descriptor_sign_builder = ot_variant_builder_new ( + G_VARIANT_TYPE (OSTREE_STATIC_DELTA_SIGNED_FORMAT), descriptor_sign_tmpf.fd); g_assert (descriptor_sign_builder != NULL); if (!ot_variant_builder_add (descriptor_sign_builder, error, "t", GUINT64_TO_BE (OSTREE_STATIC_DELTA_SIGNED_MAGIC))) return FALSE; - if (!ot_variant_builder_add (descriptor_sign_builder, error, "@ay", ot_gvariant_new_ay_bytes (tmpdata))) + if (!ot_variant_builder_add (descriptor_sign_builder, error, "@ay", + ot_gvariant_new_ay_bytes (tmpdata))) return FALSE; if (!ot_variant_builder_open (descriptor_sign_builder, G_VARIANT_TYPE ("a{sv}"), error)) return FALSE; - if (!ot_variant_builder_add (descriptor_sign_builder, error, "{sv}", - signature_key, g_variant_builder_end(signature_builder))) + if (!ot_variant_builder_add (descriptor_sign_builder, error, "{sv}", signature_key, + g_variant_builder_end (signature_builder))) return FALSE; if (!ot_variant_builder_close (descriptor_sign_builder, error)) return FALSE; @@ -1669,8 +1583,8 @@ ostree_repo_static_delta_generate (OstreeRepo *self, if (fchmod (descriptor_sign_tmpf.fd, 0644) < 0) return glnx_throw_errno_prefix (error, "fchmod"); - if (!glnx_link_tmpfile_at (&descriptor_sign_tmpf, GLNX_LINK_TMPFILE_REPLACE, - descriptor_dfd, descriptor_name, error)) + if (!glnx_link_tmpfile_at (&descriptor_sign_tmpf, GLNX_LINK_TMPFILE_REPLACE, descriptor_dfd, + descriptor_name, error)) return FALSE; } else @@ -1678,8 +1592,8 @@ ostree_repo_static_delta_generate (OstreeRepo *self, if (fchmod (descriptor_tmpf.fd, 0644) < 0) return glnx_throw_errno_prefix (error, "fchmod"); - if (!glnx_link_tmpfile_at (&descriptor_tmpf, GLNX_LINK_TMPFILE_REPLACE, - descriptor_dfd, descriptor_name, error)) + if (!glnx_link_tmpfile_at (&descriptor_tmpf, GLNX_LINK_TMPFILE_REPLACE, descriptor_dfd, + descriptor_name, error)) return FALSE; } diff --git a/src/libostree/ostree-repo-static-delta-core.c b/src/libostree/ostree-repo-static-delta-core.c index 7854211f..dc57a2f0 100644 --- a/src/libostree/ostree-repo-static-delta-core.c +++ b/src/libostree/ostree-repo-static-delta-core.c @@ -19,31 +19,28 @@ #include "config.h" -#include -#include -#include +#include "ostree-checksum-input-stream.h" +#include "ostree-cmd-private.h" #include "ostree-core-private.h" -#include "ostree-repo-private.h" #include "ostree-lzma-decompressor.h" -#include "ostree-cmd-private.h" -#include "ostree-checksum-input-stream.h" +#include "ostree-repo-private.h" #include "ostree-repo-static-delta-private.h" #include "otutil.h" +#include +#include +#include gboolean -_ostree_static_delta_parse_checksum_array (GVariant *array, - guint8 **out_checksums_array, - guint *out_n_checksums, - GError **error) +_ostree_static_delta_parse_checksum_array (GVariant *array, guint8 **out_checksums_array, + guint *out_n_checksums, GError **error) { const gsize n = g_variant_n_children (array); const guint n_checksums = n / OSTREE_STATIC_DELTA_OBJTYPE_CSUM_LEN; - if (G_UNLIKELY(n > (G_MAXUINT32/OSTREE_STATIC_DELTA_OBJTYPE_CSUM_LEN) || - (n_checksums * OSTREE_STATIC_DELTA_OBJTYPE_CSUM_LEN) != n)) + if (G_UNLIKELY (n > (G_MAXUINT32 / OSTREE_STATIC_DELTA_OBJTYPE_CSUM_LEN) + || (n_checksums * OSTREE_STATIC_DELTA_OBJTYPE_CSUM_LEN) != n)) { - return glnx_throw (error, - "Invalid checksum array length %" G_GSIZE_FORMAT, n); + return glnx_throw (error, "Invalid checksum array length %" G_GSIZE_FORMAT, n); } *out_checksums_array = (gpointer)g_variant_get_data (array); @@ -53,20 +50,18 @@ _ostree_static_delta_parse_checksum_array (GVariant *array, } GVariant * -_ostree_repo_static_delta_superblock_digest (OstreeRepo *repo, - const char *from, - const char *to, - GCancellable *cancellable, - GError **error) +_ostree_repo_static_delta_superblock_digest (OstreeRepo *repo, const char *from, const char *to, + GCancellable *cancellable, GError **error) { - g_autofree char *superblock = _ostree_get_relative_static_delta_superblock_path ((from && from[0]) ? from : NULL, to); + g_autofree char *superblock + = _ostree_get_relative_static_delta_superblock_path ((from && from[0]) ? from : NULL, to); glnx_autofd int superblock_file_fd = -1; guint8 digest[OSTREE_SHA256_DIGEST_LEN]; if (!glnx_openat_rdonly (repo->repo_dir_fd, superblock, TRUE, &superblock_file_fd, error)) return NULL; - g_autoptr(GBytes) superblock_content = ot_fd_readall_or_mmap (superblock_file_fd, 0, error); + g_autoptr (GBytes) superblock_content = ot_fd_readall_or_mmap (superblock_file_fd, 0, error); if (!superblock_content) return NULL; @@ -78,7 +73,8 @@ _ostree_repo_static_delta_superblock_digest (OstreeRepo *repo, /** * ostree_repo_list_static_delta_names: * @self: Repo - * @out_deltas: (out) (element-type utf8) (transfer container): String name of deltas (checksum-checksum.delta) + * @out_deltas: (out) (element-type utf8) (transfer container): String name of deltas + * (checksum-checksum.delta) * @cancellable: Cancellable * @error: Error * @@ -86,17 +82,16 @@ _ostree_repo_static_delta_superblock_digest (OstreeRepo *repo, * repository, returning its result in @out_deltas. */ gboolean -ostree_repo_list_static_delta_names (OstreeRepo *self, - GPtrArray **out_deltas, - GCancellable *cancellable, - GError **error) +ostree_repo_list_static_delta_names (OstreeRepo *self, GPtrArray **out_deltas, + GCancellable *cancellable, GError **error) { - g_autoptr(GPtrArray) ret_deltas = g_ptr_array_new_with_free_func (g_free); + g_autoptr (GPtrArray) ret_deltas = g_ptr_array_new_with_free_func (g_free); - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; gboolean exists; - if (!ot_dfd_iter_init_allow_noent (self->repo_dir_fd, "deltas", &dfd_iter, - &exists, error)) + if (!ot_dfd_iter_init_allow_noent (self->repo_dir_fd, "deltas", &dfd_iter, &exists, error)) return FALSE; if (!exists) { @@ -107,7 +102,9 @@ ostree_repo_list_static_delta_names (OstreeRepo *self, while (TRUE) { - g_auto(GLnxDirFdIterator) sub_dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) sub_dfd_iter = { + 0, + }; struct dirent *dent; if (!glnx_dirfd_iterator_next_dent_ensure_dtype (&dfd_iter, &dent, cancellable, error)) @@ -117,15 +114,14 @@ ostree_repo_list_static_delta_names (OstreeRepo *self, if (dent->d_type != DT_DIR) continue; - if (!glnx_dirfd_iterator_init_at (dfd_iter.fd, dent->d_name, FALSE, - &sub_dfd_iter, error)) + if (!glnx_dirfd_iterator_init_at (dfd_iter.fd, dent->d_name, FALSE, &sub_dfd_iter, error)) return FALSE; while (TRUE) { struct dirent *sub_dent; - if (!glnx_dirfd_iterator_next_dent_ensure_dtype (&sub_dfd_iter, &sub_dent, - cancellable, error)) + if (!glnx_dirfd_iterator_next_dent_ensure_dtype (&sub_dfd_iter, &sub_dent, cancellable, + error)) return FALSE; if (sub_dent == NULL) break; @@ -143,7 +139,7 @@ ostree_repo_list_static_delta_names (OstreeRepo *self, g_autofree char *buf = g_strconcat (name1, name2, NULL); GString *out = g_string_new (""); - char checksum[OSTREE_SHA256_STRING_LEN+1]; + char checksum[OSTREE_SHA256_STRING_LEN + 1]; guchar csum[OSTREE_SHA256_DIGEST_LEN]; const char *dash = strchr (buf, '-'); @@ -153,7 +149,7 @@ ostree_repo_list_static_delta_names (OstreeRepo *self, if (dash) { g_string_append_c (out, '-'); - ostree_checksum_b64_inplace_to_bytes (dash+1, csum); + ostree_checksum_b64_inplace_to_bytes (dash + 1, csum); ostree_checksum_inplace_from_bytes (csum, checksum); g_string_append (out, checksum); } @@ -169,7 +165,8 @@ ostree_repo_list_static_delta_names (OstreeRepo *self, /** * ostree_repo_list_static_delta_indexes: * @self: Repo - * @out_indexes: (out) (element-type utf8) (transfer container): String name of delta indexes (checksum) + * @out_indexes: (out) (element-type utf8) (transfer container): String name of delta indexes + * (checksum) * @cancellable: Cancellable * @error: Error * @@ -179,17 +176,16 @@ ostree_repo_list_static_delta_names (OstreeRepo *self, * Since: 2020.8 */ gboolean -ostree_repo_list_static_delta_indexes (OstreeRepo *self, - GPtrArray **out_indexes, - GCancellable *cancellable, - GError **error) +ostree_repo_list_static_delta_indexes (OstreeRepo *self, GPtrArray **out_indexes, + GCancellable *cancellable, GError **error) { - g_autoptr(GPtrArray) ret_indexes = g_ptr_array_new_with_free_func (g_free); + g_autoptr (GPtrArray) ret_indexes = g_ptr_array_new_with_free_func (g_free); - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; gboolean exists; - if (!ot_dfd_iter_init_allow_noent (self->repo_dir_fd, "delta-indexes", &dfd_iter, - &exists, error)) + if (!ot_dfd_iter_init_allow_noent (self->repo_dir_fd, "delta-indexes", &dfd_iter, &exists, error)) return FALSE; if (!exists) { @@ -200,7 +196,9 @@ ostree_repo_list_static_delta_indexes (OstreeRepo *self, while (TRUE) { - g_auto(GLnxDirFdIterator) sub_dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) sub_dfd_iter = { + 0, + }; struct dirent *dent; if (!glnx_dirfd_iterator_next_dent_ensure_dtype (&dfd_iter, &dent, cancellable, error)) @@ -212,16 +210,15 @@ ostree_repo_list_static_delta_indexes (OstreeRepo *self, if (strlen (dent->d_name) != 2) continue; - if (!glnx_dirfd_iterator_init_at (dfd_iter.fd, dent->d_name, FALSE, - &sub_dfd_iter, error)) + if (!glnx_dirfd_iterator_init_at (dfd_iter.fd, dent->d_name, FALSE, &sub_dfd_iter, error)) return FALSE; while (TRUE) { struct dirent *sub_dent; - if (!glnx_dirfd_iterator_next_dent_ensure_dtype (&sub_dfd_iter, &sub_dent, - cancellable, error)) + if (!glnx_dirfd_iterator_next_dent_ensure_dtype (&sub_dfd_iter, &sub_dent, cancellable, + error)) return FALSE; if (sub_dent == NULL) break; @@ -232,14 +229,13 @@ ostree_repo_list_static_delta_indexes (OstreeRepo *self, const char *name2 = sub_dent->d_name; /* base64 len is 43, but 2 chars are in the parent dir name */ - if (strlen (name2) != 41 + strlen(".index") || - !g_str_has_suffix (name2, ".index")) + if (strlen (name2) != 41 + strlen (".index") || !g_str_has_suffix (name2, ".index")) continue; - g_autoptr(GString) out = g_string_new (name1); + g_autoptr (GString) out = g_string_new (name1); g_string_append_len (out, name2, 41); - char checksum[OSTREE_SHA256_STRING_LEN+1]; + char checksum[OSTREE_SHA256_STRING_LEN + 1]; guchar csum[OSTREE_SHA256_DIGEST_LEN]; ostree_checksum_b64_inplace_to_bytes (out->str, csum); @@ -254,19 +250,15 @@ ostree_repo_list_static_delta_indexes (OstreeRepo *self, } gboolean -_ostree_repo_static_delta_part_have_all_objects (OstreeRepo *repo, - GVariant *checksum_array, - gboolean *out_have_all, - GCancellable *cancellable, - GError **error) +_ostree_repo_static_delta_part_have_all_objects (OstreeRepo *repo, GVariant *checksum_array, + gboolean *out_have_all, GCancellable *cancellable, + GError **error) { guint8 *checksums_data = NULL; guint n_checksums = 0; gboolean have_object = TRUE; - if (!_ostree_static_delta_parse_checksum_array (checksum_array, - &checksums_data, - &n_checksums, + if (!_ostree_static_delta_parse_checksum_array (checksum_array, &checksums_data, &n_checksums, error)) return FALSE; @@ -274,15 +266,15 @@ _ostree_repo_static_delta_part_have_all_objects (OstreeRepo *repo, { guint8 objtype = *checksums_data; const guint8 *csum = checksums_data + 1; - char tmp_checksum[OSTREE_SHA256_STRING_LEN+1]; + char tmp_checksum[OSTREE_SHA256_STRING_LEN + 1]; - if (G_UNLIKELY(!ostree_validate_structureof_objtype (objtype, error))) + if (G_UNLIKELY (!ostree_validate_structureof_objtype (objtype, error))) return FALSE; ostree_checksum_inplace_from_bytes (csum, tmp_checksum); - if (!ostree_repo_has_object (repo, (OstreeObjectType) objtype, tmp_checksum, - &have_object, cancellable, error)) + if (!ostree_repo_has_object (repo, (OstreeObjectType)objtype, tmp_checksum, &have_object, + cancellable, error)) return FALSE; if (!have_object) @@ -296,23 +288,22 @@ _ostree_repo_static_delta_part_have_all_objects (OstreeRepo *repo, } static gboolean -_ostree_repo_static_delta_is_signed (OstreeRepo *self, - int fd, - GPtrArray **out_value, - GError **error) +_ostree_repo_static_delta_is_signed (OstreeRepo *self, int fd, GPtrArray **out_value, + GError **error) { - g_autoptr(GVariant) delta = NULL; - g_autoptr(GVariant) delta_sign_magic = NULL; - g_autoptr(GVariant) delta_sign = NULL; + g_autoptr (GVariant) delta = NULL; + g_autoptr (GVariant) delta_sign_magic = NULL; + g_autoptr (GVariant) delta_sign = NULL; GVariantIter iter; GVariant *item; - g_autoptr(GPtrArray) signatures = NULL; + g_autoptr (GPtrArray) signatures = NULL; gboolean ret = FALSE; if (out_value) *out_value = NULL; - if (!ot_variant_read_fd (fd, 0, (GVariantType*)OSTREE_STATIC_DELTA_SIGNED_FORMAT, TRUE, &delta, error)) + if (!ot_variant_read_fd (fd, 0, (GVariantType *)OSTREE_STATIC_DELTA_SIGNED_FORMAT, TRUE, &delta, + error)) return FALSE; delta_sign_magic = g_variant_get_child_value (delta, 0); @@ -333,7 +324,7 @@ _ostree_repo_static_delta_is_signed (OstreeRepo *self, g_variant_iter_init (&iter, delta_sign); while ((item = g_variant_iter_next_value (&iter))) { - g_autoptr(GVariant) key_v = g_variant_get_child_value (item, 0); + g_autoptr (GVariant) key_v = g_variant_get_child_value (item, 0); const char *str = g_variant_get_string (key_v, NULL); if (g_str_has_prefix (str, "ostree.sign.")) { @@ -351,36 +342,31 @@ _ostree_repo_static_delta_is_signed (OstreeRepo *self, } static gboolean -_ostree_repo_static_delta_verify_signature (OstreeRepo *self, - int fd, - OstreeSign *sign, - char **out_success_message, - GError **error) +_ostree_repo_static_delta_verify_signature (OstreeRepo *self, int fd, OstreeSign *sign, + char **out_success_message, GError **error) { - g_autoptr(GVariant) delta = NULL; + g_autoptr (GVariant) delta = NULL; - if (!ot_variant_read_fd (fd, 0, - (GVariantType*)OSTREE_STATIC_DELTA_SIGNED_FORMAT, - TRUE, &delta, error)) + if (!ot_variant_read_fd (fd, 0, (GVariantType *)OSTREE_STATIC_DELTA_SIGNED_FORMAT, TRUE, &delta, + error)) return FALSE; /* Check if there are signatures for signature engine */ - const gchar *signature_key = ostree_sign_metadata_key(sign); - GVariantType *signature_format = (GVariantType *) ostree_sign_metadata_format(sign); - g_autoptr(GVariant) delta_meta = g_variant_get_child_value (delta, 2); + const gchar *signature_key = ostree_sign_metadata_key (sign); + GVariantType *signature_format = (GVariantType *)ostree_sign_metadata_format (sign); + g_autoptr (GVariant) delta_meta = g_variant_get_child_value (delta, 2); if (delta_meta == NULL) return glnx_throw (error, "no metadata in static-delta superblock"); - g_autoptr(GVariant) signatures = g_variant_lookup_value (delta_meta, - signature_key, - signature_format); + g_autoptr (GVariant) signatures + = g_variant_lookup_value (delta_meta, signature_key, signature_format); if (!signatures) return glnx_throw (error, "no signature for '%s' in static-delta superblock", signature_key); /* Get static delta superblock */ - g_autoptr(GVariant) child = g_variant_get_child_value (delta, 1); + g_autoptr (GVariant) child = g_variant_get_child_value (delta, 1); if (child == NULL) return glnx_throw (error, "no metadata in static-delta superblock"); - g_autoptr(GBytes) signed_data = g_variant_get_data_as_bytes(child); + g_autoptr (GBytes) signed_data = g_variant_get_data_as_bytes (child); return ostree_sign_data_verify (sign, signed_data, signatures, out_success_message, error); } @@ -406,15 +392,12 @@ _ostree_repo_static_delta_verify_signature (OstreeRepo *self, * Since: 2020.7 */ gboolean -ostree_repo_static_delta_execute_offline_with_signature (OstreeRepo *self, - GFile *dir_or_file, - OstreeSign *sign, - gboolean skip_validation, - GCancellable *cancellable, - GError **error) +ostree_repo_static_delta_execute_offline_with_signature (OstreeRepo *self, GFile *dir_or_file, + OstreeSign *sign, gboolean skip_validation, + GCancellable *cancellable, GError **error) { g_autofree char *basename = NULL; - g_autoptr(GVariant) meta = NULL; + g_autoptr (GVariant) meta = NULL; const char *dir_or_file_path = gs_file_get_path_cached (dir_or_file); @@ -446,8 +429,8 @@ ostree_repo_static_delta_execute_offline_with_signature (OstreeRepo *self, gboolean verify_deltas; gboolean verified; - if (!ot_keyfile_get_boolean_with_default (self->config, "core", "sign-verify-deltas", - FALSE, &verify_deltas, error)) + if (!ot_keyfile_get_boolean_with_default (self->config, "core", "sign-verify-deltas", FALSE, + &verify_deltas, error)) return FALSE; if (verify_deltas && !sign) @@ -455,9 +438,10 @@ ostree_repo_static_delta_execute_offline_with_signature (OstreeRepo *self, if (sign) { - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; - verified = _ostree_repo_static_delta_verify_signature (self, meta_fd, sign, NULL, &local_error); + verified = _ostree_repo_static_delta_verify_signature (self, meta_fd, sign, NULL, + &local_error); if (local_error != NULL) { g_propagate_error (error, g_steal_pointer (&local_error)); @@ -468,15 +452,15 @@ ostree_repo_static_delta_execute_offline_with_signature (OstreeRepo *self, return glnx_throw (error, "Delta signature verification failed"); } - g_autoptr(GVariant) delta = NULL; - if (!ot_variant_read_fd (meta_fd, 0, (GVariantType*)OSTREE_STATIC_DELTA_SIGNED_FORMAT, - TRUE, &delta, error)) + g_autoptr (GVariant) delta = NULL; + if (!ot_variant_read_fd (meta_fd, 0, (GVariantType *)OSTREE_STATIC_DELTA_SIGNED_FORMAT, TRUE, + &delta, error)) return FALSE; - g_autoptr(GVariant) child = g_variant_get_child_value (delta, 1); - g_autoptr(GBytes) bytes = g_variant_get_data_as_bytes (child); - meta = g_variant_new_from_bytes ((GVariantType*)OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT, - bytes, FALSE); + g_autoptr (GVariant) child = g_variant_get_child_value (delta, 1); + g_autoptr (GBytes) bytes = g_variant_get_data_as_bytes (child); + meta = g_variant_new_from_bytes ((GVariantType *)OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT, bytes, + FALSE); } else { @@ -487,15 +471,15 @@ ostree_repo_static_delta_execute_offline_with_signature (OstreeRepo *self, /* Parsing OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT */ - g_autoptr(GVariant) metadata = g_variant_get_child_value (meta, 0); + g_autoptr (GVariant) metadata = g_variant_get_child_value (meta, 0); g_autofree char *to_checksum = NULL; g_autofree char *from_checksum = NULL; /* Write the to-commit object */ { - g_autoptr(GVariant) to_csum_v = NULL; - g_autoptr(GVariant) from_csum_v = NULL; - g_autoptr(GVariant) to_commit = NULL; + g_autoptr (GVariant) to_csum_v = NULL; + g_autoptr (GVariant) from_csum_v = NULL; + g_autoptr (GVariant) to_commit = NULL; gboolean have_to_commit; gboolean have_from_commit; @@ -516,59 +500,59 @@ ostree_repo_static_delta_execute_offline_with_signature (OstreeRepo *self, return FALSE; if (!have_from_commit) - return glnx_throw (error, "Commit %s, which is the delta source, is not in repository", from_checksum); + return glnx_throw (error, "Commit %s, which is the delta source, is not in repository", + from_checksum); } - if (!ostree_repo_has_object (self, OSTREE_OBJECT_TYPE_COMMIT, to_checksum, - &have_to_commit, cancellable, error)) + if (!ostree_repo_has_object (self, OSTREE_OBJECT_TYPE_COMMIT, to_checksum, &have_to_commit, + cancellable, error)) return FALSE; if (!have_to_commit) { - g_autofree char *detached_path = _ostree_get_relative_static_delta_path (from_checksum, to_checksum, "commitmeta"); - g_autoptr(GVariant) detached_data = - g_variant_lookup_value (metadata, detached_path, G_VARIANT_TYPE("a{sv}")); - if (detached_data && !ostree_repo_write_commit_detached_metadata (self, - to_checksum, - detached_data, - cancellable, - error)) + g_autofree char *detached_path + = _ostree_get_relative_static_delta_path (from_checksum, to_checksum, "commitmeta"); + g_autoptr (GVariant) detached_data + = g_variant_lookup_value (metadata, detached_path, G_VARIANT_TYPE ("a{sv}")); + if (detached_data + && !ostree_repo_write_commit_detached_metadata (self, to_checksum, detached_data, + cancellable, error)) return FALSE; to_commit = g_variant_get_child_value (meta, 4); - if (!ostree_repo_write_metadata (self, OSTREE_OBJECT_TYPE_COMMIT, - to_checksum, to_commit, NULL, - cancellable, error)) + if (!ostree_repo_write_metadata (self, OSTREE_OBJECT_TYPE_COMMIT, to_checksum, to_commit, + NULL, cancellable, error)) return FALSE; } } - g_autoptr(GVariant) fallback = g_variant_get_child_value (meta, 7); + g_autoptr (GVariant) fallback = g_variant_get_child_value (meta, 7); if (g_variant_n_children (fallback) > 0) - return glnx_throw (error, "Cannot execute delta offline: contains nonempty http fallback entries"); + return glnx_throw (error, + "Cannot execute delta offline: contains nonempty http fallback entries"); - g_autoptr(GVariant) headers = g_variant_get_child_value (meta, 6); + g_autoptr (GVariant) headers = g_variant_get_child_value (meta, 6); const guint n = g_variant_n_children (headers); for (guint i = 0; i < n; i++) { guint32 version; guint64 size; guint64 usize; - char checksum[OSTREE_SHA256_STRING_LEN+1]; - g_autoptr(GVariant) csum_v = NULL; - g_autoptr(GVariant) objects = NULL; - g_autoptr(GVariant) part = NULL; - OstreeStaticDeltaOpenFlags delta_open_flags = - skip_validation ? OSTREE_STATIC_DELTA_OPEN_FLAGS_SKIP_CHECKSUM : 0; - g_autoptr(GVariant) header = g_variant_get_child_value (headers, i); + char checksum[OSTREE_SHA256_STRING_LEN + 1]; + g_autoptr (GVariant) csum_v = NULL; + g_autoptr (GVariant) objects = NULL; + g_autoptr (GVariant) part = NULL; + OstreeStaticDeltaOpenFlags delta_open_flags + = skip_validation ? OSTREE_STATIC_DELTA_OPEN_FLAGS_SKIP_CHECKSUM : 0; + g_autoptr (GVariant) header = g_variant_get_child_value (headers, i); g_variant_get (header, "(u@aytt@ay)", &version, &csum_v, &size, &usize, &objects); if (version > OSTREE_DELTAPART_VERSION) return glnx_throw (error, "Delta part has too new version %u", version); gboolean have_all; - if (!_ostree_repo_static_delta_part_have_all_objects (self, objects, &have_all, - cancellable, error)) + if (!_ostree_repo_static_delta_part_have_all_objects (self, objects, &have_all, cancellable, + error)) return FALSE; /* If we already have these objects, don't bother executing the @@ -582,14 +566,15 @@ ostree_repo_static_delta_execute_offline_with_signature (OstreeRepo *self, return FALSE; ostree_checksum_inplace_from_bytes (csum, checksum); - g_autofree char *deltapart_path = - _ostree_get_relative_static_delta_part_path (from_checksum, to_checksum, i); + g_autofree char *deltapart_path + = _ostree_get_relative_static_delta_part_path (from_checksum, to_checksum, i); - g_autoptr(GInputStream) part_in = NULL; - g_autoptr(GVariant) inline_part_data = g_variant_lookup_value (metadata, deltapart_path, G_VARIANT_TYPE("(yay)")); + g_autoptr (GInputStream) part_in = NULL; + g_autoptr (GVariant) inline_part_data + = g_variant_lookup_value (metadata, deltapart_path, G_VARIANT_TYPE ("(yay)")); if (inline_part_data) { - g_autoptr(GBytes) inline_part_bytes = g_variant_get_data_as_bytes (inline_part_data); + g_autoptr (GBytes) inline_part_bytes = g_variant_get_data_as_bytes (inline_part_data); part_in = g_memory_input_stream_new_from_bytes (inline_part_bytes); /* For inline parts, we don't checksum, because it's @@ -599,11 +584,8 @@ ostree_repo_static_delta_execute_offline_with_signature (OstreeRepo *self, */ delta_open_flags |= OSTREE_STATIC_DELTA_OPEN_FLAGS_SKIP_CHECKSUM; - if (!_ostree_static_delta_part_open (part_in, inline_part_bytes, - delta_open_flags, - NULL, - &part, - cancellable, error)) + if (!_ostree_static_delta_part_open (part_in, inline_part_bytes, delta_open_flags, NULL, + &part, cancellable, error)) return FALSE; } else @@ -615,16 +597,13 @@ ostree_repo_static_delta_execute_offline_with_signature (OstreeRepo *self, part_in = g_unix_input_stream_new (part_fd, FALSE); - if (!_ostree_static_delta_part_open (part_in, NULL, - delta_open_flags, - checksum, - &part, + if (!_ostree_static_delta_part_open (part_in, NULL, delta_open_flags, checksum, &part, cancellable, error)) return FALSE; } - if (!_ostree_static_delta_part_execute (self, objects, part, skip_validation, - NULL, cancellable, error)) + if (!_ostree_static_delta_part_execute (self, objects, part, skip_validation, NULL, + cancellable, error)) return glnx_prefix_error (error, "Executing delta part %i", i); } @@ -645,26 +624,18 @@ ostree_repo_static_delta_execute_offline_with_signature (OstreeRepo *self, * must contain a file named "superblock", along with at least one part. */ gboolean -ostree_repo_static_delta_execute_offline (OstreeRepo *self, - GFile *dir_or_file, - gboolean skip_validation, - GCancellable *cancellable, - GError **error) +ostree_repo_static_delta_execute_offline (OstreeRepo *self, GFile *dir_or_file, + gboolean skip_validation, GCancellable *cancellable, + GError **error) { - return ostree_repo_static_delta_execute_offline_with_signature(self, dir_or_file, NULL, - skip_validation, - cancellable, - error); + return ostree_repo_static_delta_execute_offline_with_signature ( + self, dir_or_file, NULL, skip_validation, cancellable, error); } gboolean -_ostree_static_delta_part_open (GInputStream *part_in, - GBytes *inline_part_bytes, - OstreeStaticDeltaOpenFlags flags, - const char *expected_checksum, - GVariant **out_part, - GCancellable *cancellable, - GError **error) +_ostree_static_delta_part_open (GInputStream *part_in, GBytes *inline_part_bytes, + OstreeStaticDeltaOpenFlags flags, const char *expected_checksum, + GVariant **out_part, GCancellable *cancellable, GError **error) { const gboolean trusted = (flags & OSTREE_STATIC_DELTA_OPEN_FLAGS_VARIANT_TRUSTED) > 0; const gboolean skip_checksum = (flags & OSTREE_STATIC_DELTA_OPEN_FLAGS_SKIP_CHECKSUM) > 0; @@ -673,13 +644,13 @@ _ostree_static_delta_part_open (GInputStream *part_in, g_return_val_if_fail (G_IS_FILE_DESCRIPTOR_BASED (part_in) || inline_part_bytes != NULL, FALSE); g_return_val_if_fail (skip_checksum || expected_checksum != NULL, FALSE); - g_autoptr(GChecksum) checksum = NULL; - g_autoptr(GInputStream) checksum_in = NULL; + g_autoptr (GChecksum) checksum = NULL; + g_autoptr (GInputStream) checksum_in = NULL; GInputStream *source_in; if (!skip_checksum) { checksum = g_checksum_new (G_CHECKSUM_SHA256); - checksum_in = (GInputStream*)ostree_checksum_input_stream_new (part_in, checksum); + checksum_in = (GInputStream *)ostree_checksum_input_stream_new (part_in, checksum); source_in = checksum_in; } else @@ -688,52 +659,52 @@ _ostree_static_delta_part_open (GInputStream *part_in, } guint8 comptype; - { guint8 buf[1]; + { + guint8 buf[1]; gsize bytes_read; /* First byte is compression type */ - if (!g_input_stream_read_all (source_in, buf, sizeof(buf), &bytes_read, - cancellable, error)) + if (!g_input_stream_read_all (source_in, buf, sizeof (buf), &bytes_read, cancellable, error)) return glnx_prefix_error (error, "Reading initial compression flag byte"); comptype = buf[0]; } - g_autoptr(GVariant) ret_part = NULL; + g_autoptr (GVariant) ret_part = NULL; switch (comptype) { case 0: if (!inline_part_bytes) { - int part_fd = g_file_descriptor_based_get_fd ((GFileDescriptorBased*)part_in); + int part_fd = g_file_descriptor_based_get_fd ((GFileDescriptorBased *)part_in); /* No compression, no checksums - a fast path */ - if (!ot_variant_read_fd (part_fd, 1, G_VARIANT_TYPE (OSTREE_STATIC_DELTA_PART_PAYLOAD_FORMAT_V0), + if (!ot_variant_read_fd (part_fd, 1, + G_VARIANT_TYPE (OSTREE_STATIC_DELTA_PART_PAYLOAD_FORMAT_V0), trusted, &ret_part, error)) return FALSE; } else { - g_autoptr(GBytes) content_bytes = g_bytes_new_from_bytes (inline_part_bytes, 1, - g_bytes_get_size (inline_part_bytes) - 1); - ret_part = g_variant_new_from_bytes (G_VARIANT_TYPE (OSTREE_STATIC_DELTA_PART_PAYLOAD_FORMAT_V0), - content_bytes, trusted); + g_autoptr (GBytes) content_bytes = g_bytes_new_from_bytes ( + inline_part_bytes, 1, g_bytes_get_size (inline_part_bytes) - 1); + ret_part = g_variant_new_from_bytes ( + G_VARIANT_TYPE (OSTREE_STATIC_DELTA_PART_PAYLOAD_FORMAT_V0), content_bytes, trusted); g_variant_ref_sink (ret_part); } if (!skip_checksum) - g_checksum_update (checksum, g_variant_get_data (ret_part), - g_variant_get_size (ret_part)); + g_checksum_update (checksum, g_variant_get_data (ret_part), g_variant_get_size (ret_part)); break; case 'x': { - g_autoptr(GConverter) decomp = (GConverter*) _ostree_lzma_decompressor_new (); - g_autoptr(GInputStream) convin = g_converter_input_stream_new (source_in, decomp); - g_autoptr(GBytes) buf = ot_map_anonymous_tmpfile_from_content (convin, cancellable, error); + g_autoptr (GConverter) decomp = (GConverter *)_ostree_lzma_decompressor_new (); + g_autoptr (GInputStream) convin = g_converter_input_stream_new (source_in, decomp); + g_autoptr (GBytes) buf = ot_map_anonymous_tmpfile_from_content (convin, cancellable, error); if (!buf) return FALSE; - ret_part = g_variant_new_from_bytes (G_VARIANT_TYPE (OSTREE_STATIC_DELTA_PART_PAYLOAD_FORMAT_V0), - buf, FALSE); + ret_part = g_variant_new_from_bytes ( + G_VARIANT_TYPE (OSTREE_STATIC_DELTA_PART_PAYLOAD_FORMAT_V0), buf, FALSE); } break; default: @@ -758,69 +729,57 @@ _ostree_static_delta_part_open (GInputStream *part_in, */ static gboolean -show_one_part (OstreeRepo *self, - gboolean swap_endian, - const char *from, - const char *to, - GVariant *meta_entries, - guint i, - guint64 *total_size_ref, - guint64 *total_usize_ref, - GCancellable *cancellable, - GError **error) +show_one_part (OstreeRepo *self, gboolean swap_endian, const char *from, const char *to, + GVariant *meta_entries, guint i, guint64 *total_size_ref, guint64 *total_usize_ref, + GCancellable *cancellable, GError **error) { g_autofree char *part_path = _ostree_get_relative_static_delta_part_path (from, to, i); guint32 version; guint64 size, usize; - g_autoptr(GVariant) objects = NULL; + g_autoptr (GVariant) objects = NULL; g_variant_get_child (meta_entries, i, "(u@aytt@ay)", &version, NULL, &size, &usize, &objects); size = maybe_swap_endian_u64 (swap_endian, size); usize = maybe_swap_endian_u64 (swap_endian, usize); *total_size_ref += size; *total_usize_ref += usize; - g_print ("PartMeta%u: nobjects=%u size=%" G_GUINT64_FORMAT " usize=%" G_GUINT64_FORMAT "\n", - i, (guint)(g_variant_get_size (objects) / OSTREE_STATIC_DELTA_OBJTYPE_CSUM_LEN), size, usize); + g_print ("PartMeta%u: nobjects=%u size=%" G_GUINT64_FORMAT " usize=%" G_GUINT64_FORMAT "\n", i, + (guint)(g_variant_get_size (objects) / OSTREE_STATIC_DELTA_OBJTYPE_CSUM_LEN), size, + usize); glnx_autofd int part_fd = openat (self->repo_dir_fd, part_path, O_RDONLY | O_CLOEXEC); if (part_fd < 0) return glnx_throw_errno_prefix (error, "openat(%s)", part_path); - g_autoptr(GInputStream) part_in = g_unix_input_stream_new (part_fd, FALSE); + g_autoptr (GInputStream) part_in = g_unix_input_stream_new (part_fd, FALSE); - g_autoptr(GVariant) part = NULL; - if (!_ostree_static_delta_part_open (part_in, NULL, - OSTREE_STATIC_DELTA_OPEN_FLAGS_SKIP_CHECKSUM, - NULL, - &part, - cancellable, error)) + g_autoptr (GVariant) part = NULL; + if (!_ostree_static_delta_part_open (part_in, NULL, OSTREE_STATIC_DELTA_OPEN_FLAGS_SKIP_CHECKSUM, + NULL, &part, cancellable, error)) return FALSE; - { g_autoptr(GVariant) modes = NULL; - g_autoptr(GVariant) xattrs = NULL; - g_autoptr(GVariant) blob = NULL; - g_autoptr(GVariant) ops = NULL; - OstreeDeltaExecuteStats stats = { { 0, }, }; - - g_variant_get (part, "(@a(uuu)@aa(ayay)@ay@ay)", - &modes, &xattrs, &blob, &ops); - - g_print ("PartPayload%u: nmodes=%" G_GUINT64_FORMAT - " nxattrs=%" G_GUINT64_FORMAT - " blobsize=%" G_GUINT64_FORMAT - " opsize=%" G_GUINT64_FORMAT - "\n", - i, - (guint64)g_variant_n_children (modes), - (guint64)g_variant_n_children (xattrs), - (guint64)g_variant_n_children (blob), - (guint64)g_variant_n_children (ops)); - - if (!_ostree_static_delta_part_execute (self, objects, - part, TRUE, - &stats, cancellable, error)) + { + g_autoptr (GVariant) modes = NULL; + g_autoptr (GVariant) xattrs = NULL; + g_autoptr (GVariant) blob = NULL; + g_autoptr (GVariant) ops = NULL; + OstreeDeltaExecuteStats stats = { + { + 0, + }, + }; + + g_variant_get (part, "(@a(uuu)@aa(ayay)@ay@ay)", &modes, &xattrs, &blob, &ops); + + g_print ("PartPayload%u: nmodes=%" G_GUINT64_FORMAT " nxattrs=%" G_GUINT64_FORMAT + " blobsize=%" G_GUINT64_FORMAT " opsize=%" G_GUINT64_FORMAT "\n", + i, (guint64)g_variant_n_children (modes), (guint64)g_variant_n_children (xattrs), + (guint64)g_variant_n_children (blob), (guint64)g_variant_n_children (ops)); + + if (!_ostree_static_delta_part_execute (self, objects, part, TRUE, &stats, cancellable, error)) return FALSE; - { const guint *n_ops = stats.n_ops_executed; + { + const guint *n_ops = stats.n_ops_executed; g_print ("PartPayloadOps%u: openspliceclose=%u open=%u write=%u setread=%u " "unsetread=%u close=%u bspatch=%u\n", i, n_ops[0], n_ops[1], n_ops[2], n_ops[3], n_ops[4], n_ops[5], n_ops[6]); @@ -831,11 +790,10 @@ show_one_part (OstreeRepo *self, } OstreeDeltaEndianness -_ostree_delta_get_endianness (GVariant *superblock, - gboolean *out_was_heuristic) +_ostree_delta_get_endianness (GVariant *superblock, gboolean *out_was_heuristic) { - g_autoptr(GVariant) delta_meta = g_variant_get_child_value (superblock, 0); - g_autoptr(GVariantDict) delta_metadict = g_variant_dict_new (delta_meta); + g_autoptr (GVariant) delta_meta = g_variant_get_child_value (superblock, 0); + g_autoptr (GVariantDict) delta_metadict = g_variant_dict_new (delta_meta); if (out_was_heuristic) *out_was_heuristic = FALSE; @@ -860,7 +818,8 @@ _ostree_delta_get_endianness (GVariant *superblock, guint64 total_size = 0; guint64 total_usize = 0; guint total_objects = 0; - { g_autoptr(GVariant) meta_entries = NULL; + { + g_autoptr (GVariant) meta_entries = NULL; gboolean is_byteswapped = FALSE; g_variant_get_child (superblock, 6, "@a" OSTREE_STATIC_DELTA_META_ENTRY_FORMAT, &meta_entries); @@ -868,7 +827,7 @@ _ostree_delta_get_endianness (GVariant *superblock, for (guint i = 0; i < n_parts; i++) { - g_autoptr(GVariant) objects = NULL; + g_autoptr (GVariant) objects = NULL; guint64 size, usize; guint n_objects; @@ -881,9 +840,10 @@ _ostree_delta_get_endianness (GVariant *superblock, if (size > usize) { - double ratio = ((double)size)/((double)usize); + double ratio = ((double)size) / ((double)usize); - /* This should really never happen where compressing things makes it more than 50% bigger. + /* This should really never happen where compressing things makes it more than 50% + * bigger. */ if (ratio > 1.2) { @@ -939,10 +899,8 @@ _ostree_delta_needs_byteswap (GVariant *superblock) } gboolean -_ostree_repo_static_delta_delete (OstreeRepo *self, - const char *delta_id, - GCancellable *cancellable, - GError **error) +_ostree_repo_static_delta_delete (OstreeRepo *self, const char *delta_id, GCancellable *cancellable, + GError **error) { g_autofree char *from = NULL; g_autofree char *to = NULL; @@ -955,27 +913,23 @@ _ostree_repo_static_delta_delete (OstreeRepo *self, { if (errno == ENOENT) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "Can't find delta %s", delta_id); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Can't find delta %s", delta_id); return FALSE; } else return glnx_throw_errno_prefix (error, "fstatat(%s)", deltadir); } - if (!glnx_shutil_rm_rf_at (self->repo_dir_fd, deltadir, - cancellable, error)) + if (!glnx_shutil_rm_rf_at (self->repo_dir_fd, deltadir, cancellable, error)) return FALSE; return TRUE; } gboolean -_ostree_repo_static_delta_query_exists (OstreeRepo *self, - const char *delta_id, - gboolean *out_exists, - GCancellable *cancellable, - GError **error) +_ostree_repo_static_delta_query_exists (OstreeRepo *self, const char *delta_id, + gboolean *out_exists, GCancellable *cancellable, + GError **error) { g_autofree char *from = NULL; g_autofree char *to = NULL; @@ -991,14 +945,12 @@ _ostree_repo_static_delta_query_exists (OstreeRepo *self, } gboolean -_ostree_repo_static_delta_dump (OstreeRepo *self, - const char *delta_id, - GCancellable *cancellable, - GError **error) +_ostree_repo_static_delta_dump (OstreeRepo *self, const char *delta_id, GCancellable *cancellable, + GError **error) { glnx_autofd int superblock_fd = -1; - g_autoptr(GVariant) delta = NULL; - g_autoptr(GVariant) delta_superblock = NULL; + g_autoptr (GVariant) delta = NULL; + g_autoptr (GVariant) delta_superblock = NULL; if (strchr (delta_id, '/')) { @@ -1012,34 +964,35 @@ _ostree_repo_static_delta_dump (OstreeRepo *self, if (!_ostree_parse_delta_name (delta_id, &from, &to, error)) return FALSE; - g_autofree char *superblock_path = _ostree_get_relative_static_delta_superblock_path (from, to); + g_autofree char *superblock_path + = _ostree_get_relative_static_delta_superblock_path (from, to); if (!glnx_openat_rdonly (self->repo_dir_fd, superblock_path, TRUE, &superblock_fd, error)) return FALSE; } - gboolean is_signed = _ostree_repo_static_delta_is_signed(self, superblock_fd, NULL, NULL); + gboolean is_signed = _ostree_repo_static_delta_is_signed (self, superblock_fd, NULL, NULL); if (is_signed) { - if (!ot_variant_read_fd (superblock_fd, 0, (GVariantType*)OSTREE_STATIC_DELTA_SIGNED_FORMAT, + if (!ot_variant_read_fd (superblock_fd, 0, (GVariantType *)OSTREE_STATIC_DELTA_SIGNED_FORMAT, TRUE, &delta, error)) return FALSE; - g_autoptr(GVariant) child = g_variant_get_child_value (delta, 1); - g_autoptr(GBytes) bytes = g_variant_get_data_as_bytes(child); - delta_superblock = g_variant_new_from_bytes ((GVariantType*)OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT, - bytes, FALSE); + g_autoptr (GVariant) child = g_variant_get_child_value (delta, 1); + g_autoptr (GBytes) bytes = g_variant_get_data_as_bytes (child); + delta_superblock = g_variant_new_from_bytes ( + (GVariantType *)OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT, bytes, FALSE); } else { if (!ot_variant_read_fd (superblock_fd, 0, - (GVariantType*)OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT, - TRUE, &delta_superblock, error)) + (GVariantType *)OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT, TRUE, + &delta_superblock, error)) return FALSE; } g_print ("Delta: %s\n", delta_id); g_print ("Signed: %s\n", is_signed ? "yes" : "no"); - g_autoptr(GVariant) from_commit_v = NULL; + g_autoptr (GVariant) from_commit_v = NULL; g_variant_get_child (delta_superblock, 2, "@ay", &from_commit_v); g_autofree char *from_commit = NULL; if (g_variant_n_children (from_commit_v) > 0) @@ -1053,7 +1006,7 @@ _ostree_repo_static_delta_dump (OstreeRepo *self, { g_print ("From \n"); } - g_autoptr(GVariant) to_commit_v = NULL; + g_autoptr (GVariant) to_commit_v = NULL; g_variant_get_child (delta_superblock, 3, "@ay", &to_commit_v); if (!ostree_checksum_bytes_peek_validate (to_commit_v, error)) return FALSE; @@ -1062,7 +1015,8 @@ _ostree_repo_static_delta_dump (OstreeRepo *self, gboolean swap_endian = FALSE; OstreeDeltaEndianness endianness; - { const char *endianness_description; + { + const char *endianness_description; gboolean was_heuristic; endianness = _ostree_delta_get_endianness (delta_superblock, &was_heuristic); @@ -1099,11 +1053,12 @@ _ostree_repo_static_delta_dump (OstreeRepo *self, g_variant_get_child (delta_superblock, 1, "t", &ts); g_print ("Timestamp: %" G_GUINT64_FORMAT "\n", GUINT64_FROM_BE (ts)); - g_autoptr(GVariant) recurse = NULL; + g_autoptr (GVariant) recurse = NULL; g_variant_get_child (delta_superblock, 5, "@ay", &recurse); - g_print ("Number of parents: %u\n", (guint)(g_variant_get_size (recurse) / (OSTREE_SHA256_DIGEST_LEN * 2))); + g_print ("Number of parents: %u\n", + (guint)(g_variant_get_size (recurse) / (OSTREE_SHA256_DIGEST_LEN * 2))); - g_autoptr(GVariant) fallback = NULL; + g_autoptr (GVariant) fallback = NULL; g_variant_get_child (delta_superblock, 7, "@a" OSTREE_STATIC_DELTA_FALLBACK_FORMAT, &fallback); const guint n_fallback = g_variant_n_children (fallback); @@ -1114,8 +1069,8 @@ _ostree_repo_static_delta_dump (OstreeRepo *self, for (guint i = 0; i < n_fallback; i++) { guint64 size, usize; - g_autoptr(GVariant) checksum_v = NULL; - char checksum[OSTREE_SHA256_STRING_LEN+1]; + g_autoptr (GVariant) checksum_v = NULL; + char checksum[OSTREE_SHA256_STRING_LEN + 1]; g_variant_get_child (fallback, i, "(y@aytt)", NULL, &checksum_v, &size, &usize); ostree_checksum_inplace_from_bytes (ostree_checksum_bytes_peek (checksum_v), checksum); size = maybe_swap_endian_u64 (swap_endian, size); @@ -1124,34 +1079,38 @@ _ostree_repo_static_delta_dump (OstreeRepo *self, total_fallback_size += size; total_fallback_usize += usize; } - { g_autofree char *sizestr = g_format_size (total_fallback_size); + { + g_autofree char *sizestr = g_format_size (total_fallback_size); g_autofree char *usizestr = g_format_size (total_fallback_usize); g_print ("Total Fallback Size: %" G_GUINT64_FORMAT " (%s)\n", total_fallback_size, sizestr); - g_print ("Total Fallback Uncompressed Size: %" G_GUINT64_FORMAT " (%s)\n", total_fallback_usize, usizestr); + g_print ("Total Fallback Uncompressed Size: %" G_GUINT64_FORMAT " (%s)\n", total_fallback_usize, + usizestr); } - g_autoptr(GVariant) meta_entries = NULL; + g_autoptr (GVariant) meta_entries = NULL; guint n_parts; - g_variant_get_child (delta_superblock, 6, "@a" OSTREE_STATIC_DELTA_META_ENTRY_FORMAT, &meta_entries); + g_variant_get_child (delta_superblock, 6, "@a" OSTREE_STATIC_DELTA_META_ENTRY_FORMAT, + &meta_entries); n_parts = g_variant_n_children (meta_entries); g_print ("Number of parts: %u\n", n_parts); for (guint i = 0; i < n_parts; i++) { - if (!show_one_part (self, swap_endian, from_commit, to_commit, meta_entries, i, - &total_size, &total_usize, - cancellable, error)) + if (!show_one_part (self, swap_endian, from_commit, to_commit, meta_entries, i, &total_size, + &total_usize, cancellable, error)) return FALSE; } - { g_autofree char *sizestr = g_format_size (total_size); + { + g_autofree char *sizestr = g_format_size (total_size); g_autofree char *usizestr = g_format_size (total_usize); g_print ("Total Part Size: %" G_GUINT64_FORMAT " (%s)\n", total_size, sizestr); g_print ("Total Part Uncompressed Size: %" G_GUINT64_FORMAT " (%s)\n", total_usize, usizestr); } - { guint64 overall_size = total_size + total_fallback_size; + { + guint64 overall_size = total_size + total_fallback_size; guint64 overall_usize = total_usize + total_fallback_usize; g_autofree char *sizestr = g_format_size (overall_size); g_autofree char *usizestr = g_format_size (overall_usize); @@ -1178,13 +1137,10 @@ _ostree_repo_static_delta_dump (OstreeRepo *self, * Since: 2020.7 */ gboolean -ostree_repo_static_delta_verify_signature (OstreeRepo *self, - const char *delta_id, - OstreeSign *sign, - char **out_success_message, - GError **error) +ostree_repo_static_delta_verify_signature (OstreeRepo *self, const char *delta_id, OstreeSign *sign, + char **out_success_message, GError **error) { - g_autoptr(GVariant) delta_meta = NULL; + g_autoptr (GVariant) delta_meta = NULL; glnx_autofd int delta_fd = -1; if (strchr (delta_id, '/')) @@ -1207,7 +1163,8 @@ ostree_repo_static_delta_verify_signature (OstreeRepo *self, if (!_ostree_repo_static_delta_is_signed (self, delta_fd, NULL, error)) return FALSE; - return _ostree_repo_static_delta_verify_signature (self, delta_fd, sign, out_success_message, error); + return _ostree_repo_static_delta_verify_signature (self, delta_fd, sign, out_success_message, + error); } static void @@ -1218,10 +1175,7 @@ null_or_ptr_array_unref (GPtrArray *array) } static gboolean -file_has_content (OstreeRepo *repo, - const char *subpath, - GBytes *data, - GCancellable *cancellable) +file_has_content (OstreeRepo *repo, const char *subpath, GBytes *data, GCancellable *cancellable) { struct stat stbuf; glnx_autofd int existing_fd = -1; @@ -1235,7 +1189,7 @@ file_has_content (OstreeRepo *repo, if (!glnx_openat_rdonly (repo->repo_dir_fd, subpath, TRUE, &existing_fd, NULL)) return FALSE; - g_autoptr(GBytes) existing_data = glnx_fd_readall_bytes (existing_fd, cancellable, NULL); + g_autoptr (GBytes) existing_data = glnx_fd_readall_bytes (existing_fd, cancellable, NULL); if (existing_data == NULL) return FALSE; @@ -1255,48 +1209,48 @@ file_has_content (OstreeRepo *repo, * a particular commit (if @opt_to_commit is non-%NULL), or for all commits that * are reachable by an existing delta (if @opt_to_commit is %NULL). * - * This is normally called automatically when the summary is updated in ostree_repo_regenerate_summary(). + * This is normally called automatically when the summary is updated in + * ostree_repo_regenerate_summary(). * * Locking: shared * * Since: 2020.8 */ gboolean -ostree_repo_static_delta_reindex (OstreeRepo *repo, - OstreeStaticDeltaIndexFlags flags, - const char *opt_to_commit, - GCancellable *cancellable, - GError **error) +ostree_repo_static_delta_reindex (OstreeRepo *repo, OstreeStaticDeltaIndexFlags flags, + const char *opt_to_commit, GCancellable *cancellable, + GError **error) { - g_autoptr(GPtrArray) all_deltas = NULL; - g_autoptr(GHashTable) deltas_to_commit_ht = NULL; /* map: to checksum -> ptrarray of from checksums (or NULL) */ + g_autoptr (GPtrArray) all_deltas = NULL; + g_autoptr (GHashTable) deltas_to_commit_ht + = NULL; /* map: to checksum -> ptrarray of from checksums (or NULL) */ gboolean opt_indexed_deltas; /* Protect against parallel prune operation */ - g_autoptr(OstreeRepoAutoLock) lock = - ostree_repo_auto_lock_push (repo, OSTREE_REPO_LOCK_SHARED, cancellable, error); + g_autoptr (OstreeRepoAutoLock) lock + = ostree_repo_auto_lock_push (repo, OSTREE_REPO_LOCK_SHARED, cancellable, error); if (!lock) return FALSE; /* Enusre that the "indexed-deltas" option is set on the config, so we know this when pulling */ - if (!ot_keyfile_get_boolean_with_default (repo->config, "core", - "indexed-deltas", FALSE, + if (!ot_keyfile_get_boolean_with_default (repo->config, "core", "indexed-deltas", FALSE, &opt_indexed_deltas, error)) return FALSE; if (!opt_indexed_deltas) { - g_autoptr(GKeyFile) config = ostree_repo_copy_config (repo); + g_autoptr (GKeyFile) config = ostree_repo_copy_config (repo); g_key_file_set_boolean (config, "core", "indexed-deltas", TRUE); if (!ostree_repo_write_config (repo, config, error)) return FALSE; } - deltas_to_commit_ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)null_or_ptr_array_unref); + deltas_to_commit_ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, + (GDestroyNotify)null_or_ptr_array_unref); if (opt_to_commit == NULL) { - g_autoptr(GPtrArray) old_indexes = NULL; + g_autoptr (GPtrArray) old_indexes = NULL; /* To ensure all old index files either is regenerated, or * removed, we initialize all existing indexes to NULL in the @@ -1345,7 +1299,7 @@ ostree_repo_static_delta_reindex (OstreeRepo *repo, g_ptr_array_add (deltas_to_commit, g_steal_pointer (&from)); } - GLNX_HASH_TABLE_FOREACH_KV (deltas_to_commit_ht, const char*, to, GPtrArray*, froms) + GLNX_HASH_TABLE_FOREACH_KV (deltas_to_commit_ht, const char *, to, GPtrArray *, froms) { g_autofree char *index_path = _ostree_get_relative_static_delta_index_path (to); @@ -1359,10 +1313,10 @@ ostree_repo_static_delta_reindex (OstreeRepo *repo, } else { - g_auto(GVariantDict) index_builder = OT_VARIANT_BUILDER_INITIALIZER; - g_auto(GVariantDict) deltas_builder = OT_VARIANT_BUILDER_INITIALIZER; - g_autoptr(GVariant) index_variant = NULL; - g_autoptr(GBytes) index = NULL; + g_auto (GVariantDict) index_builder = OT_VARIANT_BUILDER_INITIALIZER; + g_auto (GVariantDict) deltas_builder = OT_VARIANT_BUILDER_INITIALIZER; + g_autoptr (GVariant) index_variant = NULL; + g_autoptr (GBytes) index = NULL; /* We sort on from here so that the index file is reproducible */ g_ptr_array_sort (froms, (GCompareFunc)g_strcmp0); @@ -1375,7 +1329,8 @@ ostree_repo_static_delta_reindex (OstreeRepo *repo, g_autofree char *delta_name = NULL; GVariant *digest; - digest = _ostree_repo_static_delta_superblock_digest (repo, from, to, cancellable, error); + digest = _ostree_repo_static_delta_superblock_digest (repo, from, to, cancellable, + error); if (digest == NULL) return FALSE; @@ -1387,28 +1342,31 @@ ostree_repo_static_delta_reindex (OstreeRepo *repo, g_variant_dict_insert_value (&deltas_builder, delta_name, digest); } - /* The toplevel of the index is an a{sv} for extensibility, and we use same key name (and format) as when - * storing deltas in the summary. */ + /* The toplevel of the index is an a{sv} for extensibility, and we use same key name (and + * format) as when storing deltas in the summary. */ g_variant_dict_init (&index_builder, NULL); - g_variant_dict_insert_value (&index_builder, OSTREE_SUMMARY_STATIC_DELTAS, g_variant_dict_end (&deltas_builder)); + g_variant_dict_insert_value (&index_builder, OSTREE_SUMMARY_STATIC_DELTAS, + g_variant_dict_end (&deltas_builder)); index_variant = g_variant_ref_sink (g_variant_dict_end (&index_builder)); index = g_variant_get_data_as_bytes (index_variant); g_autofree char *index_dirname = g_path_get_dirname (index_path); - if (!glnx_shutil_mkdir_p_at (repo->repo_dir_fd, index_dirname, DEFAULT_DIRECTORY_MODE, cancellable, error)) + if (!glnx_shutil_mkdir_p_at (repo->repo_dir_fd, index_dirname, DEFAULT_DIRECTORY_MODE, + cancellable, error)) return FALSE; - /* delta indexes are generally small and static, so reading it back and comparing is cheap, and it will - lower the write load (and particular sync-load) on the disk during reindexing (i.e. summary updates), */ + /* delta indexes are generally small and static, so reading it back and comparing is + cheap, and it will lower the write load (and particular sync-load) on the disk during + reindexing (i.e. summary updates), */ if (file_has_content (repo, index_path, index, cancellable)) continue; g_debug ("Updating delta index for %s", to); if (!glnx_file_replace_contents_at (repo->repo_dir_fd, index_path, - g_bytes_get_data (index, NULL), g_bytes_get_size (index), - 0, cancellable, error)) + g_bytes_get_data (index, NULL), + g_bytes_get_size (index), 0, cancellable, error)) return FALSE; } } diff --git a/src/libostree/ostree-repo-static-delta-private.h b/src/libostree/ostree-repo-static-delta-private.h index e1b4de3b..72208c2e 100644 --- a/src/libostree/ostree-repo-static-delta-private.h +++ b/src/libostree/ostree-repo-static-delta-private.h @@ -24,7 +24,7 @@ G_BEGIN_DECLS /* Arbitrarily chosen */ -#define OSTREE_STATIC_DELTA_PART_MAX_SIZE_BYTES (16*1024*1024) +#define OSTREE_STATIC_DELTA_PART_MAX_SIZE_BYTES (16 * 1024 * 1024) /* 1 byte for object type, 32 bytes for checksum */ #define OSTREE_STATIC_DELTA_OBJTYPE_CSUM_LEN 33 @@ -57,7 +57,6 @@ G_BEGIN_DECLS #define OSTREE_STATIC_DELTA_META_ENTRY_FORMAT "(uayttay)" - /** * OSTREE_STATIC_DELTA_FALLBACK_FORMAT: * @@ -100,7 +99,9 @@ G_BEGIN_DECLS * fetch individually - the compiler determined it wasn't worth * duplicating the space. */ -#define OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT "(a{sv}tayay" OSTREE_COMMIT_GVARIANT_STRING "aya" OSTREE_STATIC_DELTA_META_ENTRY_FORMAT "a" OSTREE_STATIC_DELTA_FALLBACK_FORMAT ")" +#define OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT \ + "(a{sv}tayay" OSTREE_COMMIT_GVARIANT_STRING "aya" OSTREE_STATIC_DELTA_META_ENTRY_FORMAT \ + "a" OSTREE_STATIC_DELTA_FALLBACK_FORMAT ")" /** * OSTREE_STATIC_DELTA_SIGNED_FORMAT @@ -119,15 +120,17 @@ G_BEGIN_DECLS */ #define OSTREE_STATIC_DELTA_SIGNED_FORMAT "(taya{sv})" -#define OSTREE_STATIC_DELTA_SIGNED_MAGIC 0x4F535453474E4454 /* OSTSGNDT */ +#define OSTREE_STATIC_DELTA_SIGNED_MAGIC 0x4F535453474E4454 /* OSTSGNDT */ -typedef enum { +typedef enum +{ OSTREE_STATIC_DELTA_OPEN_FLAGS_NONE = 0, OSTREE_STATIC_DELTA_OPEN_FLAGS_SKIP_CHECKSUM = (1 << 0), OSTREE_STATIC_DELTA_OPEN_FLAGS_VARIANT_TRUSTED = (1 << 1) } OstreeStaticDeltaOpenFlags; -typedef enum { +typedef enum +{ OSTREE_STATIC_DELTA_OP_OPEN_SPLICE_AND_CLOSE = 'S', OSTREE_STATIC_DELTA_OP_OPEN = 'o', OSTREE_STATIC_DELTA_OP_WRITE = 'w', @@ -138,52 +141,39 @@ typedef enum { } OstreeStaticDeltaOpCode; #define OSTREE_STATIC_DELTA_N_OPS 7 -gboolean -_ostree_static_delta_part_open (GInputStream *part_in, - GBytes *inline_part_bytes, - OstreeStaticDeltaOpenFlags flags, - const char *expected_checksum, - GVariant **out_part, - GCancellable *cancellable, - GError **error); +gboolean _ostree_static_delta_part_open (GInputStream *part_in, GBytes *inline_part_bytes, + OstreeStaticDeltaOpenFlags flags, + const char *expected_checksum, GVariant **out_part, + GCancellable *cancellable, GError **error); -typedef struct { +typedef struct +{ guint n_ops_executed[OSTREE_STATIC_DELTA_N_OPS]; } OstreeDeltaExecuteStats; -gboolean _ostree_static_delta_part_execute (OstreeRepo *repo, - GVariant *header, - GVariant *part_payload, - gboolean stats_only, +gboolean _ostree_static_delta_part_execute (OstreeRepo *repo, GVariant *header, + GVariant *part_payload, gboolean stats_only, OstreeDeltaExecuteStats *stats, - GCancellable *cancellable, - GError **error); - -void _ostree_static_delta_part_execute_async (OstreeRepo *repo, - GVariant *header, - GVariant *part_payload, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); - -gboolean _ostree_static_delta_part_execute_finish (OstreeRepo *repo, - GAsyncResult *result, - GError **error); - -gboolean -_ostree_static_delta_parse_checksum_array (GVariant *array, - guint8 **out_checksums_array, - guint *out_n_checksums, - GError **error); - -gboolean -_ostree_repo_static_delta_part_have_all_objects (OstreeRepo *repo, - GVariant *checksum_array, - gboolean *out_have_all, - GCancellable *cancellable, - GError **error); - -typedef struct { + GCancellable *cancellable, GError **error); + +void _ostree_static_delta_part_execute_async (OstreeRepo *repo, GVariant *header, + GVariant *part_payload, GCancellable *cancellable, + GAsyncReadyCallback callback, gpointer user_data); + +gboolean _ostree_static_delta_part_execute_finish (OstreeRepo *repo, GAsyncResult *result, + GError **error); + +gboolean _ostree_static_delta_parse_checksum_array (GVariant *array, guint8 **out_checksums_array, + guint *out_n_checksums, GError **error); + +gboolean _ostree_repo_static_delta_part_have_all_objects (OstreeRepo *repo, + GVariant *checksum_array, + gboolean *out_have_all, + GCancellable *cancellable, + GError **error); + +typedef struct +{ char *checksum; guint64 size; GPtrArray *basenames; @@ -191,45 +181,27 @@ typedef struct { void _ostree_delta_content_sizenames_free (gpointer v); -gboolean -_ostree_delta_compute_similar_objects (OstreeRepo *repo, - GVariant *from_commit, - GVariant *to_commit, - GHashTable *new_reachable_regfile_content, - guint similarity_percent_threshold, - GHashTable **out_modified_regfile_content, - GCancellable *cancellable, - GError **error); - -gboolean -_ostree_repo_static_delta_query_exists (OstreeRepo *repo, - const char *delta_id, - gboolean *out_exists, - GCancellable *cancellable, - GError **error); -GVariant * -_ostree_repo_static_delta_superblock_digest (OstreeRepo *repo, - const char *from, - const char *to, - GCancellable *cancellable, - GError **error); - -gboolean -_ostree_repo_static_delta_dump (OstreeRepo *repo, - const char *delta_id, - GCancellable *cancellable, - GError **error); - -gboolean -_ostree_repo_static_delta_delete (OstreeRepo *repo, - const char *delta_id, - GCancellable *cancellable, - GError **error); -gboolean -_ostree_repo_static_delta_reindex (OstreeRepo *repo, - const char *opt_to_commit, - GCancellable *cancellable, - GError **error); +gboolean _ostree_delta_compute_similar_objects (OstreeRepo *repo, GVariant *from_commit, + GVariant *to_commit, + GHashTable *new_reachable_regfile_content, + guint similarity_percent_threshold, + GHashTable **out_modified_regfile_content, + GCancellable *cancellable, GError **error); + +gboolean _ostree_repo_static_delta_query_exists (OstreeRepo *repo, const char *delta_id, + gboolean *out_exists, GCancellable *cancellable, + GError **error); +GVariant *_ostree_repo_static_delta_superblock_digest (OstreeRepo *repo, const char *from, + const char *to, GCancellable *cancellable, + GError **error); + +gboolean _ostree_repo_static_delta_dump (OstreeRepo *repo, const char *delta_id, + GCancellable *cancellable, GError **error); + +gboolean _ostree_repo_static_delta_delete (OstreeRepo *repo, const char *delta_id, + GCancellable *cancellable, GError **error); +gboolean _ostree_repo_static_delta_reindex (OstreeRepo *repo, const char *opt_to_commit, + GCancellable *cancellable, GError **error); /* Used for static deltas which due to a historical mistake are * inconsistent endian. @@ -237,8 +209,7 @@ _ostree_repo_static_delta_reindex (OstreeRepo *repo, * https://bugzilla.gnome.org/show_bug.cgi?id=762515 */ static inline guint32 -maybe_swap_endian_u32 (gboolean swap, - guint32 v) +maybe_swap_endian_u32 (gboolean swap, guint32 v) { if (!swap) return v; @@ -246,21 +217,22 @@ maybe_swap_endian_u32 (gboolean swap, } static inline guint64 -maybe_swap_endian_u64 (gboolean swap, - guint64 v) +maybe_swap_endian_u64 (gboolean swap, guint64 v) { if (!swap) return v; return GUINT64_SWAP_LE_BE (v); } -typedef enum { +typedef enum +{ OSTREE_DELTA_ENDIAN_BIG, OSTREE_DELTA_ENDIAN_LITTLE, OSTREE_DELTA_ENDIAN_INVALID } OstreeDeltaEndianness; -OstreeDeltaEndianness _ostree_delta_get_endianness (GVariant *superblock, gboolean *out_was_heuristic); +OstreeDeltaEndianness _ostree_delta_get_endianness (GVariant *superblock, + gboolean *out_was_heuristic); gboolean _ostree_delta_needs_byteswap (GVariant *superblock); diff --git a/src/libostree/ostree-repo-static-delta-processing.c b/src/libostree/ostree-repo-static-delta-processing.c index 47e6c064..94876fa4 100644 --- a/src/libostree/ostree-repo-static-delta-processing.c +++ b/src/libostree/ostree-repo-static-delta-processing.c @@ -22,93 +22,89 @@ #include -#include +#include #include #include -#include +#include +#include "bsdiff/bspatch.h" #include "ostree-core-private.h" +#include "ostree-lzma-decompressor.h" #include "ostree-repo-private.h" #include "ostree-repo-static-delta-private.h" -#include "ostree-lzma-decompressor.h" -#include "otutil.h" #include "ostree-varint.h" -#include "bsdiff/bspatch.h" +#include "otutil.h" /* This should really always be true, but hey, let's just assert it */ G_STATIC_ASSERT (sizeof (guint) >= sizeof (guint32)); -typedef struct { - gboolean stats_only; - OstreeRepo *repo; - guint checksum_index; - const guint8 *checksums; - guint n_checksums; +typedef struct +{ + gboolean stats_only; + OstreeRepo *repo; + guint checksum_index; + const guint8 *checksums; + guint n_checksums; - const guint8 *opdata; - guint oplen; + const guint8 *opdata; + guint oplen; - GVariant *mode_dict; - GVariant *xattr_dict; + GVariant *mode_dict; + GVariant *xattr_dict; - gboolean object_start; - gboolean caught_error; - GError **async_error; + gboolean object_start; + gboolean caught_error; + GError **async_error; OstreeObjectType output_objtype; - guint64 content_size; - char checksum[OSTREE_SHA256_STRING_LEN+1]; + guint64 content_size; + char checksum[OSTREE_SHA256_STRING_LEN + 1]; OstreeRepoBareContent content_out; - char *read_source_object; - int read_source_fd; - gboolean have_obj; - guint32 uid; - guint32 gid; - guint32 mode; - GVariant *xattrs; - - const guint8 *output_target; - const guint8 *input_target_csum; - - const guint8 *payload_data; - guint64 payload_size; + char *read_source_object; + int read_source_fd; + gboolean have_obj; + guint32 uid; + guint32 gid; + guint32 mode; + GVariant *xattrs; + + const guint8 *output_target; + const guint8 *input_target_csum; + + const guint8 *payload_data; + guint64 payload_size; } StaticDeltaExecutionState; -typedef struct { +typedef struct +{ StaticDeltaExecutionState *state; - char checksum[OSTREE_SHA256_STRING_LEN+1]; + char checksum[OSTREE_SHA256_STRING_LEN + 1]; } StaticDeltaContentWrite; -typedef gboolean (*DispatchOpFunc) (OstreeRepo *repo, - StaticDeltaExecutionState *state, - GCancellable *cancellable, - GError **error); +typedef gboolean (*DispatchOpFunc) (OstreeRepo *repo, StaticDeltaExecutionState *state, + GCancellable *cancellable, GError **error); #define OPPROTO(name) \ - static gboolean dispatch_##name (OstreeRepo *repo, \ - StaticDeltaExecutionState *state, \ - GCancellable *cancellable, \ - GError **error); - -OPPROTO(open_splice_and_close) -OPPROTO(open) -OPPROTO(write) -OPPROTO(set_read_source) -OPPROTO(unset_read_source) -OPPROTO(close) -OPPROTO(bspatch) + static gboolean dispatch_##name (OstreeRepo *repo, StaticDeltaExecutionState *state, \ + GCancellable *cancellable, GError **error); + +OPPROTO (open_splice_and_close) +OPPROTO (open) +OPPROTO (write) +OPPROTO (set_read_source) +OPPROTO (unset_read_source) +OPPROTO (close) +OPPROTO (bspatch) #undef OPPROTO static void -static_delta_execution_state_init (StaticDeltaExecutionState *state) +static_delta_execution_state_init (StaticDeltaExecutionState *state) { state->read_source_fd = -1; } static gboolean -read_varuint64 (StaticDeltaExecutionState *state, - guint64 *out_value, - GError **error) +read_varuint64 (StaticDeltaExecutionState *state, guint64 *out_value, GError **error) { gsize bytes_read; if (!_ostree_read_varuint64 (state->opdata, state->oplen, out_value, &bytes_read)) @@ -121,20 +117,19 @@ read_varuint64 (StaticDeltaExecutionState *state, } static gboolean -open_output_target (StaticDeltaExecutionState *state, - GCancellable *cancellable, - GError **error) +open_output_target (StaticDeltaExecutionState *state, GCancellable *cancellable, GError **error) { g_assert (state->checksums != NULL); g_assert (state->output_target == NULL); g_assert (state->checksum_index < state->n_checksums); - guint8 *objcsum = (guint8*)state->checksums + (state->checksum_index * OSTREE_STATIC_DELTA_OBJTYPE_CSUM_LEN); + guint8 *objcsum + = (guint8 *)state->checksums + (state->checksum_index * OSTREE_STATIC_DELTA_OBJTYPE_CSUM_LEN); - if (G_UNLIKELY(!ostree_validate_structureof_objtype (*objcsum, error))) + if (G_UNLIKELY (!ostree_validate_structureof_objtype (*objcsum, error))) return FALSE; - state->output_objtype = (OstreeObjectType) *objcsum; + state->output_objtype = (OstreeObjectType)*objcsum; state->output_target = objcsum + 1; ostree_checksum_inplace_from_bytes (state->output_target, state->checksum); @@ -167,21 +162,19 @@ delta_opcode_index (OstreeStaticDeltaOpCode op) } gboolean -_ostree_static_delta_part_execute (OstreeRepo *repo, - GVariant *objects, - GVariant *part, - gboolean stats_only, - OstreeDeltaExecuteStats *stats, - GCancellable *cancellable, - GError **error) +_ostree_static_delta_part_execute (OstreeRepo *repo, GVariant *objects, GVariant *part, + gboolean stats_only, OstreeDeltaExecuteStats *stats, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; guint8 *checksums_data; - g_autoptr(GVariant) mode_dict = NULL; - g_autoptr(GVariant) xattr_dict = NULL; - g_autoptr(GVariant) payload = NULL; - g_autoptr(GVariant) ops = NULL; - StaticDeltaExecutionState statedata = { 0, }; + g_autoptr (GVariant) mode_dict = NULL; + g_autoptr (GVariant) xattr_dict = NULL; + g_autoptr (GVariant) payload = NULL; + g_autoptr (GVariant) ops = NULL; + StaticDeltaExecutionState statedata = { + 0, + }; StaticDeltaExecutionState *state = &statedata; guint n_executed = 0; @@ -191,9 +184,7 @@ _ostree_static_delta_part_execute (OstreeRepo *repo, state->async_error = error; state->stats_only = stats_only; - if (!_ostree_static_delta_parse_checksum_array (objects, - &checksums_data, - &state->n_checksums, + if (!_ostree_static_delta_parse_checksum_array (objects, &checksums_data, &state->n_checksums, error)) goto out; @@ -206,10 +197,7 @@ _ostree_static_delta_part_execute (OstreeRepo *repo, state->checksums = checksums_data; - g_variant_get (part, "(@a(uuu)@aa(ayay)@ay@ay)", - &mode_dict, - &xattr_dict, - &payload, &ops); + g_variant_get (part, "(@a(uuu)@aa(ayay)@ay@ay)", &mode_dict, &xattr_dict, &payload, &ops); state->mode_dict = mode_dict; state->xattr_dict = xattr_dict; @@ -269,19 +257,20 @@ _ostree_static_delta_part_execute (OstreeRepo *repo, n_executed++; if (stats) - stats->n_ops_executed[delta_opcode_index(opcode)]++; + stats->n_ops_executed[delta_opcode_index (opcode)]++; } if (state->caught_error) goto out; ret = TRUE; - out: +out: _ostree_repo_bare_content_cleanup (&state->content_out); return ret; } -typedef struct { +typedef struct +{ OstreeRepo *repo; GVariant *header; GVariant *part; @@ -301,18 +290,13 @@ static_delta_part_execute_async_data_free (gpointer user_data) } static void -static_delta_part_execute_thread (GTask *task, - GObject *object, - gpointer datap, - GCancellable *cancellable) +static_delta_part_execute_thread (GTask *task, GObject *object, gpointer datap, + GCancellable *cancellable) { GError *error = NULL; StaticDeltaPartExecuteAsyncData *data = datap; - if (!_ostree_static_delta_part_execute (data->repo, - data->header, - data->part, - FALSE, NULL, + if (!_ostree_static_delta_part_execute (data->repo, data->header, data->part, FALSE, NULL, cancellable, &error)) g_task_return_error (task, error); else @@ -320,14 +304,11 @@ static_delta_part_execute_thread (GTask *task, } void -_ostree_static_delta_part_execute_async (OstreeRepo *repo, - GVariant *header, - GVariant *part, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +_ostree_static_delta_part_execute_async (OstreeRepo *repo, GVariant *header, GVariant *part, + GCancellable *cancellable, GAsyncReadyCallback callback, + gpointer user_data) { - g_autoptr(GTask) task = NULL; + g_autoptr (GTask) task = NULL; StaticDeltaPartExecuteAsyncData *asyncdata; asyncdata = g_new0 (StaticDeltaPartExecuteAsyncData, 1); @@ -343,41 +324,34 @@ _ostree_static_delta_part_execute_async (OstreeRepo *repo, } gboolean -_ostree_static_delta_part_execute_finish (OstreeRepo *repo, - GAsyncResult *result, - GError **error) +_ostree_static_delta_part_execute_finish (OstreeRepo *repo, GAsyncResult *result, GError **error) { g_return_val_if_fail (OSTREE_IS_REPO (repo), FALSE); g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); g_return_val_if_fail (g_task_is_valid (result, repo), FALSE); - g_return_val_if_fail (g_async_result_is_tagged (result, _ostree_static_delta_part_execute_async), FALSE); + g_return_val_if_fail (g_async_result_is_tagged (result, _ostree_static_delta_part_execute_async), + FALSE); return g_task_propagate_boolean (G_TASK (result), error); } static gboolean -validate_ofs (StaticDeltaExecutionState *state, - guint64 offset, - guint64 length, - GError **error) +validate_ofs (StaticDeltaExecutionState *state, guint64 offset, guint64 length, GError **error) { - if (G_UNLIKELY (offset + length < offset || - offset + length > state->payload_size)) + if (G_UNLIKELY (offset + length < offset || offset + length > state->payload_size)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, - "Invalid offset/length %" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, - offset, length); + "Invalid offset/length %" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, offset, + length); return FALSE; } return TRUE; } static gboolean -do_content_open_generic (OstreeRepo *repo, - StaticDeltaExecutionState *state, - GCancellable *cancellable, - GError **error) +do_content_open_generic (OstreeRepo *repo, StaticDeltaExecutionState *state, + GCancellable *cancellable, GError **error) { guint64 mode_offset; guint64 xattr_offset; @@ -387,7 +361,7 @@ do_content_open_generic (OstreeRepo *repo, if (!read_varuint64 (state, &xattr_offset, error)) return FALSE; - g_autoptr(GVariant) modev = g_variant_get_child_value (state->mode_dict, mode_offset); + g_autoptr (GVariant) modev = g_variant_get_child_value (state->mode_dict, mode_offset); guint32 uid, gid, mode; g_variant_get (modev, "(uuu)", &uid, &gid, &mode); state->uid = GUINT32_FROM_BE (uid); @@ -401,12 +375,12 @@ do_content_open_generic (OstreeRepo *repo, struct bzpatch_opaque_s { - StaticDeltaExecutionState *state; + StaticDeltaExecutionState *state; guint64 offset, length; }; static int -bspatch_read (const struct bspatch_stream* stream, void* buffer, int length) +bspatch_read (const struct bspatch_stream *stream, void *buffer, int length) { struct bzpatch_opaque_s *opaque = stream->opaque; @@ -420,10 +394,8 @@ bspatch_read (const struct bspatch_stream* stream, void* buffer, int length) } static gboolean -dispatch_bspatch (OstreeRepo *repo, - StaticDeltaExecutionState *state, - GCancellable *cancellable, - GError **error) +dispatch_bspatch (OstreeRepo *repo, StaticDeltaExecutionState *state, GCancellable *cancellable, + GError **error) { guint64 offset, length; @@ -437,7 +409,8 @@ dispatch_bspatch (OstreeRepo *repo, if (!state->have_obj) { - g_autoptr(GMappedFile) input_mfile = g_mapped_file_new_from_fd (state->read_source_fd, FALSE, error); + g_autoptr (GMappedFile) input_mfile + = g_mapped_file_new_from_fd (state->read_source_fd, FALSE, error); if (!input_mfile) return FALSE; @@ -450,15 +423,12 @@ dispatch_bspatch (OstreeRepo *repo, struct bspatch_stream stream; stream.read = bspatch_read; stream.opaque = &opaque; - if (bspatch ((const guint8*)g_mapped_file_get_contents (input_mfile), - g_mapped_file_get_length (input_mfile), - buf, - state->content_size, - &stream) < 0) + if (bspatch ((const guint8 *)g_mapped_file_get_contents (input_mfile), + g_mapped_file_get_length (input_mfile), buf, state->content_size, &stream) + < 0) return glnx_throw (error, "bsdiff patch failed"); - if (!_ostree_repo_bare_content_write (repo, &state->content_out, - buf, state->content_size, + if (!_ostree_repo_bare_content_write (repo, &state->content_out, buf, state->content_size, cancellable, error)) return FALSE; } @@ -467,10 +437,8 @@ dispatch_bspatch (OstreeRepo *repo, } static gboolean -dispatch_open_splice_and_close (OstreeRepo *repo, - StaticDeltaExecutionState *state, - GCancellable *cancellable, - GError **error) +dispatch_open_splice_and_close (OstreeRepo *repo, StaticDeltaExecutionState *state, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; @@ -479,7 +447,7 @@ dispatch_open_splice_and_close (OstreeRepo *repo, if (OSTREE_OBJECT_TYPE_IS_META (state->output_objtype)) { - g_autoptr(GVariant) metadata = NULL; + g_autoptr (GVariant) metadata = NULL; guint64 offset; guint64 length; @@ -500,18 +468,15 @@ dispatch_open_splice_and_close (OstreeRepo *repo, * and we didn't guarantee that in static deltas. We can do so in the * future. */ - g_autoptr(GBytes) metadata_copy = g_bytes_new (state->payload_data + offset, length); + g_autoptr (GBytes) metadata_copy = g_bytes_new (state->payload_data + offset, length); metadata = g_variant_new_from_bytes (ostree_metadata_variant_type (state->output_objtype), metadata_copy, FALSE); { g_autofree guchar *actual_csum = NULL; - if (!ostree_repo_write_metadata (state->repo, state->output_objtype, - state->checksum, - metadata, &actual_csum, - cancellable, - error)) + if (!ostree_repo_write_metadata (state->repo, state->output_objtype, state->checksum, + metadata, &actual_csum, cancellable, error)) goto out; } } @@ -519,8 +484,8 @@ dispatch_open_splice_and_close (OstreeRepo *repo, { guint64 content_offset; guint64 objlen; - g_autoptr(GInputStream) object_input = NULL; - g_autoptr(GInputStream) memin = NULL; + g_autoptr (GInputStream) object_input = NULL; + g_autoptr (GInputStream) memin = NULL; if (!do_content_open_generic (repo, state, cancellable, error)) goto out; @@ -539,8 +504,7 @@ dispatch_open_splice_and_close (OstreeRepo *repo, } /* Fast path for regular files to bare repositories */ - if (S_ISREG (state->mode) && - _ostree_repo_mode_is_bare (repo->mode)) + if (S_ISREG (state->mode) && _ostree_repo_mode_is_bare (repo->mode)) { if (!ostree_repo_has_object (repo, OSTREE_OBJECT_TYPE_FILE, state->checksum, &state->have_obj, cancellable, error)) @@ -548,54 +512,45 @@ dispatch_open_splice_and_close (OstreeRepo *repo, if (!state->have_obj) { - if (!_ostree_repo_bare_content_open (repo, state->checksum, - state->content_size, - state->uid, state->gid, state->mode, - state->xattrs, - &state->content_out, - cancellable, error)) + if (!_ostree_repo_bare_content_open ( + repo, state->checksum, state->content_size, state->uid, state->gid, + state->mode, state->xattrs, &state->content_out, cancellable, error)) goto out; if (!_ostree_repo_bare_content_write (repo, &state->content_out, state->payload_data + content_offset, - state->content_size, - cancellable, error)) + state->content_size, cancellable, error)) goto out; } } else { /* Slower path, for symlinks and unpacking deltas into archive */ - g_autoptr(GFileInfo) finfo = - _ostree_mode_uidgid_to_gfileinfo (state->mode, state->uid, state->gid); + g_autoptr (GFileInfo) finfo + = _ostree_mode_uidgid_to_gfileinfo (state->mode, state->uid, state->gid); if (S_ISLNK (state->mode)) { - g_autofree char *nulterminated_target = - g_strndup ((char*)state->payload_data + content_offset, state->content_size); + g_autofree char *nulterminated_target + = g_strndup ((char *)state->payload_data + content_offset, state->content_size); g_file_info_set_symlink_target (finfo, nulterminated_target); } else { g_assert (S_ISREG (state->mode)); g_file_info_set_size (finfo, state->content_size); - memin = g_memory_input_stream_new_from_data (state->payload_data + content_offset, state->content_size, NULL); + memin = g_memory_input_stream_new_from_data (state->payload_data + content_offset, + state->content_size, NULL); } - if (!ostree_raw_file_to_content_stream (memin, finfo, state->xattrs, - &object_input, &objlen, - cancellable, error)) + if (!ostree_raw_file_to_content_stream (memin, finfo, state->xattrs, &object_input, + &objlen, cancellable, error)) goto out; { g_autofree guchar *actual_csum = NULL; - if (!ostree_repo_write_content (state->repo, - state->checksum, - object_input, - objlen, - &actual_csum, - cancellable, - error)) + if (!ostree_repo_write_content (state->repo, state->checksum, object_input, objlen, + &actual_csum, cancellable, error)) goto out; } } @@ -605,29 +560,26 @@ dispatch_open_splice_and_close (OstreeRepo *repo, goto out; ret = TRUE; - out: +out: if (state->stats_only) - (void) dispatch_close (repo, state, cancellable, NULL); + (void)dispatch_close (repo, state, cancellable, NULL); if (!ret) g_prefix_error (error, "opcode open-splice-and-close: "); return ret; } static gboolean -dispatch_open (OstreeRepo *repo, - StaticDeltaExecutionState *state, - GCancellable *cancellable, - GError **error) +dispatch_open (OstreeRepo *repo, StaticDeltaExecutionState *state, GCancellable *cancellable, + GError **error) { - GLNX_AUTO_PREFIX_ERROR("opcode open", error); + GLNX_AUTO_PREFIX_ERROR ("opcode open", error); g_assert (state->output_target == NULL); /* FIXME - lift this restriction */ if (!state->stats_only) { - g_assert (repo->mode == OSTREE_REPO_MODE_BARE || - repo->mode == OSTREE_REPO_MODE_BARE_USER || - repo->mode == OSTREE_REPO_MODE_BARE_USER_ONLY); + g_assert (repo->mode == OSTREE_REPO_MODE_BARE || repo->mode == OSTREE_REPO_MODE_BARE_USER + || repo->mode == OSTREE_REPO_MODE_BARE_USER_ONLY); } if (!open_output_target (state, cancellable, error)) @@ -642,18 +594,15 @@ dispatch_open (OstreeRepo *repo, if (state->stats_only) return TRUE; /* Early return */ - if (!ostree_repo_has_object (repo, OSTREE_OBJECT_TYPE_FILE, state->checksum, - &state->have_obj, cancellable, error)) + if (!ostree_repo_has_object (repo, OSTREE_OBJECT_TYPE_FILE, state->checksum, &state->have_obj, + cancellable, error)) return FALSE; if (!state->have_obj) { - if (!_ostree_repo_bare_content_open (repo, state->checksum, - state->content_size, - state->uid, state->gid, state->mode, - state->xattrs, - &state->content_out, - cancellable, error)) + if (!_ostree_repo_bare_content_open (repo, state->checksum, state->content_size, state->uid, + state->gid, state->mode, state->xattrs, + &state->content_out, cancellable, error)) return FALSE; } @@ -661,12 +610,10 @@ dispatch_open (OstreeRepo *repo, } static gboolean -dispatch_write (OstreeRepo *repo, - StaticDeltaExecutionState *state, - GCancellable *cancellable, - GError **error) +dispatch_write (OstreeRepo *repo, StaticDeltaExecutionState *state, GCancellable *cancellable, + GError **error) { - GLNX_AUTO_PREFIX_ERROR("opcode write", error); + GLNX_AUTO_PREFIX_ERROR ("opcode write", error); guint64 content_size; guint64 content_offset; @@ -688,16 +635,17 @@ dispatch_write (OstreeRepo *repo, gssize bytes_read; do - bytes_read = pread (state->read_source_fd, buf, MIN(sizeof(buf), content_size), content_offset); + bytes_read = pread (state->read_source_fd, buf, MIN (sizeof (buf), content_size), + content_offset); while (G_UNLIKELY (bytes_read == -1 && errno == EINTR)); if (bytes_read == -1) return glnx_throw_errno_prefix (error, "read"); if (G_UNLIKELY (bytes_read == 0)) - return glnx_throw (error, "Unexpected EOF reading object %s", state->read_source_object); + return glnx_throw (error, "Unexpected EOF reading object %s", + state->read_source_object); - if (!_ostree_repo_bare_content_write (repo, &state->content_out, - (guint8*)buf, bytes_read, - cancellable, error)) + if (!_ostree_repo_bare_content_write (repo, &state->content_out, (guint8 *)buf, + bytes_read, cancellable, error)) return FALSE; content_size -= bytes_read; @@ -720,12 +668,10 @@ dispatch_write (OstreeRepo *repo, } static gboolean -dispatch_set_read_source (OstreeRepo *repo, - StaticDeltaExecutionState *state, - GCancellable *cancellable, - GError **error) +dispatch_set_read_source (OstreeRepo *repo, StaticDeltaExecutionState *state, + GCancellable *cancellable, GError **error) { - GLNX_AUTO_PREFIX_ERROR("opcode set-read-source", error); + GLNX_AUTO_PREFIX_ERROR ("opcode set-read-source", error); guint64 source_offset; glnx_close_fd (&state->read_source_fd); @@ -741,22 +687,18 @@ dispatch_set_read_source (OstreeRepo *repo, g_free (state->read_source_object); state->read_source_object = ostree_checksum_from_bytes (state->payload_data + source_offset); - if (!_ostree_repo_load_file_bare (repo, state->read_source_object, - &state->read_source_fd, - NULL, NULL, NULL, - cancellable, error)) + if (!_ostree_repo_load_file_bare (repo, state->read_source_object, &state->read_source_fd, NULL, + NULL, NULL, cancellable, error)) return FALSE; return TRUE; } static gboolean -dispatch_unset_read_source (OstreeRepo *repo, - StaticDeltaExecutionState *state, - GCancellable *cancellable, - GError **error) +dispatch_unset_read_source (OstreeRepo *repo, StaticDeltaExecutionState *state, + GCancellable *cancellable, GError **error) { - GLNX_AUTO_PREFIX_ERROR("opcode unset-read-source", error); + GLNX_AUTO_PREFIX_ERROR ("opcode unset-read-source", error); if (state->stats_only) return TRUE; /* Early return */ @@ -768,19 +710,16 @@ dispatch_unset_read_source (OstreeRepo *repo, } static gboolean -dispatch_close (OstreeRepo *repo, - StaticDeltaExecutionState *state, - GCancellable *cancellable, - GError **error) +dispatch_close (OstreeRepo *repo, StaticDeltaExecutionState *state, GCancellable *cancellable, + GError **error) { - GLNX_AUTO_PREFIX_ERROR("opcode close", error); + GLNX_AUTO_PREFIX_ERROR ("opcode close", error); if (state->content_out.initialized) { - char actual_checksum[OSTREE_SHA256_STRING_LEN+1]; + char actual_checksum[OSTREE_SHA256_STRING_LEN + 1]; if (!_ostree_repo_bare_content_commit (repo, &state->content_out, actual_checksum, - sizeof (actual_checksum), - cancellable, error)) + sizeof (actual_checksum), cancellable, error)) return FALSE; g_assert_cmpstr (state->checksum, ==, actual_checksum); diff --git a/src/libostree/ostree-repo-traverse.c b/src/libostree/ostree-repo-traverse.c index 6de36f86..08172b8c 100644 --- a/src/libostree/ostree-repo-traverse.c +++ b/src/libostree/ostree-repo-traverse.c @@ -25,7 +25,8 @@ #include "ostree.h" #include "otutil.h" -struct _OstreeRepoRealCommitTraverseIter { +struct _OstreeRepoRealCommitTraverseIter +{ gboolean initialized; OstreeRepo *repo; GVariant *commit; @@ -33,8 +34,8 @@ struct _OstreeRepoRealCommitTraverseIter { const char *name; OstreeRepoCommitIterResult state; guint idx; - char checksum_content[OSTREE_SHA256_STRING_LEN+1]; - char checksum_meta[OSTREE_SHA256_STRING_LEN+1]; + char checksum_content[OSTREE_SHA256_STRING_LEN + 1]; + char checksum_meta[OSTREE_SHA256_STRING_LEN + 1]; }; /** @@ -48,14 +49,11 @@ struct _OstreeRepoRealCommitTraverseIter { * Initialize (in place) an iterator over the root of a commit object. */ gboolean -ostree_repo_commit_traverse_iter_init_commit (OstreeRepoCommitTraverseIter *iter, - OstreeRepo *repo, - GVariant *commit, - OstreeRepoCommitTraverseFlags flags, - GError **error) +ostree_repo_commit_traverse_iter_init_commit (OstreeRepoCommitTraverseIter *iter, OstreeRepo *repo, + GVariant *commit, OstreeRepoCommitTraverseFlags flags, + GError **error) { - struct _OstreeRepoRealCommitTraverseIter *real = - (struct _OstreeRepoRealCommitTraverseIter*)iter; + struct _OstreeRepoRealCommitTraverseIter *real = (struct _OstreeRepoRealCommitTraverseIter *)iter; memset (real, 0, sizeof (*real)); real->initialized = TRUE; @@ -64,14 +62,14 @@ ostree_repo_commit_traverse_iter_init_commit (OstreeRepoCommitTraverseIter *it real->current_dir = NULL; real->idx = 0; - g_autoptr(GVariant) content_csum_bytes = NULL; + g_autoptr (GVariant) content_csum_bytes = NULL; g_variant_get_child (commit, 6, "@ay", &content_csum_bytes); const guchar *csum = ostree_checksum_bytes_peek_validate (content_csum_bytes, error); if (!csum) return FALSE; ostree_checksum_inplace_from_bytes (csum, real->checksum_content); - g_autoptr(GVariant) meta_csum_bytes = NULL; + g_autoptr (GVariant) meta_csum_bytes = NULL; g_variant_get_child (commit, 7, "@ay", &meta_csum_bytes); csum = ostree_checksum_bytes_peek_validate (meta_csum_bytes, error); if (!csum) @@ -92,14 +90,11 @@ ostree_repo_commit_traverse_iter_init_commit (OstreeRepoCommitTraverseIter *it * Initialize (in place) an iterator over a directory tree. */ gboolean -ostree_repo_commit_traverse_iter_init_dirtree (OstreeRepoCommitTraverseIter *iter, - OstreeRepo *repo, - GVariant *dirtree, - OstreeRepoCommitTraverseFlags flags, - GError **error) +ostree_repo_commit_traverse_iter_init_dirtree (OstreeRepoCommitTraverseIter *iter, OstreeRepo *repo, + GVariant *dirtree, + OstreeRepoCommitTraverseFlags flags, GError **error) { - struct _OstreeRepoRealCommitTraverseIter *real = - (struct _OstreeRepoRealCommitTraverseIter*)iter; + struct _OstreeRepoRealCommitTraverseIter *real = (struct _OstreeRepoRealCommitTraverseIter *)iter; memset (real, 0, sizeof (*real)); real->initialized = TRUE; @@ -131,19 +126,15 @@ ostree_repo_commit_traverse_iter_init_dirtree (OstreeRepoCommitTraverseIter *i */ OstreeRepoCommitIterResult ostree_repo_commit_traverse_iter_next (OstreeRepoCommitTraverseIter *iter, - GCancellable *cancellable, - GError **error) + GCancellable *cancellable, GError **error) { - struct _OstreeRepoRealCommitTraverseIter *real = - (struct _OstreeRepoRealCommitTraverseIter*)iter; + struct _OstreeRepoRealCommitTraverseIter *real = (struct _OstreeRepoRealCommitTraverseIter *)iter; OstreeRepoCommitIterResult res = OSTREE_REPO_COMMIT_ITER_RESULT_ERROR; if (!real->current_dir) { if (!ostree_repo_load_variant (real->repo, OSTREE_OBJECT_TYPE_DIR_TREE, - real->checksum_content, - &real->current_dir, - error)) + real->checksum_content, &real->current_dir, error)) goto out; res = OSTREE_REPO_COMMIT_ITER_RESULT_DIR; } @@ -153,10 +144,10 @@ ostree_repo_commit_traverse_iter_next (OstreeRepoCommitTraverseIter *iter, guint ndirs; guint idx; const guchar *csum; - g_autoptr(GVariant) content_csum_v = NULL; - g_autoptr(GVariant) meta_csum_v = 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; + g_autoptr (GVariant) files_variant = NULL; + g_autoptr (GVariant) dirs_variant = NULL; files_variant = g_variant_get_child_value (real->current_dir, 0); dirs_variant = g_variant_get_child_value (real->current_dir, 1); @@ -166,9 +157,7 @@ ostree_repo_commit_traverse_iter_next (OstreeRepoCommitTraverseIter *iter, if (real->idx < nfiles) { idx = real->idx; - g_variant_get_child (files_variant, idx, "(&s@ay)", - &real->name, - &content_csum_v); + g_variant_get_child (files_variant, idx, "(&s@ay)", &real->name, &content_csum_v); csum = ostree_checksum_bytes_peek_validate (content_csum_v, error); if (!csum) @@ -183,8 +172,8 @@ ostree_repo_commit_traverse_iter_next (OstreeRepoCommitTraverseIter *iter, { idx = real->idx - nfiles; - g_variant_get_child (dirs_variant, idx, "(&s@ay@ay)", - &real->name, &content_csum_v, &meta_csum_v); + g_variant_get_child (dirs_variant, idx, "(&s@ay@ay)", &real->name, &content_csum_v, + &meta_csum_v); csum = ostree_checksum_bytes_peek_validate (content_csum_v, error); if (!csum) @@ -205,7 +194,7 @@ ostree_repo_commit_traverse_iter_next (OstreeRepoCommitTraverseIter *iter, } real->state = res; - out: +out: return res; } @@ -220,14 +209,12 @@ ostree_repo_commit_traverse_iter_next (OstreeRepoCommitTraverseIter *iter, * ostree_repo_commit_traverse_iter_next(). */ void -ostree_repo_commit_traverse_iter_get_file (OstreeRepoCommitTraverseIter *iter, - char **out_name, - char **out_checksum) +ostree_repo_commit_traverse_iter_get_file (OstreeRepoCommitTraverseIter *iter, char **out_name, + char **out_checksum) { - struct _OstreeRepoRealCommitTraverseIter *real = - (struct _OstreeRepoRealCommitTraverseIter*)iter; - *out_name = (char*)real->name; - *out_checksum = (char*)real->checksum_content; + struct _OstreeRepoRealCommitTraverseIter *real = (struct _OstreeRepoRealCommitTraverseIter *)iter; + *out_name = (char *)real->name; + *out_checksum = (char *)real->checksum_content; } /** @@ -242,23 +229,19 @@ ostree_repo_commit_traverse_iter_get_file (OstreeRepoCommitTraverseIter *iter, * from ostree_repo_commit_traverse_iter_next(). */ void -ostree_repo_commit_traverse_iter_get_dir (OstreeRepoCommitTraverseIter *iter, - char **out_name, - char **out_content_checksum, - char **out_meta_checksum) +ostree_repo_commit_traverse_iter_get_dir (OstreeRepoCommitTraverseIter *iter, char **out_name, + char **out_content_checksum, char **out_meta_checksum) { - struct _OstreeRepoRealCommitTraverseIter *real = - (struct _OstreeRepoRealCommitTraverseIter*)iter; - *out_name = (char*)real->name; - *out_content_checksum = (char*)real->checksum_content; - *out_meta_checksum = (char*)real->checksum_meta; + struct _OstreeRepoRealCommitTraverseIter *real = (struct _OstreeRepoRealCommitTraverseIter *)iter; + *out_name = (char *)real->name; + *out_content_checksum = (char *)real->checksum_content; + *out_meta_checksum = (char *)real->checksum_meta; } void ostree_repo_commit_traverse_iter_clear (OstreeRepoCommitTraverseIter *iter) { - struct _OstreeRepoRealCommitTraverseIter *real = - (struct _OstreeRepoRealCommitTraverseIter*)iter; + struct _OstreeRepoRealCommitTraverseIter *real = (struct _OstreeRepoRealCommitTraverseIter *)iter; g_clear_object (&real->repo); g_clear_pointer (&real->commit, g_variant_unref); g_clear_pointer (&real->current_dir, g_variant_unref); @@ -268,8 +251,7 @@ void ostree_repo_commit_traverse_iter_cleanup (void *p) { OstreeRepoCommitTraverseIter *iter = p; - struct _OstreeRepoRealCommitTraverseIter *real = - (struct _OstreeRepoRealCommitTraverseIter*)iter; + struct _OstreeRepoRealCommitTraverseIter *real = (struct _OstreeRepoRealCommitTraverseIter *)iter; if (real->initialized) { ostree_repo_commit_traverse_iter_clear (iter); @@ -288,8 +270,8 @@ ostree_repo_commit_traverse_iter_cleanup (void *p) GHashTable * ostree_repo_traverse_new_reachable (void) { - return g_hash_table_new_full (ostree_hash_object_name, g_variant_equal, - NULL, (GDestroyNotify)g_variant_unref); + return g_hash_table_new_full (ostree_hash_object_name, g_variant_equal, NULL, + (GDestroyNotify)g_variant_unref); } /** @@ -334,7 +316,7 @@ parents_get_commits (GHashTable *parents_ht, GVariant *object, GHashTable *res) for (i = 0; i < len; i++) { - g_autoptr(GVariant) parent = g_variant_get_child_value (parents, i); + g_autoptr (GVariant) parent = g_variant_get_child_value (parents, i); parents_get_commits (parents_ht, parent, res); } } @@ -357,27 +339,20 @@ parents_get_commits (GHashTable *parents_ht, GVariant *object, GHashTable *res) char ** ostree_repo_traverse_parents_get_commits (GHashTable *parents, GVariant *object) { - g_autoptr(GHashTable) res = g_hash_table_new (g_str_hash, g_str_equal); + g_autoptr (GHashTable) res = g_hash_table_new (g_str_hash, g_str_equal); parents_get_commits (parents, object, res); return (char **)g_hash_table_get_keys_as_array (res, NULL); } -static gboolean -traverse_dirtree (OstreeRepo *repo, - const char *checksum, - GVariant *parent_key, - GHashTable *inout_reachable, - GHashTable *inout_parents, - gboolean ignore_missing_dirs, - GCancellable *cancellable, - GError **error); +static gboolean traverse_dirtree (OstreeRepo *repo, const char *checksum, GVariant *parent_key, + GHashTable *inout_reachable, GHashTable *inout_parents, + gboolean ignore_missing_dirs, GCancellable *cancellable, + GError **error); static void -add_parent_ref (GHashTable *inout_parents, - GVariant *key, - GVariant *parent_key) +add_parent_ref (GHashTable *inout_parents, GVariant *key, GVariant *parent_key) { GVariant *old_parents; @@ -398,10 +373,10 @@ add_parent_ref (GHashTable *inout_parents, if (g_variant_is_of_type (old_parents, G_VARIANT_TYPE_ARRAY)) { gsize old_parents_len = g_variant_n_children (old_parents); - new_parents = g_new (GVariant *, old_parents_len + 1); - for (i = 0; i < old_parents_len ; i++) + new_parents = g_new (GVariant *, old_parents_len + 1); + for (i = 0; i < old_parents_len; i++) { - g_autoptr(GVariant) old_parent = g_variant_get_child_value (old_parents, i); + g_autoptr (GVariant) old_parent = g_variant_get_child_value (old_parents, i); if (!g_variant_equal (old_parent, parent_key)) new_parents[len++] = g_steal_pointer (&old_parent); } @@ -413,41 +388,36 @@ add_parent_ref (GHashTable *inout_parents, new_parents[len++] = g_variant_ref (old_parents); } new_parents[len++] = g_variant_ref (parent_key); - g_hash_table_insert (inout_parents, g_variant_ref (key), - g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("(su)"), new_parents , len))); + g_hash_table_insert ( + inout_parents, g_variant_ref (key), + g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("(su)"), new_parents, len))); for (i = 0; i < len; i++) g_variant_unref (new_parents[i]); } } - static gboolean -traverse_iter (OstreeRepo *repo, - OstreeRepoCommitTraverseIter *iter, - GVariant *parent_key, - GHashTable *inout_reachable, - GHashTable *inout_parents, - gboolean ignore_missing_dirs, - GCancellable *cancellable, - GError **error) +traverse_iter (OstreeRepo *repo, OstreeRepoCommitTraverseIter *iter, GVariant *parent_key, + GHashTable *inout_reachable, GHashTable *inout_parents, gboolean ignore_missing_dirs, + GCancellable *cancellable, GError **error) { while (TRUE) { - g_autoptr(GVariant) key = NULL; - g_autoptr(GError) local_error = NULL; - OstreeRepoCommitIterResult iterres = - ostree_repo_commit_traverse_iter_next (iter, cancellable, &local_error); + g_autoptr (GVariant) key = NULL; + g_autoptr (GError) local_error = NULL; + OstreeRepoCommitIterResult iterres + = ostree_repo_commit_traverse_iter_next (iter, cancellable, &local_error); if (iterres == OSTREE_REPO_COMMIT_ITER_RESULT_ERROR) { /* There is only one kind of not-found error, which is failing to load the dirmeta itself, if so, we ignore that (and the whole subtree) if told to. */ - if (ignore_missing_dirs && - g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) + if (ignore_missing_dirs + && g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { g_debug ("Ignoring not-found dirmeta"); - return TRUE; /* Note early return */ + return TRUE; /* Note early return */ } g_propagate_error (error, g_steal_pointer (&local_error)); @@ -463,7 +433,8 @@ traverse_iter (OstreeRepo *repo, ostree_repo_commit_traverse_iter_get_file (iter, &name, &checksum); g_debug ("Found file object %s", checksum); - key = g_variant_ref_sink (ostree_object_name_serialize (checksum, OSTREE_OBJECT_TYPE_FILE)); + key = g_variant_ref_sink ( + ostree_object_name_serialize (checksum, OSTREE_OBJECT_TYPE_FILE)); add_parent_ref (inout_parents, key, parent_key); g_hash_table_add (inout_reachable, g_steal_pointer (&key)); } @@ -473,16 +444,17 @@ traverse_iter (OstreeRepo *repo, char *content_checksum; char *meta_checksum; - ostree_repo_commit_traverse_iter_get_dir (iter, &name, &content_checksum, - &meta_checksum); + ostree_repo_commit_traverse_iter_get_dir (iter, &name, &content_checksum, &meta_checksum); g_debug ("Found dirtree object %s", content_checksum); g_debug ("Found dirmeta object %s", meta_checksum); - key = g_variant_ref_sink (ostree_object_name_serialize (meta_checksum, OSTREE_OBJECT_TYPE_DIR_META)); + key = g_variant_ref_sink ( + ostree_object_name_serialize (meta_checksum, OSTREE_OBJECT_TYPE_DIR_META)); add_parent_ref (inout_parents, key, parent_key); g_hash_table_add (inout_reachable, g_steal_pointer (&key)); - key = g_variant_ref_sink (ostree_object_name_serialize (content_checksum, OSTREE_OBJECT_TYPE_DIR_TREE)); + key = g_variant_ref_sink ( + ostree_object_name_serialize (content_checksum, OSTREE_OBJECT_TYPE_DIR_TREE)); add_parent_ref (inout_parents, key, parent_key); if (!g_hash_table_lookup (inout_reachable, key)) { @@ -501,23 +473,17 @@ traverse_iter (OstreeRepo *repo, } static gboolean -traverse_dirtree (OstreeRepo *repo, - const char *checksum, - GVariant *parent_key, - GHashTable *inout_reachable, - GHashTable *inout_parents, - gboolean ignore_missing_dirs, - GCancellable *cancellable, - GError **error) +traverse_dirtree (OstreeRepo *repo, const char *checksum, GVariant *parent_key, + GHashTable *inout_reachable, GHashTable *inout_parents, + gboolean ignore_missing_dirs, GCancellable *cancellable, GError **error) { - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; - g_autoptr(GVariant) dirtree = NULL; - if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_DIR_TREE, checksum, - &dirtree, &local_error)) + g_autoptr (GVariant) dirtree = NULL; + if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_DIR_TREE, checksum, &dirtree, + &local_error)) { - if (ignore_missing_dirs && - g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) + if (ignore_missing_dirs && g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { g_debug ("Ignoring not-found dirmeta %s", checksum); return TRUE; /* Early return */ @@ -528,14 +494,15 @@ traverse_dirtree (OstreeRepo *repo, } g_debug ("Traversing dirtree %s", checksum); - ostree_cleanup_repo_commit_traverse_iter - OstreeRepoCommitTraverseIter iter = { 0, }; + ostree_cleanup_repo_commit_traverse_iter OstreeRepoCommitTraverseIter iter = { + 0, + }; if (!ostree_repo_commit_traverse_iter_init_dirtree (&iter, repo, dirtree, - OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE, - error)) + OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE, error)) return FALSE; - if (!traverse_iter (repo, &iter, parent_key, inout_reachable, inout_parents, ignore_missing_dirs, cancellable, error)) + if (!traverse_iter (repo, &iter, parent_key, inout_reachable, inout_parents, ignore_missing_dirs, + cancellable, error)) return FALSE; return TRUE; @@ -562,30 +529,25 @@ traverse_dirtree (OstreeRepo *repo, * Since: 2018.5 */ gboolean -ostree_repo_traverse_commit_with_flags (OstreeRepo *repo, - OstreeRepoCommitTraverseFlags flags, - const char *commit_checksum, - int maxdepth, - GHashTable *inout_reachable, - GHashTable *inout_parents, - GCancellable *cancellable, - GError **error) +ostree_repo_traverse_commit_with_flags (OstreeRepo *repo, OstreeRepoCommitTraverseFlags flags, + const char *commit_checksum, int maxdepth, + GHashTable *inout_reachable, GHashTable *inout_parents, + GCancellable *cancellable, GError **error) { g_autofree char *tmp_checksum = NULL; gboolean commit_only = flags & OSTREE_REPO_COMMIT_TRAVERSE_FLAG_COMMIT_ONLY; while (TRUE) { - g_autoptr(GVariant) key = - g_variant_ref_sink (ostree_object_name_serialize (commit_checksum, OSTREE_OBJECT_TYPE_COMMIT)); + g_autoptr (GVariant) key = g_variant_ref_sink ( + ostree_object_name_serialize (commit_checksum, OSTREE_OBJECT_TYPE_COMMIT)); if (g_hash_table_contains (inout_reachable, key)) break; - g_autoptr(GVariant) commit = NULL; - if (!ostree_repo_load_variant_if_exists (repo, OSTREE_OBJECT_TYPE_COMMIT, - commit_checksum, &commit, - error)) + g_autoptr (GVariant) commit = NULL; + if (!ostree_repo_load_variant_if_exists (repo, OSTREE_OBJECT_TYPE_COMMIT, commit_checksum, + &commit, error)) return FALSE; /* Just return if the parent isn't found; we do expect most @@ -596,8 +558,7 @@ ostree_repo_traverse_commit_with_flags (OstreeRepo *repo, /* See if the commit is partial, if so it's not an error to lack objects */ OstreeRepoCommitState commitstate; - if (!ostree_repo_load_commit (repo, commit_checksum, NULL, &commitstate, - error)) + if (!ostree_repo_load_commit (repo, commit_checksum, NULL, &commitstate, error)) return FALSE; gboolean ignore_missing_dirs = FALSE; @@ -610,14 +571,15 @@ ostree_repo_traverse_commit_with_flags (OstreeRepo *repo, if (!commit_only) { g_debug ("Traversing commit %s", commit_checksum); - ostree_cleanup_repo_commit_traverse_iter - OstreeRepoCommitTraverseIter iter = { 0, }; - if (!ostree_repo_commit_traverse_iter_init_commit (&iter, repo, commit, - OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE, - error)) + ostree_cleanup_repo_commit_traverse_iter OstreeRepoCommitTraverseIter iter = { + 0, + }; + if (!ostree_repo_commit_traverse_iter_init_commit ( + &iter, repo, commit, OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE, error)) return FALSE; - if (!traverse_iter (repo, &iter, key, inout_reachable, inout_parents, ignore_missing_dirs, cancellable, error)) + if (!traverse_iter (repo, &iter, key, inout_reachable, inout_parents, ignore_missing_dirs, + cancellable, error)) return FALSE; } @@ -661,17 +623,14 @@ ostree_repo_traverse_commit_with_flags (OstreeRepo *repo, * Since: 2018.5 */ gboolean -ostree_repo_traverse_commit_union_with_parents (OstreeRepo *repo, - const char *commit_checksum, - int maxdepth, - GHashTable *inout_reachable, - GHashTable *inout_parents, - GCancellable *cancellable, - GError **error) +ostree_repo_traverse_commit_union_with_parents (OstreeRepo *repo, const char *commit_checksum, + int maxdepth, GHashTable *inout_reachable, + GHashTable *inout_parents, + GCancellable *cancellable, GError **error) { - return ostree_repo_traverse_commit_with_flags(repo, OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE, - commit_checksum, maxdepth, inout_reachable, inout_parents, - cancellable, error); + return ostree_repo_traverse_commit_with_flags (repo, OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE, + commit_checksum, maxdepth, inout_reachable, + inout_parents, cancellable, error); } /** @@ -687,17 +646,12 @@ ostree_repo_traverse_commit_union_with_parents (OstreeRepo *repo, * from @commit_checksum, traversing @maxdepth parent commits. */ gboolean -ostree_repo_traverse_commit_union (OstreeRepo *repo, - const char *commit_checksum, - int maxdepth, - GHashTable *inout_reachable, - GCancellable *cancellable, - GError **error) +ostree_repo_traverse_commit_union (OstreeRepo *repo, const char *commit_checksum, int maxdepth, + GHashTable *inout_reachable, GCancellable *cancellable, + GError **error) { - return - ostree_repo_traverse_commit_union_with_parents (repo, commit_checksum, maxdepth, - inout_reachable, NULL, - cancellable, error); + return ostree_repo_traverse_commit_union_with_parents (repo, commit_checksum, maxdepth, + inout_reachable, NULL, cancellable, error); } /** @@ -705,7 +659,8 @@ ostree_repo_traverse_commit_union (OstreeRepo *repo, * @repo: Repo * @commit_checksum: ASCII SHA256 checksum * @maxdepth: Traverse this many parent commits, -1 for unlimited - * @out_reachable: (out) (transfer container) (element-type GVariant GVariant): Set of reachable objects + * @out_reachable: (out) (transfer container) (element-type GVariant GVariant): Set of reachable + * objects * @cancellable: Cancellable * @error: Error * @@ -713,16 +668,12 @@ ostree_repo_traverse_commit_union (OstreeRepo *repo, * from @commit_checksum, traversing @maxdepth parent commits. */ gboolean -ostree_repo_traverse_commit (OstreeRepo *repo, - const char *commit_checksum, - int maxdepth, - GHashTable **out_reachable, - GCancellable *cancellable, - GError **error) +ostree_repo_traverse_commit (OstreeRepo *repo, const char *commit_checksum, int maxdepth, + GHashTable **out_reachable, GCancellable *cancellable, GError **error) { - g_autoptr(GHashTable) ret_reachable = ostree_repo_traverse_new_reachable (); - if (!ostree_repo_traverse_commit_union (repo, commit_checksum, maxdepth, - ret_reachable, cancellable, error)) + g_autoptr (GHashTable) ret_reachable = ostree_repo_traverse_new_reachable (); + if (!ostree_repo_traverse_commit_union (repo, commit_checksum, maxdepth, ret_reachable, + cancellable, error)) return FALSE; if (out_reachable) diff --git a/src/libostree/ostree-repo-verity.c b/src/libostree/ostree-repo-verity.c index 403058c0..8c199e85 100644 --- a/src/libostree/ostree-repo-verity.c +++ b/src/libostree/ostree-repo-verity.c @@ -23,8 +23,8 @@ #include "ostree-core-private.h" #include "ostree-repo-private.h" -#include "otutil.h" #include "ot-fs-utils.h" +#include "otutil.h" #ifdef HAVE_LINUX_FSVERITY_H #include #endif @@ -41,8 +41,8 @@ _ostree_repo_parse_fsverity_config (OstreeRepo *self, GError **error) self->fs_verity_supported = _OSTREE_FEATURE_NO; #endif gboolean fsverity_required = FALSE; - if (!ot_keyfile_get_boolean_with_default (self->config, fsverity_key, "required", - FALSE, &fsverity_required, error)) + if (!ot_keyfile_get_boolean_with_default (self->config, fsverity_key, "required", FALSE, + &fsverity_required, error)) return FALSE; if (fsverity_required) { @@ -53,8 +53,8 @@ _ostree_repo_parse_fsverity_config (OstreeRepo *self, GError **error) else { gboolean fsverity_opportunistic = FALSE; - if (!ot_keyfile_get_boolean_with_default (self->config, fsverity_key, "opportunistic", - FALSE, &fsverity_opportunistic, error)) + if (!ot_keyfile_get_boolean_with_default (self->config, fsverity_key, "opportunistic", FALSE, + &fsverity_opportunistic, error)) return FALSE; if (fsverity_opportunistic) self->fs_verity_wanted = _OSTREE_FEATURE_MAYBE; @@ -63,16 +63,13 @@ _ostree_repo_parse_fsverity_config (OstreeRepo *self, GError **error) return TRUE; } - /* Wrapper around the fsverity ioctl, compressing the result to * "success, unsupported or error". This is used for /boot where * we enable verity if supported. * */ gboolean -_ostree_tmpf_fsverity_core (GLnxTmpfile *tmpf, - _OstreeFeatureSupport fsverity_requested, - gboolean *supported, - GError **error) +_ostree_tmpf_fsverity_core (GLnxTmpfile *tmpf, _OstreeFeatureSupport fsverity_requested, + gboolean *supported, GError **error) { /* Set this by default to simplify the code below */ if (supported) @@ -88,11 +85,13 @@ _ostree_tmpf_fsverity_core (GLnxTmpfile *tmpf, if (!glnx_tmpfile_reopen_rdonly (tmpf, error)) return FALSE; - struct fsverity_enable_arg arg = { 0, }; + struct fsverity_enable_arg arg = { + 0, + }; arg.version = 1; - arg.hash_algorithm = FS_VERITY_HASH_ALG_SHA256; /* TODO configurable? */ - arg.block_size = 4096; /* FIXME query */ - arg.salt_size = 0; /* TODO store salt in ostree repo config */ + arg.hash_algorithm = FS_VERITY_HASH_ALG_SHA256; /* TODO configurable? */ + arg.block_size = 4096; /* FIXME query */ + arg.salt_size = 0; /* TODO store salt in ostree repo config */ arg.salt_ptr = 0; arg.sig_size = 0; /* We don't currently expect use of in-kernel signature verification */ arg.sig_ptr = 0; @@ -101,11 +100,11 @@ _ostree_tmpf_fsverity_core (GLnxTmpfile *tmpf, { switch (errno) { - case ENOTTY: - case EOPNOTSUPP: - return TRUE; - default: - return glnx_throw_errno_prefix (error, "ioctl(FS_IOC_ENABLE_VERITY)"); + case ENOTTY: + case EOPNOTSUPP: + return TRUE; + default: + return glnx_throw_errno_prefix (error, "ioctl(FS_IOC_ENABLE_VERITY)"); } } @@ -121,9 +120,7 @@ _ostree_tmpf_fsverity_core (GLnxTmpfile *tmpf, * as well as to support "opportunistic" use (requested and if filesystem supports). * */ gboolean -_ostree_tmpf_fsverity (OstreeRepo *self, - GLnxTmpfile *tmpf, - GError **error) +_ostree_tmpf_fsverity (OstreeRepo *self, GLnxTmpfile *tmpf, GError **error) { #ifdef HAVE_LINUX_FSVERITY_H g_mutex_lock (&self->txn_lock); @@ -133,16 +130,16 @@ _ostree_tmpf_fsverity (OstreeRepo *self, switch (fsverity_wanted) { - case _OSTREE_FEATURE_YES: - { - if (fsverity_supported == _OSTREE_FEATURE_NO) - return glnx_throw (error, "fsverity required but filesystem does not support it"); - } - break; - case _OSTREE_FEATURE_MAYBE: - break; - case _OSTREE_FEATURE_NO: - return TRUE; + case _OSTREE_FEATURE_YES: + { + if (fsverity_supported == _OSTREE_FEATURE_NO) + return glnx_throw (error, "fsverity required but filesystem does not support it"); + } + break; + case _OSTREE_FEATURE_MAYBE: + break; + case _OSTREE_FEATURE_NO: + return TRUE; } gboolean supported = FALSE; diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c index 282970e6..6e58253d 100644 --- a/src/libostree/ostree-repo.c +++ b/src/libostree/ostree-repo.c @@ -23,33 +23,33 @@ #include "config.h" -#include -#include -#include -#include #include "libglnx.h" #include "ostree-core.h" #include "otutil.h" +#include +#include +#include +#include #include #include +#include "ostree-autocleanups.h" #include "ostree-core-private.h" -#include "ostree-sysroot-private.h" +#include "ostree-gpg-verifier.h" #include "ostree-remote-private.h" -#include "ostree-repo-private.h" -#include "ostree-repo-file.h" #include "ostree-repo-file-enumerator.h" -#include "ostree-gpg-verifier.h" +#include "ostree-repo-file.h" +#include "ostree-repo-private.h" #include "ostree-repo-static-delta-private.h" -#include "ot-fs-utils.h" -#include "ostree-autocleanups.h" #include "ostree-sign-private.h" +#include "ostree-sysroot-private.h" +#include "ot-fs-utils.h" -#include #include +#include #include -#include #include +#include #define REPO_LOCK_DISABLED (-2) #define REPO_LOCK_BLOCKING (-1) @@ -62,27 +62,20 @@ * `$ pahole OstreeRepoTransactionStats`. */ #if __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 8 && __SIZEOF_INT__ == 4 -G_STATIC_ASSERT(sizeof(OstreeRepoTransactionStats) == sizeof(int) * 4 + 8 * 5); -G_STATIC_ASSERT(sizeof(OstreeRepoImportArchiveOptions) == sizeof(int) * 9 + 4 + sizeof(void*) * 8); -G_STATIC_ASSERT(sizeof(OstreeRepoExportArchiveOptions) == sizeof(int) * 9 + 4 + 8 + sizeof(void*) * 8); -G_STATIC_ASSERT(sizeof(OstreeRepoCheckoutAtOptions) == - sizeof(OstreeRepoCheckoutMode) + sizeof(OstreeRepoCheckoutOverwriteMode) + - sizeof(int)*6 + - sizeof(int)*5 + - sizeof(int) + - sizeof(void*)*2 + - sizeof(int)*6 + - sizeof(void*)*7); -G_STATIC_ASSERT(sizeof(OstreeRepoCommitTraverseIter) == - sizeof(int) + sizeof(int) + - sizeof(void*) * 10 + - 130 + 6); /* 6 byte hole */ -G_STATIC_ASSERT(sizeof(OstreeRepoPruneOptions) == - sizeof(OstreeRepoPruneFlags) + - 4 + - sizeof(void*) + - sizeof(int) * 12 + - sizeof(void*) * 7); +G_STATIC_ASSERT (sizeof (OstreeRepoTransactionStats) == sizeof (int) * 4 + 8 * 5); +G_STATIC_ASSERT (sizeof (OstreeRepoImportArchiveOptions) + == sizeof (int) * 9 + 4 + sizeof (void *) * 8); +G_STATIC_ASSERT (sizeof (OstreeRepoExportArchiveOptions) + == sizeof (int) * 9 + 4 + 8 + sizeof (void *) * 8); +G_STATIC_ASSERT (sizeof (OstreeRepoCheckoutAtOptions) + == sizeof (OstreeRepoCheckoutMode) + sizeof (OstreeRepoCheckoutOverwriteMode) + + sizeof (int) * 6 + sizeof (int) * 5 + sizeof (int) + sizeof (void *) * 2 + + sizeof (int) * 6 + sizeof (void *) * 7); +G_STATIC_ASSERT (sizeof (OstreeRepoCommitTraverseIter) + == sizeof (int) + sizeof (int) + sizeof (void *) * 10 + 130 + 6); /* 6 byte hole */ +G_STATIC_ASSERT (sizeof (OstreeRepoPruneOptions) + == sizeof (OstreeRepoPruneFlags) + 4 + sizeof (void *) + sizeof (int) * 12 + + sizeof (void *) * 7); #endif /** @@ -139,17 +132,17 @@ G_STATIC_ASSERT(sizeof(OstreeRepoPruneOptions) == * `org.exampleos.Main` and `org.exampleos.Apps`. For the complete format of * collection IDs, see ostree_validate_collection_id(). */ -typedef struct { +typedef struct +{ GObjectClass parent_class; #ifndef OSTREE_DISABLE_GPGME - void (*gpg_verify_result) (OstreeRepo *self, - const char *checksum, - OstreeGpgVerifyResult *result); + void (*gpg_verify_result) (OstreeRepo *self, const char *checksum, OstreeGpgVerifyResult *result); #endif } OstreeRepoClass; -enum { +enum +{ PROP_0, PROP_PATH, @@ -157,7 +150,8 @@ enum { PROP_SYSROOT_PATH }; -enum { +enum +{ GPG_VERIFY_RESULT, LAST_SIGNAL }; @@ -210,7 +204,8 @@ G_DEFINE_TYPE (OstreeRepo, ostree_repo, G_TYPE_OBJECT) * operations performed. */ -typedef struct { +typedef struct +{ guint len; int state; const char *name; @@ -233,8 +228,7 @@ lock_state_name (int state) } static void -repo_lock_info (OstreeRepo *self, GMutexLocker *locker, - OstreeRepoLockInfo *out_info) +repo_lock_info (OstreeRepo *self, GMutexLocker *locker, OstreeRepoLockInfo *out_info) { g_assert (self != NULL); g_assert (locker != NULL); @@ -243,11 +237,11 @@ repo_lock_info (OstreeRepo *self, GMutexLocker *locker, OstreeRepoLockInfo info; info.len = self->lock.shared + self->lock.exclusive; if (info.len == 0) - info.state = LOCK_UN; + info.state = LOCK_UN; else if (self->lock.exclusive > 0) - info.state = LOCK_EX; + info.state = LOCK_EX; else - info.state = LOCK_SH; + info.state = LOCK_SH; info.name = lock_state_name (info.state); *out_info = info; @@ -255,8 +249,7 @@ repo_lock_info (OstreeRepo *self, GMutexLocker *locker, /* Wrapper to handle flock vs OFD locking based on GLnxLockFile */ static gboolean -do_repo_lock (int fd, - int flags) +do_repo_lock (int fd, int flags) { int res; @@ -288,8 +281,7 @@ do_repo_lock (int fd, /* Wrapper to handle flock vs OFD unlocking based on GLnxLockFile */ static gboolean -do_repo_unlock (int fd, - int flags) +do_repo_unlock (int fd, int flags) { int res; @@ -320,27 +312,22 @@ do_repo_unlock (int fd, } static gboolean -push_repo_lock (OstreeRepo *self, - OstreeRepoLockType lock_type, - gboolean blocking, - GError **error) +push_repo_lock (OstreeRepo *self, OstreeRepoLockType lock_type, gboolean blocking, GError **error) { int flags = (lock_type == OSTREE_REPO_LOCK_EXCLUSIVE) ? LOCK_EX : LOCK_SH; int next_state = flags; if (!blocking) flags |= LOCK_NB; - g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&self->lock.mutex); + g_autoptr (GMutexLocker) locker = g_mutex_locker_new (&self->lock.mutex); if (self->lock.fd == -1) { g_debug ("Opening repo lock file"); - self->lock.fd = TEMP_FAILURE_RETRY (openat (self->repo_dir_fd, ".lock", - O_CREAT | O_RDWR | O_CLOEXEC, - DEFAULT_REGFILE_MODE)); + self->lock.fd = TEMP_FAILURE_RETRY ( + openat (self->repo_dir_fd, ".lock", O_CREAT | O_RDWR | O_CLOEXEC, DEFAULT_REGFILE_MODE)); if (self->lock.fd < 0) - return glnx_throw_errno_prefix (error, - "Opening lock file %s/.lock failed", + return glnx_throw_errno_prefix (error, "Opening lock file %s/.lock failed", gs_file_get_path_cached (self->repodir)); } @@ -350,9 +337,9 @@ push_repo_lock (OstreeRepo *self, guint *counter; if (next_state == LOCK_EX) - counter = &(self->lock.exclusive); + counter = &(self->lock.exclusive); else - counter = &(self->lock.shared); + counter = &(self->lock.shared); /* Check for overflow */ if (*counter == G_MAXUINT) @@ -370,8 +357,7 @@ push_repo_lock (OstreeRepo *self, const char *next_state_name = lock_state_name (next_state); g_debug ("Locking repo %s", next_state_name); if (!do_repo_lock (self->lock.fd, flags)) - return glnx_throw_errno_prefix (error, "Locking repo %s failed", - next_state_name); + return glnx_throw_errno_prefix (error, "Locking repo %s failed", next_state_name); } /* Update state */ @@ -381,14 +367,11 @@ push_repo_lock (OstreeRepo *self, } static gboolean -pop_repo_lock (OstreeRepo *self, - OstreeRepoLockType lock_type, - gboolean blocking, - GError **error) +pop_repo_lock (OstreeRepo *self, OstreeRepoLockType lock_type, gboolean blocking, GError **error) { int flags = blocking ? 0 : LOCK_NB; - g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&self->lock.mutex); + g_autoptr (GMutexLocker) locker = g_mutex_locker_new (&self->lock.mutex); if (self->lock.fd == -1) g_error ("Cannot pop repo never locked repo lock"); @@ -444,8 +427,7 @@ pop_repo_lock (OstreeRepo *self, g_assert (next_state == LOCK_SH); g_debug ("Returning lock state to shared"); if (!do_repo_lock (self->lock.fd, next_state | flags)) - return glnx_throw_errno_prefix (error, - "Setting repo lock to shared failed"); + return glnx_throw_errno_prefix (error, "Setting repo lock to shared failed"); } /* Update state */ @@ -483,10 +465,8 @@ pop_repo_lock (OstreeRepo *self, * Since: 2021.3 */ gboolean -ostree_repo_lock_push (OstreeRepo *self, - OstreeRepoLockType lock_type, - GCancellable *cancellable, - GError **error) +ostree_repo_lock_push (OstreeRepo *self, OstreeRepoLockType lock_type, GCancellable *cancellable, + GError **error) { g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (OSTREE_IS_REPO (self), FALSE); @@ -510,19 +490,17 @@ ostree_repo_lock_push (OstreeRepo *self, /* Convert to unsigned to guard against negative values */ guint lock_timeout_seconds = self->lock_timeout_seconds; guint waited = 0; - g_debug ("Pushing lock non-blocking with timeout %u", - lock_timeout_seconds); + g_debug ("Pushing lock non-blocking with timeout %u", lock_timeout_seconds); for (;;) { if (g_cancellable_set_error_if_cancelled (cancellable, error)) return FALSE; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; if (push_repo_lock (self, lock_type, FALSE, &local_error)) return TRUE; - if (!g_error_matches (local_error, G_IO_ERROR, - G_IO_ERROR_WOULD_BLOCK)) + if (!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { g_propagate_error (error, g_steal_pointer (&local_error)); return FALSE; @@ -530,8 +508,7 @@ ostree_repo_lock_push (OstreeRepo *self, if (waited >= lock_timeout_seconds) { - g_debug ("Push lock: Could not acquire lock within %u seconds", - lock_timeout_seconds); + g_debug ("Push lock: Could not acquire lock within %u seconds", lock_timeout_seconds); g_propagate_error (error, g_steal_pointer (&local_error)); return FALSE; } @@ -540,8 +517,8 @@ ostree_repo_lock_push (OstreeRepo *self, if (waited % 60 == 0) { guint remaining = lock_timeout_seconds - waited; - g_debug ("Push lock: Waiting %u more second%s to acquire lock", - remaining, (remaining == 1) ? "" : "s"); + g_debug ("Push lock: Waiting %u more second%s to acquire lock", remaining, + (remaining == 1) ? "" : "s"); } waited++; sleep (1); @@ -577,10 +554,8 @@ ostree_repo_lock_push (OstreeRepo *self, * Since: 2021.3 */ gboolean -ostree_repo_lock_pop (OstreeRepo *self, - OstreeRepoLockType lock_type, - GCancellable *cancellable, - GError **error) +ostree_repo_lock_pop (OstreeRepo *self, OstreeRepoLockType lock_type, GCancellable *cancellable, + GError **error) { g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (OSTREE_IS_REPO (self), FALSE); @@ -604,19 +579,17 @@ ostree_repo_lock_pop (OstreeRepo *self, /* Convert to unsigned to guard against negative values */ guint lock_timeout_seconds = self->lock_timeout_seconds; guint waited = 0; - g_debug ("Popping lock non-blocking with timeout %u", - lock_timeout_seconds); + g_debug ("Popping lock non-blocking with timeout %u", lock_timeout_seconds); for (;;) { if (g_cancellable_set_error_if_cancelled (cancellable, error)) return FALSE; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; if (pop_repo_lock (self, lock_type, FALSE, &local_error)) return TRUE; - if (!g_error_matches (local_error, G_IO_ERROR, - G_IO_ERROR_WOULD_BLOCK)) + if (!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { g_propagate_error (error, g_steal_pointer (&local_error)); return FALSE; @@ -624,8 +597,7 @@ ostree_repo_lock_pop (OstreeRepo *self, if (waited >= lock_timeout_seconds) { - g_debug ("Pop lock: Could not remove lock within %u seconds", - lock_timeout_seconds); + g_debug ("Pop lock: Could not remove lock within %u seconds", lock_timeout_seconds); g_propagate_error (error, g_steal_pointer (&local_error)); return FALSE; } @@ -634,8 +606,8 @@ ostree_repo_lock_pop (OstreeRepo *self, if (waited % 60 == 0) { guint remaining = lock_timeout_seconds - waited; - g_debug ("Pop lock: Waiting %u more second%s to remove lock", - remaining, (remaining == 1) ? "" : "s"); + g_debug ("Pop lock: Waiting %u more second%s to remove lock", remaining, + (remaining == 1) ? "" : "s"); } waited++; sleep (1); @@ -643,7 +615,8 @@ ostree_repo_lock_pop (OstreeRepo *self, } } -struct OstreeRepoAutoLock { +struct OstreeRepoAutoLock +{ OstreeRepo *repo; OstreeRepoLockType lock_type; }; @@ -671,10 +644,8 @@ struct OstreeRepoAutoLock { * Since: 2021.3 */ OstreeRepoAutoLock * -ostree_repo_auto_lock_push (OstreeRepo *self, - OstreeRepoLockType lock_type, - GCancellable *cancellable, - GError **error) +ostree_repo_auto_lock_push (OstreeRepo *self, OstreeRepoLockType lock_type, + GCancellable *cancellable, GError **error) { if (!ostree_repo_lock_push (self, lock_type, cancellable, error)) return NULL; @@ -700,7 +671,7 @@ ostree_repo_auto_lock_cleanup (OstreeRepoAutoLock *auto_lock) { if (auto_lock != NULL) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; int errsv = errno; if (!ostree_repo_lock_pop (auto_lock->repo, auto_lock->lock_type, NULL, &error)) @@ -731,7 +702,7 @@ _ostree_repo_auto_transaction_new (OstreeRepo *repo) { g_assert (repo != NULL); - OstreeRepoAutoTransaction *txn = g_malloc(sizeof(OstreeRepoAutoTransaction)); + OstreeRepoAutoTransaction *txn = g_malloc (sizeof (OstreeRepoAutoTransaction)); txn->atomic_refcount = 1; txn->repo = g_object_ref (repo); @@ -750,9 +721,7 @@ _ostree_repo_auto_transaction_new (OstreeRepo *repo) * %NULL otherwise. */ OstreeRepoAutoTransaction * -_ostree_repo_auto_transaction_start (OstreeRepo *repo, - GCancellable *cancellable, - GError **error) +_ostree_repo_auto_transaction_start (OstreeRepo *repo, GCancellable *cancellable, GError **error) { g_assert (repo != NULL); @@ -773,15 +742,15 @@ _ostree_repo_auto_transaction_start (OstreeRepo *repo, * Returns: %TRUE on successful commit, %FALSE otherwise. */ gboolean -_ostree_repo_auto_transaction_abort (OstreeRepoAutoTransaction *txn, - GCancellable *cancellable, - GError **error) +_ostree_repo_auto_transaction_abort (OstreeRepoAutoTransaction *txn, GCancellable *cancellable, + GError **error) { g_assert (txn != NULL); - if (txn->repo == NULL) { - return glnx_throw (error, "transaction already completed"); - } + if (txn->repo == NULL) + { + return glnx_throw (error, "transaction already completed"); + } if (!ostree_repo_abort_transaction (txn->repo, cancellable, error)) return FALSE; @@ -803,16 +772,16 @@ _ostree_repo_auto_transaction_abort (OstreeRepoAutoTransaction *txn, * Returns: %TRUE on successful aborting, %FALSE otherwise. */ gboolean -_ostree_repo_auto_transaction_commit (OstreeRepoAutoTransaction *txn, +_ostree_repo_auto_transaction_commit (OstreeRepoAutoTransaction *txn, OstreeRepoTransactionStats *out_stats, - GCancellable *cancellable, - GError **error) + GCancellable *cancellable, GError **error) { g_assert (txn != NULL); - if (txn->repo == NULL) { - return glnx_throw (error, "transaction already completed"); - } + if (txn->repo == NULL) + { + return glnx_throw (error, "transaction already completed"); + } if (!ostree_repo_commit_transaction (txn->repo, out_stats, cancellable, error)) return FALSE; @@ -860,9 +829,9 @@ _ostree_repo_auto_transaction_unref (OstreeRepoAutoTransaction *txn) // Auto-abort only if transaction has not already been aborted/committed. if (txn->repo != NULL) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; if (!ostree_repo_abort_transaction (txn->repo, NULL, &error)) - g_warning("Failed to auto-cleanup OSTree transaction: %s", error->message); + g_warning ("Failed to auto-cleanup OSTree transaction: %s", error->message); g_clear_object (&txn->repo); } @@ -871,18 +840,13 @@ _ostree_repo_auto_transaction_unref (OstreeRepoAutoTransaction *txn) return; } -G_DEFINE_BOXED_TYPE(OstreeRepoAutoTransaction, _ostree_repo_auto_transaction, - _ostree_repo_auto_transaction_ref, - _ostree_repo_auto_transaction_unref); +G_DEFINE_BOXED_TYPE (OstreeRepoAutoTransaction, _ostree_repo_auto_transaction, + _ostree_repo_auto_transaction_ref, _ostree_repo_auto_transaction_unref); -static GFile * -get_remotes_d_dir (OstreeRepo *self, - GFile *sysroot); +static GFile *get_remotes_d_dir (OstreeRepo *self, GFile *sysroot); OstreeRemote * -_ostree_repo_get_remote (OstreeRepo *self, - const char *name, - GError **error) +_ostree_repo_get_remote (OstreeRepo *self, const char *name, GError **error) { OstreeRemote *remote = NULL; @@ -895,8 +859,7 @@ _ostree_repo_get_remote (OstreeRepo *self, if (remote != NULL) ostree_remote_ref (remote); else - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "Remote \"%s\" not found", name); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Remote \"%s\" not found", name); g_mutex_unlock (&self->remotes_lock); @@ -904,12 +867,10 @@ _ostree_repo_get_remote (OstreeRepo *self, } OstreeRemote * -_ostree_repo_get_remote_inherited (OstreeRepo *self, - const char *name, - GError **error) +_ostree_repo_get_remote_inherited (OstreeRepo *self, const char *name, GError **error) { - g_autoptr(OstreeRemote) remote = NULL; - g_autoptr(GError) temp_error = NULL; + g_autoptr (OstreeRemote) remote = NULL; + g_autoptr (GError) temp_error = NULL; remote = _ostree_repo_get_remote (self, name, &temp_error); if (remote == NULL) @@ -925,8 +886,7 @@ _ostree_repo_get_remote_inherited (OstreeRepo *self, } gboolean -_ostree_repo_add_remote (OstreeRepo *self, - OstreeRemote *remote) +_ostree_repo_add_remote (OstreeRepo *self, OstreeRemote *remote) { gboolean already_existed; @@ -944,8 +904,7 @@ _ostree_repo_add_remote (OstreeRepo *self, } gboolean -_ostree_repo_remove_remote (OstreeRepo *self, - OstreeRemote *remote) +_ostree_repo_remove_remote (OstreeRepo *self, OstreeRemote *remote) { gboolean removed; @@ -987,16 +946,12 @@ _ostree_repo_remote_name_is_file (const char *remote_name) * Since: 2016.5 */ gboolean -ostree_repo_get_remote_option (OstreeRepo *self, - const char *remote_name, - const char *option_name, - const char *default_value, - char **out_value, - GError **error) -{ - g_autoptr(OstreeRemote) remote = NULL; +ostree_repo_get_remote_option (OstreeRepo *self, const char *remote_name, const char *option_name, + const char *default_value, char **out_value, GError **error) +{ + g_autoptr (OstreeRemote) remote = NULL; gboolean ret = FALSE; - g_autoptr(GError) temp_error = NULL; + g_autoptr (GError) temp_error = NULL; g_autofree char *value = NULL; if (_ostree_repo_remote_name_is_file (remote_name)) @@ -1016,12 +971,9 @@ ostree_repo_get_remote_option (OstreeRepo *self, /* Note: We ignore errors on the parent because the parent config may not specify this remote, causing a "remote not found" error, but we found the remote at some point, so we need to instead return the default */ - if (self->parent_repo != NULL && - ostree_repo_get_remote_option (self->parent_repo, - remote_name, option_name, - default_value, - out_value, - NULL)) + if (self->parent_repo != NULL + && ostree_repo_get_remote_option (self->parent_repo, remote_name, option_name, + default_value, out_value, NULL)) return TRUE; value = g_strdup (default_value); @@ -1034,11 +986,8 @@ ostree_repo_get_remote_option (OstreeRepo *self, ret = TRUE; } else if (self->parent_repo != NULL) - return ostree_repo_get_remote_option (self->parent_repo, - remote_name, option_name, - default_value, - out_value, - error); + return ostree_repo_get_remote_option (self->parent_repo, remote_name, option_name, + default_value, out_value, error); else g_propagate_error (error, g_steal_pointer (&temp_error)); @@ -1067,16 +1016,13 @@ ostree_repo_get_remote_option (OstreeRepo *self, * Since: 2016.5 */ gboolean -ostree_repo_get_remote_list_option (OstreeRepo *self, - const char *remote_name, - const char *option_name, - char ***out_value, - GError **error) +ostree_repo_get_remote_list_option (OstreeRepo *self, const char *remote_name, + const char *option_name, char ***out_value, GError **error) { - g_autoptr(OstreeRemote) remote = NULL; + g_autoptr (OstreeRemote) remote = NULL; gboolean ret = FALSE; - g_autoptr(GError) temp_error = NULL; - g_auto(GStrv) value = NULL; + g_autoptr (GError) temp_error = NULL; + g_auto (GStrv) value = NULL; if (_ostree_repo_remote_name_is_file (remote_name)) { @@ -1087,10 +1033,8 @@ ostree_repo_get_remote_list_option (OstreeRepo *self, remote = _ostree_repo_get_remote (self, remote_name, &temp_error); if (remote != NULL) { - value = g_key_file_get_string_list (remote->options, - remote->group, - option_name, - NULL, &temp_error); + value = g_key_file_get_string_list (remote->options, remote->group, option_name, NULL, + &temp_error); /* Default value if key not found is always NULL. */ if (g_error_matches (temp_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) @@ -1098,11 +1042,9 @@ ostree_repo_get_remote_list_option (OstreeRepo *self, /* Note: We ignore errors on the parent because the parent config may not specify this remote, causing a "remote not found" error, but we found the remote at some point, so we need to instead return the default */ - if (self->parent_repo != NULL && - ostree_repo_get_remote_list_option (self->parent_repo, - remote_name, option_name, - out_value, - NULL)) + if (self->parent_repo != NULL + && ostree_repo_get_remote_list_option (self->parent_repo, remote_name, option_name, + out_value, NULL)) return TRUE; ret = TRUE; @@ -1113,10 +1055,8 @@ ostree_repo_get_remote_list_option (OstreeRepo *self, ret = TRUE; } else if (self->parent_repo != NULL) - return ostree_repo_get_remote_list_option (self->parent_repo, - remote_name, option_name, - out_value, - error); + return ostree_repo_get_remote_list_option (self->parent_repo, remote_name, option_name, + out_value, error); else g_propagate_error (error, g_steal_pointer (&temp_error)); @@ -1144,15 +1084,12 @@ ostree_repo_get_remote_list_option (OstreeRepo *self, * Since: 2016.5 */ gboolean -ostree_repo_get_remote_boolean_option (OstreeRepo *self, - const char *remote_name, - const char *option_name, - gboolean default_value, - gboolean *out_value, - GError **error) -{ - g_autoptr(OstreeRemote) remote = NULL; - g_autoptr(GError) temp_error = NULL; +ostree_repo_get_remote_boolean_option (OstreeRepo *self, const char *remote_name, + const char *option_name, gboolean default_value, + gboolean *out_value, GError **error) +{ + g_autoptr (OstreeRemote) remote = NULL; + g_autoptr (GError) temp_error = NULL; gboolean ret = FALSE; gboolean value = FALSE; @@ -1173,12 +1110,9 @@ ostree_repo_get_remote_boolean_option (OstreeRepo *self, /* Note: We ignore errors on the parent because the parent config may not specify this remote, causing a "remote not found" error, but we found the remote at some point, so we need to instead return the default */ - if (self->parent_repo != NULL && - ostree_repo_get_remote_boolean_option (self->parent_repo, - remote_name, option_name, - default_value, - out_value, - NULL)) + if (self->parent_repo != NULL + && ostree_repo_get_remote_boolean_option ( + self->parent_repo, remote_name, option_name, default_value, out_value, NULL)) return TRUE; value = default_value; @@ -1191,11 +1125,8 @@ ostree_repo_get_remote_boolean_option (OstreeRepo *self, ret = TRUE; } else if (self->parent_repo != NULL) - return ostree_repo_get_remote_boolean_option (self->parent_repo, - remote_name, option_name, - default_value, - out_value, - error); + return ostree_repo_get_remote_boolean_option (self->parent_repo, remote_name, option_name, + default_value, out_value, error); else g_propagate_error (error, g_steal_pointer (&temp_error)); @@ -1251,10 +1182,7 @@ ostree_repo_finalize (GObject *object) } static void -ostree_repo_set_property(GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) +ostree_repo_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { OstreeRepo *self = OSTREE_REPO (object); @@ -1276,10 +1204,7 @@ ostree_repo_set_property(GObject *object, } static void -ostree_repo_get_property(GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) +ostree_repo_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { OstreeRepo *self = OSTREE_REPO (object); @@ -1319,11 +1244,10 @@ ostree_repo_class_init (OstreeRepoClass *klass) * to the repository's directory fd via `ostree_repo_get_dfd()` and * use file-descriptor relative operations. */ - g_object_class_install_property (object_class, - PROP_PATH, - g_param_spec_object ("path", "Path", "Path", - G_TYPE_FILE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property ( + object_class, PROP_PATH, + g_param_spec_object ("path", "Path", "Path", G_TYPE_FILE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); /** * OstreeRepo:sysroot-path: * @@ -1335,13 +1259,10 @@ ostree_repo_class_init (OstreeRepoClass *klass) * on a system repository, use `OstreeSysroot` and access the repository * object via `ostree_sysroot_repo()`. */ - g_object_class_install_property (object_class, - PROP_SYSROOT_PATH, - g_param_spec_object ("sysroot-path", - "", - "", - G_TYPE_FILE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property ( + object_class, PROP_SYSROOT_PATH, + g_param_spec_object ("sysroot-path", "", "", G_TYPE_FILE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); /** * OstreeRepo:remotes-config-dir: * @@ -1351,13 +1272,10 @@ ostree_repo_class_init (OstreeRepoClass *klass) * * This value will only be used for system repositories. */ - g_object_class_install_property (object_class, - PROP_REMOTES_CONFIG_DIR, - g_param_spec_string ("remotes-config-dir", - "", - "", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property ( + object_class, PROP_REMOTES_CONFIG_DIR, + g_param_spec_string ("remotes-config-dir", "", "", NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); #ifndef OSTREE_DISABLE_GPGME /** @@ -1374,14 +1292,10 @@ ostree_repo_class_init (OstreeRepoClass *klass) * thread-default at the point when ostree_repo_pull_with_options() * is called. */ - signals[GPG_VERIFY_RESULT] = g_signal_new ("gpg-verify-result", - OSTREE_TYPE_REPO, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (OstreeRepoClass, gpg_verify_result), - NULL, NULL, NULL, - G_TYPE_NONE, 2, - G_TYPE_STRING, - OSTREE_TYPE_GPG_VERIFY_RESULT); + signals[GPG_VERIFY_RESULT] + = g_signal_new ("gpg-verify-result", OSTREE_TYPE_REPO, G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (OstreeRepoClass, gpg_verify_result), NULL, NULL, NULL, + G_TYPE_NONE, 2, G_TYPE_STRING, OSTREE_TYPE_GPG_VERIFY_RESULT); #endif /* OSTREE_DISABLE_GPGME */ } @@ -1411,12 +1325,10 @@ ostree_repo_init (OstreeRepo *self) g_mutex_init (&self->cache_lock); g_mutex_init (&self->txn_lock); - self->remotes = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify) NULL, - (GDestroyNotify) ostree_remote_unref); - self->bls_append_values = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) g_free); + self->remotes = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)NULL, + (GDestroyNotify)ostree_remote_unref); + self->bls_append_values = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, + (GDestroyNotify)g_free); g_mutex_init (&self->remotes_lock); self->repo_dir_fd = -1; @@ -1434,18 +1346,16 @@ ostree_repo_init (OstreeRepo *self) * * Returns: (transfer full): An accessor object for an OSTree repository located at @path */ -OstreeRepo* +OstreeRepo * ostree_repo_new (GFile *path) { return g_object_new (OSTREE_TYPE_REPO, "path", path, NULL); } static OstreeRepo * -repo_open_at_take_fd (int *dfd, - GCancellable *cancellable, - GError **error) +repo_open_at_take_fd (int *dfd, GCancellable *cancellable, GError **error) { - g_autoptr(OstreeRepo) repo = g_object_new (OSTREE_TYPE_REPO, NULL); + g_autoptr (OstreeRepo) repo = g_object_new (OSTREE_TYPE_REPO, NULL); repo->repo_dir_fd = g_steal_fd (dfd); if (!ostree_repo_open (repo, cancellable, error)) @@ -1466,11 +1376,8 @@ repo_open_at_take_fd (int *dfd, * * Since: 2017.10 */ -OstreeRepo* -ostree_repo_open_at (int dfd, - const char *path, - GCancellable *cancellable, - GError **error) +OstreeRepo * +ostree_repo_open_at (int dfd, const char *path, GCancellable *cancellable, GError **error) { glnx_autofd int repo_dfd = -1; if (!glnx_opendirat (dfd, path, TRUE, &repo_dfd, error)) @@ -1499,8 +1406,7 @@ get_default_repo_path (GFile *sysroot_path) * Returns: (transfer full): An accessor object for the OSTree repository located at @repo_path. */ OstreeRepo * -ostree_repo_new_for_sysroot_path (GFile *repo_path, - GFile *sysroot_path) +ostree_repo_new_for_sysroot_path (GFile *repo_path, GFile *sysroot_path) { return g_object_new (OSTREE_TYPE_REPO, "path", repo_path, "sysroot-path", sysroot_path, NULL); } @@ -1516,19 +1422,18 @@ ostree_repo_new_for_sysroot_path (GFile *repo_path, * * Returns: (transfer full): An accessor object for an OSTree repository located at /ostree/repo */ -OstreeRepo* +OstreeRepo * ostree_repo_new_default (void) { - if (g_file_test ("objects", G_FILE_TEST_IS_DIR) - && g_file_test ("config", G_FILE_TEST_IS_REGULAR)) + if (g_file_test ("objects", G_FILE_TEST_IS_DIR) && g_file_test ("config", G_FILE_TEST_IS_REGULAR)) { - g_autoptr(GFile) cwd = g_file_new_for_path ("."); + g_autoptr (GFile) cwd = g_file_new_for_path ("."); return ostree_repo_new (cwd); } else { const char *envvar = g_getenv ("OSTREE_REPO"); - g_autoptr(GFile) repo_path = NULL; + g_autoptr (GFile) repo_path = NULL; if (envvar == NULL || *envvar == '\0') repo_path = get_default_repo_path (NULL); @@ -1546,15 +1451,15 @@ ostree_repo_new_default (void) * Returns: %TRUE if this repository is the root-owned system global repository */ gboolean -ostree_repo_is_system (OstreeRepo *repo) +ostree_repo_is_system (OstreeRepo *repo) { g_return_val_if_fail (OSTREE_IS_REPO (repo), FALSE); /* If we were created via ostree_sysroot_get_repo(), we know the answer is yes * without having to compare file paths. */ - if (repo->sysroot_kind == OSTREE_REPO_SYSROOT_KIND_VIA_SYSROOT || - repo->sysroot_kind == OSTREE_REPO_SYSROOT_KIND_IS_SYSROOT_OSTREE) + if (repo->sysroot_kind == OSTREE_REPO_SYSROOT_KIND_VIA_SYSROOT + || repo->sysroot_kind == OSTREE_REPO_SYSROOT_KIND_IS_SYSROOT_OSTREE) return TRUE; /* No sysroot_dir set? Not a system repo then. */ @@ -1566,7 +1471,7 @@ ostree_repo_is_system (OstreeRepo *repo) */ if (repo->repodir) { - g_autoptr(GFile) default_repo_path = get_default_repo_path (repo->sysroot_dir); + g_autoptr (GFile) default_repo_path = get_default_repo_path (repo->sysroot_dir); return g_file_equal (repo->repodir, default_repo_path); } /* Otherwise, not a system repo */ @@ -1584,8 +1489,7 @@ ostree_repo_is_system (OstreeRepo *repo) * Returns: %TRUE if this repository is writable */ gboolean -ostree_repo_is_writable (OstreeRepo *self, - GError **error) +ostree_repo_is_writable (OstreeRepo *self, GError **error) { g_assert (self != NULL); g_assert (self->inited); @@ -1606,8 +1510,7 @@ ostree_repo_is_writable (OstreeRepo *self, * can detect that the refs have updated. */ gboolean -_ostree_repo_update_mtime (OstreeRepo *self, - GError **error) +_ostree_repo_update_mtime (OstreeRepo *self, GError **error) { if (futimens (self->repo_dir_fd, NULL) != 0) { @@ -1665,9 +1568,7 @@ ostree_repo_copy_config (OstreeRepo *self) * Save @new_config in place of this repository's config file. */ gboolean -ostree_repo_write_config (OstreeRepo *self, - GKeyFile *new_config, - GError **error) +ostree_repo_write_config (OstreeRepo *self, GKeyFile *new_config, GError **error) { g_return_val_if_fail (self->inited, FALSE); @@ -1675,20 +1576,19 @@ ostree_repo_write_config (OstreeRepo *self, * separate config file. */ gsize num_groups; - g_auto(GStrv) groups = g_key_file_get_groups (new_config, &num_groups); + g_auto (GStrv) groups = g_key_file_get_groups (new_config, &num_groups); for (gsize i = 0; i < num_groups; i++) { - g_autoptr(OstreeRemote) new_remote = ostree_remote_new_from_keyfile (new_config, groups[i]); + g_autoptr (OstreeRemote) new_remote = ostree_remote_new_from_keyfile (new_config, groups[i]); if (new_remote != NULL) { - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; - g_autoptr(OstreeRemote) cur_remote = - _ostree_repo_get_remote (self, new_remote->name, &local_error); + g_autoptr (OstreeRemote) cur_remote + = _ostree_repo_get_remote (self, new_remote->name, &local_error); if (cur_remote == NULL) { - if (!g_error_matches (local_error, G_IO_ERROR, - G_IO_ERROR_NOT_FOUND)) + if (!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { g_propagate_error (error, g_steal_pointer (&local_error)); return FALSE; @@ -1697,8 +1597,7 @@ ostree_repo_write_config (OstreeRepo *self, else if (cur_remote->file != NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS, - "Remote \"%s\" already defined in %s", - new_remote->name, + "Remote \"%s\" already defined in %s", new_remote->name, gs_file_get_path_cached (cur_remote->file)); return FALSE; } @@ -1707,9 +1606,8 @@ ostree_repo_write_config (OstreeRepo *self, gsize len; g_autofree char *data = g_key_file_to_data (new_config, &len, error); - if (!glnx_file_replace_contents_at (self->repo_dir_fd, "config", - (guint8*)data, len, 0, - NULL, error)) + if (!glnx_file_replace_contents_at (self->repo_dir_fd, "config", (guint8 *)data, len, 0, NULL, + error)) return FALSE; g_key_file_free (self->config); @@ -1722,9 +1620,7 @@ ostree_repo_write_config (OstreeRepo *self, /* Bind a subset of an a{sv} to options in a given GKeyfile section */ static void -keyfile_set_from_vardict (GKeyFile *keyfile, - const char *section, - GVariant *vardict) +keyfile_set_from_vardict (GKeyFile *keyfile, const char *section, GVariant *vardict) { GVariantIter viter; const char *key; @@ -1733,7 +1629,7 @@ keyfile_set_from_vardict (GKeyFile *keyfile, g_variant_iter_init (&viter, vardict); while (g_variant_iter_loop (&viter, "{&s@v}", &key, &val)) { - g_autoptr(GVariant) child = g_variant_get_variant (val); + g_autoptr (GVariant) child = g_variant_get_variant (val); if (g_variant_is_of_type (child, G_VARIANT_TYPE_STRING)) g_key_file_set_string (keyfile, section, key, g_variant_get_string (child, NULL)); else if (g_variant_is_of_type (child, G_VARIANT_TYPE_BOOLEAN)) @@ -1745,28 +1641,22 @@ keyfile_set_from_vardict (GKeyFile *keyfile, g_key_file_set_string_list (keyfile, section, key, strv_child, len); } else - g_critical ("Unhandled type '%s' in %s", - (char*)g_variant_get_type (child), G_STRFUNC); + g_critical ("Unhandled type '%s' in %s", (char *)g_variant_get_type (child), G_STRFUNC); } } static gboolean -impl_repo_remote_add (OstreeRepo *self, - GFile *sysroot, - gboolean if_not_exists, - const char *name, - const char *url, - GVariant *options, - GCancellable *cancellable, - GError **error) +impl_repo_remote_add (OstreeRepo *self, GFile *sysroot, gboolean if_not_exists, const char *name, + const char *url, GVariant *options, GCancellable *cancellable, GError **error) { g_return_val_if_fail (name != NULL, FALSE); - g_return_val_if_fail (options == NULL || g_variant_is_of_type (options, G_VARIANT_TYPE ("a{sv}")), FALSE); + g_return_val_if_fail (options == NULL || g_variant_is_of_type (options, G_VARIANT_TYPE ("a{sv}")), + FALSE); if (!ostree_validate_remote_name (name, error)) return FALSE; - g_autoptr(OstreeRemote) remote = _ostree_repo_get_remote (self, name, NULL); + g_autoptr (OstreeRemote) remote = _ostree_repo_get_remote (self, name, NULL); if (remote != NULL && if_not_exists) { /* Note early return */ @@ -1774,9 +1664,8 @@ impl_repo_remote_add (OstreeRepo *self, } else if (remote != NULL) { - return glnx_throw (error, - "Remote configuration for \"%s\" already exists: %s", - name, remote->file ? gs_file_get_path_cached (remote->file) : "(in config)"); + return glnx_throw (error, "Remote configuration for \"%s\" already exists: %s", name, + remote->file ? gs_file_get_path_cached (remote->file) : "(in config)"); } remote = ostree_remote_new (name); @@ -1785,13 +1674,12 @@ impl_repo_remote_add (OstreeRepo *self, * add-remotes-config-dir is true. This is the default for system * repos. */ - g_autoptr(GFile) etc_ostree_remotes_d = get_remotes_d_dir (self, sysroot); + g_autoptr (GFile) etc_ostree_remotes_d = get_remotes_d_dir (self, sysroot); if (etc_ostree_remotes_d && self->add_remotes_config_dir) { - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; - if (!g_file_make_directory_with_parents (etc_ostree_remotes_d, - cancellable, &local_error)) + if (!g_file_make_directory_with_parents (etc_ostree_remotes_d, cancellable, &local_error)) { if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_EXISTS)) { @@ -1811,7 +1699,8 @@ impl_repo_remote_add (OstreeRepo *self, if (url) { if (g_str_has_prefix (url, "metalink=")) - g_key_file_set_string (remote->options, remote->group, "metalink", url + strlen ("metalink=")); + g_key_file_set_string (remote->options, remote->group, "metalink", + url + strlen ("metalink=")); else g_key_file_set_string (remote->options, remote->group, "url", url); } @@ -1824,15 +1713,13 @@ impl_repo_remote_add (OstreeRepo *self, gsize length; g_autofree char *data = g_key_file_to_data (remote->options, &length, NULL); - if (!g_file_replace_contents (remote->file, - data, length, - NULL, FALSE, 0, NULL, - cancellable, error)) + if (!g_file_replace_contents (remote->file, data, length, NULL, FALSE, 0, NULL, cancellable, + error)) return FALSE; } else { - g_autoptr(GKeyFile) config = NULL; + g_autoptr (GKeyFile) config = NULL; config = ostree_repo_copy_config (self); ot_keyfile_copy_group (remote->options, config, remote->group); @@ -1865,31 +1752,22 @@ impl_repo_remote_add (OstreeRepo *self, * */ gboolean -ostree_repo_remote_add (OstreeRepo *self, - const char *name, - const char *url, - GVariant *options, - GCancellable *cancellable, - GError **error) +ostree_repo_remote_add (OstreeRepo *self, const char *name, const char *url, GVariant *options, + GCancellable *cancellable, GError **error) { - return impl_repo_remote_add (self, NULL, FALSE, name, url, options, - cancellable, error); + return impl_repo_remote_add (self, NULL, FALSE, name, url, options, cancellable, error); } static gboolean -impl_repo_remote_delete (OstreeRepo *self, - GFile *sysroot, - gboolean if_exists, - const char *name, - GCancellable *cancellable, - GError **error) +impl_repo_remote_delete (OstreeRepo *self, GFile *sysroot, gboolean if_exists, const char *name, + GCancellable *cancellable, GError **error) { g_return_val_if_fail (name != NULL, FALSE); if (!ostree_validate_remote_name (name, error)) return FALSE; - g_autoptr(OstreeRemote) remote = NULL; + g_autoptr (OstreeRemote) remote = NULL; if (if_exists) { remote = _ostree_repo_get_remote (self, name, NULL); @@ -1912,7 +1790,7 @@ impl_repo_remote_delete (OstreeRepo *self, } else { - g_autoptr(GKeyFile) config = ostree_repo_copy_config (self); + g_autoptr (GKeyFile) config = ostree_repo_copy_config (self); /* XXX Not sure it's worth failing if the group to remove * isn't found. It's the end result we want, after all. */ @@ -1944,32 +1822,25 @@ impl_repo_remote_delete (OstreeRepo *self, * */ gboolean -ostree_repo_remote_delete (OstreeRepo *self, - const char *name, - GCancellable *cancellable, - GError **error) +ostree_repo_remote_delete (OstreeRepo *self, const char *name, GCancellable *cancellable, + GError **error) { return impl_repo_remote_delete (self, NULL, FALSE, name, cancellable, error); } - static gboolean -impl_repo_remote_replace (OstreeRepo *self, - GFile *sysroot, - const char *name, - const char *url, - GVariant *options, - GCancellable *cancellable, - GError **error) +impl_repo_remote_replace (OstreeRepo *self, GFile *sysroot, const char *name, const char *url, + GVariant *options, GCancellable *cancellable, GError **error) { g_return_val_if_fail (name != NULL, FALSE); - g_return_val_if_fail (options == NULL || g_variant_is_of_type (options, G_VARIANT_TYPE ("a{sv}")), FALSE); + g_return_val_if_fail (options == NULL || g_variant_is_of_type (options, G_VARIANT_TYPE ("a{sv}")), + FALSE); if (!ostree_validate_remote_name (name, error)) return FALSE; - g_autoptr(GError) local_error = NULL; - g_autoptr(OstreeRemote) remote = _ostree_repo_get_remote (self, name, &local_error); + g_autoptr (GError) local_error = NULL; + g_autoptr (OstreeRemote) remote = _ostree_repo_get_remote (self, name, &local_error); if (remote == NULL) { if (!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) @@ -1978,8 +1849,7 @@ impl_repo_remote_replace (OstreeRepo *self, return FALSE; } g_clear_error (&local_error); - if (!impl_repo_remote_add (self, sysroot, FALSE, name, url, options, - cancellable, error)) + if (!impl_repo_remote_add (self, sysroot, FALSE, name, url, options, cancellable, error)) return FALSE; } else @@ -2004,17 +1874,15 @@ impl_repo_remote_replace (OstreeRepo *self, if (remote->file != NULL) { gsize length; - g_autofree char *data = g_key_file_to_data (remote->options, &length, - NULL); + g_autofree char *data = g_key_file_to_data (remote->options, &length, NULL); - if (!g_file_replace_contents (remote->file, data, length, - NULL, FALSE, 0, NULL, + if (!g_file_replace_contents (remote->file, data, length, NULL, FALSE, 0, NULL, cancellable, error)) return FALSE; } else { - g_autoptr(GKeyFile) config = ostree_repo_copy_config (self); + g_autoptr (GKeyFile) config = ostree_repo_copy_config (self); /* Remove the existing group if it exists */ if (!g_key_file_remove_group (config, remote->group, &local_error)) @@ -2054,39 +1922,28 @@ impl_repo_remote_replace (OstreeRepo *self, * */ gboolean -ostree_repo_remote_change (OstreeRepo *self, - GFile *sysroot, - OstreeRepoRemoteChange changeop, - const char *name, - const char *url, - GVariant *options, - GCancellable *cancellable, - GError **error) +ostree_repo_remote_change (OstreeRepo *self, GFile *sysroot, OstreeRepoRemoteChange changeop, + const char *name, const char *url, GVariant *options, + GCancellable *cancellable, GError **error) { switch (changeop) { case OSTREE_REPO_REMOTE_CHANGE_ADD: - return impl_repo_remote_add (self, sysroot, FALSE, name, url, options, - cancellable, error); + return impl_repo_remote_add (self, sysroot, FALSE, name, url, options, cancellable, error); case OSTREE_REPO_REMOTE_CHANGE_ADD_IF_NOT_EXISTS: - return impl_repo_remote_add (self, sysroot, TRUE, name, url, options, - cancellable, error); + return impl_repo_remote_add (self, sysroot, TRUE, name, url, options, cancellable, error); case OSTREE_REPO_REMOTE_CHANGE_DELETE: - return impl_repo_remote_delete (self, sysroot, FALSE, name, - cancellable, error); + return impl_repo_remote_delete (self, sysroot, FALSE, name, cancellable, error); case OSTREE_REPO_REMOTE_CHANGE_DELETE_IF_EXISTS: - return impl_repo_remote_delete (self, sysroot, TRUE, name, - cancellable, error); + return impl_repo_remote_delete (self, sysroot, TRUE, name, cancellable, error); case OSTREE_REPO_REMOTE_CHANGE_REPLACE: - return impl_repo_remote_replace (self, sysroot, name, url, options, - cancellable, error); + return impl_repo_remote_replace (self, sysroot, name, url, options, cancellable, error); } g_assert_not_reached (); } static void -_ostree_repo_remote_list (OstreeRepo *self, - GHashTable *out) +_ostree_repo_remote_list (OstreeRepo *self, GHashTable *out) { GHashTableIter iter; gpointer key, value; @@ -2115,16 +1972,14 @@ _ostree_repo_remote_list (OstreeRepo *self, * array of remote names **/ char ** -ostree_repo_remote_list (OstreeRepo *self, - guint *out_n_remotes) +ostree_repo_remote_list (OstreeRepo *self, guint *out_n_remotes) { char **remotes = NULL; guint n_remotes; - g_autoptr(GHashTable) remotes_ht = NULL; + g_autoptr (GHashTable) remotes_ht = NULL; - remotes_ht = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) NULL); + remotes_ht = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, + (GDestroyNotify)NULL); _ostree_repo_remote_list (self, remotes_ht); @@ -2138,7 +1993,7 @@ ostree_repo_remote_list (OstreeRepo *self, remotes = g_new (char *, n_remotes + 1); list = g_hash_table_get_keys (remotes_ht); - list = g_list_sort (list, (GCompareFunc) strcmp); + list = g_list_sort (list, (GCompareFunc)strcmp); for (link = list; link != NULL; link = link->next) remotes[ii++] = g_strdup (link->data); @@ -2167,10 +2022,7 @@ ostree_repo_remote_list (OstreeRepo *self, * Returns: %TRUE on success, %FALSE on failure */ gboolean -ostree_repo_remote_get_url (OstreeRepo *self, - const char *name, - char **out_url, - GError **error) +ostree_repo_remote_get_url (OstreeRepo *self, const char *name, char **out_url, GError **error) { g_return_val_if_fail (name != NULL, FALSE); @@ -2211,10 +2063,8 @@ ostree_repo_remote_get_url (OstreeRepo *self, * Returns: %TRUE on success, %FALSE on failure */ gboolean -ostree_repo_remote_get_gpg_verify (OstreeRepo *self, - const char *name, - gboolean *out_gpg_verify, - GError **error) +ostree_repo_remote_get_gpg_verify (OstreeRepo *self, const char *name, gboolean *out_gpg_verify, + GError **error) { g_return_val_if_fail (OSTREE_IS_REPO (self), FALSE); g_return_val_if_fail (name != NULL, FALSE); @@ -2227,8 +2077,8 @@ ostree_repo_remote_get_gpg_verify (OstreeRepo *self, return TRUE; } - return ostree_repo_get_remote_boolean_option (self, name, "gpg-verify", - TRUE, out_gpg_verify, error); + return ostree_repo_get_remote_boolean_option (self, name, "gpg-verify", TRUE, out_gpg_verify, + error); } /** @@ -2245,13 +2095,11 @@ ostree_repo_remote_get_gpg_verify (OstreeRepo *self, * Returns: %TRUE on success, %FALSE on failure */ gboolean -ostree_repo_remote_get_gpg_verify_summary (OstreeRepo *self, - const char *name, - gboolean *out_gpg_verify_summary, - GError **error) +ostree_repo_remote_get_gpg_verify_summary (OstreeRepo *self, const char *name, + gboolean *out_gpg_verify_summary, GError **error) { - return ostree_repo_get_remote_boolean_option (self, name, "gpg-verify-summary", - FALSE, out_gpg_verify_summary, error); + return ostree_repo_get_remote_boolean_option (self, name, "gpg-verify-summary", FALSE, + out_gpg_verify_summary, error); } /** @@ -2259,7 +2107,8 @@ ostree_repo_remote_get_gpg_verify_summary (OstreeRepo *self, * @self: Self * @name: name of a remote * @source_stream: (nullable): a #GInputStream, or %NULL - * @key_ids: (array zero-terminated=1) (element-type utf8) (nullable): a %NULL-terminated array of GPG key IDs, or %NULL + * @key_ids: (array zero-terminated=1) (element-type utf8) (nullable): a %NULL-terminated array of + * GPG key IDs, or %NULL * @out_imported: (out) (optional): return location for the number of imported * keys, or %NULL * @cancellable: a #GCancellable @@ -2276,25 +2125,21 @@ ostree_repo_remote_get_gpg_verify_summary (OstreeRepo *self, * Returns: %TRUE on success, %FALSE on failure */ gboolean -ostree_repo_remote_gpg_import (OstreeRepo *self, - const char *name, - GInputStream *source_stream, - const char * const *key_ids, - guint *out_imported, - GCancellable *cancellable, - GError **error) +ostree_repo_remote_gpg_import (OstreeRepo *self, const char *name, GInputStream *source_stream, + const char *const *key_ids, guint *out_imported, + GCancellable *cancellable, GError **error) { #ifndef OSTREE_DISABLE_GPGME OstreeRemote *remote; - g_auto(gpgme_ctx_t) source_context = NULL; - g_auto(gpgme_ctx_t) target_context = NULL; - g_auto(gpgme_data_t) data_buffer = NULL; + g_auto (gpgme_ctx_t) source_context = NULL; + g_auto (gpgme_ctx_t) target_context = NULL; + g_auto (gpgme_data_t) data_buffer = NULL; gpgme_import_result_t import_result; gpgme_import_status_t import_status; g_autofree char *source_tmp_dir = NULL; g_autofree char *target_tmp_dir = NULL; glnx_autofd int target_temp_fd = -1; - g_autoptr(GPtrArray) keys = NULL; + g_autoptr (GPtrArray) keys = NULL; struct stat stbuf; gpgme_error_t gpg_error; gboolean ret = FALSE; @@ -2321,8 +2166,7 @@ ostree_repo_remote_gpg_import (OstreeRepo *self, { data_buffer = ot_gpgme_data_input (source_stream); - if (!ot_gpgme_ctx_tmp_home_dir (source_context, &source_tmp_dir, - NULL, cancellable, error)) + if (!ot_gpgme_ctx_tmp_home_dir (source_context, &source_tmp_dir, NULL, cancellable, error)) { g_prefix_error (error, "Unable to configure context: "); goto out; @@ -2343,7 +2187,7 @@ ostree_repo_remote_gpg_import (OstreeRepo *self, /* The keys array will contain a NULL terminator, but it turns out, * although not documented, gpgme_key_unref() gracefully handles it. */ - 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) { @@ -2401,8 +2245,7 @@ ostree_repo_remote_gpg_import (OstreeRepo *self, goto out; /* No need for an output stream since we copy in a pubring.gpg. */ - if (!ot_gpgme_ctx_tmp_home_dir (target_context, &target_tmp_dir, - NULL, cancellable, error)) + if (!ot_gpgme_ctx_tmp_home_dir (target_context, &target_tmp_dir, NULL, cancellable, error)) { g_prefix_error (error, "Unable to configure context: "); goto out; @@ -2416,9 +2259,8 @@ ostree_repo_remote_gpg_import (OstreeRepo *self, if (fstatat (self->repo_dir_fd, remote->keyring, &stbuf, AT_SYMLINK_NOFOLLOW) == 0) { - if (!glnx_file_copy_at (self->repo_dir_fd, remote->keyring, - &stbuf, target_temp_fd, "pubring.gpg", - GLNX_FILE_COPY_NOXATTRS, cancellable, error)) + if (!glnx_file_copy_at (self->repo_dir_fd, remote->keyring, &stbuf, target_temp_fd, + "pubring.gpg", GLNX_FILE_COPY_NOXATTRS, cancellable, error)) { g_prefix_error (error, "Unable to copy remote's keyring: "); goto out; @@ -2435,8 +2277,7 @@ ostree_repo_remote_gpg_import (OstreeRepo *self, * * [1] https://gnupg.org/faq/whats-new-in-2.1.html#keybox */ - fd = openat (target_temp_fd, "pubring.gpg", - O_WRONLY | O_CREAT | O_CLOEXEC | O_NOCTTY, 0644); + fd = openat (target_temp_fd, "pubring.gpg", O_WRONLY | O_CREAT | O_CLOEXEC | O_NOCTTY, 0644); if (fd == -1) { glnx_set_prefix_error_from_errno (error, "%s", "Unable to create pubring.gpg"); @@ -2459,16 +2300,14 @@ ostree_repo_remote_gpg_import (OstreeRepo *self, goto out; } - gpg_error = gpgme_op_export_keys (source_context, - (gpgme_key_t *) keys->pdata, 0, - data_buffer); + gpg_error = gpgme_op_export_keys (source_context, (gpgme_key_t *)keys->pdata, 0, data_buffer); if (gpg_error != GPG_ERR_NO_ERROR) { ot_gpgme_throw (gpg_error, error, "Unable to export keys"); goto out; } - (void) gpgme_data_seek (data_buffer, 0, SEEK_SET); + (void)gpgme_data_seek (data_buffer, 0, SEEK_SET); gpg_error = gpgme_op_import (target_context, data_buffer); if (gpg_error != GPG_ERR_NO_ERROR) @@ -2482,28 +2321,24 @@ ostree_repo_remote_gpg_import (OstreeRepo *self, /* Check the status of each import and fail on the first error. * All imports must be successful to update the remote's keyring. */ - for (import_status = import_result->imports; - import_status != NULL; + for (import_status = import_result->imports; import_status != NULL; import_status = import_status->next) { if (import_status->result != GPG_ERR_NO_ERROR) { - ot_gpgme_throw (gpg_error, error, "Unable to import key \"%s\"", - import_status->fpr); + ot_gpgme_throw (gpg_error, error, "Unable to import key \"%s\"", import_status->fpr); goto out; } } /* Import successful; replace the remote's old keyring with the * updated keyring in the target context's temporary directory. */ - if (!glnx_file_copy_at (target_temp_fd, "pubring.gpg", NULL, - self->repo_dir_fd, remote->keyring, - GLNX_FILE_COPY_NOXATTRS | GLNX_FILE_COPY_OVERWRITE, - cancellable, error)) + if (!glnx_file_copy_at (target_temp_fd, "pubring.gpg", NULL, self->repo_dir_fd, remote->keyring, + GLNX_FILE_COPY_NOXATTRS | GLNX_FILE_COPY_OVERWRITE, cancellable, error)) goto out; if (out_imported != NULL) - *out_imported = (guint) import_result->imported; + *out_imported = (guint)import_result->imported; ret = TRUE; @@ -2511,34 +2346,32 @@ out: if (remote != NULL) ostree_remote_unref (remote); - if (source_tmp_dir != NULL) { - ot_gpgme_kill_agent (source_tmp_dir); - (void) glnx_shutil_rm_rf_at (AT_FDCWD, source_tmp_dir, NULL, NULL); - } + if (source_tmp_dir != NULL) + { + ot_gpgme_kill_agent (source_tmp_dir); + (void)glnx_shutil_rm_rf_at (AT_FDCWD, source_tmp_dir, NULL, NULL); + } - if (target_tmp_dir != NULL) { - ot_gpgme_kill_agent (target_tmp_dir); - (void) glnx_shutil_rm_rf_at (AT_FDCWD, target_tmp_dir, NULL, NULL); - } + if (target_tmp_dir != NULL) + { + ot_gpgme_kill_agent (target_tmp_dir); + (void)glnx_shutil_rm_rf_at (AT_FDCWD, target_tmp_dir, NULL, NULL); + } g_prefix_error (error, "GPG: "); return ret; -#else /* OSTREE_DISABLE_GPGME */ +#else /* OSTREE_DISABLE_GPGME */ return glnx_throw (error, "GPG feature is disabled in a build time"); #endif /* OSTREE_DISABLE_GPGME */ } #ifndef OSTREE_DISABLE_GPGME -static gboolean -_ostree_repo_gpg_prepare_verifier (OstreeRepo *self, - const gchar *remote_name, - GFile *keyringdir, - GFile *extra_keyring, - gboolean add_global_keyrings, - OstreeGpgVerifier **out_verifier, - GCancellable *cancellable, - GError **error); +static gboolean _ostree_repo_gpg_prepare_verifier (OstreeRepo *self, const gchar *remote_name, + GFile *keyringdir, GFile *extra_keyring, + gboolean add_global_keyrings, + OstreeGpgVerifier **out_verifier, + GCancellable *cancellable, GError **error); #endif /* OSTREE_DISABLE_GPGME */ /** @@ -2565,39 +2398,32 @@ _ostree_repo_gpg_prepare_verifier (OstreeRepo *self, * Since: 2021.4 */ gboolean -ostree_repo_remote_get_gpg_keys (OstreeRepo *self, - const char *name, - const char * const *key_ids, - GPtrArray **out_keys, - GCancellable *cancellable, - GError **error) +ostree_repo_remote_get_gpg_keys (OstreeRepo *self, const char *name, const char *const *key_ids, + GPtrArray **out_keys, GCancellable *cancellable, GError **error) { #ifndef OSTREE_DISABLE_GPGME - g_autoptr(OstreeGpgVerifier) verifier = NULL; + g_autoptr (OstreeGpgVerifier) verifier = NULL; gboolean global_keyrings = (name == NULL); - if (!_ostree_repo_gpg_prepare_verifier (self, name, NULL, NULL, global_keyrings, - &verifier, cancellable, error)) + if (!_ostree_repo_gpg_prepare_verifier (self, name, NULL, NULL, global_keyrings, &verifier, + cancellable, error)) return FALSE; - g_autoptr(GPtrArray) gpg_keys = NULL; - if (!_ostree_gpg_verifier_list_keys (verifier, key_ids, &gpg_keys, - cancellable, error)) + g_autoptr (GPtrArray) gpg_keys = NULL; + if (!_ostree_gpg_verifier_list_keys (verifier, key_ids, &gpg_keys, cancellable, error)) return FALSE; - g_autoptr(GPtrArray) keys = - g_ptr_array_new_with_free_func ((GDestroyNotify) g_variant_unref); + g_autoptr (GPtrArray) keys = g_ptr_array_new_with_free_func ((GDestroyNotify)g_variant_unref); for (guint i = 0; i < gpg_keys->len; i++) { gpgme_key_t key = gpg_keys->pdata[i]; - g_auto(GVariantBuilder) subkeys_builder = OT_VARIANT_BUILDER_INITIALIZER; + g_auto (GVariantBuilder) subkeys_builder = OT_VARIANT_BUILDER_INITIALIZER; g_variant_builder_init (&subkeys_builder, G_VARIANT_TYPE ("aa{sv}")); - g_auto(GVariantBuilder) uids_builder = OT_VARIANT_BUILDER_INITIALIZER; + g_auto (GVariantBuilder) uids_builder = OT_VARIANT_BUILDER_INITIALIZER; g_variant_builder_init (&uids_builder, G_VARIANT_TYPE ("aa{sv}")); - for (gpgme_subkey_t subkey = key->subkeys; subkey != NULL; - subkey = subkey->next) + for (gpgme_subkey_t subkey = key->subkeys; subkey != NULL; subkey = subkey->next) { - g_auto(GVariantDict) subkey_dict = OT_VARIANT_BUILDER_INITIALIZER; + g_auto (GVariantDict) subkey_dict = OT_VARIANT_BUILDER_INITIALIZER; g_variant_dict_init (&subkey_dict, NULL); g_variant_dict_insert_value (&subkey_dict, "fingerprint", g_variant_new_string (subkey->fpr)); @@ -2611,8 +2437,7 @@ ostree_repo_remote_get_gpg_keys (OstreeRepo *self, g_variant_new_boolean (subkey->expired)); g_variant_dict_insert_value (&subkey_dict, "invalid", g_variant_new_boolean (subkey->invalid)); - g_variant_builder_add (&subkeys_builder, "@a{sv}", - g_variant_dict_end (&subkey_dict)); + g_variant_builder_add (&subkeys_builder, "@a{sv}", g_variant_dict_end (&subkey_dict)); } for (gpgme_user_id_t uid = key->uids; uid != NULL; uid = uid->next) @@ -2622,41 +2447,31 @@ ostree_repo_remote_get_gpg_keys (OstreeRepo *self, g_autofree char *direct_url = NULL; if (uid->address != NULL) { - if (!ot_gpg_wkd_urls (uid->address, &advanced_url, &direct_url, - error)) + if (!ot_gpg_wkd_urls (uid->address, &advanced_url, &direct_url, error)) return FALSE; } - g_auto(GVariantDict) uid_dict = OT_VARIANT_BUILDER_INITIALIZER; + g_auto (GVariantDict) uid_dict = OT_VARIANT_BUILDER_INITIALIZER; g_variant_dict_init (&uid_dict, NULL); - g_variant_dict_insert_value (&uid_dict, "uid", - g_variant_new_string (uid->uid)); - g_variant_dict_insert_value (&uid_dict, "name", - g_variant_new_string (uid->name)); - g_variant_dict_insert_value (&uid_dict, "comment", - g_variant_new_string (uid->comment)); - g_variant_dict_insert_value (&uid_dict, "email", - g_variant_new_string (uid->email)); - g_variant_dict_insert_value (&uid_dict, "revoked", - g_variant_new_boolean (uid->revoked)); - g_variant_dict_insert_value (&uid_dict, "invalid", - g_variant_new_boolean (uid->invalid)); + g_variant_dict_insert_value (&uid_dict, "uid", g_variant_new_string (uid->uid)); + g_variant_dict_insert_value (&uid_dict, "name", g_variant_new_string (uid->name)); + g_variant_dict_insert_value (&uid_dict, "comment", g_variant_new_string (uid->comment)); + g_variant_dict_insert_value (&uid_dict, "email", g_variant_new_string (uid->email)); + g_variant_dict_insert_value (&uid_dict, "revoked", g_variant_new_boolean (uid->revoked)); + g_variant_dict_insert_value (&uid_dict, "invalid", g_variant_new_boolean (uid->invalid)); g_variant_dict_insert_value (&uid_dict, "advanced_url", g_variant_new ("ms", advanced_url)); - g_variant_dict_insert_value (&uid_dict, "direct_url", - g_variant_new ("ms", direct_url)); - g_variant_builder_add (&uids_builder, "@a{sv}", - g_variant_dict_end (&uid_dict)); + g_variant_dict_insert_value (&uid_dict, "direct_url", g_variant_new ("ms", direct_url)); + g_variant_builder_add (&uids_builder, "@a{sv}", g_variant_dict_end (&uid_dict)); } /* Currently empty */ - g_auto(GVariantDict) metadata_dict = OT_VARIANT_BUILDER_INITIALIZER; + g_auto (GVariantDict) metadata_dict = OT_VARIANT_BUILDER_INITIALIZER; g_variant_dict_init (&metadata_dict, NULL); - GVariant *key_variant = g_variant_new ("(@aa{sv}@aa{sv}@a{sv})", - g_variant_builder_end (&subkeys_builder), - g_variant_builder_end (&uids_builder), - g_variant_dict_end (&metadata_dict)); + GVariant *key_variant = g_variant_new ( + "(@aa{sv}@aa{sv}@a{sv})", g_variant_builder_end (&subkeys_builder), + g_variant_builder_end (&uids_builder), g_variant_dict_end (&metadata_dict)); g_ptr_array_add (keys, g_variant_ref_sink (key_variant)); } @@ -2664,7 +2479,7 @@ ostree_repo_remote_get_gpg_keys (OstreeRepo *self, *out_keys = g_steal_pointer (&keys); return TRUE; -#else /* OSTREE_DISABLE_GPGME */ +#else /* OSTREE_DISABLE_GPGME */ return glnx_throw (error, "GPG feature is disabled in a build time"); #endif /* OSTREE_DISABLE_GPGME */ } @@ -2697,26 +2512,16 @@ ostree_repo_remote_get_gpg_keys (OstreeRepo *self, * Returns: %TRUE on success, %FALSE on failure */ gboolean -ostree_repo_remote_fetch_summary (OstreeRepo *self, - const char *name, - GBytes **out_summary, - GBytes **out_signatures, - GCancellable *cancellable, - GError **error) -{ - return ostree_repo_remote_fetch_summary_with_options (self, - name, - NULL, - out_summary, - out_signatures, - cancellable, - error); +ostree_repo_remote_fetch_summary (OstreeRepo *self, const char *name, GBytes **out_summary, + GBytes **out_signatures, GCancellable *cancellable, + GError **error) +{ + return ostree_repo_remote_fetch_summary_with_options (self, name, NULL, out_summary, + out_signatures, cancellable, error); } static gboolean -ostree_repo_mode_to_string (OstreeRepoMode mode, - const char **out_mode, - GError **error) +ostree_repo_mode_to_string (OstreeRepoMode mode, const char **out_mode, GError **error) { const char *ret_mode; @@ -2733,7 +2538,7 @@ ostree_repo_mode_to_string (OstreeRepoMode mode, break; case OSTREE_REPO_MODE_ARCHIVE: /* Legacy alias */ - ret_mode ="archive-z2"; + ret_mode = "archive-z2"; break; case OSTREE_REPO_MODE_BARE_SPLIT_XATTRS: ret_mode = "bare-split-xattrs"; @@ -2753,9 +2558,7 @@ ostree_repo_mode_to_string (OstreeRepoMode mode, * @error: a #GError if the string is not a valid mode */ gboolean -ostree_repo_mode_from_string (const char *mode, - OstreeRepoMode *out_mode, - GError **error) +ostree_repo_mode_from_string (const char *mode, OstreeRepoMode *out_mode, GError **error) { OstreeRepoMode ret_mode; @@ -2765,8 +2568,7 @@ ostree_repo_mode_from_string (const char *mode, ret_mode = OSTREE_REPO_MODE_BARE_USER; else if (strcmp (mode, "bare-user-only") == 0) ret_mode = OSTREE_REPO_MODE_BARE_USER_ONLY; - else if (strcmp (mode, "archive-z2") == 0 || - strcmp (mode, "archive") == 0) + else if (strcmp (mode, "archive-z2") == 0 || strcmp (mode, "archive") == 0) ret_mode = OSTREE_REPO_MODE_ARCHIVE; else if (strcmp (mode, "bare-split-xattrs") == 0) ret_mode = OSTREE_REPO_MODE_BARE_SPLIT_XATTRS; @@ -2777,28 +2579,24 @@ ostree_repo_mode_from_string (const char *mode, return TRUE; } -#define DEFAULT_CONFIG_CONTENTS ("[core]\n" \ - "repo_version=1\n") +#define DEFAULT_CONFIG_CONTENTS \ + ("[core]\n" \ + "repo_version=1\n") /* Just write the dirs to disk, return a dfd */ static gboolean -repo_create_at_internal (int dfd, - const char *path, - OstreeRepoMode mode, - GVariant *options, - int *out_dfd, - GCancellable *cancellable, - GError **error) +repo_create_at_internal (int dfd, const char *path, OstreeRepoMode mode, GVariant *options, + int *out_dfd, GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("Creating repo", error); - struct stat stbuf; + struct stat stbuf; /* We do objects/ last - if it exists we do nothing and exit successfully */ - const char *state_dirs[] = { "tmp", "extensions", "state", - "refs", "refs/heads", "refs/mirrors", - "refs/remotes", "objects" }; + const char *state_dirs[] = { "tmp", "extensions", "state", "refs", + "refs/heads", "refs/mirrors", "refs/remotes", "objects" }; /* Early return if we have an existing repo */ - { g_autofree char *objects_path = g_build_filename (path, "objects", NULL); + { + g_autofree char *objects_path = g_build_filename (path, "objects", NULL); if (!glnx_fstatat_allow_noent (dfd, objects_path, &stbuf, 0, error)) return FALSE; @@ -2829,7 +2627,7 @@ repo_create_at_internal (int dfd, if (errno == ENOENT) { const char *mode_str = NULL; - g_autoptr(GString) config_data = g_string_new (DEFAULT_CONFIG_CONTENTS); + g_autoptr (GString) config_data = g_string_new (DEFAULT_CONFIG_CONTENTS); if (!ostree_repo_mode_to_string (mode, &mode_str, error)) return FALSE; @@ -2843,9 +2641,8 @@ repo_create_at_internal (int dfd, if (collection_id != NULL) g_string_append_printf (config_data, "collection-id=%s\n", collection_id); - if (!glnx_file_replace_contents_at (repo_dfd, "config", - (guint8*)config_data->str, config_data->len, - 0, cancellable, error)) + if (!glnx_file_replace_contents_at (repo_dfd, "config", (guint8 *)config_data->str, + config_data->len, 0, cancellable, error)) return FALSE; } @@ -2864,13 +2661,15 @@ repo_create_at_internal (int dfd, */ if (mode == OSTREE_REPO_MODE_BARE_USER) { - g_auto(GLnxTmpfile) tmpf = { 0, }; + g_auto (GLnxTmpfile) tmpf = { + 0, + }; - if (!glnx_open_tmpfile_linkable_at (repo_dfd, ".", O_RDWR|O_CLOEXEC, &tmpf, error)) + if (!glnx_open_tmpfile_linkable_at (repo_dfd, ".", O_RDWR | O_CLOEXEC, &tmpf, error)) return FALSE; if (!_ostree_write_bareuser_metadata (tmpf.fd, 0, 0, 644, NULL, error)) return FALSE; - } + } *out_dfd = g_steal_fd (&repo_dfd); return TRUE; @@ -2899,24 +2698,20 @@ repo_create_at_internal (int dfd, * this function on a repository initialized via ostree_repo_open_at(). */ gboolean -ostree_repo_create (OstreeRepo *self, - OstreeRepoMode mode, - GCancellable *cancellable, - GError **error) +ostree_repo_create (OstreeRepo *self, OstreeRepoMode mode, GCancellable *cancellable, + GError **error) { g_return_val_if_fail (self->repodir, FALSE); const char *repopath = gs_file_get_path_cached (self->repodir); - g_autoptr(GVariantBuilder) builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); + g_autoptr (GVariantBuilder) builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); if (self->collection_id) g_variant_builder_add (builder, "{s@v}", "collection-id", g_variant_new_variant (g_variant_new_string (self->collection_id))); glnx_autofd int repo_dir_fd = -1; - g_autoptr(GVariant) options = g_variant_ref_sink (g_variant_builder_end (builder)); - if (!repo_create_at_internal (AT_FDCWD, repopath, mode, - options, - &repo_dir_fd, - cancellable, error)) + g_autoptr (GVariant) options = g_variant_ref_sink (g_variant_builder_end (builder)); + if (!repo_create_at_internal (AT_FDCWD, repopath, mode, options, &repo_dir_fd, cancellable, + error)) return FALSE; self->repo_dir_fd = g_steal_fd (&repo_dir_fd); if (!ostree_repo_open (self, cancellable, error)) @@ -2951,33 +2746,25 @@ ostree_repo_create (OstreeRepo *self, * Since: 2017.10 */ OstreeRepo * -ostree_repo_create_at (int dfd, - const char *path, - OstreeRepoMode mode, - GVariant *options, - GCancellable *cancellable, - GError **error) +ostree_repo_create_at (int dfd, const char *path, OstreeRepoMode mode, GVariant *options, + GCancellable *cancellable, GError **error) { glnx_autofd int repo_dfd = -1; - if (!repo_create_at_internal (dfd, path, mode, options, &repo_dfd, - cancellable, error)) + if (!repo_create_at_internal (dfd, path, mode, options, &repo_dfd, cancellable, error)) return NULL; return repo_open_at_take_fd (&repo_dfd, cancellable, error); } static gboolean -enumerate_directory_allow_noent (GFile *dirpath, - const char *queryargs, - GFileQueryInfoFlags queryflags, - GFileEnumerator **out_direnum, - GCancellable *cancellable, - GError **error) -{ - g_autoptr(GError) temp_error = NULL; - g_autoptr(GFileEnumerator) ret_direnum = NULL; - - ret_direnum = g_file_enumerate_children (dirpath, queryargs, queryflags, - cancellable, &temp_error); +enumerate_directory_allow_noent (GFile *dirpath, const char *queryargs, + GFileQueryInfoFlags queryflags, GFileEnumerator **out_direnum, + GCancellable *cancellable, GError **error) +{ + g_autoptr (GError) temp_error = NULL; + g_autoptr (GFileEnumerator) ret_direnum = NULL; + + ret_direnum + = g_file_enumerate_children (dirpath, queryargs, queryflags, cancellable, &temp_error); if (!ret_direnum) { if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) @@ -2995,13 +2782,10 @@ enumerate_directory_allow_noent (GFile *dirpath, } static gboolean -add_remotes_from_keyfile (OstreeRepo *self, - GKeyFile *keyfile, - GFile *file, - GError **error) +add_remotes_from_keyfile (OstreeRepo *self, GKeyFile *keyfile, GFile *file, GError **error) { GQueue queue = G_QUEUE_INIT; - g_auto(GStrv) groups = NULL; + g_auto (GStrv) groups = NULL; gsize length, ii; gboolean ret = FALSE; @@ -3024,8 +2808,7 @@ add_remotes_from_keyfile (OstreeRepo *self, if (g_hash_table_contains (self->remotes, remote->name)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Multiple specifications found for remote \"%s\"", - remote->name); + "Multiple specifications found for remote \"%s\"", remote->name); goto out; } @@ -3042,7 +2825,7 @@ add_remotes_from_keyfile (OstreeRepo *self, ret = TRUE; - out: +out: while (!g_queue_is_empty (&queue)) ostree_remote_unref (g_queue_pop_head (&queue)); @@ -3052,31 +2835,26 @@ add_remotes_from_keyfile (OstreeRepo *self, } static gboolean -append_one_remote_config (OstreeRepo *self, - GFile *path, - GCancellable *cancellable, - GError **error) -{ - g_autoptr(GKeyFile) remotedata = g_key_file_new (); - if (!g_key_file_load_from_file (remotedata, gs_file_get_path_cached (path), - 0, error)) +append_one_remote_config (OstreeRepo *self, GFile *path, GCancellable *cancellable, GError **error) +{ + g_autoptr (GKeyFile) remotedata = g_key_file_new (); + if (!g_key_file_load_from_file (remotedata, gs_file_get_path_cached (path), 0, error)) return FALSE; return add_remotes_from_keyfile (self, remotedata, path, error); } static GFile * -get_remotes_d_dir (OstreeRepo *self, - GFile *sysroot) +get_remotes_d_dir (OstreeRepo *self, GFile *sysroot) { - g_autoptr(GFile) sysroot_owned = NULL; + g_autoptr (GFile) sysroot_owned = NULL; /* Very complicated sysroot logic; this bit breaks the otherwise mostly clean * layering between OstreeRepo and OstreeSysroot. First, If a sysroot was * provided, use it. Otherwise, check to see whether we reference * /ostree/repo, or if not that, see if we have a ref to a sysroot (and it's * physical). */ - g_autoptr(OstreeSysroot) sysroot_ref = NULL; + g_autoptr (OstreeSysroot) sysroot_ref = NULL; if (sysroot == NULL) { /* No explicit sysroot? Let's see if we have a kind */ @@ -3091,7 +2869,7 @@ get_remotes_d_dir (OstreeRepo *self, sysroot = sysroot_owned = g_file_new_for_path ("/"); break; case OSTREE_REPO_SYSROOT_KIND_VIA_SYSROOT: - sysroot_ref = (OstreeSysroot*)g_weak_ref_get (&self->sysroot); + sysroot_ref = (OstreeSysroot *)g_weak_ref_get (&self->sysroot); /* Only write to /etc/ostree/remotes.d if we are pointed at a deployment */ if (sysroot_ref != NULL && !sysroot_ref->is_physical) sysroot = ostree_sysroot_get_path (sysroot_ref); @@ -3133,19 +2911,25 @@ min_free_space_calculate_reserved_bytes (OstreeRepo *self, guint64 *bytes, GErro if (self->min_free_space_mb > 0) { if (self->min_free_space_mb > (G_MAXUINT64 >> 20)) - return glnx_throw (error, "min-free-space value is greater than the maximum allowed value of %" G_GUINT64_FORMAT " bytes", - (G_MAXUINT64 >> 20)); + return glnx_throw ( + error, + "min-free-space value is greater than the maximum allowed value of %" G_GUINT64_FORMAT + " bytes", + (G_MAXUINT64 >> 20)); reserved_bytes = self->min_free_space_mb << 20; } else if (self->min_free_space_percent > 0) { if (stvfsbuf.f_frsize > (G_MAXUINT64 / stvfsbuf.f_blocks)) - return glnx_throw (error, "Filesystem's size is greater than the maximum allowed value of %" G_GUINT64_FORMAT " bytes", - (G_MAXUINT64 / stvfsbuf.f_blocks)); + return glnx_throw ( + error, + "Filesystem's size is greater than the maximum allowed value of %" G_GUINT64_FORMAT + " bytes", + (G_MAXUINT64 / stvfsbuf.f_blocks)); guint64 total_bytes = (stvfsbuf.f_frsize * stvfsbuf.f_blocks); - reserved_bytes = ((double)total_bytes) * (self->min_free_space_percent/100.0); + reserved_bytes = ((double)total_bytes) * (self->min_free_space_percent / 100.0); } *bytes = reserved_bytes; @@ -3153,9 +2937,8 @@ min_free_space_calculate_reserved_bytes (OstreeRepo *self, guint64 *bytes, GErro } static gboolean -min_free_space_size_validate_and_convert (OstreeRepo *self, - const char *min_free_space_size_str, - GError **error) +min_free_space_size_validate_and_convert (OstreeRepo *self, const char *min_free_space_size_str, + GError **error) { static GRegex *regex; static gsize regex_initialized; @@ -3166,7 +2949,7 @@ min_free_space_size_validate_and_convert (OstreeRepo *self, g_once_init_leave (®ex_initialized, 1); } - g_autoptr(GMatchInfo) match = NULL; + g_autoptr (GMatchInfo) match = NULL; if (!g_regex_match (regex, min_free_space_size_str, 0, &match)) return glnx_throw (error, "It should be of the format '123MB', '123GB' or '123TB'"); @@ -3176,17 +2959,17 @@ min_free_space_size_validate_and_convert (OstreeRepo *self, switch (*unit) { - case 'M': - shifts = 0; - break; - case 'G': - shifts = 10; - break; - case 'T': - shifts = 20; - break; - default: - g_assert_not_reached (); + case 'M': + shifts = 0; + break; + case 'G': + shifts = 10; + break; + case 'T': + shifts = 20; + break; + default: + g_assert_not_reached (); } guint64 min_free_space = g_ascii_strtoull (size_str, NULL, 10); @@ -3199,9 +2982,7 @@ min_free_space_size_validate_and_convert (OstreeRepo *self, } static gboolean -reload_core_config (OstreeRepo *self, - GCancellable *cancellable, - GError **error) +reload_core_config (OstreeRepo *self, GCancellable *cancellable, GError **error) { g_autofree char *version = NULL; g_autofree char *mode = NULL; @@ -3213,8 +2994,7 @@ reload_core_config (OstreeRepo *self, g_clear_pointer (&self->config, g_key_file_unref); self->config = g_key_file_new (); - contents = glnx_file_get_contents_utf8_at (self->repo_dir_fd, "config", &len, - NULL, error); + contents = glnx_file_get_contents_utf8_at (self->repo_dir_fd, "config", &len, NULL, error); if (!contents) return FALSE; if (!g_key_file_load_from_data (self->config, contents, len, 0, error)) @@ -3230,18 +3010,18 @@ reload_core_config (OstreeRepo *self, if (strcmp (version, "1") != 0) return glnx_throw (error, "Invalid repository version '%s'", version); - if (!ot_keyfile_get_boolean_with_default (self->config, "core", "archive", - FALSE, &is_archive, error)) + if (!ot_keyfile_get_boolean_with_default (self->config, "core", "archive", FALSE, &is_archive, + error)) return FALSE; if (is_archive) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, - "This version of OSTree no longer supports \"archive\" repositories; use archive-z2 instead"); + "This version of OSTree no longer supports \"archive\" repositories; use " + "archive-z2 instead"); return FALSE; } - if (!ot_keyfile_get_value_with_default (self->config, "core", "mode", - "bare", &mode, error)) + if (!ot_keyfile_get_value_with_default (self->config, "core", "mode", "bare", &mode, error)) return FALSE; if (!ostree_repo_mode_from_string (mode, &self->mode, error)) return FALSE; @@ -3258,24 +3038,25 @@ reload_core_config (OstreeRepo *self, { gboolean do_fsync; - if (!ot_keyfile_get_boolean_with_default (self->config, "core", "fsync", - TRUE, &do_fsync, error)) + if (!ot_keyfile_get_boolean_with_default (self->config, "core", "fsync", TRUE, &do_fsync, + error)) return FALSE; if (!do_fsync) ostree_repo_set_disable_fsync (self, TRUE); } - if (!ot_keyfile_get_boolean_with_default (self->config, "core", "per-object-fsync", - FALSE, &self->per_object_fsync, error)) + if (!ot_keyfile_get_boolean_with_default (self->config, "core", "per-object-fsync", FALSE, + &self->per_object_fsync, error)) return FALSE; /* See https://github.com/ostreedev/ostree/issues/758 */ - if (!ot_keyfile_get_boolean_with_default (self->config, "core", "disable-xattrs", - FALSE, &self->disable_xattrs, error)) + if (!ot_keyfile_get_boolean_with_default (self->config, "core", "disable-xattrs", FALSE, + &self->disable_xattrs, error)) return FALSE; - { g_autofree char *tmp_expiry_seconds = NULL; + { + g_autofree char *tmp_expiry_seconds = NULL; /* 86400 secs = one day */ if (!ot_keyfile_get_value_with_default (self->config, "core", "tmp-expiry-secs", "86400", @@ -3285,10 +3066,11 @@ reload_core_config (OstreeRepo *self, self->tmp_expiry_seconds = g_ascii_strtoull (tmp_expiry_seconds, NULL, 10); } - { gboolean locking; + { + gboolean locking; /* Enabled by default in 2018.05 */ - if (!ot_keyfile_get_boolean_with_default (self->config, "core", "locking", - TRUE, &locking, error)) + if (!ot_keyfile_get_boolean_with_default (self->config, "core", "locking", TRUE, &locking, + error)) return FALSE; if (!locking) { @@ -3306,7 +3088,8 @@ reload_core_config (OstreeRepo *self, } } - { g_autofree char *compression_level_str = NULL; + { + g_autofree char *compression_level_str = NULL; /* gzip defaults to 6 */ (void)ot_keyfile_get_value_with_default (self->config, "archive", "zlib-level", NULL, @@ -3314,26 +3097,29 @@ reload_core_config (OstreeRepo *self, if (compression_level_str) /* Ensure level is in [1,9] */ - self->zlib_compression_level = MAX (1, MIN (9, g_ascii_strtoull (compression_level_str, NULL, 10))); + self->zlib_compression_level + = MAX (1, MIN (9, g_ascii_strtoull (compression_level_str, NULL, 10))); else self->zlib_compression_level = OSTREE_ARCHIVE_DEFAULT_COMPRESSION_LEVEL; } { - /* Try to parse both min-free-space-* config options first. If both are absent, fallback on 3% free space. - * If both are present and are non-zero, use min-free-space-size unconditionally and display a warning. + /* Try to parse both min-free-space-* config options first. If both are absent, fallback on 3% + * free space. If both are present and are non-zero, use min-free-space-size unconditionally + * and display a warning. */ if (g_key_file_has_key (self->config, "core", "min-free-space-size", NULL)) { g_autofree char *min_free_space_size_str = NULL; - if (!ot_keyfile_get_value_with_default (self->config, "core", "min-free-space-size", - NULL, &min_free_space_size_str, error)) + if (!ot_keyfile_get_value_with_default (self->config, "core", "min-free-space-size", NULL, + &min_free_space_size_str, error)) return FALSE; /* Validate the string and convert the size to MBs */ if (!min_free_space_size_validate_and_convert (self, min_free_space_size_str, error)) - return glnx_prefix_error (error, "Invalid min-free-space-size '%s'", min_free_space_size_str); + return glnx_prefix_error (error, "Invalid min-free-space-size '%s'", + min_free_space_size_str); } if (g_key_file_has_key (self->config, "core", "min-free-space-percent", NULL)) @@ -3346,11 +3132,13 @@ reload_core_config (OstreeRepo *self, self->min_free_space_percent = g_ascii_strtoull (min_free_space_percent_str, NULL, 10); if (self->min_free_space_percent > 99) - return glnx_throw (error, "Invalid min-free-space-percent '%s'", min_free_space_percent_str); + return glnx_throw (error, "Invalid min-free-space-percent '%s'", + min_free_space_percent_str); } else if (!g_key_file_has_key (self->config, "core", "min-free-space-size", NULL)) { - /* Default fallback of 3% free space. If changing this, be sure to change the man page too */ + /* Default fallback of 3% free space. If changing this, be sure to change the man page too + */ self->min_free_space_percent = 3; self->min_free_space_mb = 0; } @@ -3358,7 +3146,8 @@ reload_core_config (OstreeRepo *self, if (self->min_free_space_percent != 0 && self->min_free_space_mb != 0) { self->min_free_space_percent = 0; - g_debug ("Both min-free-space-percent and -size are mentioned in config. Enforcing min-free-space-size check only."); + g_debug ("Both min-free-space-percent and -size are mentioned in config. Enforcing " + "min-free-space-size check only."); } } @@ -3367,18 +3156,18 @@ reload_core_config (OstreeRepo *self, { g_clear_pointer (&self->collection_id, g_free); - if (!ot_keyfile_get_value_with_default (self->config, "core", "collection-id", - NULL, &self->collection_id, NULL)) + if (!ot_keyfile_get_value_with_default (self->config, "core", "collection-id", NULL, + &self->collection_id, NULL)) return FALSE; } - if (!ot_keyfile_get_value_with_default (self->config, "core", "parent", - NULL, &parent_repo_path, error)) + if (!ot_keyfile_get_value_with_default (self->config, "core", "parent", NULL, &parent_repo_path, + error)) return FALSE; if (parent_repo_path && parent_repo_path[0]) { - g_autoptr(GFile) parent_repo_f = g_file_new_for_path (parent_repo_path); + g_autoptr (GFile) parent_repo_f = g_file_new_for_path (parent_repo_path); g_clear_object (&self->parent_repo); self->parent_repo = ostree_repo_new (parent_repo_f); @@ -3395,14 +3184,16 @@ reload_core_config (OstreeRepo *self, * system repos. This is to preserve legacy behavior for non-system * repos that specify a remotes config dir (flatpak). */ - { gboolean is_system = ostree_repo_is_system (self); + { + gboolean is_system = ostree_repo_is_system (self); if (!ot_keyfile_get_boolean_with_default (self->config, "core", "add-remotes-config-dir", is_system, &self->add_remotes_config_dir, error)) return FALSE; } - { g_autofree char *payload_threshold = NULL; + { + g_autofree char *payload_threshold = NULL; if (!ot_keyfile_get_value_with_default (self->config, "core", "payload-link-threshold", "-1", &payload_threshold, error)) @@ -3411,8 +3202,9 @@ reload_core_config (OstreeRepo *self, self->payload_link_threshold = g_ascii_strtoull (payload_threshold, NULL, 10); } - { g_auto(GStrv) configured_finders = NULL; - g_autoptr(GError) local_error = NULL; + { + g_auto (GStrv) configured_finders = NULL; + g_autoptr (GError) local_error = NULL; configured_finders = g_key_file_get_string_list (self->config, "core", "default-repo-finders", NULL, &local_error); @@ -3431,9 +3223,8 @@ reload_core_config (OstreeRepo *self, { const char *repo_finder = *iter; - if (strcmp (repo_finder, "config") != 0 && - strcmp (repo_finder, "lan") != 0 && - strcmp (repo_finder, "mount") != 0) + if (strcmp (repo_finder, "config") != 0 && strcmp (repo_finder, "lan") != 0 + && strcmp (repo_finder, "mount") != 0) return glnx_throw (error, "Invalid configured repo-finder '%s'", repo_finder); } @@ -3449,9 +3240,7 @@ reload_core_config (OstreeRepo *self, } static gboolean -reload_remote_config (OstreeRepo *self, - GCancellable *cancellable, - GError **error) +reload_remote_config (OstreeRepo *self, GCancellable *cancellable, GError **error) { g_mutex_lock (&self->remotes_lock); @@ -3461,13 +3250,12 @@ reload_remote_config (OstreeRepo *self, if (!add_remotes_from_keyfile (self, self->config, NULL, error)) return FALSE; - g_autoptr(GFile) remotes_d = get_remotes_d_dir (self, NULL); + g_autoptr (GFile) remotes_d = get_remotes_d_dir (self, NULL); if (remotes_d == NULL) return TRUE; - g_autoptr(GFileEnumerator) direnum = NULL; - if (!enumerate_directory_allow_noent (remotes_d, OSTREE_GIO_FAST_QUERYINFO, 0, - &direnum, + g_autoptr (GFileEnumerator) direnum = NULL; + if (!enumerate_directory_allow_noent (remotes_d, OSTREE_GIO_FAST_QUERYINFO, 0, &direnum, cancellable, error)) return FALSE; if (direnum) @@ -3479,8 +3267,7 @@ reload_remote_config (OstreeRepo *self, const char *name; guint32 type; - if (!g_file_enumerator_iterate (direnum, &file_info, &path, - NULL, error)) + if (!g_file_enumerator_iterate (direnum, &file_info, &path, NULL, error)) return FALSE; if (file_info == NULL) break; @@ -3488,8 +3275,7 @@ reload_remote_config (OstreeRepo *self, name = g_file_info_get_attribute_byte_string (file_info, "standard::name"); type = g_file_info_get_attribute_uint32 (file_info, "standard::type"); - if (type == G_FILE_TYPE_REGULAR && - g_str_has_suffix (name, ".conf")) + if (type == G_FILE_TYPE_REGULAR && g_str_has_suffix (name, ".conf")) { if (!append_one_remote_config (self, path, cancellable, error)) return FALSE; @@ -3501,15 +3287,12 @@ reload_remote_config (OstreeRepo *self, } static gboolean -reload_sysroot_config (OstreeRepo *self, - GCancellable *cancellable, - GError **error) +reload_sysroot_config (OstreeRepo *self, GCancellable *cancellable, GError **error) { g_autofree char *bootloader = NULL; - if (!ot_keyfile_get_value_with_default_group_optional (self->config, "sysroot", - "bootloader", "auto", - &bootloader, error)) + if (!ot_keyfile_get_value_with_default_group_optional (self->config, "sysroot", "bootloader", + "auto", &bootloader, error)) return FALSE; /* TODO: possibly later add support for specifying a generic bootloader @@ -3522,19 +3305,19 @@ reload_sysroot_config (OstreeRepo *self, { if (g_str_equal (bootloader, CFG_SYSROOT_BOOTLOADER_OPTS_STR[i])) { - self->bootloader = (OstreeCfgSysrootBootloaderOpt) i; + self->bootloader = (OstreeCfgSysrootBootloaderOpt)i; valid_bootloader = TRUE; } } if (!valid_bootloader) - { - return glnx_throw (error, "Invalid bootloader configuration: '%s'", bootloader); - } + { + return glnx_throw (error, "Invalid bootloader configuration: '%s'", bootloader); + } /* Parse bls-append-except-default string list. */ - g_auto(GStrv) read_values = NULL; - if (!ot_keyfile_get_string_list_with_default (self->config, "sysroot", "bls-append-except-default", - ';', NULL, &read_values, error)) - return glnx_throw(error, "Unable to parse bls-append-except-default"); + g_auto (GStrv) read_values = NULL; + if (!ot_keyfile_get_string_list_with_default ( + self->config, "sysroot", "bls-append-except-default", ';', NULL, &read_values, error)) + return glnx_throw (error, "Unable to parse bls-append-except-default"); /* get all key value pairs in bls-append-except-default */ g_hash_table_remove_all (self->bls_append_values); @@ -3544,7 +3327,9 @@ reload_sysroot_config (OstreeRepo *self, const char *sep = strchr (key_value, '='); if (sep == NULL) { - glnx_throw (error, "bls-append-except-default key must be of the form \"key1=value1;key2=value2...\""); + glnx_throw ( + error, + "bls-append-except-default key must be of the form \"key1=value1;key2=value2...\""); return FALSE; } char *key = g_strndup (key_value, sep - key_value); @@ -3552,8 +3337,7 @@ reload_sysroot_config (OstreeRepo *self, g_hash_table_replace (self->bls_append_values, key, value); } - if (!ot_keyfile_get_boolean_with_default (self->config, "sysroot", - "bootprefix", FALSE, + if (!ot_keyfile_get_boolean_with_default (self->config, "sysroot", "bootprefix", FALSE, &self->enable_bootprefix, error)) return FALSE; @@ -3572,9 +3356,7 @@ reload_sysroot_config (OstreeRepo *self, * Since: 2017.2 */ gboolean -ostree_repo_reload_config (OstreeRepo *self, - GCancellable *cancellable, - GError **error) +ostree_repo_reload_config (OstreeRepo *self, GCancellable *cancellable, GError **error) { if (!reload_core_config (self, cancellable, error)) return FALSE; @@ -3586,9 +3368,7 @@ ostree_repo_reload_config (OstreeRepo *self, } gboolean -ostree_repo_open (OstreeRepo *self, - GCancellable *cancellable, - GError **error) +ostree_repo_open (OstreeRepo *self, GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("opening repo", error); @@ -3603,17 +3383,15 @@ ostree_repo_open (OstreeRepo *self, * where if the ${BOOT_ID} doesn't match, we know file contents * possibly haven't been sync'd to disk and need to be discarded. */ - { const char *env_bootid = getenv ("OSTREE_BOOTID"); + { + const char *env_bootid = getenv ("OSTREE_BOOTID"); g_autofree char *boot_id = NULL; if (env_bootid != NULL) boot_id = g_strdup (env_bootid); else { - if (!g_file_get_contents ("/proc/sys/kernel/random/boot_id", - &boot_id, - NULL, - error)) + if (!g_file_get_contents ("/proc/sys/kernel/random/boot_id", &boot_id, NULL, error)) return FALSE; g_strdelimit (boot_id, "\n", '\0'); } @@ -3634,8 +3412,7 @@ ostree_repo_open (OstreeRepo *self, self->device = stbuf.st_dev; self->inode = stbuf.st_ino; - if (!glnx_opendirat (self->repo_dir_fd, "objects", TRUE, - &self->objects_dir_fd, error)) + if (!glnx_opendirat (self->repo_dir_fd, "objects", TRUE, &self->objects_dir_fd, error)) return FALSE; self->writable = faccessat (self->objects_dir_fd, ".", W_OK, 0) == 0; @@ -3669,7 +3446,8 @@ ostree_repo_open (OstreeRepo *self, if (self->writable && getenv ("OSTREE_SKIP_CACHE") == NULL) { - if (!glnx_shutil_mkdir_p_at (self->tmp_dir_fd, _OSTREE_CACHE_DIR, DEFAULT_DIRECTORY_MODE, cancellable, error)) + if (!glnx_shutil_mkdir_p_at (self->tmp_dir_fd, _OSTREE_CACHE_DIR, DEFAULT_DIRECTORY_MODE, + cancellable, error)) return FALSE; if (!glnx_opendirat (self->tmp_dir_fd, _OSTREE_CACHE_DIR, TRUE, &self->cache_dir_fd, error)) @@ -3687,8 +3465,7 @@ ostree_repo_open (OstreeRepo *self, if (fstatat (AT_FDCWD, "/ostree/repo", &system_stbuf, 0) == 0) { /* Are we the same as /ostree/repo? */ - if (self->device == system_stbuf.st_dev && - self->inode == system_stbuf.st_ino) + if (self->device == system_stbuf.st_dev && self->inode == system_stbuf.st_ino) self->sysroot_kind = OSTREE_REPO_SYSROOT_KIND_IS_SYSROOT_OSTREE; else self->sysroot_kind = OSTREE_REPO_SYSROOT_KIND_NO; @@ -3715,8 +3492,7 @@ ostree_repo_open (OstreeRepo *self, * ensuring data consistency. */ void -ostree_repo_set_disable_fsync (OstreeRepo *self, - gboolean disable_fsync) +ostree_repo_set_disable_fsync (OstreeRepo *self, gboolean disable_fsync) { self->disable_fsync = disable_fsync; } @@ -3737,11 +3513,8 @@ ostree_repo_set_disable_fsync (OstreeRepo *self, * Since: 2016.5 */ gboolean -ostree_repo_set_cache_dir (OstreeRepo *self, - int dfd, - const char *path, - GCancellable *cancellable, - GError **error) +ostree_repo_set_cache_dir (OstreeRepo *self, int dfd, const char *path, GCancellable *cancellable, + GError **error) { glnx_autofd int fd = -1; if (!glnx_opendirat (dfd, path, TRUE, &fd, error)) @@ -3762,7 +3535,7 @@ ostree_repo_set_cache_dir (OstreeRepo *self, * Returns: Whether or not fsync() is enabled for this repo. */ gboolean -ostree_repo_get_disable_fsync (OstreeRepo *self) +ostree_repo_get_disable_fsync (OstreeRepo *self) { return self->disable_fsync; } @@ -3771,16 +3544,12 @@ ostree_repo_get_disable_fsync (OstreeRepo *self) * policy. */ gboolean -_ostree_repo_file_replace_contents (OstreeRepo *self, - int dfd, - const char *path, - const guint8 *buf, - gsize len, - GCancellable *cancellable, - GError **error) +_ostree_repo_file_replace_contents (OstreeRepo *self, int dfd, const char *path, const guint8 *buf, + gsize len, GCancellable *cancellable, GError **error) { return glnx_file_replace_contents_at (dfd, path, buf, len, - self->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : GLNX_FILE_REPLACE_DATASYNC_NEW, + self->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC + : GLNX_FILE_REPLACE_DATASYNC_NEW, cancellable, error); } @@ -3795,7 +3564,7 @@ _ostree_repo_file_replace_contents (OstreeRepo *self, * Returns: (transfer none): Path to repo */ GFile * -ostree_repo_get_path (OstreeRepo *self) +ostree_repo_get_path (OstreeRepo *self) { /* Did we have an abspath? Return it */ if (self->repodir) @@ -3819,7 +3588,7 @@ ostree_repo_get_path (OstreeRepo *self) * Since: 2016.4 */ int -ostree_repo_get_dfd (OstreeRepo *self) +ostree_repo_get_dfd (OstreeRepo *self) { g_return_val_if_fail (self->repo_dir_fd != -1, -1); return self->repo_dir_fd; @@ -3868,8 +3637,7 @@ ostree_repo_hash (OstreeRepo *self) * Since: 2017.12 */ gboolean -ostree_repo_equal (OstreeRepo *a, - OstreeRepo *b) +ostree_repo_equal (OstreeRepo *a, OstreeRepo *b) { g_return_val_if_fail (OSTREE_IS_REPO (a), FALSE); g_return_val_if_fail (OSTREE_IS_REPO (b), FALSE); @@ -3881,7 +3649,7 @@ ostree_repo_equal (OstreeRepo *a, } OstreeRepoMode -ostree_repo_get_mode (OstreeRepo *self) +ostree_repo_get_mode (OstreeRepo *self) { g_assert (self != NULL); g_assert (self->inited); @@ -3904,7 +3672,7 @@ ostree_repo_get_mode (OstreeRepo *self) * Since: 2018.9 */ gboolean -ostree_repo_get_min_free_space_bytes (OstreeRepo *self, guint64 *out_reserved_bytes, GError **error) +ostree_repo_get_min_free_space_bytes (OstreeRepo *self, guint64 *out_reserved_bytes, GError **error) { g_return_val_if_fail (OSTREE_IS_REPO (self), FALSE); g_return_val_if_fail (out_reserved_bytes != NULL, FALSE); @@ -3926,24 +3694,21 @@ ostree_repo_get_min_free_space_bytes (OstreeRepo *self, guint64 *out_reserved_b * Returns: (transfer none) (nullable): Parent repository, or %NULL if none */ OstreeRepo * -ostree_repo_get_parent (OstreeRepo *self) +ostree_repo_get_parent (OstreeRepo *self) { return self->parent_repo; } static gboolean -list_loose_objects_at (OstreeRepo *self, - GVariant *dummy_value, - GHashTable *inout_objects, - int dfd, - const char *prefix, - const char *commit_starting_with, - GCancellable *cancellable, - GError **error) +list_loose_objects_at (OstreeRepo *self, GVariant *dummy_value, GHashTable *inout_objects, int dfd, + const char *prefix, const char *commit_starting_with, + GCancellable *cancellable, GError **error) { GVariant *key; - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; gboolean exists; if (!ot_dfd_iter_init_allow_noent (dfd, prefix, &dfd_iter, &exists, error)) return FALSE; @@ -3961,8 +3726,7 @@ list_loose_objects_at (OstreeRepo *self, break; const char *name = dent->d_name; - if (strcmp (name, ".") == 0 || - strcmp (name, "..") == 0) + if (strcmp (name, ".") == 0 || strcmp (name, "..") == 0) continue; const char *dot = strrchr (name, '.'); @@ -3970,10 +3734,8 @@ list_loose_objects_at (OstreeRepo *self, continue; OstreeObjectType objtype; - if ((self->mode == OSTREE_REPO_MODE_ARCHIVE - && strcmp (dot, ".filez") == 0) || - ((_ostree_repo_mode_is_bare (self->mode)) - && strcmp (dot, ".file") == 0)) + if ((self->mode == OSTREE_REPO_MODE_ARCHIVE && strcmp (dot, ".filez") == 0) + || ((_ostree_repo_mode_is_bare (self->mode)) && strcmp (dot, ".file") == 0)) objtype = OSTREE_OBJECT_TYPE_FILE; else if (strcmp (dot, ".dirtree") == 0) objtype = OSTREE_OBJECT_TYPE_DIR_TREE; @@ -3989,11 +3751,11 @@ list_loose_objects_at (OstreeRepo *self, if ((dot - name) != 62) continue; - char buf[OSTREE_SHA256_STRING_LEN+1]; + char buf[OSTREE_SHA256_STRING_LEN + 1]; memcpy (buf, prefix, 2); memcpy (buf + 2, name, 62); - buf[sizeof(buf)-1] = '\0'; + buf[sizeof (buf) - 1] = '\0'; /* if we passed in a "starting with" argument, then we only want to return .commit objects with a checksum @@ -4002,7 +3764,7 @@ list_loose_objects_at (OstreeRepo *self, { /* object is not a commit, do not add to array */ if (objtype != OSTREE_OBJECT_TYPE_COMMIT) - continue; + continue; /* commit checksum does not match "starting with", do not add to array */ if (!g_str_has_prefix (buf, commit_starting_with)) @@ -4013,8 +3775,7 @@ list_loose_objects_at (OstreeRepo *self, /* transfer ownership */ if (dummy_value) - g_hash_table_replace (inout_objects, g_variant_ref_sink (key), - g_variant_ref (dummy_value)); + g_hash_table_replace (inout_objects, g_variant_ref_sink (key), g_variant_ref (dummy_value)); else g_hash_table_add (inout_objects, g_variant_ref_sink (key)); } @@ -4023,12 +3784,8 @@ list_loose_objects_at (OstreeRepo *self, } static gboolean -list_loose_objects (OstreeRepo *self, - GVariant *dummy_value, - GHashTable *inout_objects, - const char *commit_starting_with, - GCancellable *cancellable, - GError **error) +list_loose_objects (OstreeRepo *self, GVariant *dummy_value, GHashTable *inout_objects, + const char *commit_starting_with, GCancellable *cancellable, GError **error) { static const gchar hexchars[] = "0123456789abcdef"; @@ -4038,10 +3795,8 @@ list_loose_objects (OstreeRepo *self, buf[0] = hexchars[c >> 4]; buf[1] = hexchars[c & 0xF]; buf[2] = '\0'; - if (!list_loose_objects_at (self, dummy_value, - inout_objects, self->objects_dir_fd, buf, - commit_starting_with, - cancellable, error)) + if (!list_loose_objects_at (self, dummy_value, inout_objects, self->objects_dir_fd, buf, + commit_starting_with, cancellable, error)) return FALSE; } @@ -4049,21 +3804,15 @@ list_loose_objects (OstreeRepo *self, } static gboolean -load_metadata_internal (OstreeRepo *self, - OstreeObjectType objtype, - const char *sha256, - gboolean error_if_not_found, - GVariant **out_variant, - GInputStream **out_stream, - guint64 *out_size, - OstreeRepoCommitState *out_state, - GCancellable *cancellable, - GError **error) +load_metadata_internal (OstreeRepo *self, OstreeObjectType objtype, const char *sha256, + gboolean error_if_not_found, GVariant **out_variant, + GInputStream **out_stream, guint64 *out_size, + OstreeRepoCommitState *out_state, GCancellable *cancellable, GError **error) { char loose_path_buf[_OSTREE_LOOSE_PATH_MAX]; glnx_autofd int fd = -1; - g_autoptr(GInputStream) ret_stream = NULL; - g_autoptr(GVariant) ret_variant = NULL; + g_autoptr (GInputStream) ret_stream = NULL; + g_autoptr (GVariant) ret_variant = NULL; g_return_val_if_fail (OSTREE_OBJECT_TYPE_IS_META (objtype), FALSE); g_return_val_if_fail (objtype == OSTREE_OBJECT_TYPE_COMMIT || out_state == NULL, FALSE); @@ -4075,8 +3824,8 @@ load_metadata_internal (OstreeRepo *self, /* Special caching for dirmeta objects, since they're commonly referenced many * times. */ - const gboolean is_dirmeta_cachable = - (objtype == OSTREE_OBJECT_TYPE_DIR_META && out_variant && !out_stream); + const gboolean is_dirmeta_cachable + = (objtype == OSTREE_OBJECT_TYPE_DIR_META && out_variant && !out_stream); if (is_dirmeta_cachable) { GMutex *lock = &self->cache_lock; @@ -4094,14 +3843,12 @@ load_metadata_internal (OstreeRepo *self, _ostree_loose_path (loose_path_buf, sha256, objtype, self->mode); - if (!ot_openat_ignore_enoent (self->objects_dir_fd, loose_path_buf, &fd, - error)) + if (!ot_openat_ignore_enoent (self->objects_dir_fd, loose_path_buf, &fd, error)) return FALSE; if (fd < 0 && self->commit_stagedir.initialized) { - if (!ot_openat_ignore_enoent (self->commit_stagedir.fd, loose_path_buf, &fd, - error)) + if (!ot_openat_ignore_enoent (self->commit_stagedir.fd, loose_path_buf, &fd, error)) return FALSE; } @@ -4122,7 +3869,8 @@ load_metadata_internal (OstreeRepo *self, GMutex *lock = &self->cache_lock; g_mutex_lock (lock); if (self->dirmeta_cache) - g_hash_table_replace (self->dirmeta_cache, g_strdup (sha256), g_variant_ref (ret_variant)); + g_hash_table_replace (self->dirmeta_cache, g_strdup (sha256), + g_variant_ref (ret_variant)); g_mutex_unlock (lock); } } @@ -4143,17 +3891,18 @@ load_metadata_internal (OstreeRepo *self, *out_state = 0; glnx_autofd int commitpartial_fd = -1; - if (!ot_openat_ignore_enoent (self->repo_dir_fd, commitpartial_path, &commitpartial_fd, error)) + if (!ot_openat_ignore_enoent (self->repo_dir_fd, commitpartial_path, &commitpartial_fd, + error)) return FALSE; if (commitpartial_fd != -1) { *out_state |= OSTREE_REPO_COMMIT_STATE_PARTIAL; - char reason; - if (read (commitpartial_fd, &reason, 1) == 1) - { - if (reason == 'f') - *out_state |= OSTREE_REPO_COMMIT_STATE_FSCK_PARTIAL; - } + char reason; + if (read (commitpartial_fd, &reason, 1) == 1) + { + if (reason == 'f') + *out_state |= OSTREE_REPO_COMMIT_STATE_FSCK_PARTIAL; + } } } } @@ -4161,14 +3910,13 @@ load_metadata_internal (OstreeRepo *self, { /* Directly recurse to simplify out parameters */ return load_metadata_internal (self->parent_repo, objtype, sha256, error_if_not_found, - out_variant, out_stream, out_size, out_state, - cancellable, error); + out_variant, out_stream, out_size, out_state, cancellable, + error); } else if (error_if_not_found) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "No such metadata object %s.%s", - sha256, ostree_object_type_to_string (objtype)); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "No such metadata object %s.%s", sha256, + ostree_object_type_to_string (objtype)); return FALSE; } @@ -4177,15 +3925,13 @@ load_metadata_internal (OstreeRepo *self, return TRUE; } -static GVariant * -filemeta_to_stat (struct stat *stbuf, - GVariant *metadata) +static GVariant * +filemeta_to_stat (struct stat *stbuf, GVariant *metadata) { guint32 uid, gid, mode; GVariant *xattrs; - g_variant_get (metadata, "(uuu@a(ayay))", - &uid, &gid, &mode, &xattrs); + g_variant_get (metadata, "(uuu@a(ayay))", &uid, &gid, &mode, &xattrs); stbuf->st_uid = GUINT32_FROM_BE (uid); stbuf->st_gid = GUINT32_FROM_BE (gid); stbuf->st_mode = GUINT32_FROM_BE (mode); @@ -4194,27 +3940,21 @@ filemeta_to_stat (struct stat *stbuf, } static gboolean -repo_load_file_archive (OstreeRepo *self, - const char *checksum, - GInputStream **out_input, - GFileInfo **out_file_info, - GVariant **out_xattrs, - GCancellable *cancellable, - GError **error) +repo_load_file_archive (OstreeRepo *self, const char *checksum, GInputStream **out_input, + GFileInfo **out_file_info, GVariant **out_xattrs, GCancellable *cancellable, + GError **error) { struct stat stbuf; char loose_path_buf[_OSTREE_LOOSE_PATH_MAX]; _ostree_loose_path (loose_path_buf, checksum, OSTREE_OBJECT_TYPE_FILE, self->mode); glnx_autofd int fd = -1; - if (!ot_openat_ignore_enoent (self->objects_dir_fd, loose_path_buf, &fd, - error)) + if (!ot_openat_ignore_enoent (self->objects_dir_fd, loose_path_buf, &fd, error)) return FALSE; if (fd < 0 && self->commit_stagedir.initialized) { - if (!ot_openat_ignore_enoent (self->commit_stagedir.fd, loose_path_buf, &fd, - error)) + if (!ot_openat_ignore_enoent (self->commit_stagedir.fd, loose_path_buf, &fd, error)) return FALSE; } @@ -4223,31 +3963,27 @@ repo_load_file_archive (OstreeRepo *self, if (!glnx_fstat (fd, &stbuf, error)) return FALSE; - g_autoptr(GInputStream) tmp_stream = g_unix_input_stream_new (g_steal_fd (&fd), TRUE); + g_autoptr (GInputStream) tmp_stream = g_unix_input_stream_new (g_steal_fd (&fd), TRUE); /* Note return here */ - return ostree_content_stream_parse (TRUE, tmp_stream, stbuf.st_size, TRUE, - out_input, out_file_info, out_xattrs, - cancellable, error); + return ostree_content_stream_parse (TRUE, tmp_stream, stbuf.st_size, TRUE, out_input, + out_file_info, out_xattrs, cancellable, error); } else if (self->parent_repo) { - return ostree_repo_load_file (self->parent_repo, checksum, - out_input, out_file_info, out_xattrs, - cancellable, error); + return ostree_repo_load_file (self->parent_repo, checksum, out_input, out_file_info, + out_xattrs, cancellable, error); } else { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "Couldn't find file object '%s'", checksum); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Couldn't find file object '%s'", + checksum); return FALSE; } } static GVariant * -_ostree_repo_read_xattrs_file_link (OstreeRepo *self, - const char *checksum, - GCancellable *cancellable, - GError **error) +_ostree_repo_read_xattrs_file_link (OstreeRepo *self, const char *checksum, + GCancellable *cancellable, GError **error) { g_assert (self != NULL); g_assert (checksum != NULL); @@ -4255,14 +3991,13 @@ _ostree_repo_read_xattrs_file_link (OstreeRepo *self, char xattr_path[_OSTREE_LOOSE_PATH_MAX]; _ostree_loose_path (xattr_path, checksum, OSTREE_OBJECT_TYPE_FILE_XATTRS_LINK, self->mode); - g_autoptr(GVariant) xattrs = NULL; + g_autoptr (GVariant) xattrs = NULL; glnx_autofd int fd = -1; if (!glnx_openat_rdonly (self->objects_dir_fd, xattr_path, FALSE, &fd, error)) return FALSE; g_assert (fd >= 0); - if (!ot_variant_read_fd (fd, 0, G_VARIANT_TYPE ("a(ayay)"), TRUE, - &xattrs, error)) + if (!ot_variant_read_fd (fd, 0, G_VARIANT_TYPE ("a(ayay)"), TRUE, &xattrs, error)) return glnx_prefix_error_null (error, "Deserializing xattrs content"); g_assert (xattrs != NULL); @@ -4270,20 +4005,15 @@ _ostree_repo_read_xattrs_file_link (OstreeRepo *self, } gboolean -_ostree_repo_load_file_bare (OstreeRepo *self, - const char *checksum, - int *out_fd, - struct stat *out_stbuf, - char **out_symlink, - GVariant **out_xattrs, - GCancellable *cancellable, - GError **error) +_ostree_repo_load_file_bare (OstreeRepo *self, const char *checksum, int *out_fd, + struct stat *out_stbuf, char **out_symlink, GVariant **out_xattrs, + GCancellable *cancellable, GError **error) { /* The bottom case recursing on the parent repo */ if (self == NULL) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "Couldn't find file object '%s'", checksum); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Couldn't find file object '%s'", + checksum); return FALSE; } @@ -4293,14 +4023,15 @@ _ostree_repo_load_file_bare (OstreeRepo *self, struct stat stbuf; glnx_autofd int fd = -1; g_autofree char *ret_symlink = NULL; - g_autoptr(GVariant) ret_xattrs = NULL; + g_autoptr (GVariant) ret_xattrs = NULL; char loose_path_buf[_OSTREE_LOOSE_PATH_MAX]; _ostree_loose_path (loose_path_buf, checksum, OSTREE_OBJECT_TYPE_FILE, self->mode); /* Do a fstatat() and find the object directory that contains this object */ int objdir_fd = self->objects_dir_fd; int res; - if ((res = TEMP_FAILURE_RETRY (fstatat (objdir_fd, loose_path_buf, &stbuf, AT_SYMLINK_NOFOLLOW))) < 0 + if ((res = TEMP_FAILURE_RETRY (fstatat (objdir_fd, loose_path_buf, &stbuf, AT_SYMLINK_NOFOLLOW))) + < 0 && errno == ENOENT && self->commit_stagedir.initialized) { objdir_fd = self->commit_stagedir.fd; @@ -4311,14 +4042,12 @@ _ostree_repo_load_file_bare (OstreeRepo *self, else if (res < 0) { g_assert (errno == ENOENT); - return _ostree_repo_load_file_bare (self->parent_repo, checksum, out_fd, - out_stbuf, out_symlink, out_xattrs, - cancellable, error); + return _ostree_repo_load_file_bare (self->parent_repo, checksum, out_fd, out_stbuf, + out_symlink, out_xattrs, cancellable, error); } - const gboolean need_open = (out_fd || - (out_xattrs && self->mode == OSTREE_REPO_MODE_BARE) || - self->mode == OSTREE_REPO_MODE_BARE_USER); + const gboolean need_open = (out_fd || (out_xattrs && self->mode == OSTREE_REPO_MODE_BARE) + || self->mode == OSTREE_REPO_MODE_BARE_USER); /* If it's a regular file and we're requested to return the fd, do it now. As * a special case in bare-user, we always do an open, since the stat() metadata * lives there. @@ -4334,31 +4063,29 @@ _ostree_repo_load_file_bare (OstreeRepo *self, return glnx_throw (error, "Not a regular file or symlink"); /* In the non-bare-user case, gather symlink info if requested */ - if (self->mode != OSTREE_REPO_MODE_BARE_USER - && S_ISLNK (stbuf.st_mode) && out_symlink) + if (self->mode != OSTREE_REPO_MODE_BARE_USER && S_ISLNK (stbuf.st_mode) && out_symlink) { - ret_symlink = glnx_readlinkat_malloc (objdir_fd, loose_path_buf, - cancellable, error); + ret_symlink = glnx_readlinkat_malloc (objdir_fd, loose_path_buf, cancellable, error); if (!ret_symlink) return FALSE; } if (self->mode == OSTREE_REPO_MODE_BARE_USER) { - g_autoptr(GBytes) bytes = glnx_fgetxattr_bytes (fd, "user.ostreemeta", error); + g_autoptr (GBytes) bytes = glnx_fgetxattr_bytes (fd, "user.ostreemeta", error); if (bytes == NULL) return FALSE; - g_autoptr(GVariant) metadata = g_variant_ref_sink (g_variant_new_from_bytes (OSTREE_FILEMETA_GVARIANT_FORMAT, - bytes, FALSE)); + g_autoptr (GVariant) metadata = g_variant_ref_sink ( + g_variant_new_from_bytes (OSTREE_FILEMETA_GVARIANT_FORMAT, bytes, FALSE)); ret_xattrs = filemeta_to_stat (&stbuf, metadata); if (S_ISLNK (stbuf.st_mode)) { if (out_symlink) { - char targetbuf[PATH_MAX+1]; + char targetbuf[PATH_MAX + 1]; gsize target_size; - g_autoptr(GInputStream) target_input = g_unix_input_stream_new (fd, FALSE); + g_autoptr (GInputStream) target_input = g_unix_input_stream_new (fd, FALSE); if (!g_input_stream_read_all (target_input, targetbuf, sizeof (targetbuf), &target_size, cancellable, error)) return FALSE; @@ -4388,7 +4115,8 @@ _ostree_repo_load_file_bare (OstreeRepo *self, if (S_ISREG (stbuf.st_mode) && out_xattrs) { if (self->disable_xattrs) - ret_xattrs = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("(ayay)"), NULL, 0)); + ret_xattrs + = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("(ayay)"), NULL, 0)); else { ret_xattrs = ostree_fs_get_all_xattrs (fd, cancellable, error); @@ -4399,9 +4127,9 @@ _ostree_repo_load_file_bare (OstreeRepo *self, else if (S_ISLNK (stbuf.st_mode) && out_xattrs) { if (self->disable_xattrs) - ret_xattrs = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("(ayay)"), NULL, 0)); - else if (!glnx_dfd_name_get_all_xattrs (objdir_fd, loose_path_buf, - &ret_xattrs, + ret_xattrs + = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("(ayay)"), NULL, 0)); + else if (!glnx_dfd_name_get_all_xattrs (objdir_fd, loose_path_buf, &ret_xattrs, cancellable, error)) return FALSE; } @@ -4410,7 +4138,7 @@ _ostree_repo_load_file_bare (OstreeRepo *self, { if (out_xattrs) { - ret_xattrs = _ostree_repo_read_xattrs_file_link(self, checksum, cancellable, error); + ret_xattrs = _ostree_repo_read_xattrs_file_link (self, checksum, cancellable, error); if (ret_xattrs == NULL) return FALSE; } @@ -4443,13 +4171,9 @@ _ostree_repo_load_file_bare (OstreeRepo *self, * content (for regular files), the metadata, and extended attributes. */ gboolean -ostree_repo_load_file (OstreeRepo *self, - const char *checksum, - GInputStream **out_input, - GFileInfo **out_file_info, - GVariant **out_xattrs, - GCancellable *cancellable, - GError **error) +ostree_repo_load_file (OstreeRepo *self, const char *checksum, GInputStream **out_input, + GFileInfo **out_file_info, GVariant **out_xattrs, GCancellable *cancellable, + GError **error) { if (self->mode == OSTREE_REPO_MODE_ARCHIVE) return repo_load_file_archive (self, checksum, out_input, out_file_info, out_xattrs, @@ -4459,13 +4183,11 @@ ostree_repo_load_file (OstreeRepo *self, glnx_autofd int fd = -1; struct stat stbuf; g_autofree char *symlink_target = NULL; - g_autoptr(GVariant) ret_xattrs = NULL; - if (!_ostree_repo_load_file_bare (self, checksum, - out_input ? &fd : NULL, + g_autoptr (GVariant) ret_xattrs = NULL; + if (!_ostree_repo_load_file_bare (self, checksum, out_input ? &fd : NULL, out_file_info ? &stbuf : NULL, out_file_info ? &symlink_target : NULL, - out_xattrs ? &ret_xattrs : NULL, - cancellable, error)) + out_xattrs ? &ret_xattrs : NULL, cancellable, error)) return FALSE; /* Convert fd → GInputStream and struct stat → GFileInfo */ @@ -4504,37 +4226,30 @@ ostree_repo_load_file (OstreeRepo *self, * repositories. */ gboolean -ostree_repo_load_object_stream (OstreeRepo *self, - OstreeObjectType objtype, - const char *checksum, - GInputStream **out_input, - guint64 *out_size, - GCancellable *cancellable, - GError **error) +ostree_repo_load_object_stream (OstreeRepo *self, OstreeObjectType objtype, const char *checksum, + GInputStream **out_input, guint64 *out_size, + GCancellable *cancellable, GError **error) { guint64 size; - g_autoptr(GInputStream) ret_input = NULL; + g_autoptr (GInputStream) ret_input = NULL; if (OSTREE_OBJECT_TYPE_IS_META (objtype)) { - if (!load_metadata_internal (self, objtype, checksum, TRUE, NULL, - &ret_input, &size, NULL, + if (!load_metadata_internal (self, objtype, checksum, TRUE, NULL, &ret_input, &size, NULL, cancellable, error)) return FALSE; } else { - g_autoptr(GInputStream) input = NULL; - g_autoptr(GFileInfo) finfo = NULL; - g_autoptr(GVariant) xattrs = NULL; + g_autoptr (GInputStream) input = NULL; + g_autoptr (GFileInfo) finfo = NULL; + g_autoptr (GVariant) xattrs = NULL; - if (!ostree_repo_load_file (self, checksum, &input, &finfo, &xattrs, - cancellable, error)) + if (!ostree_repo_load_file (self, checksum, &input, &finfo, &xattrs, cancellable, error)) return FALSE; - if (!ostree_raw_file_to_content_stream (input, finfo, xattrs, - &ret_input, &size, - cancellable, error)) + if (!ostree_raw_file_to_content_stream (input, finfo, xattrs, &ret_input, &size, cancellable, + error)) return FALSE; } @@ -4551,12 +4266,8 @@ ostree_repo_load_object_stream (OstreeRepo *self, * set to TRUE. @loose_path_buf is always set to the loose path. */ gboolean -_ostree_repo_has_loose_object (OstreeRepo *self, - const char *checksum, - OstreeObjectType objtype, - gboolean *out_is_stored, - GCancellable *cancellable, - GError **error) +_ostree_repo_has_loose_object (OstreeRepo *self, const char *checksum, OstreeObjectType objtype, + gboolean *out_is_stored, GCancellable *cancellable, GError **error) { char loose_path_buf[_OSTREE_LOOSE_PATH_MAX]; _ostree_loose_path (loose_path_buf, checksum, objtype, self->mode); @@ -4605,25 +4316,21 @@ _ostree_repo_has_loose_object (OstreeRepo *self, * Returns: %FALSE if an unexpected error occurred, %TRUE otherwise */ gboolean -ostree_repo_has_object (OstreeRepo *self, - OstreeObjectType objtype, - const char *checksum, - gboolean *out_have_object, - GCancellable *cancellable, - GError **error) +ostree_repo_has_object (OstreeRepo *self, OstreeObjectType objtype, const char *checksum, + gboolean *out_have_object, GCancellable *cancellable, GError **error) { gboolean ret_have_object = FALSE; - if (!_ostree_repo_has_loose_object (self, checksum, objtype, &ret_have_object, - cancellable, error)) + if (!_ostree_repo_has_loose_object (self, checksum, objtype, &ret_have_object, cancellable, + error)) return FALSE; /* In the future, here is where we would also look up in metadata pack files */ if (!ret_have_object && self->parent_repo) { - if (!ostree_repo_has_object (self->parent_repo, objtype, checksum, - &ret_have_object, cancellable, error)) + if (!ostree_repo_has_object (self->parent_repo, objtype, checksum, &ret_have_object, + cancellable, error)) return FALSE; } @@ -4645,11 +4352,8 @@ ostree_repo_has_object (OstreeRepo *self, * is thrown if the object does not exist. */ gboolean -ostree_repo_delete_object (OstreeRepo *self, - OstreeObjectType objtype, - const char *sha256, - GCancellable *cancellable, - GError **error) +ostree_repo_delete_object (OstreeRepo *self, OstreeObjectType objtype, const char *sha256, + GCancellable *cancellable, GError **error) { char loose_path[_OSTREE_LOOSE_PATH_MAX]; _ostree_loose_path (loose_path, sha256, objtype, self->mode); @@ -4665,9 +4369,11 @@ ostree_repo_delete_object (OstreeRepo *self, } if (!glnx_unlinkat (self->objects_dir_fd, loose_path, 0, error)) - return glnx_prefix_error (error, "Deleting object %s.%s", sha256, ostree_object_type_to_string (objtype)); + return glnx_prefix_error (error, "Deleting object %s.%s", sha256, + ostree_object_type_to_string (objtype)); - /* If the repository is configured to use tombstone commits, create one when deleting a commit. */ + /* If the repository is configured to use tombstone commits, create one when deleting a commit. + */ if (objtype == OSTREE_OBJECT_TYPE_COMMIT) { gboolean tombstone_commits = FALSE; @@ -4678,18 +4384,14 @@ ostree_repo_delete_object (OstreeRepo *self, if (tombstone_commits) { - g_auto(GVariantBuilder) builder = OT_VARIANT_BUILDER_INITIALIZER; - g_autoptr(GVariant) variant = NULL; + g_auto (GVariantBuilder) builder = OT_VARIANT_BUILDER_INITIALIZER; + g_autoptr (GVariant) variant = NULL; g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); g_variant_builder_add (&builder, "{sv}", "commit", g_variant_new_bytestring (sha256)); variant = g_variant_ref_sink (g_variant_builder_end (&builder)); - if (!ostree_repo_write_metadata_trusted (self, - OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT, - sha256, - variant, - cancellable, - error)) + if (!ostree_repo_write_metadata_trusted (self, OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT, + sha256, variant, cancellable, error)) return FALSE; } } @@ -4699,17 +4401,13 @@ ostree_repo_delete_object (OstreeRepo *self, /* Thin wrapper for _ostree_verify_metadata_object() */ static gboolean -fsck_metadata_object (OstreeRepo *self, - OstreeObjectType objtype, - const char *sha256, - GCancellable *cancellable, - GError **error) +fsck_metadata_object (OstreeRepo *self, OstreeObjectType objtype, const char *sha256, + GCancellable *cancellable, GError **error) { const char *errmsg = glnx_strjoina ("fsck ", sha256, ".", ostree_object_type_to_string (objtype)); GLNX_AUTO_PREFIX_ERROR (errmsg, error); - g_autoptr(GVariant) metadata = NULL; - if (!load_metadata_internal (self, objtype, sha256, TRUE, - &metadata, NULL, NULL, NULL, + g_autoptr (GVariant) metadata = NULL; + if (!load_metadata_internal (self, objtype, sha256, TRUE, &metadata, NULL, NULL, NULL, cancellable, error)) return FALSE; @@ -4717,19 +4415,16 @@ fsck_metadata_object (OstreeRepo *self, } static gboolean -fsck_content_object (OstreeRepo *self, - const char *sha256, - GCancellable *cancellable, - GError **error) +fsck_content_object (OstreeRepo *self, const char *sha256, GCancellable *cancellable, + GError **error) { const char *errmsg = glnx_strjoina ("fsck content object ", sha256); GLNX_AUTO_PREFIX_ERROR (errmsg, error); - g_autoptr(GInputStream) input = NULL; - g_autoptr(GFileInfo) file_info = NULL; - g_autoptr(GVariant) xattrs = NULL; + g_autoptr (GInputStream) input = NULL; + g_autoptr (GFileInfo) file_info = NULL; + g_autoptr (GVariant) xattrs = NULL; - if (!ostree_repo_load_file (self, sha256, &input, &file_info, &xattrs, - cancellable, error)) + if (!ostree_repo_load_file (self, sha256, &input, &file_info, &xattrs, cancellable, error)) return FALSE; /* TODO more consistency checks here */ @@ -4738,12 +4433,11 @@ fsck_content_object (OstreeRepo *self, return FALSE; g_autofree guchar *computed_csum = NULL; - if (!ostree_checksum_file_from_input (file_info, xattrs, input, - OSTREE_OBJECT_TYPE_FILE, &computed_csum, - cancellable, error)) + if (!ostree_checksum_file_from_input (file_info, xattrs, input, OSTREE_OBJECT_TYPE_FILE, + &computed_csum, cancellable, error)) return FALSE; - char actual_checksum[OSTREE_SHA256_STRING_LEN+1]; + char actual_checksum[OSTREE_SHA256_STRING_LEN + 1]; ostree_checksum_inplace_from_bytes (computed_csum, actual_checksum); return _ostree_compare_object_checksum (OSTREE_OBJECT_TYPE_FILE, sha256, actual_checksum, error); } @@ -4763,11 +4457,8 @@ fsck_content_object (OstreeRepo *self, * Since: 2017.15 */ gboolean -ostree_repo_fsck_object (OstreeRepo *self, - OstreeObjectType objtype, - const char *sha256, - GCancellable *cancellable, - GError **error) +ostree_repo_fsck_object (OstreeRepo *self, OstreeObjectType objtype, const char *sha256, + GCancellable *cancellable, GError **error) { if (OSTREE_OBJECT_TYPE_IS_META (objtype)) return fsck_metadata_object (self, objtype, sha256, cancellable, error); @@ -4792,16 +4483,11 @@ ostree_repo_fsck_object (OstreeRepo *self, * Otherwise, a copy will be performed. */ gboolean -ostree_repo_import_object_from (OstreeRepo *self, - OstreeRepo *source, - OstreeObjectType objtype, - const char *checksum, - GCancellable *cancellable, - GError **error) +ostree_repo_import_object_from (OstreeRepo *self, OstreeRepo *source, OstreeObjectType objtype, + const char *checksum, GCancellable *cancellable, GError **error) { - return - ostree_repo_import_object_from_with_trust (self, source, objtype, - checksum, TRUE, cancellable, error); + return ostree_repo_import_object_from_with_trust (self, source, objtype, checksum, TRUE, + cancellable, error); } /** @@ -4824,18 +4510,14 @@ ostree_repo_import_object_from (OstreeRepo *self, * Since: 2016.5 */ gboolean -ostree_repo_import_object_from_with_trust (OstreeRepo *self, - OstreeRepo *source, - OstreeObjectType objtype, - const char *checksum, - gboolean trusted, - GCancellable *cancellable, - GError **error) +ostree_repo_import_object_from_with_trust (OstreeRepo *self, OstreeRepo *source, + OstreeObjectType objtype, const char *checksum, + gboolean trusted, GCancellable *cancellable, + GError **error) { /* This just wraps a currently internal API, may make it public later */ OstreeRepoImportFlags flags = trusted ? _OSTREE_REPO_IMPORT_FLAGS_TRUSTED : 0; - return _ostree_repo_import_object (self, source, objtype, checksum, - flags, cancellable, error); + return _ostree_repo_import_object (self, source, objtype, checksum, flags, cancellable, error); } /** @@ -4851,24 +4533,24 @@ ostree_repo_import_object_from_with_trust (OstreeRepo *self, * compression has been applied. */ gboolean -ostree_repo_query_object_storage_size (OstreeRepo *self, - OstreeObjectType objtype, - const char *sha256, - guint64 *out_size, - GCancellable *cancellable, - GError **error) +ostree_repo_query_object_storage_size (OstreeRepo *self, OstreeObjectType objtype, + const char *sha256, guint64 *out_size, + GCancellable *cancellable, GError **error) { char loose_path[_OSTREE_LOOSE_PATH_MAX]; _ostree_loose_path (loose_path, sha256, objtype, self->mode); int res; struct stat stbuf; - res = TEMP_FAILURE_RETRY (fstatat (self->objects_dir_fd, loose_path, &stbuf, AT_SYMLINK_NOFOLLOW)); + res = TEMP_FAILURE_RETRY ( + fstatat (self->objects_dir_fd, loose_path, &stbuf, AT_SYMLINK_NOFOLLOW)); if (res < 0 && errno == ENOENT && self->commit_stagedir.initialized) - res = TEMP_FAILURE_RETRY (fstatat (self->commit_stagedir.fd, loose_path, &stbuf, AT_SYMLINK_NOFOLLOW)); + res = TEMP_FAILURE_RETRY ( + fstatat (self->commit_stagedir.fd, loose_path, &stbuf, AT_SYMLINK_NOFOLLOW)); if (res < 0) - return glnx_throw_errno_prefix (error, "Querying object %s.%s", sha256, ostree_object_type_to_string (objtype)); + return glnx_throw_errno_prefix (error, "Querying object %s.%s", sha256, + ostree_object_type_to_string (objtype)); *out_size = stbuf.st_size; return TRUE; @@ -4888,14 +4570,11 @@ ostree_repo_query_object_storage_size (OstreeRepo *self, * return TRUE. */ gboolean -ostree_repo_load_variant_if_exists (OstreeRepo *self, - OstreeObjectType objtype, - const char *sha256, - GVariant **out_variant, - GError **error) +ostree_repo_load_variant_if_exists (OstreeRepo *self, OstreeObjectType objtype, const char *sha256, + GVariant **out_variant, GError **error) { - return load_metadata_internal (self, objtype, sha256, FALSE, - out_variant, NULL, NULL, NULL, NULL, error); + return load_metadata_internal (self, objtype, sha256, FALSE, out_variant, NULL, NULL, NULL, NULL, + error); } /** @@ -4910,14 +4589,11 @@ ostree_repo_load_variant_if_exists (OstreeRepo *self, * result in @out_variant. */ gboolean -ostree_repo_load_variant (OstreeRepo *self, - OstreeObjectType objtype, - const char *sha256, - GVariant **out_variant, - GError **error) +ostree_repo_load_variant (OstreeRepo *self, OstreeObjectType objtype, const char *sha256, + GVariant **out_variant, GError **error) { - return load_metadata_internal (self, objtype, sha256, TRUE, - out_variant, NULL, NULL, NULL, NULL, error); + return load_metadata_internal (self, objtype, sha256, TRUE, out_variant, NULL, NULL, NULL, NULL, + error); } /** @@ -4934,30 +4610,23 @@ ostree_repo_load_variant (OstreeRepo *self, * means that only a sub-path of the commit is available. */ gboolean -ostree_repo_load_commit (OstreeRepo *self, - const char *checksum, - GVariant **out_variant, - OstreeRepoCommitState *out_state, - GError **error) +ostree_repo_load_commit (OstreeRepo *self, const char *checksum, GVariant **out_variant, + OstreeRepoCommitState *out_state, GError **error) { - return load_metadata_internal (self, OSTREE_OBJECT_TYPE_COMMIT, checksum, TRUE, - out_variant, NULL, NULL, out_state, NULL, error); + return load_metadata_internal (self, OSTREE_OBJECT_TYPE_COMMIT, checksum, TRUE, out_variant, NULL, + NULL, out_state, NULL, error); } static GHashTable * -repo_list_objects_impl (OstreeRepo *self, - OstreeRepoListObjectsFlags flags, - GVariant *dummy_value, - GCancellable *cancellable, - GError **error) +repo_list_objects_impl (OstreeRepo *self, OstreeRepoListObjectsFlags flags, GVariant *dummy_value, + GCancellable *cancellable, GError **error) { g_assert (error == NULL || *error == NULL); g_assert (self->inited); - g_autoptr(GHashTable) ret_objects = - g_hash_table_new_full (ostree_hash_object_name, g_variant_equal, - (GDestroyNotify) g_variant_unref, - dummy_value ? (GDestroyNotify) g_variant_unref : NULL); + g_autoptr (GHashTable) ret_objects = g_hash_table_new_full ( + ostree_hash_object_name, g_variant_equal, (GDestroyNotify)g_variant_unref, + dummy_value ? (GDestroyNotify)g_variant_unref : NULL); if (flags & OSTREE_REPO_LIST_OBJECTS_ALL) flags |= (OSTREE_REPO_LIST_OBJECTS_LOOSE | OSTREE_REPO_LIST_OBJECTS_PACKED); @@ -4968,7 +4637,8 @@ repo_list_objects_impl (OstreeRepo *self, return FALSE; if ((flags & OSTREE_REPO_LIST_OBJECTS_NO_PARENTS) == 0 && self->parent_repo) { - if (!list_loose_objects (self->parent_repo, dummy_value, ret_objects, NULL, cancellable, error)) + if (!list_loose_objects (self->parent_repo, dummy_value, ret_objects, NULL, cancellable, + error)) return FALSE; } } @@ -4985,10 +4655,8 @@ repo_list_objects_impl (OstreeRepo *self, * a set, and not a map (with a useless value). */ GHashTable * -ostree_repo_list_objects_set (OstreeRepo *self, - OstreeRepoListObjectsFlags flags, - GCancellable *cancellable, - GError **error) +ostree_repo_list_objects_set (OstreeRepo *self, OstreeRepoListObjectsFlags flags, + GCancellable *cancellable, GError **error) { return repo_list_objects_impl (self, flags, NULL, cancellable, error); } @@ -5020,14 +4688,12 @@ get_dummy_list_objects_variant (void) * Returns: %TRUE on success, %FALSE on error, and @error will be set */ gboolean -ostree_repo_list_objects (OstreeRepo *self, - OstreeRepoListObjectsFlags flags, - GHashTable **out_objects, - GCancellable *cancellable, - GError **error) -{ - g_autoptr(GVariant) dummy_value = get_dummy_list_objects_variant (); - g_autoptr(GHashTable) ret = repo_list_objects_impl (self, flags, dummy_value, cancellable, error); +ostree_repo_list_objects (OstreeRepo *self, OstreeRepoListObjectsFlags flags, + GHashTable **out_objects, GCancellable *cancellable, GError **error) +{ + g_autoptr (GVariant) dummy_value = get_dummy_list_objects_variant (); + g_autoptr (GHashTable) ret + = repo_list_objects_impl (self, flags, dummy_value, cancellable, error); if (!ret) return FALSE; ot_transfer_out_value (out_objects, &ret); @@ -5051,22 +4717,20 @@ ostree_repo_list_objects (OstreeRepo *self, * Returns: %TRUE on success, %FALSE on error, and @error will be set */ gboolean -ostree_repo_list_commit_objects_starting_with (OstreeRepo *self, - const char *start, - GHashTable **out_commits, - GCancellable *cancellable, - GError **error) +ostree_repo_list_commit_objects_starting_with (OstreeRepo *self, const char *start, + GHashTable **out_commits, GCancellable *cancellable, + GError **error) { g_return_val_if_fail (error == NULL || *error == NULL, FALSE); g_return_val_if_fail (self->inited, FALSE); - g_autoptr(GHashTable) ret_commits = - g_hash_table_new_full (ostree_hash_object_name, g_variant_equal, - (GDestroyNotify) g_variant_unref, - (GDestroyNotify) g_variant_unref); - g_autoptr(GVariant) dummy_loose_object_variant = get_dummy_list_objects_variant (); + g_autoptr (GHashTable) ret_commits + = g_hash_table_new_full (ostree_hash_object_name, g_variant_equal, + (GDestroyNotify)g_variant_unref, (GDestroyNotify)g_variant_unref); + g_autoptr (GVariant) dummy_loose_object_variant = get_dummy_list_objects_variant (); - if (!list_loose_objects (self, dummy_loose_object_variant, ret_commits, start, cancellable, error)) + if (!list_loose_objects (self, dummy_loose_object_variant, ret_commits, start, cancellable, + error)) return FALSE; if (self->parent_repo) @@ -5092,26 +4756,23 @@ ostree_repo_list_commit_objects_starting_with (OstreeRepo *self * Load the content for @rev into @out_root. */ gboolean -ostree_repo_read_commit (OstreeRepo *self, - const char *ref, - GFile **out_root, - char **out_commit, - GCancellable *cancellable, - GError **error) +ostree_repo_read_commit (OstreeRepo *self, const char *ref, GFile **out_root, char **out_commit, + GCancellable *cancellable, GError **error) { g_autofree char *resolved_commit = NULL; if (!ostree_repo_resolve_rev (self, ref, FALSE, &resolved_commit, error)) return FALSE; - g_autoptr(GFile) ret_root = (GFile*) _ostree_repo_file_new_for_commit (self, resolved_commit, error); + g_autoptr (GFile) ret_root + = (GFile *)_ostree_repo_file_new_for_commit (self, resolved_commit, error); if (!ret_root) return FALSE; - if (!ostree_repo_file_ensure_resolved ((OstreeRepoFile*)ret_root, error)) + if (!ostree_repo_file_ensure_resolved ((OstreeRepoFile *)ret_root, error)) return FALSE; - ot_transfer_out_value(out_root, &ret_root); - ot_transfer_out_value(out_commit, &resolved_commit); + ot_transfer_out_value (out_root, &ret_root); + ot_transfer_out_value (out_commit, &resolved_commit); return TRUE; } @@ -5119,7 +4780,8 @@ ostree_repo_read_commit (OstreeRepo *self, * ostree_repo_pull: * @self: Repo * @remote_name: Name of remote - * @refs_to_fetch: (array zero-terminated=1) (element-type utf8) (allow-none): Optional list of refs; if %NULL, fetch all configured refs + * @refs_to_fetch: (array zero-terminated=1) (element-type utf8) (allow-none): Optional list of + * refs; if %NULL, fetch all configured refs * @flags: Options controlling fetch behavior * @progress: (allow-none): Progress * @cancellable: Cancellable @@ -5143,15 +4805,12 @@ ostree_repo_read_commit (OstreeRepo *self, * one around this call. */ gboolean -ostree_repo_pull (OstreeRepo *self, - const char *remote_name, - char **refs_to_fetch, - OstreeRepoPullFlags flags, - OstreeAsyncProgress *progress, - GCancellable *cancellable, - GError **error) +ostree_repo_pull (OstreeRepo *self, const char *remote_name, char **refs_to_fetch, + OstreeRepoPullFlags flags, OstreeAsyncProgress *progress, + GCancellable *cancellable, GError **error) { - return ostree_repo_pull_one_dir (self, remote_name, NULL, refs_to_fetch, flags, progress, cancellable, error); + return ostree_repo_pull_one_dir (self, remote_name, NULL, refs_to_fetch, flags, progress, + cancellable, error); } /** @@ -5159,7 +4818,8 @@ ostree_repo_pull (OstreeRepo *self, * @self: Repo * @remote_name: Name of remote * @dir_to_pull: Subdirectory path - * @refs_to_fetch: (array zero-terminated=1) (element-type utf8) (allow-none): Optional list of refs; if %NULL, fetch all configured refs + * @refs_to_fetch: (array zero-terminated=1) (element-type utf8) (allow-none): Optional list of + * refs; if %NULL, fetch all configured refs * @flags: Options controlling fetch behavior * @progress: (allow-none): Progress * @cancellable: Cancellable @@ -5169,17 +4829,12 @@ ostree_repo_pull (OstreeRepo *self, * subpath. */ gboolean -ostree_repo_pull_one_dir (OstreeRepo *self, - const char *remote_name, - const char *dir_to_pull, - char **refs_to_fetch, - OstreeRepoPullFlags flags, - OstreeAsyncProgress *progress, - GCancellable *cancellable, - GError **error) +ostree_repo_pull_one_dir (OstreeRepo *self, const char *remote_name, const char *dir_to_pull, + char **refs_to_fetch, OstreeRepoPullFlags flags, + OstreeAsyncProgress *progress, GCancellable *cancellable, GError **error) { GVariantBuilder builder; - g_autoptr(GVariant) options = NULL; + g_autoptr (GVariant) options = NULL; g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); @@ -5189,12 +4844,12 @@ ostree_repo_pull_one_dir (OstreeRepo *self, g_variant_builder_add (&builder, "{s@v}", "flags", g_variant_new_variant (g_variant_new_int32 (flags))); if (refs_to_fetch) - g_variant_builder_add (&builder, "{s@v}", "refs", - g_variant_new_variant (g_variant_new_strv ((const char *const*) refs_to_fetch, -1))); + g_variant_builder_add ( + &builder, "{s@v}", "refs", + g_variant_new_variant (g_variant_new_strv ((const char *const *)refs_to_fetch, -1))); options = g_variant_ref_sink (g_variant_builder_end (&builder)); - return ostree_repo_pull_with_options (self, remote_name, options, - progress, cancellable, error); + return ostree_repo_pull_with_options (self, remote_name, options, progress, cancellable, error); } /** @@ -5247,7 +4902,7 @@ _formatted_time_remaining_from_seconds (guint64 seconds_remaining) **/ void ostree_repo_pull_default_console_progress_changed (OstreeAsyncProgress *progress, - gpointer user_data) + gpointer user_data) { g_autofree char *status = NULL; gboolean caught_error, scanning; @@ -5260,21 +4915,15 @@ ostree_repo_pull_default_console_progress_changed (OstreeAsyncProgress *progress guint fetched_delta_part_fallbacks; guint total_delta_part_fallbacks; - g_autoptr(GString) buf = g_string_new (""); - - ostree_async_progress_get (progress, - "outstanding-fetches", "u", &outstanding_fetches, - "outstanding-metadata-fetches", "u", &outstanding_metadata_fetches, - "outstanding-writes", "u", &outstanding_writes, - "caught-error", "b", &caught_error, - "scanning", "u", &scanning, - "scanned-metadata", "u", &n_scanned_metadata, - "fetched-delta-parts", "u", &fetched_delta_parts, - "total-delta-parts", "u", &total_delta_parts, - "fetched-delta-fallbacks", "u", &fetched_delta_part_fallbacks, - "total-delta-fallbacks", "u", &total_delta_part_fallbacks, - "status", "s", &status, - NULL); + g_autoptr (GString) buf = g_string_new (""); + + ostree_async_progress_get ( + progress, "outstanding-fetches", "u", &outstanding_fetches, "outstanding-metadata-fetches", + "u", &outstanding_metadata_fetches, "outstanding-writes", "u", &outstanding_writes, + "caught-error", "b", &caught_error, "scanning", "u", &scanning, "scanned-metadata", "u", + &n_scanned_metadata, "fetched-delta-parts", "u", &fetched_delta_parts, "total-delta-parts", + "u", &total_delta_parts, "fetched-delta-fallbacks", "u", &fetched_delta_part_fallbacks, + "total-delta-fallbacks", "u", &total_delta_part_fallbacks, "status", "s", &status, NULL); if (*status != '\0') { @@ -5294,14 +4943,10 @@ ostree_repo_pull_default_console_progress_changed (OstreeAsyncProgress *progress guint64 bytes_sec; /* Note: This is not atomic wrt the above getter call. */ - ostree_async_progress_get (progress, - "bytes-transferred", "t", &bytes_transferred, - "fetched", "u", &fetched, - "metadata-fetched", "u", &metadata_fetched, - "requested", "u", &requested, - "start-time", "t", &start_time, - "total-delta-part-size", "t", &total_delta_part_size, - NULL); + ostree_async_progress_get (progress, "bytes-transferred", "t", &bytes_transferred, "fetched", + "u", &fetched, "metadata-fetched", "u", &metadata_fetched, + "requested", "u", &requested, "start-time", "t", &start_time, + "total-delta-part-size", "t", &total_delta_part_size, NULL); formatted_bytes_transferred = g_format_size_full (bytes_transferred, 0); @@ -5322,7 +4967,8 @@ ostree_repo_pull_default_console_progress_changed (OstreeAsyncProgress *progress /* Are we doing deltas? If so, we can be more accurate */ if (total_delta_parts > 0) { - guint64 fetched_delta_part_size = ostree_async_progress_get_uint64 (progress, "fetched-delta-part-size"); + guint64 fetched_delta_part_size + = ostree_async_progress_get_uint64 (progress, "fetched-delta-part-size"); g_autofree char *formatted_fetched = NULL; g_autofree char *formatted_total = NULL; @@ -5338,31 +4984,33 @@ ostree_repo_pull_default_console_progress_changed (OstreeAsyncProgress *progress guint64 est_time_remaining = 0; if (total_delta_part_size > fetched_delta_part_size) est_time_remaining = (total_delta_part_size - fetched_delta_part_size) / bytes_sec; - g_autofree char *formatted_est_time_remaining = _formatted_time_remaining_from_seconds (est_time_remaining); - /* No space between %s and remaining, since formatted_est_time_remaining has a trailing space */ + g_autofree char *formatted_est_time_remaining + = _formatted_time_remaining_from_seconds (est_time_remaining); + /* No space between %s and remaining, since formatted_est_time_remaining has a + * trailing space */ g_string_append_printf (buf, "Receiving delta parts: %u/%u %s/%s %s/s %sremaining", - fetched_delta_parts, total_delta_parts, - formatted_fetched, formatted_total, - formatted_bytes_sec, + fetched_delta_parts, total_delta_parts, formatted_fetched, + formatted_total, formatted_bytes_sec, formatted_est_time_remaining); } else { g_string_append_printf (buf, "Receiving delta parts: %u/%u %s/%s", - fetched_delta_parts, total_delta_parts, - formatted_fetched, formatted_total); + fetched_delta_parts, total_delta_parts, formatted_fetched, + formatted_total); } } else if (scanning || outstanding_metadata_fetches) { g_string_append_printf (buf, "Receiving metadata objects: %u/(estimating) %s/s %s", - metadata_fetched, formatted_bytes_sec, formatted_bytes_transferred); + metadata_fetched, formatted_bytes_sec, + formatted_bytes_transferred); } else { g_string_append_printf (buf, "Receiving objects: %u%% (%u/%u) %s/s %s", - (guint)((((double)fetched) / requested) * 100), - fetched, requested, formatted_bytes_sec, formatted_bytes_transferred); + (guint)((((double)fetched) / requested) * 100), fetched, + requested, formatted_bytes_sec, formatted_bytes_transferred); } } else if (outstanding_writes) @@ -5388,28 +5036,20 @@ ostree_repo_pull_default_console_progress_changed (OstreeAsyncProgress *progress * Append a GPG signature to a commit. */ gboolean -ostree_repo_append_gpg_signature (OstreeRepo *self, - const gchar *commit_checksum, - GBytes *signature_bytes, - GCancellable *cancellable, - GError **error) -{ - g_autoptr(GVariant) metadata = NULL; - if (!ostree_repo_read_commit_detached_metadata (self, - commit_checksum, - &metadata, - cancellable, +ostree_repo_append_gpg_signature (OstreeRepo *self, const gchar *commit_checksum, + GBytes *signature_bytes, GCancellable *cancellable, + GError **error) +{ + g_autoptr (GVariant) metadata = NULL; + if (!ostree_repo_read_commit_detached_metadata (self, commit_checksum, &metadata, cancellable, error)) return FALSE; #ifndef OSTREE_DISABLE_GPGME - g_autoptr(GVariant) new_metadata = - _ostree_detached_metadata_append_gpg_sig (metadata, signature_bytes); + g_autoptr (GVariant) new_metadata + = _ostree_detached_metadata_append_gpg_sig (metadata, signature_bytes); - if (!ostree_repo_write_commit_detached_metadata (self, - commit_checksum, - new_metadata, - cancellable, + if (!ostree_repo_write_commit_detached_metadata (self, commit_checksum, new_metadata, cancellable, error)) return FALSE; @@ -5421,34 +5061,32 @@ ostree_repo_append_gpg_signature (OstreeRepo *self, #ifndef OSTREE_DISABLE_GPGME static gboolean -sign_data (OstreeRepo *self, - GBytes *input_data, - const gchar *key_id, - const gchar *homedir, - GBytes **out_signature, - GCancellable *cancellable, - GError **error) -{ - g_auto(GLnxTmpfile) tmpf = { 0, }; - if (!glnx_open_tmpfile_linkable_at (self->tmp_dir_fd, ".", O_RDWR | O_CLOEXEC, - &tmpf, error)) +sign_data (OstreeRepo *self, GBytes *input_data, const gchar *key_id, const gchar *homedir, + GBytes **out_signature, GCancellable *cancellable, GError **error) +{ + g_auto (GLnxTmpfile) tmpf = { + 0, + }; + if (!glnx_open_tmpfile_linkable_at (self->tmp_dir_fd, ".", O_RDWR | O_CLOEXEC, &tmpf, error)) return FALSE; - g_autoptr(GOutputStream) tmp_signature_output = g_unix_output_stream_new (tmpf.fd, FALSE); + g_autoptr (GOutputStream) tmp_signature_output = g_unix_output_stream_new (tmpf.fd, FALSE); - g_auto(gpgme_ctx_t) context = ot_gpgme_new_ctx (homedir, error); + g_auto (gpgme_ctx_t) context = ot_gpgme_new_ctx (homedir, error); if (!context) return FALSE; /* Get the secret keys with the given key id */ - g_auto(gpgme_key_t) key = NULL; + g_auto (gpgme_key_t) key = NULL; gpgme_error_t err = gpgme_get_key (context, key_id, &key, 1); if (gpgme_err_code (err) == GPG_ERR_EOF) return glnx_throw (error, "No gpg key found with ID %s (homedir: %s)", key_id, homedir ? homedir : ""); - else if (gpgme_err_code (err) == GPG_ERR_AMBIGUOUS_NAME) { - return glnx_throw (error, "gpg key id %s ambiguous (homedir: %s). Try the fingerprint instead", key_id, - homedir ? homedir : ""); - } + else if (gpgme_err_code (err) == GPG_ERR_AMBIGUOUS_NAME) + { + return glnx_throw (error, + "gpg key id %s ambiguous (homedir: %s). Try the fingerprint instead", + key_id, homedir ? homedir : ""); + } else if (err != GPG_ERR_NO_ERROR) return ot_gpgme_throw (err, error, "Unable to lookup key ID %s", key_id); @@ -5457,14 +5095,14 @@ sign_data (OstreeRepo *self, return ot_gpgme_throw (err, error, "Error signing commit"); /* Get a gpg buffer from the commit */ - g_auto(gpgme_data_t) commit_buffer = NULL; + g_auto (gpgme_data_t) commit_buffer = NULL; gsize len; const char *buf = g_bytes_get_data (input_data, &len); if ((err = gpgme_data_new_from_mem (&commit_buffer, buf, len, FALSE)) != GPG_ERR_NO_ERROR) return ot_gpgme_throw (err, error, "Failed to create buffer from commit file"); /* Sign it */ - g_auto(gpgme_data_t) signature_buffer = ot_gpgme_data_output (tmp_signature_output); + g_auto (gpgme_data_t) signature_buffer = ot_gpgme_data_output (tmp_signature_output); if ((err = gpgme_op_sign (context, commit_buffer, signature_buffer, GPGME_SIG_MODE_DETACH)) != GPG_ERR_NO_ERROR) return ot_gpgme_throw (err, error, "Failure signing commit file"); @@ -5472,7 +5110,7 @@ sign_data (OstreeRepo *self, return FALSE; /* Return a mmap() reference */ - g_autoptr(GMappedFile) signature_file = g_mapped_file_new_from_fd (tmpf.fd, FALSE, error); + g_autoptr (GMappedFile) signature_file = g_mapped_file_new_from_fd (tmpf.fd, FALSE, error); if (!signature_file) return FALSE; @@ -5494,27 +5132,20 @@ sign_data (OstreeRepo *self, * Add a GPG signature to a commit. */ gboolean -ostree_repo_sign_commit (OstreeRepo *self, - const gchar *commit_checksum, - const gchar *key_id, - const gchar *homedir, - GCancellable *cancellable, - GError **error) +ostree_repo_sign_commit (OstreeRepo *self, const gchar *commit_checksum, const gchar *key_id, + const gchar *homedir, GCancellable *cancellable, GError **error) { #ifndef OSTREE_DISABLE_GPGME - g_autoptr(GBytes) commit_data = NULL; - g_autoptr(GBytes) signature = NULL; + g_autoptr (GBytes) commit_data = NULL; + g_autoptr (GBytes) signature = NULL; - g_autoptr(GVariant) commit_variant = NULL; - if (!ostree_repo_load_variant (self, OSTREE_OBJECT_TYPE_COMMIT, - commit_checksum, &commit_variant, error)) + g_autoptr (GVariant) commit_variant = NULL; + if (!ostree_repo_load_variant (self, OSTREE_OBJECT_TYPE_COMMIT, commit_checksum, &commit_variant, + error)) return glnx_prefix_error (error, "Failed to read commit"); - g_autoptr(GVariant) old_metadata = NULL; - if (!ostree_repo_read_commit_detached_metadata (self, - commit_checksum, - &old_metadata, - cancellable, + g_autoptr (GVariant) old_metadata = NULL; + if (!ostree_repo_read_commit_detached_metadata (self, commit_checksum, &old_metadata, cancellable, error)) return glnx_prefix_error (error, "Failed to read detached metadata"); @@ -5525,14 +5156,12 @@ ostree_repo_sign_commit (OstreeRepo *self, * We want to avoid storing duplicate signatures in the metadata. We * pass the homedir so that the signing key can be imported, allowing * subkey signatures to be recognised. */ - g_autoptr(GError) local_error = NULL; - g_autoptr(GFile) verify_keydir = NULL; + g_autoptr (GError) local_error = NULL; + g_autoptr (GFile) verify_keydir = NULL; if (homedir != NULL) verify_keydir = g_file_new_for_path (homedir); - g_autoptr(OstreeGpgVerifyResult) result - =_ostree_repo_gpg_verify_with_metadata (self, commit_data, old_metadata, - NULL, verify_keydir, NULL, - cancellable, &local_error); + g_autoptr (OstreeGpgVerifyResult) result = _ostree_repo_gpg_verify_with_metadata ( + self, commit_data, old_metadata, NULL, verify_keydir, NULL, cancellable, &local_error); if (!result) { /* "Not found" just means the commit is not yet signed. That's okay. */ @@ -5545,22 +5174,18 @@ ostree_repo_sign_commit (OstreeRepo *self, } else if (ostree_gpg_verify_result_lookup (result, key_id, NULL)) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS, - "Commit is already signed with GPG key %s", key_id); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS, "Commit is already signed with GPG key %s", + key_id); return FALSE; } - if (!sign_data (self, commit_data, key_id, homedir, - &signature, cancellable, error)) + if (!sign_data (self, commit_data, key_id, homedir, &signature, cancellable, error)) return FALSE; - g_autoptr(GVariant) new_metadata = - _ostree_detached_metadata_append_gpg_sig (old_metadata, signature); + g_autoptr (GVariant) new_metadata + = _ostree_detached_metadata_append_gpg_sig (old_metadata, signature); - if (!ostree_repo_write_commit_detached_metadata (self, - commit_checksum, - new_metadata, - cancellable, + if (!ostree_repo_write_commit_detached_metadata (self, commit_checksum, new_metadata, cancellable, error)) return FALSE; @@ -5585,67 +5210,54 @@ ostree_repo_sign_commit (OstreeRepo *self, * Add a GPG signature to a static delta. */ gboolean -ostree_repo_sign_delta (OstreeRepo *self, - const gchar *from_commit, - const gchar *to_commit, - const gchar *key_id, - const gchar *homedir, - GCancellable *cancellable, - GError **error) -{ - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, - "ostree_repo_sign_delta is deprecated"); +ostree_repo_sign_delta (OstreeRepo *self, const gchar *from_commit, const gchar *to_commit, + const gchar *key_id, const gchar *homedir, GCancellable *cancellable, + GError **error) +{ + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "ostree_repo_sign_delta is deprecated"); return FALSE; } static gboolean -_ostree_repo_add_gpg_signature_summary_at (OstreeRepo *self, - int dir_fd, - const gchar **key_id, - const gchar *homedir, - GCancellable *cancellable, - GError **error) +_ostree_repo_add_gpg_signature_summary_at (OstreeRepo *self, int dir_fd, const gchar **key_id, + const gchar *homedir, GCancellable *cancellable, + GError **error) { #ifndef OSTREE_DISABLE_GPGME glnx_autofd int fd = -1; if (!glnx_openat_rdonly (dir_fd, "summary", TRUE, &fd, error)) return FALSE; - g_autoptr(GBytes) summary_data = ot_fd_readall_or_mmap (fd, 0, error); + g_autoptr (GBytes) summary_data = ot_fd_readall_or_mmap (fd, 0, error); if (!summary_data) return FALSE; /* Note that fd is reused below */ glnx_close_fd (&fd); - g_autoptr(GVariant) metadata = NULL; + g_autoptr (GVariant) metadata = NULL; if (!ot_openat_ignore_enoent (dir_fd, "summary.sig", &fd, error)) return FALSE; if (fd >= 0) { - if (!ot_variant_read_fd (fd, 0, G_VARIANT_TYPE (OSTREE_SUMMARY_SIG_GVARIANT_STRING), - FALSE, &metadata, error)) + if (!ot_variant_read_fd (fd, 0, G_VARIANT_TYPE (OSTREE_SUMMARY_SIG_GVARIANT_STRING), FALSE, + &metadata, error)) return FALSE; } for (guint i = 0; key_id[i]; i++) { - g_autoptr(GBytes) signature_data = NULL; - if (!sign_data (self, summary_data, key_id[i], homedir, - &signature_data, - cancellable, error)) + g_autoptr (GBytes) signature_data = NULL; + if (!sign_data (self, summary_data, key_id[i], homedir, &signature_data, cancellable, error)) return FALSE; - g_autoptr(GVariant) old_metadata = g_steal_pointer (&metadata); + g_autoptr (GVariant) old_metadata = g_steal_pointer (&metadata); metadata = _ostree_detached_metadata_append_gpg_sig (old_metadata, signature_data); } - g_autoptr(GVariant) normalized = g_variant_get_normal_form (metadata); + g_autoptr (GVariant) normalized = g_variant_get_normal_form (metadata); - if (!_ostree_repo_file_replace_contents (self, - dir_fd, - "summary.sig", + if (!_ostree_repo_file_replace_contents (self, dir_fd, "summary.sig", g_variant_get_data (normalized), - g_variant_get_size (normalized), - cancellable, error)) + g_variant_get_size (normalized), cancellable, error)) return FALSE; return TRUE; @@ -5665,25 +5277,17 @@ _ostree_repo_add_gpg_signature_summary_at (OstreeRepo *self, * Add a GPG signature to a summary file. */ gboolean -ostree_repo_add_gpg_signature_summary (OstreeRepo *self, - const gchar **key_id, - const gchar *homedir, - GCancellable *cancellable, - GError **error) +ostree_repo_add_gpg_signature_summary (OstreeRepo *self, const gchar **key_id, const gchar *homedir, + GCancellable *cancellable, GError **error) { #ifndef OSTREE_DISABLE_GPGME - return _ostree_repo_add_gpg_signature_summary_at (self, - self->repo_dir_fd, - key_id, - homedir, - cancellable, - error); + return _ostree_repo_add_gpg_signature_summary_at (self, self->repo_dir_fd, key_id, homedir, + cancellable, error); #else return glnx_throw (error, "GPG feature is disabled in a build time"); #endif /* OSTREE_DISABLE_GPGME */ } - /** * ostree_repo_gpg_sign_data: * @self: Self @@ -5707,31 +5311,25 @@ ostree_repo_add_gpg_signature_summary (OstreeRepo *self, * Since: 2020.8 */ gboolean -ostree_repo_gpg_sign_data (OstreeRepo *self, - GBytes *data, - GBytes *old_signatures, - const gchar **key_id, - const gchar *homedir, - GBytes **out_signatures, - GCancellable *cancellable, - GError **error) +ostree_repo_gpg_sign_data (OstreeRepo *self, GBytes *data, GBytes *old_signatures, + const gchar **key_id, const gchar *homedir, GBytes **out_signatures, + GCancellable *cancellable, GError **error) { #ifndef OSTREE_DISABLE_GPGME - g_autoptr(GVariant) metadata = NULL; - g_autoptr(GVariant) res = NULL; + g_autoptr (GVariant) metadata = NULL; + g_autoptr (GVariant) res = NULL; if (old_signatures) - metadata = g_variant_ref_sink (g_variant_new_from_bytes (G_VARIANT_TYPE (OSTREE_SUMMARY_SIG_GVARIANT_STRING), old_signatures, FALSE)); + metadata = g_variant_ref_sink (g_variant_new_from_bytes ( + G_VARIANT_TYPE (OSTREE_SUMMARY_SIG_GVARIANT_STRING), old_signatures, FALSE)); for (guint i = 0; key_id[i]; i++) { - g_autoptr(GBytes) signature_data = NULL; - if (!sign_data (self, data, key_id[i], homedir, - &signature_data, - cancellable, error)) + g_autoptr (GBytes) signature_data = NULL; + if (!sign_data (self, data, key_id[i], homedir, &signature_data, cancellable, error)) return FALSE; - g_autoptr(GVariant) old_metadata = g_steal_pointer (&metadata); + g_autoptr (GVariant) old_metadata = g_steal_pointer (&metadata); metadata = _ostree_detached_metadata_append_gpg_sig (old_metadata, signature_data); } @@ -5743,7 +5341,6 @@ ostree_repo_gpg_sign_data (OstreeRepo *self, #endif /* OSTREE_DISABLE_GPGME */ } - #ifndef OSTREE_DISABLE_GPGME /* Special remote for _ostree_repo_gpg_verify_with_metadata() */ static const char *OSTREE_ALL_REMOTES = "__OSTREE_ALL_REMOTES__"; @@ -5752,11 +5349,8 @@ static const char *OSTREE_ALL_REMOTES = "__OSTREE_ALL_REMOTES__"; * /etc/ostree/remotes.d. */ static gboolean -find_keyring (OstreeRepo *self, - OstreeRemote *remote, - GBytes **ret_bytes, - GCancellable *cancellable, - GError **error) +find_keyring (OstreeRepo *self, OstreeRemote *remote, GBytes **ret_bytes, GCancellable *cancellable, + GError **error) { glnx_autofd int fd = -1; if (!ot_openat_ignore_enoent (self->repo_dir_fd, remote->keyring, &fd, error)) @@ -5771,10 +5365,10 @@ find_keyring (OstreeRepo *self, return TRUE; } - g_autoptr(GFile) remotes_d = get_remotes_d_dir (self, NULL); + g_autoptr (GFile) remotes_d = get_remotes_d_dir (self, NULL); if (remotes_d) { - g_autoptr(GFile) child = g_file_get_child (remotes_d, remote->keyring); + g_autoptr (GFile) child = g_file_get_child (remotes_d, remote->keyring); if (!ot_openat_ignore_enoent (AT_FDCWD, gs_file_get_path_cached (child), &fd, error)) return FALSE; @@ -5797,36 +5391,32 @@ find_keyring (OstreeRepo *self, } static gboolean -_ostree_repo_gpg_prepare_verifier (OstreeRepo *self, - const gchar *remote_name, - GFile *keyringdir, - GFile *extra_keyring, - gboolean add_global_keyrings, - OstreeGpgVerifier **out_verifier, - GCancellable *cancellable, - GError **error) +_ostree_repo_gpg_prepare_verifier (OstreeRepo *self, const gchar *remote_name, GFile *keyringdir, + GFile *extra_keyring, gboolean add_global_keyrings, + OstreeGpgVerifier **out_verifier, GCancellable *cancellable, + GError **error) { - g_autoptr(OstreeGpgVerifier) verifier = _ostree_gpg_verifier_new (); + g_autoptr (OstreeGpgVerifier) verifier = _ostree_gpg_verifier_new (); if (remote_name == OSTREE_ALL_REMOTES) { /* Add all available remote keyring files. */ - if (!_ostree_gpg_verifier_add_keyring_dir_at (verifier, self->repo_dir_fd, ".", - cancellable, error)) + if (!_ostree_gpg_verifier_add_keyring_dir_at (verifier, self->repo_dir_fd, ".", cancellable, + error)) return FALSE; } else if (remote_name != NULL) { /* Add the remote's keyring file if it exists. */ - g_autoptr(OstreeRemote) remote = NULL; + g_autoptr (OstreeRemote) remote = NULL; remote = _ostree_repo_get_remote_inherited (self, remote_name, error); if (remote == NULL) return FALSE; - g_autoptr(GBytes) keyring_data = NULL; + g_autoptr (GBytes) keyring_data = NULL; if (!find_keyring (self, remote, &keyring_data, cancellable, error)) return FALSE; @@ -5836,21 +5426,16 @@ _ostree_repo_gpg_prepare_verifier (OstreeRepo *self, add_global_keyrings = FALSE; } - g_auto(GStrv) gpgkeypath_list = NULL; + g_auto (GStrv) gpgkeypath_list = NULL; - if (!ot_keyfile_get_string_list_with_separator_choice (remote->options, - remote->group, - "gpgkeypath", - ";,", - &gpgkeypath_list, - error)) + if (!ot_keyfile_get_string_list_with_separator_choice ( + remote->options, remote->group, "gpgkeypath", ";,", &gpgkeypath_list, error)) return FALSE; if (gpgkeypath_list) { for (char **iter = gpgkeypath_list; *iter != NULL; ++iter) - if (!_ostree_gpg_verifier_add_keyfile_path (verifier, *iter, - cancellable, error)) + if (!_ostree_gpg_verifier_add_keyfile_path (verifier, *iter, cancellable, error)) return FALSE; } } @@ -5864,8 +5449,7 @@ _ostree_repo_gpg_prepare_verifier (OstreeRepo *self, if (keyringdir) { - if (!_ostree_gpg_verifier_add_keyring_dir (verifier, keyringdir, - cancellable, error)) + if (!_ostree_gpg_verifier_add_keyring_dir (verifier, keyringdir, cancellable, error)) return FALSE; } if (extra_keyring != NULL) @@ -5880,57 +5464,38 @@ _ostree_repo_gpg_prepare_verifier (OstreeRepo *self, } static OstreeGpgVerifyResult * -_ostree_repo_gpg_verify_data_internal (OstreeRepo *self, - const gchar *remote_name, - GBytes *data, - GBytes *signatures, - GFile *keyringdir, - GFile *extra_keyring, - GCancellable *cancellable, - GError **error) -{ - g_autoptr(OstreeGpgVerifier) verifier = NULL; - if (!_ostree_repo_gpg_prepare_verifier (self, - remote_name, - keyringdir, - extra_keyring, - TRUE, - &verifier, - cancellable, - error)) +_ostree_repo_gpg_verify_data_internal (OstreeRepo *self, const gchar *remote_name, GBytes *data, + GBytes *signatures, GFile *keyringdir, GFile *extra_keyring, + GCancellable *cancellable, GError **error) +{ + g_autoptr (OstreeGpgVerifier) verifier = NULL; + if (!_ostree_repo_gpg_prepare_verifier (self, remote_name, keyringdir, extra_keyring, TRUE, + &verifier, cancellable, error)) return NULL; - return _ostree_gpg_verifier_check_signature (verifier, - data, - signatures, - cancellable, - error); + return _ostree_gpg_verifier_check_signature (verifier, data, signatures, cancellable, error); } OstreeGpgVerifyResult * -_ostree_repo_gpg_verify_with_metadata (OstreeRepo *self, - GBytes *signed_data, - GVariant *metadata, - const char *remote_name, - GFile *keyringdir, - GFile *extra_keyring, - GCancellable *cancellable, - GError **error) -{ - g_autoptr(GVariant) signaturedata = NULL; +_ostree_repo_gpg_verify_with_metadata (OstreeRepo *self, GBytes *signed_data, GVariant *metadata, + const char *remote_name, GFile *keyringdir, + GFile *extra_keyring, GCancellable *cancellable, + GError **error) +{ + g_autoptr (GVariant) signaturedata = NULL; GByteArray *buffer; GVariantIter iter; GVariant *child; g_autoptr (GBytes) signatures = NULL; if (metadata) - signaturedata = g_variant_lookup_value (metadata, - _OSTREE_METADATA_GPGSIGS_NAME, + signaturedata = g_variant_lookup_value (metadata, _OSTREE_METADATA_GPGSIGS_NAME, _OSTREE_METADATA_GPGSIGS_TYPE); if (!signaturedata) { g_set_error_literal (error, OSTREE_GPG_ERROR, OSTREE_GPG_ERROR_NO_SIGNATURE, - "GPG verification enabled, but no signatures found (use gpg-verify=false in remote config to disable)"); + "GPG verification enabled, but no signatures found (use " + "gpg-verify=false in remote config to disable)"); return NULL; } @@ -5946,50 +5511,35 @@ _ostree_repo_gpg_verify_with_metadata (OstreeRepo *self, g_variant_iter_init (&iter, signaturedata); while ((child = g_variant_iter_next_value (&iter)) != NULL) { - g_byte_array_append (buffer, - g_variant_get_data (child), - g_variant_get_size (child)); + g_byte_array_append (buffer, g_variant_get_data (child), g_variant_get_size (child)); g_variant_unref (child); } signatures = g_byte_array_free_to_bytes (buffer); - return _ostree_repo_gpg_verify_data_internal (self, - remote_name, - signed_data, - signatures, - keyringdir, - extra_keyring, - cancellable, - error); + return _ostree_repo_gpg_verify_data_internal (self, remote_name, signed_data, signatures, + keyringdir, extra_keyring, cancellable, error); } /* Needed an internal version for the remote_name parameter. */ OstreeGpgVerifyResult * -_ostree_repo_verify_commit_internal (OstreeRepo *self, - const char *commit_checksum, - const char *remote_name, - GFile *keyringdir, - GFile *extra_keyring, - GCancellable *cancellable, - GError **error) -{ - g_autoptr(GVariant) commit_variant = NULL; +_ostree_repo_verify_commit_internal (OstreeRepo *self, const char *commit_checksum, + const char *remote_name, GFile *keyringdir, + GFile *extra_keyring, GCancellable *cancellable, + GError **error) +{ + g_autoptr (GVariant) commit_variant = NULL; /* Load the commit */ - if (!ostree_repo_load_variant (self, OSTREE_OBJECT_TYPE_COMMIT, - commit_checksum, &commit_variant, + if (!ostree_repo_load_variant (self, OSTREE_OBJECT_TYPE_COMMIT, commit_checksum, &commit_variant, error)) return glnx_prefix_error_null (error, "Failed to read commit"); /* Load the metadata */ - g_autoptr(GVariant) metadata = NULL; - if (!ostree_repo_read_commit_detached_metadata (self, - commit_checksum, - &metadata, - cancellable, + g_autoptr (GVariant) metadata = NULL; + if (!ostree_repo_read_commit_detached_metadata (self, commit_checksum, &metadata, cancellable, error)) return glnx_prefix_error_null (error, "Failed to read detached metadata"); - g_autoptr(GBytes) signed_data = g_variant_get_data_as_bytes (commit_variant); + g_autoptr (GBytes) signed_data = g_variant_get_data_as_bytes (commit_variant); /* XXX This is a hackish way to indicate to use ALL remote-specific * keyrings in the signature verification. We want this when @@ -5997,10 +5547,8 @@ _ostree_repo_verify_commit_internal (OstreeRepo *self, if (remote_name == NULL) remote_name = OSTREE_ALL_REMOTES; - return _ostree_repo_gpg_verify_with_metadata (self, signed_data, - metadata, remote_name, - keyringdir, extra_keyring, - cancellable, error); + return _ostree_repo_gpg_verify_with_metadata (self, signed_data, metadata, remote_name, + keyringdir, extra_keyring, cancellable, error); } #endif /* OSTREE_DISABLE_GPGME */ @@ -6019,18 +5567,13 @@ _ostree_repo_verify_commit_internal (OstreeRepo *self, * Returns: %TRUE if there was a GPG signature from a trusted keyring, otherwise %FALSE */ gboolean -ostree_repo_verify_commit (OstreeRepo *self, - const gchar *commit_checksum, - GFile *keyringdir, - GFile *extra_keyring, - GCancellable *cancellable, - GError **error) +ostree_repo_verify_commit (OstreeRepo *self, const gchar *commit_checksum, GFile *keyringdir, + GFile *extra_keyring, GCancellable *cancellable, GError **error) { #ifndef OSTREE_DISABLE_GPGME - g_autoptr(OstreeGpgVerifyResult) result = NULL; + g_autoptr (OstreeGpgVerifyResult) result = NULL; - result = ostree_repo_verify_commit_ext (self, commit_checksum, - keyringdir, extra_keyring, + result = ostree_repo_verify_commit_ext (self, commit_checksum, keyringdir, extra_keyring, cancellable, error); if (!ostree_gpg_verify_result_require_valid_signature (result, error)) @@ -6057,21 +5600,12 @@ ostree_repo_verify_commit (OstreeRepo *self, * Returns: (transfer full): an #OstreeGpgVerifyResult, or %NULL on error */ OstreeGpgVerifyResult * -ostree_repo_verify_commit_ext (OstreeRepo *self, - const gchar *commit_checksum, - GFile *keyringdir, - GFile *extra_keyring, - GCancellable *cancellable, - GError **error) +ostree_repo_verify_commit_ext (OstreeRepo *self, const gchar *commit_checksum, GFile *keyringdir, + GFile *extra_keyring, GCancellable *cancellable, GError **error) { #ifndef OSTREE_DISABLE_GPGME - return _ostree_repo_verify_commit_internal (self, - commit_checksum, - NULL, - keyringdir, - extra_keyring, - cancellable, - error); + return _ostree_repo_verify_commit_internal (self, commit_checksum, NULL, keyringdir, + extra_keyring, cancellable, error); #else glnx_throw (error, "GPG feature is disabled in a build time"); return NULL; @@ -6095,20 +5629,13 @@ ostree_repo_verify_commit_ext (OstreeRepo *self, * Since: 2016.14 */ OstreeGpgVerifyResult * -ostree_repo_verify_commit_for_remote (OstreeRepo *self, - const gchar *commit_checksum, - const gchar *remote_name, - GCancellable *cancellable, - GError **error) +ostree_repo_verify_commit_for_remote (OstreeRepo *self, const gchar *commit_checksum, + const gchar *remote_name, GCancellable *cancellable, + GError **error) { #ifndef OSTREE_DISABLE_GPGME - return _ostree_repo_verify_commit_internal (self, - commit_checksum, - remote_name, - NULL, - NULL, - cancellable, - error); + return _ostree_repo_verify_commit_internal (self, commit_checksum, remote_name, NULL, NULL, + cancellable, error); #else glnx_throw (error, "GPG feature is disabled in a build time"); return NULL; @@ -6137,28 +5664,18 @@ ostree_repo_verify_commit_for_remote (OstreeRepo *self, * Since: 2016.6 */ OstreeGpgVerifyResult * -ostree_repo_gpg_verify_data (OstreeRepo *self, - const gchar *remote_name, - GBytes *data, - GBytes *signatures, - GFile *keyringdir, - GFile *extra_keyring, - GCancellable *cancellable, - GError **error) +ostree_repo_gpg_verify_data (OstreeRepo *self, const gchar *remote_name, GBytes *data, + GBytes *signatures, GFile *keyringdir, GFile *extra_keyring, + GCancellable *cancellable, GError **error) { g_return_val_if_fail (OSTREE_IS_REPO (self), NULL); g_return_val_if_fail (data != NULL, NULL); g_return_val_if_fail (signatures != NULL, NULL); #ifndef OSTREE_DISABLE_GPGME - return _ostree_repo_gpg_verify_data_internal (self, - (remote_name != NULL) ? remote_name : OSTREE_ALL_REMOTES, - data, - signatures, - keyringdir, - extra_keyring, - cancellable, - error); + return _ostree_repo_gpg_verify_data_internal ( + self, (remote_name != NULL) ? remote_name : OSTREE_ALL_REMOTES, data, signatures, keyringdir, + extra_keyring, cancellable, error); #else glnx_throw (error, "GPG feature is disabled in a build time"); return NULL; @@ -6180,31 +5697,22 @@ ostree_repo_gpg_verify_data (OstreeRepo *self, * Returns: (transfer full): an #OstreeGpgVerifyResult, or %NULL on error */ OstreeGpgVerifyResult * -ostree_repo_verify_summary (OstreeRepo *self, - const char *remote_name, - GBytes *summary, - GBytes *signatures, - GCancellable *cancellable, - GError **error) +ostree_repo_verify_summary (OstreeRepo *self, const char *remote_name, GBytes *summary, + GBytes *signatures, GCancellable *cancellable, GError **error) { - g_autoptr(GVariant) signatures_variant = NULL; + g_autoptr (GVariant) signatures_variant = NULL; g_return_val_if_fail (OSTREE_IS_REPO (self), NULL); g_return_val_if_fail (remote_name != NULL, NULL); g_return_val_if_fail (summary != NULL, NULL); g_return_val_if_fail (signatures != NULL, NULL); - signatures_variant = g_variant_new_from_bytes (OSTREE_SUMMARY_SIG_GVARIANT_FORMAT, - signatures, FALSE); + signatures_variant + = g_variant_new_from_bytes (OSTREE_SUMMARY_SIG_GVARIANT_FORMAT, signatures, FALSE); #ifndef OSTREE_DISABLE_GPGME - return _ostree_repo_gpg_verify_with_metadata (self, - summary, - signatures_variant, - remote_name, - NULL, NULL, - cancellable, - error); + return _ostree_repo_gpg_verify_with_metadata (self, summary, signatures_variant, remote_name, + NULL, NULL, cancellable, error); #else glnx_throw (error, "GPG feature is disabled in a build time"); return NULL; @@ -6215,15 +5723,13 @@ ostree_repo_verify_summary (OstreeRepo *self, * @refs_builder to go into a `summary` file. This includes building the * standard additional metadata keys for the ref. */ static gboolean -summary_add_ref_entry (OstreeRepo *self, - const char *ref, - const char *checksum, - GVariantBuilder *refs_builder, - GError **error) +summary_add_ref_entry (OstreeRepo *self, const char *ref, const char *checksum, + GVariantBuilder *refs_builder, GError **error) { - g_auto(GVariantDict) commit_metadata_builder = OT_VARIANT_BUILDER_INITIALIZER; + g_auto (GVariantDict) commit_metadata_builder = OT_VARIANT_BUILDER_INITIALIZER; - g_assert (ref); g_assert (checksum); + g_assert (ref); + g_assert (checksum); g_autofree char *remotename = NULL; if (!ostree_parse_refspec (ref, &remotename, NULL, NULL)) @@ -6233,16 +5739,16 @@ summary_add_ref_entry (OstreeRepo *self, if (remotename != NULL) return TRUE; - g_autoptr(GVariant) commit_obj = NULL; + g_autoptr (GVariant) commit_obj = NULL; if (!ostree_repo_load_variant (self, OSTREE_OBJECT_TYPE_COMMIT, checksum, &commit_obj, error)) return FALSE; - g_autoptr(GVariant) orig_metadata = g_variant_get_child_value (commit_obj, 0); + g_autoptr (GVariant) orig_metadata = g_variant_get_child_value (commit_obj, 0); g_variant_dict_init (&commit_metadata_builder, NULL); /* Forward the commit’s timestamp and version if they're valid. */ guint64 commit_timestamp = ostree_commit_get_timestamp (commit_obj); - g_autoptr(GDateTime) dt = g_date_time_new_from_unix_utc (commit_timestamp); + g_autoptr (GDateTime) dt = g_date_time_new_from_unix_utc (commit_timestamp); if (dt != NULL) g_variant_dict_insert_value (&commit_metadata_builder, OSTREE_COMMIT_TIMESTAMP, @@ -6252,43 +5758,37 @@ summary_add_ref_entry (OstreeRepo *self, if (g_variant_lookup (orig_metadata, OSTREE_COMMIT_META_KEY_VERSION, "&s", &version)) g_variant_dict_insert (&commit_metadata_builder, OSTREE_COMMIT_VERSION, "s", version); - g_variant_builder_add_value (refs_builder, - g_variant_new ("(s(t@ay@a{sv}))", ref, - (guint64) g_variant_get_size (commit_obj), - ostree_checksum_to_bytes_v (checksum), - g_variant_dict_end (&commit_metadata_builder))); + g_variant_builder_add_value ( + refs_builder, g_variant_new ("(s(t@ay@a{sv}))", ref, (guint64)g_variant_get_size (commit_obj), + ostree_checksum_to_bytes_v (checksum), + g_variant_dict_end (&commit_metadata_builder))); return TRUE; } static gboolean -regenerate_metadata (OstreeRepo *self, - gboolean do_metadata_commit, - GVariant *additional_metadata, - GVariant *options, - GCancellable *cancellable, - GError **error) -{ - g_autoptr(OstreeRepoAutoLock) lock = NULL; +regenerate_metadata (OstreeRepo *self, gboolean do_metadata_commit, GVariant *additional_metadata, + GVariant *options, GCancellable *cancellable, GError **error) +{ + g_autoptr (OstreeRepoAutoLock) lock = NULL; gboolean no_deltas_in_summary = FALSE; - lock = ostree_repo_auto_lock_push (self, OSTREE_REPO_LOCK_SHARED, - cancellable, error); + lock = ostree_repo_auto_lock_push (self, OSTREE_REPO_LOCK_SHARED, cancellable, error); if (!lock) return FALSE; /* Parse options vardict. */ g_autofree char **gpg_key_ids = NULL; const char *gpg_homedir = NULL; - g_autoptr(GVariant) sign_keys = NULL; + g_autoptr (GVariant) sign_keys = NULL; const char *sign_type = NULL; - g_autoptr(OstreeSign) sign = NULL; + g_autoptr (OstreeSign) sign = NULL; if (options != NULL) { if (!g_variant_is_of_type (options, G_VARIANT_TYPE_VARDICT)) return glnx_throw (error, "Invalid options doesn't match variant type '%s'", - (const char *) G_VARIANT_TYPE_VARDICT); + (const char *)G_VARIANT_TYPE_VARDICT); g_variant_lookup (options, "gpg-key-ids", "^a&s", &gpg_key_ids); g_variant_lookup (options, "gpg-homedir", "&s", &gpg_homedir); @@ -6311,8 +5811,8 @@ regenerate_metadata (OstreeRepo *self, /* Write out a new metadata commit for the repository when it has a collection ID. */ if (do_metadata_commit && main_collection_id != NULL) { - g_autoptr(OstreeRepoAutoTransaction) txn = - _ostree_repo_auto_transaction_start (self, cancellable, error); + g_autoptr (OstreeRepoAutoTransaction) txn + = _ostree_repo_auto_transaction_start (self, cancellable, error); if (!txn) return FALSE; @@ -6320,27 +5820,20 @@ regenerate_metadata (OstreeRepo *self, self->txn.disable_auto_summary = TRUE; g_autofree gchar *new_ostree_metadata_checksum = NULL; - if (!_ostree_repo_transaction_write_repo_metadata (self, - additional_metadata, - &new_ostree_metadata_checksum, - cancellable, - error)) + if (!_ostree_repo_transaction_write_repo_metadata ( + self, additional_metadata, &new_ostree_metadata_checksum, cancellable, error)) return FALSE; /* Sign the new commit. */ if (gpg_key_ids != NULL) { - for (const char * const *iter = (const char * const *) gpg_key_ids; + for (const char *const *iter = (const char *const *)gpg_key_ids; iter != NULL && *iter != NULL; iter++) { const char *gpg_key_id = *iter; - if (!ostree_repo_sign_commit (self, - new_ostree_metadata_checksum, - gpg_key_id, - gpg_homedir, - cancellable, - error)) + if (!ostree_repo_sign_commit (self, new_ostree_metadata_checksum, gpg_key_id, + gpg_homedir, cancellable, error)) return FALSE; } } @@ -6356,8 +5849,8 @@ regenerate_metadata (OstreeRepo *self, if (!ostree_sign_set_sk (sign, key, error)) return FALSE; - if (!ostree_sign_commit (sign, self, new_ostree_metadata_checksum, - cancellable, error)) + if (!ostree_sign_commit (sign, self, new_ostree_metadata_checksum, cancellable, + error)) return FALSE; } } @@ -6366,18 +5859,19 @@ regenerate_metadata (OstreeRepo *self, return FALSE; } - g_auto(GVariantDict) additional_metadata_builder = OT_VARIANT_BUILDER_INITIALIZER; + g_auto (GVariantDict) additional_metadata_builder = OT_VARIANT_BUILDER_INITIALIZER; g_variant_dict_init (&additional_metadata_builder, additional_metadata); - g_autoptr(GVariantBuilder) refs_builder = g_variant_builder_new (G_VARIANT_TYPE ("a(s(taya{sv}))")); + g_autoptr (GVariantBuilder) refs_builder + = g_variant_builder_new (G_VARIANT_TYPE ("a(s(taya{sv}))")); { if (main_collection_id == NULL) { - g_autoptr(GHashTable) refs = NULL; + g_autoptr (GHashTable) refs = NULL; if (!ostree_repo_list_refs (self, NULL, &refs, cancellable, error)) return FALSE; - g_autoptr(GList) ordered_keys = g_hash_table_get_keys (refs); + g_autoptr (GList) ordered_keys = g_hash_table_get_keys (refs); ordered_keys = g_list_sort (ordered_keys, (GCompareFunc)strcmp); for (GList *iter = ordered_keys; iter; iter = iter->next) @@ -6391,15 +5885,14 @@ regenerate_metadata (OstreeRepo *self, } } - if (!ot_keyfile_get_boolean_with_default (self->config, "core", - "no-deltas-in-summary", FALSE, + if (!ot_keyfile_get_boolean_with_default (self->config, "core", "no-deltas-in-summary", FALSE, &no_deltas_in_summary, error)) return FALSE; if (!no_deltas_in_summary) { - g_autoptr(GPtrArray) delta_names = NULL; - g_auto(GVariantDict) deltas_builder = OT_VARIANT_BUILDER_INITIALIZER; + g_autoptr (GPtrArray) delta_names = NULL; + g_auto (GVariantDict) deltas_builder = OT_VARIANT_BUILDER_INITIALIZER; if (!ostree_repo_list_static_delta_names (self, &delta_names, cancellable, error)) return FALSE; @@ -6414,9 +5907,8 @@ regenerate_metadata (OstreeRepo *self, if (!_ostree_parse_delta_name (delta_names->pdata[i], &from, &to, error)) return FALSE; - digest = _ostree_repo_static_delta_superblock_digest (self, - (from && from[0]) ? from : NULL, - to, cancellable, error); + digest = _ostree_repo_static_delta_superblock_digest ( + self, (from && from[0]) ? from : NULL, to, cancellable, error); if (digest == NULL) return FALSE; @@ -6424,18 +5916,20 @@ regenerate_metadata (OstreeRepo *self, } if (delta_names->len > 0) - g_variant_dict_insert_value (&additional_metadata_builder, OSTREE_SUMMARY_STATIC_DELTAS, g_variant_dict_end (&deltas_builder)); + g_variant_dict_insert_value (&additional_metadata_builder, OSTREE_SUMMARY_STATIC_DELTAS, + g_variant_dict_end (&deltas_builder)); } { - g_variant_dict_insert_value (&additional_metadata_builder, OSTREE_SUMMARY_LAST_MODIFIED, - g_variant_new_uint64 (GUINT64_TO_BE (g_get_real_time () / G_USEC_PER_SEC))); + g_variant_dict_insert_value ( + &additional_metadata_builder, OSTREE_SUMMARY_LAST_MODIFIED, + g_variant_new_uint64 (GUINT64_TO_BE (g_get_real_time () / G_USEC_PER_SEC))); } { g_autofree char *remote_mode_str = NULL; - if (!ot_keyfile_get_value_with_default (self->config, "core", "mode", "bare", - &remote_mode_str, error)) + if (!ot_keyfile_get_value_with_default (self->config, "core", "mode", "bare", &remote_mode_str, + error)) return FALSE; g_variant_dict_insert_value (&additional_metadata_builder, OSTREE_SUMMARY_MODE, g_variant_new_string (remote_mode_str)); @@ -6456,21 +5950,21 @@ regenerate_metadata (OstreeRepo *self, /* Add refs which have a collection specified, which could be in refs/mirrors, * refs/heads, and/or refs/remotes. */ { - g_autoptr(GHashTable) collection_refs = NULL; + g_autoptr (GHashTable) collection_refs = NULL; if (!ostree_repo_list_collection_refs (self, NULL, &collection_refs, OSTREE_REPO_LIST_REFS_EXT_NONE, cancellable, error)) return FALSE; gsize collection_map_size = 0; GHashTableIter iter; - g_autoptr(GHashTable) collection_map = NULL; /* (element-type utf8 GHashTable) */ + g_autoptr (GHashTable) collection_map = NULL; /* (element-type utf8 GHashTable) */ g_hash_table_iter_init (&iter, collection_refs); - collection_map = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, - (GDestroyNotify)g_hash_table_unref); + collection_map + = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify)g_hash_table_unref); const OstreeCollectionRef *c_ref; const char *checksum; - while (g_hash_table_iter_next (&iter, (gpointer *) &c_ref, (gpointer *) &checksum)) + while (g_hash_table_iter_next (&iter, (gpointer *)&c_ref, (gpointer *)&checksum)) { GHashTable *ref_map = g_hash_table_lookup (collection_map, c_ref->collection_id); @@ -6480,22 +5974,25 @@ regenerate_metadata (OstreeRepo *self, g_hash_table_insert (collection_map, c_ref->collection_id, ref_map); } - g_hash_table_insert (ref_map, c_ref->ref_name, (gpointer) checksum); + g_hash_table_insert (ref_map, c_ref->ref_name, (gpointer)checksum); } - g_autoptr(GVariantBuilder) collection_refs_builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sa(s(taya{sv}))}")); + g_autoptr (GVariantBuilder) collection_refs_builder + = g_variant_builder_new (G_VARIANT_TYPE ("a{sa(s(taya{sv}))}")); - g_autoptr(GList) ordered_collection_ids = g_hash_table_get_keys (collection_map); - ordered_collection_ids = g_list_sort (ordered_collection_ids, (GCompareFunc) strcmp); + g_autoptr (GList) ordered_collection_ids = g_hash_table_get_keys (collection_map); + ordered_collection_ids = g_list_sort (ordered_collection_ids, (GCompareFunc)strcmp); - for (GList *collection_iter = ordered_collection_ids; collection_iter; collection_iter = collection_iter->next) + for (GList *collection_iter = ordered_collection_ids; collection_iter; + collection_iter = collection_iter->next) { const char *collection_id = collection_iter->data; GHashTable *ref_map = g_hash_table_lookup (collection_map, collection_id); /* We put the local repo's collection ID in the main refs map, rather * than the collection map, for backwards compatibility. */ - gboolean is_main_collection_id = (main_collection_id != NULL && g_str_equal (collection_id, main_collection_id)); + gboolean is_main_collection_id + = (main_collection_id != NULL && g_str_equal (collection_id, main_collection_id)); if (!is_main_collection_id) { @@ -6504,14 +6001,15 @@ regenerate_metadata (OstreeRepo *self, g_variant_builder_open (collection_refs_builder, G_VARIANT_TYPE ("a(s(taya{sv}))")); } - g_autoptr(GList) ordered_refs = g_hash_table_get_keys (ref_map); - ordered_refs = g_list_sort (ordered_refs, (GCompareFunc) strcmp); + g_autoptr (GList) ordered_refs = g_hash_table_get_keys (ref_map); + ordered_refs = g_list_sort (ordered_refs, (GCompareFunc)strcmp); for (GList *ref_iter = ordered_refs; ref_iter != NULL; ref_iter = ref_iter->next) { const char *ref = ref_iter->data; const char *commit = g_hash_table_lookup (ref_map, ref); - GVariantBuilder *builder = is_main_collection_id ? refs_builder : collection_refs_builder; + GVariantBuilder *builder + = is_main_collection_id ? refs_builder : collection_refs_builder; if (!summary_add_ref_entry (self, ref, commit, builder, error)) return FALSE; @@ -6522,8 +6020,8 @@ regenerate_metadata (OstreeRepo *self, if (!is_main_collection_id) { - g_variant_builder_close (collection_refs_builder); /* array */ - g_variant_builder_close (collection_refs_builder); /* dict entry */ + g_variant_builder_close (collection_refs_builder); /* array */ + g_variant_builder_close (collection_refs_builder); /* dict entry */ } } @@ -6535,13 +6033,14 @@ regenerate_metadata (OstreeRepo *self, g_variant_builder_end (collection_refs_builder)); } - g_autoptr(GVariant) summary = NULL; + g_autoptr (GVariant) summary = NULL; { - g_autoptr(GVariantBuilder) summary_builder = - g_variant_builder_new (OSTREE_SUMMARY_GVARIANT_FORMAT); + g_autoptr (GVariantBuilder) summary_builder + = g_variant_builder_new (OSTREE_SUMMARY_GVARIANT_FORMAT); g_variant_builder_add_value (summary_builder, g_variant_builder_end (refs_builder)); - g_variant_builder_add_value (summary_builder, g_variant_dict_end (&additional_metadata_builder)); + g_variant_builder_add_value (summary_builder, + g_variant_dict_end (&additional_metadata_builder)); summary = g_variant_builder_end (summary_builder); g_variant_ref_sink (summary); } @@ -6552,49 +6051,41 @@ regenerate_metadata (OstreeRepo *self, /* Create the summary and signature in a temporary directory so that * the summary isn't published without a matching signature. */ - g_auto(GLnxTmpDir) summary_tmpdir = { 0, }; - if (!glnx_mkdtempat (self->tmp_dir_fd, "summary-XXXXXX", 0777, - &summary_tmpdir, error)) + g_auto (GLnxTmpDir) summary_tmpdir = { + 0, + }; + if (!glnx_mkdtempat (self->tmp_dir_fd, "summary-XXXXXX", 0777, &summary_tmpdir, error)) return FALSE; g_debug ("Using summary tmpdir %s", summary_tmpdir.path); - if (!_ostree_repo_file_replace_contents (self, - summary_tmpdir.fd, - "summary", + if (!_ostree_repo_file_replace_contents (self, summary_tmpdir.fd, "summary", g_variant_get_data (summary), - g_variant_get_size (summary), - cancellable, - error)) + g_variant_get_size (summary), cancellable, error)) return FALSE; - if (gpg_key_ids != NULL && - !_ostree_repo_add_gpg_signature_summary_at (self, summary_tmpdir.fd, - (const char **) gpg_key_ids, gpg_homedir, - cancellable, error)) + if (gpg_key_ids != NULL + && !_ostree_repo_add_gpg_signature_summary_at ( + self, summary_tmpdir.fd, (const char **)gpg_key_ids, gpg_homedir, cancellable, error)) return FALSE; - if (sign_keys != NULL && - !_ostree_sign_summary_at (sign, self, summary_tmpdir.fd, sign_keys, - cancellable, error)) + if (sign_keys != NULL + && !_ostree_sign_summary_at (sign, self, summary_tmpdir.fd, sign_keys, cancellable, error)) return FALSE; /* Rename them into place */ - if (!glnx_renameat (summary_tmpdir.fd, "summary", - self->repo_dir_fd, "summary", - error)) + if (!glnx_renameat (summary_tmpdir.fd, "summary", self->repo_dir_fd, "summary", error)) return glnx_prefix_error (error, "Unable to rename summary file: "); if (gpg_key_ids != NULL || sign_keys != NULL) { - if (!glnx_renameat (summary_tmpdir.fd, "summary.sig", - self->repo_dir_fd, "summary.sig", + if (!glnx_renameat (summary_tmpdir.fd, "summary.sig", self->repo_dir_fd, "summary.sig", error)) { /* Delete an existing signature since it no longer corresponds * to the published summary. */ g_debug ("Deleting existing unmatched summary.sig file"); - (void) ot_ensure_unlinked_at (self->repo_dir_fd, "summary.sig", NULL); + (void)ot_ensure_unlinked_at (self->repo_dir_fd, "summary.sig", NULL); return glnx_prefix_error (error, "Unable to rename summary signature file: "); } @@ -6636,10 +6127,8 @@ regenerate_metadata (OstreeRepo *self, * Locking: shared (Prior to 2021.7, this was exclusive) */ gboolean -ostree_repo_regenerate_summary (OstreeRepo *self, - GVariant *additional_metadata, - GCancellable *cancellable, - GError **error) +ostree_repo_regenerate_summary (OstreeRepo *self, GVariant *additional_metadata, + GCancellable *cancellable, GError **error) { return regenerate_metadata (self, FALSE, additional_metadata, NULL, cancellable, error); } @@ -6676,11 +6165,8 @@ ostree_repo_regenerate_summary (OstreeRepo *self, * Since: 2023.1 */ gboolean -ostree_repo_regenerate_metadata (OstreeRepo *self, - GVariant *additional_metadata, - GVariant *options, - GCancellable *cancellable, - GError **error) +ostree_repo_regenerate_metadata (OstreeRepo *self, GVariant *additional_metadata, GVariant *options, + GCancellable *cancellable, GError **error) { return regenerate_metadata (self, TRUE, additional_metadata, options, cancellable, error); } @@ -6692,25 +6178,21 @@ ostree_repo_regenerate_metadata (OstreeRepo *self, * transactions instead of automatically here. `auto-update-summary` only updates * atomically within a transaction. */ gboolean -_ostree_repo_maybe_regenerate_summary (OstreeRepo *self, - GCancellable *cancellable, - GError **error) +_ostree_repo_maybe_regenerate_summary (OstreeRepo *self, GCancellable *cancellable, GError **error) { gboolean auto_update_summary; - if (!ot_keyfile_get_boolean_with_default (self->config, "core", - "auto-update-summary", FALSE, + if (!ot_keyfile_get_boolean_with_default (self->config, "core", "auto-update-summary", FALSE, &auto_update_summary, error)) return FALSE; /* Deprecated alias for `auto-update-summary`. */ gboolean commit_update_summary; - if (!ot_keyfile_get_boolean_with_default (self->config, "core", - "commit-update-summary", FALSE, + if (!ot_keyfile_get_boolean_with_default (self->config, "core", "commit-update-summary", FALSE, &commit_update_summary, error)) return FALSE; - if ((auto_update_summary || commit_update_summary) && - !ostree_repo_regenerate_summary (self, NULL, cancellable, error)) + if ((auto_update_summary || commit_update_summary) + && !ostree_repo_regenerate_summary (self, NULL, cancellable, error)) return FALSE; return TRUE; @@ -6723,20 +6205,16 @@ _ostree_repo_has_staging_prefix (const char *filename) } gboolean -_ostree_repo_try_lock_tmpdir (int tmpdir_dfd, - const char *tmpdir_name, - GLnxLockFile *file_lock_out, - gboolean *out_did_lock, - GError **error) +_ostree_repo_try_lock_tmpdir (int tmpdir_dfd, const char *tmpdir_name, GLnxLockFile *file_lock_out, + gboolean *out_did_lock, GError **error) { g_autofree char *lock_name = g_strconcat (tmpdir_name, "-lock", NULL); gboolean did_lock = FALSE; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; /* We put the lock outside the dir, so we can hold the lock * until the directory is fully removed */ - if (!glnx_make_lock_file (tmpdir_dfd, lock_name, LOCK_EX | LOCK_NB, - file_lock_out, &local_error)) + if (!glnx_make_lock_file (tmpdir_dfd, lock_name, LOCK_EX | LOCK_NB, file_lock_out, &local_error)) { /* we need to handle EACCES too in the case of POSIX locks; see F_SETLK in fcntl(2) */ if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK) @@ -6771,28 +6249,28 @@ _ostree_repo_try_lock_tmpdir (int tmpdir_dfd, /* This allocates and locks a subdir of the repo tmp dir, using an existing * one with the same prefix if it is not in use already. */ gboolean -_ostree_repo_allocate_tmpdir (int tmpdir_dfd, - const char *tmpdir_prefix, - GLnxTmpDir *tmpdir_out, - GLnxLockFile *file_lock_out, - gboolean *reusing_dir_out, - GCancellable *cancellable, - GError **error) +_ostree_repo_allocate_tmpdir (int tmpdir_dfd, const char *tmpdir_prefix, GLnxTmpDir *tmpdir_out, + GLnxLockFile *file_lock_out, gboolean *reusing_dir_out, + GCancellable *cancellable, GError **error) { g_return_val_if_fail (_ostree_repo_has_staging_prefix (tmpdir_prefix), FALSE); /* Look for existing tmpdir (with same prefix) to reuse */ - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; if (!glnx_dirfd_iterator_init_at (tmpdir_dfd, ".", FALSE, &dfd_iter, error)) return FALSE; gboolean reusing_dir = FALSE; gboolean did_lock = FALSE; - g_auto(GLnxTmpDir) ret_tmpdir = { 0, }; + g_auto (GLnxTmpDir) ret_tmpdir = { + 0, + }; while (!ret_tmpdir.initialized) { struct dirent *dent; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; if (!glnx_dirfd_iterator_next_dent (&dfd_iter, &dent, cancellable, error)) return FALSE; @@ -6804,16 +6282,14 @@ _ostree_repo_allocate_tmpdir (int tmpdir_dfd, continue; /* Quickly skip non-dirs, if unknown we ignore ENOTDIR when opening instead */ - if (dent->d_type != DT_UNKNOWN && - dent->d_type != DT_DIR) + if (dent->d_type != DT_UNKNOWN && dent->d_type != DT_DIR) continue; glnx_autofd int target_dfd = -1; - if (!glnx_opendirat (dfd_iter.fd, dent->d_name, FALSE, - &target_dfd, &local_error)) + if (!glnx_opendirat (dfd_iter.fd, dent->d_name, FALSE, &target_dfd, &local_error)) { - if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY) || - g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) + if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY) + || g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) continue; else { @@ -6824,9 +6300,7 @@ _ostree_repo_allocate_tmpdir (int tmpdir_dfd, /* We put the lock outside the dir, so we can hold the lock * until the directory is fully removed */ - if (!_ostree_repo_try_lock_tmpdir (tmpdir_dfd, dent->d_name, - file_lock_out, &did_lock, - error)) + if (!_ostree_repo_try_lock_tmpdir (tmpdir_dfd, dent->d_name, file_lock_out, &did_lock, error)) return FALSE; if (!did_lock) continue; @@ -6848,17 +6322,18 @@ _ostree_repo_allocate_tmpdir (int tmpdir_dfd, const char *tmpdir_name_template = glnx_strjoina (tmpdir_prefix, "XXXXXX"); while (!ret_tmpdir.initialized) { - g_auto(GLnxTmpDir) new_tmpdir = { 0, }; + g_auto (GLnxTmpDir) new_tmpdir = { + 0, + }; /* No existing tmpdir found, create a new */ - if (!glnx_mkdtempat (tmpdir_dfd, tmpdir_name_template, DEFAULT_DIRECTORY_MODE, - &new_tmpdir, error)) + if (!glnx_mkdtempat (tmpdir_dfd, tmpdir_name_template, DEFAULT_DIRECTORY_MODE, &new_tmpdir, + error)) return FALSE; /* Note, at this point we can race with another process that picks up this * new directory. If that happens we need to retry, making a new directory. */ - if (!_ostree_repo_try_lock_tmpdir (new_tmpdir.src_dfd, new_tmpdir.path, - file_lock_out, &did_lock, - error)) + if (!_ostree_repo_try_lock_tmpdir (new_tmpdir.src_dfd, new_tmpdir.path, file_lock_out, + &did_lock, error)) return FALSE; if (!did_lock) { @@ -6885,17 +6360,16 @@ _ostree_repo_allocate_tmpdir (int tmpdir_dfd, /* See ostree-repo-private.h for more information about this */ void -_ostree_repo_memory_cache_ref_init (OstreeRepoMemoryCacheRef *state, - OstreeRepo *repo) +_ostree_repo_memory_cache_ref_init (OstreeRepoMemoryCacheRef *state, OstreeRepo *repo) { state->repo = g_object_ref (repo); GMutex *lock = &repo->cache_lock; g_mutex_lock (lock); repo->dirmeta_cache_refcount++; if (repo->dirmeta_cache == NULL) - repo->dirmeta_cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_variant_unref); + repo->dirmeta_cache + = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_variant_unref); g_mutex_unlock (lock); - } /* See ostree-repo-private.h for more information about this */ @@ -6943,9 +6417,7 @@ ostree_repo_get_collection_id (OstreeRepo *self) * Since: 2018.6 */ gboolean -ostree_repo_set_collection_id (OstreeRepo *self, - const gchar *collection_id, - GError **error) +ostree_repo_set_collection_id (OstreeRepo *self, const gchar *collection_id, GError **error) { if (collection_id != NULL && !ostree_validate_collection_id (collection_id, error)) return FALSE; @@ -6976,12 +6448,12 @@ ostree_repo_set_collection_id (OstreeRepo *self, * %NULL-terminated array of strings. * Since: 2018.9 */ -const gchar * const * +const gchar *const * ostree_repo_get_default_repo_finders (OstreeRepo *self) { g_return_val_if_fail (OSTREE_IS_REPO (self), NULL); - return (const gchar * const *)self->repo_finders; + return (const gchar *const *)self->repo_finders; } /** @@ -6995,14 +6467,13 @@ ostree_repo_get_default_repo_finders (OstreeRepo *self) * Since: 2019.2 */ const gchar * -ostree_repo_get_bootloader (OstreeRepo *self) +ostree_repo_get_bootloader (OstreeRepo *self) { g_return_val_if_fail (OSTREE_IS_REPO (self), NULL); return CFG_SYSROOT_BOOTLOADER_OPTS_STR[self->bootloader]; } - /** * _ostree_repo_verify_bindings: * @collection_id: (nullable): Locally specified collection ID for the remote @@ -7030,17 +6501,12 @@ ostree_repo_get_bootloader (OstreeRepo *self) * Since: 2017.14 */ gboolean -_ostree_repo_verify_bindings (const char *collection_id, - const char *ref_name, - GVariant *commit, - GError **error) +_ostree_repo_verify_bindings (const char *collection_id, const char *ref_name, GVariant *commit, + GError **error) { - g_autoptr(GVariant) metadata = g_variant_get_child_value (commit, 0); + g_autoptr (GVariant) metadata = g_variant_get_child_value (commit, 0); g_autofree const char **refs = NULL; - if (!g_variant_lookup (metadata, - OSTREE_COMMIT_META_KEY_REF_BINDING, - "^a&s", - &refs)) + if (!g_variant_lookup (metadata, OSTREE_COMMIT_META_KEY_REF_BINDING, "^a&s", &refs)) { /* Early return here - if the remote collection ID is NULL, then * we certainly will not verify the collection binding in the @@ -7049,16 +6515,15 @@ _ostree_repo_verify_bindings (const char *collection_id, if (collection_id == NULL) return TRUE; - return glnx_throw (error, - "Expected commit metadata to have ref " - "binding information, found none"); + return glnx_throw (error, "Expected commit metadata to have ref " + "binding information, found none"); } if (ref_name != NULL) { - if (!g_strv_contains ((const char *const *) refs, ref_name)) + if (!g_strv_contains ((const char *const *)refs, ref_name)) { - g_autoptr(GString) refs_dump = g_string_new (NULL); + g_autoptr (GString) refs_dump = g_string_new (NULL); const char *refs_str; if (refs != NULL && (*refs) != NULL) @@ -7079,7 +6544,8 @@ _ostree_repo_verify_bindings (const char *collection_id, refs_str = "no refs"; } - return glnx_throw (error, "Commit has no requested ref ‘%s’ " + return glnx_throw (error, + "Commit has no requested ref ‘%s’ " "in ref binding metadata (%s)", ref_name, refs_str); } @@ -7088,13 +6554,10 @@ _ostree_repo_verify_bindings (const char *collection_id, if (collection_id != NULL) { const char *collection_id_binding; - if (!g_variant_lookup (metadata, - OSTREE_COMMIT_META_KEY_COLLECTION_BINDING, - "&s", + if (!g_variant_lookup (metadata, OSTREE_COMMIT_META_KEY_COLLECTION_BINDING, "&s", &collection_id_binding)) - return glnx_throw (error, - "Expected commit metadata to have collection ID " - "binding information, found none"); + return glnx_throw (error, "Expected commit metadata to have collection ID " + "binding information, found none"); if (!g_str_equal (collection_id_binding, collection_id)) return glnx_throw (error, "Commit has collection ID ‘%s’ in collection binding " diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h index a85db11a..1e6b3202 100644 --- a/src/libostree/ostree-repo.h +++ b/src/libostree/ostree-repo.h @@ -23,143 +23,111 @@ #include -#include "ostree-core.h" -#include "ostree-types.h" #include "ostree-async-progress.h" +#include "ostree-core.h" +#include "ostree-gpg-verify-result.h" #include "ostree-ref.h" #include "ostree-repo-finder.h" #include "ostree-sepolicy.h" -#include "ostree-gpg-verify-result.h" #include "ostree-sign.h" +#include "ostree-types.h" G_BEGIN_DECLS -#define OSTREE_TYPE_REPO ostree_repo_get_type() -#define OSTREE_REPO(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSTREE_TYPE_REPO, OstreeRepo)) -#define OSTREE_IS_REPO(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSTREE_TYPE_REPO)) +#define OSTREE_TYPE_REPO ostree_repo_get_type () +#define OSTREE_REPO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSTREE_TYPE_REPO, OstreeRepo)) +#define OSTREE_IS_REPO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSTREE_TYPE_REPO)) _OSTREE_PUBLIC -gboolean ostree_repo_mode_from_string (const char *mode, - OstreeRepoMode *out_mode, - GError **error); +gboolean ostree_repo_mode_from_string (const char *mode, OstreeRepoMode *out_mode, GError **error); _OSTREE_PUBLIC GType ostree_repo_get_type (void); _OSTREE_PUBLIC -OstreeRepo* ostree_repo_new (GFile *path); +OstreeRepo *ostree_repo_new (GFile *path); _OSTREE_PUBLIC -OstreeRepo* ostree_repo_new_for_sysroot_path (GFile *repo_path, - GFile *sysroot_path); +OstreeRepo *ostree_repo_new_for_sysroot_path (GFile *repo_path, GFile *sysroot_path); _OSTREE_PUBLIC -OstreeRepo* ostree_repo_new_default (void); +OstreeRepo *ostree_repo_new_default (void); _OSTREE_PUBLIC -gboolean ostree_repo_open (OstreeRepo *self, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_open (OstreeRepo *self, GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -OstreeRepo* -ostree_repo_open_at (int dfd, - const char *path, - GCancellable *cancellable, - GError **error); +OstreeRepo *ostree_repo_open_at (int dfd, const char *path, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -void ostree_repo_set_disable_fsync (OstreeRepo *self, - gboolean disable_fsync); +void ostree_repo_set_disable_fsync (OstreeRepo *self, gboolean disable_fsync); _OSTREE_PUBLIC -gboolean ostree_repo_set_cache_dir (OstreeRepo *self, - int dfd, - const char *path, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_set_cache_dir (OstreeRepo *self, int dfd, const char *path, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_get_disable_fsync (OstreeRepo *self); +gboolean ostree_repo_get_disable_fsync (OstreeRepo *self); _OSTREE_PUBLIC -gboolean ostree_repo_is_system (OstreeRepo *repo); +gboolean ostree_repo_is_system (OstreeRepo *repo); _OSTREE_PUBLIC -gboolean ostree_repo_is_writable (OstreeRepo *self, - GError **error); +gboolean ostree_repo_is_writable (OstreeRepo *self, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_create (OstreeRepo *self, - OstreeRepoMode mode, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_create (OstreeRepo *self, OstreeRepoMode mode, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -OstreeRepo * ostree_repo_create_at (int dfd, - const char *path, - OstreeRepoMode mode, - GVariant *options, - GCancellable *cancellable, - GError **error); +OstreeRepo *ostree_repo_create_at (int dfd, const char *path, OstreeRepoMode mode, + GVariant *options, GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -const gchar * ostree_repo_get_collection_id (OstreeRepo *self); +const gchar *ostree_repo_get_collection_id (OstreeRepo *self); _OSTREE_PUBLIC -gboolean ostree_repo_set_collection_id (OstreeRepo *self, - const gchar *collection_id, - GError **error); +gboolean ostree_repo_set_collection_id (OstreeRepo *self, const gchar *collection_id, + GError **error); _OSTREE_PUBLIC -const gchar * const * ostree_repo_get_default_repo_finders (OstreeRepo *self); +const gchar *const *ostree_repo_get_default_repo_finders (OstreeRepo *self); _OSTREE_PUBLIC -const gchar * ostree_repo_get_bootloader (OstreeRepo *self); +const gchar *ostree_repo_get_bootloader (OstreeRepo *self); _OSTREE_PUBLIC -GFile * ostree_repo_get_path (OstreeRepo *self); +GFile *ostree_repo_get_path (OstreeRepo *self); _OSTREE_PUBLIC -int ostree_repo_get_dfd (OstreeRepo *self); +int ostree_repo_get_dfd (OstreeRepo *self); _OSTREE_PUBLIC -guint ostree_repo_hash (OstreeRepo *self); +guint ostree_repo_hash (OstreeRepo *self); _OSTREE_PUBLIC -gboolean ostree_repo_equal (OstreeRepo *a, - OstreeRepo *b); +gboolean ostree_repo_equal (OstreeRepo *a, OstreeRepo *b); _OSTREE_PUBLIC -OstreeRepoMode ostree_repo_get_mode (OstreeRepo *self); +OstreeRepoMode ostree_repo_get_mode (OstreeRepo *self); _OSTREE_PUBLIC -gboolean ostree_repo_get_min_free_space_bytes (OstreeRepo *self, - guint64 *out_reserved_bytes, - GError **error); +gboolean ostree_repo_get_min_free_space_bytes (OstreeRepo *self, guint64 *out_reserved_bytes, + GError **error); _OSTREE_PUBLIC -GKeyFile * ostree_repo_get_config (OstreeRepo *self); +GKeyFile *ostree_repo_get_config (OstreeRepo *self); _OSTREE_PUBLIC -GKeyFile * ostree_repo_copy_config (OstreeRepo *self); +GKeyFile *ostree_repo_copy_config (OstreeRepo *self); _OSTREE_PUBLIC -gboolean ostree_repo_reload_config (OstreeRepo *self, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_reload_config (OstreeRepo *self, GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_remote_add (OstreeRepo *self, - const char *name, - const char *url, - GVariant *options, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_remote_add (OstreeRepo *self, const char *name, const char *url, + GVariant *options, GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_remote_delete (OstreeRepo *self, - const char *name, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_remote_delete (OstreeRepo *self, const char *name, GCancellable *cancellable, + GError **error); /** * OstreeRepoRemoteChange: @@ -167,10 +135,12 @@ gboolean ostree_repo_remote_delete (OstreeRepo *self, * @OSTREE_REPO_REMOTE_CHANGE_ADD: Add a remote * @OSTREE_REPO_REMOTE_CHANGE_ADD_IF_NOT_EXISTS: Like above, but do nothing if the remote exists * @OSTREE_REPO_REMOTE_CHANGE_DELETE: Delete a remote - * @OSTREE_REPO_REMOTE_CHANGE_DELETE_IF_EXISTS: Delete a remote, do nothing if the remote does not exist + * @OSTREE_REPO_REMOTE_CHANGE_DELETE_IF_EXISTS: Delete a remote, do nothing if the remote does not + * exist * @OSTREE_REPO_REMOTE_CHANGE_REPLACE: Add or replace a remote (Since: 2019.2) */ -typedef enum { +typedef enum +{ OSTREE_REPO_REMOTE_CHANGE_ADD, OSTREE_REPO_REMOTE_CHANGE_ADD_IF_NOT_EXISTS, OSTREE_REPO_REMOTE_CHANGE_DELETE, @@ -179,73 +149,49 @@ typedef enum { } OstreeRepoRemoteChange; _OSTREE_PUBLIC -gboolean ostree_repo_remote_change (OstreeRepo *self, - GFile *sysroot, - OstreeRepoRemoteChange changeop, - const char *name, - const char *url, - GVariant *options, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_remote_change (OstreeRepo *self, GFile *sysroot, + OstreeRepoRemoteChange changeop, const char *name, + const char *url, GVariant *options, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -char ** ostree_repo_remote_list (OstreeRepo *self, - guint *out_n_remotes); +char **ostree_repo_remote_list (OstreeRepo *self, guint *out_n_remotes); _OSTREE_PUBLIC -gboolean ostree_repo_remote_get_url (OstreeRepo *self, - const char *name, - char **out_url, - GError **error); +gboolean ostree_repo_remote_get_url (OstreeRepo *self, const char *name, char **out_url, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_get_remote_option (OstreeRepo *self, - const char *remote_name, - const char *option_name, - const char *default_value, - char **out_value, - GError **error); +gboolean ostree_repo_get_remote_option (OstreeRepo *self, const char *remote_name, + const char *option_name, const char *default_value, + char **out_value, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_get_remote_list_option (OstreeRepo *self, - const char *remote_name, - const char *option_name, - char ***out_value, - GError **error); +gboolean ostree_repo_get_remote_list_option (OstreeRepo *self, const char *remote_name, + const char *option_name, char ***out_value, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_get_remote_boolean_option (OstreeRepo *self, - const char *remote_name, - const char *option_name, - gboolean default_value, - gboolean *out_value, - GError **error); - +gboolean ostree_repo_get_remote_boolean_option (OstreeRepo *self, const char *remote_name, + const char *option_name, gboolean default_value, + gboolean *out_value, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_remote_fetch_summary (OstreeRepo *self, - const char *name, - GBytes **out_summary, - GBytes **out_signatures, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_remote_fetch_summary (OstreeRepo *self, const char *name, GBytes **out_summary, + GBytes **out_signatures, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, - const char *name, - GVariant *options, - GBytes **out_summary, - GBytes **out_signatures, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, const char *name, + GVariant *options, GBytes **out_summary, + GBytes **out_signatures, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -OstreeRepo * ostree_repo_get_parent (OstreeRepo *self); +OstreeRepo *ostree_repo_get_parent (OstreeRepo *self); _OSTREE_PUBLIC -gboolean ostree_repo_write_config (OstreeRepo *self, - GKeyFile *new_config, - GError **error); +gboolean ostree_repo_write_config (OstreeRepo *self, GKeyFile *new_config, GError **error); /** * OstreeRepoCommitState: @@ -261,7 +207,8 @@ gboolean ostree_repo_write_config (OstreeRepo *self, * * Since: 2015.7 */ -typedef enum { +typedef enum +{ OSTREE_REPO_COMMIT_STATE_NORMAL = 0, OSTREE_REPO_COMMIT_STATE_PARTIAL = (1 << 0), OSTREE_REPO_COMMIT_STATE_FSCK_PARTIAL = (1 << 1), @@ -289,7 +236,8 @@ typedef enum { */ typedef struct _OstreeRepoTransactionStats OstreeRepoTransactionStats; -struct _OstreeRepoTransactionStats { +struct _OstreeRepoTransactionStats +{ guint metadata_objects_total; guint metadata_objects_written; guint content_objects_total; @@ -297,7 +245,7 @@ struct _OstreeRepoTransactionStats { guint64 content_bytes_written; guint devino_cache_hits; - guint padding1; + guint padding1; guint64 padding2; guint64 padding3; guint64 padding4; @@ -307,232 +255,154 @@ _OSTREE_PUBLIC GType ostree_repo_transaction_stats_get_type (void); _OSTREE_PUBLIC -gboolean ostree_repo_scan_hardlinks (OstreeRepo *self, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_scan_hardlinks (OstreeRepo *self, GCancellable *cancellable, GError **error); + +_OSTREE_PUBLIC +gboolean ostree_repo_prepare_transaction (OstreeRepo *self, gboolean *out_transaction_resume, + GCancellable *cancellable, GError **error); + +_OSTREE_PUBLIC +gboolean ostree_repo_commit_transaction (OstreeRepo *self, OstreeRepoTransactionStats *out_stats, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_prepare_transaction (OstreeRepo *self, - gboolean *out_transaction_resume, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_abort_transaction (OstreeRepo *self, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_commit_transaction (OstreeRepo *self, - OstreeRepoTransactionStats *out_stats, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_mark_commit_partial (OstreeRepo *self, const char *checksum, + gboolean is_partial, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_abort_transaction (OstreeRepo *self, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_mark_commit_partial_reason (OstreeRepo *self, const char *checksum, + gboolean is_partial, + OstreeRepoCommitState in_state, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_mark_commit_partial (OstreeRepo *self, - const char *checksum, - gboolean is_partial, - GError **error); +void ostree_repo_transaction_set_refspec (OstreeRepo *self, const char *refspec, + const char *checksum); _OSTREE_PUBLIC -gboolean ostree_repo_mark_commit_partial_reason (OstreeRepo *self, - const char *checksum, - gboolean is_partial, - OstreeRepoCommitState in_state, - GError **error); +void ostree_repo_transaction_set_ref (OstreeRepo *self, const char *remote, const char *ref, + const char *checksum); _OSTREE_PUBLIC -void ostree_repo_transaction_set_refspec (OstreeRepo *self, - const char *refspec, - const char *checksum); +void ostree_repo_transaction_set_collection_ref (OstreeRepo *self, const OstreeCollectionRef *ref, + const char *checksum); _OSTREE_PUBLIC -void ostree_repo_transaction_set_ref (OstreeRepo *self, - const char *remote, - const char *ref, - const char *checksum); +gboolean ostree_repo_set_ref_immediate (OstreeRepo *self, const char *remote, const char *ref, + const char *checksum, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -void ostree_repo_transaction_set_collection_ref (OstreeRepo *self, - const OstreeCollectionRef *ref, - const char *checksum); +gboolean ostree_repo_set_alias_ref_immediate (OstreeRepo *self, const char *remote, const char *ref, + const char *target, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_set_ref_immediate (OstreeRepo *self, - const char *remote, - const char *ref, - const char *checksum, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_set_collection_ref_immediate (OstreeRepo *self, const OstreeCollectionRef *ref, + const char *checksum, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_set_alias_ref_immediate (OstreeRepo *self, - const char *remote, - const char *ref, - const char *target, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_has_object (OstreeRepo *self, OstreeObjectType objtype, const char *checksum, + gboolean *out_have_object, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_set_collection_ref_immediate (OstreeRepo *self, - const OstreeCollectionRef *ref, - const char *checksum, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_write_metadata (OstreeRepo *self, OstreeObjectType objtype, + const char *expected_checksum, GVariant *object, + guchar **out_csum, GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_has_object (OstreeRepo *self, - OstreeObjectType objtype, - const char *checksum, - gboolean *out_have_object, - GCancellable *cancellable, - GError **error); +void ostree_repo_write_metadata_async (OstreeRepo *self, OstreeObjectType objtype, + const char *expected_checksum, GVariant *object, + GCancellable *cancellable, GAsyncReadyCallback callback, + gpointer user_data); _OSTREE_PUBLIC -gboolean ostree_repo_write_metadata (OstreeRepo *self, - OstreeObjectType objtype, - const char *expected_checksum, - GVariant *object, - guchar **out_csum, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_write_metadata_finish (OstreeRepo *self, GAsyncResult *result, + guchar **out_csum, GError **error); _OSTREE_PUBLIC -void ostree_repo_write_metadata_async (OstreeRepo *self, - OstreeObjectType objtype, - const char *expected_checksum, - GVariant *object, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); +gboolean ostree_repo_write_content (OstreeRepo *self, const char *expected_checksum, + GInputStream *object_input, guint64 length, guchar **out_csum, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_write_metadata_finish (OstreeRepo *self, - GAsyncResult *result, - guchar **out_csum, - GError **error); +char *ostree_repo_write_regfile_inline (OstreeRepo *self, const char *expected_checksum, + guint32 uid, guint32 gid, guint32 mode, GVariant *xattrs, + const guint8 *buf, gsize len, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_write_content (OstreeRepo *self, - const char *expected_checksum, - GInputStream *object_input, - guint64 length, - guchar **out_csum, - GCancellable *cancellable, - GError **error); +OstreeContentWriter *ostree_repo_write_regfile (OstreeRepo *self, const char *expected_checksum, + guint32 uid, guint32 gid, guint32 mode, + guint64 content_len, GVariant *xattrs, + GError **error); _OSTREE_PUBLIC -char * ostree_repo_write_regfile_inline (OstreeRepo *self, - const char *expected_checksum, - guint32 uid, - guint32 gid, - guint32 mode, - GVariant *xattrs, - const guint8* buf, - gsize len, - GCancellable *cancellable, - GError **error); +char *ostree_repo_write_symlink (OstreeRepo *self, const char *expected_checksum, guint32 uid, + guint32 gid, GVariant *xattrs, const char *symlink_target, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -OstreeContentWriter * ostree_repo_write_regfile (OstreeRepo *self, - const char *expected_checksum, - guint32 uid, - guint32 gid, - guint32 mode, - guint64 content_len, - GVariant *xattrs, - GError **error); +gboolean ostree_repo_write_metadata_trusted (OstreeRepo *self, OstreeObjectType objtype, + const char *checksum, GVariant *variant, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -char * ostree_repo_write_symlink (OstreeRepo *self, - const char *expected_checksum, - guint32 uid, - guint32 gid, - GVariant *xattrs, - const char *symlink_target, - GCancellable *cancellable, - GError **error); - -_OSTREE_PUBLIC -gboolean ostree_repo_write_metadata_trusted (OstreeRepo *self, - OstreeObjectType objtype, - const char *checksum, - GVariant *variant, - GCancellable *cancellable, - GError **error); - -_OSTREE_PUBLIC -gboolean ostree_repo_write_metadata_stream_trusted (OstreeRepo *self, - OstreeObjectType objtype, - const char *checksum, - GInputStream *object_input, - guint64 length, - GCancellable *cancellable, - GError **error); - -_OSTREE_PUBLIC -gboolean ostree_repo_write_content_trusted (OstreeRepo *self, - const char *checksum, - GInputStream *object_input, - guint64 length, - GCancellable *cancellable, - GError **error); - -_OSTREE_PUBLIC -void ostree_repo_write_content_async (OstreeRepo *self, - const char *expected_checksum, - GInputStream *object, - guint64 length, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); - -_OSTREE_PUBLIC -gboolean ostree_repo_write_content_finish (OstreeRepo *self, - GAsyncResult *result, - guchar **out_csum, - GError **error); - -_OSTREE_PUBLIC -gboolean ostree_repo_resolve_rev (OstreeRepo *self, - const char *refspec, - gboolean allow_noent, - char **out_rev, - GError **error); +gboolean ostree_repo_write_metadata_stream_trusted (OstreeRepo *self, OstreeObjectType objtype, + const char *checksum, + GInputStream *object_input, guint64 length, + GCancellable *cancellable, GError **error); + +_OSTREE_PUBLIC +gboolean ostree_repo_write_content_trusted (OstreeRepo *self, const char *checksum, + GInputStream *object_input, guint64 length, + GCancellable *cancellable, GError **error); + +_OSTREE_PUBLIC +void ostree_repo_write_content_async (OstreeRepo *self, const char *expected_checksum, + GInputStream *object, guint64 length, + GCancellable *cancellable, GAsyncReadyCallback callback, + gpointer user_data); + +_OSTREE_PUBLIC +gboolean ostree_repo_write_content_finish (OstreeRepo *self, GAsyncResult *result, + guchar **out_csum, GError **error); + +_OSTREE_PUBLIC +gboolean ostree_repo_resolve_rev (OstreeRepo *self, const char *refspec, gboolean allow_noent, + char **out_rev, GError **error); /** * OstreeRepoResolveRevExtFlags: * @OSTREE_REPO_RESOLVE_REV_EXT_NONE: No flags. * @OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY: Exclude remote and mirrored refs. Since: 2019.2 */ -typedef enum { +typedef enum +{ OSTREE_REPO_RESOLVE_REV_EXT_NONE = 0, OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY = (1 << 0), } OstreeRepoResolveRevExtFlags; _OSTREE_PUBLIC -gboolean ostree_repo_resolve_rev_ext (OstreeRepo *self, - const char *refspec, - gboolean allow_noent, - OstreeRepoResolveRevExtFlags flags, - char **out_rev, - GError **error); +gboolean ostree_repo_resolve_rev_ext (OstreeRepo *self, const char *refspec, gboolean allow_noent, + OstreeRepoResolveRevExtFlags flags, char **out_rev, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_resolve_collection_ref (OstreeRepo *self, - const OstreeCollectionRef *ref, - gboolean allow_noent, - OstreeRepoResolveRevExtFlags flags, - char **out_rev, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_resolve_collection_ref (OstreeRepo *self, const OstreeCollectionRef *ref, + gboolean allow_noent, + OstreeRepoResolveRevExtFlags flags, char **out_rev, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_list_refs (OstreeRepo *self, - const char *refspec_prefix, - GHashTable **out_all_refs, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_list_refs (OstreeRepo *self, const char *refspec_prefix, + GHashTable **out_all_refs, GCancellable *cancellable, + GError **error); /** * OstreeRepoListRefsExtFlags: @@ -541,7 +411,8 @@ gboolean ostree_repo_list_refs (OstreeRepo *self, * @OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES: Exclude remote refs. Since: 2017.11 * @OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_MIRRORS: Exclude mirrored refs. Since: 2019.2 */ -typedef enum { +typedef enum +{ OSTREE_REPO_LIST_REFS_EXT_NONE = 0, OSTREE_REPO_LIST_REFS_EXT_ALIASES = (1 << 0), OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES = (1 << 1), @@ -549,110 +420,74 @@ typedef enum { } OstreeRepoListRefsExtFlags; _OSTREE_PUBLIC -gboolean ostree_repo_list_refs_ext (OstreeRepo *self, - const char *refspec_prefix, - GHashTable **out_all_refs, - OstreeRepoListRefsExtFlags flags, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_list_refs_ext (OstreeRepo *self, const char *refspec_prefix, + GHashTable **out_all_refs, OstreeRepoListRefsExtFlags flags, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_remote_list_refs (OstreeRepo *self, - const char *remote_name, - GHashTable **out_all_refs, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_remote_list_refs (OstreeRepo *self, const char *remote_name, + GHashTable **out_all_refs, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_remote_list_collection_refs (OstreeRepo *self, - const char *remote_name, - GHashTable **out_all_refs, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_remote_list_collection_refs (OstreeRepo *self, const char *remote_name, + GHashTable **out_all_refs, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_load_variant (OstreeRepo *self, - OstreeObjectType objtype, - const char *sha256, - GVariant **out_variant, - GError **error); +gboolean ostree_repo_load_variant (OstreeRepo *self, OstreeObjectType objtype, const char *sha256, + GVariant **out_variant, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_load_variant_if_exists (OstreeRepo *self, - OstreeObjectType objtype, - const char *sha256, - GVariant **out_variant, - GError **error); +gboolean ostree_repo_load_variant_if_exists (OstreeRepo *self, OstreeObjectType objtype, + const char *sha256, GVariant **out_variant, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_load_commit (OstreeRepo *self, - const char *checksum, - GVariant **out_commit, - OstreeRepoCommitState *out_state, - GError **error); +gboolean ostree_repo_load_commit (OstreeRepo *self, const char *checksum, GVariant **out_commit, + OstreeRepoCommitState *out_state, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_load_file (OstreeRepo *self, - const char *checksum, - GInputStream **out_input, - GFileInfo **out_file_info, - GVariant **out_xattrs, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_load_file (OstreeRepo *self, const char *checksum, GInputStream **out_input, + GFileInfo **out_file_info, GVariant **out_xattrs, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_load_object_stream (OstreeRepo *self, - OstreeObjectType objtype, - const char *checksum, - GInputStream **out_input, - guint64 *out_size, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_load_object_stream (OstreeRepo *self, OstreeObjectType objtype, + const char *checksum, GInputStream **out_input, + guint64 *out_size, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_query_object_storage_size (OstreeRepo *self, - OstreeObjectType objtype, - const char *sha256, - guint64 *out_size, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_query_object_storage_size (OstreeRepo *self, OstreeObjectType objtype, + const char *sha256, guint64 *out_size, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_import_object_from (OstreeRepo *self, - OstreeRepo *source, - OstreeObjectType objtype, - const char *checksum, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_import_object_from (OstreeRepo *self, OstreeRepo *source, + OstreeObjectType objtype, const char *checksum, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_import_object_from_with_trust (OstreeRepo *self, - OstreeRepo *source, - OstreeObjectType objtype, - const char *checksum, - gboolean trusted, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_import_object_from_with_trust (OstreeRepo *self, OstreeRepo *source, + OstreeObjectType objtype, const char *checksum, + gboolean trusted, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_delete_object (OstreeRepo *self, - OstreeObjectType objtype, - const char *sha256, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_delete_object (OstreeRepo *self, OstreeObjectType objtype, const char *sha256, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_fsck_object (OstreeRepo *self, - OstreeObjectType objtype, - const char *sha256, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_fsck_object (OstreeRepo *self, OstreeObjectType objtype, const char *sha256, + GCancellable *cancellable, GError **error); /** * OstreeRepoCommitFilterResult: * @OSTREE_REPO_COMMIT_FILTER_ALLOW: Do commit this object * @OSTREE_REPO_COMMIT_FILTER_SKIP: Ignore this object */ -typedef enum { +typedef enum +{ OSTREE_REPO_COMMIT_FILTER_ALLOW, OSTREE_REPO_COMMIT_FILTER_SKIP } OstreeRepoCommitFilterResult; @@ -666,10 +501,9 @@ typedef enum { * * Returns: #OstreeRepoCommitFilterResult saying whether or not to commit this file */ -typedef OstreeRepoCommitFilterResult (*OstreeRepoCommitFilter) (OstreeRepo *repo, - const char *path, - GFileInfo *file_info, - gpointer user_data); +typedef OstreeRepoCommitFilterResult (*OstreeRepoCommitFilter) (OstreeRepo *repo, const char *path, + GFileInfo *file_info, + gpointer user_data); /** * OstreeRepoCommitModifierFlags: @@ -677,15 +511,20 @@ typedef OstreeRepoCommitFilterResult (*OstreeRepoCommitFilter) (OstreeRepo *r * @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS: Do not process extended attributes * @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES: Generate size information. * @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS: Canonicalize permissions. - * @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_ERROR_ON_UNLABELED: Emit an error if configured SELinux policy does not provide a label - * @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CONSUME: Delete added files/directories after commit; Since: 2017.13 - * @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_DEVINO_CANONICAL: If a devino cache hit is found, skip modifier filters (non-directories only); Since: 2017.14 + * @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_ERROR_ON_UNLABELED: Emit an error if configured SELinux + * policy does not provide a label + * @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CONSUME: Delete added files/directories after commit; Since: + * 2017.13 + * @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_DEVINO_CANONICAL: If a devino cache hit is found, skip + * modifier filters (non-directories only); Since: 2017.14 * - * Flags modifying commit behavior. In bare-user-only mode, @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS - * and @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS are automatically enabled. + * Flags modifying commit behavior. In bare-user-only mode, + * @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS and + * @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS are automatically enabled. * */ -typedef enum { +typedef enum +{ OSTREE_REPO_COMMIT_MODIFIER_FLAGS_NONE = 0, OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS = (1 << 0), OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES = (1 << 1), @@ -703,39 +542,36 @@ typedef enum { typedef struct OstreeRepoCommitModifier OstreeRepoCommitModifier; _OSTREE_PUBLIC -OstreeRepoCommitModifier *ostree_repo_commit_modifier_new (OstreeRepoCommitModifierFlags flags, - OstreeRepoCommitFilter commit_filter, - gpointer user_data, - GDestroyNotify destroy_notify); +OstreeRepoCommitModifier *ostree_repo_commit_modifier_new (OstreeRepoCommitModifierFlags flags, + OstreeRepoCommitFilter commit_filter, + gpointer user_data, + GDestroyNotify destroy_notify); _OSTREE_PUBLIC GType ostree_repo_commit_modifier_get_type (void); -typedef GVariant *(*OstreeRepoCommitModifierXattrCallback) (OstreeRepo *repo, - const char *path, - GFileInfo *file_info, - gpointer user_data); +typedef GVariant *(*OstreeRepoCommitModifierXattrCallback) (OstreeRepo *repo, const char *path, + GFileInfo *file_info, + gpointer user_data); _OSTREE_PUBLIC -void ostree_repo_commit_modifier_set_xattr_callback (OstreeRepoCommitModifier *modifier, - OstreeRepoCommitModifierXattrCallback callback, - GDestroyNotify destroy, - gpointer user_data); +void ostree_repo_commit_modifier_set_xattr_callback (OstreeRepoCommitModifier *modifier, + OstreeRepoCommitModifierXattrCallback callback, + GDestroyNotify destroy, gpointer user_data); _OSTREE_PUBLIC -void ostree_repo_commit_modifier_set_sepolicy (OstreeRepoCommitModifier *modifier, - OstreeSePolicy *sepolicy); +void ostree_repo_commit_modifier_set_sepolicy (OstreeRepoCommitModifier *modifier, + OstreeSePolicy *sepolicy); _OSTREE_PUBLIC -gboolean ostree_repo_commit_modifier_set_sepolicy_from_commit (OstreeRepoCommitModifier *modifier, - OstreeRepo *repo, - const char *rev, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_commit_modifier_set_sepolicy_from_commit (OstreeRepoCommitModifier *modifier, + OstreeRepo *repo, const char *rev, + GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -void ostree_repo_commit_modifier_set_devino_cache (OstreeRepoCommitModifier *modifier, - OstreeRepoDevInoCache *cache); +void ostree_repo_commit_modifier_set_devino_cache (OstreeRepoCommitModifier *modifier, + OstreeRepoDevInoCache *cache); _OSTREE_PUBLIC OstreeRepoCommitModifier *ostree_repo_commit_modifier_ref (OstreeRepoCommitModifier *modifier); @@ -743,41 +579,30 @@ _OSTREE_PUBLIC void ostree_repo_commit_modifier_unref (OstreeRepoCommitModifier *modifier); _OSTREE_PUBLIC -gboolean ostree_repo_write_directory_to_mtree (OstreeRepo *self, - GFile *dir, - OstreeMutableTree *mtree, - OstreeRepoCommitModifier *modifier, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_write_directory_to_mtree (OstreeRepo *self, GFile *dir, + OstreeMutableTree *mtree, + OstreeRepoCommitModifier *modifier, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_write_dfd_to_mtree (OstreeRepo *self, - int dfd, - const char *path, - OstreeMutableTree *mtree, - OstreeRepoCommitModifier *modifier, - GCancellable *cancellable, - GError **error); - +gboolean ostree_repo_write_dfd_to_mtree (OstreeRepo *self, int dfd, const char *path, + OstreeMutableTree *mtree, + OstreeRepoCommitModifier *modifier, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_write_archive_to_mtree (OstreeRepo *self, - GFile *archive, - OstreeMutableTree *mtree, - OstreeRepoCommitModifier *modifier, - gboolean autocreate_parents, - GCancellable *cancellable, - GError **error); - +gboolean ostree_repo_write_archive_to_mtree (OstreeRepo *self, GFile *archive, + OstreeMutableTree *mtree, + OstreeRepoCommitModifier *modifier, + gboolean autocreate_parents, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_write_archive_to_mtree_from_fd (OstreeRepo *self, - int fd, - OstreeMutableTree *mtree, - OstreeRepoCommitModifier *modifier, - gboolean autocreate_parents, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_write_archive_to_mtree_from_fd (OstreeRepo *self, int fd, + OstreeMutableTree *mtree, + OstreeRepoCommitModifier *modifier, + gboolean autocreate_parents, + GCancellable *cancellable, GError **error); /** * OstreeRepoImportArchiveTranslatePathname: @@ -799,10 +624,10 @@ gboolean ostree_repo_write_archive_to_mtree_from_fd (OstreeRepo * * Since: 2017.11 */ -typedef char *(*OstreeRepoImportArchiveTranslatePathname) (OstreeRepo *repo, +typedef char *(*OstreeRepoImportArchiveTranslatePathname) (OstreeRepo *repo, const struct stat *stbuf, - const char *src_path, - gpointer user_data); + const char *src_path, + gpointer user_data); /** * OstreeRepoImportArchiveOptions: (skip) @@ -811,7 +636,8 @@ typedef char *(*OstreeRepoImportArchiveTranslatePathname) (OstreeRepo *repo, * you have entirely zeroed the structure, then set just the desired * options. This is used by ostree_repo_import_archive_to_mtree(). */ -typedef struct { +typedef struct +{ guint ignore_unsupported_content : 1; guint autocreate_parents : 1; guint use_ostree_convention : 1; @@ -825,13 +651,12 @@ typedef struct { } OstreeRepoImportArchiveOptions; _OSTREE_PUBLIC -gboolean ostree_repo_import_archive_to_mtree (OstreeRepo *self, - OstreeRepoImportArchiveOptions *opts, - void *archive, /* Really struct archive * */ - OstreeMutableTree *mtree, - OstreeRepoCommitModifier *modifier, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_import_archive_to_mtree (OstreeRepo *self, + OstreeRepoImportArchiveOptions *opts, + void *archive, /* Really struct archive * */ + OstreeMutableTree *mtree, + OstreeRepoCommitModifier *modifier, + GCancellable *cancellable, GError **error); /** * OstreeRepoExportArchiveOptions: (skip) @@ -840,7 +665,8 @@ gboolean ostree_repo_import_archive_to_mtree (OstreeRepo * you have entirely zeroed the structure, then set just the desired * options. This is used by ostree_repo_export_tree_to_archive(). */ -typedef struct { +typedef struct +{ guint disable_xattrs : 1; guint reserved : 31; @@ -855,63 +681,44 @@ typedef struct { } OstreeRepoExportArchiveOptions; _OSTREE_PUBLIC -gboolean ostree_repo_export_tree_to_archive (OstreeRepo *self, - OstreeRepoExportArchiveOptions *opts, - OstreeRepoFile *root, - void *archive, /* Really struct archive * */ - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_export_tree_to_archive (OstreeRepo *self, OstreeRepoExportArchiveOptions *opts, + OstreeRepoFile *root, + void *archive, /* Really struct archive * */ + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_write_mtree (OstreeRepo *self, - OstreeMutableTree *mtree, - GFile **out_file, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_write_mtree (OstreeRepo *self, OstreeMutableTree *mtree, GFile **out_file, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_write_commit (OstreeRepo *self, - const char *parent, - const char *subject, - const char *body, - GVariant *metadata, - OstreeRepoFile *root, - char **out_commit, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_write_commit (OstreeRepo *self, const char *parent, const char *subject, + const char *body, GVariant *metadata, OstreeRepoFile *root, + char **out_commit, GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_write_commit_with_time (OstreeRepo *self, - const char *parent, - const char *subject, - const char *body, - GVariant *metadata, - OstreeRepoFile *root, - guint64 time, - char **out_commit, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_write_commit_with_time (OstreeRepo *self, const char *parent, + const char *subject, const char *body, + GVariant *metadata, OstreeRepoFile *root, guint64 time, + char **out_commit, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_read_commit_detached_metadata (OstreeRepo *self, - const char *checksum, - GVariant **out_metadata, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_read_commit_detached_metadata (OstreeRepo *self, const char *checksum, + GVariant **out_metadata, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_write_commit_detached_metadata (OstreeRepo *self, - const char *checksum, - GVariant *metadata, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_write_commit_detached_metadata (OstreeRepo *self, const char *checksum, + GVariant *metadata, GCancellable *cancellable, + GError **error); /** * OstreeRepoCheckoutMode: * @OSTREE_REPO_CHECKOUT_MODE_NONE: No special options * @OSTREE_REPO_CHECKOUT_MODE_USER: Ignore uid/gid of files */ -typedef enum { +typedef enum +{ OSTREE_REPO_CHECKOUT_MODE_NONE = 0, OSTREE_REPO_CHECKOUT_MODE_USER = 1 } OstreeRepoCheckoutMode; @@ -919,27 +726,27 @@ typedef enum { /** * OstreeRepoCheckoutOverwriteMode: * @OSTREE_REPO_CHECKOUT_OVERWRITE_NONE: No special options - * @OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_FILES: When layering checkouts, unlink() and replace existing files, but do not modify existing directories (unless whiteouts are enabled, then directories are replaced) + * @OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_FILES: When layering checkouts, unlink() and replace + * existing files, but do not modify existing directories (unless whiteouts are enabled, then + * directories are replaced) * @OSTREE_REPO_CHECKOUT_OVERWRITE_ADD_FILES: Only add new files/directories - * @OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_IDENTICAL: Like UNION_FILES, but error if files are not identical (requires hardlink checkouts) + * @OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_IDENTICAL: Like UNION_FILES, but error if files are not + * identical (requires hardlink checkouts) */ -typedef enum { +typedef enum +{ OSTREE_REPO_CHECKOUT_OVERWRITE_NONE = 0, OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_FILES = 1, - OSTREE_REPO_CHECKOUT_OVERWRITE_ADD_FILES = 2, /* Since: 2017.3 */ + OSTREE_REPO_CHECKOUT_OVERWRITE_ADD_FILES = 2, /* Since: 2017.3 */ OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_IDENTICAL = 3, /* Since: 2017.11 */ } OstreeRepoCheckoutOverwriteMode; _OSTREE_PUBLIC -gboolean -ostree_repo_checkout_tree (OstreeRepo *self, - OstreeRepoCheckoutMode mode, - OstreeRepoCheckoutOverwriteMode overwrite_mode, - GFile *destination, - OstreeRepoFile *source, - GFileInfo *source_info, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_checkout_tree (OstreeRepo *self, OstreeRepoCheckoutMode mode, + OstreeRepoCheckoutOverwriteMode overwrite_mode, + GFile *destination, OstreeRepoFile *source, + GFileInfo *source_info, GCancellable *cancellable, + GError **error); /** * OstreeRepoCheckoutFilterResult: @@ -948,7 +755,8 @@ ostree_repo_checkout_tree (OstreeRepo *self, * * Since: 2018.2 */ -typedef enum { +typedef enum +{ OSTREE_REPO_CHECKOUT_FILTER_ALLOW, OSTREE_REPO_CHECKOUT_FILTER_SKIP } OstreeRepoCheckoutFilterResult; @@ -964,10 +772,10 @@ typedef enum { * * Since: 2018.2 */ -typedef OstreeRepoCheckoutFilterResult (*OstreeRepoCheckoutFilter) (OstreeRepo *repo, - const char *path, - struct stat *stbuf, - gpointer user_data); +typedef OstreeRepoCheckoutFilterResult (*OstreeRepoCheckoutFilter) (OstreeRepo *repo, + const char *path, + struct stat *stbuf, + gpointer user_data); /** * OstreeRepoCheckoutAtOptions: @@ -978,16 +786,17 @@ typedef OstreeRepoCheckoutFilterResult (*OstreeRepoCheckoutFilter) (OstreeRepo * supercedes previous separate enumeration usage in * ostree_repo_checkout_tree() and ostree_repo_checkout_tree_at(). */ -typedef struct { +typedef struct +{ OstreeRepoCheckoutMode mode; OstreeRepoCheckoutOverwriteMode overwrite_mode; - gboolean enable_uncompressed_cache; /* Deprecated */ - gboolean enable_fsync; /* Deprecated */ + gboolean enable_uncompressed_cache; /* Deprecated */ + gboolean enable_fsync; /* Deprecated */ gboolean process_whiteouts; gboolean no_copy_fallback; - gboolean force_copy; /* Since: 2017.6 */ - gboolean bareuseronly_dirs; /* Since: 2017.7 */ + gboolean force_copy; /* Since: 2017.6 */ + gboolean bareuseronly_dirs; /* Since: 2017.7 */ gboolean force_copy_zerosized; /* Since: 2018.9 */ gboolean process_passthrough_whiteouts; gboolean unused_bools[3]; @@ -1000,8 +809,8 @@ typedef struct { int unused_ints[6]; gpointer unused_ptrs[3]; OstreeRepoCheckoutFilter filter; /* Since: 2018.2 */ - gpointer filter_user_data; /* Since: 2018.2 */ - OstreeSePolicy *sepolicy; /* Since: 2017.6 */ + gpointer filter_user_data; /* Since: 2018.2 */ + OstreeSePolicy *sepolicy; /* Since: 2017.6 */ const char *sepolicy_prefix; } OstreeRepoCheckoutAtOptions; @@ -1010,34 +819,25 @@ GType ostree_repo_devino_cache_get_type (void); _OSTREE_PUBLIC OstreeRepoDevInoCache *ostree_repo_devino_cache_new (void); _OSTREE_PUBLIC -OstreeRepoDevInoCache * ostree_repo_devino_cache_ref (OstreeRepoDevInoCache *cache); +OstreeRepoDevInoCache *ostree_repo_devino_cache_ref (OstreeRepoDevInoCache *cache); _OSTREE_PUBLIC void ostree_repo_devino_cache_unref (OstreeRepoDevInoCache *cache); _OSTREE_PUBLIC -void ostree_repo_checkout_at_options_set_devino (OstreeRepoCheckoutAtOptions *opts, OstreeRepoDevInoCache *cache); +void ostree_repo_checkout_at_options_set_devino (OstreeRepoCheckoutAtOptions *opts, + OstreeRepoDevInoCache *cache); _OSTREE_PUBLIC -gboolean ostree_repo_checkout_at (OstreeRepo *self, - OstreeRepoCheckoutAtOptions *options, - int destination_dfd, - const char *destination_path, - const char *commit, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_checkout_at (OstreeRepo *self, OstreeRepoCheckoutAtOptions *options, + int destination_dfd, const char *destination_path, + const char *commit, GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_checkout_gc (OstreeRepo *self, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_checkout_gc (OstreeRepo *self, GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_read_commit (OstreeRepo *self, - const char *ref, - GFile **out_root, - char **out_commit, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_read_commit (OstreeRepo *self, const char *ref, GFile **out_root, + char **out_commit, GCancellable *cancellable, GError **error); /** * OstreeRepoListObjectsFlags: @@ -1046,7 +846,8 @@ gboolean ostree_repo_read_commit (OstreeRepo *self, * @OSTREE_REPO_LIST_OBJECTS_ALL: List all objects * @OSTREE_REPO_LIST_OBJECTS_NO_PARENTS: Only list objects in this repo, not parents */ -typedef enum { +typedef enum +{ OSTREE_REPO_LIST_OBJECTS_LOOSE = (1 << 0), OSTREE_REPO_LIST_OBJECTS_PACKED = (1 << 1), OSTREE_REPO_LIST_OBJECTS_ALL = (1 << 2), @@ -1062,30 +863,22 @@ typedef enum { #define OSTREE_REPO_LIST_OBJECTS_VARIANT_TYPE (G_VARIANT_TYPE ("(bas)") _OSTREE_PUBLIC -gboolean ostree_repo_list_objects (OstreeRepo *self, - OstreeRepoListObjectsFlags flags, - GHashTable **out_objects, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_list_objects (OstreeRepo *self, OstreeRepoListObjectsFlags flags, + GHashTable **out_objects, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_list_commit_objects_starting_with ( OstreeRepo *self, - const char *start, - GHashTable **out_commits, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_list_commit_objects_starting_with (OstreeRepo *self, const char *start, + GHashTable **out_commits, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_list_static_delta_names (OstreeRepo *self, - GPtrArray **out_deltas, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_list_static_delta_names (OstreeRepo *self, GPtrArray **out_deltas, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_list_static_delta_indexes (OstreeRepo *self, - GPtrArray **out_indexes, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_list_static_delta_indexes (OstreeRepo *self, GPtrArray **out_indexes, + GCancellable *cancellable, GError **error); /** * OstreeStaticDeltaGenerateOpt: @@ -1094,20 +887,17 @@ gboolean ostree_repo_list_static_delta_indexes (OstreeRepo *sel * * Parameters controlling optimization of static deltas. */ -typedef enum { +typedef enum +{ OSTREE_STATIC_DELTA_GENERATE_OPT_LOWLATENCY, OSTREE_STATIC_DELTA_GENERATE_OPT_MAJOR } OstreeStaticDeltaGenerateOpt; _OSTREE_PUBLIC -gboolean ostree_repo_static_delta_generate (OstreeRepo *self, - OstreeStaticDeltaGenerateOpt opt, - const char *from, - const char *to, - GVariant *metadata, - GVariant *params, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_static_delta_generate (OstreeRepo *self, OstreeStaticDeltaGenerateOpt opt, + const char *from, const char *to, GVariant *metadata, + GVariant *params, GCancellable *cancellable, + GError **error); /** * OstreeStaticDeltaIndexFlags: @@ -1115,48 +905,43 @@ gboolean ostree_repo_static_delta_generate (OstreeRepo *self, * * Flags controlling static delta index generation. */ -typedef enum { +typedef enum +{ OSTREE_STATIC_DELTA_INDEX_FLAGS_NONE = 0, } OstreeStaticDeltaIndexFlags; /** * OstreeRepoCommitTraverseFlags: * @OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE: No special options for traverse - * @OSTREE_REPO_COMMIT_TRAVERSE_FLAG_COMMIT_ONLY: Traverse and retrieve only commit objects. (Since: 2022.2) + * @OSTREE_REPO_COMMIT_TRAVERSE_FLAG_COMMIT_ONLY: Traverse and retrieve only commit objects. + * (Since: 2022.2) */ -typedef enum { +typedef enum +{ OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE = (1 << 0), OSTREE_REPO_COMMIT_TRAVERSE_FLAG_COMMIT_ONLY = (1 << 1), } OstreeRepoCommitTraverseFlags; _OSTREE_PUBLIC -gboolean ostree_repo_static_delta_reindex (OstreeRepo *repo, - OstreeStaticDeltaIndexFlags flags, - const char *opt_to_commit, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_static_delta_reindex (OstreeRepo *repo, OstreeStaticDeltaIndexFlags flags, + const char *opt_to_commit, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_static_delta_execute_offline_with_signature (OstreeRepo *self, - GFile *dir_or_file, - OstreeSign *sign, - gboolean skip_validation, - GCancellable *cancellable, - GError **error); +gboolean +ostree_repo_static_delta_execute_offline_with_signature (OstreeRepo *self, GFile *dir_or_file, + OstreeSign *sign, gboolean skip_validation, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_static_delta_execute_offline (OstreeRepo *self, - GFile *dir_or_file, - gboolean skip_validation, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_static_delta_execute_offline (OstreeRepo *self, GFile *dir_or_file, + gboolean skip_validation, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_static_delta_verify_signature (OstreeRepo *self, - const char *delta_id, - OstreeSign *sign, - char **out_success_message, - GError **error); +gboolean ostree_repo_static_delta_verify_signature (OstreeRepo *self, const char *delta_id, + OstreeSign *sign, char **out_success_message, + GError **error); _OSTREE_PUBLIC GHashTable *ostree_repo_traverse_new_reachable (void); @@ -1165,69 +950,57 @@ _OSTREE_PUBLIC GHashTable *ostree_repo_traverse_new_parents (void); _OSTREE_PUBLIC -char ** ostree_repo_traverse_parents_get_commits (GHashTable *parents, GVariant *object); +char **ostree_repo_traverse_parents_get_commits (GHashTable *parents, GVariant *object); _OSTREE_PUBLIC -gboolean ostree_repo_traverse_commit (OstreeRepo *repo, - const char *commit_checksum, - int maxdepth, - GHashTable **out_reachable, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_traverse_commit (OstreeRepo *repo, const char *commit_checksum, int maxdepth, + GHashTable **out_reachable, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_traverse_commit_union (OstreeRepo *repo, - const char *commit_checksum, - int maxdepth, - GHashTable *inout_reachable, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_traverse_commit_union (OstreeRepo *repo, const char *commit_checksum, + int maxdepth, GHashTable *inout_reachable, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_traverse_commit_union_with_parents (OstreeRepo *repo, - const char *commit_checksum, - int maxdepth, - GHashTable *inout_reachable, - GHashTable *inout_parents, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_traverse_commit_union_with_parents (OstreeRepo *repo, + const char *commit_checksum, int maxdepth, + GHashTable *inout_reachable, + GHashTable *inout_parents, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_traverse_commit_with_flags (OstreeRepo *repo, - OstreeRepoCommitTraverseFlags flags, - const char *commit_checksum, - int maxdepth, - GHashTable *inout_reachable, - GHashTable *inout_parents, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_traverse_commit_with_flags (OstreeRepo *repo, + OstreeRepoCommitTraverseFlags flags, + const char *commit_checksum, int maxdepth, + GHashTable *inout_reachable, + GHashTable *inout_parents, + GCancellable *cancellable, GError **error); -struct _OstreeRepoCommitTraverseIter { +struct _OstreeRepoCommitTraverseIter +{ gboolean initialized; /* 4 byte hole on 64 bit */ gpointer dummy[10]; - char dummy_checksum_data[(OSTREE_SHA256_STRING_LEN+1)*2]; + char dummy_checksum_data[(OSTREE_SHA256_STRING_LEN + 1) * 2]; }; typedef struct _OstreeRepoCommitTraverseIter OstreeRepoCommitTraverseIter; _OSTREE_PUBLIC -gboolean -ostree_repo_commit_traverse_iter_init_commit (OstreeRepoCommitTraverseIter *iter, - OstreeRepo *repo, - GVariant *commit, - OstreeRepoCommitTraverseFlags flags, - GError **error); +gboolean ostree_repo_commit_traverse_iter_init_commit (OstreeRepoCommitTraverseIter *iter, + OstreeRepo *repo, GVariant *commit, + OstreeRepoCommitTraverseFlags flags, + GError **error); _OSTREE_PUBLIC -gboolean -ostree_repo_commit_traverse_iter_init_dirtree (OstreeRepoCommitTraverseIter *iter, - OstreeRepo *repo, - GVariant *dirtree, - OstreeRepoCommitTraverseFlags flags, - GError **error); +gboolean ostree_repo_commit_traverse_iter_init_dirtree (OstreeRepoCommitTraverseIter *iter, + OstreeRepo *repo, GVariant *dirtree, + OstreeRepoCommitTraverseFlags flags, + GError **error); -typedef enum { +typedef enum +{ OSTREE_REPO_COMMIT_ITER_RESULT_ERROR, OSTREE_REPO_COMMIT_ITER_RESULT_END, OSTREE_REPO_COMMIT_ITER_RESULT_FILE, @@ -1235,20 +1008,18 @@ typedef enum { } OstreeRepoCommitIterResult; _OSTREE_PUBLIC -OstreeRepoCommitIterResult ostree_repo_commit_traverse_iter_next (OstreeRepoCommitTraverseIter *iter, - GCancellable *cancellable, - GError **error); +OstreeRepoCommitIterResult +ostree_repo_commit_traverse_iter_next (OstreeRepoCommitTraverseIter *iter, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -void ostree_repo_commit_traverse_iter_get_file (OstreeRepoCommitTraverseIter *iter, - char **out_name, - char **out_checksum); +void ostree_repo_commit_traverse_iter_get_file (OstreeRepoCommitTraverseIter *iter, char **out_name, + char **out_checksum); _OSTREE_PUBLIC -void ostree_repo_commit_traverse_iter_get_dir (OstreeRepoCommitTraverseIter *iter, - char **out_name, - char **out_content_checksum, - char **out_meta_checksum); +void ostree_repo_commit_traverse_iter_get_dir (OstreeRepoCommitTraverseIter *iter, char **out_name, + char **out_content_checksum, + char **out_meta_checksum); _OSTREE_PUBLIC void ostree_repo_commit_traverse_iter_clear (OstreeRepoCommitTraverseIter *iter); @@ -1256,16 +1027,19 @@ void ostree_repo_commit_traverse_iter_clear (OstreeRepoCommitTraverseIter *iter) _OSTREE_PUBLIC void ostree_repo_commit_traverse_iter_cleanup (void *p); -#define ostree_cleanup_repo_commit_traverse_iter __attribute__ ((cleanup(ostree_repo_commit_traverse_iter_cleanup))) +#define ostree_cleanup_repo_commit_traverse_iter \ + __attribute__ ((cleanup (ostree_repo_commit_traverse_iter_cleanup))) /** * OstreeRepoPruneFlags: * @OSTREE_REPO_PRUNE_FLAGS_NONE: No special options for pruning * @OSTREE_REPO_PRUNE_FLAGS_NO_PRUNE: Don't actually delete objects - * @OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY: Do not traverse individual commit objects, only follow refs for reachability calculations + * @OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY: Do not traverse individual commit objects, only follow refs + * for reachability calculations * @OSTREE_REPO_PRUNE_FLAGS_COMMIT_ONLY: Only traverse commit objects. (Since 2022.2) */ -typedef enum { +typedef enum +{ OSTREE_REPO_PRUNE_FLAGS_NONE = 0, OSTREE_REPO_PRUNE_FLAGS_NO_PRUNE = (1 << 0), OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY = (1 << 1), @@ -1273,22 +1047,17 @@ typedef enum { } OstreeRepoPruneFlags; _OSTREE_PUBLIC -gboolean -ostree_repo_prune_static_deltas (OstreeRepo *self, const char *commit, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_prune_static_deltas (OstreeRepo *self, const char *commit, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_prune (OstreeRepo *self, - OstreeRepoPruneFlags flags, - gint depth, - gint *out_objects_total, - gint *out_objects_pruned, - guint64 *out_pruned_object_size_total, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_prune (OstreeRepo *self, OstreeRepoPruneFlags flags, gint depth, + gint *out_objects_total, gint *out_objects_pruned, + guint64 *out_pruned_object_size_total, GCancellable *cancellable, + GError **error); -struct _OstreeRepoPruneOptions { +struct _OstreeRepoPruneOptions +{ OstreeRepoPruneFlags flags; /* 4 byte hole on 64 bit */ @@ -1303,32 +1072,30 @@ struct _OstreeRepoPruneOptions { typedef struct _OstreeRepoPruneOptions OstreeRepoPruneOptions; _OSTREE_PUBLIC -gboolean -ostree_repo_traverse_reachable_refs (OstreeRepo *self, - guint depth, - GHashTable *reachable, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_traverse_reachable_refs (OstreeRepo *self, guint depth, GHashTable *reachable, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_prune_from_reachable (OstreeRepo *self, - OstreeRepoPruneOptions *options, - gint *out_objects_total, - gint *out_objects_pruned, - guint64 *out_pruned_object_size_total, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_prune_from_reachable (OstreeRepo *self, OstreeRepoPruneOptions *options, + gint *out_objects_total, gint *out_objects_pruned, + guint64 *out_pruned_object_size_total, + GCancellable *cancellable, GError **error); /** * OstreeRepoPullFlags: * @OSTREE_REPO_PULL_FLAGS_NONE: No special options for pull - * @OSTREE_REPO_PULL_FLAGS_MIRROR: Write out refs suitable for mirrors and fetch all refs if none requested + * @OSTREE_REPO_PULL_FLAGS_MIRROR: Write out refs suitable for mirrors and fetch all refs if none + * requested * @OSTREE_REPO_PULL_FLAGS_COMMIT_ONLY: Fetch only the commit metadata - * @OSTREE_REPO_PULL_FLAGS_UNTRUSTED: Do verify checksums of local (filesystem-accessible) repositories (defaults on for HTTP) - * @OSTREE_REPO_PULL_FLAGS_BAREUSERONLY_FILES: Since 2017.7. Reject writes of content objects with modes outside of 0775. - * @OSTREE_REPO_PULL_FLAGS_TRUSTED_HTTP: Don't verify checksums of objects HTTP repositories (Since: 2017.12) + * @OSTREE_REPO_PULL_FLAGS_UNTRUSTED: Do verify checksums of local (filesystem-accessible) + * repositories (defaults on for HTTP) + * @OSTREE_REPO_PULL_FLAGS_BAREUSERONLY_FILES: Since 2017.7. Reject writes of content objects with + * modes outside of 0775. + * @OSTREE_REPO_PULL_FLAGS_TRUSTED_HTTP: Don't verify checksums of objects HTTP repositories + * (Since: 2017.12) */ -typedef enum { +typedef enum +{ OSTREE_REPO_PULL_FLAGS_NONE, OSTREE_REPO_PULL_FLAGS_MIRROR = (1 << 0), OSTREE_REPO_PULL_FLAGS_COMMIT_ONLY = (1 << 1), @@ -1338,115 +1105,79 @@ typedef enum { } OstreeRepoPullFlags; _OSTREE_PUBLIC -gboolean ostree_repo_pull (OstreeRepo *self, - const char *remote_name, - char **refs_to_fetch, - OstreeRepoPullFlags flags, - OstreeAsyncProgress *progress, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_pull (OstreeRepo *self, const char *remote_name, char **refs_to_fetch, + OstreeRepoPullFlags flags, OstreeAsyncProgress *progress, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean -ostree_repo_pull_one_dir (OstreeRepo *self, - const char *remote_name, - const char *dir_to_pull, - char **refs_to_fetch, - OstreeRepoPullFlags flags, - OstreeAsyncProgress *progress, - GCancellable *cancellable, - GError **error); - -_OSTREE_PUBLIC -gboolean ostree_repo_pull_with_options (OstreeRepo *self, - const char *remote_name_or_baseurl, - GVariant *options, - OstreeAsyncProgress *progress, - GCancellable *cancellable, - GError **error); - -_OSTREE_PUBLIC -void ostree_repo_find_remotes_async (OstreeRepo *self, - const OstreeCollectionRef * const *refs, - GVariant *options, - OstreeRepoFinder **finders, - OstreeAsyncProgress *progress, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -_OSTREE_PUBLIC -OstreeRepoFinderResult **ostree_repo_find_remotes_finish (OstreeRepo *self, - GAsyncResult *result, - GError **error); - -_OSTREE_PUBLIC -void ostree_repo_pull_from_remotes_async (OstreeRepo *self, - const OstreeRepoFinderResult * const *results, - GVariant *options, - OstreeAsyncProgress *progress, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -_OSTREE_PUBLIC -gboolean ostree_repo_pull_from_remotes_finish (OstreeRepo *self, - GAsyncResult *result, - GError **error); - -_OSTREE_PUBLIC -OstreeRemote *ostree_repo_resolve_keyring_for_collection (OstreeRepo *self, - const gchar *collection_id, - GCancellable *cancellable, - GError **error); - -_OSTREE_PUBLIC -gboolean ostree_repo_list_collection_refs (OstreeRepo *self, - const char *match_collection_id, - GHashTable **out_all_refs, +gboolean ostree_repo_pull_one_dir (OstreeRepo *self, const char *remote_name, + const char *dir_to_pull, char **refs_to_fetch, + OstreeRepoPullFlags flags, OstreeAsyncProgress *progress, + GCancellable *cancellable, GError **error); + +_OSTREE_PUBLIC +gboolean ostree_repo_pull_with_options (OstreeRepo *self, const char *remote_name_or_baseurl, + GVariant *options, OstreeAsyncProgress *progress, + GCancellable *cancellable, GError **error); + +_OSTREE_PUBLIC +void ostree_repo_find_remotes_async (OstreeRepo *self, const OstreeCollectionRef *const *refs, + GVariant *options, OstreeRepoFinder **finders, + OstreeAsyncProgress *progress, GCancellable *cancellable, + GAsyncReadyCallback callback, gpointer user_data); +_OSTREE_PUBLIC +OstreeRepoFinderResult **ostree_repo_find_remotes_finish (OstreeRepo *self, GAsyncResult *result, + GError **error); + +_OSTREE_PUBLIC +void ostree_repo_pull_from_remotes_async (OstreeRepo *self, + const OstreeRepoFinderResult *const *results, + GVariant *options, OstreeAsyncProgress *progress, + GCancellable *cancellable, GAsyncReadyCallback callback, + gpointer user_data); +_OSTREE_PUBLIC +gboolean ostree_repo_pull_from_remotes_finish (OstreeRepo *self, GAsyncResult *result, + GError **error); + +_OSTREE_PUBLIC +OstreeRemote *ostree_repo_resolve_keyring_for_collection (OstreeRepo *self, + const gchar *collection_id, + GCancellable *cancellable, + GError **error); + +_OSTREE_PUBLIC +gboolean ostree_repo_list_collection_refs (OstreeRepo *self, const char *match_collection_id, + GHashTable **out_all_refs, OstreeRepoListRefsExtFlags flags, - GCancellable *cancellable, - GError **error); + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC void ostree_repo_pull_default_console_progress_changed (OstreeAsyncProgress *progress, - gpointer user_data); + gpointer user_data); _OSTREE_PUBLIC -gboolean ostree_repo_sign_commit (OstreeRepo *self, - const gchar *commit_checksum, - const gchar *key_id, - const gchar *homedir, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_sign_commit (OstreeRepo *self, const gchar *commit_checksum, + const gchar *key_id, const gchar *homedir, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_sign_delta (OstreeRepo *self, - const gchar *from_commit, - const gchar *to_commit, - const gchar *key_id, - const gchar *homedir, - GCancellable *cancellable, - GError **error); - +gboolean ostree_repo_sign_delta (OstreeRepo *self, const gchar *from_commit, const gchar *to_commit, + const gchar *key_id, const gchar *homedir, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_verify_commit (OstreeRepo *self, - const gchar *commit_checksum, - GFile *keyringdir, - GFile *extra_keyring, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_verify_commit (OstreeRepo *self, const gchar *commit_checksum, + GFile *keyringdir, GFile *extra_keyring, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_remote_get_gpg_verify (OstreeRepo *self, - const char *name, - gboolean *out_gpg_verify, - GError **error); +gboolean ostree_repo_remote_get_gpg_verify (OstreeRepo *self, const char *name, + gboolean *out_gpg_verify, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_remote_get_gpg_verify_summary (OstreeRepo *self, - const char *name, - gboolean *out_gpg_verify_summary, - GError **error); +gboolean ostree_repo_remote_get_gpg_verify_summary (OstreeRepo *self, const char *name, + gboolean *out_gpg_verify_summary, + GError **error); /** * OSTREE_GPG_KEY_GVARIANT_FORMAT: @@ -1482,79 +1213,55 @@ gboolean ostree_repo_remote_get_gpg_verify_summary (OstreeRepo *self, #define OSTREE_GPG_KEY_GVARIANT_FORMAT G_VARIANT_TYPE (OSTREE_GPG_KEY_GVARIANT_STRING) _OSTREE_PUBLIC -gboolean ostree_repo_remote_get_gpg_keys (OstreeRepo *self, - const char *name, - const char * const *key_ids, - GPtrArray **out_keys, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_remote_get_gpg_keys (OstreeRepo *self, const char *name, + const char *const *key_ids, GPtrArray **out_keys, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_remote_gpg_import (OstreeRepo *self, - const char *name, - GInputStream *source_stream, - const char * const *key_ids, - guint *out_imported, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_remote_gpg_import (OstreeRepo *self, const char *name, + GInputStream *source_stream, const char *const *key_ids, + guint *out_imported, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_add_gpg_signature_summary (OstreeRepo *self, - const gchar **key_id, - const gchar *homedir, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_add_gpg_signature_summary (OstreeRepo *self, const gchar **key_id, + const gchar *homedir, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_append_gpg_signature (OstreeRepo *self, - const gchar *commit_checksum, - GBytes *signature_bytes, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_append_gpg_signature (OstreeRepo *self, const gchar *commit_checksum, + GBytes *signature_bytes, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_gpg_sign_data (OstreeRepo *self, - GBytes *data, - GBytes *old_signatures, - const gchar **key_id, - const gchar *homedir, - GBytes **out_signatures, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_gpg_sign_data (OstreeRepo *self, GBytes *data, GBytes *old_signatures, + const gchar **key_id, const gchar *homedir, + GBytes **out_signatures, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -OstreeGpgVerifyResult * ostree_repo_verify_commit_ext (OstreeRepo *self, - const gchar *commit_checksum, - GFile *keyringdir, - GFile *extra_keyring, - GCancellable *cancellable, - GError **error); +OstreeGpgVerifyResult *ostree_repo_verify_commit_ext (OstreeRepo *self, + const gchar *commit_checksum, + GFile *keyringdir, GFile *extra_keyring, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -OstreeGpgVerifyResult * -ostree_repo_verify_commit_for_remote (OstreeRepo *self, - const gchar *commit_checksum, - const gchar *remote_name, - GCancellable *cancellable, - GError **error); +OstreeGpgVerifyResult *ostree_repo_verify_commit_for_remote (OstreeRepo *self, + const gchar *commit_checksum, + const gchar *remote_name, + GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -OstreeGpgVerifyResult * ostree_repo_gpg_verify_data (OstreeRepo *self, - const gchar *remote_name, - GBytes *data, - GBytes *signatures, - GFile *keyringdir, - GFile *extra_keyring, - GCancellable *cancellable, - GError **error); +OstreeGpgVerifyResult *ostree_repo_gpg_verify_data (OstreeRepo *self, const gchar *remote_name, + GBytes *data, GBytes *signatures, + GFile *keyringdir, GFile *extra_keyring, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -OstreeGpgVerifyResult * ostree_repo_verify_summary (OstreeRepo *self, - const char *remote_name, - GBytes *summary, - GBytes *signatures, - GCancellable *cancellable, - GError **error); +OstreeGpgVerifyResult *ostree_repo_verify_summary (OstreeRepo *self, const char *remote_name, + GBytes *summary, GBytes *signatures, + GCancellable *cancellable, GError **error); /** * OstreeRepoVerifyFlags: @@ -1564,34 +1271,27 @@ OstreeGpgVerifyResult * ostree_repo_verify_summary (OstreeRepo *self, * * Since: 2021.4 */ -typedef enum { +typedef enum +{ OSTREE_REPO_VERIFY_FLAGS_NONE = 0, OSTREE_REPO_VERIFY_FLAGS_NO_GPG = (1 << 0), OSTREE_REPO_VERIFY_FLAGS_NO_SIGNAPI = (1 << 1), } OstreeRepoVerifyFlags; _OSTREE_PUBLIC -gboolean ostree_repo_signature_verify_commit_data (OstreeRepo *self, - const char *remote_name, - GBytes *commit_data, - GBytes *commit_metadata, - OstreeRepoVerifyFlags flags, - char **out_results, - GError **error); +gboolean ostree_repo_signature_verify_commit_data (OstreeRepo *self, const char *remote_name, + GBytes *commit_data, GBytes *commit_metadata, + OstreeRepoVerifyFlags flags, char **out_results, + GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_regenerate_summary (OstreeRepo *self, - GVariant *additional_metadata, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_regenerate_summary (OstreeRepo *self, GVariant *additional_metadata, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_regenerate_metadata (OstreeRepo *self, - GVariant *additional_metadata, - GVariant *options, - GCancellable *cancellable, - GError **error); - +gboolean ostree_repo_regenerate_metadata (OstreeRepo *self, GVariant *additional_metadata, + GVariant *options, GCancellable *cancellable, + GError **error); /** * OstreeRepoLockType: @@ -1602,21 +1302,18 @@ gboolean ostree_repo_regenerate_metadata (OstreeRepo *self, * * Since: 2021.3 */ -typedef enum { +typedef enum +{ OSTREE_REPO_LOCK_SHARED, OSTREE_REPO_LOCK_EXCLUSIVE } OstreeRepoLockType; _OSTREE_PUBLIC -gboolean ostree_repo_lock_push (OstreeRepo *self, - OstreeRepoLockType lock_type, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_lock_push (OstreeRepo *self, OstreeRepoLockType lock_type, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_repo_lock_pop (OstreeRepo *self, - OstreeRepoLockType lock_type, - GCancellable *cancellable, - GError **error); +gboolean ostree_repo_lock_pop (OstreeRepo *self, OstreeRepoLockType lock_type, + GCancellable *cancellable, GError **error); /* C convenience API only */ #ifndef __GI_SCANNER__ @@ -1631,10 +1328,8 @@ gboolean ostree_repo_lock_pop (OstreeRepo *self, typedef struct OstreeRepoAutoLock OstreeRepoAutoLock; _OSTREE_PUBLIC -OstreeRepoAutoLock * ostree_repo_auto_lock_push (OstreeRepo *self, - OstreeRepoLockType lock_type, - GCancellable *cancellable, - GError **error); +OstreeRepoAutoLock *ostree_repo_auto_lock_push (OstreeRepo *self, OstreeRepoLockType lock_type, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC void ostree_repo_auto_lock_cleanup (OstreeRepoAutoLock *lock); @@ -1642,7 +1337,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeRepoAutoLock, ostree_repo_auto_lock_cleanup #endif - /** * OSTREE_REPO_METADATA_REF: * @@ -1691,7 +1385,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeRepoAutoLock, ostree_repo_auto_lock_cleanup G_END_DECLS - /* Include here as the functions defined before should not depend on anything which is defined in -deprecated.h. */ #include "ostree-repo-deprecated.h" diff --git a/src/libostree/ostree-rollsum.c b/src/libostree/ostree-rollsum.c index a13688cf..e09ceb6b 100644 --- a/src/libostree/ostree-rollsum.c +++ b/src/libostree/ostree-rollsum.c @@ -22,14 +22,14 @@ #include #include -#include "ostree-rollsum.h" -#include "libglnx.h" #include "bupsplit.h" +#include "libglnx.h" +#include "ostree-rollsum.h" -#define ROLLSUM_BLOB_MAX (8192*4) +#define ROLLSUM_BLOB_MAX (8192 * 4) static GHashTable * -rollsum_chunks_crc32 (GBytes *bytes) +rollsum_chunks_crc32 (GBytes *bytes) { gsize start = 0; gboolean rollsum_end = FALSE; @@ -49,26 +49,27 @@ rollsum_chunks_crc32 (GBytes *bytes) if (!rollsum_end) { - offset = bupsplit_find_ofs (buf + start, MIN(G_MAXINT32, remaining), &bits); + offset = bupsplit_find_ofs (buf + start, MIN (G_MAXINT32, remaining), &bits); if (offset == 0) { rollsum_end = TRUE; - offset = MIN(ROLLSUM_BLOB_MAX, remaining); + offset = MIN (ROLLSUM_BLOB_MAX, remaining); } else if (offset > ROLLSUM_BLOB_MAX) offset = ROLLSUM_BLOB_MAX; } else - offset = MIN(ROLLSUM_BLOB_MAX, remaining); + offset = MIN (ROLLSUM_BLOB_MAX, remaining); /* Use zlib's crc32 */ - { guint32 crc = crc32 (0L, NULL, 0); + { + guint32 crc = crc32 (0L, NULL, 0); GVariant *val; GPtrArray *matches; crc = crc32 (crc, buf, offset); - val = g_variant_ref_sink (g_variant_new ("(utt)", crc, (guint64) start, (guint64)offset)); + val = g_variant_ref_sink (g_variant_new ("(utt)", crc, (guint64)start, (guint64)offset)); matches = g_hash_table_lookup (ret_rollsums, GUINT_TO_POINTER (crc)); if (!matches) { @@ -86,12 +87,11 @@ rollsum_chunks_crc32 (GBytes *bytes) } static gint -compare_matches (const void *app, - const void *bpp) +compare_matches (const void *app, const void *bpp) { - GVariant **avpp = (GVariant**)app; + GVariant **avpp = (GVariant **)app; GVariant *a = *avpp; - GVariant **bvpp = (GVariant**)bpp; + GVariant **bvpp = (GVariant **)bpp; GVariant *b = *bvpp; guint64 a_start, b_start; @@ -106,13 +106,12 @@ compare_matches (const void *app, } OstreeRollsumMatches * -_ostree_compute_rollsum_matches (GBytes *from, - GBytes *to) +_ostree_compute_rollsum_matches (GBytes *from, GBytes *to) { OstreeRollsumMatches *ret_rollsum = NULL; - g_autoptr(GHashTable) from_rollsum = NULL; - g_autoptr(GHashTable) to_rollsum = NULL; - g_autoptr(GPtrArray) matches = NULL; + g_autoptr (GHashTable) from_rollsum = NULL; + g_autoptr (GHashTable) to_rollsum = NULL; + g_autoptr (GPtrArray) matches = NULL; const guint8 *from_buf; gsize from_len; const guint8 *to_buf; @@ -171,7 +170,8 @@ _ostree_compute_rollsum_matches (GBytes *from, */ if (memcmp (from_buf + from_start, to_buf + to_start, to_offset) == 0) { - GVariant *match = g_variant_new ("(uttt)", fromcrc, to_offset, to_start, from_start); + GVariant *match + = g_variant_new ("(uttt)", fromcrc, to_offset, to_start, from_start); ret_rollsum->bufmatches++; ret_rollsum->match_size += to_offset; g_ptr_array_add (matches, g_variant_ref_sink (match)); @@ -186,9 +186,12 @@ _ostree_compute_rollsum_matches (GBytes *from, g_ptr_array_sort (matches, compare_matches); - ret_rollsum->from_rollsums = from_rollsum; from_rollsum = NULL; - ret_rollsum->to_rollsums = to_rollsum; to_rollsum = NULL; - ret_rollsum->matches = matches; matches = NULL; + ret_rollsum->from_rollsums = from_rollsum; + from_rollsum = NULL; + ret_rollsum->to_rollsums = to_rollsum; + to_rollsum = NULL; + ret_rollsum->matches = matches; + matches = NULL; return ret_rollsum; } diff --git a/src/libostree/ostree-rollsum.h b/src/libostree/ostree-rollsum.h index 50016b3b..ac620f48 100644 --- a/src/libostree/ostree-rollsum.h +++ b/src/libostree/ostree-rollsum.h @@ -19,12 +19,13 @@ #pragma once -#include #include "libglnx.h" +#include G_BEGIN_DECLS -typedef struct { +typedef struct +{ GHashTable *from_rollsums; GHashTable *to_rollsums; guint crcmatches; @@ -34,11 +35,9 @@ typedef struct { GPtrArray *matches; } OstreeRollsumMatches; -OstreeRollsumMatches * -_ostree_compute_rollsum_matches (GBytes *from, - GBytes *to); +OstreeRollsumMatches *_ostree_compute_rollsum_matches (GBytes *from, GBytes *to); void _ostree_rollsum_matches_free (OstreeRollsumMatches *rollsum); -G_DEFINE_AUTOPTR_CLEANUP_FUNC(OstreeRollsumMatches, _ostree_rollsum_matches_free) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeRollsumMatches, _ostree_rollsum_matches_free) G_END_DECLS diff --git a/src/libostree/ostree-sepolicy-private.h b/src/libostree/ostree-sepolicy-private.h index 7bbc1a1b..350ef407 100644 --- a/src/libostree/ostree-sepolicy-private.h +++ b/src/libostree/ostree-sepolicy-private.h @@ -23,18 +23,16 @@ G_BEGIN_DECLS -typedef struct { +typedef struct +{ gboolean initialized; } OstreeSepolicyFsCreatecon; void _ostree_sepolicy_fscreatecon_clear (OstreeSepolicyFsCreatecon *con); -G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(OstreeSepolicyFsCreatecon, _ostree_sepolicy_fscreatecon_clear) +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (OstreeSepolicyFsCreatecon, _ostree_sepolicy_fscreatecon_clear) -gboolean _ostree_sepolicy_preparefscreatecon (OstreeSepolicyFsCreatecon *con, - OstreeSePolicy *self, - const char *path, - guint32 mode, - GError **error); +gboolean _ostree_sepolicy_preparefscreatecon (OstreeSepolicyFsCreatecon *con, OstreeSePolicy *self, + const char *path, guint32 mode, GError **error); GVariant *_ostree_filter_selinux_xattr (GVariant *xattrs); diff --git a/src/libostree/ostree-sepolicy.c b/src/libostree/ostree-sepolicy.c index a7795a96..d61a9cc5 100644 --- a/src/libostree/ostree-sepolicy.c +++ b/src/libostree/ostree-sepolicy.c @@ -20,17 +20,17 @@ #include "config.h" #ifdef HAVE_SELINUX -#include #include +#include #endif #include "otutil.h" -#include "ostree-sepolicy.h" +#include "ostree-bootloader-syslinux.h" +#include "ostree-bootloader-uboot.h" #include "ostree-repo.h" #include "ostree-sepolicy-private.h" -#include "ostree-bootloader-uboot.h" -#include "ostree-bootloader-syslinux.h" +#include "ostree-sepolicy.h" /** * SECTION:ostree-sepolicy @@ -40,7 +40,8 @@ * A #OstreeSePolicy object can load the SELinux policy from a given * root and perform labeling. */ -struct OstreeSePolicy { +struct OstreeSePolicy +{ GObject parent; int rootfs_dfd; @@ -56,13 +57,15 @@ struct OstreeSePolicy { #endif }; -typedef struct { +typedef struct +{ GObjectClass parent_class; } OstreeSePolicyClass; -static void initable_iface_init (GInitableIface *initable_iface); +static void initable_iface_init (GInitableIface *initable_iface); -enum { +enum +{ PROP_0, PROP_PATH, @@ -77,11 +80,11 @@ ostree_sepolicy_finalize (GObject *object) { OstreeSePolicy *self = OSTREE_SEPOLICY (object); - (void) glnx_tmpdir_delete (&self->tmpdir, NULL, NULL); + (void)glnx_tmpdir_delete (&self->tmpdir, NULL, NULL); g_clear_object (&self->path); if (self->rootfs_dfd_owned != -1) - (void) close (self->rootfs_dfd_owned); + (void)close (self->rootfs_dfd_owned); #ifdef HAVE_SELINUX g_clear_object (&self->selinux_policy_root); g_clear_pointer (&self->selinux_policy_name, g_free); @@ -97,10 +100,8 @@ ostree_sepolicy_finalize (GObject *object) } static void -ostree_sepolicy_set_property(GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) +ostree_sepolicy_set_property (GObject *object, guint prop_id, const GValue *value, + GParamSpec *pspec) { OstreeSePolicy *self = OSTREE_SEPOLICY (object); @@ -134,10 +135,7 @@ ostree_sepolicy_set_property(GObject *object, } static void -ostree_sepolicy_get_property(GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) +ostree_sepolicy_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { OstreeSePolicy *self = OSTREE_SEPOLICY (object); @@ -175,35 +173,25 @@ ostree_sepolicy_class_init (OstreeSePolicyClass *klass) object_class->set_property = ostree_sepolicy_set_property; object_class->finalize = ostree_sepolicy_finalize; - g_object_class_install_property (object_class, - PROP_PATH, - g_param_spec_object ("path", - "", - "", - G_TYPE_FILE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - g_object_class_install_property (object_class, - PROP_ROOTFS_DFD, - g_param_spec_int ("rootfs-dfd", - "", "", - -1, G_MAXINT, -1, + g_object_class_install_property ( + object_class, PROP_PATH, + g_param_spec_object ("path", "", "", G_TYPE_FILE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property (object_class, PROP_ROOTFS_DFD, + g_param_spec_int ("rootfs-dfd", "", "", -1, G_MAXINT, -1, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - } #ifdef HAVE_SELINUX /* Find the latest policy file in our root and return its checksum. */ static gboolean -get_policy_checksum (char **out_csum, - GCancellable *cancellable, - GError **error) +get_policy_checksum (char **out_csum, GCancellable *cancellable, GError **error) { const char *binary_policy_path = selinux_binary_policy_path (); const char *binfile_prefix = glnx_basename (binary_policy_path); g_autofree char *bindir_path = g_path_get_dirname (binary_policy_path); - g_autofree char *best_policy = NULL; int best_version = 0; @@ -211,7 +199,9 @@ get_policy_checksum (char **out_csum, if (!glnx_opendirat (AT_FDCWD, bindir_path, TRUE, &bindir_dfd, error)) return FALSE; - g_auto(GLnxDirFdIterator) dfd_iter = { 0,}; + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; if (!glnx_dirfd_iterator_init_at (bindir_dfd, ".", FALSE, &dfd_iter, error)) return FALSE; @@ -219,8 +209,7 @@ get_policy_checksum (char **out_csum, { struct dirent *dent = NULL; - 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; @@ -233,16 +222,14 @@ get_policy_checksum (char **out_csum, * somehow change; there would be cheers & slow-mo high-fives at the * sight of our code not breaking. Is that hope not worth a fraction * of a millisecond? I believe it is... or maybe I'm just lazy. */ - g_autofree char *regex = g_strdup_printf ("^\\Q%s\\E\\.[0-9]+$", - binfile_prefix); + g_autofree char *regex = g_strdup_printf ("^\\Q%s\\E\\.[0-9]+$", binfile_prefix); /* we could use match groups to extract the version, but mehhh, we * already have the prefix on hand */ if (g_regex_match_simple (regex, dent->d_name, 0, 0)) { int version = /* do +1 for the period */ - (int)g_ascii_strtoll (dent->d_name + strlen (binfile_prefix)+1, - NULL, 10); + (int)g_ascii_strtoll (dent->d_name + strlen (binfile_prefix) + 1, NULL, 10); g_assert (version > 0); if (version > best_version) @@ -258,8 +245,7 @@ get_policy_checksum (char **out_csum, if (!best_policy) return glnx_throw (error, "Could not find binary policy file"); - *out_csum = ot_checksum_file_at (bindir_dfd, best_policy, G_CHECKSUM_SHA256, - cancellable, error); + *out_csum = ot_checksum_file_at (bindir_dfd, best_policy, G_CHECKSUM_SHA256, cancellable, error); if (*out_csum == NULL) return FALSE; @@ -282,21 +268,21 @@ get_policy_checksum (char **out_csum, * * Returns: (transfer full): A new policy */ -OstreeSePolicy* -ostree_sepolicy_new_from_commit (OstreeRepo *repo, - const char *rev, - GCancellable *cancellable, - GError **error) +OstreeSePolicy * +ostree_sepolicy_new_from_commit (OstreeRepo *repo, const char *rev, GCancellable *cancellable, + GError **error) { GLNX_AUTO_PREFIX_ERROR ("setting sepolicy from commit", error); - g_autoptr(GFile) root = NULL; + g_autoptr (GFile) root = NULL; g_autofree char *commit = NULL; if (!ostree_repo_read_commit (repo, rev, &root, &commit, cancellable, error)) return NULL; const char policypath[] = "usr/etc/selinux"; - g_autoptr(GFile) policyroot = g_file_get_child (root, policypath); + g_autoptr (GFile) policyroot = g_file_get_child (root, policypath); - GLnxTmpDir tmpdir = {0,}; + GLnxTmpDir tmpdir = { + 0, + }; if (!glnx_mkdtemp ("ostree-commit-sepolicy-XXXXXX", 0700, &tmpdir, error)) return FALSE; if (!glnx_shutil_mkdir_p_at (tmpdir.fd, "usr/etc", 0755, cancellable, error)) @@ -304,12 +290,15 @@ ostree_sepolicy_new_from_commit (OstreeRepo *repo, if (g_file_query_exists (policyroot, NULL)) { - OstreeRepoCheckoutAtOptions coopts = {0,}; - coopts.mode = OSTREE_REPO_CHECKOUT_MODE_USER; - coopts.subpath = glnx_strjoina ("/", policypath); - - if (!ostree_repo_checkout_at (repo, &coopts, tmpdir.fd, policypath, commit, cancellable, error)) - return glnx_prefix_error_null (error, "policy checkout"); + OstreeRepoCheckoutAtOptions coopts = { + 0, + }; + coopts.mode = OSTREE_REPO_CHECKOUT_MODE_USER; + coopts.subpath = glnx_strjoina ("/", policypath); + + if (!ostree_repo_checkout_at (repo, &coopts, tmpdir.fd, policypath, commit, cancellable, + error)) + return glnx_prefix_error_null (error, "policy checkout"); } OstreeSePolicy *ret = ostree_sepolicy_new_at (tmpdir.fd, cancellable, error); @@ -338,9 +327,7 @@ cached_is_selinux_enabled (void) #endif static gboolean -initable_init (GInitable *initable, - GCancellable *cancellable, - GError **error) +initable_init (GInitable *initable, GCancellable *cancellable, GError **error) { #ifdef HAVE_SELINUX OstreeSePolicy *self = OSTREE_SEPOLICY (initable); @@ -352,10 +339,10 @@ initable_init (GInitable *initable, /* First thing here, call is_selinux_enabled() to prime the cache. See the * link above for more information why. */ - (void) cached_is_selinux_enabled (); + (void)cached_is_selinux_enabled (); /* TODO - use this below */ - g_autoptr(GFile) path = NULL; + g_autoptr (GFile) path = NULL; if (self->rootfs_dfd != -1) path = ot_fdrel_to_gfile (self->rootfs_dfd, "."); else if (self->path) @@ -372,30 +359,30 @@ initable_init (GInitable *initable, else g_assert_not_reached (); - g_autoptr(GFile) etc_selinux_dir = g_file_resolve_relative_path (path, "etc/selinux"); + g_autoptr (GFile) etc_selinux_dir = g_file_resolve_relative_path (path, "etc/selinux"); if (!g_file_query_exists (etc_selinux_dir, NULL)) { g_object_unref (etc_selinux_dir); etc_selinux_dir = g_file_resolve_relative_path (path, "usr/etc/selinux"); } - g_autoptr(GFile) policy_config_path = g_file_get_child (etc_selinux_dir, "config"); - g_autoptr(GFile) policy_root = NULL; + g_autoptr (GFile) policy_config_path = g_file_get_child (etc_selinux_dir, "config"); + g_autoptr (GFile) policy_root = NULL; if (g_file_query_exists (policy_config_path, NULL)) { - g_autoptr(GFileInputStream) filein = g_file_read (policy_config_path, cancellable, error); + g_autoptr (GFileInputStream) filein = g_file_read (policy_config_path, cancellable, error); if (!filein) return FALSE; - g_autoptr(GDataInputStream) datain = g_data_input_stream_new ((GInputStream*)filein); + g_autoptr (GDataInputStream) datain = g_data_input_stream_new ((GInputStream *)filein); while (TRUE) { gsize len; - g_autoptr(GError) temp_error = NULL; - g_autofree char *line = g_data_input_stream_read_line_utf8 (datain, &len, - cancellable, &temp_error); + g_autoptr (GError) temp_error = NULL; + g_autofree char *line + = g_data_input_stream_read_line_utf8 (datain, &len, cancellable, &temp_error); if (temp_error) return g_propagate_error (error, g_steal_pointer (&temp_error)), FALSE; @@ -411,8 +398,8 @@ initable_init (GInitable *initable, else if (g_str_has_prefix (line, selinux_prefix)) { const char *enabled_str = line + strlen (selinux_prefix); - if (g_ascii_strncasecmp (enabled_str, "enforcing", strlen ("enforcing")) == 0 || - g_ascii_strncasecmp (enabled_str, "permissive", strlen ("permissive")) == 0) + if (g_ascii_strncasecmp (enabled_str, "enforcing", strlen ("enforcing")) == 0 + || g_ascii_strncasecmp (enabled_str, "permissive", strlen ("permissive")) == 0) enabled = TRUE; } } @@ -427,13 +414,13 @@ initable_init (GInitable *initable, self->selinux_hnd = selabel_open (SELABEL_CTX_FILE, NULL, 0); if (!self->selinux_hnd) - return glnx_throw_errno_prefix (error, "With policy root '%s': selabel_open(SELABEL_CTX_FILE)", - policy_rootpath); + return glnx_throw_errno_prefix ( + error, "With policy root '%s': selabel_open(SELABEL_CTX_FILE)", policy_rootpath); char *con = NULL; if (selabel_lookup_raw (self->selinux_hnd, &con, "/", 0755) != 0) - return glnx_throw_errno_prefix (error, "With policy root '%s': Failed to look up context of /", - policy_rootpath); + return glnx_throw_errno_prefix ( + error, "With policy root '%s': Failed to look up context of /", policy_rootpath); freecon (con); if (!get_policy_checksum (&self->selinux_policy_csum, cancellable, error)) @@ -468,10 +455,8 @@ initable_iface_init (GInitableIface *initable_iface) * * Returns: (transfer full): An accessor object for SELinux policy in root located at @path */ -OstreeSePolicy* -ostree_sepolicy_new (GFile *path, - GCancellable *cancellable, - GError **error) +OstreeSePolicy * +ostree_sepolicy_new (GFile *path, GCancellable *cancellable, GError **error) { return g_initable_new (OSTREE_TYPE_SEPOLICY, cancellable, error, "path", path, NULL); } @@ -486,10 +471,8 @@ ostree_sepolicy_new (GFile *path, * * Since: 2017.4 */ -OstreeSePolicy* -ostree_sepolicy_new_at (int rootfs_dfd, - GCancellable *cancellable, - GError **error) +OstreeSePolicy * +ostree_sepolicy_new_at (int rootfs_dfd, GCancellable *cancellable, GError **error) { return g_initable_new (OSTREE_TYPE_SEPOLICY, cancellable, error, "rootfs-dfd", rootfs_dfd, NULL); } @@ -505,7 +488,7 @@ ostree_sepolicy_new_at (int rootfs_dfd, * Returns: (transfer none) (nullable): Path to rootfs */ GFile * -ostree_sepolicy_get_path (OstreeSePolicy *self) +ostree_sepolicy_get_path (OstreeSePolicy *self) { return self->path; } @@ -558,12 +541,8 @@ ostree_sepolicy_get_csum (OstreeSePolicy *self) * will be returned. */ gboolean -ostree_sepolicy_get_label (OstreeSePolicy *self, - const char *relpath, - guint32 unix_mode, - char **out_label, - GCancellable *cancellable, - GError **error) +ostree_sepolicy_get_label (OstreeSePolicy *self, const char *relpath, guint32 unix_mode, + char **out_label, GCancellable *cancellable, GError **error) { *out_label = NULL; #ifdef HAVE_SELINUX @@ -611,23 +590,17 @@ ostree_sepolicy_get_label (OstreeSePolicy *self, * Reset the security context of @target based on the SELinux policy. */ gboolean -ostree_sepolicy_restorecon (OstreeSePolicy *self, - const char *path, - GFileInfo *info, - GFile *target, - OstreeSePolicyRestoreconFlags flags, - char **out_new_label, - GCancellable *cancellable, - GError **error) +ostree_sepolicy_restorecon (OstreeSePolicy *self, const char *path, GFileInfo *info, GFile *target, + OstreeSePolicyRestoreconFlags flags, char **out_new_label, + GCancellable *cancellable, GError **error) { #ifdef HAVE_SELINUX - g_autoptr(GFileInfo) src_info = NULL; + g_autoptr (GFileInfo) src_info = NULL; if (info != NULL) src_info = g_object_ref (info); else { - src_info = g_file_query_info (target, "unix::mode", - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + src_info = g_file_query_info (target, "unix::mode", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!src_info) return FALSE; @@ -637,8 +610,7 @@ ostree_sepolicy_restorecon (OstreeSePolicy *self, if (flags & OSTREE_SEPOLICY_RESTORECON_FLAGS_KEEP_EXISTING) { char *existing_con = NULL; - if (lgetfilecon_raw (gs_file_get_path_cached (target), &existing_con) > 0 - && existing_con) + if (lgetfilecon_raw (gs_file_get_path_cached (target), &existing_con) > 0 && existing_con) { do_relabel = FALSE; freecon (existing_con); @@ -650,8 +622,7 @@ ostree_sepolicy_restorecon (OstreeSePolicy *self, { if (!ostree_sepolicy_get_label (self, path, g_file_info_get_attribute_uint32 (src_info, "unix::mode"), - &label, - cancellable, error)) + &label, cancellable, error)) return FALSE; if (!label) @@ -681,10 +652,8 @@ ostree_sepolicy_restorecon (OstreeSePolicy *self, * */ gboolean -ostree_sepolicy_setfscreatecon (OstreeSePolicy *self, - const char *path, - guint32 mode, - GError **error) +ostree_sepolicy_setfscreatecon (OstreeSePolicy *self, const char *path, guint32 mode, + GError **error) { #ifdef HAVE_SELINUX g_autofree char *label = NULL; @@ -726,11 +695,8 @@ ostree_sepolicy_fscreatecon_cleanup (void **unused) * g_auto() cleanup. May be made public later. */ gboolean -_ostree_sepolicy_preparefscreatecon (OstreeSepolicyFsCreatecon *con, - OstreeSePolicy *self, - const char *path, - guint32 mode, - GError **error) +_ostree_sepolicy_preparefscreatecon (OstreeSepolicyFsCreatecon *con, OstreeSePolicy *self, + const char *path, guint32 mode, GError **error) { if (!self || ostree_sepolicy_get_name (self) == NULL) return TRUE; @@ -768,10 +734,9 @@ _ostree_filter_selinux_xattr (GVariant *xattrs) for (guint i = 0; i < n; i++) { const char *name = NULL; - g_autoptr(GVariant) value = NULL; + g_autoptr (GVariant) value = NULL; - g_variant_get_child (xattrs, i, "(^&ay@ay)", - &name, &value); + g_variant_get_child (xattrs, i, "(^&ay@ay)", &name, &value); if (strcmp (name, "security.selinux") == 0) continue; @@ -781,9 +746,7 @@ _ostree_filter_selinux_xattr (GVariant *xattrs) have_xattrs = TRUE; g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ayay)")); } - g_variant_builder_add (&builder, "(@ay@ay)", - g_variant_new_bytestring (name), - value); + g_variant_builder_add (&builder, "(@ay@ay)", g_variant_new_bytestring (name), value); } /* Canonicalize zero length to NULL for efficiency */ if (!have_xattrs) diff --git a/src/libostree/ostree-sepolicy.h b/src/libostree/ostree-sepolicy.h index 3534a530..20984567 100644 --- a/src/libostree/ostree-sepolicy.h +++ b/src/libostree/ostree-sepolicy.h @@ -23,33 +23,26 @@ G_BEGIN_DECLS -#define OSTREE_TYPE_SEPOLICY ostree_sepolicy_get_type() +#define OSTREE_TYPE_SEPOLICY ostree_sepolicy_get_type () #define OSTREE_SEPOLICY(obj) \ (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSTREE_TYPE_SEPOLICY, OstreeSePolicy)) -#define OSTREE_IS_SEPOLICY(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSTREE_TYPE_SEPOLICY)) +#define OSTREE_IS_SEPOLICY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSTREE_TYPE_SEPOLICY)) _OSTREE_PUBLIC GType ostree_sepolicy_get_type (void); _OSTREE_PUBLIC -OstreeSePolicy* ostree_sepolicy_new (GFile *path, - GCancellable *cancellable, - GError **error); +OstreeSePolicy *ostree_sepolicy_new (GFile *path, GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -OstreeSePolicy* ostree_sepolicy_new_at (int rootfs_dfd, - GCancellable *cancellable, - GError **error); +OstreeSePolicy *ostree_sepolicy_new_at (int rootfs_dfd, GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -OstreeSePolicy* ostree_sepolicy_new_from_commit (OstreeRepo *repo, - const char *rev, - GCancellable *cancellable, - GError **error); +OstreeSePolicy *ostree_sepolicy_new_from_commit (OstreeRepo *repo, const char *rev, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -GFile * ostree_sepolicy_get_path (OstreeSePolicy *self); +GFile *ostree_sepolicy_get_path (OstreeSePolicy *self); _OSTREE_PUBLIC const char *ostree_sepolicy_get_name (OstreeSePolicy *self); @@ -58,38 +51,30 @@ _OSTREE_PUBLIC const char *ostree_sepolicy_get_csum (OstreeSePolicy *self); _OSTREE_PUBLIC -gboolean ostree_sepolicy_get_label (OstreeSePolicy *self, - const char *relpath, - guint32 unix_mode, - char **out_label, - GCancellable *cancellable, - GError **error); - -typedef enum { +gboolean ostree_sepolicy_get_label (OstreeSePolicy *self, const char *relpath, guint32 unix_mode, + char **out_label, GCancellable *cancellable, GError **error); + +typedef enum +{ OSTREE_SEPOLICY_RESTORECON_FLAGS_NONE, OSTREE_SEPOLICY_RESTORECON_FLAGS_ALLOW_NOLABEL = (1 << 0), OSTREE_SEPOLICY_RESTORECON_FLAGS_KEEP_EXISTING = (1 << 1) } OstreeSePolicyRestoreconFlags; _OSTREE_PUBLIC -gboolean ostree_sepolicy_restorecon (OstreeSePolicy *self, - const char *path, - GFileInfo *info, - GFile *target, - OstreeSePolicyRestoreconFlags flags, - char **out_new_label, - GCancellable *cancellable, - GError **error); +gboolean ostree_sepolicy_restorecon (OstreeSePolicy *self, const char *path, GFileInfo *info, + GFile *target, OstreeSePolicyRestoreconFlags flags, + char **out_new_label, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_sepolicy_setfscreatecon (OstreeSePolicy *self, - const char *path, - guint32 mode, - GError **error); +gboolean ostree_sepolicy_setfscreatecon (OstreeSePolicy *self, const char *path, guint32 mode, + GError **error); _OSTREE_PUBLIC void ostree_sepolicy_fscreatecon_cleanup (void **unused); -#define ostree_cleanup_sepolicy_fscreatecon __attribute__ ((cleanup(ostree_sepolicy_fscreatecon_cleanup))) +#define ostree_cleanup_sepolicy_fscreatecon \ + __attribute__ ((cleanup (ostree_sepolicy_fscreatecon_cleanup))) G_END_DECLS diff --git a/src/libostree/ostree-sign-dummy.c b/src/libostree/ostree-sign-dummy.c index 562413e8..fdd6ca59 100644 --- a/src/libostree/ostree-sign-dummy.c +++ b/src/libostree/ostree-sign-dummy.c @@ -22,8 +22,8 @@ #include "config.h" -#include #include "ostree-sign-dummy.h" +#include #include #undef G_LOG_DOMAIN @@ -45,11 +45,10 @@ struct _OstreeSignDummy G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeSignDummy, g_object_unref) #endif -static void -ostree_sign_dummy_iface_init (OstreeSignInterface *self); +static void ostree_sign_dummy_iface_init (OstreeSignInterface *self); G_DEFINE_TYPE_WITH_CODE (OstreeSignDummy, _ostree_sign_dummy, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (OSTREE_TYPE_SIGN, ostree_sign_dummy_iface_init)); + G_IMPLEMENT_INTERFACE (OSTREE_TYPE_SIGN, ostree_sign_dummy_iface_init)); static gboolean check_dummy_sign_enabled (GError **error) @@ -87,73 +86,74 @@ _ostree_sign_dummy_init (OstreeSignDummy *self) self->pk_ascii = NULL; } -gboolean ostree_sign_dummy_set_sk (OstreeSign *self, GVariant *key, GError **error) +gboolean +ostree_sign_dummy_set_sk (OstreeSign *self, GVariant *key, GError **error) { if (!check_dummy_sign_enabled (error)) return FALSE; - OstreeSignDummy *sign = _ostree_sign_dummy_get_instance_private(OSTREE_SIGN_DUMMY(self)); + OstreeSignDummy *sign = _ostree_sign_dummy_get_instance_private (OSTREE_SIGN_DUMMY (self)); - g_free(sign->sk_ascii); + g_free (sign->sk_ascii); sign->sk_ascii = g_variant_dup_string (key, 0); return TRUE; } -gboolean ostree_sign_dummy_set_pk (OstreeSign *self, GVariant *key, GError **error) +gboolean +ostree_sign_dummy_set_pk (OstreeSign *self, GVariant *key, GError **error) { - OstreeSignDummy *sign = _ostree_sign_dummy_get_instance_private(OSTREE_SIGN_DUMMY(self)); + OstreeSignDummy *sign = _ostree_sign_dummy_get_instance_private (OSTREE_SIGN_DUMMY (self)); - g_free(sign->pk_ascii); + g_free (sign->pk_ascii); sign->pk_ascii = g_variant_dup_string (key, 0); return TRUE; } -gboolean ostree_sign_dummy_data (OstreeSign *self, - GBytes *data, - GBytes **signature, - GCancellable *cancellable, - GError **error) +gboolean +ostree_sign_dummy_data (OstreeSign *self, GBytes *data, GBytes **signature, + GCancellable *cancellable, GError **error) { if (!check_dummy_sign_enabled (error)) return FALSE; g_return_val_if_fail (OSTREE_IS_SIGN (self), FALSE); - OstreeSignDummy *sign = _ostree_sign_dummy_get_instance_private(OSTREE_SIGN_DUMMY(self)); + OstreeSignDummy *sign = _ostree_sign_dummy_get_instance_private (OSTREE_SIGN_DUMMY (self)); - *signature = g_bytes_new (sign->sk_ascii, strlen(sign->sk_ascii)); + *signature = g_bytes_new (sign->sk_ascii, strlen (sign->sk_ascii)); return TRUE; } -const gchar * ostree_sign_dummy_get_name (OstreeSign *self) +const gchar * +ostree_sign_dummy_get_name (OstreeSign *self) { g_return_val_if_fail (OSTREE_IS_SIGN (self), FALSE); return OSTREE_SIGN_DUMMY_NAME; } -const gchar * ostree_sign_dummy_metadata_key (OstreeSign *self) +const gchar * +ostree_sign_dummy_metadata_key (OstreeSign *self) { return OSTREE_SIGN_METADATA_DUMMY_KEY; } -const gchar * ostree_sign_dummy_metadata_format (OstreeSign *self) +const gchar * +ostree_sign_dummy_metadata_format (OstreeSign *self) { return OSTREE_SIGN_METADATA_DUMMY_TYPE; } -gboolean ostree_sign_dummy_data_verify (OstreeSign *self, - GBytes *data, - GVariant *signatures, - char **out_success_message, - GError **error) +gboolean +ostree_sign_dummy_data_verify (OstreeSign *self, GBytes *data, GVariant *signatures, + char **out_success_message, GError **error) { if (!check_dummy_sign_enabled (error)) return FALSE; @@ -161,27 +161,27 @@ gboolean ostree_sign_dummy_data_verify (OstreeSign *self, g_return_val_if_fail (OSTREE_IS_SIGN (self), FALSE); g_return_val_if_fail (data != NULL, FALSE); - OstreeSignDummy *sign = _ostree_sign_dummy_get_instance_private(OSTREE_SIGN_DUMMY(self)); + OstreeSignDummy *sign = _ostree_sign_dummy_get_instance_private (OSTREE_SIGN_DUMMY (self)); if (signatures == NULL) return glnx_throw (error, "signature: dummy: commit have no signatures of my type"); - if (!g_variant_is_of_type (signatures, (GVariantType *) OSTREE_SIGN_METADATA_DUMMY_TYPE)) + if (!g_variant_is_of_type (signatures, (GVariantType *)OSTREE_SIGN_METADATA_DUMMY_TYPE)) return glnx_throw (error, "signature: dummy: wrong type passed for verification"); - gsize n = g_variant_n_children(signatures); + gsize n = g_variant_n_children (signatures); for (gsize i = 0; i < n; i++) { g_autoptr (GVariant) child = g_variant_get_child_value (signatures, i); - g_autoptr (GBytes) signature = g_variant_get_data_as_bytes(child); + g_autoptr (GBytes) signature = g_variant_get_data_as_bytes (child); gsize sign_size = 0; g_bytes_get_data (signature, &sign_size); - g_autofree gchar *sign_ascii = g_strndup(g_bytes_get_data (signature, NULL), sign_size); - g_debug("Read signature %d: %s", (gint)i, sign_ascii); - g_debug("Stored signature %d: %s", (gint)i, sign->pk_ascii); + g_autofree gchar *sign_ascii = g_strndup (g_bytes_get_data (signature, NULL), sign_size); + g_debug ("Read signature %d: %s", (gint)i, sign_ascii); + g_debug ("Stored signature %d: %s", (gint)i, sign->pk_ascii); - if (!g_strcmp0(sign_ascii, sign->pk_ascii)) + if (!g_strcmp0 (sign_ascii, sign->pk_ascii)) { if (out_success_message) *out_success_message = g_strdup ("dummy: Signature verified"); diff --git a/src/libostree/ostree-sign-dummy.h b/src/libostree/ostree-sign-dummy.h index 3f4d7643..b13dbd18 100644 --- a/src/libostree/ostree-sign-dummy.h +++ b/src/libostree/ostree-sign-dummy.h @@ -34,10 +34,21 @@ GType _ostree_sign_dummy_get_type (void); G_GNUC_BEGIN_IGNORE_DEPRECATIONS typedef struct _OstreeSignDummy OstreeSignDummy; -typedef struct { GObjectClass parent_class; } OstreeSignDummyClass; - -static inline OstreeSignDummy *OSTREE_SIGN_DUMMY (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_CAST (ptr, _ostree_sign_dummy_get_type (), OstreeSignDummy); } -static inline gboolean OSTREE_IS_SIGN_DUMMY (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_TYPE (ptr, _ostree_sign_dummy_get_type ()); } +typedef struct +{ + GObjectClass parent_class; +} OstreeSignDummyClass; + +static inline OstreeSignDummy * +OSTREE_SIGN_DUMMY (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_CAST (ptr, _ostree_sign_dummy_get_type (), OstreeSignDummy); +} +static inline gboolean +OSTREE_IS_SIGN_DUMMY (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_TYPE (ptr, _ostree_sign_dummy_get_type ()); +} G_GNUC_END_IGNORE_DEPRECATIONS @@ -50,26 +61,19 @@ G_DECLARE_FINAL_TYPE (OstreeSignDummy, GObject) */ -const gchar * ostree_sign_dummy_get_name (OstreeSign *self); +const gchar *ostree_sign_dummy_get_name (OstreeSign *self); -gboolean ostree_sign_dummy_data (OstreeSign *self, - GBytes *data, - GBytes **signature, - GCancellable *cancellable, - GError **error); +gboolean ostree_sign_dummy_data (OstreeSign *self, GBytes *data, GBytes **signature, + GCancellable *cancellable, GError **error); -gboolean ostree_sign_dummy_data_verify (OstreeSign *self, - GBytes *data, - GVariant *signatures, - char **success_message, - GError **error); +gboolean ostree_sign_dummy_data_verify (OstreeSign *self, GBytes *data, GVariant *signatures, + char **success_message, GError **error); -const gchar * ostree_sign_dummy_metadata_key (OstreeSign *self); -const gchar * ostree_sign_dummy_metadata_format (OstreeSign *self); +const gchar *ostree_sign_dummy_metadata_key (OstreeSign *self); +const gchar *ostree_sign_dummy_metadata_format (OstreeSign *self); gboolean ostree_sign_dummy_set_sk (OstreeSign *self, GVariant *key, GError **error); gboolean ostree_sign_dummy_set_pk (OstreeSign *self, GVariant *key, GError **error); gboolean ostree_sign_dummy_add_pk (OstreeSign *self, GVariant *key, GError **error); G_END_DECLS - diff --git a/src/libostree/ostree-sign-ed25519.c b/src/libostree/ostree-sign-ed25519.c index 5839a0a1..f93695a2 100644 --- a/src/libostree/ostree-sign-ed25519.c +++ b/src/libostree/ostree-sign-ed25519.c @@ -23,8 +23,8 @@ #include "config.h" -#include #include "ostree-sign-ed25519.h" +#include #ifdef HAVE_LIBSODIUM #include #endif @@ -57,11 +57,10 @@ struct _OstreeSignEd25519 G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeSignEd25519, g_object_unref) #endif -static void -ostree_sign_ed25519_iface_init (OstreeSignInterface *self); +static void ostree_sign_ed25519_iface_init (OstreeSignInterface *self); G_DEFINE_TYPE_WITH_CODE (OstreeSignEd25519, _ostree_sign_ed25519, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (OSTREE_TYPE_SIGN, ostree_sign_ed25519_iface_init)); + G_IMPLEMENT_INTERFACE (OSTREE_TYPE_SIGN, ostree_sign_ed25519_iface_init)); static void ostree_sign_ed25519_iface_init (OstreeSignInterface *self) @@ -94,8 +93,8 @@ _ostree_sign_ed25519_init (OstreeSignEd25519 *self) self->revoked_keys = NULL; #ifdef HAVE_LIBSODIUM - if (sodium_init() < 0) - self->state = ED25519_FAILED_INITIALIZATION; + if (sodium_init () < 0) + self->state = ED25519_FAILED_INITIALIZATION; #else self->state = ED25519_NOT_SUPPORTED; #endif /* HAVE_LIBSODIUM */ @@ -109,30 +108,28 @@ _ostree_sign_ed25519_is_initialized (OstreeSignEd25519 *self, GError **error) case ED25519_OK: break; case ED25519_NOT_SUPPORTED: - return glnx_throw(error, "ed25519: engine is not supported"); + return glnx_throw (error, "ed25519: engine is not supported"); case ED25519_FAILED_INITIALIZATION: - return glnx_throw(error, "ed25519: libsodium library isn't initialized properly"); + return glnx_throw (error, "ed25519: libsodium library isn't initialized properly"); } return TRUE; } -gboolean ostree_sign_ed25519_data (OstreeSign *self, - GBytes *data, - GBytes **signature, - GCancellable *cancellable, - GError **error) +gboolean +ostree_sign_ed25519_data (OstreeSign *self, GBytes *data, GBytes **signature, + GCancellable *cancellable, GError **error) { g_assert (OSTREE_IS_SIGN (self)); - OstreeSignEd25519 *sign = _ostree_sign_ed25519_get_instance_private(OSTREE_SIGN_ED25519(self)); + OstreeSignEd25519 *sign = _ostree_sign_ed25519_get_instance_private (OSTREE_SIGN_ED25519 (self)); #ifdef HAVE_LIBSODIUM guchar *sig = NULL; #endif if (!_ostree_sign_ed25519_is_initialized (sign, error)) - return FALSE; + return FALSE; if (sign->secret_key == NULL) return glnx_throw (error, "Not able to sign: secret key is not set"); @@ -140,12 +137,9 @@ gboolean ostree_sign_ed25519_data (OstreeSign *self, #ifdef HAVE_LIBSODIUM unsigned long long sig_size = 0; - sig = g_malloc0(crypto_sign_BYTES); + sig = g_malloc0 (crypto_sign_BYTES); - if (crypto_sign_detached (sig, - &sig_size, - g_bytes_get_data (data, NULL), - g_bytes_get_size (data), + if (crypto_sign_detached (sig, &sig_size, g_bytes_get_data (data, NULL), g_bytes_get_size (data), sign->secret_key)) { return glnx_throw (error, "Not able to sign: fail to sign the object"); @@ -159,23 +153,22 @@ gboolean ostree_sign_ed25519_data (OstreeSign *self, #ifdef HAVE_LIBSODIUM static gint -_compare_ed25519_keys(gconstpointer a, gconstpointer b) { - return memcmp (a, b, crypto_sign_PUBLICKEYBYTES); +_compare_ed25519_keys (gconstpointer a, gconstpointer b) +{ + return memcmp (a, b, crypto_sign_PUBLICKEYBYTES); } #endif -gboolean ostree_sign_ed25519_data_verify (OstreeSign *self, - GBytes *data, - GVariant *signatures, - char **out_success_message, - GError **error) +gboolean +ostree_sign_ed25519_data_verify (OstreeSign *self, GBytes *data, GVariant *signatures, + char **out_success_message, GError **error) { g_assert (OSTREE_IS_SIGN (self)); if (data == NULL) return glnx_throw (error, "ed25519: unable to verify NULL data"); - OstreeSignEd25519 *sign = _ostree_sign_ed25519_get_instance_private(OSTREE_SIGN_ED25519(self)); + OstreeSignEd25519 *sign = _ostree_sign_ed25519_get_instance_private (OSTREE_SIGN_ED25519 (self)); if (!_ostree_sign_ed25519_is_initialized (sign, error)) return FALSE; @@ -183,7 +176,7 @@ gboolean ostree_sign_ed25519_data_verify (OstreeSign *self, if (signatures == NULL) return glnx_throw (error, "ed25519: commit have no signatures of my type"); - if (!g_variant_is_of_type (signatures, (GVariantType *) OSTREE_SIGN_METADATA_ED25519_TYPE)) + if (!g_variant_is_of_type (signatures, (GVariantType *)OSTREE_SIGN_METADATA_ED25519_TYPE)) return glnx_throw (error, "ed25519: wrong type passed for verification"); #ifdef HAVE_LIBSODIUM @@ -201,40 +194,43 @@ gboolean ostree_sign_ed25519_data_verify (OstreeSign *self, return FALSE; } - g_debug ("verify: data hash = 0x%x", g_bytes_hash(data)); + g_debug ("verify: data hash = 0x%x", g_bytes_hash (data)); - g_autoptr(GString) invalid_signatures = NULL; + g_autoptr (GString) invalid_signatures = NULL; guint n_invalid_signatures = 0; - for (gsize i = 0; i < g_variant_n_children(signatures); i++) + for (gsize i = 0; i < g_variant_n_children (signatures); i++) { g_autoptr (GVariant) child = g_variant_get_child_value (signatures, i); - g_autoptr (GBytes) signature = g_variant_get_data_as_bytes(child); + g_autoptr (GBytes) signature = g_variant_get_data_as_bytes (child); if (g_bytes_get_size (signature) != crypto_sign_BYTES) - return glnx_throw (error, "Invalid signature length of %" G_GSIZE_FORMAT " bytes, expected %" G_GSIZE_FORMAT, (gsize) g_bytes_get_size (signature), (gsize) crypto_sign_BYTES); + return glnx_throw (error, + "Invalid signature length of %" G_GSIZE_FORMAT + " bytes, expected %" G_GSIZE_FORMAT, + (gsize)g_bytes_get_size (signature), (gsize)crypto_sign_BYTES); - g_autofree char * hex = g_malloc0 (crypto_sign_PUBLICKEYBYTES*2 + 1); + g_autofree char *hex = g_malloc0 (crypto_sign_PUBLICKEYBYTES * 2 + 1); - g_debug("Read signature %d: %s", (gint)i, g_variant_print(child, TRUE)); + g_debug ("Read signature %d: %s", (gint)i, g_variant_print (child, TRUE)); - for (GList *public_key = sign->public_keys; - public_key != NULL; - public_key = public_key->next) + for (GList *public_key = sign->public_keys; public_key != NULL; public_key = public_key->next) { /* TODO: use non-list for tons of revoked keys? */ - if (g_list_find_custom (sign->revoked_keys, public_key->data, _compare_ed25519_keys) != NULL) + if (g_list_find_custom (sign->revoked_keys, public_key->data, _compare_ed25519_keys) + != NULL) { - g_debug("Skip revoked key '%s'", - sodium_bin2hex (hex, crypto_sign_PUBLICKEYBYTES*2+1, public_key->data, crypto_sign_PUBLICKEYBYTES)); + g_debug ("Skip revoked key '%s'", + sodium_bin2hex (hex, crypto_sign_PUBLICKEYBYTES * 2 + 1, public_key->data, + crypto_sign_PUBLICKEYBYTES)); continue; } - if (crypto_sign_verify_detached ((guchar *) g_variant_get_data (child), - g_bytes_get_data (data, NULL), - g_bytes_get_size (data), - public_key->data) != 0) + if (crypto_sign_verify_detached ((guchar *)g_variant_get_data (child), + g_bytes_get_data (data, NULL), g_bytes_get_size (data), + public_key->data) + != 0) { /* Incorrect signature! */ if (invalid_signatures == NULL) @@ -243,15 +239,18 @@ gboolean ostree_sign_ed25519_data_verify (OstreeSign *self, g_string_append (invalid_signatures, "; "); n_invalid_signatures++; g_string_append_printf (invalid_signatures, "key '%s'", - sodium_bin2hex (hex, crypto_sign_PUBLICKEYBYTES*2+1, public_key->data, crypto_sign_PUBLICKEYBYTES)); + sodium_bin2hex (hex, crypto_sign_PUBLICKEYBYTES * 2 + 1, + public_key->data, + crypto_sign_PUBLICKEYBYTES)); } else { if (out_success_message) { - *out_success_message = - g_strdup_printf ("ed25519: Signature verified successfully with key '%s'", - sodium_bin2hex (hex, crypto_sign_PUBLICKEYBYTES*2+1, public_key->data, crypto_sign_PUBLICKEYBYTES)); + *out_success_message = g_strdup_printf ( + "ed25519: Signature verified successfully with key '%s'", + sodium_bin2hex (hex, crypto_sign_PUBLICKEYBYTES * 2 + 1, public_key->data, + crypto_sign_PUBLICKEYBYTES)); } return TRUE; } @@ -265,8 +264,10 @@ gboolean ostree_sign_ed25519_data_verify (OstreeSign *self, * cap a reasonable error message at 3. */ if (n_invalid_signatures > 3) - return glnx_throw (error, "ed25519: Signature couldn't be verified; tried %u keys", n_invalid_signatures); - return glnx_throw (error, "ed25519: Signature couldn't be verified with: %s", invalid_signatures->str); + return glnx_throw (error, "ed25519: Signature couldn't be verified; tried %u keys", + n_invalid_signatures); + return glnx_throw (error, "ed25519: Signature couldn't be verified with: %s", + invalid_signatures->str); } return glnx_throw (error, "ed25519: no signatures found"); #endif /* HAVE_LIBSODIUM */ @@ -274,31 +275,34 @@ gboolean ostree_sign_ed25519_data_verify (OstreeSign *self, return FALSE; } -const gchar * ostree_sign_ed25519_get_name (OstreeSign *self) +const gchar * +ostree_sign_ed25519_get_name (OstreeSign *self) { g_assert (OSTREE_IS_SIGN (self)); return OSTREE_SIGN_ED25519_NAME; } -const gchar * ostree_sign_ed25519_metadata_key (OstreeSign *self) +const gchar * +ostree_sign_ed25519_metadata_key (OstreeSign *self) { return OSTREE_SIGN_METADATA_ED25519_KEY; } -const gchar * ostree_sign_ed25519_metadata_format (OstreeSign *self) +const gchar * +ostree_sign_ed25519_metadata_format (OstreeSign *self) { return OSTREE_SIGN_METADATA_ED25519_TYPE; } -gboolean ostree_sign_ed25519_clear_keys (OstreeSign *self, - GError **error) +gboolean +ostree_sign_ed25519_clear_keys (OstreeSign *self, GError **error) { g_assert (OSTREE_IS_SIGN (self)); - OstreeSignEd25519 *sign = _ostree_sign_ed25519_get_instance_private(OSTREE_SIGN_ED25519(self)); + OstreeSignEd25519 *sign = _ostree_sign_ed25519_get_instance_private (OSTREE_SIGN_ED25519 (self)); if (!_ostree_sign_ed25519_is_initialized (sign, error)) return FALSE; @@ -306,11 +310,11 @@ gboolean ostree_sign_ed25519_clear_keys (OstreeSign *self, #ifdef HAVE_LIBSODIUM /* Clear secret key */ if (sign->secret_key != NULL) - { - memset (sign->secret_key, 0, crypto_sign_SECRETKEYBYTES); - g_free (sign->secret_key); - sign->secret_key = NULL; - } + { + memset (sign->secret_key, 0, crypto_sign_SECRETKEYBYTES); + g_free (sign->secret_key); + sign->secret_key = NULL; + } /* Clear already loaded trusted keys */ if (sign->public_keys != NULL) @@ -336,9 +340,8 @@ gboolean ostree_sign_ed25519_clear_keys (OstreeSign *self, * base64 ascii -- secret key is passed as string * raw key -- key is passed as bytes array * */ -gboolean ostree_sign_ed25519_set_sk (OstreeSign *self, - GVariant *secret_key, - GError **error) +gboolean +ostree_sign_ed25519_set_sk (OstreeSign *self, GVariant *secret_key, GError **error) { g_assert (OSTREE_IS_SIGN (self)); @@ -346,7 +349,7 @@ gboolean ostree_sign_ed25519_set_sk (OstreeSign *self, return FALSE; #ifdef HAVE_LIBSODIUM - OstreeSignEd25519 *sign = _ostree_sign_ed25519_get_instance_private(OSTREE_SIGN_ED25519(self)); + OstreeSignEd25519 *sign = _ostree_sign_ed25519_get_instance_private (OSTREE_SIGN_ED25519 (self)); gsize n_elements = 0; @@ -357,11 +360,12 @@ gboolean ostree_sign_ed25519_set_sk (OstreeSign *self, } else if (g_variant_is_of_type (secret_key, G_VARIANT_TYPE_BYTESTRING)) { - sign->secret_key = (guchar *) g_variant_get_fixed_array (secret_key, &n_elements, sizeof(guchar)); + sign->secret_key + = (guchar *)g_variant_get_fixed_array (secret_key, &n_elements, sizeof (guchar)); } else { - return glnx_throw (error, "Unknown ed25519 secret key type"); + return glnx_throw (error, "Unknown ed25519 secret key type"); } if (n_elements != crypto_sign_SECRETKEYBYTES) @@ -377,9 +381,8 @@ gboolean ostree_sign_ed25519_set_sk (OstreeSign *self, * base64 ascii -- public key is passed as string * raw key -- key is passed as bytes array * */ -gboolean ostree_sign_ed25519_set_pk (OstreeSign *self, - GVariant *public_key, - GError **error) +gboolean +ostree_sign_ed25519_set_pk (OstreeSign *self, GVariant *public_key, GError **error) { g_assert (OSTREE_IS_SIGN (self)); @@ -393,13 +396,12 @@ gboolean ostree_sign_ed25519_set_pk (OstreeSign *self, * base64 ascii -- public key is passed as string * raw key -- key is passed as bytes array * */ -gboolean ostree_sign_ed25519_add_pk (OstreeSign *self, - GVariant *public_key, - GError **error) +gboolean +ostree_sign_ed25519_add_pk (OstreeSign *self, GVariant *public_key, GError **error) { g_assert (OSTREE_IS_SIGN (self)); - OstreeSignEd25519 *sign = _ostree_sign_ed25519_get_instance_private(OSTREE_SIGN_ED25519(self)); + OstreeSignEd25519 *sign = _ostree_sign_ed25519_get_instance_private (OSTREE_SIGN_ED25519 (self)); if (!_ostree_sign_ed25519_is_initialized (sign, error)) return FALSE; @@ -415,7 +417,7 @@ gboolean ostree_sign_ed25519_add_pk (OstreeSign *self, } else if (g_variant_is_of_type (public_key, G_VARIANT_TYPE_BYTESTRING)) { - key = (gpointer) g_variant_get_fixed_array (public_key, &n_elements, sizeof(guchar)); + key = (gpointer)g_variant_get_fixed_array (public_key, &n_elements, sizeof (guchar)); } else { @@ -425,8 +427,9 @@ gboolean ostree_sign_ed25519_add_pk (OstreeSign *self, if (n_elements != crypto_sign_PUBLICKEYBYTES) return glnx_throw (error, "Incorrect ed25519 public key"); - g_autofree char *hex = g_malloc0 (crypto_sign_PUBLICKEYBYTES*2 + 1); - g_debug ("Read ed25519 public key = %s", sodium_bin2hex (hex, crypto_sign_PUBLICKEYBYTES*2+1, key, n_elements)); + g_autofree char *hex = g_malloc0 (crypto_sign_PUBLICKEYBYTES * 2 + 1); + g_debug ("Read ed25519 public key = %s", + sodium_bin2hex (hex, crypto_sign_PUBLICKEYBYTES * 2 + 1, key, n_elements)); if (g_list_find_custom (sign->public_keys, key, _compare_ed25519_keys) == NULL) { @@ -441,16 +444,14 @@ gboolean ostree_sign_ed25519_add_pk (OstreeSign *self, #ifdef HAVE_LIBSODIUM /* Add revoked public key */ static gboolean -_ed25519_add_revoked (OstreeSign *self, - GVariant *revoked_key, - GError **error) +_ed25519_add_revoked (OstreeSign *self, GVariant *revoked_key, GError **error) { g_assert (OSTREE_IS_SIGN (self)); if (!g_variant_is_of_type (revoked_key, G_VARIANT_TYPE_STRING)) return glnx_throw (error, "Unknown ed25519 revoked key type"); - OstreeSignEd25519 *sign = _ostree_sign_ed25519_get_instance_private(OSTREE_SIGN_ED25519(self)); + OstreeSignEd25519 *sign = _ostree_sign_ed25519_get_instance_private (OSTREE_SIGN_ED25519 (self)); const gchar *rk_ascii = g_variant_get_string (revoked_key, NULL); gsize n_elements = 0; @@ -461,8 +462,9 @@ _ed25519_add_revoked (OstreeSign *self, return glnx_throw (error, "Incorrect ed25519 revoked key"); } - g_autofree char * hex = g_malloc0 (crypto_sign_PUBLICKEYBYTES*2 + 1); - g_debug ("Read ed25519 revoked key = %s", sodium_bin2hex (hex, crypto_sign_PUBLICKEYBYTES*2+1, key, n_elements)); + g_autofree char *hex = g_malloc0 (crypto_sign_PUBLICKEYBYTES * 2 + 1); + g_debug ("Read ed25519 revoked key = %s", + sodium_bin2hex (hex, crypto_sign_PUBLICKEYBYTES * 2 + 1, key, n_elements)); if (g_list_find_custom (sign->revoked_keys, key, _compare_ed25519_keys) == NULL) { @@ -474,11 +476,8 @@ _ed25519_add_revoked (OstreeSign *self, } #endif /* HAVE_LIBSODIUM */ - static gboolean -_load_pk_from_stream (OstreeSign *self, - GDataInputStream *key_data_in, - gboolean trusted, +_load_pk_from_stream (OstreeSign *self, GDataInputStream *key_data_in, gboolean trusted, GError **error) { if (key_data_in == NULL) @@ -493,7 +492,7 @@ _load_pk_from_stream (OstreeSign *self, gsize len = 0; g_autoptr (GVariant) pk = NULL; gboolean added = FALSE; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; g_autofree char *line = g_data_input_stream_read_line (key_data_in, &len, NULL, &local_error); if (local_error != NULL) @@ -514,10 +513,7 @@ _load_pk_from_stream (OstreeSign *self, else added = _ed25519_add_revoked (self, pk, error); - g_debug ("%s %s key: %s", - added ? "Added" : "Invalid", - trusted ? "public" : "revoked", - line); + g_debug ("%s %s key: %s", added ? "Added" : "Invalid", trusted ? "public" : "revoked", line); /* Mark what we load at least one key */ if (added) @@ -528,10 +524,7 @@ _load_pk_from_stream (OstreeSign *self, } static gboolean -_load_pk_from_file (OstreeSign *self, - const gchar *filename, - gboolean trusted, - GError **error) +_load_pk_from_file (OstreeSign *self, const gchar *filename, gboolean trusted, GError **error) { g_debug ("Processing file '%s'", filename); @@ -550,15 +543,13 @@ _load_pk_from_file (OstreeSign *self, if (key_stream_in == NULL) return FALSE; - key_data_in = g_data_input_stream_new (G_INPUT_STREAM(key_stream_in)); + key_data_in = g_data_input_stream_new (G_INPUT_STREAM (key_stream_in)); g_assert (key_data_in != NULL); if (!_load_pk_from_stream (self, key_data_in, trusted, error)) { if (error == NULL || *error == NULL) - return glnx_throw (error, - "signature: ed25519: no valid keys in file '%s'", - filename); + return glnx_throw (error, "signature: ed25519: no valid keys in file '%s'", filename); else return FALSE; } @@ -567,10 +558,7 @@ _load_pk_from_file (OstreeSign *self, } static gboolean -_ed25519_load_pk (OstreeSign *self, - GVariant *options, - gboolean trusted, - GError **error) +_ed25519_load_pk (OstreeSign *self, GVariant *options, gboolean trusted, GError **error) { gboolean ret = FALSE; @@ -592,15 +580,14 @@ _ed25519_load_pk (OstreeSign *self, } /* Scan all well-known directories and construct the list with file names to scan keys */ - for (gint i=0; i < base_dirs->len; i++) + for (gint i = 0; i < base_dirs->len; i++) { gchar *base_name = NULL; g_autofree gchar *base_dir = NULL; g_autoptr (GDir) dir = NULL; base_name = g_build_filename ((gchar *)g_ptr_array_index (base_dirs, i), - trusted ? "trusted.ed25519" : "revoked.ed25519", - NULL); + trusted ? "trusted.ed25519" : "revoked.ed25519", NULL); g_debug ("Check ed25519 keys from file: %s", base_name); g_ptr_array_add (ed25519_files, base_name); @@ -622,14 +609,13 @@ _ed25519_load_pk (OstreeSign *self, } /* Scan all well-known files */ - for (gint i=0; i < ed25519_files->len; i++) + for (gint i = 0; i < ed25519_files->len; i++) { if (!_load_pk_from_file (self, (gchar *)g_ptr_array_index (ed25519_files, i), trusted, error)) { - g_debug ("Problem with loading ed25519 %s keys from `%s`", - trusted ? "public" : "revoked", + g_debug ("Problem with loading ed25519 %s keys from `%s`", trusted ? "public" : "revoked", (gchar *)g_ptr_array_index (ed25519_files, i)); - g_clear_error(error); + g_clear_error (error); } else ret = TRUE; @@ -650,20 +636,18 @@ _ed25519_load_pk (OstreeSign *self, * directories if defaults are not suitable for any reason. */ gboolean -ostree_sign_ed25519_load_pk (OstreeSign *self, - GVariant *options, - GError **error) +ostree_sign_ed25519_load_pk (OstreeSign *self, GVariant *options, GError **error) { const gchar *filename = NULL; - OstreeSignEd25519 *sign = _ostree_sign_ed25519_get_instance_private(OSTREE_SIGN_ED25519(self)); + OstreeSignEd25519 *sign = _ostree_sign_ed25519_get_instance_private (OSTREE_SIGN_ED25519 (self)); if (!_ostree_sign_ed25519_is_initialized (sign, error)) return FALSE; /* Read keys only from single file provided */ if (g_variant_lookup (options, "filename", "&s", &filename)) - return _load_pk_from_file (self, filename, TRUE, error); + return _load_pk_from_file (self, filename, TRUE, error); /* Load public keys from well-known directories and files */ if (!_ed25519_load_pk (self, options, TRUE, error)) @@ -674,7 +658,7 @@ ostree_sign_ed25519_load_pk (OstreeSign *self, * empty list of revoked keys. * */ if (!_ed25519_load_pk (self, options, FALSE, error)) - g_clear_error(error); + g_clear_error (error); return TRUE; } diff --git a/src/libostree/ostree-sign-ed25519.h b/src/libostree/ostree-sign-ed25519.h index ec5271d7..e8c3df2a 100644 --- a/src/libostree/ostree-sign-ed25519.h +++ b/src/libostree/ostree-sign-ed25519.h @@ -34,10 +34,21 @@ GType _ostree_sign_ed25519_get_type (void); G_GNUC_BEGIN_IGNORE_DEPRECATIONS typedef struct _OstreeSignEd25519 OstreeSignEd25519; -typedef struct { GObjectClass parent_class; } OstreeSignEd25519Class; - -static inline OstreeSignEd25519 *OSTREE_SIGN_ED25519 (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_CAST (ptr, _ostree_sign_ed25519_get_type (), OstreeSignEd25519); } -static inline gboolean OSTREE_IS_SIGN_ED25519 (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_TYPE (ptr, _ostree_sign_ed25519_get_type ()); } +typedef struct +{ + GObjectClass parent_class; +} OstreeSignEd25519Class; + +static inline OstreeSignEd25519 * +OSTREE_SIGN_ED25519 (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_CAST (ptr, _ostree_sign_ed25519_get_type (), OstreeSignEd25519); +} +static inline gboolean +OSTREE_IS_SIGN_ED25519 (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_TYPE (ptr, _ostree_sign_ed25519_get_type ()); +} G_GNUC_END_IGNORE_DEPRECATIONS @@ -50,40 +61,24 @@ G_DECLARE_FINAL_TYPE (OstreeSignEd25519, GObject) */ -gboolean ostree_sign_ed25519_data (OstreeSign *self, - GBytes *data, - GBytes **signature, - GCancellable *cancellable, - GError **error); +gboolean ostree_sign_ed25519_data (OstreeSign *self, GBytes *data, GBytes **signature, + GCancellable *cancellable, GError **error); -gboolean ostree_sign_ed25519_data_verify (OstreeSign *self, - GBytes *data, - GVariant *signatures, - char **out_success_message, - GError **error); +gboolean ostree_sign_ed25519_data_verify (OstreeSign *self, GBytes *data, GVariant *signatures, + char **out_success_message, GError **error); -const gchar * ostree_sign_ed25519_get_name (OstreeSign *self); -const gchar * ostree_sign_ed25519_metadata_key (OstreeSign *self); -const gchar * ostree_sign_ed25519_metadata_format (OstreeSign *self); +const gchar *ostree_sign_ed25519_get_name (OstreeSign *self); +const gchar *ostree_sign_ed25519_metadata_key (OstreeSign *self); +const gchar *ostree_sign_ed25519_metadata_format (OstreeSign *self); -gboolean ostree_sign_ed25519_clear_keys (OstreeSign *self, - GError **error); +gboolean ostree_sign_ed25519_clear_keys (OstreeSign *self, GError **error); -gboolean ostree_sign_ed25519_set_sk (OstreeSign *self, - GVariant *secret_key, - GError **error); +gboolean ostree_sign_ed25519_set_sk (OstreeSign *self, GVariant *secret_key, GError **error); -gboolean ostree_sign_ed25519_set_pk (OstreeSign *self, - GVariant *public_key, - GError **error); +gboolean ostree_sign_ed25519_set_pk (OstreeSign *self, GVariant *public_key, GError **error); -gboolean ostree_sign_ed25519_add_pk (OstreeSign *self, - GVariant *public_key, - GError **error); +gboolean ostree_sign_ed25519_add_pk (OstreeSign *self, GVariant *public_key, GError **error); -gboolean ostree_sign_ed25519_load_pk (OstreeSign *self, - GVariant *options, - GError **error); +gboolean ostree_sign_ed25519_load_pk (OstreeSign *self, GVariant *options, GError **error); G_END_DECLS - diff --git a/src/libostree/ostree-sign-private.h b/src/libostree/ostree-sign-private.h index c3826d47..b14dc634 100644 --- a/src/libostree/ostree-sign-private.h +++ b/src/libostree/ostree-sign-private.h @@ -29,11 +29,7 @@ G_BEGIN_DECLS -gboolean _ostree_sign_summary_at (OstreeSign *self, - OstreeRepo *repo, - int dir_fd, - GVariant *keys, - GCancellable *cancellable, - GError **error); +gboolean _ostree_sign_summary_at (OstreeSign *self, OstreeRepo *repo, int dir_fd, GVariant *keys, + GCancellable *cancellable, GError **error); G_END_DECLS diff --git a/src/libostree/ostree-sign.c b/src/libostree/ostree-sign.c index 305250de..be333a30 100644 --- a/src/libostree/ostree-sign.c +++ b/src/libostree/ostree-sign.c @@ -31,17 +31,17 @@ #include "config.h" -#include -#include -#include #include "libglnx.h" #include "otutil.h" +#include +#include +#include #include "ostree-autocleanups.h" #include "ostree-core.h" -#include "ostree-sign.h" -#include "ostree-sign-private.h" #include "ostree-sign-dummy.h" +#include "ostree-sign-private.h" +#include "ostree-sign.h" #ifdef HAVE_LIBSODIUM #include "ostree-sign-ed25519.h" #endif @@ -58,20 +58,19 @@ typedef struct GType type; } _sign_type; -_sign_type sign_types[] = -{ +_sign_type sign_types[] = { #if defined(HAVE_LIBSODIUM) - {OSTREE_SIGN_NAME_ED25519, 0}, + { OSTREE_SIGN_NAME_ED25519, 0 }, #endif - {"dummy", 0} + { "dummy", 0 } }; enum { #if defined(HAVE_LIBSODIUM) - SIGN_ED25519, + SIGN_ED25519, #endif - SIGN_DUMMY + SIGN_DUMMY }; G_DEFINE_INTERFACE (OstreeSign, ostree_sign, G_TYPE_OBJECT) @@ -140,8 +139,7 @@ ostree_sign_metadata_format (OstreeSign *self) * Since: 2020.2 */ gboolean -ostree_sign_clear_keys (OstreeSign *self, - GError **error) +ostree_sign_clear_keys (OstreeSign *self, GError **error) { g_assert (OSTREE_IS_SIGN (self)); @@ -167,9 +165,7 @@ ostree_sign_clear_keys (OstreeSign *self, * Since: 2020.2 */ gboolean -ostree_sign_set_sk (OstreeSign *self, - GVariant *secret_key, - GError **error) +ostree_sign_set_sk (OstreeSign *self, GVariant *secret_key, GError **error) { g_assert (OSTREE_IS_SIGN (self)); @@ -196,9 +192,7 @@ ostree_sign_set_sk (OstreeSign *self, * Since: 2020.2 */ gboolean -ostree_sign_set_pk (OstreeSign *self, - GVariant *public_key, - GError **error) +ostree_sign_set_pk (OstreeSign *self, GVariant *public_key, GError **error) { g_assert (OSTREE_IS_SIGN (self)); @@ -225,9 +219,7 @@ ostree_sign_set_pk (OstreeSign *self, * Since: 2020.2 */ gboolean -ostree_sign_add_pk (OstreeSign *self, - GVariant *public_key, - GError **error) +ostree_sign_add_pk (OstreeSign *self, GVariant *public_key, GError **error) { g_assert (OSTREE_IS_SIGN (self)); @@ -265,9 +257,7 @@ ostree_sign_add_pk (OstreeSign *self, * what the signing software will load the secret key in it's own way. */ gboolean -ostree_sign_load_pk (OstreeSign *self, - GVariant *options, - GError **error) +ostree_sign_load_pk (OstreeSign *self, GVariant *options, GError **error) { g_assert (OSTREE_IS_SIGN (self)); @@ -296,10 +286,7 @@ ostree_sign_load_pk (OstreeSign *self, * Since: 2020.2 */ gboolean -ostree_sign_data (OstreeSign *self, - GBytes *data, - GBytes **signature, - GCancellable *cancellable, +ostree_sign_data (OstreeSign *self, GBytes *data, GBytes **signature, GCancellable *cancellable, GError **error) { g_assert (OSTREE_IS_SIGN (self)); @@ -315,7 +302,8 @@ ostree_sign_data (OstreeSign *self, * @self: an #OstreeSign object * @data: the raw data to check * @signatures: the signatures to be checked - * @out_success_message: (out) (nullable) (optional): success message returned by the signing engine + * @out_success_message: (out) (nullable) (optional): success message returned by the signing + * engine * @error: a #GError * * Verify given data against signatures with pre-loaded public keys. @@ -330,28 +318,24 @@ ostree_sign_data (OstreeSign *self, * Since: 2020.2 */ gboolean -ostree_sign_data_verify (OstreeSign *self, - GBytes *data, - GVariant *signatures, - char **out_success_message, - GError **error) +ostree_sign_data_verify (OstreeSign *self, GBytes *data, GVariant *signatures, + char **out_success_message, GError **error) { g_assert (OSTREE_IS_SIGN (self)); if (OSTREE_SIGN_GET_IFACE (self)->data_verify == NULL) return glnx_throw (error, "not implemented"); - return OSTREE_SIGN_GET_IFACE (self)->data_verify(self, data, signatures, out_success_message, error); + return OSTREE_SIGN_GET_IFACE (self)->data_verify (self, data, signatures, out_success_message, + error); } /* * Adopted version of _ostree_detached_metadata_append_gpg_sig () */ static GVariant * -_sign_detached_metadata_append (OstreeSign *self, - GVariant *existing_metadata, - GBytes *signature_bytes, - GError **error) +_sign_detached_metadata_append (OstreeSign *self, GVariant *existing_metadata, + GBytes *signature_bytes, GError **error) { g_assert (OSTREE_IS_SIGN (self)); @@ -359,28 +343,26 @@ _sign_detached_metadata_append (OstreeSign *self, return glnx_null_throw (error, "Invalid NULL signature bytes"); GVariantDict metadata_dict; - g_autoptr(GVariant) signature_data = NULL; - g_autoptr(GVariantBuilder) signature_builder = NULL; + g_autoptr (GVariant) signature_data = NULL; + g_autoptr (GVariantBuilder) signature_builder = NULL; g_variant_dict_init (&metadata_dict, existing_metadata); - const gchar *signature_key = ostree_sign_metadata_key(self); - GVariantType *signature_format = (GVariantType *) ostree_sign_metadata_format(self); + const gchar *signature_key = ostree_sign_metadata_key (self); + GVariantType *signature_format = (GVariantType *)ostree_sign_metadata_format (self); - signature_data = g_variant_dict_lookup_value (&metadata_dict, - signature_key, - (GVariantType*)signature_format); + signature_data = g_variant_dict_lookup_value (&metadata_dict, signature_key, + (GVariantType *)signature_format); /* signature_data may be NULL */ signature_builder = ot_util_variant_builder_from_variant (signature_data, signature_format); g_variant_builder_add (signature_builder, "@ay", ot_gvariant_new_ay_bytes (signature_bytes)); - g_variant_dict_insert_value (&metadata_dict, - signature_key, + g_variant_dict_insert_value (&metadata_dict, signature_key, g_variant_builder_end (signature_builder)); - return g_variant_ref_sink (g_variant_dict_end (&metadata_dict)); + return g_variant_ref_sink (g_variant_dict_end (&metadata_dict)); } /** @@ -388,7 +370,8 @@ _sign_detached_metadata_append (OstreeSign *self, * @self: an #OstreeSign object * @repo: an #OsreeRepo object * @commit_checksum: SHA256 of given commit to verify - * @out_success_message: (out) (nullable) (optional): success message returned by the signing engine + * @out_success_message: (out) (nullable) (optional): success message returned by the signing + * engine * @cancellable: A #GCancellable * @error: a #GError * @@ -404,50 +387,35 @@ _sign_detached_metadata_append (OstreeSign *self, * Since: 2020.2 */ gboolean -ostree_sign_commit_verify (OstreeSign *self, - OstreeRepo *repo, - const gchar *commit_checksum, - char **out_success_message, - GCancellable *cancellable, - GError **error) +ostree_sign_commit_verify (OstreeSign *self, OstreeRepo *repo, const gchar *commit_checksum, + char **out_success_message, GCancellable *cancellable, GError **error) { g_assert (OSTREE_IS_SIGN (self)); - g_autoptr(GVariant) commit_variant = NULL; + g_autoptr (GVariant) commit_variant = NULL; /* Load the commit */ - if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, - commit_checksum, &commit_variant, + if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, commit_checksum, &commit_variant, error)) return glnx_prefix_error (error, "Failed to read commit"); /* Load the metadata */ - g_autoptr(GVariant) metadata = NULL; - if (!ostree_repo_read_commit_detached_metadata (repo, - commit_checksum, - &metadata, - cancellable, + g_autoptr (GVariant) metadata = NULL; + if (!ostree_repo_read_commit_detached_metadata (repo, commit_checksum, &metadata, cancellable, error)) return glnx_prefix_error (error, "Failed to read detached metadata"); - g_autoptr(GBytes) signed_data = g_variant_get_data_as_bytes (commit_variant); + g_autoptr (GBytes) signed_data = g_variant_get_data_as_bytes (commit_variant); - g_autoptr(GVariant) signatures = NULL; + g_autoptr (GVariant) signatures = NULL; - const gchar *signature_key = ostree_sign_metadata_key(self); - GVariantType *signature_format = (GVariantType *) ostree_sign_metadata_format(self); + const gchar *signature_key = ostree_sign_metadata_key (self); + GVariantType *signature_format = (GVariantType *)ostree_sign_metadata_format (self); if (metadata) - signatures = g_variant_lookup_value (metadata, - signature_key, - signature_format); - + signatures = g_variant_lookup_value (metadata, signature_key, signature_format); - return ostree_sign_data_verify (self, - signed_data, - signatures, - out_success_message, - error); + return ostree_sign_data_verify (self, signed_data, signatures, out_success_message, error); } /** @@ -491,45 +459,34 @@ ostree_sign_get_name (OstreeSign *self) * Since: 2020.2 */ gboolean -ostree_sign_commit (OstreeSign *self, - OstreeRepo *repo, - const gchar *commit_checksum, - GCancellable *cancellable, - GError **error) +ostree_sign_commit (OstreeSign *self, OstreeRepo *repo, const gchar *commit_checksum, + GCancellable *cancellable, GError **error) { - g_autoptr(GBytes) commit_data = NULL; - g_autoptr(GBytes) signature = NULL; - g_autoptr(GVariant) commit_variant = NULL; - g_autoptr(GVariant) old_metadata = NULL; - g_autoptr(GVariant) new_metadata = NULL; + g_autoptr (GBytes) commit_data = NULL; + g_autoptr (GBytes) signature = NULL; + g_autoptr (GVariant) commit_variant = NULL; + g_autoptr (GVariant) old_metadata = NULL; + g_autoptr (GVariant) new_metadata = NULL; - if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, - commit_checksum, &commit_variant, error)) + if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, commit_checksum, &commit_variant, + error)) return glnx_prefix_error (error, "Failed to read commit"); - if (!ostree_repo_read_commit_detached_metadata (repo, - commit_checksum, - &old_metadata, - cancellable, + if (!ostree_repo_read_commit_detached_metadata (repo, commit_checksum, &old_metadata, cancellable, error)) return glnx_prefix_error (error, "Failed to read detached metadata"); commit_data = g_variant_get_data_as_bytes (commit_variant); - if (!ostree_sign_data (self, commit_data, &signature, - cancellable, error)) + if (!ostree_sign_data (self, commit_data, &signature, cancellable, error)) return glnx_prefix_error (error, "Not able to sign the cobject"); - new_metadata = - _sign_detached_metadata_append (self, old_metadata, signature, error); + new_metadata = _sign_detached_metadata_append (self, old_metadata, signature, error); if (new_metadata == NULL) return FALSE; - if (!ostree_repo_write_commit_detached_metadata (repo, - commit_checksum, - new_metadata, - cancellable, + if (!ostree_repo_write_commit_detached_metadata (repo, commit_checksum, new_metadata, cancellable, error)) return FALSE; @@ -549,8 +506,8 @@ ostree_sign_commit (OstreeSign *self, GPtrArray * ostree_sign_get_all (void) { - g_autoptr(GPtrArray) engines = g_ptr_array_new_with_free_func (g_object_unref); - for (guint i = 0; i < G_N_ELEMENTS(sign_types); i++) + g_autoptr (GPtrArray) engines = g_ptr_array_new_with_free_func (g_object_unref); + for (guint i = 0; i < G_N_ELEMENTS (sign_types); i++) { OstreeSign *engine = ostree_sign_get_by_name (sign_types[i].name, NULL); g_assert (engine); @@ -585,37 +542,33 @@ ostree_sign_get_by_name (const gchar *name, GError **error) if (sign_types[SIGN_DUMMY].type == 0) sign_types[SIGN_DUMMY].type = OSTREE_TYPE_SIGN_DUMMY; - for (gint i=0; i < G_N_ELEMENTS(sign_types); i++) - { - if (g_strcmp0 (name, sign_types[i].name) == 0) - { - g_debug ("Using '%s' signing engine", sign_types[i].name); - sign = g_object_new (sign_types[i].type, NULL); - break; - } - } + for (gint i = 0; i < G_N_ELEMENTS (sign_types); i++) + { + if (g_strcmp0 (name, sign_types[i].name) == 0) + { + g_debug ("Using '%s' signing engine", sign_types[i].name); + sign = g_object_new (sign_types[i].type, NULL); + break; + } + } if (sign == NULL) - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Requested signature type is not implemented"); + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, + "Requested signature type is not implemented"); return sign; } gboolean -_ostree_sign_summary_at (OstreeSign *self, - OstreeRepo *repo, - int dir_fd, - GVariant *keys, - GCancellable *cancellable, - GError **error) +_ostree_sign_summary_at (OstreeSign *self, OstreeRepo *repo, int dir_fd, GVariant *keys, + GCancellable *cancellable, GError **error) { g_assert (OSTREE_IS_SIGN (self)); g_assert (OSTREE_IS_REPO (repo)); - g_autoptr(GVariant) normalized = NULL; - g_autoptr(GBytes) summary_data = NULL; - g_autoptr(GVariant) metadata = NULL; + g_autoptr (GVariant) normalized = NULL; + g_autoptr (GBytes) summary_data = NULL; + g_autoptr (GVariant) metadata = NULL; glnx_autofd int fd = -1; if (!glnx_openat_rdonly (dir_fd, "summary", TRUE, &fd, error)) @@ -632,12 +585,11 @@ _ostree_sign_summary_at (OstreeSign *self, if (fd >= 0) { - if (!ot_variant_read_fd (fd, 0, OSTREE_SUMMARY_SIG_GVARIANT_FORMAT, - FALSE, &metadata, error)) + if (!ot_variant_read_fd (fd, 0, OSTREE_SUMMARY_SIG_GVARIANT_FORMAT, FALSE, &metadata, error)) return FALSE; } - if (g_variant_n_children(keys) == 0) + if (g_variant_n_children (keys) == 0) return glnx_throw (error, "No keys passed for signing summary"); GVariantIter *iter; @@ -651,28 +603,20 @@ _ostree_sign_summary_at (OstreeSign *self, if (!ostree_sign_set_sk (self, key, error)) return FALSE; - if (!ostree_sign_data (self, - summary_data, - &signature, - cancellable, - error)) + if (!ostree_sign_data (self, summary_data, &signature, cancellable, error)) return FALSE; - g_autoptr(GVariant) old_metadata = g_steal_pointer (&metadata); - metadata = - _sign_detached_metadata_append (self, old_metadata, signature, error); + g_autoptr (GVariant) old_metadata = g_steal_pointer (&metadata); + metadata = _sign_detached_metadata_append (self, old_metadata, signature, error); if (metadata == NULL) return FALSE; } g_variant_iter_free (iter); normalized = g_variant_get_normal_form (metadata); - if (!_ostree_repo_file_replace_contents (repo, - dir_fd, - "summary.sig", + if (!_ostree_repo_file_replace_contents (repo, dir_fd, "summary.sig", g_variant_get_data (normalized), - g_variant_get_size (normalized), - cancellable, error)) + g_variant_get_size (normalized), cancellable, error)) return FALSE; return TRUE; @@ -694,12 +638,8 @@ _ostree_sign_summary_at (OstreeSign *self, * Since: 2020.2 */ gboolean -ostree_sign_summary (OstreeSign *self, - OstreeRepo *repo, - GVariant *keys, - GCancellable *cancellable, - GError **error) +ostree_sign_summary (OstreeSign *self, OstreeRepo *repo, GVariant *keys, GCancellable *cancellable, + GError **error) { - return _ostree_sign_summary_at (self, repo, repo->repo_dir_fd, keys, - cancellable, error); + return _ostree_sign_summary_at (self, repo, repo->repo_dir_fd, keys, cancellable, error); } diff --git a/src/libostree/ostree-sign.h b/src/libostree/ostree-sign.h index 3a9bcc6a..ba84c565 100644 --- a/src/libostree/ostree-sign.h +++ b/src/libostree/ostree-sign.h @@ -24,8 +24,8 @@ #pragma once -#include #include +#include #include "ostree-ref.h" #include "ostree-remote.h" @@ -42,9 +42,21 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS typedef struct _OstreeSign OstreeSign; typedef struct _OstreeSignInterface OstreeSignInterface; -static inline OstreeSign *OSTREE_SIGN (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_sign_get_type (), OstreeSign); } -static inline gboolean OSTREE_IS_SIGN (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_sign_get_type ()); } -static inline OstreeSignInterface *OSTREE_SIGN_GET_IFACE (gpointer ptr) { return G_TYPE_INSTANCE_GET_INTERFACE (ptr, ostree_sign_get_type (), OstreeSignInterface); } +static inline OstreeSign * +OSTREE_SIGN (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_sign_get_type (), OstreeSign); +} +static inline gboolean +OSTREE_IS_SIGN (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_sign_get_type ()); +} +static inline OstreeSignInterface * +OSTREE_SIGN_GET_IFACE (gpointer ptr) +{ + return G_TYPE_INSTANCE_GET_INTERFACE (ptr, ostree_sign_get_type (), OstreeSignInterface); +} G_GNUC_END_IGNORE_DEPRECATIONS /** @@ -63,109 +75,68 @@ G_DECLARE_INTERFACE (OstreeSign, ostree_sign, OSTREE, SIGN, GObject) struct _OstreeSignInterface { GTypeInterface g_iface; - const gchar *(* get_name) (OstreeSign *self); - gboolean (* data) (OstreeSign *self, - GBytes *data, - GBytes **signature, - GCancellable *cancellable, - GError **error); - gboolean (* data_verify) (OstreeSign *self, - GBytes *data, - GVariant *signatures, - char **out_success_message, - GError **error); - const gchar *(* metadata_key) (OstreeSign *self); - const gchar *(* metadata_format) (OstreeSign *self); - gboolean (* clear_keys) (OstreeSign *self, - GError **error); - gboolean (* set_sk) (OstreeSign *self, - GVariant *secret_key, - GError **error); - gboolean (* set_pk) (OstreeSign *self, - GVariant *public_key, - GError **error); - gboolean (* add_pk) (OstreeSign *self, - GVariant *public_key, - GError **error); - gboolean (* load_pk) (OstreeSign *self, - GVariant *options, - GError **error); + const gchar *(*get_name) (OstreeSign *self); + gboolean (*data) (OstreeSign *self, GBytes *data, GBytes **signature, GCancellable *cancellable, + GError **error); + gboolean (*data_verify) (OstreeSign *self, GBytes *data, GVariant *signatures, + char **out_success_message, GError **error); + const gchar *(*metadata_key) (OstreeSign *self); + const gchar *(*metadata_format) (OstreeSign *self); + gboolean (*clear_keys) (OstreeSign *self, GError **error); + gboolean (*set_sk) (OstreeSign *self, GVariant *secret_key, GError **error); + gboolean (*set_pk) (OstreeSign *self, GVariant *public_key, GError **error); + gboolean (*add_pk) (OstreeSign *self, GVariant *public_key, GError **error); + gboolean (*load_pk) (OstreeSign *self, GVariant *options, GError **error); }; _OSTREE_PUBLIC -const gchar * ostree_sign_get_name (OstreeSign *self); +const gchar *ostree_sign_get_name (OstreeSign *self); _OSTREE_PUBLIC -gboolean ostree_sign_data (OstreeSign *self, - GBytes *data, - GBytes **signature, - GCancellable *cancellable, - GError **error); +gboolean ostree_sign_data (OstreeSign *self, GBytes *data, GBytes **signature, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_sign_data_verify (OstreeSign *self, - GBytes *data, - GVariant *signatures, - char **out_success_message, - GError **error); +gboolean ostree_sign_data_verify (OstreeSign *self, GBytes *data, GVariant *signatures, + char **out_success_message, GError **error); _OSTREE_PUBLIC -const gchar * ostree_sign_metadata_key (OstreeSign *self); +const gchar *ostree_sign_metadata_key (OstreeSign *self); _OSTREE_PUBLIC -const gchar * ostree_sign_metadata_format (OstreeSign *self); +const gchar *ostree_sign_metadata_format (OstreeSign *self); _OSTREE_PUBLIC -gboolean ostree_sign_commit (OstreeSign *self, - OstreeRepo *repo, - const gchar *commit_checksum, - GCancellable *cancellable, - GError **error); +gboolean ostree_sign_commit (OstreeSign *self, OstreeRepo *repo, const gchar *commit_checksum, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_sign_commit_verify (OstreeSign *self, - OstreeRepo *repo, - const gchar *commit_checksum, - char **out_success_message, - GCancellable *cancellable, - GError **error); +gboolean ostree_sign_commit_verify (OstreeSign *self, OstreeRepo *repo, + const gchar *commit_checksum, char **out_success_message, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_sign_clear_keys (OstreeSign *self, - GError **error); +gboolean ostree_sign_clear_keys (OstreeSign *self, GError **error); _OSTREE_PUBLIC -gboolean ostree_sign_set_sk (OstreeSign *self, - GVariant *secret_key, - GError **error); +gboolean ostree_sign_set_sk (OstreeSign *self, GVariant *secret_key, GError **error); _OSTREE_PUBLIC -gboolean ostree_sign_set_pk (OstreeSign *self, - GVariant *public_key, - GError **error); +gboolean ostree_sign_set_pk (OstreeSign *self, GVariant *public_key, GError **error); _OSTREE_PUBLIC -gboolean ostree_sign_add_pk (OstreeSign *self, - GVariant *public_key, - GError **error); +gboolean ostree_sign_add_pk (OstreeSign *self, GVariant *public_key, GError **error); _OSTREE_PUBLIC -gboolean ostree_sign_load_pk (OstreeSign *self, - GVariant *options, - GError **error); - +gboolean ostree_sign_load_pk (OstreeSign *self, GVariant *options, GError **error); _OSTREE_PUBLIC -GPtrArray * ostree_sign_get_all(void); +GPtrArray *ostree_sign_get_all (void); _OSTREE_PUBLIC -OstreeSign * ostree_sign_get_by_name (const gchar *name, GError **error); +OstreeSign *ostree_sign_get_by_name (const gchar *name, GError **error); _OSTREE_PUBLIC -gboolean ostree_sign_summary (OstreeSign *self, - OstreeRepo *repo, - GVariant *keys, - GCancellable *cancellable, - GError **error); +gboolean ostree_sign_summary (OstreeSign *self, OstreeRepo *repo, GVariant *keys, + GCancellable *cancellable, GError **error); G_END_DECLS - diff --git a/src/libostree/ostree-sysroot-cleanup.c b/src/libostree/ostree-sysroot-cleanup.c index 533a4fdd..090b0044 100644 --- a/src/libostree/ostree-sysroot-cleanup.c +++ b/src/libostree/ostree-sysroot-cleanup.c @@ -19,9 +19,9 @@ #include "config.h" -#include "otutil.h" -#include "ostree-repo-private.h" #include "ostree-linuxfsutil.h" +#include "ostree-repo-private.h" +#include "otutil.h" #include "ostree-sysroot-private.h" @@ -30,13 +30,13 @@ * @inout_deployments: All deployments in this subdir will be appended to this array */ gboolean -_ostree_sysroot_list_deployment_dirs_for_os (int deploydir_dfd, - const char *osname, - GPtrArray *inout_deployments, - GCancellable *cancellable, - GError **error) +_ostree_sysroot_list_deployment_dirs_for_os (int deploydir_dfd, const char *osname, + GPtrArray *inout_deployments, + GCancellable *cancellable, GError **error) { - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; gboolean exists; const char *osdeploy_path = glnx_strjoina (osname, "/deploy"); if (!ot_dfd_iter_init_allow_noent (deploydir_dfd, osdeploy_path, &dfd_iter, &exists, error)) @@ -61,7 +61,8 @@ _ostree_sysroot_list_deployment_dirs_for_os (int deploydir_dfd, if (!_ostree_sysroot_parse_deploy_path_name (dent->d_name, &csum, &deployserial, error)) return FALSE; - g_ptr_array_add (inout_deployments, ostree_deployment_new (-1, osname, csum, deployserial, NULL, -1)); + g_ptr_array_add (inout_deployments, + ostree_deployment_new (-1, osname, csum, deployserial, NULL, -1)); } return TRUE; @@ -71,15 +72,14 @@ _ostree_sysroot_list_deployment_dirs_for_os (int deploydir_dfd, * filesystem state. */ static gboolean -list_all_deployment_directories (OstreeSysroot *self, - GPtrArray **out_deployments, - GCancellable *cancellable, - GError **error) +list_all_deployment_directories (OstreeSysroot *self, GPtrArray **out_deployments, + GCancellable *cancellable, GError **error) { - g_autoptr(GPtrArray) ret_deployments = - g_ptr_array_new_with_free_func (g_object_unref); + g_autoptr (GPtrArray) ret_deployments = g_ptr_array_new_with_free_func (g_object_unref); - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; gboolean exists; if (!ot_dfd_iter_init_allow_noent (self->sysroot_fd, "ostree/deploy", &dfd_iter, &exists, error)) return FALSE; @@ -98,8 +98,7 @@ list_all_deployment_directories (OstreeSysroot *self, if (dent->d_type != DT_DIR) continue; - if (!_ostree_sysroot_list_deployment_dirs_for_os (dfd_iter.fd, dent->d_name, - ret_deployments, + if (!_ostree_sysroot_list_deployment_dirs_for_os (dfd_iter.fd, dent->d_name, ret_deployments, cancellable, error)) return FALSE; } @@ -109,9 +108,7 @@ list_all_deployment_directories (OstreeSysroot *self, } gboolean -_ostree_sysroot_parse_bootdir_name (const char *name, - char **out_osname, - char **out_csum) +_ostree_sysroot_parse_bootdir_name (const char *name, char **out_osname, char **out_csum) { const char *lastdash; @@ -137,16 +134,17 @@ _ostree_sysroot_parse_bootdir_name (const char *name, } gboolean -_ostree_sysroot_list_all_boot_directories (OstreeSysroot *self, - char ***out_bootdirs, - GCancellable *cancellable, - GError **error) +_ostree_sysroot_list_all_boot_directories (OstreeSysroot *self, char ***out_bootdirs, + GCancellable *cancellable, GError **error) { - g_autoptr(GPtrArray) ret_bootdirs = g_ptr_array_new_with_free_func (g_free); + g_autoptr (GPtrArray) ret_bootdirs = g_ptr_array_new_with_free_func (g_free); gboolean exists = FALSE; - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; - if (self->boot_fd >= 0 && !ot_dfd_iter_init_allow_noent (self->boot_fd, "ostree", &dfd_iter, &exists, error)) + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; + if (self->boot_fd >= 0 + && !ot_dfd_iter_init_allow_noent (self->boot_fd, "ostree", &dfd_iter, &exists, error)) return FALSE; while (exists) @@ -170,7 +168,7 @@ _ostree_sysroot_list_all_boot_directories (OstreeSysroot *self, } g_ptr_array_add (ret_bootdirs, NULL); - *out_bootdirs = (char**)g_ptr_array_free (g_steal_pointer (&ret_bootdirs), FALSE); + *out_bootdirs = (char **)g_ptr_array_free (g_steal_pointer (&ret_bootdirs), FALSE); return TRUE; } @@ -179,31 +177,34 @@ _ostree_sysroot_list_all_boot_directories (OstreeSysroot *self, * other versions that aren't active. */ static gboolean -cleanup_other_bootversions (OstreeSysroot *self, - GCancellable *cancellable, - GError **error) +cleanup_other_bootversions (OstreeSysroot *self, GCancellable *cancellable, GError **error) { const int cleanup_bootversion = self->bootversion == 0 ? 1 : 0; const int cleanup_subbootversion = self->subbootversion == 0 ? 1 : 0; /* Reusable buffer for path */ - g_autoptr(GString) buf = g_string_new (""); + g_autoptr (GString) buf = g_string_new (""); /* These directories are for the other major version */ - g_string_truncate (buf, 0); g_string_append_printf (buf, "boot/loader.%d", cleanup_bootversion); + g_string_truncate (buf, 0); + g_string_append_printf (buf, "boot/loader.%d", cleanup_bootversion); if (!glnx_shutil_rm_rf_at (self->sysroot_fd, buf->str, cancellable, error)) return FALSE; - g_string_truncate (buf, 0); g_string_append_printf (buf, "ostree/boot.%d", cleanup_bootversion); + g_string_truncate (buf, 0); + g_string_append_printf (buf, "ostree/boot.%d", cleanup_bootversion); if (!glnx_shutil_rm_rf_at (self->sysroot_fd, buf->str, cancellable, error)) return FALSE; - g_string_truncate (buf, 0); g_string_append_printf (buf, "ostree/boot.%d.0", cleanup_bootversion); + g_string_truncate (buf, 0); + g_string_append_printf (buf, "ostree/boot.%d.0", cleanup_bootversion); if (!glnx_shutil_rm_rf_at (self->sysroot_fd, buf->str, cancellable, error)) return FALSE; - g_string_truncate (buf, 0); g_string_append_printf (buf, "ostree/boot.%d.1", cleanup_bootversion); + g_string_truncate (buf, 0); + g_string_append_printf (buf, "ostree/boot.%d.1", cleanup_bootversion); if (!glnx_shutil_rm_rf_at (self->sysroot_fd, buf->str, cancellable, error)) return FALSE; /* And finally the other subbootversion */ - g_string_truncate (buf, 0); g_string_append_printf (buf, "ostree/boot.%d.%d", self->bootversion, cleanup_subbootversion); + g_string_truncate (buf, 0); + g_string_append_printf (buf, "ostree/boot.%d.%d", self->bootversion, cleanup_subbootversion); if (!glnx_shutil_rm_rf_at (self->sysroot_fd, buf->str, cancellable, error)) return FALSE; @@ -212,18 +213,15 @@ cleanup_other_bootversions (OstreeSysroot *self, /* Delete a deployment directory */ gboolean -_ostree_sysroot_rmrf_deployment (OstreeSysroot *self, - OstreeDeployment *deployment, - GCancellable *cancellable, - GError **error) +_ostree_sysroot_rmrf_deployment (OstreeSysroot *self, OstreeDeployment *deployment, + GCancellable *cancellable, GError **error) { g_autofree char *origin_relpath = ostree_deployment_get_origin_relpath (deployment); g_autofree char *deployment_path = ostree_sysroot_get_deployment_dirpath (self, deployment); struct stat stbuf; glnx_autofd int deployment_fd = -1; - if (!glnx_opendirat (self->sysroot_fd, deployment_path, TRUE, - &deployment_fd, error)) + if (!glnx_opendirat (self->sysroot_fd, deployment_path, TRUE, &deployment_fd, error)) return FALSE; if (!glnx_fstat (deployment_fd, &stbuf, error)) @@ -232,13 +230,11 @@ _ostree_sysroot_rmrf_deployment (OstreeSysroot *self, /* This shouldn't happen, because higher levels should * disallow having the booted deployment not in the active * deployment list, but let's be extra safe. */ - if (stbuf.st_dev == self->root_device && - stbuf.st_ino == self->root_inode) + if (stbuf.st_dev == self->root_device && stbuf.st_ino == self->root_inode) return TRUE; /* This deployment wasn't referenced, so delete it */ - if (!_ostree_linuxfs_fd_alter_immutable_flag (deployment_fd, FALSE, - cancellable, error)) + if (!_ostree_linuxfs_fd_alter_immutable_flag (deployment_fd, FALSE, cancellable, error)) return FALSE; if (!glnx_shutil_rm_rf_at (self->sysroot_fd, origin_relpath, cancellable, error)) return FALSE; @@ -253,13 +249,11 @@ _ostree_sysroot_rmrf_deployment (OstreeSysroot *self, * referenced. */ static gboolean -cleanup_old_deployments (OstreeSysroot *self, - GCancellable *cancellable, - GError **error) +cleanup_old_deployments (OstreeSysroot *self, GCancellable *cancellable, GError **error) { /* Load all active deployments referenced by bootloader configuration. */ - g_autoptr(GHashTable) active_deployment_dirs = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + g_autoptr (GHashTable) active_deployment_dirs + = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); for (guint i = 0; i < self->deployments->len; i++) { OstreeDeployment *deployment = self->deployments->pdata[i]; @@ -269,9 +263,8 @@ cleanup_old_deployments (OstreeSysroot *self, } /* Find all deployment directories, both active and inactive */ - g_autoptr(GPtrArray) all_deployment_dirs = NULL; - if (!list_all_deployment_directories (self, &all_deployment_dirs, - cancellable, error)) + g_autoptr (GPtrArray) all_deployment_dirs = NULL; + if (!list_all_deployment_directories (self, &all_deployment_dirs, cancellable, error)) return FALSE; g_assert (all_deployment_dirs); /* Pacify static analysis */ for (guint i = 0; i < all_deployment_dirs->len; i++) @@ -293,15 +286,13 @@ cleanup_old_deployments (OstreeSysroot *self, * bootloader configuration. */ gboolean -_ostree_sysroot_cleanup_bootfs (OstreeSysroot *self, - GCancellable *cancellable, - GError **error) +_ostree_sysroot_cleanup_bootfs (OstreeSysroot *self, GCancellable *cancellable, GError **error) { /* Load all active bootcsums and overlays referenced by bootloader configuration. */ - g_autoptr(GHashTable) active_boot_checksums = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - g_autoptr(GHashTable) active_overlay_initrds = - g_hash_table_new (g_str_hash, g_str_equal); /* borrows from deployment's bootconfig */ + g_autoptr (GHashTable) active_boot_checksums + = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + g_autoptr (GHashTable) active_overlay_initrds + = g_hash_table_new (g_str_hash, g_str_equal); /* borrows from deployment's bootconfig */ for (guint i = 0; i < self->deployments->len; i++) { OstreeDeployment *deployment = self->deployments->pdata[i]; @@ -312,11 +303,11 @@ _ostree_sysroot_cleanup_bootfs (OstreeSysroot *self, OstreeBootconfigParser *bootconfig = ostree_deployment_get_bootconfig (deployment); char **initrds = ostree_bootconfig_parser_get_overlay_initrds (bootconfig); for (char **it = initrds; it && *it; it++) - g_hash_table_add (active_overlay_initrds, (char*)glnx_basename (*it)); + g_hash_table_add (active_overlay_initrds, (char *)glnx_basename (*it)); } /* Clean up boot directories */ - g_auto(GStrv) all_boot_dirs = NULL; + g_auto (GStrv) all_boot_dirs = NULL; if (!_ostree_sysroot_list_all_boot_directories (self, &all_boot_dirs, cancellable, error)) return FALSE; @@ -337,8 +328,8 @@ _ostree_sysroot_cleanup_bootfs (OstreeSysroot *self, } /* Clean up overlay initrds */ - glnx_autofd int overlays_dfd = - glnx_opendirat_with_errno (self->sysroot_fd, _OSTREE_SYSROOT_INITRAMFS_OVERLAYS, FALSE); + glnx_autofd int overlays_dfd + = glnx_opendirat_with_errno (self->sysroot_fd, _OSTREE_SYSROOT_INITRAMFS_OVERLAYS, FALSE); if (overlays_dfd < 0) { if (errno != ENOENT) @@ -346,8 +337,10 @@ _ostree_sysroot_cleanup_bootfs (OstreeSysroot *self, } else { - g_autoptr(GPtrArray) initrds_to_delete = g_ptr_array_new_with_free_func (g_free); - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; + g_autoptr (GPtrArray) initrds_to_delete = g_ptr_array_new_with_free_func (g_free); + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; if (!glnx_dirfd_iterator_init_at (overlays_dfd, ".", TRUE, &dfd_iter, error)) return FALSE; while (TRUE) @@ -377,15 +370,13 @@ _ostree_sysroot_cleanup_bootfs (OstreeSysroot *self, /* Delete the ref bindings for a non-active boot version */ static gboolean -cleanup_ref_prefix (OstreeRepo *repo, - int bootversion, - int subbootversion, - GCancellable *cancellable, - GError **error) +cleanup_ref_prefix (OstreeRepo *repo, int bootversion, int subbootversion, + GCancellable *cancellable, GError **error) { g_autofree char *prefix = g_strdup_printf ("ostree/%d/%d", bootversion, subbootversion); - g_autoptr(GHashTable) refs = NULL; - if (!ostree_repo_list_refs_ext (repo, prefix, &refs, OSTREE_REPO_LIST_REFS_EXT_NONE, cancellable, error)) + g_autoptr (GHashTable) refs = NULL; + if (!ostree_repo_list_refs_ext (repo, prefix, &refs, OSTREE_REPO_LIST_REFS_EXT_NONE, cancellable, + error)) return FALSE; GLNX_HASH_TABLE_FOREACH (refs, const char *, ref) @@ -402,39 +393,31 @@ cleanup_ref_prefix (OstreeRepo *repo, * to match active deployments. */ static gboolean -generate_deployment_refs (OstreeSysroot *self, - OstreeRepo *repo, - int bootversion, - int subbootversion, - GPtrArray *deployments, - GCancellable *cancellable, - GError **error) +generate_deployment_refs (OstreeSysroot *self, OstreeRepo *repo, int bootversion, + int subbootversion, GPtrArray *deployments, GCancellable *cancellable, + GError **error) { int cleanup_bootversion = (bootversion == 0) ? 1 : 0; int cleanup_subbootversion = (subbootversion == 0) ? 1 : 0; - if (!cleanup_ref_prefix (repo, cleanup_bootversion, 0, - cancellable, error)) + if (!cleanup_ref_prefix (repo, cleanup_bootversion, 0, cancellable, error)) return FALSE; - if (!cleanup_ref_prefix (repo, cleanup_bootversion, 1, - cancellable, error)) + if (!cleanup_ref_prefix (repo, cleanup_bootversion, 1, cancellable, error)) return FALSE; - if (!cleanup_ref_prefix (repo, bootversion, cleanup_subbootversion, - cancellable, error)) + if (!cleanup_ref_prefix (repo, bootversion, cleanup_subbootversion, cancellable, error)) return FALSE; - g_autoptr(OstreeRepoAutoTransaction) txn = - _ostree_repo_auto_transaction_start (repo, cancellable, error); + g_autoptr (OstreeRepoAutoTransaction) txn + = _ostree_repo_auto_transaction_start (repo, cancellable, error); if (!txn) return FALSE; for (guint i = 0; i < deployments->len; i++) { OstreeDeployment *deployment = deployments->pdata[i]; - g_autofree char *refname = g_strdup_printf ("ostree/%d/%d/%u", - bootversion, subbootversion, - i); + g_autofree char *refname + = g_strdup_printf ("ostree/%d/%d/%u", bootversion, subbootversion, i); ostree_repo_transaction_set_refspec (repo, refname, ostree_deployment_get_csum (deployment)); } @@ -466,13 +449,10 @@ generate_deployment_refs (OstreeSysroot *self, * Since: 2018.6 */ gboolean -ostree_sysroot_cleanup_prune_repo (OstreeSysroot *sysroot, - OstreeRepoPruneOptions *options, - gint *out_objects_total, - gint *out_objects_pruned, - guint64 *out_pruned_object_size_total, - GCancellable *cancellable, - GError **error) +ostree_sysroot_cleanup_prune_repo (OstreeSysroot *sysroot, OstreeRepoPruneOptions *options, + gint *out_objects_total, gint *out_objects_pruned, + guint64 *out_pruned_object_size_total, GCancellable *cancellable, + GError **error) { GLNX_AUTO_PREFIX_ERROR ("Pruning system repository", error); OstreeRepo *repo = ostree_sysroot_repo (sysroot); @@ -484,8 +464,8 @@ ostree_sysroot_cleanup_prune_repo (OstreeSysroot *sysroot, /* Hold an exclusive lock by default across gathering refs and doing * the prune. */ - g_autoptr(OstreeRepoAutoLock) lock = - ostree_repo_auto_lock_push (repo, OSTREE_REPO_LOCK_EXCLUSIVE, cancellable, error); + g_autoptr (OstreeRepoAutoLock) lock + = ostree_repo_auto_lock_push (repo, OSTREE_REPO_LOCK_EXCLUSIVE, cancellable, error); if (!lock) return FALSE; @@ -511,10 +491,8 @@ ostree_sysroot_cleanup_prune_repo (OstreeSysroot *sysroot, return FALSE; } - if (!ostree_repo_prune_from_reachable (repo, options, - out_objects_total, out_objects_pruned, - out_pruned_object_size_total, - cancellable, error)) + if (!ostree_repo_prune_from_reachable (repo, options, out_objects_total, out_objects_pruned, + out_pruned_object_size_total, cancellable, error)) return FALSE; return TRUE; @@ -530,9 +508,7 @@ ostree_sysroot_cleanup_prune_repo (OstreeSysroot *sysroot, * transaction, such as incomplete deployments. */ gboolean -ostree_sysroot_cleanup (OstreeSysroot *self, - GCancellable *cancellable, - GError **error) +ostree_sysroot_cleanup (OstreeSysroot *self, GCancellable *cancellable, GError **error) { return _ostree_sysroot_cleanup_internal (self, TRUE, cancellable, error); } @@ -547,18 +523,14 @@ ostree_sysroot_cleanup (OstreeSysroot *self, * and old boot versions, but does NOT prune the repository. */ gboolean -ostree_sysroot_prepare_cleanup (OstreeSysroot *self, - GCancellable *cancellable, - GError **error) +ostree_sysroot_prepare_cleanup (OstreeSysroot *self, GCancellable *cancellable, GError **error) { return _ostree_sysroot_cleanup_internal (self, FALSE, cancellable, error); } gboolean -_ostree_sysroot_cleanup_internal (OstreeSysroot *self, - gboolean do_prune_repo, - GCancellable *cancellable, - GError **error) +_ostree_sysroot_cleanup_internal (OstreeSysroot *self, gboolean do_prune_repo, + GCancellable *cancellable, GError **error) { g_assert (OSTREE_IS_SYSROOT (self)); g_assert (self->loadstate == OSTREE_SYSROOT_LOAD_STATE_LOADED); @@ -576,11 +548,8 @@ _ostree_sysroot_cleanup_internal (OstreeSysroot *self, return glnx_prefix_error (error, "Cleaning bootfs"); OstreeRepo *repo = ostree_sysroot_repo (self); - if (!generate_deployment_refs (self, repo, - self->bootversion, - self->subbootversion, - self->deployments, - cancellable, error)) + if (!generate_deployment_refs (self, repo, self->bootversion, self->subbootversion, + self->deployments, cancellable, error)) return glnx_prefix_error (error, "Generating deployment refs"); if (do_prune_repo) @@ -588,11 +557,10 @@ _ostree_sysroot_cleanup_internal (OstreeSysroot *self, gint n_objects_total; gint n_objects_pruned; guint64 freed_space; - g_autoptr(GHashTable) reachable = ostree_repo_traverse_new_reachable (); + g_autoptr (GHashTable) reachable = ostree_repo_traverse_new_reachable (); OstreeRepoPruneOptions opts = { OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY, reachable }; - if (!ostree_sysroot_cleanup_prune_repo (self, &opts, &n_objects_total, - &n_objects_pruned, &freed_space, - cancellable, error)) + if (!ostree_sysroot_cleanup_prune_repo (self, &opts, &n_objects_total, &n_objects_pruned, + &freed_space, cancellable, error)) return FALSE; /* TODO remove printf in library */ diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index 0bd119fa..b87866ff 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -19,17 +19,17 @@ #include "config.h" +#include #include #include #include +#include #include -#include -#include -#include #include -#include +#include #include -#include +#include +#include #ifdef HAVE_LIBMOUNT #include @@ -38,21 +38,25 @@ #include #endif -#include "otutil.h" -#include "ostree.h" -#include "ostree-repo-private.h" -#include "ostree-sysroot-private.h" -#include "ostree-sepolicy-private.h" -#include "ostree-deployment-private.h" +#include "libglnx.h" #include "ostree-core-private.h" +#include "ostree-deployment-private.h" #include "ostree-linuxfsutil.h" -#include "libglnx.h" +#include "ostree-repo-private.h" +#include "ostree-sepolicy-private.h" +#include "ostree-sysroot-private.h" +#include "ostree.h" +#include "otutil.h" #ifdef HAVE_LIBSYSTEMD -#define OSTREE_VARRELABEL_ID SD_ID128_MAKE(da,67,9b,08,ac,d3,45,04,b7,89,d9,6f,81,8e,a7,81) -#define OSTREE_CONFIGMERGE_ID SD_ID128_MAKE(d3,86,3b,ae,c1,3e,44,49,ab,03,84,68,4a,8a,f3,a7) -#define OSTREE_DEPLOYMENT_COMPLETE_ID SD_ID128_MAKE(dd,44,0e,3e,54,90,83,b6,3d,0e,fc,7d,c1,52,55,f1) -#define OSTREE_DEPLOYMENT_FINALIZING_ID SD_ID128_MAKE(e8,64,6c,d6,3d,ff,46,25,b7,79,09,a8,e7,a4,09,94) +#define OSTREE_VARRELABEL_ID \ + SD_ID128_MAKE (da, 67, 9b, 08, ac, d3, 45, 04, b7, 89, d9, 6f, 81, 8e, a7, 81) +#define OSTREE_CONFIGMERGE_ID \ + SD_ID128_MAKE (d3, 86, 3b, ae, c1, 3e, 44, 49, ab, 03, 84, 68, 4a, 8a, f3, a7) +#define OSTREE_DEPLOYMENT_COMPLETE_ID \ + SD_ID128_MAKE (dd, 44, 0e, 3e, 54, 90, 83, b6, 3d, 0e, fc, 7d, c1, 52, 55, f1) +#define OSTREE_DEPLOYMENT_FINALIZING_ID \ + SD_ID128_MAKE (e8, 64, 6c, d6, 3d, ff, 46, 25, b7, 79, 09, a8, e7, a4, 09, 94) #endif /* @@ -60,11 +64,8 @@ * symlink. */ static gboolean -symlink_at_replace (const char *oldpath, - int parent_dfd, - const char *newpath, - GCancellable *cancellable, - GError **error) +symlink_at_replace (const char *oldpath, int parent_dfd, const char *newpath, + GCancellable *cancellable, GError **error) { /* Possibly in the future generate a temporary random name here, * would need to move "generate a temporary name" code into @@ -73,7 +74,7 @@ symlink_at_replace (const char *oldpath, g_autofree char *temppath = g_strconcat (newpath, ".tmp", NULL); /* Clean up any stale temporary links */ - (void) unlinkat (parent_dfd, temppath, 0); + (void)unlinkat (parent_dfd, temppath, 0); /* Create the temp link */ if (TEMP_FAILURE_RETRY (symlinkat (oldpath, parent_dfd, temppath)) < 0) @@ -87,8 +88,7 @@ symlink_at_replace (const char *oldpath, } static GLnxFileCopyFlags -sysroot_flags_to_copy_flags (GLnxFileCopyFlags defaults, - OstreeSysrootDebugFlags sysrootflags) +sysroot_flags_to_copy_flags (GLnxFileCopyFlags defaults, OstreeSysrootDebugFlags sysrootflags) { if (sysrootflags & OSTREE_SYSROOT_DEBUG_NO_XATTRS) defaults |= GLNX_FILE_COPY_NOXATTRS; @@ -100,14 +100,9 @@ sysroot_flags_to_copy_flags (GLnxFileCopyFlags defaults, * hardlink if we're on the same partition. */ static gboolean -install_into_boot (OstreeRepo *repo, - OstreeSePolicy *sepolicy, - int src_dfd, - const char *src_subpath, - int dest_dfd, - const char *dest_subpath, - GCancellable *cancellable, - GError **error) +install_into_boot (OstreeRepo *repo, OstreeSePolicy *sepolicy, int src_dfd, const char *src_subpath, + int dest_dfd, const char *dest_subpath, GCancellable *cancellable, + GError **error) { if (linkat (src_dfd, src_subpath, dest_dfd, dest_subpath, 0) == 0) return TRUE; /* Note early return */ @@ -124,27 +119,30 @@ install_into_boot (OstreeRepo *repo, return FALSE; /* Be sure we relabel when copying the kernel, as in current - * e.g. Fedora it might be labeled module_object_t or usr_t, - * but policy may not allow other processes to read from that - * like kdump. - * See also https://github.com/fedora-selinux/selinux-policy/commit/747f4e6775d773ab74efae5aa37f3e5e7f0d4aca - * This means we also drop xattrs but...I doubt anyone uses - * non-SELinux xattrs for the kernel anyways aside from perhaps - * IMA but that's its own story. - */ - g_auto(OstreeSepolicyFsCreatecon) fscreatecon = { 0, }; + * e.g. Fedora it might be labeled module_object_t or usr_t, + * but policy may not allow other processes to read from that + * like kdump. + * See also + * https://github.com/fedora-selinux/selinux-policy/commit/747f4e6775d773ab74efae5aa37f3e5e7f0d4aca + * This means we also drop xattrs but...I doubt anyone uses + * non-SELinux xattrs for the kernel anyways aside from perhaps + * IMA but that's its own story. + */ + g_auto (OstreeSepolicyFsCreatecon) fscreatecon = { + 0, + }; const char *boot_path = glnx_strjoina ("/boot/", glnx_basename (dest_subpath)); - if (!_ostree_sepolicy_preparefscreatecon (&fscreatecon, sepolicy, - boot_path, S_IFREG | 0644, + if (!_ostree_sepolicy_preparefscreatecon (&fscreatecon, sepolicy, boot_path, S_IFREG | 0644, error)) return FALSE; - g_auto(GLnxTmpfile) tmp_dest = { 0, }; - if (!glnx_open_tmpfile_linkable_at (dest_dfd, ".", O_WRONLY | O_CLOEXEC, - &tmp_dest, error)) + g_auto (GLnxTmpfile) tmp_dest = { + 0, + }; + if (!glnx_open_tmpfile_linkable_at (dest_dfd, ".", O_WRONLY | O_CLOEXEC, &tmp_dest, error)) return FALSE; - if (glnx_regfile_copy_bytes (src_fd, tmp_dest.fd, (off_t) -1) < 0) + if (glnx_regfile_copy_bytes (src_fd, tmp_dest.fd, (off_t)-1) < 0) return glnx_throw_errno_prefix (error, "regfile copy"); /* Kernel data should always be root-owned */ @@ -176,15 +174,11 @@ install_into_boot (OstreeRepo *repo, /* Copy ownership, mode, and xattrs from source directory to destination */ static gboolean -dirfd_copy_attributes_and_xattrs (int src_parent_dfd, - const char *src_name, - int src_dfd, - int dest_dfd, - OstreeSysrootDebugFlags flags, - GCancellable *cancellable, - GError **error) +dirfd_copy_attributes_and_xattrs (int src_parent_dfd, const char *src_name, int src_dfd, + int dest_dfd, OstreeSysrootDebugFlags flags, + GCancellable *cancellable, GError **error) { - g_autoptr(GVariant) xattrs = NULL; + g_autoptr (GVariant) xattrs = NULL; /* Clone all xattrs first, so we get the SELinux security context * right. This will allow other users access if they have ACLs, but @@ -192,11 +186,9 @@ dirfd_copy_attributes_and_xattrs (int src_parent_dfd, */ if (!(flags & OSTREE_SYSROOT_DEBUG_NO_XATTRS)) { - if (!glnx_dfd_name_get_all_xattrs (src_parent_dfd, src_name, - &xattrs, cancellable, error)) + if (!glnx_dfd_name_get_all_xattrs (src_parent_dfd, src_name, &xattrs, cancellable, error)) return FALSE; - if (!glnx_fd_set_all_xattrs (dest_dfd, xattrs, - cancellable, error)) + if (!glnx_fd_set_all_xattrs (dest_dfd, xattrs, cancellable, error)) return FALSE; } @@ -214,20 +206,19 @@ dirfd_copy_attributes_and_xattrs (int src_parent_dfd, static gint str_sort_cb (gconstpointer name_ptr_a, gconstpointer name_ptr_b) { - const gchar *name_a = *((const gchar **) name_ptr_a); - const gchar *name_b = *((const gchar **) name_ptr_b); + const gchar *name_a = *((const gchar **)name_ptr_a); + const gchar *name_b = *((const gchar **)name_ptr_b); return g_strcmp0 (name_a, name_b); } static gboolean -checksum_dir_recurse (int dfd, - const char *path, - OtChecksum *checksum, - GCancellable *cancellable, - GError **error) +checksum_dir_recurse (int dfd, const char *path, OtChecksum *checksum, GCancellable *cancellable, + GError **error) { - g_auto(GLnxDirFdIterator) dfditer = { 0, }; + g_auto (GLnxDirFdIterator) dfditer = { + 0, + }; g_autoptr (GPtrArray) d_entries = g_ptr_array_new_with_free_func (g_free); if (!glnx_dirfd_iterator_init_at (dfd, path, TRUE, &dfditer, error)) @@ -249,20 +240,19 @@ checksum_dir_recurse (int dfd, /* File systems do not guarantee dir entry order, make sure this is * reproducable */ - g_ptr_array_sort(d_entries, str_sort_cb); + g_ptr_array_sort (d_entries, str_sort_cb); - for (gint i=0; i < d_entries->len; i++) + for (gint i = 0; i < d_entries->len; i++) { const gchar *d_name = (gchar *)g_ptr_array_index (d_entries, i); struct stat stbuf; - if (!glnx_fstatat (dfditer.fd, d_name, &stbuf, - AT_SYMLINK_NOFOLLOW, error)) + if (!glnx_fstatat (dfditer.fd, d_name, &stbuf, AT_SYMLINK_NOFOLLOW, error)) return FALSE; if (S_ISDIR (stbuf.st_mode)) { - if (!checksum_dir_recurse(dfditer.fd, d_name, checksum, cancellable, error)) + if (!checksum_dir_recurse (dfditer.fd, d_name, checksum, cancellable, error)) return FALSE; } else @@ -273,26 +263,23 @@ checksum_dir_recurse (int dfd, return FALSE; if (fd != -1) { - g_autoptr(GInputStream) in = g_unix_input_stream_new (g_steal_fd (&fd), TRUE); + g_autoptr (GInputStream) in = g_unix_input_stream_new (g_steal_fd (&fd), TRUE); if (!ot_gio_splice_update_checksum (NULL, in, checksum, cancellable, error)) return FALSE; } } - } return TRUE; } static gboolean -copy_dir_recurse (int src_parent_dfd, - int dest_parent_dfd, - const char *name, - OstreeSysrootDebugFlags flags, - GCancellable *cancellable, - GError **error) -{ - g_auto(GLnxDirFdIterator) src_dfd_iter = { 0, }; +copy_dir_recurse (int src_parent_dfd, int dest_parent_dfd, const char *name, + OstreeSysrootDebugFlags flags, GCancellable *cancellable, GError **error) +{ + g_auto (GLnxDirFdIterator) src_dfd_iter = { + 0, + }; glnx_autofd int dest_dfd = -1; struct dirent *dent; @@ -306,8 +293,8 @@ copy_dir_recurse (int src_parent_dfd, if (!glnx_opendirat (dest_parent_dfd, name, TRUE, &dest_dfd, error)) return FALSE; - if (!dirfd_copy_attributes_and_xattrs (src_parent_dfd, name, src_dfd_iter.fd, dest_dfd, - flags, cancellable, error)) + if (!dirfd_copy_attributes_and_xattrs (src_parent_dfd, name, src_dfd_iter.fd, dest_dfd, flags, + cancellable, error)) return glnx_prefix_error (error, "Copying attributes of %s", name); while (TRUE) @@ -319,20 +306,19 @@ copy_dir_recurse (int src_parent_dfd, if (dent == NULL) break; - if (!glnx_fstatat (src_dfd_iter.fd, dent->d_name, &child_stbuf, - AT_SYMLINK_NOFOLLOW, error)) + if (!glnx_fstatat (src_dfd_iter.fd, dent->d_name, &child_stbuf, AT_SYMLINK_NOFOLLOW, error)) return FALSE; if (S_ISDIR (child_stbuf.st_mode)) { - if (!copy_dir_recurse (src_dfd_iter.fd, dest_dfd, dent->d_name, - flags, cancellable, error)) + if (!copy_dir_recurse (src_dfd_iter.fd, dest_dfd, dent->d_name, flags, cancellable, + error)) return FALSE; } else { - if (!glnx_file_copy_at (src_dfd_iter.fd, dent->d_name, &child_stbuf, - dest_dfd, dent->d_name, + if (!glnx_file_copy_at (src_dfd_iter.fd, dent->d_name, &child_stbuf, dest_dfd, + dent->d_name, sysroot_flags_to_copy_flags (GLNX_FILE_COPY_OVERWRITE, flags), cancellable, error)) return glnx_prefix_error (error, "Copying %s", dent->d_name); @@ -346,14 +332,9 @@ copy_dir_recurse (int src_parent_dfd, * they're created. */ static gboolean -ensure_directory_from_template (int orig_etc_fd, - int modified_etc_fd, - int new_etc_fd, - const char *path, - int *out_dfd, - OstreeSysrootDebugFlags flags, - GCancellable *cancellable, - GError **error) +ensure_directory_from_template (int orig_etc_fd, int modified_etc_fd, int new_etc_fd, + const char *path, int *out_dfd, OstreeSysrootDebugFlags flags, + GCancellable *cancellable, GError **error) { glnx_autofd int src_dfd = -1; glnx_autofd int target_dfd = -1; @@ -365,7 +346,7 @@ ensure_directory_from_template (int orig_etc_fd, return FALSE; /* Create with mode 0700, we'll fchmod/fchown later */ - again: +again: if (mkdirat (new_etc_fd, path, 0700) != 0) { if (errno == EEXIST) @@ -398,8 +379,8 @@ ensure_directory_from_template (int orig_etc_fd, if (!glnx_opendirat (new_etc_fd, path, TRUE, &target_dfd, error)) return FALSE; - if (!dirfd_copy_attributes_and_xattrs (modified_etc_fd, path, src_dfd, target_dfd, - flags, cancellable, error)) + if (!dirfd_copy_attributes_and_xattrs (modified_etc_fd, path, src_dfd, target_dfd, flags, + cancellable, error)) return FALSE; if (out_dfd) @@ -412,13 +393,8 @@ ensure_directory_from_template (int orig_etc_fd, * or a directory. Directories will be copied recursively. */ static gboolean -copy_modified_config_file (int orig_etc_fd, - int modified_etc_fd, - int new_etc_fd, - const char *path, - OstreeSysrootDebugFlags flags, - GCancellable *cancellable, - GError **error) +copy_modified_config_file (int orig_etc_fd, int modified_etc_fd, int new_etc_fd, const char *path, + OstreeSysrootDebugFlags flags, GCancellable *cancellable, GError **error) { struct stat modified_stbuf; struct stat new_stbuf; @@ -431,8 +407,8 @@ copy_modified_config_file (int orig_etc_fd, { g_autofree char *parent = g_path_get_dirname (path); - if (!ensure_directory_from_template (orig_etc_fd, modified_etc_fd, new_etc_fd, - parent, &dest_parent_dfd, flags, cancellable, error)) + if (!ensure_directory_from_template (orig_etc_fd, modified_etc_fd, new_etc_fd, parent, + &dest_parent_dfd, flags, cancellable, error)) return FALSE; } else @@ -449,13 +425,14 @@ copy_modified_config_file (int orig_etc_fd, if (errno != ENOENT) return glnx_throw_errno_prefix (error, "fstatat"); } - else if (S_ISDIR(new_stbuf.st_mode)) + else if (S_ISDIR (new_stbuf.st_mode)) { - if (!S_ISDIR(modified_stbuf.st_mode)) + if (!S_ISDIR (modified_stbuf.st_mode)) { return g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Modified config file newly defaults to directory '%s', cannot merge", - path), FALSE; + path), + FALSE; } else { @@ -473,21 +450,20 @@ copy_modified_config_file (int orig_etc_fd, if (S_ISDIR (modified_stbuf.st_mode)) { - if (!copy_dir_recurse (modified_etc_fd, new_etc_fd, path, flags, - cancellable, error)) + if (!copy_dir_recurse (modified_etc_fd, new_etc_fd, path, flags, cancellable, error)) return FALSE; } else if (S_ISLNK (modified_stbuf.st_mode) || S_ISREG (modified_stbuf.st_mode)) { - if (!glnx_file_copy_at (modified_etc_fd, path, &modified_stbuf, - new_etc_fd, path, + if (!glnx_file_copy_at (modified_etc_fd, path, &modified_stbuf, new_etc_fd, path, sysroot_flags_to_copy_flags (GLNX_FILE_COPY_OVERWRITE, flags), cancellable, error)) return glnx_prefix_error (error, "Copying %s", path); } else { - ot_journal_print (LOG_INFO, "Ignoring non-regular/non-symlink file found during /etc merge: %s", path); + ot_journal_print (LOG_INFO, + "Ignoring non-regular/non-symlink file found during /etc merge: %s", path); } return TRUE; @@ -511,12 +487,9 @@ copy_modified_config_file (int orig_etc_fd, * changed in @new_etc, the modified version always wins. */ static gboolean -merge_configuration_from (OstreeSysroot *sysroot, - OstreeDeployment *merge_deployment, - OstreeDeployment *new_deployment, - int new_deployment_dfd, - GCancellable *cancellable, - GError **error) +merge_configuration_from (OstreeSysroot *sysroot, OstreeDeployment *merge_deployment, + OstreeDeployment *new_deployment, int new_deployment_dfd, + GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("During /etc merge", error); const OstreeSysrootDebugFlags flags = sysroot->debug_flags; @@ -524,19 +497,21 @@ merge_configuration_from (OstreeSysroot *sysroot, g_assert (merge_deployment != NULL && new_deployment != NULL); g_assert (new_deployment_dfd != -1); - g_autofree char *merge_deployment_path = ostree_sysroot_get_deployment_dirpath (sysroot, merge_deployment); + g_autofree char *merge_deployment_path + = ostree_sysroot_get_deployment_dirpath (sysroot, merge_deployment); glnx_autofd int merge_deployment_dfd = -1; - if (!glnx_opendirat (sysroot->sysroot_fd, merge_deployment_path, FALSE, - &merge_deployment_dfd, error)) + if (!glnx_opendirat (sysroot->sysroot_fd, merge_deployment_path, FALSE, &merge_deployment_dfd, + error)) return FALSE; /* TODO: get rid of GFile usage here */ - g_autoptr(GFile) orig_etc = ot_fdrel_to_gfile (merge_deployment_dfd, "usr/etc"); - g_autoptr(GFile) modified_etc = ot_fdrel_to_gfile (merge_deployment_dfd, "etc"); + g_autoptr (GFile) orig_etc = ot_fdrel_to_gfile (merge_deployment_dfd, "usr/etc"); + g_autoptr (GFile) modified_etc = ot_fdrel_to_gfile (merge_deployment_dfd, "etc"); /* Return values for below */ - g_autoptr(GPtrArray) modified = g_ptr_array_new_with_free_func ((GDestroyNotify) ostree_diff_item_unref); - g_autoptr(GPtrArray) removed = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); - g_autoptr(GPtrArray) added = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); + g_autoptr (GPtrArray) modified + = g_ptr_array_new_with_free_func ((GDestroyNotify)ostree_diff_item_unref); + g_autoptr (GPtrArray) removed = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref); + g_autoptr (GPtrArray) added = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref); /* For now, ignore changes to xattrs; the problem is that * security.selinux will be different between the /usr/etc labels * and the ones in the real /etc, so they all show up as different. @@ -545,20 +520,17 @@ merge_configuration_from (OstreeSysroot *sysroot, * file, to have that change persist across upgrades, you must also * modify the content of the file. */ - if (!ostree_diff_dirs (OSTREE_DIFF_FLAGS_IGNORE_XATTRS, - orig_etc, modified_etc, modified, removed, added, - cancellable, error)) + if (!ostree_diff_dirs (OSTREE_DIFF_FLAGS_IGNORE_XATTRS, orig_etc, modified_etc, modified, removed, + added, cancellable, error)) return glnx_prefix_error (error, "While computing configuration diff"); - { g_autofree char *msg = - g_strdup_printf ("Copying /etc changes: %u modified, %u removed, %u added", - modified->len, removed->len, added->len); - ot_journal_send ("MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(OSTREE_CONFIGMERGE_ID), - "MESSAGE=%s", msg, - "ETC_N_MODIFIED=%u", modified->len, - "ETC_N_REMOVED=%u", removed->len, - "ETC_N_ADDED=%u", added->len, - NULL); + { + g_autofree char *msg + = g_strdup_printf ("Copying /etc changes: %u modified, %u removed, %u added", modified->len, + removed->len, added->len); + ot_journal_send ("MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL (OSTREE_CONFIGMERGE_ID), + "MESSAGE=%s", msg, "ETC_N_MODIFIED=%u", modified->len, "ETC_N_REMOVED=%u", + removed->len, "ETC_N_ADDED=%u", added->len, NULL); _ostree_sysroot_emit_journal_msg (sysroot, msg); } @@ -591,8 +563,8 @@ merge_configuration_from (OstreeSysroot *sysroot, g_assert (path); - if (!copy_modified_config_file (orig_etc_fd, modified_etc_fd, new_etc_fd, path, - flags, cancellable, error)) + if (!copy_modified_config_file (orig_etc_fd, modified_etc_fd, new_etc_fd, path, flags, + cancellable, error)) return FALSE; } for (guint i = 0; i < added->len; i++) @@ -602,8 +574,8 @@ merge_configuration_from (OstreeSysroot *sysroot, g_assert (path); - if (!copy_modified_config_file (orig_etc_fd, modified_etc_fd, new_etc_fd, path, - flags, cancellable, error)) + if (!copy_modified_config_file (orig_etc_fd, modified_etc_fd, new_etc_fd, path, flags, + cancellable, error)) return FALSE; } @@ -615,17 +587,13 @@ merge_configuration_from (OstreeSysroot *sysroot, * A dfd for the result is returned in @out_deployment_dfd. */ static gboolean -checkout_deployment_tree (OstreeSysroot *sysroot, - OstreeRepo *repo, - OstreeDeployment *deployment, - int *out_deployment_dfd, - GCancellable *cancellable, - GError **error) +checkout_deployment_tree (OstreeSysroot *sysroot, OstreeRepo *repo, OstreeDeployment *deployment, + int *out_deployment_dfd, GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("Checking out deployment tree", error); /* Find the directory with deployments for this stateroot */ - g_autofree char *osdeploy_path = - g_strconcat ("ostree/deploy/", ostree_deployment_get_osname (deployment), "/deploy", NULL); + g_autofree char *osdeploy_path + = g_strconcat ("ostree/deploy/", ostree_deployment_get_osname (deployment), "/deploy", NULL); if (!glnx_shutil_mkdir_p_at (sysroot->sysroot_fd, osdeploy_path, 0775, cancellable, error)) return FALSE; @@ -635,24 +603,22 @@ checkout_deployment_tree (OstreeSysroot *sysroot, /* Clean up anything that was there before, from e.g. an interrupted checkout */ const char *csum = ostree_deployment_get_csum (deployment); - g_autofree char *checkout_target_name = - g_strdup_printf ("%s.%d", csum, ostree_deployment_get_deployserial (deployment)); + g_autofree char *checkout_target_name + = g_strdup_printf ("%s.%d", csum, ostree_deployment_get_deployserial (deployment)); if (!glnx_shutil_rm_rf_at (osdeploy_dfd, checkout_target_name, cancellable, error)) return FALSE; /* Generate hardlink farm, then opendir it */ OstreeRepoCheckoutAtOptions checkout_opts = { .process_passthrough_whiteouts = TRUE }; - if (!ostree_repo_checkout_at (repo, &checkout_opts, osdeploy_dfd, - checkout_target_name, csum, + if (!ostree_repo_checkout_at (repo, &checkout_opts, osdeploy_dfd, checkout_target_name, csum, cancellable, error)) return FALSE; - return glnx_opendirat (osdeploy_dfd, checkout_target_name, TRUE, out_deployment_dfd, - error); + return glnx_opendirat (osdeploy_dfd, checkout_target_name, TRUE, out_deployment_dfd, error); } static char * -ptrarray_path_join (GPtrArray *path) +ptrarray_path_join (GPtrArray *path) { GString *path_buf; @@ -676,49 +642,36 @@ ptrarray_path_join (GPtrArray *path) } static gboolean -relabel_one_path (OstreeSysroot *sysroot, - OstreeSePolicy *sepolicy, - GFile *path, - GFileInfo *info, - GPtrArray *path_parts, - GCancellable *cancellable, - GError **error) +relabel_one_path (OstreeSysroot *sysroot, OstreeSePolicy *sepolicy, GFile *path, GFileInfo *info, + GPtrArray *path_parts, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; g_autofree char *relpath = NULL; relpath = ptrarray_path_join (path_parts); - if (!ostree_sepolicy_restorecon (sepolicy, relpath, - info, path, - OSTREE_SEPOLICY_RESTORECON_FLAGS_ALLOW_NOLABEL, - NULL, + if (!ostree_sepolicy_restorecon (sepolicy, relpath, info, path, + OSTREE_SEPOLICY_RESTORECON_FLAGS_ALLOW_NOLABEL, NULL, cancellable, error)) goto out; ret = TRUE; - out: +out: return ret; } static gboolean -relabel_recursively (OstreeSysroot *sysroot, - OstreeSePolicy *sepolicy, - GFile *dir, - GFileInfo *dir_info, - GPtrArray *path_parts, - GCancellable *cancellable, - GError **error) +relabel_recursively (OstreeSysroot *sysroot, OstreeSePolicy *sepolicy, GFile *dir, + GFileInfo *dir_info, GPtrArray *path_parts, GCancellable *cancellable, + GError **error) { gboolean ret = FALSE; - g_autoptr(GFileEnumerator) direnum = NULL; + g_autoptr (GFileEnumerator) direnum = NULL; - if (!relabel_one_path (sysroot, sepolicy, dir, dir_info, path_parts, - cancellable, error)) + if (!relabel_one_path (sysroot, sepolicy, dir, dir_info, path_parts, cancellable, error)) goto out; direnum = g_file_enumerate_children (dir, OSTREE_GIO_FAST_QUERYINFO, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - cancellable, error); + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!direnum) goto out; @@ -728,25 +681,24 @@ relabel_recursively (OstreeSysroot *sysroot, GFile *child; GFileType ftype; - if (!g_file_enumerator_iterate (direnum, &file_info, &child, - cancellable, error)) + if (!g_file_enumerator_iterate (direnum, &file_info, &child, cancellable, error)) goto out; if (file_info == NULL) break; - g_ptr_array_add (path_parts, (char*)g_file_info_get_name (file_info)); + g_ptr_array_add (path_parts, (char *)g_file_info_get_name (file_info)); ftype = g_file_info_get_file_type (file_info); if (ftype == G_FILE_TYPE_DIRECTORY) { - if (!relabel_recursively (sysroot, sepolicy, child, file_info, path_parts, - cancellable, error)) + if (!relabel_recursively (sysroot, sepolicy, child, file_info, path_parts, cancellable, + error)) goto out; } else { - if (!relabel_one_path (sysroot, sepolicy, child, file_info, path_parts, - cancellable, error)) + if (!relabel_one_path (sysroot, sepolicy, child, file_info, path_parts, cancellable, + error)) goto out; } @@ -754,30 +706,23 @@ relabel_recursively (OstreeSysroot *sysroot, } ret = TRUE; - out: +out: return ret; } static gboolean -selinux_relabel_dir (OstreeSysroot *sysroot, - OstreeSePolicy *sepolicy, - GFile *dir, - const char *prefix, - GCancellable *cancellable, - GError **error) -{ - - g_autoptr(GFileInfo) root_info = - g_file_query_info (dir, OSTREE_GIO_FAST_QUERYINFO, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - cancellable, error); +selinux_relabel_dir (OstreeSysroot *sysroot, OstreeSePolicy *sepolicy, GFile *dir, + const char *prefix, GCancellable *cancellable, GError **error) +{ + + g_autoptr (GFileInfo) root_info = g_file_query_info ( + dir, OSTREE_GIO_FAST_QUERYINFO, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!root_info) return FALSE; - g_autoptr(GPtrArray) path_parts = g_ptr_array_new (); - g_ptr_array_add (path_parts, (char*)prefix); - if (!relabel_recursively (sysroot, sepolicy, dir, root_info, path_parts, - cancellable, error)) + g_autoptr (GPtrArray) path_parts = g_ptr_array_new (); + g_ptr_array_add (path_parts, (char *)prefix); + if (!relabel_recursively (sysroot, sepolicy, dir, root_info, path_parts, cancellable, error)) return glnx_prefix_error (error, "Relabeling /%s", prefix); return TRUE; @@ -787,11 +732,8 @@ selinux_relabel_dir (OstreeSysroot *sysroot, * https://github.com/ostreedev/ostree/pull/872 */ static gboolean -selinux_relabel_var_if_needed (OstreeSysroot *sysroot, - OstreeSePolicy *sepolicy, - int os_deploy_dfd, - GCancellable *cancellable, - GError **error) +selinux_relabel_var_if_needed (OstreeSysroot *sysroot, OstreeSePolicy *sepolicy, int os_deploy_dfd, + GCancellable *cancellable, GError **error) { /* This is a bit of a hack; we should change the code at some * point in the distant future to only create (and label) /var @@ -803,34 +745,32 @@ selinux_relabel_var_if_needed (OstreeSysroot *sysroot, return FALSE; if (errno == ENOENT) { - { g_autofree char *msg = - g_strdup_printf ("Relabeling /var (no stamp file '%s' found)", selabeled); - ot_journal_send ("MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(OSTREE_VARRELABEL_ID), - "MESSAGE=%s", msg, - NULL); + { + g_autofree char *msg + = g_strdup_printf ("Relabeling /var (no stamp file '%s' found)", selabeled); + ot_journal_send ("MESSAGE_ID=" SD_ID128_FORMAT_STR, + SD_ID128_FORMAT_VAL (OSTREE_VARRELABEL_ID), "MESSAGE=%s", msg, NULL); _ostree_sysroot_emit_journal_msg (sysroot, msg); } - g_autoptr(GFile) deployment_var_path = ot_fdrel_to_gfile (os_deploy_dfd, "var"); - if (!selinux_relabel_dir (sysroot, sepolicy, - deployment_var_path, "var", - cancellable, error)) + g_autoptr (GFile) deployment_var_path = ot_fdrel_to_gfile (os_deploy_dfd, "var"); + if (!selinux_relabel_dir (sysroot, sepolicy, deployment_var_path, "var", cancellable, error)) { g_prefix_error (error, "Relabeling /var: "); return FALSE; } - { g_auto(OstreeSepolicyFsCreatecon) con = { 0, }; + { + g_auto (OstreeSepolicyFsCreatecon) con = { + 0, + }; const char *selabeled_abspath = glnx_strjoina ("/", selabeled); - if (!_ostree_sepolicy_preparefscreatecon (&con, sepolicy, - selabeled_abspath, - 0644, error)) + if (!_ostree_sepolicy_preparefscreatecon (&con, sepolicy, selabeled_abspath, 0644, error)) return FALSE; - if (!glnx_file_replace_contents_at (os_deploy_dfd, selabeled, (guint8*)"", 0, - GLNX_FILE_REPLACE_DATASYNC_NEW, - cancellable, error)) + if (!glnx_file_replace_contents_at (os_deploy_dfd, selabeled, (guint8 *)"", 0, + GLNX_FILE_REPLACE_DATASYNC_NEW, cancellable, error)) return FALSE; } } @@ -842,12 +782,8 @@ selinux_relabel_var_if_needed (OstreeSysroot *sysroot, * merge_configuration_from(). */ static gboolean -prepare_deployment_etc (OstreeSysroot *sysroot, - OstreeRepo *repo, - OstreeDeployment *deployment, - int deployment_dfd, - GCancellable *cancellable, - GError **error) +prepare_deployment_etc (OstreeSysroot *sysroot, OstreeRepo *repo, OstreeDeployment *deployment, + int deployment_dfd, GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("Preparing /etc", error); @@ -861,8 +797,8 @@ prepare_deployment_etc (OstreeSysroot *sysroot, if (etc_exists) { - if (usretc_exists) - return glnx_throw (error, "Tree contains both /etc and /usr/etc"); + if (usretc_exists) + return glnx_throw (error, "Tree contains both /etc and /usr/etc"); /* Compatibility hack */ if (!glnx_renameat (deployment_dfd, "etc", deployment_dfd, "usr/etc", error)) return FALSE; @@ -874,26 +810,23 @@ prepare_deployment_etc (OstreeSysroot *sysroot, /* We need copies of /etc from /usr/etc (so admins can use vi), and if * SELinux is enabled, we need to relabel. */ - OstreeRepoCheckoutAtOptions etc_co_opts = { .force_copy = TRUE, - .subpath = "/usr/etc", - .sepolicy_prefix = "/etc"}; + OstreeRepoCheckoutAtOptions etc_co_opts + = { .force_copy = TRUE, .subpath = "/usr/etc", .sepolicy_prefix = "/etc" }; /* Here, we initialize SELinux policy from the /usr/etc inside * the root - this is before we've finalized the configuration * merge into /etc. */ - g_autoptr(OstreeSePolicy) sepolicy = ostree_sepolicy_new_at (deployment_dfd, cancellable, error); + g_autoptr (OstreeSePolicy) sepolicy + = ostree_sepolicy_new_at (deployment_dfd, cancellable, error); if (!sepolicy) return FALSE; if (ostree_sepolicy_get_name (sepolicy) != NULL) etc_co_opts.sepolicy = sepolicy; /* Copy usr/etc → etc */ - if (!ostree_repo_checkout_at (repo, &etc_co_opts, - deployment_dfd, "etc", - ostree_deployment_get_csum (deployment), - cancellable, error)) + if (!ostree_repo_checkout_at (repo, &etc_co_opts, deployment_dfd, "etc", + ostree_deployment_get_csum (deployment), cancellable, error)) return FALSE; - } return TRUE; @@ -903,44 +836,36 @@ prepare_deployment_etc (OstreeSysroot *sysroot, * the assumption the caller may be writing multiple. */ static gboolean -write_origin_file_internal (OstreeSysroot *sysroot, - OstreeSePolicy *sepolicy, - OstreeDeployment *deployment, - GKeyFile *new_origin, - GLnxFileReplaceFlags flags, - GCancellable *cancellable, - GError **error) +write_origin_file_internal (OstreeSysroot *sysroot, OstreeSePolicy *sepolicy, + OstreeDeployment *deployment, GKeyFile *new_origin, + GLnxFileReplaceFlags flags, GCancellable *cancellable, GError **error) { if (!_ostree_sysroot_ensure_writable (sysroot, error)) return FALSE; GLNX_AUTO_PREFIX_ERROR ("Writing out origin file", error); - GKeyFile *origin = - new_origin ? new_origin : ostree_deployment_get_origin (deployment); + GKeyFile *origin = new_origin ? new_origin : ostree_deployment_get_origin (deployment); if (origin) { - g_auto(OstreeSepolicyFsCreatecon) con = { 0, }; - if (!_ostree_sepolicy_preparefscreatecon (&con, sepolicy, - "/etc/ostree/remotes.d/dummy.conf", + g_auto (OstreeSepolicyFsCreatecon) con = { + 0, + }; + if (!_ostree_sepolicy_preparefscreatecon (&con, sepolicy, "/etc/ostree/remotes.d/dummy.conf", 0644, error)) return FALSE; - g_autofree char *origin_path = - g_strdup_printf ("ostree/deploy/%s/deploy/%s.%d.origin", - ostree_deployment_get_osname (deployment), - ostree_deployment_get_csum (deployment), - ostree_deployment_get_deployserial (deployment)); + g_autofree char *origin_path = g_strdup_printf ( + "ostree/deploy/%s/deploy/%s.%d.origin", ostree_deployment_get_osname (deployment), + ostree_deployment_get_csum (deployment), ostree_deployment_get_deployserial (deployment)); gsize len; g_autofree char *contents = g_key_file_to_data (origin, &len, error); if (!contents) return FALSE; - if (!glnx_file_replace_contents_at (sysroot->sysroot_fd, - origin_path, (guint8*)contents, len, - flags, - cancellable, error)) + if (!glnx_file_replace_contents_at (sysroot->sysroot_fd, origin_path, (guint8 *)contents, len, + flags, cancellable, error)) return FALSE; } @@ -960,20 +885,16 @@ write_origin_file_internal (OstreeSysroot *sysroot, * this function will write the current origin of @deployment. */ gboolean -ostree_sysroot_write_origin_file (OstreeSysroot *sysroot, - OstreeDeployment *deployment, - GKeyFile *new_origin, - GCancellable *cancellable, - GError **error) -{ - g_autoptr(GFile) rootfs = g_file_new_for_path ("/"); - g_autoptr(OstreeSePolicy) sepolicy = ostree_sepolicy_new (rootfs, cancellable, error); +ostree_sysroot_write_origin_file (OstreeSysroot *sysroot, OstreeDeployment *deployment, + GKeyFile *new_origin, GCancellable *cancellable, GError **error) +{ + g_autoptr (GFile) rootfs = g_file_new_for_path ("/"); + g_autoptr (OstreeSePolicy) sepolicy = ostree_sepolicy_new (rootfs, cancellable, error); if (!sepolicy) return FALSE; if (!write_origin_file_internal (sysroot, sepolicy, deployment, new_origin, - GLNX_FILE_REPLACE_DATASYNC_NEW, - cancellable, error)) + GLNX_FILE_REPLACE_DATASYNC_NEW, cancellable, error)) return FALSE; if (!_ostree_sysroot_bump_mtime (sysroot, error)) @@ -982,8 +903,9 @@ ostree_sysroot_write_origin_file (OstreeSysroot *sysroot, return TRUE; } -typedef struct { - int boot_dfd; +typedef struct +{ + int boot_dfd; char *kernel_srcpath; char *kernel_namever; char *kernel_hmac_srcpath; @@ -1013,9 +935,9 @@ _ostree_kernel_layout_free (OstreeKernelLayout *layout) g_free (layout->bootcsum); g_free (layout); } -G_DEFINE_AUTOPTR_CLEANUP_FUNC(OstreeKernelLayout, _ostree_kernel_layout_free); +G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeKernelLayout, _ostree_kernel_layout_free); -static OstreeKernelLayout* +static OstreeKernelLayout * _ostree_kernel_layout_new (void) { OstreeKernelLayout *ret = g_new0 (OstreeKernelLayout, 1); @@ -1025,18 +947,18 @@ _ostree_kernel_layout_new (void) /* See get_kernel_from_tree() below */ static gboolean -get_kernel_from_tree_usrlib_modules (OstreeSysroot *sysroot, - int deployment_dfd, - OstreeKernelLayout **out_layout, - GCancellable *cancellable, - GError **error) +get_kernel_from_tree_usrlib_modules (OstreeSysroot *sysroot, int deployment_dfd, + OstreeKernelLayout **out_layout, GCancellable *cancellable, + GError **error) { g_autofree char *kver = NULL; /* Look in usr/lib/modules */ - g_auto(GLnxDirFdIterator) mod_dfditer = { 0, }; + g_auto (GLnxDirFdIterator) mod_dfditer = { + 0, + }; gboolean exists; - if (!ot_dfd_iter_init_allow_noent (deployment_dfd, "usr/lib/modules", &mod_dfditer, - &exists, error)) + if (!ot_dfd_iter_init_allow_noent (deployment_dfd, "usr/lib/modules", &mod_dfditer, &exists, + error)) return FALSE; if (!exists) { @@ -1045,10 +967,10 @@ get_kernel_from_tree_usrlib_modules (OstreeSysroot *sysroot, return TRUE; } - g_autoptr(OstreeKernelLayout) ret_layout = _ostree_kernel_layout_new (); + g_autoptr (OstreeKernelLayout) ret_layout = _ostree_kernel_layout_new (); /* Reusable buffer for path string */ - g_autoptr(GString) pathbuf = g_string_new (""); + g_autoptr (GString) pathbuf = g_string_new (""); /* Loop until we find something that looks like a valid /usr/lib/modules/$kver */ while (ret_layout->boot_dfd == -1) { @@ -1095,13 +1017,15 @@ get_kernel_from_tree_usrlib_modules (OstreeSysroot *sysroot, } /* We found a module directory, compute the checksum */ - g_auto(OtChecksum) checksum = { 0, }; + g_auto (OtChecksum) checksum = { + 0, + }; ot_checksum_init (&checksum); glnx_autofd int fd = -1; /* Checksum the kernel */ if (!glnx_openat_rdonly (ret_layout->boot_dfd, "vmlinuz", TRUE, &fd, error)) return FALSE; - g_autoptr(GInputStream) in = g_unix_input_stream_new (fd, FALSE); + g_autoptr (GInputStream) in = g_unix_input_stream_new (fd, FALSE); if (!ot_gio_splice_update_checksum (NULL, in, &checksum, cancellable, error)) return FALSE; g_clear_object (&in); @@ -1111,9 +1035,9 @@ get_kernel_from_tree_usrlib_modules (OstreeSysroot *sysroot, * for this, let's be a bit conservative and support both `initramfs.img` and * `initramfs`. */ - const char *initramfs_paths[] = {"initramfs.img", "initramfs"}; + const char *initramfs_paths[] = { "initramfs.img", "initramfs" }; const char *initramfs_path = NULL; - for (guint i = 0; i < G_N_ELEMENTS(initramfs_paths); i++) + for (guint i = 0; i < G_N_ELEMENTS (initramfs_paths); i++) { initramfs_path = initramfs_paths[i]; if (!ot_openat_ignore_enoent (ret_layout->boot_dfd, initramfs_path, &fd, error)) @@ -1155,8 +1079,8 @@ get_kernel_from_tree_usrlib_modules (OstreeSysroot *sysroot, if (!no_dtb) { /* Check for /usr/lib/modules/$kver/devicetree first, if it does not - * exist check for /usr/lib/modules/$kver/dtb/ directory. - */ + * exist check for /usr/lib/modules/$kver/dtb/ directory. + */ if (!ot_openat_ignore_enoent (ret_layout->boot_dfd, "devicetree", &fd, error)) return FALSE; if (fd != -1) @@ -1180,7 +1104,8 @@ get_kernel_from_tree_usrlib_modules (OstreeSysroot *sysroot, ret_layout->devicetree_srcpath = g_strdup ("dtb"); ret_layout->devicetree_namever = NULL; - if (!checksum_dir_recurse(ret_layout->boot_dfd, "dtb", &checksum, cancellable, error)) + if (!checksum_dir_recurse (ret_layout->boot_dfd, "dtb", &checksum, cancellable, + error)) return FALSE; } } @@ -1194,11 +1119,13 @@ get_kernel_from_tree_usrlib_modules (OstreeSysroot *sysroot, if (errno == 0) { ret_layout->kernel_hmac_srcpath = g_strdup (".vmlinuz.hmac"); - /* Name it as dracut expects it: https://github.com/dracutdevs/dracut/blob/225e4b94cbdb702cf512490dcd2ad9ca5f5b22c1/modules.d/01fips/fips.sh#L129 */ + /* Name it as dracut expects it: + * https://github.com/dracutdevs/dracut/blob/225e4b94cbdb702cf512490dcd2ad9ca5f5b22c1/modules.d/01fips/fips.sh#L129 + */ ret_layout->kernel_hmac_namever = g_strdup_printf (".%s.hmac", ret_layout->kernel_namever); } - char hexdigest[OSTREE_SHA256_STRING_LEN+1]; + char hexdigest[OSTREE_SHA256_STRING_LEN + 1]; ot_checksum_get_hexdigest (&checksum, hexdigest, sizeof (hexdigest)); ret_layout->bootcsum = g_strdup (hexdigest); @@ -1208,16 +1135,14 @@ get_kernel_from_tree_usrlib_modules (OstreeSysroot *sysroot, /* See get_kernel_from_tree() below */ static gboolean -get_kernel_from_tree_legacy_layouts (int deployment_dfd, - OstreeKernelLayout **out_layout, - GCancellable *cancellable, - GError **error) +get_kernel_from_tree_legacy_layouts (int deployment_dfd, OstreeKernelLayout **out_layout, + GCancellable *cancellable, GError **error) { - const char *legacy_paths[] = {"usr/lib/ostree-boot", "boot"}; + const char *legacy_paths[] = { "usr/lib/ostree-boot", "boot" }; g_autofree char *kernel_checksum = NULL; g_autofree char *initramfs_checksum = NULL; g_autofree char *devicetree_checksum = NULL; - g_autoptr(OstreeKernelLayout) ret_layout = _ostree_kernel_layout_new (); + g_autoptr (OstreeKernelLayout) ret_layout = _ostree_kernel_layout_new (); for (guint i = 0; i < G_N_ELEMENTS (legacy_paths); i++) { @@ -1242,7 +1167,9 @@ get_kernel_from_tree_legacy_layouts (int deployment_dfd, /* ret_layout->boot_dfd will point to either /usr/lib/ostree-boot or /boot, let's * inspect it. */ - g_auto(GLnxDirFdIterator) dfditer = { 0, }; + g_auto (GLnxDirFdIterator) dfditer = { + 0, + }; if (!glnx_dirfd_iterator_init_at (ret_layout->boot_dfd, ".", FALSE, &dfditer, error)) return FALSE; @@ -1297,9 +1224,8 @@ get_kernel_from_tree_legacy_layouts (int deployment_dfd, } /* If we found a kernel, an initramfs and a devicetree, break out of the loop */ - if (ret_layout->kernel_srcpath != NULL && - ret_layout->initramfs_srcpath != NULL && - ret_layout->devicetree_srcpath != NULL) + if (ret_layout->kernel_srcpath != NULL && ret_layout->initramfs_srcpath != NULL + && ret_layout->devicetree_srcpath != NULL) break; } @@ -1353,17 +1279,15 @@ get_kernel_from_tree_legacy_layouts (int deployment_dfd, * initramfs there, so we need to look in /usr/lib/ostree-boot first. */ static gboolean -get_kernel_from_tree (OstreeSysroot *sysroot, - int deployment_dfd, - OstreeKernelLayout **out_layout, - GCancellable *cancellable, - GError **error) +get_kernel_from_tree (OstreeSysroot *sysroot, int deployment_dfd, OstreeKernelLayout **out_layout, + GCancellable *cancellable, GError **error) { - g_autoptr(OstreeKernelLayout) usrlib_modules_layout = NULL; - g_autoptr(OstreeKernelLayout) legacy_layout = NULL; + g_autoptr (OstreeKernelLayout) usrlib_modules_layout = NULL; + g_autoptr (OstreeKernelLayout) legacy_layout = NULL; /* First, gather from usr/lib/modules/$kver if it exists */ - if (!get_kernel_from_tree_usrlib_modules (sysroot, deployment_dfd, &usrlib_modules_layout, cancellable, error)) + if (!get_kernel_from_tree_usrlib_modules (sysroot, deployment_dfd, &usrlib_modules_layout, + cancellable, error)) return FALSE; /* Gather the legacy layout */ @@ -1393,9 +1317,8 @@ get_kernel_from_tree (OstreeSysroot *sysroot, return TRUE; } } - else if (usrlib_modules_layout != NULL && - usrlib_modules_layout->initramfs_srcpath == NULL && - legacy_layout->initramfs_srcpath != NULL) + else if (usrlib_modules_layout != NULL && usrlib_modules_layout->initramfs_srcpath == NULL + && legacy_layout->initramfs_srcpath != NULL) { /* Does the module path not have an initramfs, but the legacy does? Prefer * the latter then, to make rpm-ostree work as is today. @@ -1428,10 +1351,7 @@ get_kernel_from_tree (OstreeSysroot *sysroot, * https://github.com/ostreedev/ostree/pull/1049 */ static gboolean -fsfreeze_thaw_cycle (OstreeSysroot *self, - int rootfs_dfd, - GCancellable *cancellable, - GError **error) +fsfreeze_thaw_cycle (OstreeSysroot *self, int rootfs_dfd, GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("During fsfreeze-thaw", error); @@ -1445,7 +1365,7 @@ fsfreeze_thaw_cycle (OstreeSysroot *self, if (pid < 0) return glnx_throw_errno_prefix (error, "fork"); - const gboolean debug_fifreeze = (self->debug_flags & OSTREE_SYSROOT_DEBUG_TEST_FIFREEZE)>0; + const gboolean debug_fifreeze = (self->debug_flags & OSTREE_SYSROOT_DEBUG_TEST_FIFREEZE) > 0; char c = '!'; if (pid == 0) /* Child watchdog/unfreezer process. */ { @@ -1571,14 +1491,16 @@ fsfreeze_thaw_cycle (OstreeSysroot *self, return TRUE; } -typedef struct { +typedef struct +{ guint64 root_syncfs_msec; guint64 boot_syncfs_msec; guint64 extra_syncfs_msec; } SyncStats; -typedef struct { - int ref_count; /* atomic */ +typedef struct +{ + int ref_count; /* atomic */ bool success; GMutex mutex; GCond cond; @@ -1615,10 +1537,8 @@ sync_in_thread (void *ptr) * `sync()`. */ static gboolean -full_system_sync (OstreeSysroot *self, - SyncStats *out_stats, - GCancellable *cancellable, - GError **error) +full_system_sync (OstreeSysroot *self, SyncStats *out_stats, GCancellable *cancellable, + GError **error) { GLNX_AUTO_PREFIX_ERROR ("Full sync", error); guint64 start_msec = g_get_monotonic_time () / 1000; @@ -1628,7 +1548,7 @@ full_system_sync (OstreeSysroot *self, out_stats->root_syncfs_msec = (end_msec - start_msec); - if (!_ostree_sysroot_ensure_boot_fd (self, error)) + if (!_ostree_sysroot_ensure_boot_fd (self, error)) return FALSE; start_msec = g_get_monotonic_time () / 1000; @@ -1694,11 +1614,8 @@ full_system_sync (OstreeSysroot *self, * These new links are made active by swap_bootlinks(). */ static gboolean -create_new_bootlinks (OstreeSysroot *self, - int bootversion, - GPtrArray *new_deployments, - GCancellable *cancellable, - GError **error) +create_new_bootlinks (OstreeSysroot *self, int bootversion, GPtrArray *new_deployments, + GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("Creating new current bootlinks", error); glnx_autofd int ostree_dfd = -1; @@ -1720,7 +1637,8 @@ create_new_bootlinks (OstreeSysroot *self, /* Create the "subbootdir", which is a directory holding a symlink farm pointing to * deployments per-osname. */ - g_autofree char *ostree_subbootdir_name = g_strdup_printf ("boot.%d.%d", bootversion, new_subbootversion); + g_autofree char *ostree_subbootdir_name + = g_strdup_printf ("boot.%d.%d", bootversion, new_subbootversion); if (!glnx_shutil_rm_rf_at (ostree_dfd, ostree_subbootdir_name, cancellable, error)) return FALSE; if (!glnx_shutil_mkdir_p_at (ostree_dfd, ostree_subbootdir_name, 0755, cancellable, error)) @@ -1733,17 +1651,17 @@ create_new_bootlinks (OstreeSysroot *self, for (guint i = 0; i < new_deployments->len; i++) { OstreeDeployment *deployment = new_deployments->pdata[i]; - g_autofree char *bootlink_parent = g_strconcat (ostree_deployment_get_osname (deployment), - "/", - ostree_deployment_get_bootcsum (deployment), - NULL); - g_autofree char *bootlink_pathname = g_strdup_printf ("%s/%d", bootlink_parent, ostree_deployment_get_bootserial (deployment)); - g_autofree char *bootlink_target = g_strdup_printf ("../../../deploy/%s/deploy/%s.%d", - ostree_deployment_get_osname (deployment), - ostree_deployment_get_csum (deployment), - ostree_deployment_get_deployserial (deployment)); - - if (!glnx_shutil_mkdir_p_at (ostree_subbootdir_dfd, bootlink_parent, 0755, cancellable, error)) + g_autofree char *bootlink_parent + = g_strconcat (ostree_deployment_get_osname (deployment), "/", + ostree_deployment_get_bootcsum (deployment), NULL); + g_autofree char *bootlink_pathname = g_strdup_printf ( + "%s/%d", bootlink_parent, ostree_deployment_get_bootserial (deployment)); + g_autofree char *bootlink_target = g_strdup_printf ( + "../../../deploy/%s/deploy/%s.%d", ostree_deployment_get_osname (deployment), + ostree_deployment_get_csum (deployment), ostree_deployment_get_deployserial (deployment)); + + if (!glnx_shutil_mkdir_p_at (ostree_subbootdir_dfd, bootlink_parent, 0755, cancellable, + error)) return FALSE; if (!symlink_at_replace (bootlink_target, ostree_subbootdir_dfd, bootlink_pathname, @@ -1757,12 +1675,8 @@ create_new_bootlinks (OstreeSysroot *self, /* Rename into place symlinks created via create_new_bootlinks(). */ static gboolean -swap_bootlinks (OstreeSysroot *self, - int bootversion, - GPtrArray *new_deployments, - char **out_subbootdir, - GCancellable *cancellable, - GError **error) +swap_bootlinks (OstreeSysroot *self, int bootversion, GPtrArray *new_deployments, + char **out_subbootdir, GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("Swapping new version bootlinks", error); glnx_autofd int ostree_dfd = -1; @@ -1781,9 +1695,10 @@ swap_bootlinks (OstreeSysroot *self, int new_subbootversion = old_subbootversion == 0 ? 1 : 0; g_autofree char *ostree_bootdir_name = g_strdup_printf ("boot.%d", bootversion); - g_autofree char *ostree_subbootdir_name = g_strdup_printf ("boot.%d.%d", bootversion, new_subbootversion); - if (!symlink_at_replace (ostree_subbootdir_name, ostree_dfd, ostree_bootdir_name, - cancellable, error)) + g_autofree char *ostree_subbootdir_name + = g_strdup_printf ("boot.%d.%d", bootversion, new_subbootversion); + if (!symlink_at_replace (ostree_subbootdir_name, ostree_dfd, ostree_bootdir_name, cancellable, + error)) return FALSE; if (out_subbootdir) *out_subbootdir = g_steal_pointer (&ostree_subbootdir_name); @@ -1791,8 +1706,7 @@ swap_bootlinks (OstreeSysroot *self, } static GHashTable * -parse_os_release (const char *contents, - const char *split) +parse_os_release (const char *contents, const char *split) { g_autofree char **lines = g_strsplit (contents, split, -1); GHashTable *ret = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); @@ -1825,44 +1739,37 @@ parse_os_release (const char *contents, * /boot/loader/entries. */ static gboolean -install_deployment_kernel (OstreeSysroot *sysroot, - int new_bootversion, - OstreeDeployment *deployment, - guint n_deployments, - gboolean show_osname, - GCancellable *cancellable, - GError **error) +install_deployment_kernel (OstreeSysroot *sysroot, int new_bootversion, + OstreeDeployment *deployment, guint n_deployments, gboolean show_osname, + GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("Installing kernel", error); OstreeBootconfigParser *bootconfig = ostree_deployment_get_bootconfig (deployment); g_autofree char *deployment_dirpath = ostree_sysroot_get_deployment_dirpath (sysroot, deployment); glnx_autofd int deployment_dfd = -1; - if (!glnx_opendirat (sysroot->sysroot_fd, deployment_dirpath, FALSE, - &deployment_dfd, error)) + if (!glnx_opendirat (sysroot->sysroot_fd, deployment_dirpath, FALSE, &deployment_dfd, error)) return FALSE; /* We need to label the kernels */ - g_autoptr(OstreeSePolicy) sepolicy = ostree_sepolicy_new_at (deployment_dfd, cancellable, error); + g_autoptr (OstreeSePolicy) sepolicy = ostree_sepolicy_new_at (deployment_dfd, cancellable, error); if (!sepolicy) return FALSE; /* Find the kernel/initramfs/devicetree in the tree */ - g_autoptr(OstreeKernelLayout) kernel_layout = NULL; - if (!get_kernel_from_tree (sysroot, deployment_dfd, &kernel_layout, - cancellable, error)) + g_autoptr (OstreeKernelLayout) kernel_layout = NULL; + if (!get_kernel_from_tree (sysroot, deployment_dfd, &kernel_layout, cancellable, error)) return FALSE; - if (!_ostree_sysroot_ensure_boot_fd (sysroot, error)) + if (!_ostree_sysroot_ensure_boot_fd (sysroot, error)) return FALSE; const char *osname = ostree_deployment_get_osname (deployment); const char *bootcsum = ostree_deployment_get_bootcsum (deployment); g_autofree char *bootcsumdir = g_strdup_printf ("ostree/%s-%s", osname, bootcsum); g_autofree char *bootconfdir = g_strdup_printf ("loader.%d/entries", new_bootversion); - g_autofree char *bootconf_name = g_strdup_printf ("ostree-%d-%s.conf", - n_deployments - ostree_deployment_get_index (deployment), - osname); + g_autofree char *bootconf_name = g_strdup_printf ( + "ostree-%d-%s.conf", n_deployments - ostree_deployment_get_index (deployment), osname); if (!glnx_shutil_mkdir_p_at (sysroot->boot_fd, bootcsumdir, 0775, cancellable, error)) return FALSE; @@ -1885,9 +1792,9 @@ install_deployment_kernel (OstreeSysroot *sysroot, return FALSE; if (errno == ENOENT) { - if (!install_into_boot (repo, sepolicy, kernel_layout->boot_dfd, kernel_layout->kernel_srcpath, - bootcsum_dfd, kernel_layout->kernel_namever, - cancellable, error)) + if (!install_into_boot (repo, sepolicy, kernel_layout->boot_dfd, + kernel_layout->kernel_srcpath, bootcsum_dfd, + kernel_layout->kernel_namever, cancellable, error)) return FALSE; } @@ -1897,13 +1804,14 @@ install_deployment_kernel (OstreeSysroot *sysroot, if (kernel_layout->initramfs_srcpath) { g_assert (kernel_layout->initramfs_namever); - if (!glnx_fstatat_allow_noent (bootcsum_dfd, kernel_layout->initramfs_namever, &stbuf, 0, error)) + if (!glnx_fstatat_allow_noent (bootcsum_dfd, kernel_layout->initramfs_namever, &stbuf, 0, + error)) return FALSE; if (errno == ENOENT) { - if (!install_into_boot (repo, sepolicy, kernel_layout->boot_dfd, kernel_layout->initramfs_srcpath, - bootcsum_dfd, kernel_layout->initramfs_namever, - cancellable, error)) + if (!install_into_boot (repo, sepolicy, kernel_layout->boot_dfd, + kernel_layout->initramfs_srcpath, bootcsum_dfd, + kernel_layout->initramfs_namever, cancellable, error)) return FALSE; } } @@ -1913,33 +1821,36 @@ install_deployment_kernel (OstreeSysroot *sysroot, /* If devicetree_namever is set a single device tree is deployed */ if (kernel_layout->devicetree_namever) { - if (!glnx_fstatat_allow_noent (bootcsum_dfd, kernel_layout->devicetree_namever, &stbuf, 0, error)) + if (!glnx_fstatat_allow_noent (bootcsum_dfd, kernel_layout->devicetree_namever, &stbuf, 0, + error)) return FALSE; if (errno == ENOENT) { - if (!install_into_boot (repo, sepolicy, kernel_layout->boot_dfd, kernel_layout->devicetree_srcpath, - bootcsum_dfd, kernel_layout->devicetree_namever, - cancellable, error)) + if (!install_into_boot (repo, sepolicy, kernel_layout->boot_dfd, + kernel_layout->devicetree_srcpath, bootcsum_dfd, + kernel_layout->devicetree_namever, cancellable, error)) return FALSE; } } else { - if (!copy_dir_recurse (kernel_layout->boot_dfd, bootcsum_dfd, kernel_layout->devicetree_srcpath, - sysroot->debug_flags, cancellable, error)) + if (!copy_dir_recurse (kernel_layout->boot_dfd, bootcsum_dfd, + kernel_layout->devicetree_srcpath, sysroot->debug_flags, + cancellable, error)) return FALSE; } } if (kernel_layout->kernel_hmac_srcpath) { - if (!glnx_fstatat_allow_noent (bootcsum_dfd, kernel_layout->kernel_hmac_namever, &stbuf, 0, error)) + if (!glnx_fstatat_allow_noent (bootcsum_dfd, kernel_layout->kernel_hmac_namever, &stbuf, 0, + error)) return FALSE; if (errno == ENOENT) { - if (!install_into_boot (repo, sepolicy, kernel_layout->boot_dfd, kernel_layout->kernel_hmac_srcpath, - bootcsum_dfd, kernel_layout->kernel_hmac_namever, - cancellable, error)) + if (!install_into_boot (repo, sepolicy, kernel_layout->boot_dfd, + kernel_layout->kernel_hmac_srcpath, bootcsum_dfd, + kernel_layout->kernel_hmac_namever, cancellable, error)) return FALSE; } } @@ -1952,16 +1863,16 @@ install_deployment_kernel (OstreeSysroot *sysroot, if (errno == ENOENT) { - if (!install_into_boot (repo, sepolicy, kernel_layout->boot_dfd, kernel_layout->aboot_srcpath, - bootcsum_dfd, kernel_layout->aboot_namever, - cancellable, error)) + if (!install_into_boot (repo, sepolicy, kernel_layout->boot_dfd, + kernel_layout->aboot_srcpath, bootcsum_dfd, + kernel_layout->aboot_namever, cancellable, error)) return FALSE; } } /* NOTE: if adding more things in bootcsum_dfd, also update get_kernel_layout_size() */ - g_autoptr(GPtrArray) overlay_initrds = NULL; + g_autoptr (GPtrArray) overlay_initrds = NULL; for (char **it = _ostree_deployment_get_overlay_initrds (deployment); it && *it; it++) { char *checksum = *it; @@ -1973,8 +1884,8 @@ install_deployment_kernel (OstreeSysroot *sysroot, * across different boocsums). Eventually, it'd be nice to have an OSTree repo in * /boot itself and drop the boocsum dir concept entirely. */ - g_autofree char *destpath = - g_strdup_printf ("%s%s/%s.img", bootprefix, _OSTREE_SYSROOT_BOOT_INITRAMFS_OVERLAYS, checksum); + g_autofree char *destpath = g_strdup_printf ( + "%s%s/%s.img", bootprefix, _OSTREE_SYSROOT_BOOT_INITRAMFS_OVERLAYS, checksum); const char *rel_destpath = destpath + 1; /* lazily allocate array and create dir so we don't pollute /boot if not needed */ @@ -1991,8 +1902,8 @@ install_deployment_kernel (OstreeSysroot *sysroot, return FALSE; if (errno == ENOENT) { - g_autofree char *srcpath = - g_strdup_printf (_OSTREE_SYSROOT_RUNSTATE_STAGED_INITRDS_DIR "/%s", checksum); + g_autofree char *srcpath + = g_strdup_printf (_OSTREE_SYSROOT_RUNSTATE_STAGED_INITRDS_DIR "/%s", checksum); if (!install_into_boot (repo, sepolicy, AT_FDCWD, srcpath, sysroot->boot_fd, rel_destpath, cancellable, error)) return FALSE; @@ -2020,11 +1931,11 @@ install_deployment_kernel (OstreeSysroot *sysroot, return glnx_prefix_error (error, "Reading /usr/lib/os-release"); } - g_autoptr(GHashTable) osrelease_values = parse_os_release (contents, "\n"); + g_autoptr (GHashTable) osrelease_values = parse_os_release (contents, "\n"); /* title */ const char *val = g_hash_table_lookup (osrelease_values, "PRETTY_NAME"); if (val == NULL) - val = g_hash_table_lookup (osrelease_values, "ID"); + val = g_hash_table_lookup (osrelease_values, "ID"); if (val == NULL) return glnx_throw (error, "No PRETTY_NAME or ID in /etc/os-release"); @@ -2033,24 +1944,24 @@ install_deployment_kernel (OstreeSysroot *sysroot, { /* Try extracting a version for this deployment. */ const char *csum = ostree_deployment_get_csum (deployment); - g_autoptr(GVariant) variant = NULL; - g_autoptr(GVariant) metadata = NULL; + g_autoptr (GVariant) variant = NULL; + g_autoptr (GVariant) metadata = NULL; /* XXX Copying ot_admin_checksum_version() + bits from * ot-admin-builtin-status.c. Maybe this should be * public API in libostree? */ - if (ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, csum, - &variant, NULL)) + if (ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, csum, &variant, NULL)) { metadata = g_variant_get_child_value (variant, 0); - (void) g_variant_lookup (metadata, OSTREE_COMMIT_META_KEY_VERSION, "s", &deployment_version); + (void)g_variant_lookup (metadata, OSTREE_COMMIT_META_KEY_VERSION, "s", + &deployment_version); } } /* XXX The SYSLINUX bootloader backend actually parses the title string * (specifically, it looks for the substring "(ostree"), so further * changes to the title format may require updating that backend. */ - g_autoptr(GString) title_key = g_string_new (val); + g_autoptr (GString) title_key = g_string_new (val); if (deployment_version && *deployment_version && !strstr (val, deployment_version)) { g_string_append_c (title_key, ' '); @@ -2068,36 +1979,39 @@ install_deployment_kernel (OstreeSysroot *sysroot, g_string_append_c (title_key, ')'); ostree_bootconfig_parser_set (bootconfig, "title", title_key->str); - g_autofree char *version_key = g_strdup_printf ("%d", n_deployments - ostree_deployment_get_index (deployment)); + g_autofree char *version_key + = g_strdup_printf ("%d", n_deployments - ostree_deployment_get_index (deployment)); ostree_bootconfig_parser_set (bootconfig, OSTREE_COMMIT_META_KEY_VERSION, version_key); - g_autofree char * boot_relpath = g_strconcat (bootprefix, bootcsumdir, "/", kernel_layout->kernel_namever, NULL); + g_autofree char *boot_relpath + = g_strconcat (bootprefix, bootcsumdir, "/", kernel_layout->kernel_namever, NULL); ostree_bootconfig_parser_set (bootconfig, "linux", boot_relpath); val = ostree_bootconfig_parser_get (bootconfig, "options"); - g_autoptr(OstreeKernelArgs) kargs = ostree_kernel_args_from_string (val); + g_autoptr (OstreeKernelArgs) kargs = ostree_kernel_args_from_string (val); if (kernel_layout->initramfs_namever) { - g_autofree char * initrd_boot_relpath = - g_strconcat (bootprefix, bootcsumdir, "/", kernel_layout->initramfs_namever, NULL); + g_autofree char *initrd_boot_relpath + = g_strconcat (bootprefix, bootcsumdir, "/", kernel_layout->initramfs_namever, NULL); ostree_bootconfig_parser_set (bootconfig, "initrd", initrd_boot_relpath); if (overlay_initrds) { g_ptr_array_add (overlay_initrds, NULL); - ostree_bootconfig_parser_set_overlay_initrds (bootconfig, (char**)overlay_initrds->pdata); + ostree_bootconfig_parser_set_overlay_initrds (bootconfig, + (char **)overlay_initrds->pdata); } } else { g_autofree char *prepare_root_arg = NULL; - prepare_root_arg = g_strdup_printf ("init=/ostree/boot.%d/%s/%s/%d/usr/lib/ostree/ostree-prepare-root", - new_bootversion, osname, bootcsum, - ostree_deployment_get_bootserial (deployment)); + prepare_root_arg = g_strdup_printf ( + "init=/ostree/boot.%d/%s/%s/%d/usr/lib/ostree/ostree-prepare-root", new_bootversion, + osname, bootcsum, ostree_deployment_get_bootserial (deployment)); ostree_kernel_args_replace_take (kargs, g_steal_pointer (&prepare_root_arg)); } - const char* aboot_fn = NULL; + const char *aboot_fn = NULL; if (kernel_layout->aboot_namever) { aboot_fn = kernel_layout->aboot_namever; @@ -2109,21 +2023,24 @@ install_deployment_kernel (OstreeSysroot *sysroot, if (aboot_fn) { - g_autofree char * aboot_relpath = g_strconcat ("/", bootcsumdir, "/", aboot_fn, NULL); + g_autofree char *aboot_relpath = g_strconcat ("/", bootcsumdir, "/", aboot_fn, NULL); ostree_bootconfig_parser_set (bootconfig, "aboot", aboot_relpath); } else { - g_autofree char * aboot_relpath = g_strconcat ("/", deployment_dirpath, "/usr/lib/ostree-boot/aboot.img", NULL); + g_autofree char *aboot_relpath + = g_strconcat ("/", deployment_dirpath, "/usr/lib/ostree-boot/aboot.img", NULL); ostree_bootconfig_parser_set (bootconfig, "aboot", aboot_relpath); } - g_autofree char * abootcfg_relpath = g_strconcat ("/", deployment_dirpath, "/usr/lib/ostree-boot/aboot.cfg", NULL); + g_autofree char *abootcfg_relpath + = g_strconcat ("/", deployment_dirpath, "/usr/lib/ostree-boot/aboot.cfg", NULL); ostree_bootconfig_parser_set (bootconfig, "abootcfg", abootcfg_relpath); if (kernel_layout->devicetree_namever) { - g_autofree char * dt_boot_relpath = g_strconcat (bootprefix, bootcsumdir, "/", kernel_layout->devicetree_namever, NULL); + g_autofree char *dt_boot_relpath + = g_strconcat (bootprefix, bootcsumdir, "/", kernel_layout->devicetree_namever, NULL); ostree_bootconfig_parser_set (bootconfig, "devicetree", dt_boot_relpath); } else if (kernel_layout->devicetree_srcpath) @@ -2132,14 +2049,15 @@ install_deployment_kernel (OstreeSysroot *sysroot, * want to point to a whole directory of device trees. * See: https://github.com/ostreedev/ostree/issues/1900 */ - g_autofree char * dt_boot_relpath = g_strconcat (bootprefix, bootcsumdir, "/", kernel_layout->devicetree_srcpath, NULL); + g_autofree char *dt_boot_relpath + = g_strconcat (bootprefix, bootcsumdir, "/", kernel_layout->devicetree_srcpath, NULL); ostree_bootconfig_parser_set (bootconfig, "fdtdir", dt_boot_relpath); } /* Note this is parsed in ostree-impl-system-generator.c */ - g_autofree char *ostree_kernel_arg = g_strdup_printf ("ostree=/ostree/boot.%d/%s/%s/%d", - new_bootversion, osname, bootcsum, - ostree_deployment_get_bootserial (deployment)); + g_autofree char *ostree_kernel_arg + = g_strdup_printf ("ostree=/ostree/boot.%d/%s/%s/%d", new_bootversion, osname, bootcsum, + ostree_deployment_get_bootserial (deployment)); ostree_kernel_args_replace_take (kargs, g_steal_pointer (&ostree_kernel_arg)); g_autofree char *options_key = ostree_kernel_args_to_string (kargs); @@ -2148,7 +2066,7 @@ install_deployment_kernel (OstreeSysroot *sysroot, /* Only append to this BLS config if: * - this is not the default deployment */ - /* If deployment was prepended, it is the new default */ + /* If deployment was prepended, it is the new default */ gboolean is_new_default = (ostree_deployment_get_index (deployment) == 0); gboolean allow_append = !is_new_default; if (allow_append) @@ -2163,8 +2081,7 @@ install_deployment_kernel (OstreeSysroot *sysroot, return FALSE; if (!ostree_bootconfig_parser_write_at (ostree_deployment_get_bootconfig (deployment), - bootconf_dfd, bootconf_name, - cancellable, error)) + bootconf_dfd, bootconf_name, cancellable, error)) return FALSE; return TRUE; @@ -2175,15 +2092,12 @@ install_deployment_kernel (OstreeSysroot *sysroot, * rename it into place. */ static gboolean -prepare_new_bootloader_link (OstreeSysroot *sysroot, - int current_bootversion, - int new_bootversion, - GCancellable *cancellable, - GError **error) +prepare_new_bootloader_link (OstreeSysroot *sysroot, int current_bootversion, int new_bootversion, + GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("Preparing final bootloader swap", error); - g_assert ((current_bootversion == 0 && new_bootversion == 1) || - (current_bootversion == 1 && new_bootversion == 0)); + g_assert ((current_bootversion == 0 && new_bootversion == 1) + || (current_bootversion == 1 && new_bootversion == 0)); /* This allows us to support both /boot on a seperate filesystem to / as well * as on the same filesystem. */ @@ -2195,8 +2109,7 @@ prepare_new_bootloader_link (OstreeSysroot *sysroot, /* We shouldn't actually need to replace but it's easier to reuse that code */ - if (!symlink_at_replace (new_target, sysroot->sysroot_fd, "boot/loader.tmp", - cancellable, error)) + if (!symlink_at_replace (new_target, sysroot->sysroot_fd, "boot/loader.tmp", cancellable, error)) return FALSE; return TRUE; @@ -2204,19 +2117,15 @@ prepare_new_bootloader_link (OstreeSysroot *sysroot, /* Update the /boot/loader symlink to point to /boot/loader.$new_bootversion */ static gboolean -swap_bootloader (OstreeSysroot *sysroot, - OstreeBootloader *bootloader, - int current_bootversion, - int new_bootversion, - GCancellable *cancellable, - GError **error) +swap_bootloader (OstreeSysroot *sysroot, OstreeBootloader *bootloader, int current_bootversion, + int new_bootversion, GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("Final bootloader swap", error); - g_assert ((current_bootversion == 0 && new_bootversion == 1) || - (current_bootversion == 1 && new_bootversion == 0)); + g_assert ((current_bootversion == 0 && new_bootversion == 1) + || (current_bootversion == 1 && new_bootversion == 0)); - if (!_ostree_sysroot_ensure_boot_fd (sysroot, error)) + if (!_ostree_sysroot_ensure_boot_fd (sysroot, error)) return FALSE; /* The symlink was already written, and we used syncfs() to ensure @@ -2254,10 +2163,9 @@ swap_bootloader (OstreeSysroot *sysroot, * per-bootchecksum. It's used by the symbolic links after the bootloader. */ static void -assign_bootserials (GPtrArray *deployments) +assign_bootserials (GPtrArray *deployments) { - g_autoptr(GHashTable) serials = - g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); + g_autoptr (GHashTable) serials = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); for (guint i = 0; i < deployments->len; i++) { @@ -2265,36 +2173,34 @@ assign_bootserials (GPtrArray *deployments) const char *bootcsum = ostree_deployment_get_bootcsum (deployment); /* Note that not-found maps to NULL which converts to zero */ guint count = GPOINTER_TO_UINT (g_hash_table_lookup (serials, bootcsum)); - g_hash_table_replace (serials, (char*) bootcsum, - GUINT_TO_POINTER (count + 1)); + g_hash_table_replace (serials, (char *)bootcsum, GUINT_TO_POINTER (count + 1)); ostree_deployment_set_bootserial (deployment, count); } } -static char* +static char * get_deployment_nonostree_kargs (OstreeDeployment *deployment) { /* pick up kernel arguments but filter out ostree= */ OstreeBootconfigParser *bootconfig = ostree_deployment_get_bootconfig (deployment); const char *boot_options = ostree_bootconfig_parser_get (bootconfig, "options"); - g_autoptr(OstreeKernelArgs) kargs = ostree_kernel_args_from_string (boot_options); + g_autoptr (OstreeKernelArgs) kargs = ostree_kernel_args_from_string (boot_options); ostree_kernel_args_replace (kargs, "ostree"); return ostree_kernel_args_to_string (kargs); } -static char* -get_deployment_ostree_version (OstreeRepo *repo, - OstreeDeployment *deployment) +static char * +get_deployment_ostree_version (OstreeRepo *repo, OstreeDeployment *deployment) { const char *csum = ostree_deployment_get_csum (deployment); g_autofree char *version = NULL; - g_autoptr(GVariant) variant = NULL; + g_autoptr (GVariant) variant = NULL; if (ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, csum, &variant, NULL)) { - g_autoptr(GVariant) metadata = g_variant_get_child_value (variant, 0); - (void) g_variant_lookup (metadata, OSTREE_COMMIT_META_KEY_VERSION, "s", &version); + g_autoptr (GVariant) metadata = g_variant_get_child_value (variant, 0); + (void)g_variant_lookup (metadata, OSTREE_COMMIT_META_KEY_VERSION, "s", &version); } return g_steal_pointer (&version); @@ -2310,9 +2216,7 @@ get_deployment_ostree_version (OstreeRepo *repo, * bootloader perspective. */ static gboolean -deployment_bootconfigs_equal (OstreeRepo *repo, - OstreeDeployment *a, - OstreeDeployment *b) +deployment_bootconfigs_equal (OstreeRepo *repo, OstreeDeployment *a, OstreeDeployment *b) { /* same kernel & initramfs? */ const char *a_bootcsum = ostree_deployment_get_bootcsum (a); @@ -2345,11 +2249,9 @@ deployment_bootconfigs_equal (OstreeRepo *repo, * the OSTree API to find deployments. */ static gboolean -cleanup_legacy_current_symlinks (OstreeSysroot *self, - GCancellable *cancellable, - GError **error) +cleanup_legacy_current_symlinks (OstreeSysroot *self, GCancellable *cancellable, GError **error) { - g_autoptr(GString) buf = g_string_new (""); + g_autoptr (GString) buf = g_string_new (""); for (guint i = 0; i < self->deployments->len; i++) { @@ -2377,14 +2279,12 @@ cleanup_legacy_current_symlinks (OstreeSysroot *self, * version will perform post-deployment cleanup by default. */ gboolean -ostree_sysroot_write_deployments (OstreeSysroot *self, - GPtrArray *new_deployments, - GCancellable *cancellable, - GError **error) +ostree_sysroot_write_deployments (OstreeSysroot *self, GPtrArray *new_deployments, + GCancellable *cancellable, GError **error) { OstreeSysrootWriteDeploymentsOpts opts = { .do_postclean = TRUE }; - return ostree_sysroot_write_deployments_with_options (self, new_deployments, &opts, - cancellable, error); + return ostree_sysroot_write_deployments_with_options (self, new_deployments, &opts, cancellable, + error); } /* Handle writing out a new bootloader config. One reason this needs to be a @@ -2392,22 +2292,18 @@ ostree_sysroot_write_deployments (OstreeSysroot *self, * rw. */ static gboolean -write_deployments_bootswap (OstreeSysroot *self, - GPtrArray *new_deployments, - OstreeSysrootWriteDeploymentsOpts *opts, - OstreeBootloader *bootloader, - SyncStats *out_syncstats, - char **out_subbootdir, - GCancellable *cancellable, - GError **error) +write_deployments_bootswap (OstreeSysroot *self, GPtrArray *new_deployments, + OstreeSysrootWriteDeploymentsOpts *opts, OstreeBootloader *bootloader, + SyncStats *out_syncstats, char **out_subbootdir, + GCancellable *cancellable, GError **error) { const int new_bootversion = self->bootversion ? 0 : 1; - g_autofree char* new_loader_entries_dir = g_strdup_printf ("boot/loader.%d/entries", new_bootversion); + g_autofree char *new_loader_entries_dir + = g_strdup_printf ("boot/loader.%d/entries", new_bootversion); if (!glnx_shutil_rm_rf_at (self->sysroot_fd, new_loader_entries_dir, cancellable, error)) return FALSE; - if (!glnx_shutil_mkdir_p_at (self->sysroot_fd, new_loader_entries_dir, 0755, - cancellable, error)) + if (!glnx_shutil_mkdir_p_at (self->sysroot_fd, new_loader_entries_dir, 0755, cancellable, error)) return FALSE; /* Only show the osname in bootloader titles if there are multiple @@ -2427,42 +2323,35 @@ write_deployments_bootswap (OstreeSysroot *self, for (guint i = 0; i < new_deployments->len; i++) { OstreeDeployment *deployment = new_deployments->pdata[i]; - if (!install_deployment_kernel (self, new_bootversion, - deployment, new_deployments->len, + if (!install_deployment_kernel (self, new_bootversion, deployment, new_deployments->len, show_osname, cancellable, error)) return FALSE; } /* Create and swap bootlinks for *new* version */ - if (!create_new_bootlinks (self, new_bootversion, - new_deployments, - cancellable, error)) + if (!create_new_bootlinks (self, new_bootversion, new_deployments, cancellable, error)) return FALSE; g_autofree char *new_subbootdir = NULL; - if (!swap_bootlinks (self, new_bootversion, new_deployments, &new_subbootdir, - cancellable, error)) + if (!swap_bootlinks (self, new_bootversion, new_deployments, &new_subbootdir, cancellable, error)) return FALSE; - g_debug ("Using bootloader: %s", bootloader ? - g_type_name (G_TYPE_FROM_INSTANCE (bootloader)) : "(none)"); + g_debug ("Using bootloader: %s", + bootloader ? g_type_name (G_TYPE_FROM_INSTANCE (bootloader)) : "(none)"); if (bootloader) { - if (!_ostree_bootloader_write_config (bootloader, new_bootversion, - new_deployments, cancellable, - error)) + if (!_ostree_bootloader_write_config (bootloader, new_bootversion, new_deployments, + cancellable, error)) return glnx_prefix_error (error, "Bootloader write config"); } - if (!prepare_new_bootloader_link (self, self->bootversion, new_bootversion, - cancellable, error)) + if (!prepare_new_bootloader_link (self, self->bootversion, new_bootversion, cancellable, error)) return FALSE; if (!full_system_sync (self, out_syncstats, cancellable, error)) return FALSE; - if (!swap_bootloader (self, bootloader, self->bootversion, new_bootversion, - cancellable, error)) + if (!swap_bootloader (self, bootloader, self->bootversion, new_bootversion, cancellable, error)) return FALSE; if (out_subbootdir) @@ -2472,9 +2361,7 @@ write_deployments_bootswap (OstreeSysroot *self, /* Actions taken after writing deployments is complete */ static gboolean -write_deployments_finish (OstreeSysroot *self, - GCancellable *cancellable, - GError **error) +write_deployments_finish (OstreeSysroot *self, GCancellable *cancellable, GError **error) { if (!_ostree_sysroot_bump_mtime (self, error)) return FALSE; @@ -2490,10 +2377,7 @@ write_deployments_finish (OstreeSysroot *self, } static gboolean -add_file_size_if_nonnull (int dfd, - const char *path, - guint64 *inout_size, - GError **error) +add_file_size_if_nonnull (int dfd, const char *path, guint64 *inout_size, GError **error) { if (path == NULL) return TRUE; @@ -2509,47 +2393,48 @@ add_file_size_if_nonnull (int dfd, /* calculates the total size of the bootcsum dir in /boot after we would copy * it. This reflects the logic in install_deployment_kernel(). */ static gboolean -get_kernel_layout_size (OstreeSysroot *self, - OstreeDeployment *deployment, - guint64 *out_size, - GCancellable *cancellable, - GError **error) +get_kernel_layout_size (OstreeSysroot *self, OstreeDeployment *deployment, guint64 *out_size, + GCancellable *cancellable, GError **error) { g_autofree char *deployment_dirpath = ostree_sysroot_get_deployment_dirpath (self, deployment); glnx_autofd int deployment_dfd = -1; - if (!glnx_opendirat (self->sysroot_fd, deployment_dirpath, FALSE, - &deployment_dfd, error)) + if (!glnx_opendirat (self->sysroot_fd, deployment_dirpath, FALSE, &deployment_dfd, error)) return FALSE; - g_autoptr(OstreeKernelLayout) kernel_layout = NULL; - if (!get_kernel_from_tree (self, deployment_dfd, &kernel_layout, - cancellable, error)) + g_autoptr (OstreeKernelLayout) kernel_layout = NULL; + if (!get_kernel_from_tree (self, deployment_dfd, &kernel_layout, cancellable, error)) return FALSE; guint64 bootdir_size = 0; - if (!add_file_size_if_nonnull (kernel_layout->boot_dfd, kernel_layout->kernel_srcpath, &bootdir_size, error)) + if (!add_file_size_if_nonnull (kernel_layout->boot_dfd, kernel_layout->kernel_srcpath, + &bootdir_size, error)) return FALSE; - if (!add_file_size_if_nonnull (kernel_layout->boot_dfd, kernel_layout->initramfs_srcpath, &bootdir_size, error)) + if (!add_file_size_if_nonnull (kernel_layout->boot_dfd, kernel_layout->initramfs_srcpath, + &bootdir_size, error)) return FALSE; if (kernel_layout->devicetree_srcpath) { /* These conditionals mirror the logic in install_deployment_kernel(). */ if (kernel_layout->devicetree_namever) { - if (!add_file_size_if_nonnull (kernel_layout->boot_dfd, kernel_layout->devicetree_srcpath, &bootdir_size, error)) + if (!add_file_size_if_nonnull (kernel_layout->boot_dfd, kernel_layout->devicetree_srcpath, + &bootdir_size, error)) return FALSE; } else { guint64 dirsize = 0; - if (!ot_get_dir_size (kernel_layout->boot_dfd, kernel_layout->devicetree_srcpath, &dirsize, cancellable, error)) + if (!ot_get_dir_size (kernel_layout->boot_dfd, kernel_layout->devicetree_srcpath, + &dirsize, cancellable, error)) return FALSE; bootdir_size += dirsize; } } - if (!add_file_size_if_nonnull (kernel_layout->boot_dfd, kernel_layout->kernel_hmac_srcpath, &bootdir_size, error)) + if (!add_file_size_if_nonnull (kernel_layout->boot_dfd, kernel_layout->kernel_hmac_srcpath, + &bootdir_size, error)) return FALSE; - if (!add_file_size_if_nonnull (kernel_layout->boot_dfd, kernel_layout->aboot_srcpath, &bootdir_size, error)) + if (!add_file_size_if_nonnull (kernel_layout->boot_dfd, kernel_layout->aboot_srcpath, + &bootdir_size, error)) return FALSE; *out_size = bootdir_size; @@ -2561,10 +2446,8 @@ get_kernel_layout_size (OstreeSysroot *self, * getting rotated out (e.g. the current rollback) would free up sufficient * space. If so, call ostree_sysroot_write_deployments() to delete them. */ static gboolean -auto_early_prune_old_deployments (OstreeSysroot *self, - GPtrArray *new_deployments, - GCancellable *cancellable, - GError **error) +auto_early_prune_old_deployments (OstreeSysroot *self, GPtrArray *new_deployments, + GCancellable *cancellable, GError **error) { /* If we're not booted into a deployment, then this is some kind of e.g. disk * creation/provisioning. The situation isn't as dire, so let's not resort to @@ -2588,12 +2471,14 @@ auto_early_prune_old_deployments (OstreeSysroot *self, return FALSE; /* tracks all the bootcsums currently in /boot */ - g_autoptr(GHashTable) current_bootcsums = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + g_autoptr (GHashTable) current_bootcsums + = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); /* tracks all the bootcsums of new_deployments */ - g_autoptr(GHashTable) new_bootcsums = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + g_autoptr (GHashTable) new_bootcsums + = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - g_auto(GStrv) bootdirs = NULL; + g_auto (GStrv) bootdirs = NULL; if (!_ostree_sysroot_list_all_boot_directories (self, &bootdirs, cancellable, error)) return glnx_prefix_error (error, "listing bootcsum directories in bootfs"); @@ -2623,12 +2508,14 @@ auto_early_prune_old_deployments (OstreeSysroot *self, * size aware too for better accuracy, which is awkward since the * function itself is generic over directories and doesn't consider * e.g. mount points from different filesystems. */ - g_printerr ("bootcsum %s size exceeds %u; disabling auto-prune optimization\n", bootdir, G_MAXUINT); + g_printerr ("bootcsum %s size exceeds %u; disabling auto-prune optimization\n", bootdir, + G_MAXUINT); return TRUE; } g_assert_cmpuint (bootdir_size, >, 0); - g_hash_table_insert (current_bootcsums, g_steal_pointer (&bootcsum), GUINT_TO_POINTER (bootdir_size)); + g_hash_table_insert (current_bootcsums, g_steal_pointer (&bootcsum), + GUINT_TO_POINTER (bootdir_size)); } /* total size of all bootcsums dirs that aren't already in /boot */ @@ -2654,8 +2541,9 @@ auto_early_prune_old_deployments (OstreeSysroot *self, /* see similar logic in previous loop */ if (bootdir_size > G_MAXUINT) { - g_printerr ("deployment %s kernel layout size exceeds %u; disabling auto-prune optimization\n", - ostree_deployment_get_csum (deployment), G_MAXUINT); + g_printerr ( + "deployment %s kernel layout size exceeds %u; disabling auto-prune optimization\n", + ostree_deployment_get_csum (deployment), G_MAXUINT); return TRUE; } @@ -2696,7 +2584,7 @@ auto_early_prune_old_deployments (OstreeSysroot *self, g_printerr ("Insufficient space left in bootfs; updating bootloader in two steps\n"); /* Auto-pruning can salvage the situation. Calculate the set of deployments in common. */ - g_autoptr(GPtrArray) common_deployments = g_ptr_array_new (); + g_autoptr (GPtrArray) common_deployments = g_ptr_array_new (); for (guint i = 0; i < self->deployments->len; i++) { OstreeDeployment *deployment = self->deployments->pdata[i]; @@ -2719,8 +2607,10 @@ auto_early_prune_old_deployments (OstreeSysroot *self, * common deployments. To be safe, disable auto-pruning to make recursion * impossible (though the logic in this function shouldn't kick in anyway in * that recursive call). Disable cleaning since it's an intermediate stage. */ - OstreeSysrootWriteDeploymentsOpts opts = { .do_postclean = FALSE, .disable_auto_early_prune = TRUE }; - if (!ostree_sysroot_write_deployments_with_options (self, common_deployments, &opts, cancellable, error)) + OstreeSysrootWriteDeploymentsOpts opts + = { .do_postclean = FALSE, .disable_auto_early_prune = TRUE }; + if (!ostree_sysroot_write_deployments_with_options (self, common_deployments, &opts, cancellable, + error)) return FALSE; /* clean up /boot */ @@ -2748,11 +2638,9 @@ auto_early_prune_old_deployments (OstreeSysroot *self, * Since: 2017.4 */ gboolean -ostree_sysroot_write_deployments_with_options (OstreeSysroot *self, - GPtrArray *new_deployments, +ostree_sysroot_write_deployments_with_options (OstreeSysroot *self, GPtrArray *new_deployments, OstreeSysrootWriteDeploymentsOpts *opts, - GCancellable *cancellable, - GError **error) + GCancellable *cancellable, GError **error) { g_assert (self->loadstate == OSTREE_SYSROOT_LOAD_STATE_LOADED); @@ -2761,8 +2649,8 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self, /* for now, this is gated on an environment variable */ const gboolean opted_in = (self->opt_flags & OSTREE_SYSROOT_GLOBAL_OPT_EARLY_PRUNE) > 0; - if (opted_in && !opts->disable_auto_early_prune && - !auto_early_prune_old_deployments (self, new_deployments, cancellable, error)) + if (opted_in && !opts->disable_auto_early_prune + && !auto_early_prune_old_deployments (self, new_deployments, cancellable, error)) return FALSE; /* Dealing with the staged deployment is quite tricky here. This function is @@ -2773,7 +2661,7 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self, * silently dropped. */ - g_autoptr(GPtrArray) new_deployments_copy = g_ptr_array_new (); + g_autoptr (GPtrArray) new_deployments_copy = g_ptr_array_new (); gboolean removed_staged = (self->staged_deployment != NULL); if (new_deployments->len > 0) { @@ -2882,7 +2770,8 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self, if (ostree_deployment_equal (deployment, self->booted_deployment)) found_booted_deployment = TRUE; - g_autoptr(GFile) deployment_root = ostree_sysroot_get_deployment_directory (self, deployment); + g_autoptr (GFile) deployment_root + = ostree_sysroot_get_deployment_directory (self, deployment); if (!g_file_query_exists (deployment_root, NULL)) return glnx_throw (error, "Unable to find expected deployment root: %s", gs_file_get_path_cached (deployment_root)); @@ -2894,22 +2783,21 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self, return glnx_throw (error, "Attempting to remove booted deployment"); gboolean bootloader_is_atomic = FALSE; - SyncStats syncstats = { 0, }; - g_autoptr(OstreeBootloader) bootloader = NULL; + SyncStats syncstats = { + 0, + }; + g_autoptr (OstreeBootloader) bootloader = NULL; g_autofree char *new_subbootdir = NULL; if (!requires_new_bootversion) { - if (!create_new_bootlinks (self, self->bootversion, - new_deployments, - cancellable, error)) + if (!create_new_bootlinks (self, self->bootversion, new_deployments, cancellable, error)) return FALSE; if (!full_system_sync (self, &syncstats, cancellable, error)) return FALSE; - if (!swap_bootlinks (self, self->bootversion, - new_deployments, &new_subbootdir, - cancellable, error)) + if (!swap_bootlinks (self, self->bootversion, new_deployments, &new_subbootdir, cancellable, + error)) return FALSE; bootloader_is_atomic = TRUE; @@ -2921,29 +2809,28 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self, bootloader_is_atomic = bootloader != NULL && _ostree_bootloader_is_atomic (bootloader); - if (!write_deployments_bootswap (self, new_deployments, opts, bootloader, - &syncstats, &new_subbootdir, cancellable, error)) + if (!write_deployments_bootswap (self, new_deployments, opts, bootloader, &syncstats, + &new_subbootdir, cancellable, error)) return FALSE; } - { g_autofree char *msg = - g_strdup_printf ("%s; bootconfig swap: %s; bootversion: %s, deployment count change: %i", - (bootloader_is_atomic ? "Transaction complete" : "Bootloader updated"), - requires_new_bootversion ? "yes" : "no", - new_subbootdir, - new_deployments->len - self->deployments->len); + { + g_autofree char *msg + = g_strdup_printf ("%s; bootconfig swap: %s; bootversion: %s, deployment count change: %i", + (bootloader_is_atomic ? "Transaction complete" : "Bootloader updated"), + requires_new_bootversion ? "yes" : "no", new_subbootdir, + new_deployments->len - self->deployments->len); const gchar *bootloader_config = ostree_repo_get_bootloader (ostree_sysroot_repo (self)); - ot_journal_send ("MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(OSTREE_DEPLOYMENT_COMPLETE_ID), - "MESSAGE=%s", msg, - "OSTREE_BOOTLOADER=%s", bootloader ? _ostree_bootloader_get_name (bootloader) : "none", - "OSTREE_BOOTLOADER_CONFIG=%s", bootloader_config, - "OSTREE_BOOTLOADER_ATOMIC=%s", bootloader_is_atomic ? "yes" : "no", - "OSTREE_DID_BOOTSWAP=%s", requires_new_bootversion ? "yes" : "no", - "OSTREE_N_DEPLOYMENTS=%u", new_deployments->len, - "OSTREE_SYNCFS_ROOT_MSEC=%" G_GUINT64_FORMAT, syncstats.root_syncfs_msec, - "OSTREE_SYNCFS_BOOT_MSEC=%" G_GUINT64_FORMAT, syncstats.boot_syncfs_msec, - "OSTREE_SYNCFS_EXTRA_MSEC=%" G_GUINT64_FORMAT, syncstats.extra_syncfs_msec, - NULL); + ot_journal_send ( + "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL (OSTREE_DEPLOYMENT_COMPLETE_ID), + "MESSAGE=%s", msg, "OSTREE_BOOTLOADER=%s", + bootloader ? _ostree_bootloader_get_name (bootloader) : "none", + "OSTREE_BOOTLOADER_CONFIG=%s", bootloader_config, "OSTREE_BOOTLOADER_ATOMIC=%s", + bootloader_is_atomic ? "yes" : "no", "OSTREE_DID_BOOTSWAP=%s", + requires_new_bootversion ? "yes" : "no", "OSTREE_N_DEPLOYMENTS=%u", new_deployments->len, + "OSTREE_SYNCFS_ROOT_MSEC=%" G_GUINT64_FORMAT, syncstats.root_syncfs_msec, + "OSTREE_SYNCFS_BOOT_MSEC=%" G_GUINT64_FORMAT, syncstats.boot_syncfs_msec, + "OSTREE_SYNCFS_EXTRA_MSEC=%" G_GUINT64_FORMAT, syncstats.extra_syncfs_msec, NULL); _ostree_sysroot_emit_journal_msg (self, msg); } @@ -2962,23 +2849,17 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self, } static gboolean -allocate_deployserial (OstreeSysroot *self, - const char *osname, - const char *revision, - int *out_deployserial, - GCancellable *cancellable, - GError **error) +allocate_deployserial (OstreeSysroot *self, const char *osname, const char *revision, + int *out_deployserial, GCancellable *cancellable, GError **error) { int new_deployserial = 0; - g_autoptr(GPtrArray) tmp_current_deployments = - g_ptr_array_new_with_free_func (g_object_unref); + g_autoptr (GPtrArray) tmp_current_deployments = g_ptr_array_new_with_free_func (g_object_unref); glnx_autofd int deploy_dfd = -1; if (!glnx_opendirat (self->sysroot_fd, "ostree/deploy", TRUE, &deploy_dfd, error)) return FALSE; - if (!_ostree_sysroot_list_deployment_dirs_for_os (deploy_dfd, osname, - tmp_current_deployments, + if (!_ostree_sysroot_list_deployment_dirs_for_os (deploy_dfd, osname, tmp_current_deployments, cancellable, error)) return FALSE; @@ -2989,7 +2870,8 @@ allocate_deployserial (OstreeSysroot *self, if (strcmp (ostree_deployment_get_csum (deployment), revision) != 0) continue; - new_deployserial = MAX(new_deployserial, ostree_deployment_get_deployserial (deployment)+1); + new_deployserial + = MAX (new_deployserial, ostree_deployment_get_deployserial (deployment) + 1); } *out_deployserial = new_deployserial; @@ -2998,12 +2880,12 @@ allocate_deployserial (OstreeSysroot *self, void _ostree_deployment_set_bootconfig_from_kargs (OstreeDeployment *deployment, - char **override_kernel_argv) + char **override_kernel_argv) { /* Create an empty boot configuration; we will merge things into * it as we go. */ - g_autoptr(OstreeBootconfigParser) bootconfig = ostree_bootconfig_parser_new (); + g_autoptr (OstreeBootconfigParser) bootconfig = ostree_bootconfig_parser_new (); ostree_deployment_set_bootconfig (deployment, bootconfig); /* After this, install_deployment_kernel() will set the other boot @@ -3011,7 +2893,7 @@ _ostree_deployment_set_bootconfig_from_kargs (OstreeDeployment *deployment, */ if (override_kernel_argv) { - g_autoptr(OstreeKernelArgs) kargs = ostree_kernel_args_new (); + g_autoptr (OstreeKernelArgs) kargs = ostree_kernel_args_new (); ostree_kernel_args_append_argv (kargs, override_kernel_argv); g_autofree char *new_options = ostree_kernel_args_to_string (kargs); ostree_bootconfig_parser_set (bootconfig, "options", new_options); @@ -3022,13 +2904,12 @@ _ostree_deployment_set_bootconfig_from_kargs (OstreeDeployment *deployment, // that are likely to fail later. This function only returns // a hard error if something unexpected (e.g. I/O error) occurs. static gboolean -lint_deployment_fs (OstreeSysroot *self, - OstreeDeployment *deployment, - int deployment_dfd, - GCancellable *cancellable, - GError **error) +lint_deployment_fs (OstreeSysroot *self, OstreeDeployment *deployment, int deployment_dfd, + GCancellable *cancellable, GError **error) { - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; glnx_autofd int dest_dfd = -1; gboolean exists; @@ -3043,9 +2924,10 @@ lint_deployment_fs (OstreeSysroot *self, if (dent == NULL) break; - fprintf (stderr, "note: Deploying commit %s which contains content in /var/%s that will be ignored.\n", - ostree_deployment_get_csum (deployment), - dent->d_name); + fprintf ( + stderr, + "note: Deploying commit %s which contains content in /var/%s that will be ignored.\n", + ostree_deployment_get_csum (deployment), dent->d_name); } return TRUE; @@ -3055,14 +2937,10 @@ lint_deployment_fs (OstreeSysroot *self, * hardlink farm checkout, but we also compute some initial state. */ static gboolean -sysroot_initialize_deployment (OstreeSysroot *self, - const char *osname, - const char *revision, - GKeyFile *origin, - OstreeSysrootDeployTreeOpts *opts, - OstreeDeployment **out_new_deployment, - GCancellable *cancellable, - GError **error) +sysroot_initialize_deployment (OstreeSysroot *self, const char *osname, const char *revision, + GKeyFile *origin, OstreeSysrootDeployTreeOpts *opts, + OstreeDeployment **out_new_deployment, GCancellable *cancellable, + GError **error) { g_assert (osname != NULL || self->booted_deployment != NULL); @@ -3072,31 +2950,28 @@ sysroot_initialize_deployment (OstreeSysroot *self, OstreeRepo *repo = ostree_sysroot_repo (self); gint new_deployserial; - if (!allocate_deployserial (self, osname, revision, &new_deployserial, - cancellable, error)) + if (!allocate_deployserial (self, osname, revision, &new_deployserial, cancellable, error)) return FALSE; - g_autoptr(OstreeDeployment) new_deployment = - ostree_deployment_new (0, osname, revision, new_deployserial, NULL, -1); + g_autoptr (OstreeDeployment) new_deployment + = ostree_deployment_new (0, osname, revision, new_deployserial, NULL, -1); ostree_deployment_set_origin (new_deployment, origin); /* Check out the userspace tree onto the filesystem */ glnx_autofd int deployment_dfd = -1; - if (!checkout_deployment_tree (self, repo, new_deployment, &deployment_dfd, - cancellable, error)) + if (!checkout_deployment_tree (self, repo, new_deployment, &deployment_dfd, cancellable, error)) return FALSE; - g_autoptr(OstreeKernelLayout) kernel_layout = NULL; - if (!get_kernel_from_tree (self, deployment_dfd, &kernel_layout, - cancellable, error)) + g_autoptr (OstreeKernelLayout) kernel_layout = NULL; + if (!get_kernel_from_tree (self, deployment_dfd, &kernel_layout, cancellable, error)) return FALSE; _ostree_deployment_set_bootcsum (new_deployment, kernel_layout->bootcsum); - _ostree_deployment_set_bootconfig_from_kargs (new_deployment, opts ? opts->override_kernel_argv : NULL); + _ostree_deployment_set_bootconfig_from_kargs (new_deployment, + opts ? opts->override_kernel_argv : NULL); _ostree_deployment_set_overlay_initrds (new_deployment, opts ? opts->overlay_initrds : NULL); - if (!prepare_deployment_etc (self, repo, new_deployment, deployment_dfd, - cancellable, error)) + if (!prepare_deployment_etc (self, repo, new_deployment, deployment_dfd, cancellable, error)) return FALSE; if (!lint_deployment_fs (self, new_deployment, deployment_dfd, cancellable, error)) @@ -3116,14 +2991,11 @@ sysroot_initialize_deployment (OstreeSysroot *self, * nor (relatedly) the case of upgrading a separate stateroot. */ static gboolean -get_var_dfd (OstreeSysroot *self, - int osdeploy_dfd, - OstreeDeployment *deployment, - int *ret_fd, - GError **error) +get_var_dfd (OstreeSysroot *self, int osdeploy_dfd, OstreeDeployment *deployment, int *ret_fd, + GError **error) { - const char *booted_stateroot = - self->booted_deployment ? ostree_deployment_get_osname (self->booted_deployment) : NULL; + const char *booted_stateroot + = self->booted_deployment ? ostree_deployment_get_osname (self->booted_deployment) : NULL; int base_dfd; const char *base_path; @@ -3151,8 +3023,8 @@ get_var_dfd (OstreeSysroot *self, static void child_setup_fchdir (gpointer data) { - int fd = (int) (uintptr_t) data; - int rc __attribute__((unused)); + int fd = (int)(uintptr_t)data; + int rc __attribute__ ((unused)); rc = fchdir (fd); } @@ -3161,35 +3033,65 @@ child_setup_fchdir (gpointer data) * Derived from rpm-ostree's rust/src/bwrap.rs */ static gboolean -run_in_deployment (int deployment_dfd, - const gchar * const *child_argv, - gsize child_argc, - gint *exit_status, - gchar **stdout, - GError **error) +run_in_deployment (int deployment_dfd, const gchar *const *child_argv, gsize child_argc, + gint *exit_status, gchar **stdout, GError **error) { - static const gchar * const COMMON_ARGV[] = { + static const gchar *const COMMON_ARGV[] = { "/usr/bin/bwrap", - "--dev", "/dev", "--proc", "/proc", "--dir", "/run", "--dir", "/tmp", - "--chdir", "/", + "--dev", + "/dev", + "--proc", + "/proc", + "--dir", + "/run", + "--dir", + "/tmp", + "--chdir", + "/", "--die-with-parent", "--unshare-pid", "--unshare-uts", "--unshare-ipc", "--unshare-cgroup-try", - "--ro-bind", "/sys/block", "/sys/block", - "--ro-bind", "/sys/bus", "/sys/bus", - "--ro-bind", "/sys/class", "/sys/class", - "--ro-bind", "/sys/dev", "/sys/dev", - "--ro-bind", "/sys/devices", "/sys/devices", - "--bind", "usr", "/usr", - "--bind", "etc", "/etc", - "--bind", "var", "/var", - "--symlink", "/usr/lib", "/lib", - "--symlink", "/usr/lib32", "/lib32", - "--symlink", "/usr/lib64", "/lib64", - "--symlink", "/usr/bin", "/bin", - "--symlink", "/usr/sbin", "/sbin", + "--ro-bind", + "/sys/block", + "/sys/block", + "--ro-bind", + "/sys/bus", + "/sys/bus", + "--ro-bind", + "/sys/class", + "/sys/class", + "--ro-bind", + "/sys/dev", + "/sys/dev", + "--ro-bind", + "/sys/devices", + "/sys/devices", + "--bind", + "usr", + "/usr", + "--bind", + "etc", + "/etc", + "--bind", + "var", + "/var", + "--symlink", + "/usr/lib", + "/lib", + "--symlink", + "/usr/lib32", + "/lib32", + "--symlink", + "/usr/lib64", + "/lib64", + "--symlink", + "/usr/bin", + "/bin", + "--symlink", + "/usr/sbin", + "/sbin", }; static const gsize COMMON_ARGC = sizeof (COMMON_ARGV) / sizeof (*COMMON_ARGV); @@ -3198,18 +3100,17 @@ run_in_deployment (int deployment_dfd, g_autofree gchar **args_raw = NULL; for (i = 0; i < COMMON_ARGC; i++) - g_ptr_array_add (args, (gchar *) COMMON_ARGV[i]); + g_ptr_array_add (args, (gchar *)COMMON_ARGV[i]); for (i = 0; i < child_argc; i++) - g_ptr_array_add (args, (gchar *) child_argv[i]); + g_ptr_array_add (args, (gchar *)child_argv[i]); g_ptr_array_add (args, NULL); - args_raw = (gchar **) g_ptr_array_free (args, FALSE); + args_raw = (gchar **)g_ptr_array_free (args, FALSE); return g_spawn_sync (NULL, args_raw, NULL, 0, &child_setup_fchdir, - (gpointer) (uintptr_t) deployment_dfd, - stdout, NULL, exit_status, error); + (gpointer)(uintptr_t)deployment_dfd, stdout, NULL, exit_status, error); } /* @@ -3223,8 +3124,8 @@ sysroot_finalize_selinux_policy (int deployment_dfd, GError **error) gint exit_status; g_autofree gchar *stdout = NULL; - if (!glnx_fstatat_allow_noent (deployment_dfd, "etc/selinux/config", &stbuf, - AT_SYMLINK_NOFOLLOW, error)) + if (!glnx_fstatat_allow_noent (deployment_dfd, "etc/selinux/config", &stbuf, AT_SYMLINK_NOFOLLOW, + error)) return FALSE; /* Skip the SELinux policy refresh if /etc/selinux/config doesn't exist. */ @@ -3235,39 +3136,35 @@ sysroot_finalize_selinux_policy (int deployment_dfd, GError **error) * Skip the SELinux policy refresh if the --refresh * flag is not supported by semodule. */ - static const gchar * const SEMODULE_HELP_ARGV[] = { - "semodule", "--help" - }; - static const gsize SEMODULE_HELP_ARGC = sizeof (SEMODULE_HELP_ARGV) / sizeof (*SEMODULE_HELP_ARGV); - if (!run_in_deployment (deployment_dfd, SEMODULE_HELP_ARGV, - SEMODULE_HELP_ARGC, &exit_status, &stdout, error)) + static const gchar *const SEMODULE_HELP_ARGV[] = { "semodule", "--help" }; + static const gsize SEMODULE_HELP_ARGC + = sizeof (SEMODULE_HELP_ARGV) / sizeof (*SEMODULE_HELP_ARGV); + if (!run_in_deployment (deployment_dfd, SEMODULE_HELP_ARGV, SEMODULE_HELP_ARGC, &exit_status, + &stdout, error)) return FALSE; if (!g_spawn_check_exit_status (exit_status, error)) return glnx_prefix_error (error, "failed to run semodule"); - if (!strstr(stdout, "--refresh")) + if (!strstr (stdout, "--refresh")) { ot_journal_print (LOG_INFO, "semodule does not have --refresh"); return TRUE; } - static const gchar * const SEMODULE_REBUILD_ARGV[] = { - "semodule", "-N", "--refresh" - }; - static const gsize SEMODULE_REBUILD_ARGC = sizeof (SEMODULE_REBUILD_ARGV) / sizeof (*SEMODULE_REBUILD_ARGV); + static const gchar *const SEMODULE_REBUILD_ARGV[] = { "semodule", "-N", "--refresh" }; + static const gsize SEMODULE_REBUILD_ARGC + = sizeof (SEMODULE_REBUILD_ARGV) / sizeof (*SEMODULE_REBUILD_ARGV); - if (!run_in_deployment (deployment_dfd, SEMODULE_REBUILD_ARGV, - SEMODULE_REBUILD_ARGC, &exit_status, NULL, error)) + if (!run_in_deployment (deployment_dfd, SEMODULE_REBUILD_ARGV, SEMODULE_REBUILD_ARGC, + &exit_status, NULL, error)) return FALSE; return g_spawn_check_exit_status (exit_status, error); } #endif /* HAVE_SELINUX */ static gboolean -sysroot_finalize_deployment (OstreeSysroot *self, - OstreeDeployment *deployment, - OstreeDeployment *merge_deployment, - GCancellable *cancellable, - GError **error) +sysroot_finalize_deployment (OstreeSysroot *self, OstreeDeployment *deployment, + OstreeDeployment *merge_deployment, GCancellable *cancellable, + GError **error) { g_autofree char *deployment_path = ostree_sysroot_get_deployment_dirpath (self, deployment); glnx_autofd int deployment_dfd = -1; @@ -3281,13 +3178,13 @@ sysroot_finalize_deployment (OstreeSysroot *self, * finalize-staged path, they're set by OstreeSysroot when reading the staged GVariant. */ if (merge_deployment && ostree_bootconfig_parser_get (bootconfig, "options") == NULL) { - OstreeBootconfigParser *merge_bootconfig = ostree_deployment_get_bootconfig (merge_deployment); + OstreeBootconfigParser *merge_bootconfig + = ostree_deployment_get_bootconfig (merge_deployment); if (merge_bootconfig) { const char *kargs = ostree_bootconfig_parser_get (merge_bootconfig, "options"); ostree_bootconfig_parser_set (bootconfig, "options", kargs); } - } if (merge_deployment) @@ -3303,7 +3200,8 @@ sysroot_finalize_deployment (OstreeSysroot *self, #endif /* HAVE_SELINUX */ } - const char *osdeploypath = glnx_strjoina ("ostree/deploy/", ostree_deployment_get_osname (deployment)); + const char *osdeploypath + = glnx_strjoina ("ostree/deploy/", ostree_deployment_get_osname (deployment)); glnx_autofd int os_deploy_dfd = -1; if (!glnx_opendirat (self->sysroot_fd, osdeploypath, TRUE, &os_deploy_dfd, error)) return FALSE; @@ -3320,7 +3218,7 @@ sysroot_finalize_deployment (OstreeSysroot *self, if (!ot_ensure_unlinked_at (var_dfd, ".updated", error)) return FALSE; - g_autoptr(OstreeSePolicy) sepolicy = ostree_sepolicy_new_at (deployment_dfd, cancellable, error); + g_autoptr (OstreeSePolicy) sepolicy = ostree_sepolicy_new_at (deployment_dfd, cancellable, error); if (!sepolicy) return FALSE; @@ -3332,15 +3230,13 @@ sysroot_finalize_deployment (OstreeSysroot *self, */ if (!write_origin_file_internal (self, sepolicy, deployment, ostree_deployment_get_origin (deployment), - GLNX_FILE_REPLACE_NODATASYNC, - cancellable, error)) + GLNX_FILE_REPLACE_NODATASYNC, cancellable, error)) return FALSE; /* Seal it */ if (!(self->debug_flags & OSTREE_SYSROOT_DEBUG_MUTABLE_DEPLOYMENTS)) { - if (!ostree_sysroot_deployment_set_mutable (self, deployment, FALSE, - cancellable, error)) + if (!ostree_sysroot_deployment_set_mutable (self, deployment, FALSE, cancellable, error)) return FALSE; } @@ -3368,26 +3264,23 @@ sysroot_finalize_deployment (OstreeSysroot *self, * Since: 2020.7 */ gboolean -ostree_sysroot_deploy_tree_with_options (OstreeSysroot *self, - const char *osname, - const char *revision, - GKeyFile *origin, - OstreeDeployment *provided_merge_deployment, +ostree_sysroot_deploy_tree_with_options (OstreeSysroot *self, const char *osname, + const char *revision, GKeyFile *origin, + OstreeDeployment *provided_merge_deployment, OstreeSysrootDeployTreeOpts *opts, OstreeDeployment **out_new_deployment, - GCancellable *cancellable, - GError **error) + GCancellable *cancellable, GError **error) { if (!_ostree_sysroot_ensure_writable (self, error)) return FALSE; - g_autoptr(OstreeDeployment) deployment = NULL; - if (!sysroot_initialize_deployment (self, osname, revision, origin, opts, - &deployment, cancellable, error)) + g_autoptr (OstreeDeployment) deployment = NULL; + if (!sysroot_initialize_deployment (self, osname, revision, origin, opts, &deployment, + cancellable, error)) return FALSE; - if (!sysroot_finalize_deployment (self, deployment, provided_merge_deployment, - cancellable, error)) + if (!sysroot_finalize_deployment (self, deployment, provided_merge_deployment, cancellable, + error)) return FALSE; *out_new_deployment = g_steal_pointer (&deployment); @@ -3401,7 +3294,8 @@ ostree_sysroot_deploy_tree_with_options (OstreeSysroot *self, * @revision: Checksum to add * @origin: (nullable): Origin to use for upgrades * @provided_merge_deployment: (nullable): Use this deployment for merge path - * @override_kernel_argv: (nullable) (array zero-terminated=1) (element-type utf8): Use these as kernel arguments; if %NULL, inherit options from provided_merge_deployment + * @override_kernel_argv: (nullable) (array zero-terminated=1) (element-type utf8): Use these as + * kernel arguments; if %NULL, inherit options from provided_merge_deployment * @out_new_deployment: (out): The new deployment path * @cancellable: Cancellable * @error: Error @@ -3411,15 +3305,10 @@ ostree_sysroot_deploy_tree_with_options (OstreeSysroot *self, * Since: 2018.5 */ gboolean -ostree_sysroot_deploy_tree (OstreeSysroot *self, - const char *osname, - const char *revision, - GKeyFile *origin, - OstreeDeployment *provided_merge_deployment, - char **override_kernel_argv, - OstreeDeployment **out_new_deployment, - GCancellable *cancellable, - GError **error) +ostree_sysroot_deploy_tree (OstreeSysroot *self, const char *osname, const char *revision, + GKeyFile *origin, OstreeDeployment *provided_merge_deployment, + char **override_kernel_argv, OstreeDeployment **out_new_deployment, + GCancellable *cancellable, GError **error) { OstreeSysrootDeployTreeOpts opts = { .override_kernel_argv = override_kernel_argv }; return ostree_sysroot_deploy_tree_with_options (self, osname, revision, origin, @@ -3433,13 +3322,11 @@ ostree_sysroot_deploy_tree (OstreeSysroot *self, static GVariant * serialize_deployment_to_variant (OstreeDeployment *deployment) { - g_auto(GVariantBuilder) builder = OT_VARIANT_BUILDER_INITIALIZER; - g_variant_builder_init (&builder, (GVariantType*)"a{sv}"); - g_autofree char *name = - g_strdup_printf ("%s.%d", ostree_deployment_get_csum (deployment), - ostree_deployment_get_deployserial (deployment)); - g_variant_builder_add (&builder, "{sv}", "name", - g_variant_new_string (name)); + g_auto (GVariantBuilder) builder = OT_VARIANT_BUILDER_INITIALIZER; + g_variant_builder_init (&builder, (GVariantType *)"a{sv}"); + g_autofree char *name = g_strdup_printf ("%s.%d", ostree_deployment_get_csum (deployment), + ostree_deployment_get_deployserial (deployment)); + g_variant_builder_add (&builder, "{sv}", "name", g_variant_new_string (name)); g_variant_builder_add (&builder, "{sv}", "osname", g_variant_new_string (ostree_deployment_get_osname (deployment))); g_variant_builder_add (&builder, "{sv}", "bootcsum", @@ -3449,10 +3336,7 @@ serialize_deployment_to_variant (OstreeDeployment *deployment) } static gboolean -require_str_key (GVariantDict *dict, - const char *name, - const char **ret, - GError **error) +require_str_key (GVariantDict *dict, const char *name, const char **ret, GError **error) { if (!g_variant_dict_lookup (dict, name, "&s", ret)) return glnx_throw (error, "Missing key: %s", name); @@ -3464,10 +3348,9 @@ require_str_key (GVariantDict *dict, * higher level code. */ OstreeDeployment * -_ostree_sysroot_deserialize_deployment_from_variant (GVariant *v, - GError **error) +_ostree_sysroot_deserialize_deployment_from_variant (GVariant *v, GError **error) { - g_autoptr(GVariantDict) dict = g_variant_dict_new (v); + g_autoptr (GVariantDict) dict = g_variant_dict_new (v); const char *name = NULL; if (!require_str_key (dict, "name", &name, error)) return FALSE; @@ -3481,11 +3364,9 @@ _ostree_sysroot_deserialize_deployment_from_variant (GVariant *v, gint deployserial; if (!_ostree_sysroot_parse_deploy_path_name (name, &checksum, &deployserial, error)) return NULL; - return ostree_deployment_new (-1, osname, checksum, deployserial, - bootcsum, -1); + return ostree_deployment_new (-1, osname, checksum, deployserial, bootcsum, -1); } - /** * ostree_sysroot_stage_overlay_initrd: * @self: Sysroot @@ -3501,17 +3382,14 @@ _ostree_sysroot_deserialize_deployment_from_variant (GVariant *v, * Since: 2020.7 */ gboolean -ostree_sysroot_stage_overlay_initrd (OstreeSysroot *self, - int fd, - char **out_checksum, - GCancellable *cancellable, - GError **error) +ostree_sysroot_stage_overlay_initrd (OstreeSysroot *self, int fd, char **out_checksum, + GCancellable *cancellable, GError **error) { g_assert (fd != -1); g_assert (out_checksum != NULL); - if (!glnx_shutil_mkdir_p_at (AT_FDCWD, _OSTREE_SYSROOT_RUNSTATE_STAGED_INITRDS_DIR, - 0755, cancellable, error)) + if (!glnx_shutil_mkdir_p_at (AT_FDCWD, _OSTREE_SYSROOT_RUNSTATE_STAGED_INITRDS_DIR, 0755, + cancellable, error)) return FALSE; glnx_autofd int staged_initrds_dfd = -1; @@ -3519,30 +3397,31 @@ ostree_sysroot_stage_overlay_initrd (OstreeSysroot *self, &staged_initrds_dfd, error)) return FALSE; - g_auto(GLnxTmpfile) overlay_initrd = { 0, }; + g_auto (GLnxTmpfile) overlay_initrd = { + 0, + }; if (!glnx_open_tmpfile_linkable_at (staged_initrds_dfd, ".", O_WRONLY | O_CLOEXEC, &overlay_initrd, error)) return FALSE; - char checksum[_OSTREE_SHA256_STRING_LEN+1]; + char checksum[_OSTREE_SHA256_STRING_LEN + 1]; { - g_autoptr(GOutputStream) output = g_unix_output_stream_new (overlay_initrd.fd, FALSE); - g_autoptr(GInputStream) input = g_unix_input_stream_new (fd, FALSE); + g_autoptr (GOutputStream) output = g_unix_output_stream_new (overlay_initrd.fd, FALSE); + g_autoptr (GInputStream) input = g_unix_input_stream_new (fd, FALSE); g_autofree guchar *digest = NULL; if (!ot_gio_splice_get_checksum (output, input, &digest, cancellable, error)) return FALSE; - ot_bin2hex (checksum, (guint8*)digest, _OSTREE_SHA256_DIGEST_LEN); + ot_bin2hex (checksum, (guint8 *)digest, _OSTREE_SHA256_DIGEST_LEN); } - if (!glnx_link_tmpfile_at (&overlay_initrd, GLNX_LINK_TMPFILE_REPLACE, - staged_initrds_dfd, checksum, error)) + if (!glnx_link_tmpfile_at (&overlay_initrd, GLNX_LINK_TMPFILE_REPLACE, staged_initrds_dfd, + checksum, error)) return FALSE; *out_checksum = g_strdup (checksum); return TRUE; } - /** * ostree_sysroot_stage_tree: * @self: Sysroot @@ -3550,7 +3429,8 @@ ostree_sysroot_stage_overlay_initrd (OstreeSysroot *self, * @revision: Checksum to add * @origin: (allow-none): Origin to use for upgrades * @merge_deployment: (allow-none): Use this deployment for merge path - * @override_kernel_argv: (allow-none) (array zero-terminated=1) (element-type utf8): Use these as kernel arguments; if %NULL, inherit options from provided_merge_deployment + * @override_kernel_argv: (allow-none) (array zero-terminated=1) (element-type utf8): Use these as + * kernel arguments; if %NULL, inherit options from provided_merge_deployment * @out_new_deployment: (out): The new deployment path * @cancellable: Cancellable * @error: Error @@ -3560,23 +3440,16 @@ ostree_sysroot_stage_overlay_initrd (OstreeSysroot *self, * Since: 2018.5 */ gboolean -ostree_sysroot_stage_tree (OstreeSysroot *self, - const char *osname, - const char *revision, - GKeyFile *origin, - OstreeDeployment *merge_deployment, - char **override_kernel_argv, - OstreeDeployment **out_new_deployment, - GCancellable *cancellable, - GError **error) +ostree_sysroot_stage_tree (OstreeSysroot *self, const char *osname, const char *revision, + GKeyFile *origin, OstreeDeployment *merge_deployment, + char **override_kernel_argv, OstreeDeployment **out_new_deployment, + GCancellable *cancellable, GError **error) { OstreeSysrootDeployTreeOpts opts = { .override_kernel_argv = override_kernel_argv }; - return ostree_sysroot_stage_tree_with_options (self, osname, revision, origin, - merge_deployment, &opts, - out_new_deployment, cancellable, error); + return ostree_sysroot_stage_tree_with_options (self, osname, revision, origin, merge_deployment, + &opts, out_new_deployment, cancellable, error); } - /** * ostree_sysroot_stage_tree_with_options: * @self: Sysroot @@ -3595,15 +3468,12 @@ ostree_sysroot_stage_tree (OstreeSysroot *self, * Since: 2020.7 */ gboolean -ostree_sysroot_stage_tree_with_options (OstreeSysroot *self, - const char *osname, - const char *revision, - GKeyFile *origin, - OstreeDeployment *merge_deployment, +ostree_sysroot_stage_tree_with_options (OstreeSysroot *self, const char *osname, + const char *revision, GKeyFile *origin, + OstreeDeployment *merge_deployment, OstreeSysrootDeployTreeOpts *opts, OstreeDeployment **out_new_deployment, - GCancellable *cancellable, - GError **error) + GCancellable *cancellable, GError **error) { if (!_ostree_sysroot_ensure_writable (self, error)) return FALSE; @@ -3612,7 +3482,7 @@ ostree_sysroot_stage_tree_with_options (OstreeSysroot *self, if (booted_deployment == NULL) return glnx_prefix_error (error, "Cannot stage deployment"); - g_autoptr(OstreeDeployment) deployment = NULL; + g_autoptr (OstreeDeployment) deployment = NULL; if (!sysroot_initialize_deployment (self, osname, revision, origin, opts, &deployment, cancellable, error)) return FALSE; @@ -3621,18 +3491,18 @@ ostree_sysroot_stage_tree_with_options (OstreeSysroot *self, * now (i.e. using /usr/etc policy, not /etc); in practice we don't really * expect people to customize the label for it. */ - { g_autofree char *deployment_path = ostree_sysroot_get_deployment_dirpath (self, deployment); + { + g_autofree char *deployment_path = ostree_sysroot_get_deployment_dirpath (self, deployment); glnx_autofd int deployment_dfd = -1; - if (!glnx_opendirat (self->sysroot_fd, deployment_path, FALSE, - &deployment_dfd, error)) + if (!glnx_opendirat (self->sysroot_fd, deployment_path, FALSE, &deployment_dfd, error)) return FALSE; - g_autoptr(OstreeSePolicy) sepolicy = ostree_sepolicy_new_at (deployment_dfd, cancellable, error); + g_autoptr (OstreeSePolicy) sepolicy + = ostree_sepolicy_new_at (deployment_dfd, cancellable, error); if (!sepolicy) return FALSE; if (!write_origin_file_internal (self, sepolicy, deployment, ostree_deployment_get_origin (deployment), - GLNX_FILE_REPLACE_NODATASYNC, - cancellable, error)) + GLNX_FILE_REPLACE_NODATASYNC, cancellable, error)) return FALSE; } @@ -3641,30 +3511,29 @@ ostree_sysroot_stage_tree_with_options (OstreeSysroot *self, */ /* "target" is the staged deployment */ - g_autoptr(GVariantBuilder) builder = g_variant_builder_new ((GVariantType*)"a{sv}"); - g_variant_builder_add (builder, "{sv}", "target", - serialize_deployment_to_variant (deployment)); + g_autoptr (GVariantBuilder) builder = g_variant_builder_new ((GVariantType *)"a{sv}"); + g_variant_builder_add (builder, "{sv}", "target", serialize_deployment_to_variant (deployment)); if (merge_deployment) g_variant_builder_add (builder, "{sv}", "merge-deployment", serialize_deployment_to_variant (merge_deployment)); if (opts && opts->override_kernel_argv) - g_variant_builder_add (builder, "{sv}", "kargs", - g_variant_new_strv ((const char *const*)opts->override_kernel_argv, -1)); + g_variant_builder_add ( + builder, "{sv}", "kargs", + g_variant_new_strv ((const char *const *)opts->override_kernel_argv, -1)); if (opts && opts->overlay_initrds) g_variant_builder_add (builder, "{sv}", "overlay-initrds", - g_variant_new_strv ((const char *const*)opts->overlay_initrds, -1)); + g_variant_new_strv ((const char *const *)opts->overlay_initrds, -1)); const char *parent = dirname (strdupa (_OSTREE_SYSROOT_RUNSTATE_STAGED)); if (!glnx_shutil_mkdir_p_at (AT_FDCWD, parent, 0755, cancellable, error)) return FALSE; - g_autoptr(GVariant) state = g_variant_ref_sink (g_variant_builder_end (builder)); + g_autoptr (GVariant) state = g_variant_ref_sink (g_variant_builder_end (builder)); if (!glnx_file_replace_contents_at (AT_FDCWD, _OSTREE_SYSROOT_RUNSTATE_STAGED, g_variant_get_data (state), g_variant_get_size (state), - GLNX_FILE_REPLACE_NODATASYNC, - cancellable, error)) + GLNX_FILE_REPLACE_NODATASYNC, cancellable, error)) return FALSE; /* If we have a previous one, clean it up */ @@ -3693,9 +3562,8 @@ ostree_sysroot_stage_tree_with_options (OstreeSysroot *self, /* Invoked at shutdown time by ostree-finalize-staged.service */ static gboolean -_ostree_sysroot_finalize_staged_inner (OstreeSysroot *self, - GCancellable *cancellable, - GError **error) +_ostree_sysroot_finalize_staged_inner (OstreeSysroot *self, GCancellable *cancellable, + GError **error) { /* It's totally fine if there's no staged deployment; perhaps down the line * though we could teach the ostree cmdline to tell systemd to activate the @@ -3708,38 +3576,32 @@ _ostree_sysroot_finalize_staged_inner (OstreeSysroot *self, } /* Check if finalization is locked. */ - if (!glnx_fstatat_allow_noent (AT_FDCWD, _OSTREE_SYSROOT_RUNSTATE_STAGED_LOCKED, - NULL, 0, error)) + if (!glnx_fstatat_allow_noent (AT_FDCWD, _OSTREE_SYSROOT_RUNSTATE_STAGED_LOCKED, NULL, 0, error)) return FALSE; if (errno == 0) { - ot_journal_print (LOG_INFO, "Not finalizing; found " - _OSTREE_SYSROOT_RUNSTATE_STAGED_LOCKED); + ot_journal_print (LOG_INFO, "Not finalizing; found " _OSTREE_SYSROOT_RUNSTATE_STAGED_LOCKED); return TRUE; } /* Notice we send this *after* the trivial `return TRUE` above; this msg implies we've * committed to finalizing the deployment. */ - ot_journal_send ("MESSAGE_ID=" SD_ID128_FORMAT_STR, - SD_ID128_FORMAT_VAL(OSTREE_DEPLOYMENT_FINALIZING_ID), - "MESSAGE=Finalizing staged deployment", - "OSTREE_OSNAME=%s", - ostree_deployment_get_osname (self->staged_deployment), - "OSTREE_CHECKSUM=%s", - ostree_deployment_get_csum (self->staged_deployment), - "OSTREE_DEPLOYSERIAL=%u", - ostree_deployment_get_deployserial (self->staged_deployment), - NULL); + ot_journal_send ("MESSAGE_ID=" SD_ID128_FORMAT_STR, + SD_ID128_FORMAT_VAL (OSTREE_DEPLOYMENT_FINALIZING_ID), + "MESSAGE=Finalizing staged deployment", "OSTREE_OSNAME=%s", + ostree_deployment_get_osname (self->staged_deployment), "OSTREE_CHECKSUM=%s", + ostree_deployment_get_csum (self->staged_deployment), "OSTREE_DEPLOYSERIAL=%u", + ostree_deployment_get_deployserial (self->staged_deployment), NULL); g_assert (self->staged_deployment_data); - g_autoptr(OstreeDeployment) merge_deployment = NULL; - g_autoptr(GVariant) merge_deployment_v = NULL; + g_autoptr (OstreeDeployment) merge_deployment = NULL; + g_autoptr (GVariant) merge_deployment_v = NULL; if (g_variant_lookup (self->staged_deployment_data, "merge-deployment", "@a{sv}", &merge_deployment_v)) { - g_autoptr(OstreeDeployment) merge_deployment_stub = - _ostree_sysroot_deserialize_deployment_from_variant (merge_deployment_v, error); + g_autoptr (OstreeDeployment) merge_deployment_stub + = _ostree_sysroot_deserialize_deployment_from_variant (merge_deployment_v, error); if (!merge_deployment_stub) return FALSE; for (guint i = 0; i < self->deployments->len; i++) @@ -3764,14 +3626,14 @@ _ostree_sysroot_finalize_staged_inner (OstreeSysroot *self, if (!glnx_unlinkat (AT_FDCWD, _OSTREE_SYSROOT_RUNSTATE_STAGED, 0, error)) return FALSE; - if (!sysroot_finalize_deployment (self, self->staged_deployment, merge_deployment, - cancellable, error)) + if (!sysroot_finalize_deployment (self, self->staged_deployment, merge_deployment, cancellable, + error)) return FALSE; /* Now, take ownership of the staged state, as normally the API below strips * it out. */ - g_autoptr(OstreeDeployment) staged = g_steal_pointer (&self->staged_deployment); + g_autoptr (OstreeDeployment) staged = g_steal_pointer (&self->staged_deployment); staged->staged = FALSE; g_ptr_array_remove_index (self->deployments, 0); @@ -3781,11 +3643,10 @@ _ostree_sysroot_finalize_staged_inner (OstreeSysroot *self, * shutdown, and also because e.g. rpm-ostree wants to own the cleanup * process. */ - OstreeSysrootSimpleWriteDeploymentFlags flags = - OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NO_CLEAN; - if (!ostree_sysroot_simple_write_deployment (self, ostree_deployment_get_osname (staged), - staged, merge_deployment, flags, - cancellable, error)) + OstreeSysrootSimpleWriteDeploymentFlags flags + = OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NO_CLEAN; + if (!ostree_sysroot_simple_write_deployment (self, ostree_deployment_get_osname (staged), staged, + merge_deployment, flags, cancellable, error)) return FALSE; /* Do the basic cleanup that may impact /boot, but not the repo pruning */ @@ -3801,23 +3662,23 @@ _ostree_sysroot_finalize_staged_inner (OstreeSysroot *self, /* Invoked at shutdown time by ostree-finalize-staged.service */ gboolean -_ostree_sysroot_finalize_staged (OstreeSysroot *self, - GCancellable *cancellable, - GError **error) +_ostree_sysroot_finalize_staged (OstreeSysroot *self, GCancellable *cancellable, GError **error) { - g_autoptr(GError) finalization_error = NULL; + g_autoptr (GError) finalization_error = NULL; if (!_ostree_sysroot_ensure_boot_fd (self, error)) return FALSE; if (!_ostree_sysroot_finalize_staged_inner (self, cancellable, &finalization_error)) { - g_autoptr(GError) writing_error = NULL; + g_autoptr (GError) writing_error = NULL; g_assert_cmpint (self->boot_fd, !=, -1); if (!glnx_file_replace_contents_at (self->boot_fd, _OSTREE_FINALIZE_STAGED_FAILURE_PATH, - (guint8*)finalization_error->message, -1, - 0, cancellable, &writing_error)) + (guint8 *)finalization_error->message, -1, 0, cancellable, + &writing_error)) { - // We somehow failed to write the failure message...that's not great. Maybe ENOSPC on /boot. - g_printerr ("Failed to write %s: %s\n", _OSTREE_FINALIZE_STAGED_FAILURE_PATH, writing_error->message); + // We somehow failed to write the failure message...that's not great. Maybe ENOSPC on + // /boot. + g_printerr ("Failed to write %s: %s\n", _OSTREE_FINALIZE_STAGED_FAILURE_PATH, + writing_error->message); } g_propagate_error (error, g_steal_pointer (&finalization_error)); return FALSE; @@ -3826,7 +3687,8 @@ _ostree_sysroot_finalize_staged (OstreeSysroot *self, { /* we may have failed in a previous invocation on this boot, but we were * rerun again (likely manually) and passed this time; nuke any stamp */ - if (!glnx_shutil_rm_rf_at (self->boot_fd, _OSTREE_FINALIZE_STAGED_FAILURE_PATH, cancellable, error)) + if (!glnx_shutil_rm_rf_at (self->boot_fd, _OSTREE_FINALIZE_STAGED_FAILURE_PATH, cancellable, + error)) return FALSE; } return TRUE; @@ -3834,16 +3696,15 @@ _ostree_sysroot_finalize_staged (OstreeSysroot *self, /* Invoked at bootup time by ostree-boot-complete.service */ gboolean -_ostree_sysroot_boot_complete (OstreeSysroot *self, - GCancellable *cancellable, - GError **error) +_ostree_sysroot_boot_complete (OstreeSysroot *self, GCancellable *cancellable, GError **error) { if (!_ostree_sysroot_ensure_boot_fd (self, error)) return FALSE; glnx_autofd int failure_fd = -1; g_assert_cmpint (self->boot_fd, !=, -1); - if (!ot_openat_ignore_enoent (self->boot_fd, _OSTREE_FINALIZE_STAGED_FAILURE_PATH, &failure_fd, error)) + if (!ot_openat_ignore_enoent (self->boot_fd, _OSTREE_FINALIZE_STAGED_FAILURE_PATH, &failure_fd, + error)) return FALSE; // If we didn't find a failure log, then there's nothing to do right now. // (Actually this unit shouldn't even be invoked, but we may do more in the future) @@ -3853,8 +3714,9 @@ _ostree_sysroot_boot_complete (OstreeSysroot *self, if (failure_data == NULL) return glnx_prefix_error (error, "Reading from %s", _OSTREE_FINALIZE_STAGED_FAILURE_PATH); // Remove the file; we don't want to continually error out. - (void) unlinkat (self->boot_fd, _OSTREE_FINALIZE_STAGED_FAILURE_PATH, 0); - return glnx_throw (error, "ostree-finalize-staged.service failed on previous boot: %s", failure_data); + (void)unlinkat (self->boot_fd, _OSTREE_FINALIZE_STAGED_FAILURE_PATH, 0); + return glnx_throw (error, "ostree-finalize-staged.service failed on previous boot: %s", + failure_data); } /** @@ -3869,11 +3731,8 @@ _ostree_sysroot_boot_complete (OstreeSysroot *self, * values in @new_kargs. */ gboolean -ostree_sysroot_deployment_set_kargs (OstreeSysroot *self, - OstreeDeployment *deployment, - char **new_kargs, - GCancellable *cancellable, - GError **error) +ostree_sysroot_deployment_set_kargs (OstreeSysroot *self, OstreeDeployment *deployment, + char **new_kargs, GCancellable *cancellable, GError **error) { if (!_ostree_sysroot_ensure_writable (self, error)) return FALSE; @@ -3881,15 +3740,15 @@ ostree_sysroot_deployment_set_kargs (OstreeSysroot *self, /* For now; instead of this do a redeployment */ g_assert (!ostree_deployment_is_staged (deployment)); - g_autoptr(OstreeDeployment) new_deployment = ostree_deployment_clone (deployment); + g_autoptr (OstreeDeployment) new_deployment = ostree_deployment_clone (deployment); OstreeBootconfigParser *new_bootconfig = ostree_deployment_get_bootconfig (new_deployment); - g_autoptr(OstreeKernelArgs) kargs = ostree_kernel_args_new (); + g_autoptr (OstreeKernelArgs) kargs = ostree_kernel_args_new (); ostree_kernel_args_append_argv (kargs, new_kargs); g_autofree char *new_options = ostree_kernel_args_to_string (kargs); ostree_bootconfig_parser_set (new_bootconfig, "options", new_options); - g_autoptr(GPtrArray) new_deployments = g_ptr_array_new_with_free_func (g_object_unref); + g_autoptr (GPtrArray) new_deployments = g_ptr_array_new_with_free_func (g_object_unref); for (guint i = 0; i < self->deployments->len; i++) { OstreeDeployment *cur = self->deployments->pdata[i]; @@ -3899,8 +3758,7 @@ ostree_sysroot_deployment_set_kargs (OstreeSysroot *self, g_ptr_array_add (new_deployments, g_object_ref (cur)); } - if (!ostree_sysroot_write_deployments (self, new_deployments, - cancellable, error)) + if (!ostree_sysroot_write_deployments (self, new_deployments, cancellable, error)) return FALSE; return TRUE; @@ -3917,11 +3775,9 @@ ostree_sysroot_deployment_set_kargs (OstreeSysroot *self, * Replace the kernel arguments of @deployment with the values in @kargs_str. */ gboolean -ostree_sysroot_deployment_set_kargs_in_place (OstreeSysroot *self, - OstreeDeployment *deployment, - char *kargs_str, - GCancellable *cancellable, - GError **error) +ostree_sysroot_deployment_set_kargs_in_place (OstreeSysroot *self, OstreeDeployment *deployment, + char *kargs_str, GCancellable *cancellable, + GError **error) { if (!ostree_sysroot_initialize (self, error)) return FALSE; @@ -3938,25 +3794,23 @@ ostree_sysroot_deployment_set_kargs_in_place (OstreeSysroot *self, if (!glnx_openat_rdonly (AT_FDCWD, _OSTREE_SYSROOT_RUNSTATE_STAGED, TRUE, &fd, error)) return FALSE; - g_autoptr(GBytes) contents = ot_fd_readall_or_mmap (fd, 0, error); + g_autoptr (GBytes) contents = ot_fd_readall_or_mmap (fd, 0, error); if (!contents) return FALSE; - g_autoptr(GVariant) staged_deployment_data = - g_variant_new_from_bytes ((GVariantType*)"a{sv}", contents, TRUE); - g_autoptr(GVariantDict) staged_deployment_dict = - g_variant_dict_new (staged_deployment_data); + g_autoptr (GVariant) staged_deployment_data + = g_variant_new_from_bytes ((GVariantType *)"a{sv}", contents, TRUE); + g_autoptr (GVariantDict) staged_deployment_dict = g_variant_dict_new (staged_deployment_data); - g_autoptr(OstreeKernelArgs) kargs = ostree_kernel_args_from_string (kargs_str); - g_auto(GStrv) kargs_strv = ostree_kernel_args_to_strv (kargs); + g_autoptr (OstreeKernelArgs) kargs = ostree_kernel_args_from_string (kargs_str); + g_auto (GStrv) kargs_strv = ostree_kernel_args_to_strv (kargs); g_variant_dict_insert (staged_deployment_dict, "kargs", "^a&s", kargs_strv); - g_autoptr(GVariant) new_staged_deployment_data = g_variant_dict_end (staged_deployment_dict); + g_autoptr (GVariant) new_staged_deployment_data = g_variant_dict_end (staged_deployment_dict); if (!glnx_file_replace_contents_at (fd, _OSTREE_SYSROOT_RUNSTATE_STAGED, g_variant_get_data (new_staged_deployment_data), g_variant_get_size (new_staged_deployment_data), - GLNX_FILE_REPLACE_NODATASYNC, - cancellable, error)) + GLNX_FILE_REPLACE_NODATASYNC, cancellable, error)) return FALSE; } else @@ -3964,18 +3818,16 @@ ostree_sysroot_deployment_set_kargs_in_place (OstreeSysroot *self, OstreeBootconfigParser *new_bootconfig = ostree_deployment_get_bootconfig (deployment); ostree_bootconfig_parser_set (new_bootconfig, "options", kargs_str); - g_autofree char *bootconf_name = - g_strdup_printf ("ostree-%d-%s.conf", - self->deployments->len - ostree_deployment_get_index (deployment), - ostree_deployment_get_osname (deployment)); + g_autofree char *bootconf_name = g_strdup_printf ( + "ostree-%d-%s.conf", self->deployments->len - ostree_deployment_get_index (deployment), + ostree_deployment_get_osname (deployment)); g_autofree char *bootconfdir = g_strdup_printf ("loader.%d/entries", self->bootversion); glnx_autofd int bootconf_dfd = -1; if (!glnx_opendirat (self->boot_fd, bootconfdir, TRUE, &bootconf_dfd, error)) return FALSE; - if (!ostree_bootconfig_parser_write_at (new_bootconfig, - bootconf_dfd, bootconf_name, + if (!ostree_bootconfig_parser_write_at (new_bootconfig, bootconf_dfd, bootconf_name, cancellable, error)) return FALSE; } @@ -3996,11 +3848,9 @@ ostree_sysroot_deployment_set_kargs_in_place (OstreeSysroot *self, * layering additional non-OSTree content. */ gboolean -ostree_sysroot_deployment_set_mutable (OstreeSysroot *self, - OstreeDeployment *deployment, - gboolean is_mutable, - GCancellable *cancellable, - GError **error) +ostree_sysroot_deployment_set_mutable (OstreeSysroot *self, OstreeDeployment *deployment, + gboolean is_mutable, GCancellable *cancellable, + GError **error) { if (!_ostree_sysroot_ensure_writable (self, error)) return FALSE; diff --git a/src/libostree/ostree-sysroot-private.h b/src/libostree/ostree-sysroot-private.h index 9bd02c78..6c1c5d3e 100644 --- a/src/libostree/ostree-sysroot-private.h +++ b/src/libostree/ostree-sysroot-private.h @@ -20,12 +20,13 @@ #pragma once #include "libglnx.h" -#include "ostree.h" #include "ostree-bootloader.h" +#include "ostree.h" G_BEGIN_DECLS -typedef enum { +typedef enum +{ /* Don't flag deployments as immutable. */ OSTREE_SYSROOT_DEBUG_MUTABLE_DEPLOYMENTS = 1 << 0, @@ -38,24 +39,27 @@ typedef enum { OSTREE_SYSROOT_DEBUG_TEST_NO_DTB = 1 << 3, /* https://github.com/ostreedev/ostree/issues/2154 */ } OstreeSysrootDebugFlags; -typedef enum { +typedef enum +{ /* Skip invoking `sync()` */ OSTREE_SYSROOT_GLOBAL_OPT_SKIP_SYNC = 1 << 0, /* See https://github.com/ostreedev/ostree/pull/2847 */ OSTREE_SYSROOT_GLOBAL_OPT_EARLY_PRUNE = 1 << 1, } OstreeSysrootGlobalOptFlags; -typedef enum { - OSTREE_SYSROOT_LOAD_STATE_NONE, /* ostree_sysroot_new() was called */ - OSTREE_SYSROOT_LOAD_STATE_INIT, /* We've loaded basic sysroot state and have an fd */ - OSTREE_SYSROOT_LOAD_STATE_LOADED, /* We've loaded all of the deployments */ +typedef enum +{ + OSTREE_SYSROOT_LOAD_STATE_NONE, /* ostree_sysroot_new() was called */ + OSTREE_SYSROOT_LOAD_STATE_INIT, /* We've loaded basic sysroot state and have an fd */ + OSTREE_SYSROOT_LOAD_STATE_LOADED, /* We've loaded all of the deployments */ } OstreeSysrootLoadState; /** * OstreeSysroot: * Internal struct */ -struct OstreeSysroot { +struct OstreeSysroot +{ GObject parent; GFile *path; @@ -65,7 +69,7 @@ struct OstreeSysroot { OstreeSysrootLoadState loadstate; gboolean mount_namespace_in_use; /* TRUE if caller has told us they used CLONE_NEWNS */ - gboolean root_is_ostree_booted; /* TRUE if sysroot is / and we are booted via ostree */ + gboolean root_is_ostree_booted; /* TRUE if sysroot is / and we are booted via ostree */ /* The device/inode for /, used to detect booted deployment */ dev_t root_device; ino_t root_inode; @@ -101,106 +105,64 @@ struct OstreeSysroot { // Relative to /boot, consumed by ostree-boot-complete.service #define _OSTREE_FINALIZE_STAGED_FAILURE_PATH "ostree/finalize-failure.stamp" -gboolean -_ostree_sysroot_ensure_writable (OstreeSysroot *self, - GError **error); - -void -_ostree_sysroot_emit_journal_msg (OstreeSysroot *self, - const char *msg); - -gboolean -_ostree_sysroot_read_boot_loader_configs (OstreeSysroot *self, - int bootversion, - GPtrArray **out_loader_configs, - GCancellable *cancellable, - GError **error); - -gboolean -_ostree_sysroot_read_current_subbootversion (OstreeSysroot *self, - int bootversion, - int *out_subbootversion, - GCancellable *cancellable, - GError **error); - -gboolean -_ostree_sysroot_parse_deploy_path_name (const char *name, - char **out_csum, - int *out_serial, - GError **error); - -gboolean -_ostree_sysroot_list_deployment_dirs_for_os (int deploydir_dfd, - const char *osname, - GPtrArray *inout_deployments, - GCancellable *cancellable, - GError **error); - -void -_ostree_deployment_set_bootconfig_from_kargs (OstreeDeployment *deployment, - char **override_kernel_argv); - -gboolean -_ostree_sysroot_reload_staged (OstreeSysroot *self, GError **error); - -gboolean -_ostree_sysroot_finalize_staged (OstreeSysroot *self, - GCancellable *cancellable, - GError **error); -gboolean -_ostree_sysroot_boot_complete (OstreeSysroot *self, - GCancellable *cancellable, - GError **error); - -OstreeDeployment * -_ostree_sysroot_deserialize_deployment_from_variant (GVariant *v, - GError **error); - -char * -_ostree_sysroot_get_origin_relpath (GFile *path, - guint32 *out_device, - guint64 *out_inode, - GCancellable *cancellable, - GError **error); - -gboolean -_ostree_sysroot_rmrf_deployment (OstreeSysroot *sysroot, - OstreeDeployment *deployment, - GCancellable *cancellable, - GError **error); - -char * _ostree_sysroot_get_runstate_path (OstreeDeployment *deployment, const char *key); - -char *_ostree_sysroot_join_lines (GPtrArray *lines); - -gboolean -_ostree_sysroot_ensure_boot_fd (OstreeSysroot *self, GError **error); - -gboolean _ostree_sysroot_query_bootloader (OstreeSysroot *sysroot, +gboolean _ostree_sysroot_ensure_writable (OstreeSysroot *self, GError **error); + +void _ostree_sysroot_emit_journal_msg (OstreeSysroot *self, const char *msg); + +gboolean _ostree_sysroot_read_boot_loader_configs (OstreeSysroot *self, int bootversion, + GPtrArray **out_loader_configs, + GCancellable *cancellable, GError **error); + +gboolean _ostree_sysroot_read_current_subbootversion (OstreeSysroot *self, int bootversion, + int *out_subbootversion, + GCancellable *cancellable, GError **error); + +gboolean _ostree_sysroot_parse_deploy_path_name (const char *name, char **out_csum, int *out_serial, + GError **error); + +gboolean _ostree_sysroot_list_deployment_dirs_for_os (int deploydir_dfd, const char *osname, + GPtrArray *inout_deployments, + GCancellable *cancellable, GError **error); + +void _ostree_deployment_set_bootconfig_from_kargs (OstreeDeployment *deployment, + char **override_kernel_argv); + +gboolean _ostree_sysroot_reload_staged (OstreeSysroot *self, GError **error); + +gboolean _ostree_sysroot_finalize_staged (OstreeSysroot *self, GCancellable *cancellable, + GError **error); +gboolean _ostree_sysroot_boot_complete (OstreeSysroot *self, GCancellable *cancellable, + GError **error); + +OstreeDeployment *_ostree_sysroot_deserialize_deployment_from_variant (GVariant *v, GError **error); + +char *_ostree_sysroot_get_origin_relpath (GFile *path, guint32 *out_device, guint64 *out_inode, + GCancellable *cancellable, GError **error); + +gboolean _ostree_sysroot_rmrf_deployment (OstreeSysroot *sysroot, OstreeDeployment *deployment, + GCancellable *cancellable, GError **error); + +char *_ostree_sysroot_get_runstate_path (OstreeDeployment *deployment, const char *key); + +char *_ostree_sysroot_join_lines (GPtrArray *lines); + +gboolean _ostree_sysroot_ensure_boot_fd (OstreeSysroot *self, GError **error); + +gboolean _ostree_sysroot_query_bootloader (OstreeSysroot *sysroot, OstreeBootloader **out_bootloader, - GCancellable *cancellable, - GError **error); - -gboolean _ostree_sysroot_bump_mtime (OstreeSysroot *sysroot, - GError **error); - -gboolean _ostree_sysroot_cleanup_internal (OstreeSysroot *sysroot, - gboolean prune_repo, - GCancellable *cancellable, - GError **error); - -gboolean -_ostree_sysroot_cleanup_bootfs (OstreeSysroot *self, - GCancellable *cancellable, - GError **error); - -gboolean _ostree_sysroot_parse_bootdir_name (const char *name, - char **out_osname, - char **out_csum); - -gboolean _ostree_sysroot_list_all_boot_directories (OstreeSysroot *self, - char ***out_bootdirs, - GCancellable *cancellable, - GError **error); + GCancellable *cancellable, GError **error); + +gboolean _ostree_sysroot_bump_mtime (OstreeSysroot *sysroot, GError **error); + +gboolean _ostree_sysroot_cleanup_internal (OstreeSysroot *sysroot, gboolean prune_repo, + GCancellable *cancellable, GError **error); + +gboolean _ostree_sysroot_cleanup_bootfs (OstreeSysroot *self, GCancellable *cancellable, + GError **error); + +gboolean _ostree_sysroot_parse_bootdir_name (const char *name, char **out_osname, char **out_csum); + +gboolean _ostree_sysroot_list_all_boot_directories (OstreeSysroot *self, char ***out_bootdirs, + GCancellable *cancellable, GError **error); G_END_DECLS diff --git a/src/libostree/ostree-sysroot-upgrader.c b/src/libostree/ostree-sysroot-upgrader.c index bbfed034..94654c86 100644 --- a/src/libostree/ostree-sysroot-upgrader.c +++ b/src/libostree/ostree-sysroot-upgrader.c @@ -21,9 +21,9 @@ #include "otutil.h" -#include "ostree.h" -#include "ostree-sysroot-upgrader.h" #include "ostree-core-private.h" +#include "ostree-sysroot-upgrader.h" +#include "ostree.h" /** * SECTION:ostree-sysroot-upgrader @@ -33,11 +33,13 @@ * The #OstreeSysrootUpgrader class allows performing simple upgrade * operations. */ -typedef struct { +typedef struct +{ GObjectClass parent_class; } OstreeSysrootUpgraderClass; -struct OstreeSysrootUpgrader { +struct OstreeSysrootUpgrader +{ GObject parent; OstreeSysroot *sysroot; @@ -53,7 +55,8 @@ struct OstreeSysrootUpgrader { char *new_revision; }; -enum { +enum +{ PROP_0, PROP_SYSROOT, @@ -64,12 +67,11 @@ enum { static void ostree_sysroot_upgrader_initable_iface_init (GInitableIface *iface); G_DEFINE_TYPE_WITH_CODE (OstreeSysrootUpgrader, ostree_sysroot_upgrader, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, ostree_sysroot_upgrader_initable_iface_init)) + G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, + ostree_sysroot_upgrader_initable_iface_init)) static gboolean -parse_refspec (OstreeSysrootUpgrader *self, - GCancellable *cancellable, - GError **error) +parse_refspec (OstreeSysrootUpgrader *self, GCancellable *cancellable, GError **error) { g_autofree char *origin_refspec = NULL; g_autofree char *unconfigured_state = NULL; @@ -80,21 +82,20 @@ parse_refspec (OstreeSysrootUpgrader *self, /* If explicit action by the OS creator is requried to upgrade, print their text as an error. * NOTE: If changing this, see the matching implementation in ostree-repo-pull.c. */ - unconfigured_state = g_key_file_get_string (self->origin, "origin", "unconfigured-state", NULL); + unconfigured_state + = g_key_file_get_string (self->origin, "origin", "unconfigured-state", NULL); if (unconfigured_state) return glnx_throw (error, "origin unconfigured-state: %s", unconfigured_state); } origin_refspec = g_key_file_get_string (self->origin, "origin", "refspec", NULL); if (!origin_refspec) - return glnx_throw (error, "No origin/refspec in current deployment origin; cannot upgrade via ostree"); + return glnx_throw (error, + "No origin/refspec in current deployment origin; cannot upgrade via ostree"); g_clear_pointer (&self->origin_remote, g_free); g_clear_pointer (&self->origin_ref, g_free); - if (!ostree_parse_refspec (origin_refspec, - &self->origin_remote, - &self->origin_ref, - error)) + if (!ostree_parse_refspec (origin_refspec, &self->origin_remote, &self->origin_ref, error)) return FALSE; csum = g_key_file_get_string (self->origin, "origin", "override-commit", NULL); @@ -107,13 +108,11 @@ parse_refspec (OstreeSysrootUpgrader *self, } static gboolean -ostree_sysroot_upgrader_initable_init (GInitable *initable, - GCancellable *cancellable, - GError **error) +ostree_sysroot_upgrader_initable_init (GInitable *initable, GCancellable *cancellable, + GError **error) { - OstreeSysrootUpgrader *self = (OstreeSysrootUpgrader*)initable; - OstreeDeployment *booted_deployment = - ostree_sysroot_get_booted_deployment (self->sysroot); + OstreeSysrootUpgrader *self = (OstreeSysrootUpgrader *)initable; + OstreeDeployment *booted_deployment = ostree_sysroot_get_booted_deployment (self->sysroot); if (booted_deployment == NULL && self->osname == NULL) return glnx_throw (error, "Not currently booted into an OSTree system and no OS specified"); @@ -169,10 +168,8 @@ ostree_sysroot_upgrader_finalize (GObject *object) } static void -ostree_sysroot_upgrader_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) +ostree_sysroot_upgrader_set_property (GObject *object, guint prop_id, const GValue *value, + GParamSpec *pspec) { OstreeSysrootUpgrader *self = OSTREE_SYSROOT_UPGRADER (object); @@ -194,10 +191,8 @@ ostree_sysroot_upgrader_set_property (GObject *object, } static void -ostree_sysroot_upgrader_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) +ostree_sysroot_upgrader_get_property (GObject *object, guint prop_id, GValue *value, + GParamSpec *pspec) { OstreeSysrootUpgrader *self = OSTREE_SYSROOT_UPGRADER (object); @@ -238,22 +233,18 @@ ostree_sysroot_upgrader_class_init (OstreeSysrootUpgraderClass *klass) object_class->set_property = ostree_sysroot_upgrader_set_property; object_class->finalize = ostree_sysroot_upgrader_finalize; - g_object_class_install_property (object_class, - PROP_SYSROOT, - g_param_spec_object ("sysroot", "", "", - OSTREE_TYPE_SYSROOT, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property ( + object_class, PROP_SYSROOT, + g_param_spec_object ("sysroot", "", "", OSTREE_TYPE_SYSROOT, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - g_object_class_install_property (object_class, - PROP_OSNAME, - g_param_spec_string ("osname", "", "", NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property ( + object_class, PROP_OSNAME, + g_param_spec_string ("osname", "", "", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - g_object_class_install_property (object_class, - PROP_FLAGS, + g_object_class_install_property (object_class, PROP_FLAGS, g_param_spec_flags ("flags", "", "", - ostree_sysroot_upgrader_flags_get_type (), - 0, + ostree_sysroot_upgrader_flags_get_type (), 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); } @@ -270,13 +261,11 @@ ostree_sysroot_upgrader_init (OstreeSysrootUpgrader *self) * * Returns: (transfer full): An upgrader */ -OstreeSysrootUpgrader* -ostree_sysroot_upgrader_new (OstreeSysroot *sysroot, - GCancellable *cancellable, - GError **error) +OstreeSysrootUpgrader * +ostree_sysroot_upgrader_new (OstreeSysroot *sysroot, GCancellable *cancellable, GError **error) { - return g_initable_new (OSTREE_TYPE_SYSROOT_UPGRADER, cancellable, error, - "sysroot", sysroot, NULL); + return g_initable_new (OSTREE_TYPE_SYSROOT_UPGRADER, cancellable, error, "sysroot", sysroot, + NULL); } /** @@ -288,14 +277,12 @@ ostree_sysroot_upgrader_new (OstreeSysroot *sysroot, * * Returns: (transfer full): An upgrader */ -OstreeSysrootUpgrader* -ostree_sysroot_upgrader_new_for_os (OstreeSysroot *sysroot, - const char *osname, - GCancellable *cancellable, - GError **error) +OstreeSysrootUpgrader * +ostree_sysroot_upgrader_new_for_os (OstreeSysroot *sysroot, const char *osname, + GCancellable *cancellable, GError **error) { - return g_initable_new (OSTREE_TYPE_SYSROOT_UPGRADER, cancellable, error, - "sysroot", sysroot, "osname", osname, NULL); + return g_initable_new (OSTREE_TYPE_SYSROOT_UPGRADER, cancellable, error, "sysroot", sysroot, + "osname", osname, NULL); } /** @@ -309,14 +296,12 @@ ostree_sysroot_upgrader_new_for_os (OstreeSysroot *sysroot, * Returns: (transfer full): An upgrader */ OstreeSysrootUpgrader * -ostree_sysroot_upgrader_new_for_os_with_flags (OstreeSysroot *sysroot, - const char *osname, - OstreeSysrootUpgraderFlags flags, - GCancellable *cancellable, - GError **error) +ostree_sysroot_upgrader_new_for_os_with_flags (OstreeSysroot *sysroot, const char *osname, + OstreeSysrootUpgraderFlags flags, + GCancellable *cancellable, GError **error) { - return g_initable_new (OSTREE_TYPE_SYSROOT_UPGRADER, cancellable, error, - "sysroot", sysroot, "osname", osname, "flags", flags, NULL); + return g_initable_new (OSTREE_TYPE_SYSROOT_UPGRADER, cancellable, error, "sysroot", sysroot, + "osname", osname, "flags", flags, NULL); } /** @@ -351,8 +336,7 @@ ostree_sysroot_upgrader_dup_origin (OstreeSysrootUpgrader *self) copy = g_key_file_new (); data = g_key_file_to_data (self->origin, &length, NULL); - g_key_file_load_from_data (copy, data, length, - G_KEY_FILE_KEEP_COMMENTS, NULL); + g_key_file_load_from_data (copy, data, length, G_KEY_FILE_KEEP_COMMENTS, NULL); } return copy; @@ -368,10 +352,8 @@ ostree_sysroot_upgrader_dup_origin (OstreeSysrootUpgrader *self) * Replace the origin with @origin. */ gboolean -ostree_sysroot_upgrader_set_origin (OstreeSysrootUpgrader *self, - GKeyFile *origin, - GCancellable *cancellable, - GError **error) +ostree_sysroot_upgrader_set_origin (OstreeSysrootUpgrader *self, GKeyFile *origin, + GCancellable *cancellable, GError **error) { g_clear_pointer (&self->origin, g_key_file_unref); if (origin) @@ -388,7 +370,8 @@ ostree_sysroot_upgrader_set_origin (OstreeSysrootUpgrader *self, * ostree_sysroot_upgrader_get_origin_description: * @self: Upgrader * - * Returns: (transfer full) (nullable): A one-line descriptive summary of the origin, or %NULL if unknown. + * Returns: (transfer full) (nullable): A one-line descriptive summary of the origin, or %NULL if + * unknown. */ char * ostree_sysroot_upgrader_get_origin_description (OstreeSysrootUpgrader *self) @@ -410,28 +393,19 @@ ostree_sysroot_upgrader_get_origin_description (OstreeSysrootUpgrader *self) * attackers which provide a client with an older commit. */ gboolean -ostree_sysroot_upgrader_check_timestamps (OstreeRepo *repo, - const char *from_rev, - const char *to_rev, - GError **error) +ostree_sysroot_upgrader_check_timestamps (OstreeRepo *repo, const char *from_rev, + const char *to_rev, GError **error) { - g_autoptr(GVariant) old_commit = NULL; - if (!ostree_repo_load_variant (repo, - OSTREE_OBJECT_TYPE_COMMIT, - from_rev, - &old_commit, - error)) + g_autoptr (GVariant) old_commit = NULL; + if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, from_rev, &old_commit, error)) return FALSE; - g_autoptr(GVariant) new_commit = NULL; - if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, - to_rev, &new_commit, - error)) + g_autoptr (GVariant) new_commit = NULL; + if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, to_rev, &new_commit, error)) return FALSE; - if (!_ostree_compare_timestamps (from_rev, ostree_commit_get_timestamp (old_commit), - to_rev, ostree_commit_get_timestamp (new_commit), - error)) + if (!_ostree_compare_timestamps (from_rev, ostree_commit_get_timestamp (old_commit), to_rev, + ostree_commit_get_timestamp (new_commit), error)) return FALSE; return TRUE; @@ -455,15 +429,13 @@ ostree_sysroot_upgrader_check_timestamps (OstreeRepo *repo, * %FALSE. */ gboolean -ostree_sysroot_upgrader_pull (OstreeSysrootUpgrader *self, - OstreeRepoPullFlags flags, - OstreeSysrootUpgraderPullFlags upgrader_flags, - OstreeAsyncProgress *progress, - gboolean *out_changed, - GCancellable *cancellable, - GError **error) +ostree_sysroot_upgrader_pull (OstreeSysrootUpgrader *self, OstreeRepoPullFlags flags, + OstreeSysrootUpgraderPullFlags upgrader_flags, + OstreeAsyncProgress *progress, gboolean *out_changed, + GCancellable *cancellable, GError **error) { - return ostree_sysroot_upgrader_pull_one_dir (self, NULL, flags, upgrader_flags, progress, out_changed, cancellable, error); + return ostree_sysroot_upgrader_pull_one_dir (self, NULL, flags, upgrader_flags, progress, + out_changed, cancellable, error); } /** @@ -483,22 +455,19 @@ ostree_sysroot_upgrader_pull (OstreeSysrootUpgrader *self, * */ gboolean -ostree_sysroot_upgrader_pull_one_dir (OstreeSysrootUpgrader *self, - const char *dir_to_pull, - OstreeRepoPullFlags flags, - OstreeSysrootUpgraderPullFlags upgrader_flags, - OstreeAsyncProgress *progress, - gboolean *out_changed, - GCancellable *cancellable, - GError **error) +ostree_sysroot_upgrader_pull_one_dir (OstreeSysrootUpgrader *self, const char *dir_to_pull, + OstreeRepoPullFlags flags, + OstreeSysrootUpgraderPullFlags upgrader_flags, + OstreeAsyncProgress *progress, gboolean *out_changed, + GCancellable *cancellable, GError **error) { char *refs_to_fetch[] = { NULL, NULL }; const char *from_revision = NULL; g_autofree char *origin_refspec = NULL; g_autofree char *new_revision = NULL; - g_autoptr(GVariant) new_variant = NULL; - g_autoptr(GVariant) new_metadata = NULL; - g_autoptr(GVariant) rebase = NULL; + g_autoptr (GVariant) new_variant = NULL; + g_autoptr (GVariant) new_metadata = NULL; + g_autoptr (GVariant) rebase = NULL; if (self->override_csum != NULL) refs_to_fetch[0] = self->override_csum; @@ -515,10 +484,9 @@ ostree_sysroot_upgrader_pull_one_dir (OstreeSysrootUpgrader *self, g_assert (self->merge_deployment); from_revision = ostree_deployment_get_csum (self->merge_deployment); - if (self->origin_remote && - (upgrader_flags & OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_SYNTHETIC) == 0) + if (self->origin_remote && (upgrader_flags & OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_SYNTHETIC) == 0) { - g_autoptr(GVariantBuilder) optbuilder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); + g_autoptr (GVariantBuilder) optbuilder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); if (dir_to_pull && *dir_to_pull) g_variant_builder_add (optbuilder, "{s@v}", "subdir", g_variant_new_variant (g_variant_new_string (dir_to_pull))); @@ -529,12 +497,12 @@ ostree_sysroot_upgrader_pull_one_dir (OstreeSysrootUpgrader *self, g_variant_builder_add (optbuilder, "{s@v}", "timestamp-check-from-rev", g_variant_new_variant (g_variant_new_string (from_revision))); - g_variant_builder_add (optbuilder, "{s@v}", "refs", - g_variant_new_variant (g_variant_new_strv ((const char *const*) refs_to_fetch, -1))); - g_autoptr(GVariant) opts = g_variant_ref_sink (g_variant_builder_end (optbuilder)); - if (!ostree_repo_pull_with_options (repo, self->origin_remote, - opts, progress, - cancellable, error)) + g_variant_builder_add ( + optbuilder, "{s@v}", "refs", + g_variant_new_variant (g_variant_new_strv ((const char *const *)refs_to_fetch, -1))); + g_autoptr (GVariant) opts = g_variant_ref_sink (g_variant_builder_end (optbuilder)); + if (!ostree_repo_pull_with_options (repo, self->origin_remote, opts, progress, cancellable, + error)) return FALSE; if (progress) @@ -543,64 +511,55 @@ ostree_sysroot_upgrader_pull_one_dir (OstreeSysrootUpgrader *self, /* Check to see if the commit marks the ref as EOL, redirecting to * another. */ - if (!ostree_repo_resolve_rev (repo, origin_refspec, FALSE, - &new_revision, error)) + if (!ostree_repo_resolve_rev (repo, origin_refspec, FALSE, &new_revision, error)) return FALSE; - if (!ostree_repo_load_variant (repo, - OSTREE_OBJECT_TYPE_COMMIT, - new_revision, - &new_variant, + if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, new_revision, &new_variant, error)) return FALSE; g_variant_get_child (new_variant, 0, "@a{sv}", &new_metadata); - rebase = g_variant_lookup_value (new_metadata, OSTREE_COMMIT_META_KEY_ENDOFLIFE_REBASE, G_VARIANT_TYPE_STRING); + rebase = g_variant_lookup_value (new_metadata, OSTREE_COMMIT_META_KEY_ENDOFLIFE_REBASE, + G_VARIANT_TYPE_STRING); if (rebase) { const char *new_ref = g_variant_get_string (rebase, 0); /* Pull the new ref */ - if (self->origin_remote && - (upgrader_flags & OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_SYNTHETIC) == 0) + if (self->origin_remote + && (upgrader_flags & OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_SYNTHETIC) == 0) { - refs_to_fetch[0] = (char *) new_ref; + refs_to_fetch[0] = (char *)new_ref; if (!ostree_repo_pull_one_dir (repo, self->origin_remote, dir_to_pull, refs_to_fetch, flags, progress, cancellable, error)) return FALSE; } - /* Use the new ref for the rest of the update process */ - g_free (self->origin_ref); - self->origin_ref = g_strdup(new_ref); - g_free (origin_refspec); + /* Use the new ref for the rest of the update process */ + g_free (self->origin_ref); + self->origin_ref = g_strdup (new_ref); + g_free (origin_refspec); - if (self->origin_remote) - origin_refspec = g_strconcat (self->origin_remote, ":", new_ref, NULL); - else - origin_refspec = g_strdup (new_ref); + if (self->origin_remote) + origin_refspec = g_strconcat (self->origin_remote, ":", new_ref, NULL); + else + origin_refspec = g_strdup (new_ref); - g_key_file_set_string (self->origin, "origin", "refspec", origin_refspec); + g_key_file_set_string (self->origin, "origin", "refspec", origin_refspec); } if (self->override_csum != NULL) { - if (!ostree_repo_set_ref_immediate (repo, - self->origin_remote, - self->origin_ref, - self->override_csum, - cancellable, - error)) + if (!ostree_repo_set_ref_immediate (repo, self->origin_remote, self->origin_ref, + self->override_csum, cancellable, error)) return FALSE; self->new_revision = g_strdup (self->override_csum); } else { - if (!ostree_repo_resolve_rev (repo, origin_refspec, FALSE, - &self->new_revision, error)) + if (!ostree_repo_resolve_rev (repo, origin_refspec, FALSE, &self->new_revision, error)) return FALSE; - } if (g_strcmp0 (from_revision, self->new_revision) == 0) @@ -615,8 +574,7 @@ ostree_sysroot_upgrader_pull_one_dir (OstreeSysrootUpgrader *self, if (from_revision && !allow_older) { - if (!ostree_sysroot_upgrader_check_timestamps (repo, from_revision, - self->new_revision, + if (!ostree_sysroot_upgrader_check_timestamps (repo, from_revision, self->new_revision, error)) return FALSE; } @@ -635,41 +593,30 @@ ostree_sysroot_upgrader_pull_one_dir (OstreeSysrootUpgrader *self, * with /etc, and update the bootloader configuration. */ gboolean -ostree_sysroot_upgrader_deploy (OstreeSysrootUpgrader *self, - GCancellable *cancellable, - GError **error) +ostree_sysroot_upgrader_deploy (OstreeSysrootUpgrader *self, GCancellable *cancellable, + GError **error) { - g_autoptr(OstreeDeployment) new_deployment = NULL; + g_autoptr (OstreeDeployment) new_deployment = NULL; /* Experimental flag to enable staging */ - gboolean stage = (self->flags & OSTREE_SYSROOT_UPGRADER_FLAGS_STAGE) > 0 || getenv ("OSTREE_EX_STAGE_DEPLOYMENTS") != NULL; + gboolean stage = (self->flags & OSTREE_SYSROOT_UPGRADER_FLAGS_STAGE) > 0 + || getenv ("OSTREE_EX_STAGE_DEPLOYMENTS") != NULL; if (stage) { - if (!ostree_sysroot_stage_tree (self->sysroot, self->osname, - self->new_revision, - self->origin, - self->merge_deployment, - NULL, - &new_deployment, - cancellable, error)) + if (!ostree_sysroot_stage_tree (self->sysroot, self->osname, self->new_revision, self->origin, + self->merge_deployment, NULL, &new_deployment, cancellable, + error)) return FALSE; } else { - if (!ostree_sysroot_deploy_tree (self->sysroot, self->osname, - self->new_revision, - self->origin, - self->merge_deployment, - NULL, - &new_deployment, + if (!ostree_sysroot_deploy_tree (self->sysroot, self->osname, self->new_revision, + self->origin, self->merge_deployment, NULL, &new_deployment, cancellable, error)) return FALSE; - if (!ostree_sysroot_simple_write_deployment (self->sysroot, self->osname, - new_deployment, - self->merge_deployment, - 0, - cancellable, error)) + if (!ostree_sysroot_simple_write_deployment (self->sysroot, self->osname, new_deployment, + self->merge_deployment, 0, cancellable, error)) return FALSE; } @@ -683,13 +630,14 @@ ostree_sysroot_upgrader_flags_get_type (void) if (g_once_init_enter (&static_g_define_type_id)) { - static const GFlagsValue values[] = { - { OSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED, "OSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED", "ignore-unconfigured" }, - { OSTREE_SYSROOT_UPGRADER_FLAGS_STAGE, "OSTREE_SYSROOT_UPGRADER_FLAGS_STAGE", "stage" }, - { 0, NULL, NULL } - }; - GType g_define_type_id = - g_flags_register_static (g_intern_static_string ("OstreeSysrootUpgraderFlags"), values); + static const GFlagsValue values[] + = { { OSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED, + "OSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED", "ignore-unconfigured" }, + { OSTREE_SYSROOT_UPGRADER_FLAGS_STAGE, "OSTREE_SYSROOT_UPGRADER_FLAGS_STAGE", + "stage" }, + { 0, NULL, NULL } }; + GType g_define_type_id + = g_flags_register_static (g_intern_static_string ("OstreeSysrootUpgraderFlags"), values); g_once_init_leave (&static_g_define_type_id, g_define_type_id); } diff --git a/src/libostree/ostree-sysroot-upgrader.h b/src/libostree/ostree-sysroot-upgrader.h index b214157f..5d1e8c2a 100644 --- a/src/libostree/ostree-sysroot-upgrader.h +++ b/src/libostree/ostree-sysroot-upgrader.h @@ -23,7 +23,7 @@ G_BEGIN_DECLS -#define OSTREE_TYPE_SYSROOT_UPGRADER ostree_sysroot_upgrader_get_type() +#define OSTREE_TYPE_SYSROOT_UPGRADER ostree_sysroot_upgrader_get_type () #define OSTREE_SYSROOT_UPGRADER(obj) \ (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSTREE_TYPE_SYSROOT_UPGRADER, OstreeSysrootUpgrader)) #define OSTREE_IS_SYSROOT_UPGRADER(obj) \ @@ -32,13 +32,15 @@ G_BEGIN_DECLS /** * OstreeSysrootUpgraderFlags: * @OSTREE_SYSROOT_UPGRADER_FLAGS_NONE: No options - * @OSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED: Do not error if the origin has an unconfigured-state key + * @OSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED: Do not error if the origin has an + * unconfigured-state key * @OSTREE_SYSROOT_UPGRADER_FLAGS_STAGE: Enable "staging" (finalization at shutdown); recommended * (Since: 2021.4) * * Flags controlling operation of an #OstreeSysrootUpgrader. */ -typedef enum { +typedef enum +{ OSTREE_SYSROOT_UPGRADER_FLAGS_NONE = (1 << 0), OSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED = (1 << 1), OSTREE_SYSROOT_UPGRADER_FLAGS_STAGE = (1 << 2), @@ -52,21 +54,19 @@ GType ostree_sysroot_upgrader_flags_get_type (void); _OSTREE_PUBLIC OstreeSysrootUpgrader *ostree_sysroot_upgrader_new (OstreeSysroot *sysroot, - GCancellable *cancellable, - GError **error); + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC OstreeSysrootUpgrader *ostree_sysroot_upgrader_new_for_os (OstreeSysroot *sysroot, - const char *osname, - GCancellable *cancellable, - GError **error); + const char *osname, + GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -OstreeSysrootUpgrader *ostree_sysroot_upgrader_new_for_os_with_flags (OstreeSysroot *sysroot, - const char *osname, - OstreeSysrootUpgraderFlags flags, - GCancellable *cancellable, - GError **error); +OstreeSysrootUpgrader * +ostree_sysroot_upgrader_new_for_os_with_flags (OstreeSysroot *sysroot, const char *osname, + OstreeSysrootUpgraderFlags flags, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC GKeyFile *ostree_sysroot_upgrader_get_origin (OstreeSysrootUpgrader *self); @@ -80,39 +80,32 @@ _OSTREE_PUBLIC char *ostree_sysroot_upgrader_get_origin_description (OstreeSysrootUpgrader *self); _OSTREE_PUBLIC -gboolean ostree_sysroot_upgrader_check_timestamps (OstreeRepo *repo, - const char *from_rev, - const char *to_rev, - GError **error); +gboolean ostree_sysroot_upgrader_check_timestamps (OstreeRepo *repo, const char *from_rev, + const char *to_rev, GError **error); -typedef enum { +typedef enum +{ OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_NONE = 0, OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_ALLOW_OLDER = (1 << 0), - OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_SYNTHETIC = (1 << 1) /* Don't actually do a pull, just check timestamps/changed */ + OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_SYNTHETIC + = (1 << 1) /* Don't actually do a pull, just check timestamps/changed */ } OstreeSysrootUpgraderPullFlags; _OSTREE_PUBLIC -gboolean ostree_sysroot_upgrader_pull (OstreeSysrootUpgrader *self, - OstreeRepoPullFlags flags, - OstreeSysrootUpgraderPullFlags upgrader_flags, - OstreeAsyncProgress *progress, - gboolean *out_changed, - GCancellable *cancellable, - GError **error); +gboolean ostree_sysroot_upgrader_pull (OstreeSysrootUpgrader *self, OstreeRepoPullFlags flags, + OstreeSysrootUpgraderPullFlags upgrader_flags, + OstreeAsyncProgress *progress, gboolean *out_changed, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_sysroot_upgrader_pull_one_dir (OstreeSysrootUpgrader *self, - const char *dir_to_pull, - OstreeRepoPullFlags flags, - OstreeSysrootUpgraderPullFlags upgrader_flags, - OstreeAsyncProgress *progress, - gboolean *out_changed, - GCancellable *cancellable, - GError **error); +gboolean ostree_sysroot_upgrader_pull_one_dir (OstreeSysrootUpgrader *self, const char *dir_to_pull, + OstreeRepoPullFlags flags, + OstreeSysrootUpgraderPullFlags upgrader_flags, + OstreeAsyncProgress *progress, gboolean *out_changed, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_sysroot_upgrader_deploy (OstreeSysrootUpgrader *self, - GCancellable *cancellable, - GError **error); +gboolean ostree_sysroot_upgrader_deploy (OstreeSysrootUpgrader *self, GCancellable *cancellable, + GError **error); G_END_DECLS diff --git a/src/libostree/ostree-sysroot.c b/src/libostree/ostree-sysroot.c index f4e358dd..ca8b3277 100644 --- a/src/libostree/ostree-sysroot.c +++ b/src/libostree/ostree-sysroot.c @@ -21,22 +21,22 @@ #include "config.h" #include "otutil.h" +#include #include #include -#include #include -#include "ostree.h" +#include "ostree-bootloader-aboot.h" +#include "ostree-bootloader-grub2.h" +#include "ostree-bootloader-syslinux.h" +#include "ostree-bootloader-uboot.h" +#include "ostree-bootloader-zipl.h" #include "ostree-core-private.h" +#include "ostree-deployment-private.h" #include "ostree-repo-private.h" #include "ostree-sepolicy-private.h" #include "ostree-sysroot-private.h" -#include "ostree-deployment-private.h" -#include "ostree-bootloader-aboot.h" -#include "ostree-bootloader-uboot.h" -#include "ostree-bootloader-syslinux.h" -#include "ostree-bootloader-grub2.h" -#include "ostree-bootloader-zipl.h" +#include "ostree.h" /** * SECTION:ostree-sysroot @@ -52,21 +52,23 @@ * or external processes. You can use ostree_sysroot_lock() to * perform locking externally. */ -typedef struct { +typedef struct +{ GObjectClass parent_class; /* Signals */ - void (*journal_msg) (OstreeSysroot *sysroot, - const char *msg); + void (*journal_msg) (OstreeSysroot *sysroot, const char *msg); } OstreeSysrootClass; -enum { +enum +{ JOURNAL_MSG_SIGNAL, LAST_SIGNAL, }; static guint signals[LAST_SIGNAL] = { 0 }; -enum { +enum +{ PROP_0, PROP_PATH @@ -94,10 +96,7 @@ ostree_sysroot_finalize (GObject *object) } static void -ostree_sysroot_set_property(GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) +ostree_sysroot_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { OstreeSysroot *self = OSTREE_SYSROOT (object); @@ -113,10 +112,7 @@ ostree_sysroot_set_property(GObject *object, } static void -ostree_sysroot_get_property(GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) +ostree_sysroot_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { OstreeSysroot *self = OSTREE_SYSROOT (object); @@ -153,13 +149,10 @@ ostree_sysroot_class_init (OstreeSysrootClass *klass) object_class->set_property = ostree_sysroot_set_property; object_class->finalize = ostree_sysroot_finalize; - g_object_class_install_property (object_class, - PROP_PATH, - g_param_spec_object ("path", - "", - "", - G_TYPE_FILE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property ( + object_class, PROP_PATH, + g_param_spec_object ("path", "", "", G_TYPE_FILE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); /** * OstreeSysroot::journal-msg: @@ -175,12 +168,10 @@ ostree_sysroot_class_init (OstreeSysrootClass *klass) * * Since: 2017.10 */ - signals[JOURNAL_MSG_SIGNAL] = - g_signal_new ("journal-msg", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (OstreeSysrootClass, journal_msg), - NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_STRING); + signals[JOURNAL_MSG_SIGNAL] + = g_signal_new ("journal-msg", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (OstreeSysrootClass, journal_msg), NULL, NULL, NULL, + G_TYPE_NONE, 1, G_TYPE_STRING); } static void @@ -197,10 +188,10 @@ ostree_sysroot_init (OstreeSysroot *self) { "no-dtb", OSTREE_SYSROOT_DEBUG_TEST_NO_DTB }, }; - self->opt_flags = g_parse_debug_string (g_getenv ("OSTREE_SYSROOT_OPTS"), - globalopt_keys, G_N_ELEMENTS (globalopt_keys)); - self->debug_flags = g_parse_debug_string (g_getenv ("OSTREE_SYSROOT_DEBUG"), - keys, G_N_ELEMENTS (keys)); + self->opt_flags = g_parse_debug_string (g_getenv ("OSTREE_SYSROOT_OPTS"), globalopt_keys, + G_N_ELEMENTS (globalopt_keys)); + self->debug_flags + = g_parse_debug_string (g_getenv ("OSTREE_SYSROOT_DEBUG"), keys, G_N_ELEMENTS (keys)); self->sysroot_fd = -1; self->boot_fd = -1; @@ -217,7 +208,7 @@ ostree_sysroot_init (OstreeSysroot *self) * * Returns: (transfer full): An accessor object for an system root located at @path */ -OstreeSysroot* +OstreeSysroot * ostree_sysroot_new (GFile *path) { return g_object_new (OSTREE_TYPE_SYSROOT, "path", path, NULL); @@ -228,7 +219,7 @@ ostree_sysroot_new (GFile *path) * * Returns: (transfer full): An accessor for the current visible root / filesystem */ -OstreeSysroot* +OstreeSysroot * ostree_sysroot_new_default (void) { return ostree_sysroot_new (NULL); @@ -253,7 +244,7 @@ ostree_sysroot_new_default (void) * Since: 2020.1 */ void -ostree_sysroot_set_mount_namespace_in_use (OstreeSysroot *self) +ostree_sysroot_set_mount_namespace_in_use (OstreeSysroot *self) { /* Must be before we're loaded, as otherwise we'd have to close/reopen all our fds, e.g. the repo */ @@ -280,7 +271,8 @@ ostree_sysroot_set_mount_namespace_in_use (OstreeSysroot *self) * Since: 2022.7 */ gboolean -ostree_sysroot_initialize_with_mount_namespace (OstreeSysroot *self, GCancellable *cancellable, GError **error) +ostree_sysroot_initialize_with_mount_namespace (OstreeSysroot *self, GCancellable *cancellable, + GError **error) { GLNX_AUTO_PREFIX_ERROR ("Initializing with mountns", error); /* Must be before we're loaded, as otherwise we'd have to close/reopen all our @@ -298,12 +290,12 @@ ostree_sysroot_initialize_with_mount_namespace (OstreeSysroot *self, GCancellabl if (!self->root_is_ostree_booted) return TRUE; - g_autofree char *mntns_pid1 = - glnx_readlinkat_malloc (AT_FDCWD, "/proc/1/ns/mnt", cancellable, error); + g_autofree char *mntns_pid1 + = glnx_readlinkat_malloc (AT_FDCWD, "/proc/1/ns/mnt", cancellable, error); if (!mntns_pid1) return glnx_prefix_error (error, "Reading /proc/1/ns/mnt"); - g_autofree char *mntns_self = - glnx_readlinkat_malloc (AT_FDCWD, "/proc/self/ns/mnt", cancellable, error); + g_autofree char *mntns_self + = glnx_readlinkat_malloc (AT_FDCWD, "/proc/self/ns/mnt", cancellable, error); if (!mntns_self) return glnx_prefix_error (error, "Reading /proc/self/ns/mnt"); @@ -325,20 +317,19 @@ ostree_sysroot_initialize_with_mount_namespace (OstreeSysroot *self, GCancellabl * Returns: (transfer none) (not nullable): Path to rootfs */ GFile * -ostree_sysroot_get_path (OstreeSysroot *self) +ostree_sysroot_get_path (OstreeSysroot *self) { return self->path; } /* Open a directory file descriptor for the sysroot if we haven't yet */ static gboolean -ensure_sysroot_fd (OstreeSysroot *self, - GError **error) +ensure_sysroot_fd (OstreeSysroot *self, GError **error) { if (self->sysroot_fd == -1) { - if (!glnx_opendirat (AT_FDCWD, gs_file_get_path_cached (self->path), TRUE, - &self->sysroot_fd, error)) + if (!glnx_opendirat (AT_FDCWD, gs_file_get_path_cached (self->path), TRUE, &self->sysroot_fd, + error)) return FALSE; } @@ -350,8 +341,7 @@ _ostree_sysroot_ensure_boot_fd (OstreeSysroot *self, GError **error) { if (self->boot_fd == -1) { - if (!glnx_opendirat (self->sysroot_fd, "boot", TRUE, - &self->boot_fd, error)) + if (!glnx_opendirat (self->sysroot_fd, "boot", TRUE, &self->boot_fd, error)) return FALSE; } return TRUE; @@ -384,8 +374,7 @@ remount_writable (const char *path, gboolean *did_remount, GError **error) /* Remount /sysroot read-write if necessary */ gboolean -_ostree_sysroot_ensure_writable (OstreeSysroot *self, - GError **error) +_ostree_sysroot_ensure_writable (OstreeSysroot *self, GError **error) { if (!ostree_sysroot_initialize (self, error)) return FALSE; @@ -455,8 +444,7 @@ ostree_sysroot_is_booted (OstreeSysroot *self) } gboolean -_ostree_sysroot_bump_mtime (OstreeSysroot *self, - GError **error) +_ostree_sysroot_bump_mtime (OstreeSysroot *self, GError **error) { /* Allow other systems to monitor for changes */ if (utimensat (self->sysroot_fd, "ostree/deploy", NULL, 0) < 0) @@ -479,7 +467,7 @@ _ostree_sysroot_bump_mtime (OstreeSysroot *self, * This undoes the effect of `ostree_sysroot_load()`. */ void -ostree_sysroot_unload (OstreeSysroot *self) +ostree_sysroot_unload (OstreeSysroot *self) { glnx_close_fd (&self->sysroot_fd); glnx_close_fd (&self->boot_fd); @@ -495,42 +483,33 @@ ostree_sysroot_unload (OstreeSysroot *self) * /ostree/repo, among other things. */ gboolean -ostree_sysroot_ensure_initialized (OstreeSysroot *self, - GCancellable *cancellable, - GError **error) +ostree_sysroot_ensure_initialized (OstreeSysroot *self, GCancellable *cancellable, GError **error) { if (!ensure_sysroot_fd (self, error)) return FALSE; - if (!glnx_shutil_mkdir_p_at (self->sysroot_fd, "ostree/repo", 0755, - cancellable, error)) + if (!glnx_shutil_mkdir_p_at (self->sysroot_fd, "ostree/repo", 0755, cancellable, error)) return FALSE; - if (!glnx_shutil_mkdir_p_at (self->sysroot_fd, "ostree/deploy", 0755, - cancellable, error)) + if (!glnx_shutil_mkdir_p_at (self->sysroot_fd, "ostree/deploy", 0755, cancellable, error)) return FALSE; - g_autoptr(OstreeRepo) repo = - ostree_repo_create_at (self->sysroot_fd, "ostree/repo", - OSTREE_REPO_MODE_BARE, NULL, - cancellable, error); + g_autoptr (OstreeRepo) repo = ostree_repo_create_at ( + self->sysroot_fd, "ostree/repo", OSTREE_REPO_MODE_BARE, NULL, cancellable, error); if (!repo) return FALSE; return TRUE; } void -_ostree_sysroot_emit_journal_msg (OstreeSysroot *self, - const char *msg) +_ostree_sysroot_emit_journal_msg (OstreeSysroot *self, const char *msg) { g_signal_emit (self, signals[JOURNAL_MSG_SIGNAL], 0, msg); } gboolean -_ostree_sysroot_parse_deploy_path_name (const char *name, - char **out_csum, - int *out_serial, - GError **error) +_ostree_sysroot_parse_deploy_path_name (const char *name, char **out_csum, int *out_serial, + GError **error) { static gsize regex_initialized; @@ -542,7 +521,7 @@ _ostree_sysroot_parse_deploy_path_name (const char *name, g_once_init_leave (®ex_initialized, 1); } - g_autoptr(GMatchInfo) match = NULL; + g_autoptr (GMatchInfo) match = NULL; if (!g_regex_match (regex, name, 0, &match)) return glnx_throw (error, "Invalid deploy name '%s', expected CHECKSUM.TREESERIAL", name); @@ -554,29 +533,28 @@ _ostree_sysroot_parse_deploy_path_name (const char *name, /* For a given bootversion, get its subbootversion from `/ostree/boot.$bootversion`. */ gboolean -_ostree_sysroot_read_current_subbootversion (OstreeSysroot *self, - int bootversion, - int *out_subbootversion, - GCancellable *cancellable, - GError **error) +_ostree_sysroot_read_current_subbootversion (OstreeSysroot *self, int bootversion, + int *out_subbootversion, GCancellable *cancellable, + GError **error) { if (!ensure_sysroot_fd (self, error)) return FALSE; g_autofree char *ostree_bootdir_name = g_strdup_printf ("ostree/boot.%d", bootversion); struct stat stbuf; - if (!glnx_fstatat_allow_noent (self->sysroot_fd, ostree_bootdir_name, &stbuf, AT_SYMLINK_NOFOLLOW, error)) + if (!glnx_fstatat_allow_noent (self->sysroot_fd, ostree_bootdir_name, &stbuf, AT_SYMLINK_NOFOLLOW, + error)) return FALSE; if (errno == ENOENT) { - g_debug ("Didn't find $sysroot/ostree/boot.%d symlink; assuming subbootversion 0", bootversion); + g_debug ("Didn't find $sysroot/ostree/boot.%d symlink; assuming subbootversion 0", + bootversion); *out_subbootversion = 0; } else { - g_autofree char *current_subbootdir_name = - glnx_readlinkat_malloc (self->sysroot_fd, ostree_bootdir_name, - cancellable, error); + g_autofree char *current_subbootdir_name + = glnx_readlinkat_malloc (self->sysroot_fd, ostree_bootdir_name, cancellable, error); if (!current_subbootdir_name) return FALSE; @@ -585,16 +563,15 @@ _ostree_sysroot_read_current_subbootversion (OstreeSysroot *self, else if (g_str_has_suffix (current_subbootdir_name, ".1")) *out_subbootversion = 1; else - return glnx_throw (error, "Invalid target '%s' in %s", - current_subbootdir_name, ostree_bootdir_name); + return glnx_throw (error, "Invalid target '%s' in %s", current_subbootdir_name, + ostree_bootdir_name); } return TRUE; } static gint -compare_boot_loader_configs (OstreeBootconfigParser *a, - OstreeBootconfigParser *b) +compare_boot_loader_configs (OstreeBootconfigParser *a, OstreeBootconfigParser *b) { const char *a_version = ostree_bootconfig_parser_get (a, "version"); const char *b_version = ostree_bootconfig_parser_get (b, "version"); @@ -612,34 +589,33 @@ compare_boot_loader_configs (OstreeBootconfigParser *a, } static int -compare_loader_configs_for_sorting (gconstpointer a_pp, - gconstpointer b_pp) +compare_loader_configs_for_sorting (gconstpointer a_pp, gconstpointer b_pp) { - OstreeBootconfigParser *a = *((OstreeBootconfigParser**)a_pp); - OstreeBootconfigParser *b = *((OstreeBootconfigParser**)b_pp); + OstreeBootconfigParser *a = *((OstreeBootconfigParser **)a_pp); + OstreeBootconfigParser *b = *((OstreeBootconfigParser **)b_pp); return compare_boot_loader_configs (a, b); } /* Read all the bootconfigs from `/boot/loader/`. */ gboolean -_ostree_sysroot_read_boot_loader_configs (OstreeSysroot *self, - int bootversion, - GPtrArray **out_loader_configs, - GCancellable *cancellable, - GError **error) +_ostree_sysroot_read_boot_loader_configs (OstreeSysroot *self, int bootversion, + GPtrArray **out_loader_configs, GCancellable *cancellable, + GError **error) { if (!ensure_sysroot_fd (self, error)) return FALSE; - g_autoptr(GPtrArray) ret_loader_configs = - g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref); + g_autoptr (GPtrArray) ret_loader_configs + = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref); g_autofree char *entries_path = g_strdup_printf ("boot/loader.%d/entries", bootversion); gboolean entries_exists; - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; - if (!ot_dfd_iter_init_allow_noent (self->sysroot_fd, entries_path, - &dfd_iter, &entries_exists, error)) + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; + if (!ot_dfd_iter_init_allow_noent (self->sysroot_fd, entries_path, &dfd_iter, &entries_exists, + error)) return FALSE; if (!entries_exists) { @@ -661,13 +637,13 @@ _ostree_sysroot_read_boot_loader_configs (OstreeSysroot *self, if (!glnx_fstatat (dfd_iter.fd, dent->d_name, &stbuf, 0, error)) return FALSE; - if (g_str_has_prefix (dent->d_name, "ostree-") && - g_str_has_suffix (dent->d_name, ".conf") && - S_ISREG (stbuf.st_mode)) + if (g_str_has_prefix (dent->d_name, "ostree-") && g_str_has_suffix (dent->d_name, ".conf") + && S_ISREG (stbuf.st_mode)) { - g_autoptr(OstreeBootconfigParser) config = ostree_bootconfig_parser_new (); + g_autoptr (OstreeBootconfigParser) config = ostree_bootconfig_parser_new (); - if (!ostree_bootconfig_parser_parse_at (config, dfd_iter.fd, dent->d_name, cancellable, error)) + if (!ostree_bootconfig_parser_parse_at (config, dfd_iter.fd, dent->d_name, cancellable, + error)) return glnx_prefix_error (error, "Parsing %s", dent->d_name); g_ptr_array_add (ret_loader_configs, g_object_ref (config)); @@ -676,21 +652,20 @@ _ostree_sysroot_read_boot_loader_configs (OstreeSysroot *self, /* Callers expect us to give them a sorted array */ g_ptr_array_sort (ret_loader_configs, compare_loader_configs_for_sorting); - ot_transfer_out_value(out_loader_configs, &ret_loader_configs); + ot_transfer_out_value (out_loader_configs, &ret_loader_configs); return TRUE; } /* Get the bootversion from the `/boot/loader` symlink. */ static gboolean -read_current_bootversion (OstreeSysroot *self, - int *out_bootversion, - GCancellable *cancellable, - GError **error) +read_current_bootversion (OstreeSysroot *self, int *out_bootversion, GCancellable *cancellable, + GError **error) { int ret_bootversion; struct stat stbuf; - if (!glnx_fstatat_allow_noent (self->sysroot_fd, "boot/loader", &stbuf, AT_SYMLINK_NOFOLLOW, error)) + if (!glnx_fstatat_allow_noent (self->sysroot_fd, "boot/loader", &stbuf, AT_SYMLINK_NOFOLLOW, + error)) return FALSE; if (errno == ENOENT) { @@ -702,8 +677,8 @@ read_current_bootversion (OstreeSysroot *self, if (!S_ISLNK (stbuf.st_mode)) return glnx_throw (error, "Not a symbolic link: boot/loader"); - g_autofree char *target = - glnx_readlinkat_malloc (self->sysroot_fd, "boot/loader", cancellable, error); + g_autofree char *target + = glnx_readlinkat_malloc (self->sysroot_fd, "boot/loader", cancellable, error); if (!target) return FALSE; if (g_strcmp0 (target, "loader.0") == 0) @@ -719,10 +694,8 @@ read_current_bootversion (OstreeSysroot *self, } static gboolean -load_origin (OstreeSysroot *self, - OstreeDeployment *deployment, - GCancellable *cancellable, - GError **error) +load_origin (OstreeSysroot *self, OstreeDeployment *deployment, GCancellable *cancellable, + GError **error) { g_autofree char *origin_path = ostree_deployment_get_origin_relpath (deployment); @@ -731,12 +704,11 @@ load_origin (OstreeSysroot *self, return FALSE; if (fd >= 0) { - g_autofree char *origin_contents = - glnx_fd_readall_utf8 (fd, NULL, cancellable, error); + g_autofree char *origin_contents = glnx_fd_readall_utf8 (fd, NULL, cancellable, error); if (!origin_contents) return FALSE; - g_autoptr(GKeyFile) origin = g_key_file_new (); + g_autoptr (GKeyFile) origin = g_key_file_new (); if (!g_key_file_load_from_data (origin, origin_contents, -1, 0, error)) return glnx_prefix_error (error, "Parsing %s", origin_path); @@ -747,12 +719,8 @@ load_origin (OstreeSysroot *self, } static gboolean -parse_bootlink (const char *bootlink, - int *out_entry_bootversion, - char **out_osname, - char **out_bootcsum, - int *out_treebootserial, - GError **error) +parse_bootlink (const char *bootlink, int *out_entry_bootversion, char **out_osname, + char **out_bootcsum, int *out_treebootserial, GError **error) { static gsize regex_initialized; static GRegex *regex; @@ -763,9 +731,12 @@ parse_bootlink (const char *bootlink, g_once_init_leave (®ex_initialized, 1); } - g_autoptr(GMatchInfo) match = NULL; + g_autoptr (GMatchInfo) match = NULL; if (!g_regex_match (regex, bootlink, 0, &match)) - return glnx_throw (error, "Invalid ostree= argument '%s', expected ostree=/ostree/boot.BOOTVERSION/OSNAME/BOOTCSUM/TREESERIAL", bootlink); + return glnx_throw (error, + "Invalid ostree= argument '%s', expected " + "ostree=/ostree/boot.BOOTVERSION/OSNAME/BOOTCSUM/TREESERIAL", + bootlink); g_autofree char *bootversion_str = g_match_info_fetch (match, 1); g_autofree char *treebootserial_str = g_match_info_fetch (match, 4); @@ -779,19 +750,14 @@ parse_bootlink (const char *bootlink, char * _ostree_sysroot_get_runstate_path (OstreeDeployment *deployment, const char *key) { - return g_strdup_printf ("%s%s.%d/%s", - _OSTREE_SYSROOT_DEPLOYMENT_RUNSTATE_DIR, + return g_strdup_printf ("%s%s.%d/%s", _OSTREE_SYSROOT_DEPLOYMENT_RUNSTATE_DIR, ostree_deployment_get_csum (deployment), - ostree_deployment_get_deployserial (deployment), - key); + ostree_deployment_get_deployserial (deployment), key); } static gboolean -parse_deployment (OstreeSysroot *self, - const char *boot_link, - OstreeDeployment **out_deployment, - GCancellable *cancellable, - GError **error) +parse_deployment (OstreeSysroot *self, const char *boot_link, OstreeDeployment **out_deployment, + GCancellable *cancellable, GError **error) { if (!ensure_sysroot_fd (self, error)) return FALSE; @@ -800,40 +766,35 @@ parse_deployment (OstreeSysroot *self, g_autofree char *osname = NULL; g_autofree char *bootcsum = NULL; int treebootserial = -1; - if (!parse_bootlink (boot_link, &entry_boot_version, - &osname, &bootcsum, &treebootserial, - error)) + if (!parse_bootlink (boot_link, &entry_boot_version, &osname, &bootcsum, &treebootserial, error)) return FALSE; - g_autofree char *errprefix = - g_strdup_printf ("Parsing deployment %s in stateroot '%s'", boot_link, osname); - GLNX_AUTO_PREFIX_ERROR(errprefix, error); + g_autofree char *errprefix + = g_strdup_printf ("Parsing deployment %s in stateroot '%s'", boot_link, osname); + GLNX_AUTO_PREFIX_ERROR (errprefix, error); const char *relative_boot_link = boot_link; if (*relative_boot_link == '/') relative_boot_link++; - g_autofree char *treebootserial_target = - glnx_readlinkat_malloc (self->sysroot_fd, relative_boot_link, - cancellable, error); + g_autofree char *treebootserial_target + = glnx_readlinkat_malloc (self->sysroot_fd, relative_boot_link, cancellable, error); if (!treebootserial_target) return FALSE; const char *deploy_basename = glnx_basename (treebootserial_target); g_autofree char *treecsum = NULL; int deployserial = -1; - if (!_ostree_sysroot_parse_deploy_path_name (deploy_basename, - &treecsum, &deployserial, error)) + if (!_ostree_sysroot_parse_deploy_path_name (deploy_basename, &treecsum, &deployserial, error)) return FALSE; glnx_autofd int deployment_dfd = -1; - if (!glnx_opendirat (self->sysroot_fd, relative_boot_link, TRUE, - &deployment_dfd, error)) + if (!glnx_opendirat (self->sysroot_fd, relative_boot_link, TRUE, &deployment_dfd, error)) return FALSE; /* See if this is the booted deployment */ - const gboolean looking_for_booted_deployment = - (self->root_is_ostree_booted && !self->booted_deployment); + const gboolean looking_for_booted_deployment + = (self->root_is_ostree_booted && !self->booted_deployment); gboolean is_booted_deployment = FALSE; if (looking_for_booted_deployment) { @@ -844,21 +805,20 @@ parse_deployment (OstreeSysroot *self, * this parsing code. But eh, if something fails the sysroot state can't * be relied on anyways. */ - is_booted_deployment = (stbuf.st_dev == self->root_device && - stbuf.st_ino == self->root_inode); + is_booted_deployment + = (stbuf.st_dev == self->root_device && stbuf.st_ino == self->root_inode); } - g_autoptr(OstreeDeployment) ret_deployment - = ostree_deployment_new (-1, osname, treecsum, deployserial, - bootcsum, treebootserial); + g_autoptr (OstreeDeployment) ret_deployment + = ostree_deployment_new (-1, osname, treecsum, deployserial, bootcsum, treebootserial); if (!load_origin (self, ret_deployment, cancellable, error)) return FALSE; ret_deployment->unlocked = OSTREE_DEPLOYMENT_UNLOCKED_NONE; - g_autofree char *unlocked_development_path = - _ostree_sysroot_get_runstate_path (ret_deployment, _OSTREE_SYSROOT_DEPLOYMENT_RUNSTATE_FLAG_DEVELOPMENT); - g_autofree char *unlocked_transient_path = - _ostree_sysroot_get_runstate_path (ret_deployment, _OSTREE_SYSROOT_DEPLOYMENT_RUNSTATE_FLAG_TRANSIENT); + g_autofree char *unlocked_development_path = _ostree_sysroot_get_runstate_path ( + ret_deployment, _OSTREE_SYSROOT_DEPLOYMENT_RUNSTATE_FLAG_DEVELOPMENT); + g_autofree char *unlocked_transient_path = _ostree_sysroot_get_runstate_path ( + ret_deployment, _OSTREE_SYSROOT_DEPLOYMENT_RUNSTATE_FLAG_TRANSIENT); struct stat stbuf; if (lstat (unlocked_development_path, &stbuf) == 0) ret_deployment->unlocked = OSTREE_DEPLOYMENT_UNLOCKED_DEVELOPMENT; @@ -867,8 +827,8 @@ parse_deployment (OstreeSysroot *self, else { GKeyFile *origin = ostree_deployment_get_origin (ret_deployment); - g_autofree char *existing_unlocked_state = origin ? - g_key_file_get_string (origin, "origin", "unlocked", NULL) : NULL; + g_autofree char *existing_unlocked_state + = origin ? g_key_file_get_string (origin, "origin", "unlocked", NULL) : NULL; if (g_strcmp0 (existing_unlocked_state, "hotfix") == 0) { @@ -890,13 +850,13 @@ parse_deployment (OstreeSysroot *self, * argument. */ static char * -get_ostree_kernel_arg_from_config (OstreeBootconfigParser *config) +get_ostree_kernel_arg_from_config (OstreeBootconfigParser *config) { const char *options = ostree_bootconfig_parser_get (config, "options"); if (!options) return NULL; - g_auto(GStrv) opts = g_strsplit (options, " ", -1); + g_auto (GStrv) opts = g_strsplit (options, " ", -1); for (char **iter = opts; *iter; iter++) { const char *opt = *iter; @@ -910,24 +870,21 @@ get_ostree_kernel_arg_from_config (OstreeBootconfigParser *config) /* From a BLS config, use its ostree= karg to find the deployment it points to and add it to * the inout_deployments array. */ static gboolean -list_deployments_process_one_boot_entry (OstreeSysroot *self, - OstreeBootconfigParser *config, - GPtrArray *inout_deployments, - GCancellable *cancellable, - GError **error) +list_deployments_process_one_boot_entry (OstreeSysroot *self, OstreeBootconfigParser *config, + GPtrArray *inout_deployments, GCancellable *cancellable, + GError **error) { g_autofree char *ostree_arg = get_ostree_kernel_arg_from_config (config); if (ostree_arg == NULL) return glnx_throw (error, "No ostree= kernel argument found"); - g_autoptr(OstreeDeployment) deployment = NULL; - if (!parse_deployment (self, ostree_arg, &deployment, - cancellable, error)) + g_autoptr (OstreeDeployment) deployment = NULL; + if (!parse_deployment (self, ostree_arg, &deployment, cancellable, error)) return FALSE; ostree_deployment_set_bootconfig (deployment, config); char **overlay_initrds = ostree_bootconfig_parser_get_overlay_initrds (config); - g_autoptr(GPtrArray) initrds_chksums = NULL; + g_autoptr (GPtrArray) initrds_chksums = NULL; for (char **it = overlay_initrds; it && *it; it++) { const char *basename = glnx_basename (*it); @@ -942,7 +899,7 @@ list_deployments_process_one_boot_entry (OstreeSysroot *self, if (initrds_chksums) { g_ptr_array_add (initrds_chksums, NULL); - _ostree_deployment_set_overlay_initrds (deployment, (char**)initrds_chksums->pdata); + _ostree_deployment_set_overlay_initrds (deployment, (char **)initrds_chksums->pdata); } g_ptr_array_add (inout_deployments, g_object_ref (deployment)); @@ -950,11 +907,10 @@ list_deployments_process_one_boot_entry (OstreeSysroot *self, } static gint -compare_deployments_by_boot_loader_version_reversed (gconstpointer a_pp, - gconstpointer b_pp) +compare_deployments_by_boot_loader_version_reversed (gconstpointer a_pp, gconstpointer b_pp) { - OstreeDeployment *a = *((OstreeDeployment**)a_pp); - OstreeDeployment *b = *((OstreeDeployment**)b_pp); + OstreeDeployment *a = *((OstreeDeployment **)a_pp); + OstreeDeployment *b = *((OstreeDeployment **)b_pp); OstreeBootconfigParser *a_bootconfig = ostree_deployment_get_bootconfig (a); OstreeBootconfigParser *b_bootconfig = ostree_deployment_get_bootconfig (b); @@ -980,16 +936,13 @@ compare_deployments_by_boot_loader_version_reversed (gconstpointer a_pp, * rootfs @self. */ gboolean -ostree_sysroot_load (OstreeSysroot *self, - GCancellable *cancellable, - GError **error) +ostree_sysroot_load (OstreeSysroot *self, GCancellable *cancellable, GError **error) { return ostree_sysroot_load_if_changed (self, NULL, cancellable, error); } static gboolean -ensure_repo (OstreeSysroot *self, - GError **error) +ensure_repo (OstreeSysroot *self, GError **error) { if (self->repo != NULL) return TRUE; @@ -1027,8 +980,7 @@ ensure_repo (OstreeSysroot *self, * Since: 2020.1 */ gboolean -ostree_sysroot_initialize (OstreeSysroot *self, - GError **error) +ostree_sysroot_initialize (OstreeSysroot *self, GError **error) { if (!ensure_sysroot_fd (self, error)) return FALSE; @@ -1043,7 +995,8 @@ ostree_sysroot_initialize (OstreeSysroot *self, return FALSE; const gboolean ostree_booted = (errno == 0); - { struct stat root_stbuf; + { + struct stat root_stbuf; if (!glnx_fstatat (AT_FDCWD, "/", &root_stbuf, 0, error)) return FALSE; self->root_device = root_stbuf.st_dev; @@ -1054,9 +1007,8 @@ ostree_sysroot_initialize (OstreeSysroot *self, if (!glnx_fstatat (AT_FDCWD, gs_file_get_path_cached (self->path), &self_stbuf, 0, error)) return FALSE; - const gboolean root_is_sysroot = - (self->root_device == self_stbuf.st_dev && - self->root_inode == self_stbuf.st_ino); + const gboolean root_is_sysroot + = (self->root_device == self_stbuf.st_dev && self->root_inode == self_stbuf.st_ino); self->root_is_ostree_booted = (ostree_booted && root_is_sysroot); self->loadstate = OSTREE_SYSROOT_LOAD_STATE_INIT; @@ -1067,8 +1019,7 @@ ostree_sysroot_initialize (OstreeSysroot *self, /* Reload the staged deployment from the file in /run */ gboolean -_ostree_sysroot_reload_staged (OstreeSysroot *self, - GError **error) +_ostree_sysroot_reload_staged (OstreeSysroot *self, GError **error) { GLNX_AUTO_PREFIX_ERROR ("Loading staged deployment", error); if (!self->root_is_ostree_booted) @@ -1085,16 +1036,15 @@ _ostree_sysroot_reload_staged (OstreeSysroot *self, return FALSE; if (fd != -1) { - g_autoptr(GBytes) contents = ot_fd_readall_or_mmap (fd, 0, error); + g_autoptr (GBytes) contents = ot_fd_readall_or_mmap (fd, 0, error); if (!contents) return FALSE; - g_autoptr(GVariant) staged_deployment_data = - g_variant_new_from_bytes ((GVariantType*)"a{sv}", contents, TRUE); - g_autoptr(GVariantDict) staged_deployment_dict = - g_variant_dict_new (staged_deployment_data); + g_autoptr (GVariant) staged_deployment_data + = g_variant_new_from_bytes ((GVariantType *)"a{sv}", contents, TRUE); + g_autoptr (GVariantDict) staged_deployment_dict = g_variant_dict_new (staged_deployment_data); /* Parse it */ - g_autoptr(GVariant) target = NULL; + g_autoptr (GVariant) target = NULL; g_autofree char **kargs = NULL; g_autofree char **overlay_initrds = NULL; g_variant_dict_lookup (staged_deployment_dict, "target", "@a{sv}", &target); @@ -1102,8 +1052,8 @@ _ostree_sysroot_reload_staged (OstreeSysroot *self, g_variant_dict_lookup (staged_deployment_dict, "overlay-initrds", "^a&s", &overlay_initrds); if (target) { - g_autoptr(OstreeDeployment) staged = - _ostree_sysroot_deserialize_deployment_from_variant (target, error); + g_autoptr (OstreeDeployment) staged + = _ostree_sysroot_deserialize_deployment_from_variant (target, error); if (!staged) return FALSE; @@ -1130,9 +1080,8 @@ _ostree_sysroot_reload_staged (OstreeSysroot *self, * bootloader configs which are the source of truth. */ static gboolean -sysroot_load_from_bootloader_configs (OstreeSysroot *self, - GCancellable *cancellable, - GError **error) +sysroot_load_from_bootloader_configs (OstreeSysroot *self, GCancellable *cancellable, + GError **error) { struct stat stbuf; @@ -1141,16 +1090,17 @@ sysroot_load_from_bootloader_configs (OstreeSysroot *self, return FALSE; int subbootversion = 0; - if (!_ostree_sysroot_read_current_subbootversion (self, bootversion, &subbootversion, - cancellable, error)) + if (!_ostree_sysroot_read_current_subbootversion (self, bootversion, &subbootversion, cancellable, + error)) return FALSE; - g_autoptr(GPtrArray) boot_loader_configs = NULL; + g_autoptr (GPtrArray) boot_loader_configs = NULL; if (!_ostree_sysroot_read_boot_loader_configs (self, bootversion, &boot_loader_configs, cancellable, error)) return FALSE; - g_autoptr(GPtrArray) deployments = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref); + g_autoptr (GPtrArray) deployments + = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref); g_assert (boot_loader_configs); /* Pacify static analysis */ for (guint i = 0; i < boot_loader_configs->len; i++) @@ -1158,8 +1108,7 @@ sysroot_load_from_bootloader_configs (OstreeSysroot *self, OstreeBootconfigParser *config = boot_loader_configs->pdata[i]; /* Note this also sets self->booted_deployment */ - if (!list_deployments_process_one_boot_entry (self, config, deployments, - cancellable, error)) + if (!list_deployments_process_one_boot_entry (self, config, deployments, cancellable, error)) { g_clear_object (&self->booted_deployment); return FALSE; @@ -1168,17 +1117,21 @@ sysroot_load_from_bootloader_configs (OstreeSysroot *self, if (self->root_is_ostree_booted && !self->booted_deployment) { - if (!glnx_fstatat_allow_noent (self->sysroot_fd, "boot/loader", NULL, AT_SYMLINK_NOFOLLOW, error)) + if (!glnx_fstatat_allow_noent (self->sysroot_fd, "boot/loader", NULL, AT_SYMLINK_NOFOLLOW, + error)) return FALSE; if (errno == ENOENT) { - return glnx_throw (error, "Unexpected state: %s found, but no /boot/loader directory", OSTREE_PATH_BOOTED); + return glnx_throw (error, "Unexpected state: %s found, but no /boot/loader directory", + OSTREE_PATH_BOOTED); } else { - return glnx_throw (error, "Unexpected state: %s found and in / sysroot, but bootloader entry not found", OSTREE_PATH_BOOTED); + return glnx_throw ( + error, "Unexpected state: %s found and in / sysroot, but bootloader entry not found", + OSTREE_PATH_BOOTED); } - } + } if (!_ostree_sysroot_reload_staged (self, error)) return FALSE; @@ -1204,7 +1157,7 @@ sysroot_load_from_bootloader_configs (OstreeSysroot *self, * not physical. */ if (self->booted_deployment) - self->is_physical = FALSE; /* (the default, but explicit for clarity) */ + self->is_physical = FALSE; /* (the default, but explicit for clarity) */ /* Otherwise - check for /sysroot which should only exist in a deployment, * not in ${sysroot} (a metavariable for the real physical root). */ @@ -1237,10 +1190,8 @@ sysroot_load_from_bootloader_configs (OstreeSysroot *self, * Since: 2016.4 */ gboolean -ostree_sysroot_load_if_changed (OstreeSysroot *self, - gboolean *out_changed, - GCancellable *cancellable, - GError **error) +ostree_sysroot_load_if_changed (OstreeSysroot *self, gboolean *out_changed, + GCancellable *cancellable, GError **error) { GLNX_AUTO_PREFIX_ERROR ("loading sysroot", error); @@ -1258,8 +1209,8 @@ ostree_sysroot_load_if_changed (OstreeSysroot *self, if (!glnx_fstatat (self->sysroot_fd, "ostree/deploy", &stbuf, 0, error)) return FALSE; - if (self->loaded_ts.tv_sec == stbuf.st_mtim.tv_sec && - self->loaded_ts.tv_nsec == stbuf.st_mtim.tv_nsec) + if (self->loaded_ts.tv_sec == stbuf.st_mtim.tv_sec + && self->loaded_ts.tv_nsec == stbuf.st_mtim.tv_nsec) { if (out_changed) *out_changed = FALSE; @@ -1284,13 +1235,13 @@ ostree_sysroot_load_if_changed (OstreeSysroot *self, } int -ostree_sysroot_get_bootversion (OstreeSysroot *self) +ostree_sysroot_get_bootversion (OstreeSysroot *self) { return self->bootversion; } int -ostree_sysroot_get_subbootversion (OstreeSysroot *self) +ostree_sysroot_get_subbootversion (OstreeSysroot *self) { return self->subbootversion; } @@ -1304,7 +1255,7 @@ ostree_sysroot_get_subbootversion (OstreeSysroot *self) * Returns: (transfer none) (nullable): The currently booted deployment, or %NULL if none */ OstreeDeployment * -ostree_sysroot_get_booted_deployment (OstreeSysroot *self) +ostree_sysroot_get_booted_deployment (OstreeSysroot *self) { g_assert (self); g_assert (self->loadstate == OSTREE_SYSROOT_LOAD_STATE_LOADED); @@ -1312,7 +1263,6 @@ ostree_sysroot_get_booted_deployment (OstreeSysroot *self) return self->booted_deployment; } - /** * ostree_sysroot_require_booted_deployment: * @self: Sysroot @@ -1332,7 +1282,6 @@ ostree_sysroot_require_booted_deployment (OstreeSysroot *self, GError **error) return self->booted_deployment; } - /** * ostree_sysroot_get_staged_deployment: * @self: Sysroot @@ -1342,7 +1291,7 @@ ostree_sysroot_require_booted_deployment (OstreeSysroot *self, GError **error) * Since: 2018.5 */ OstreeDeployment * -ostree_sysroot_get_staged_deployment (OstreeSysroot *self) +ostree_sysroot_get_staged_deployment (OstreeSysroot *self) { g_assert (self->loadstate == OSTREE_SYSROOT_LOAD_STATE_LOADED); @@ -1356,7 +1305,7 @@ ostree_sysroot_get_staged_deployment (OstreeSysroot *self) * Returns: (element-type OstreeDeployment) (transfer container): Ordered list of deployments */ GPtrArray * -ostree_sysroot_get_deployments (OstreeSysroot *self) +ostree_sysroot_get_deployments (OstreeSysroot *self) { g_assert (self->loadstate == OSTREE_SYSROOT_LOAD_STATE_LOADED); @@ -1378,13 +1327,11 @@ ostree_sysroot_get_deployments (OstreeSysroot *self) * Returns: (transfer full) (not nullable): Path to deployment root directory, relative to sysroot */ char * -ostree_sysroot_get_deployment_dirpath (OstreeSysroot *self, - OstreeDeployment *deployment) +ostree_sysroot_get_deployment_dirpath (OstreeSysroot *self, OstreeDeployment *deployment) { - return g_strdup_printf ("ostree/deploy/%s/deploy/%s.%d", - ostree_deployment_get_osname (deployment), - ostree_deployment_get_csum (deployment), - ostree_deployment_get_deployserial (deployment)); + return g_strdup_printf ( + "ostree/deploy/%s/deploy/%s.%d", ostree_deployment_get_osname (deployment), + ostree_deployment_get_csum (deployment), ostree_deployment_get_deployserial (deployment)); } /** @@ -1395,8 +1342,7 @@ ostree_sysroot_get_deployment_dirpath (OstreeSysroot *self, * Returns: (transfer full): Path to deployment root directory */ GFile * -ostree_sysroot_get_deployment_directory (OstreeSysroot *self, - OstreeDeployment *deployment) +ostree_sysroot_get_deployment_directory (OstreeSysroot *self, OstreeDeployment *deployment) { g_autofree char *dirpath = ostree_sysroot_get_deployment_dirpath (self, deployment); return g_file_resolve_relative_path (self->path, dirpath); @@ -1409,11 +1355,10 @@ ostree_sysroot_get_deployment_directory (OstreeSysroot *self, * Returns: (transfer full): Path to deployment origin file */ GFile * -ostree_sysroot_get_deployment_origin_path (GFile *deployment_path) +ostree_sysroot_get_deployment_origin_path (GFile *deployment_path) { - g_autoptr(GFile) deployment_parent = g_file_get_parent (deployment_path); - return ot_gfile_resolve_path_printf (deployment_parent, - "%s.origin", + g_autoptr (GFile) deployment_parent = g_file_get_parent (deployment_path); + return ot_gfile_resolve_path_printf (deployment_parent, "%s.origin", gs_file_get_path_cached (deployment_path)); } @@ -1430,10 +1375,8 @@ ostree_sysroot_get_deployment_origin_path (GFile *deployment_path) * Returns: %TRUE on success, %FALSE otherwise */ gboolean -ostree_sysroot_get_repo (OstreeSysroot *self, - OstreeRepo **out_repo, - GCancellable *cancellable, - GError **error) +ostree_sysroot_get_repo (OstreeSysroot *self, OstreeRepo **out_repo, GCancellable *cancellable, + GError **error) { if (!ensure_repo (self, error)) return FALSE; @@ -1463,10 +1406,9 @@ ostree_sysroot_repo (OstreeSysroot *self) return self->repo; } -static OstreeBootloader* -_ostree_sysroot_new_bootloader_by_type ( - OstreeSysroot *sysroot, - OstreeCfgSysrootBootloaderOpt bl_type) +static OstreeBootloader * +_ostree_sysroot_new_bootloader_by_type (OstreeSysroot *sysroot, + OstreeCfgSysrootBootloaderOpt bl_type) { switch (bl_type) { @@ -1474,17 +1416,17 @@ _ostree_sysroot_new_bootloader_by_type ( /* No bootloader specified; do not query bootloaders to run. */ return NULL; case CFG_SYSROOT_BOOTLOADER_OPT_GRUB2: - return (OstreeBootloader*) _ostree_bootloader_grub2_new (sysroot); + return (OstreeBootloader *)_ostree_bootloader_grub2_new (sysroot); case CFG_SYSROOT_BOOTLOADER_OPT_SYSLINUX: - return (OstreeBootloader*) _ostree_bootloader_syslinux_new (sysroot); + return (OstreeBootloader *)_ostree_bootloader_syslinux_new (sysroot); case CFG_SYSROOT_BOOTLOADER_OPT_ABOOT: - return (OstreeBootloader*) _ostree_bootloader_aboot_new (sysroot); + return (OstreeBootloader *)_ostree_bootloader_aboot_new (sysroot); case CFG_SYSROOT_BOOTLOADER_OPT_UBOOT: - return (OstreeBootloader*) _ostree_bootloader_uboot_new (sysroot); + return (OstreeBootloader *)_ostree_bootloader_uboot_new (sysroot); case CFG_SYSROOT_BOOTLOADER_OPT_ZIPL: /* We never consider zipl as active by default, so it can only be created * if it's explicitly requested in the config */ - return (OstreeBootloader*) _ostree_bootloader_zipl_new (sysroot); + return (OstreeBootloader *)_ostree_bootloader_zipl_new (sysroot); case CFG_SYSROOT_BOOTLOADER_OPT_AUTO: /* "auto" is handled by ostree_sysroot_query_bootloader so we should * never get here: Fallthrough */ @@ -1496,23 +1438,22 @@ _ostree_sysroot_new_bootloader_by_type ( /** * ostree_sysroot_query_bootloader: * @sysroot: Sysroot - * @out_bootloader: (out) (transfer full) (optional) (nullable): Return location for bootloader, may be %NULL + * @out_bootloader: (out) (transfer full) (optional) (nullable): Return location for bootloader, + * may be %NULL * @cancellable: Cancellable * @error: Error */ gboolean -_ostree_sysroot_query_bootloader (OstreeSysroot *sysroot, - OstreeBootloader **out_bootloader, - GCancellable *cancellable, - GError **error) +_ostree_sysroot_query_bootloader (OstreeSysroot *sysroot, OstreeBootloader **out_bootloader, + GCancellable *cancellable, GError **error) { OstreeRepo *repo = ostree_sysroot_repo (sysroot); OstreeCfgSysrootBootloaderOpt bootloader_config = repo->bootloader; g_debug ("Using bootloader configuration: %s", - CFG_SYSROOT_BOOTLOADER_OPTS_STR[bootloader_config]); + CFG_SYSROOT_BOOTLOADER_OPTS_STR[bootloader_config]); - g_autoptr(OstreeBootloader) ret_loader = NULL; + g_autoptr (OstreeBootloader) ret_loader = NULL; if (bootloader_config == CFG_SYSROOT_BOOTLOADER_OPT_AUTO) { OstreeCfgSysrootBootloaderOpt probe[] = { @@ -1522,8 +1463,8 @@ _ostree_sysroot_query_bootloader (OstreeSysroot *sysroot, }; for (int i = 0; i < G_N_ELEMENTS (probe); i++) { - g_autoptr(OstreeBootloader) bl = _ostree_sysroot_new_bootloader_by_type ( - sysroot, probe[i]); + g_autoptr (OstreeBootloader) bl + = _ostree_sysroot_new_bootloader_by_type (sysroot, probe[i]); gboolean is_active = FALSE; if (!_ostree_bootloader_query (bl, &is_active, cancellable, error)) return FALSE; @@ -1537,12 +1478,11 @@ _ostree_sysroot_query_bootloader (OstreeSysroot *sysroot, else ret_loader = _ostree_sysroot_new_bootloader_by_type (sysroot, bootloader_config); - ot_transfer_out_value (out_bootloader, &ret_loader) - return TRUE; + ot_transfer_out_value (out_bootloader, &ret_loader) return TRUE; } char * -_ostree_sysroot_join_lines (GPtrArray *lines) +_ostree_sysroot_join_lines (GPtrArray *lines) { GString *buf = g_string_new (""); gboolean prev_was_empty = FALSE; @@ -1580,14 +1520,13 @@ _ostree_sysroot_join_lines (GPtrArray *lines) * Since: 2017.7 */ void -ostree_sysroot_query_deployments_for (OstreeSysroot *self, - const char *osname, - OstreeDeployment **out_pending, - OstreeDeployment **out_rollback) +ostree_sysroot_query_deployments_for (OstreeSysroot *self, const char *osname, + OstreeDeployment **out_pending, + OstreeDeployment **out_rollback) { g_assert (osname != NULL || self->booted_deployment != NULL); - g_autoptr(OstreeDeployment) ret_pending = NULL; - g_autoptr(OstreeDeployment) ret_rollback = NULL; + g_autoptr (OstreeDeployment) ret_pending = NULL; + g_autoptr (OstreeDeployment) ret_rollback = NULL; if (osname == NULL) osname = ostree_deployment_get_osname (self->booted_deployment); @@ -1599,11 +1538,11 @@ ostree_sysroot_query_deployments_for (OstreeSysroot *self, /* Ignore deployments not for this osname */ if (strcmp (ostree_deployment_get_osname (deployment), osname) != 0) - continue; + continue; /* Is this deployment booted? If so, note we're past the booted */ - if (self->booted_deployment != NULL && - ostree_deployment_equal (deployment, self->booted_deployment)) + if (self->booted_deployment != NULL + && ostree_deployment_equal (deployment, self->booted_deployment)) { found_booted = TRUE; continue; @@ -1620,7 +1559,6 @@ ostree_sysroot_query_deployments_for (OstreeSysroot *self, *out_rollback = g_steal_pointer (&ret_rollback); } - /** * ostree_sysroot_get_merge_deployment: * @self: Sysroot @@ -1632,8 +1570,7 @@ ostree_sysroot_query_deployments_for (OstreeSysroot *self, * Returns: (transfer full) (nullable): Configuration merge deployment */ OstreeDeployment * -ostree_sysroot_get_merge_deployment (OstreeSysroot *self, - const char *osname) +ostree_sysroot_get_merge_deployment (OstreeSysroot *self, const char *osname) { g_return_val_if_fail (osname != NULL || self->booted_deployment != NULL, NULL); @@ -1644,12 +1581,12 @@ ostree_sysroot_get_merge_deployment (OstreeSysroot *self, * merge the currently *booted* configuration, rather than the most * recently deployed. */ - if (self->booted_deployment && - g_strcmp0 (ostree_deployment_get_osname (self->booted_deployment), osname) == 0) - return g_object_ref (self->booted_deployment); + if (self->booted_deployment + && g_strcmp0 (ostree_deployment_get_osname (self->booted_deployment), osname) == 0) + return g_object_ref (self->booted_deployment); else { - g_autoptr(OstreeDeployment) pending = NULL; + g_autoptr (OstreeDeployment) pending = NULL; ostree_sysroot_query_deployments_for (self, osname, &pending, NULL); return g_steal_pointer (&pending); } @@ -1663,8 +1600,7 @@ ostree_sysroot_get_merge_deployment (OstreeSysroot *self, * Returns: (transfer full) (not nullable): A new config file which sets @refspec as an origin */ GKeyFile * -ostree_sysroot_origin_new_from_refspec (OstreeSysroot *self, - const char *refspec) +ostree_sysroot_origin_new_from_refspec (OstreeSysroot *self, const char *refspec) { GKeyFile *ret = g_key_file_new (); g_key_file_set_string (ret, "origin", "refspec", refspec); @@ -1684,8 +1620,7 @@ ostree_sysroot_origin_new_from_refspec (OstreeSysroot *self, * be released if @self is deallocated. */ gboolean -ostree_sysroot_lock (OstreeSysroot *self, - GError **error) +ostree_sysroot_lock (OstreeSysroot *self, GError **error) { if (!ensure_sysroot_fd (self, error)) return FALSE; @@ -1693,8 +1628,8 @@ ostree_sysroot_lock (OstreeSysroot *self, if (!_ostree_sysroot_ensure_writable (self, error)) return FALSE; - return glnx_make_lock_file (self->sysroot_fd, OSTREE_SYSROOT_LOCKFILE, - LOCK_EX, &self->lock, error); + return glnx_make_lock_file (self->sysroot_fd, OSTREE_SYSROOT_LOCKFILE, LOCK_EX, &self->lock, + error); } /** @@ -1712,9 +1647,7 @@ ostree_sysroot_lock (OstreeSysroot *self, * be released if @self is deallocated. */ gboolean -ostree_sysroot_try_lock (OstreeSysroot *self, - gboolean *out_acquired, - GError **error) +ostree_sysroot_try_lock (OstreeSysroot *self, gboolean *out_acquired, GError **error) { if (!ensure_sysroot_fd (self, error)) return FALSE; @@ -1723,9 +1656,9 @@ ostree_sysroot_try_lock (OstreeSysroot *self, return FALSE; /* Note use of LOCK_NB */ - g_autoptr(GError) local_error = NULL; - if (!glnx_make_lock_file (self->sysroot_fd, OSTREE_SYSROOT_LOCKFILE, - LOCK_EX | LOCK_NB, &self->lock, &local_error)) + g_autoptr (GError) local_error = NULL; + if (!glnx_make_lock_file (self->sysroot_fd, OSTREE_SYSROOT_LOCKFILE, LOCK_EX | LOCK_NB, + &self->lock, &local_error)) { if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { @@ -1754,16 +1687,13 @@ ostree_sysroot_try_lock (OstreeSysroot *self, * acquired. */ void -ostree_sysroot_unlock (OstreeSysroot *self) +ostree_sysroot_unlock (OstreeSysroot *self) { glnx_release_lock_file (&self->lock); } static void -lock_in_thread (GTask *task, - gpointer source, - gpointer task_data, - GCancellable *cancellable) +lock_in_thread (GTask *task, gpointer source, gpointer task_data, GCancellable *cancellable) { GError *local_error = NULL; OstreeSysroot *self = source; @@ -1774,7 +1704,7 @@ lock_in_thread (GTask *task, if (g_cancellable_set_error_if_cancelled (cancellable, &local_error)) ostree_sysroot_unlock (self); - out: +out: if (local_error) g_task_return_error (task, local_error); else @@ -1791,12 +1721,10 @@ lock_in_thread (GTask *task, * An asynchronous version of ostree_sysroot_lock(). */ void -ostree_sysroot_lock_async (OstreeSysroot *self, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +ostree_sysroot_lock_async (OstreeSysroot *self, GCancellable *cancellable, + GAsyncReadyCallback callback, gpointer user_data) { - 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_run_in_thread (task, lock_in_thread); } @@ -1809,12 +1737,10 @@ ostree_sysroot_lock_async (OstreeSysroot *self, * Call when ostree_sysroot_lock_async() is ready. */ gboolean -ostree_sysroot_lock_finish (OstreeSysroot *self, - GAsyncResult *result, - GError **error) +ostree_sysroot_lock_finish (OstreeSysroot *self, GAsyncResult *result, GError **error) { g_return_val_if_fail (g_task_is_valid (result, self), FALSE); - return g_task_propagate_boolean ((GTask*)result, error); + return g_task_propagate_boolean ((GTask *)result, error); } /** @@ -1831,10 +1757,8 @@ ostree_sysroot_lock_finish (OstreeSysroot *self, * Since: 2016.4 */ gboolean -ostree_sysroot_init_osname (OstreeSysroot *self, - const char *osname, - GCancellable *cancellable, - GError **error) +ostree_sysroot_init_osname (OstreeSysroot *self, const char *osname, GCancellable *cancellable, + GError **error) { if (!_ostree_sysroot_ensure_writable (self, error)) return FALSE; @@ -1915,33 +1839,29 @@ ostree_sysroot_init_osname (OstreeSysroot *self, * later, instead. */ gboolean -ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot, - const char *osname, - OstreeDeployment *new_deployment, - OstreeDeployment *merge_deployment, +ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot, const char *osname, + OstreeDeployment *new_deployment, + OstreeDeployment *merge_deployment, OstreeSysrootSimpleWriteDeploymentFlags flags, - GCancellable *cancellable, - GError **error) -{ - const gboolean postclean = - (flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NO_CLEAN) == 0; - const gboolean make_default = - !((flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NOT_DEFAULT) > 0); - const gboolean retain_pending = - (flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN_PENDING) > 0; - const gboolean retain_rollback = - (flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN_ROLLBACK) > 0; - gboolean retain = - (flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN) > 0; - - g_autoptr(GPtrArray) deployments = ostree_sysroot_get_deployments (sysroot); + GCancellable *cancellable, GError **error) +{ + const gboolean postclean = (flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NO_CLEAN) == 0; + const gboolean make_default + = !((flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NOT_DEFAULT) > 0); + const gboolean retain_pending + = (flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN_PENDING) > 0; + const gboolean retain_rollback + = (flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN_ROLLBACK) > 0; + gboolean retain = (flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN) > 0; + + g_autoptr (GPtrArray) deployments = ostree_sysroot_get_deployments (sysroot); OstreeDeployment *booted_deployment = ostree_sysroot_get_booted_deployment (sysroot); if (osname == NULL && booted_deployment) osname = ostree_deployment_get_osname (booted_deployment); gboolean added_new = FALSE; - g_autoptr(GPtrArray) new_deployments = g_ptr_array_new_with_free_func (g_object_unref); + g_autoptr (GPtrArray) new_deployments = g_ptr_array_new_with_free_func (g_object_unref); if (make_default) { g_ptr_array_add (new_deployments, g_object_ref (new_deployment)); @@ -1960,8 +1880,8 @@ ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot, for (guint i = 0; i < deployments->len; i++) { OstreeDeployment *deployment = deployments->pdata[i]; - const gboolean osname_matches = - (osname == NULL || g_str_equal (ostree_deployment_get_osname (deployment), osname)); + const gboolean osname_matches + = (osname == NULL || g_str_equal (ostree_deployment_get_osname (deployment), osname)); const gboolean is_booted = ostree_deployment_equal (deployment, booted_deployment); const gboolean is_merge = ostree_deployment_equal (deployment, merge_deployment); @@ -1982,11 +1902,8 @@ ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot, * - this is the merge or boot deployment, or * - we're keeping rollback deployments and this is a rollback deployment */ - if (retain - || ostree_deployment_is_pinned (deployment) - || !osname_matches - || (retain_pending && !passed_crossover) - || (is_booted || is_merge) + if (retain || ostree_deployment_is_pinned (deployment) || !osname_matches + || (retain_pending && !passed_crossover) || (is_booted || is_merge) || (retain_rollback && passed_crossover)) g_ptr_array_add (new_deployments, g_object_ref (deployment)); @@ -2012,11 +1929,8 @@ ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot, /* Deploy a copy of @target_deployment */ static gboolean -clone_deployment (OstreeSysroot *sysroot, - OstreeDeployment *target_deployment, - OstreeDeployment *merge_deployment, - GCancellable *cancellable, - GError **error) +clone_deployment (OstreeSysroot *sysroot, OstreeDeployment *target_deployment, + OstreeDeployment *merge_deployment, GCancellable *cancellable, GError **error) { /* Ensure we have a clean slate */ if (!ostree_sysroot_prepare_cleanup (sysroot, cancellable, error)) @@ -2024,28 +1938,28 @@ clone_deployment (OstreeSysroot *sysroot, /* Copy the bootloader config options */ OstreeBootconfigParser *bootconfig = ostree_deployment_get_bootconfig (merge_deployment); - g_auto(GStrv) previous_args = g_strsplit (ostree_bootconfig_parser_get (bootconfig, "options"), " ", -1); - g_autoptr(OstreeKernelArgs) kargs = ostree_kernel_args_new (); + g_auto (GStrv) previous_args + = g_strsplit (ostree_bootconfig_parser_get (bootconfig, "options"), " ", -1); + g_autoptr (OstreeKernelArgs) kargs = ostree_kernel_args_new (); ostree_kernel_args_append_argv (kargs, previous_args); /* Deploy the copy */ - g_autoptr(OstreeDeployment) new_deployment = NULL; - g_auto(GStrv) kargs_strv = ostree_kernel_args_to_strv (kargs); - if (!ostree_sysroot_deploy_tree (sysroot, - ostree_deployment_get_osname (target_deployment), + g_autoptr (OstreeDeployment) new_deployment = NULL; + g_auto (GStrv) kargs_strv = ostree_kernel_args_to_strv (kargs); + if (!ostree_sysroot_deploy_tree (sysroot, ostree_deployment_get_osname (target_deployment), ostree_deployment_get_csum (target_deployment), ostree_deployment_get_origin (target_deployment), - merge_deployment, kargs_strv, &new_deployment, - cancellable, error)) + merge_deployment, kargs_strv, &new_deployment, cancellable, + error)) return FALSE; /* Hotfixes push the deployment as rollback target, so it shouldn't * be the default. */ - if (!ostree_sysroot_simple_write_deployment (sysroot, ostree_deployment_get_osname (target_deployment), - new_deployment, merge_deployment, - OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NOT_DEFAULT, - cancellable, error)) + if (!ostree_sysroot_simple_write_deployment ( + sysroot, ostree_deployment_get_osname (target_deployment), new_deployment, + merge_deployment, OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NOT_DEFAULT, cancellable, + error)) return FALSE; return TRUE; @@ -2054,11 +1968,8 @@ clone_deployment (OstreeSysroot *sysroot, /* Do `mkdir()` followed by `chmod()` immediately afterwards to ensure `umask()` isn't * masking permissions where we don't want it to. Thus we avoid calling `umask()`, which * would affect the whole process. */ -static gboolean mkdir_unmasked (int dfd, - const char *path, - int mode, - GCancellable *cancellable, - GError **error) +static gboolean +mkdir_unmasked (int dfd, const char *path, int mode, GCancellable *cancellable, GError **error) { if (!glnx_shutil_mkdir_p_at (dfd, path, mode, cancellable, error)) return FALSE; @@ -2085,11 +1996,9 @@ static gboolean mkdir_unmasked (int dfd, * Since: 2016.4 */ gboolean -ostree_sysroot_deployment_unlock (OstreeSysroot *self, - OstreeDeployment *deployment, +ostree_sysroot_deployment_unlock (OstreeSysroot *self, OstreeDeployment *deployment, OstreeDeploymentUnlockedState unlocked_state, - GCancellable *cancellable, - GError **error) + GCancellable *cancellable, GError **error) { /* This function cannot re-lock */ g_return_val_if_fail (unlocked_state != OSTREE_DEPLOYMENT_UNLOCKED_NONE, FALSE); @@ -2099,8 +2008,8 @@ ostree_sysroot_deployment_unlock (OstreeSysroot *self, return glnx_throw (error, "Deployment is already in unlocked state: %s", ostree_deployment_unlocked_state_to_string (current_unlocked)); - g_autoptr(OstreeDeployment) merge_deployment = - ostree_sysroot_get_merge_deployment (self, ostree_deployment_get_osname (deployment)); + g_autoptr (OstreeDeployment) merge_deployment + = ostree_sysroot_get_merge_deployment (self, ostree_deployment_get_osname (deployment)); if (!merge_deployment) return glnx_throw (error, "No previous deployment to duplicate"); @@ -2112,8 +2021,7 @@ ostree_sysroot_deployment_unlock (OstreeSysroot *self, } /* Crack it open */ - if (!ostree_sysroot_deployment_set_mutable (self, deployment, TRUE, - cancellable, error)) + if (!ostree_sysroot_deployment_set_mutable (self, deployment, TRUE, cancellable, error)) return FALSE; g_autofree char *deployment_path = ostree_sysroot_get_deployment_dirpath (self, deployment); @@ -2121,20 +2029,22 @@ ostree_sysroot_deployment_unlock (OstreeSysroot *self, if (!glnx_opendirat (self->sysroot_fd, deployment_path, TRUE, &deployment_dfd, error)) return FALSE; - g_autoptr(OstreeSePolicy) sepolicy = ostree_sepolicy_new_at (deployment_dfd, cancellable, error); + g_autoptr (OstreeSePolicy) sepolicy = ostree_sepolicy_new_at (deployment_dfd, cancellable, error); if (!sepolicy) return FALSE; /* we want our /usr overlay to have the same permission bits as the one we'll shadow */ mode_t usr_mode; - { struct stat stbuf; + { + struct stat stbuf; if (!glnx_fstatat (deployment_dfd, "usr", &stbuf, 0, error)) return FALSE; usr_mode = stbuf.st_mode; } const char *ovl_options = NULL; - static const char hotfix_ovl_options[] = "lowerdir=usr,upperdir=.usr-ovl-upper,workdir=.usr-ovl-work"; + static const char hotfix_ovl_options[] + = "lowerdir=usr,upperdir=.usr-ovl-upper,workdir=.usr-ovl-work"; g_autofree char *unlock_ovldir = NULL; switch (unlocked_state) @@ -2166,10 +2076,12 @@ ostree_sysroot_deployment_unlock (OstreeSysroot *self, const char *development_ovl_work; /* Ensure that the directory is created with the same label as `/usr` */ - { g_auto(OstreeSepolicyFsCreatecon) con = { 0, }; + { + g_auto (OstreeSepolicyFsCreatecon) con = { + 0, + }; - if (!_ostree_sepolicy_preparefscreatecon (&con, sepolicy, - "/usr", usr_mode, error)) + if (!_ostree_sepolicy_preparefscreatecon (&con, sepolicy, "/usr", usr_mode, error)) return FALSE; if (g_mkdtemp_full (unlock_ovldir, 0755) == NULL) @@ -2228,7 +2140,7 @@ ostree_sysroot_deployment_unlock (OstreeSysroot *self, } } - g_autoptr(OstreeDeployment) deployment_clone = ostree_deployment_clone (deployment); + g_autoptr (OstreeDeployment) deployment_clone = ostree_deployment_clone (deployment); GKeyFile *origin_clone = ostree_deployment_get_origin (deployment_clone); /* Now, write out the flag saying what we did */ @@ -2240,18 +2152,18 @@ ostree_sysroot_deployment_unlock (OstreeSysroot *self, case OSTREE_DEPLOYMENT_UNLOCKED_HOTFIX: g_key_file_set_string (origin_clone, "origin", "unlocked", ostree_deployment_unlocked_state_to_string (unlocked_state)); - if (!ostree_sysroot_write_origin_file (self, deployment, origin_clone, - cancellable, error)) + if (!ostree_sysroot_write_origin_file (self, deployment, origin_clone, cancellable, error)) return FALSE; break; case OSTREE_DEPLOYMENT_UNLOCKED_DEVELOPMENT: case OSTREE_DEPLOYMENT_UNLOCKED_TRANSIENT: { - g_autofree char *devpath = - unlocked_state == OSTREE_DEPLOYMENT_UNLOCKED_DEVELOPMENT ? - _ostree_sysroot_get_runstate_path (deployment, _OSTREE_SYSROOT_DEPLOYMENT_RUNSTATE_FLAG_DEVELOPMENT) - : - _ostree_sysroot_get_runstate_path (deployment, _OSTREE_SYSROOT_DEPLOYMENT_RUNSTATE_FLAG_TRANSIENT); + g_autofree char *devpath + = unlocked_state == OSTREE_DEPLOYMENT_UNLOCKED_DEVELOPMENT + ? _ostree_sysroot_get_runstate_path ( + deployment, _OSTREE_SYSROOT_DEPLOYMENT_RUNSTATE_FLAG_DEVELOPMENT) + : _ostree_sysroot_get_runstate_path ( + deployment, _OSTREE_SYSROOT_DEPLOYMENT_RUNSTATE_FLAG_TRANSIENT); g_autofree char *devpath_parent = dirname (g_strdup (devpath)); if (!glnx_shutil_mkdir_p_at (AT_FDCWD, devpath_parent, 0755, cancellable, error)) @@ -2293,10 +2205,8 @@ ostree_sysroot_deployment_unlock (OstreeSysroot *self, * Since: 2018.3 */ gboolean -ostree_sysroot_deployment_set_pinned (OstreeSysroot *self, - OstreeDeployment *deployment, - gboolean is_pinned, - GError **error) +ostree_sysroot_deployment_set_pinned (OstreeSysroot *self, OstreeDeployment *deployment, + gboolean is_pinned, GError **error) { const gboolean current_pin = ostree_deployment_is_pinned (deployment); if (is_pinned == current_pin) @@ -2305,7 +2215,7 @@ ostree_sysroot_deployment_set_pinned (OstreeSysroot *self, if (ostree_deployment_is_staged (deployment)) return glnx_throw (error, "Cannot pin staged deployment"); - g_autoptr(OstreeDeployment) deployment_clone = ostree_deployment_clone (deployment); + g_autoptr (OstreeDeployment) deployment_clone = ostree_deployment_clone (deployment); GKeyFile *origin_clone = ostree_deployment_get_origin (deployment_clone); if (is_pinned) diff --git a/src/libostree/ostree-sysroot.h b/src/libostree/ostree-sysroot.h index b159020d..e84007a9 100644 --- a/src/libostree/ostree-sysroot.h +++ b/src/libostree/ostree-sysroot.h @@ -19,8 +19,8 @@ #pragma once -#include "ostree-repo.h" #include "ostree-deployment.h" +#include "ostree-repo.h" G_BEGIN_DECLS @@ -32,26 +32,25 @@ G_BEGIN_DECLS */ #define OSTREE_PATH_BOOTED "/run/ostree-booted" -#define OSTREE_TYPE_SYSROOT ostree_sysroot_get_type() -#define OSTREE_SYSROOT(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSTREE_TYPE_SYSROOT, OstreeSysroot)) -#define OSTREE_IS_SYSROOT(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSTREE_TYPE_SYSROOT)) +#define OSTREE_TYPE_SYSROOT ostree_sysroot_get_type () +#define OSTREE_SYSROOT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSTREE_TYPE_SYSROOT, OstreeSysroot)) +#define OSTREE_IS_SYSROOT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSTREE_TYPE_SYSROOT)) _OSTREE_PUBLIC GType ostree_sysroot_get_type (void); _OSTREE_PUBLIC -OstreeSysroot* ostree_sysroot_new (GFile *path); +OstreeSysroot *ostree_sysroot_new (GFile *path); _OSTREE_PUBLIC -OstreeSysroot* ostree_sysroot_new_default (void); +OstreeSysroot *ostree_sysroot_new_default (void); _OSTREE_PUBLIC -void ostree_sysroot_set_mount_namespace_in_use (OstreeSysroot *self); +void ostree_sysroot_set_mount_namespace_in_use (OstreeSysroot *self); _OSTREE_PUBLIC -gboolean ostree_sysroot_initialize_with_mount_namespace (OstreeSysroot *self, GCancellable *cancellable, GError **error); +gboolean ostree_sysroot_initialize_with_mount_namespace (OstreeSysroot *self, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC GFile *ostree_sysroot_get_path (OstreeSysroot *self); @@ -63,135 +62,103 @@ _OSTREE_PUBLIC int ostree_sysroot_get_fd (OstreeSysroot *self); _OSTREE_PUBLIC -gboolean ostree_sysroot_initialize (OstreeSysroot *self, - GError **error); +gboolean ostree_sysroot_initialize (OstreeSysroot *self, GError **error); _OSTREE_PUBLIC -gboolean ostree_sysroot_load (OstreeSysroot *self, - GCancellable *cancellable, - GError **error); +gboolean ostree_sysroot_load (OstreeSysroot *self, GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_sysroot_load_if_changed (OstreeSysroot *self, - gboolean *out_changed, - GCancellable *cancellable, - GError **error); +gboolean ostree_sysroot_load_if_changed (OstreeSysroot *self, gboolean *out_changed, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -void ostree_sysroot_unload (OstreeSysroot *self); +void ostree_sysroot_unload (OstreeSysroot *self); _OSTREE_PUBLIC -gboolean ostree_sysroot_ensure_initialized (OstreeSysroot *self, - GCancellable *cancellable, - GError **error); +gboolean ostree_sysroot_ensure_initialized (OstreeSysroot *self, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -int ostree_sysroot_get_bootversion (OstreeSysroot *self); +int ostree_sysroot_get_bootversion (OstreeSysroot *self); _OSTREE_PUBLIC -int ostree_sysroot_get_subbootversion (OstreeSysroot *self); +int ostree_sysroot_get_subbootversion (OstreeSysroot *self); _OSTREE_PUBLIC -GPtrArray *ostree_sysroot_get_deployments (OstreeSysroot *self); +GPtrArray *ostree_sysroot_get_deployments (OstreeSysroot *self); _OSTREE_PUBLIC OstreeDeployment *ostree_sysroot_get_booted_deployment (OstreeSysroot *self); _OSTREE_PUBLIC -OstreeDeployment * -ostree_sysroot_require_booted_deployment (OstreeSysroot *self, GError **error); +OstreeDeployment *ostree_sysroot_require_booted_deployment (OstreeSysroot *self, GError **error); _OSTREE_PUBLIC OstreeDeployment *ostree_sysroot_get_staged_deployment (OstreeSysroot *self); _OSTREE_PUBLIC -GFile *ostree_sysroot_get_deployment_directory (OstreeSysroot *self, - OstreeDeployment *deployment); +GFile *ostree_sysroot_get_deployment_directory (OstreeSysroot *self, OstreeDeployment *deployment); _OSTREE_PUBLIC -char *ostree_sysroot_get_deployment_dirpath (OstreeSysroot *self, - OstreeDeployment *deployment); +char *ostree_sysroot_get_deployment_dirpath (OstreeSysroot *self, OstreeDeployment *deployment); _OSTREE_PUBLIC -GFile * ostree_sysroot_get_deployment_origin_path (GFile *deployment_path); +GFile *ostree_sysroot_get_deployment_origin_path (GFile *deployment_path); _OSTREE_PUBLIC -gboolean ostree_sysroot_lock (OstreeSysroot *self, GError **error); +gboolean ostree_sysroot_lock (OstreeSysroot *self, GError **error); _OSTREE_PUBLIC -gboolean ostree_sysroot_try_lock (OstreeSysroot *self, - gboolean *out_acquired, - GError **error); +gboolean ostree_sysroot_try_lock (OstreeSysroot *self, gboolean *out_acquired, GError **error); _OSTREE_PUBLIC -void ostree_sysroot_lock_async (OstreeSysroot *self, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); +void ostree_sysroot_lock_async (OstreeSysroot *self, GCancellable *cancellable, + GAsyncReadyCallback callback, gpointer user_data); _OSTREE_PUBLIC -gboolean ostree_sysroot_lock_finish (OstreeSysroot *self, - GAsyncResult *result, - GError **error); +gboolean ostree_sysroot_lock_finish (OstreeSysroot *self, GAsyncResult *result, GError **error); _OSTREE_PUBLIC -void ostree_sysroot_unlock (OstreeSysroot *self); +void ostree_sysroot_unlock (OstreeSysroot *self); _OSTREE_PUBLIC -gboolean ostree_sysroot_init_osname (OstreeSysroot *self, - const char *osname, - GCancellable *cancellable, - GError **error); +gboolean ostree_sysroot_init_osname (OstreeSysroot *self, const char *osname, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_sysroot_cleanup (OstreeSysroot *self, - GCancellable *cancellable, - GError **error); +gboolean ostree_sysroot_cleanup (OstreeSysroot *self, GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_sysroot_prepare_cleanup (OstreeSysroot *self, - GCancellable *cancellable, - GError **error); +gboolean ostree_sysroot_prepare_cleanup (OstreeSysroot *self, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean -ostree_sysroot_cleanup_prune_repo (OstreeSysroot *sysroot, - OstreeRepoPruneOptions *options, - gint *out_objects_total, - gint *out_objects_pruned, - guint64 *out_pruned_object_size_total, - GCancellable *cancellable, - GError **error); +gboolean ostree_sysroot_cleanup_prune_repo (OstreeSysroot *sysroot, OstreeRepoPruneOptions *options, + gint *out_objects_total, gint *out_objects_pruned, + guint64 *out_pruned_object_size_total, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_sysroot_write_origin_file (OstreeSysroot *sysroot, - OstreeDeployment *deployment, - GKeyFile *new_origin, - GCancellable *cancellable, - GError **error); +gboolean ostree_sysroot_write_origin_file (OstreeSysroot *sysroot, OstreeDeployment *deployment, + GKeyFile *new_origin, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -OstreeRepo * ostree_sysroot_repo (OstreeSysroot *self); +OstreeRepo *ostree_sysroot_repo (OstreeSysroot *self); _OSTREE_PUBLIC -gboolean ostree_sysroot_get_repo (OstreeSysroot *self, - OstreeRepo **out_repo, - GCancellable *cancellable, - GError **error); +gboolean ostree_sysroot_get_repo (OstreeSysroot *self, OstreeRepo **out_repo, + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_sysroot_deployment_set_kargs (OstreeSysroot *self, - OstreeDeployment *deployment, - char **new_kargs, - GCancellable *cancellable, - GError **error); +gboolean ostree_sysroot_deployment_set_kargs (OstreeSysroot *self, OstreeDeployment *deployment, + char **new_kargs, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_sysroot_deployment_set_kargs_in_place (OstreeSysroot *self, - OstreeDeployment *deployment, - char *kargs_str, - GCancellable *cancellable, - GError **error); +gboolean ostree_sysroot_deployment_set_kargs_in_place (OstreeSysroot *self, + OstreeDeployment *deployment, + char *kargs_str, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_sysroot_write_deployments (OstreeSysroot *self, - GPtrArray *new_deployments, - GCancellable *cancellable, - GError **error); +gboolean ostree_sysroot_write_deployments (OstreeSysroot *self, GPtrArray *new_deployments, + GCancellable *cancellable, GError **error); -typedef struct { +typedef struct +{ gboolean do_postclean; gboolean disable_auto_early_prune; gboolean unused_bools[7]; @@ -200,20 +167,17 @@ typedef struct { } OstreeSysrootWriteDeploymentsOpts; _OSTREE_PUBLIC -gboolean ostree_sysroot_write_deployments_with_options (OstreeSysroot *self, - GPtrArray *new_deployments, +gboolean ostree_sysroot_write_deployments_with_options (OstreeSysroot *self, + GPtrArray *new_deployments, OstreeSysrootWriteDeploymentsOpts *opts, - GCancellable *cancellable, - GError **error); + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_sysroot_stage_overlay_initrd (OstreeSysroot *self, - int fd, - char **out_checksum, - GCancellable *cancellable, - GError **error); +gboolean ostree_sysroot_stage_overlay_initrd (OstreeSysroot *self, int fd, char **out_checksum, + GCancellable *cancellable, GError **error); -typedef struct { +typedef struct +{ gboolean unused_bools[8]; int unused_ints[8]; char **override_kernel_argv; @@ -222,86 +186,62 @@ typedef struct { } OstreeSysrootDeployTreeOpts; _OSTREE_PUBLIC -gboolean ostree_sysroot_deploy_tree (OstreeSysroot *self, - const char *osname, - const char *revision, - GKeyFile *origin, - OstreeDeployment *provided_merge_deployment, - char **override_kernel_argv, +gboolean ostree_sysroot_deploy_tree (OstreeSysroot *self, const char *osname, const char *revision, + GKeyFile *origin, OstreeDeployment *provided_merge_deployment, + char **override_kernel_argv, OstreeDeployment **out_new_deployment, - GCancellable *cancellable, - GError **error); + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_sysroot_deploy_tree_with_options (OstreeSysroot *self, - const char *osname, - const char *revision, - GKeyFile *origin, - OstreeDeployment *provided_merge_deployment, +gboolean ostree_sysroot_deploy_tree_with_options (OstreeSysroot *self, const char *osname, + const char *revision, GKeyFile *origin, + OstreeDeployment *provided_merge_deployment, OstreeSysrootDeployTreeOpts *opts, OstreeDeployment **out_new_deployment, - GCancellable *cancellable, - GError **error); + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_sysroot_stage_tree (OstreeSysroot *self, - const char *osname, - const char *revision, - GKeyFile *origin, - OstreeDeployment *merge_deployment, - char **override_kernel_argv, +gboolean ostree_sysroot_stage_tree (OstreeSysroot *self, const char *osname, const char *revision, + GKeyFile *origin, OstreeDeployment *merge_deployment, + char **override_kernel_argv, OstreeDeployment **out_new_deployment, - GCancellable *cancellable, - GError **error); + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_sysroot_stage_tree_with_options (OstreeSysroot *self, - const char *osname, - const char *revision, - GKeyFile *origin, - OstreeDeployment *merge_deployment, +gboolean ostree_sysroot_stage_tree_with_options (OstreeSysroot *self, const char *osname, + const char *revision, GKeyFile *origin, + OstreeDeployment *merge_deployment, OstreeSysrootDeployTreeOpts *opts, OstreeDeployment **out_new_deployment, - GCancellable *cancellable, - GError **error); - + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -gboolean ostree_sysroot_deployment_set_mutable (OstreeSysroot *self, - OstreeDeployment *deployment, - gboolean is_mutable, - GCancellable *cancellable, - GError **error); +gboolean ostree_sysroot_deployment_set_mutable (OstreeSysroot *self, OstreeDeployment *deployment, + gboolean is_mutable, GCancellable *cancellable, + GError **error); _OSTREE_PUBLIC -gboolean ostree_sysroot_deployment_set_pinned (OstreeSysroot *self, - OstreeDeployment *deployment, - gboolean is_pinned, - GError **error); +gboolean ostree_sysroot_deployment_set_pinned (OstreeSysroot *self, OstreeDeployment *deployment, + gboolean is_pinned, GError **error); _OSTREE_PUBLIC -gboolean ostree_sysroot_deployment_unlock (OstreeSysroot *self, - OstreeDeployment *deployment, +gboolean ostree_sysroot_deployment_unlock (OstreeSysroot *self, OstreeDeployment *deployment, OstreeDeploymentUnlockedState unlocked_state, - GCancellable *cancellable, - GError **error); + GCancellable *cancellable, GError **error); _OSTREE_PUBLIC -void ostree_sysroot_query_deployments_for (OstreeSysroot *self, - const char *osname, - OstreeDeployment **out_pending, - OstreeDeployment **out_rollback); +void ostree_sysroot_query_deployments_for (OstreeSysroot *self, const char *osname, + OstreeDeployment **out_pending, + OstreeDeployment **out_rollback); _OSTREE_PUBLIC -OstreeDeployment *ostree_sysroot_get_merge_deployment (OstreeSysroot *self, - const char *osname); - +OstreeDeployment *ostree_sysroot_get_merge_deployment (OstreeSysroot *self, const char *osname); _OSTREE_PUBLIC -GKeyFile *ostree_sysroot_origin_new_from_refspec (OstreeSysroot *self, - const char *refspec); +GKeyFile *ostree_sysroot_origin_new_from_refspec (OstreeSysroot *self, const char *refspec); -typedef enum { +typedef enum +{ OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NONE = 0, OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN = (1 << 0), OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NOT_DEFAULT = (1 << 1), @@ -311,12 +251,10 @@ typedef enum { } OstreeSysrootSimpleWriteDeploymentFlags; _OSTREE_PUBLIC -gboolean ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot, - const char *osname, - OstreeDeployment *new_deployment, - OstreeDeployment *merge_deployment, +gboolean ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot, const char *osname, + OstreeDeployment *new_deployment, + OstreeDeployment *merge_deployment, OstreeSysrootSimpleWriteDeploymentFlags flags, - GCancellable *cancellable, - GError **error); + GCancellable *cancellable, GError **error); G_END_DECLS diff --git a/src/libostree/ostree-tls-cert-interaction-private.h b/src/libostree/ostree-tls-cert-interaction-private.h index 58db65a4..0aca097a 100644 --- a/src/libostree/ostree-tls-cert-interaction-private.h +++ b/src/libostree/ostree-tls-cert-interaction-private.h @@ -24,20 +24,25 @@ G_BEGIN_DECLS -#define OSTREE_TYPE_TLS_CERT_INTERACTION (_ostree_tls_cert_interaction_get_type ()) -#define OSTREE_TLS_CERT_INTERACTION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_TLS_CERT_INTERACTION, OstreeTlsCertInteraction)) -#define OSTREE_TLS_CERT_INTERACTION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), OSTREE_TYPE_TLS_CERT_INTERACTION, OstreeTlsCertInteractionClass)) -#define OSTREE_IS_TLS_CERT_INTERACTION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_TLS_CERT_INTERACTION)) -#define OSTREE_IS_TLS_CERT_INTERACTION_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_TLS_CERT_INTERACTION)) -#define OSTREE_TLS_CERT_INTERACTION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_TLS_CERT_INTERACTION, OstreeTlsCertInteractionClass)) - -typedef struct _OstreeTlsCertInteraction OstreeTlsCertInteraction; -typedef struct _OstreeTlsCertInteractionClass OstreeTlsCertInteractionClass; -G_DEFINE_AUTOPTR_CLEANUP_FUNC(OstreeTlsCertInteraction, g_object_unref) - -GType _ostree_tls_cert_interaction_get_type (void) G_GNUC_CONST; - -OstreeTlsCertInteraction * _ostree_tls_cert_interaction_new (const char *cert_path, - const char *key_path); +#define OSTREE_TYPE_TLS_CERT_INTERACTION (_ostree_tls_cert_interaction_get_type ()) +#define OSTREE_TLS_CERT_INTERACTION(o) \ + (G_TYPE_CHECK_INSTANCE_CAST ((o), OSTREE_TYPE_TLS_CERT_INTERACTION, OstreeTlsCertInteraction)) +#define OSTREE_TLS_CERT_INTERACTION_CLASS(k) \ + (G_TYPE_CHECK_CLASS_CAST ((k), OSTREE_TYPE_TLS_CERT_INTERACTION, OstreeTlsCertInteractionClass)) +#define OSTREE_IS_TLS_CERT_INTERACTION(o) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((o), OSTREE_TYPE_TLS_CERT_INTERACTION)) +#define OSTREE_IS_TLS_CERT_INTERACTION_CLASS(k) \ + (G_TYPE_CHECK_CLASS_TYPE ((k), OSTREE_TYPE_TLS_CERT_INTERACTION)) +#define OSTREE_TLS_CERT_INTERACTION_GET_CLASS(o) \ + (G_TYPE_INSTANCE_GET_CLASS ((o), OSTREE_TYPE_TLS_CERT_INTERACTION, OstreeTlsCertInteractionClass)) + +typedef struct _OstreeTlsCertInteraction OstreeTlsCertInteraction; +typedef struct _OstreeTlsCertInteractionClass OstreeTlsCertInteractionClass; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeTlsCertInteraction, g_object_unref) + +GType _ostree_tls_cert_interaction_get_type (void) G_GNUC_CONST; + +OstreeTlsCertInteraction *_ostree_tls_cert_interaction_new (const char *cert_path, + const char *key_path); G_END_DECLS diff --git a/src/libostree/ostree-tls-cert-interaction.c b/src/libostree/ostree-tls-cert-interaction.c index 7614244e..25d84ea3 100644 --- a/src/libostree/ostree-tls-cert-interaction.c +++ b/src/libostree/ostree-tls-cert-interaction.c @@ -40,13 +40,10 @@ struct _OstreeTlsCertInteractionClass G_DEFINE_TYPE (OstreeTlsCertInteraction, _ostree_tls_cert_interaction, G_TYPE_TLS_INTERACTION); static GTlsInteractionResult -request_certificate (GTlsInteraction *interaction, - GTlsConnection *connection, - GTlsCertificateRequestFlags flags, - GCancellable *cancellable, - GError **error) +request_certificate (GTlsInteraction *interaction, GTlsConnection *connection, + GTlsCertificateRequestFlags flags, GCancellable *cancellable, GError **error) { - OstreeTlsCertInteraction *self = (OstreeTlsCertInteraction*)interaction; + OstreeTlsCertInteraction *self = (OstreeTlsCertInteraction *)interaction; if (!self->cert) { @@ -72,8 +69,7 @@ _ostree_tls_cert_interaction_class_init (OstreeTlsCertInteractionClass *klass) } OstreeTlsCertInteraction * -_ostree_tls_cert_interaction_new (const char *cert_path, - const char *key_path) +_ostree_tls_cert_interaction_new (const char *cert_path, const char *key_path) { OstreeTlsCertInteraction *self = g_object_new (OSTREE_TYPE_TLS_CERT_INTERACTION, NULL); self->cert_path = g_strdup (cert_path); diff --git a/src/libostree/ostree-varint.c b/src/libostree/ostree-varint.c index 35e306d0..fd7c81f9 100644 --- a/src/libostree/ostree-varint.c +++ b/src/libostree/ostree-varint.c @@ -49,7 +49,7 @@ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + */ #include "config.h" @@ -67,10 +67,7 @@ static const int max_varint_bytes = 10; * Returns: %TRUE on success, %FALSE on end of stream */ gboolean -_ostree_read_varuint64 (const guint8 *buf, - gsize buflen, - guint64 *out_value, - gsize *bytes_read) +_ostree_read_varuint64 (const guint8 *buf, gsize buflen, guint64 *out_value, gsize *bytes_read) { guint64 result = 0; int count = 0; @@ -90,7 +87,8 @@ _ostree_read_varuint64 (const guint8 *buf, buf++; buflen--; ++count; - } while (b & 0x80); + } + while (b & 0x80); *bytes_read = count; *out_value = result; @@ -126,58 +124,105 @@ _ostree_write_varuint64 (GString *buf, guint64 n) * we probably don't want to optimize for small numbers anyway. Thus, * we end up with a hardcoded binary search tree... */ - if (part2 == 0) { - if (part1 == 0) { - if (part0 < (1 << 14)) { - if (part0 < (1 << 7)) { - size = 1; goto size1; - } else { - size = 2; goto size2; + if (part2 == 0) + { + if (part1 == 0) + { + if (part0 < (1 << 14)) + { + if (part0 < (1 << 7)) + { + size = 1; + goto size1; + } + else + { + size = 2; + goto size2; + } + } + else + { + if (part0 < (1 << 21)) + { + size = 3; + goto size3; + } + else + { + size = 4; + goto size4; + } + } } - } else { - if (part0 < (1 << 21)) { - size = 3; goto size3; - } else { - size = 4; goto size4; + else + { + if (part1 < (1 << 14)) + { + if (part1 < (1 << 7)) + { + size = 5; + goto size5; + } + else + { + size = 6; + goto size6; + } + } + else + { + if (part1 < (1 << 21)) + { + size = 7; + goto size7; + } + else + { + size = 8; + goto size8; + } + } } - } - } else { - if (part1 < (1 << 14)) { - if (part1 < (1 << 7)) { - size = 5; goto size5; - } else { - size = 6; goto size6; + } + else + { + if (part2 < (1 << 7)) + { + size = 9; + goto size9; } - } else { - if (part1 < (1 << 21)) { - size = 7; goto size7; - } else { - size = 8; goto size8; + else + { + size = 10; + goto size10; } - } - } - } else { - if (part2 < (1 << 7)) { - size = 9; goto size9; - } else { - size = 10; goto size10; } - } g_assert_not_reached (); - size10: target[9] = (guint8)((part2 >> 7) | 0x80); - size9 : target[8] = (guint8)((part2 ) | 0x80); - size8 : target[7] = (guint8)((part1 >> 21) | 0x80); - size7 : target[6] = (guint8)((part1 >> 14) | 0x80); - size6 : target[5] = (guint8)((part1 >> 7) | 0x80); - size5 : target[4] = (guint8)((part1 ) | 0x80); - size4 : target[3] = (guint8)((part0 >> 21) | 0x80); - size3 : target[2] = (guint8)((part0 >> 14) | 0x80); - size2 : target[1] = (guint8)((part0 >> 7) | 0x80); - size1 : target[0] = (guint8)((part0 ) | 0x80); - - target[size-1] &= 0x7F; +size10: + target[9] = (guint8)((part2 >> 7) | 0x80); +size9: + target[8] = (guint8)((part2) | 0x80); +size8: + target[7] = (guint8)((part1 >> 21) | 0x80); +size7: + target[6] = (guint8)((part1 >> 14) | 0x80); +size6: + target[5] = (guint8)((part1 >> 7) | 0x80); +size5: + target[4] = (guint8)((part1) | 0x80); +size4: + target[3] = (guint8)((part0 >> 21) | 0x80); +size3: + target[2] = (guint8)((part0 >> 14) | 0x80); +size2: + target[1] = (guint8)((part0 >> 7) | 0x80); +size1: + target[0] = (guint8)((part0) | 0x80); + + target[size - 1] &= 0x7F; for (i = 0; i < size; i++) g_string_append_c (buf, target[i]); diff --git a/src/libostree/ostree-varint.h b/src/libostree/ostree-varint.h index db232210..4783c784 100644 --- a/src/libostree/ostree-varint.h +++ b/src/libostree/ostree-varint.h @@ -23,10 +23,8 @@ G_BEGIN_DECLS -gboolean _ostree_read_varuint64 (const guint8 *buf, - gsize buflen, - guint64 *out_value, - gsize *bytes_read); +gboolean _ostree_read_varuint64 (const guint8 *buf, gsize buflen, guint64 *out_value, + gsize *bytes_read); void _ostree_write_varuint64 (GString *buf, guint64 n); diff --git a/src/libotutil/ot-checksum-instream.c b/src/libotutil/ot-checksum-instream.c index b48b2360..31286a50 100644 --- a/src/libotutil/ot-checksum-instream.c +++ b/src/libotutil/ot-checksum-instream.c @@ -23,22 +23,20 @@ #include "ot-checksum-instream.h" #include "ot-checksum-utils.h" -struct _OtChecksumInstreamPrivate { +struct _OtChecksumInstreamPrivate +{ OtChecksum checksum; }; G_DEFINE_TYPE_WITH_PRIVATE (OtChecksumInstream, ot_checksum_instream, G_TYPE_FILTER_INPUT_STREAM) -static gssize ot_checksum_instream_read (GInputStream *stream, - void *buffer, - gsize count, - GCancellable *cancellable, - GError **error); +static gssize ot_checksum_instream_read (GInputStream *stream, void *buffer, gsize count, + GCancellable *cancellable, GError **error); static void ot_checksum_instream_finalize (GObject *object) { - OtChecksumInstream *self = (OtChecksumInstream*)object; + OtChecksumInstream *self = (OtChecksumInstream *)object; ot_checksum_clear (&self->priv->checksum); @@ -62,26 +60,21 @@ ot_checksum_instream_init (OtChecksumInstream *self) } OtChecksumInstream * -ot_checksum_instream_new (GInputStream *base, - GChecksumType checksum_type) +ot_checksum_instream_new (GInputStream *base, GChecksumType checksum_type) { return ot_checksum_instream_new_with_start (base, checksum_type, NULL, 0); } /* Initialize a checksum stream with starting state from data */ OtChecksumInstream * -ot_checksum_instream_new_with_start (GInputStream *base, - GChecksumType checksum_type, - const guint8 *buf, - size_t len) +ot_checksum_instream_new_with_start (GInputStream *base, GChecksumType checksum_type, + const guint8 *buf, size_t len) { OtChecksumInstream *stream; g_return_val_if_fail (G_IS_INPUT_STREAM (base), NULL); - stream = g_object_new (OT_TYPE_CHECKSUM_INSTREAM, - "base-stream", base, - NULL); + stream = g_object_new (OT_TYPE_CHECKSUM_INSTREAM, "base-stream", base, NULL); /* For now */ g_assert (checksum_type == G_CHECKSUM_SHA256); @@ -89,25 +82,18 @@ ot_checksum_instream_new_with_start (GInputStream *base, if (buf) ot_checksum_update (&stream->priv->checksum, buf, len); - return (OtChecksumInstream*) (stream); + return (OtChecksumInstream *)(stream); } static gssize -ot_checksum_instream_read (GInputStream *stream, - void *buffer, - gsize count, - GCancellable *cancellable, - GError **error) +ot_checksum_instream_read (GInputStream *stream, void *buffer, gsize count, + GCancellable *cancellable, GError **error) { - OtChecksumInstream *self = (OtChecksumInstream*) stream; - GFilterInputStream *fself = (GFilterInputStream*) self; + OtChecksumInstream *self = (OtChecksumInstream *)stream; + GFilterInputStream *fself = (GFilterInputStream *)self; gssize res = -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) ot_checksum_update (&self->priv->checksum, buffer, res); @@ -117,7 +103,7 @@ ot_checksum_instream_read (GInputStream *stream, char * ot_checksum_instream_get_string (OtChecksumInstream *stream) { - char buf[_OSTREE_SHA256_STRING_LEN+1]; - ot_checksum_get_hexdigest (&stream->priv->checksum, buf, sizeof(buf)); - return g_strndup (buf, sizeof(buf)); + char buf[_OSTREE_SHA256_STRING_LEN + 1]; + ot_checksum_get_hexdigest (&stream->priv->checksum, buf, sizeof (buf)); + return g_strndup (buf, sizeof (buf)); } diff --git a/src/libotutil/ot-checksum-instream.h b/src/libotutil/ot-checksum-instream.h index 643e4962..096d43c3 100644 --- a/src/libotutil/ot-checksum-instream.h +++ b/src/libotutil/ot-checksum-instream.h @@ -24,16 +24,20 @@ G_BEGIN_DECLS -#define OT_TYPE_CHECKSUM_INSTREAM (ot_checksum_instream_get_type ()) -#define OT_CHECKSUM_INSTREAM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), OT_TYPE_CHECKSUM_INPUT_STREAM, OtChecksumInstream)) -#define OT_CHECKSUM_INSTREAM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), OT_TYPE_CHECKSUM_INPUT_STREAM, OtChecksumInstreamClass)) -#define OT_IS_CHECKSUM_INSTREAM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OT_TYPE_CHECKSUM_INPUT_STREAM)) -#define OT_IS_CHECKSUM_INSTREAM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), OT_TYPE_CHECKSUM_INPUT_STREAM)) -#define OT_CHECKSUM_INSTREAM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), OT_TYPE_CHECKSUM_INPUT_STREAM, OtChecksumInstreamClass)) +#define OT_TYPE_CHECKSUM_INSTREAM (ot_checksum_instream_get_type ()) +#define OT_CHECKSUM_INSTREAM(o) \ + (G_TYPE_CHECK_INSTANCE_CAST ((o), OT_TYPE_CHECKSUM_INPUT_STREAM, OtChecksumInstream)) +#define OT_CHECKSUM_INSTREAM_CLASS(k) \ + (G_TYPE_CHECK_CLASS_CAST ((k), OT_TYPE_CHECKSUM_INPUT_STREAM, OtChecksumInstreamClass)) +#define OT_IS_CHECKSUM_INSTREAM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), OT_TYPE_CHECKSUM_INPUT_STREAM)) +#define OT_IS_CHECKSUM_INSTREAM_CLASS(k) \ + (G_TYPE_CHECK_CLASS_TYPE ((k), OT_TYPE_CHECKSUM_INPUT_STREAM)) +#define OT_CHECKSUM_INSTREAM_GET_CLASS(o) \ + (G_TYPE_INSTANCE_GET_CLASS ((o), OT_TYPE_CHECKSUM_INPUT_STREAM, OtChecksumInstreamClass)) -typedef struct _OtChecksumInstream OtChecksumInstream; -typedef struct _OtChecksumInstreamClass OtChecksumInstreamClass; -typedef struct _OtChecksumInstreamPrivate OtChecksumInstreamPrivate; +typedef struct _OtChecksumInstream OtChecksumInstream; +typedef struct _OtChecksumInstreamClass OtChecksumInstreamClass; +typedef struct _OtChecksumInstreamPrivate OtChecksumInstreamPrivate; struct _OtChecksumInstream { @@ -48,12 +52,13 @@ struct _OtChecksumInstreamClass GFilterInputStreamClass parent_class; }; -GType ot_checksum_instream_get_type (void) G_GNUC_CONST; +GType ot_checksum_instream_get_type (void) G_GNUC_CONST; -OtChecksumInstream * ot_checksum_instream_new (GInputStream *stream, GChecksumType checksum); -OtChecksumInstream * ot_checksum_instream_new_with_start (GInputStream *stream, GChecksumType checksum, - const guint8 *buf, size_t len); +OtChecksumInstream *ot_checksum_instream_new (GInputStream *stream, GChecksumType checksum); +OtChecksumInstream *ot_checksum_instream_new_with_start (GInputStream *stream, + GChecksumType checksum, const guint8 *buf, + size_t len); -char * ot_checksum_instream_get_string (OtChecksumInstream *stream); +char *ot_checksum_instream_get_string (OtChecksumInstream *stream); G_END_DECLS diff --git a/src/libotutil/ot-checksum-utils.c b/src/libotutil/ot-checksum-utils.c index 2f3a342c..8f585c09 100644 --- a/src/libotutil/ot-checksum-utils.c +++ b/src/libotutil/ot-checksum-utils.c @@ -25,8 +25,8 @@ #if defined(HAVE_OPENSSL) #include #elif defined(HAVE_GNUTLS) -#include #include +#include #endif #include @@ -41,16 +41,18 @@ ot_bin2hex (char *out_buf, const guint8 *inbuf, gsize len) { guchar byte = inbuf[i]; out_buf[j] = hexchars[byte >> 4]; - out_buf[j+1] = hexchars[byte & 0xF]; + out_buf[j + 1] = hexchars[byte & 0xF]; } out_buf[j] = '\0'; } /* I like to think of this as AbstractChecksumProxyFactoryBean. In homage to * https://news.ycombinator.com/item?id=4549544 - * aka http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.html + * aka + * http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.html */ -typedef struct { +typedef struct +{ gboolean initialized; gboolean closed; #if defined(HAVE_OPENSSL) @@ -68,7 +70,7 @@ G_STATIC_ASSERT (sizeof (OtChecksum) >= sizeof (OtRealChecksum)); void ot_checksum_init (OtChecksum *checksum) { - OtRealChecksum *real = (OtRealChecksum*)checksum; + OtRealChecksum *real = (OtRealChecksum *)checksum; g_return_if_fail (!real->initialized); #if defined(HAVE_OPENSSL) real->checksum = EVP_MD_CTX_create (); @@ -88,11 +90,9 @@ ot_checksum_init (OtChecksum *checksum) } void -ot_checksum_update (OtChecksum *checksum, - const guint8 *buf, - size_t len) +ot_checksum_update (OtChecksum *checksum, const guint8 *buf, size_t len) { - OtRealChecksum *real = (OtRealChecksum*)checksum; + OtRealChecksum *real = (OtRealChecksum *)checksum; g_return_if_fail (real->initialized); g_return_if_fail (!real->closed); #if defined(HAVE_OPENSSL) @@ -105,9 +105,7 @@ ot_checksum_update (OtChecksum *checksum, } static void -ot_checksum_get_digest_internal (OtRealChecksum *real, - guint8 *buf, - size_t buflen) +ot_checksum_get_digest_internal (OtRealChecksum *real, guint8 *buf, size_t buflen) { g_return_if_fail (real->initialized); g_assert_cmpint (buflen, ==, _OSTREE_SHA256_DIGEST_LEN); @@ -125,31 +123,27 @@ ot_checksum_get_digest_internal (OtRealChecksum *real, } void -ot_checksum_get_digest (OtChecksum *checksum, - guint8 *buf, - size_t buflen) +ot_checksum_get_digest (OtChecksum *checksum, guint8 *buf, size_t buflen) { - OtRealChecksum *real = (OtRealChecksum*)checksum; + OtRealChecksum *real = (OtRealChecksum *)checksum; ot_checksum_get_digest_internal (real, buf, buflen); real->closed = TRUE; } void -ot_checksum_get_hexdigest (OtChecksum *checksum, - char *buf, - size_t buflen) +ot_checksum_get_hexdigest (OtChecksum *checksum, char *buf, size_t buflen) { - OtRealChecksum *real = (OtRealChecksum*)checksum; + OtRealChecksum *real = (OtRealChecksum *)checksum; const guint digest_len = real->digest_len; guint8 digest_buf[digest_len]; ot_checksum_get_digest (checksum, digest_buf, digest_len); - ot_bin2hex (buf, (guint8*)digest_buf, digest_len); + ot_bin2hex (buf, (guint8 *)digest_buf, digest_len); } void ot_checksum_clear (OtChecksum *checksum) { - OtRealChecksum *real = (OtRealChecksum*)checksum; + OtRealChecksum *real = (OtRealChecksum *)checksum; if (!real->initialized) return; #if defined(HAVE_OPENSSL) @@ -163,7 +157,7 @@ ot_checksum_clear (OtChecksum *checksum) } guchar * -ot_csum_from_gchecksum (GChecksum *checksum) +ot_csum_from_gchecksum (GChecksum *checksum) { guchar *ret = g_malloc (32); gsize len = 32; @@ -174,18 +168,13 @@ ot_csum_from_gchecksum (GChecksum *checksum) } gboolean -ot_gio_write_update_checksum (GOutputStream *out, - gconstpointer data, - gsize len, - gsize *out_bytes_written, - OtChecksum *checksum, - GCancellable *cancellable, - GError **error) +ot_gio_write_update_checksum (GOutputStream *out, gconstpointer data, gsize len, + gsize *out_bytes_written, OtChecksum *checksum, + GCancellable *cancellable, GError **error) { if (out) { - if (!g_output_stream_write_all (out, data, len, out_bytes_written, - cancellable, error)) + if (!g_output_stream_write_all (out, data, len, out_bytes_written, cancellable, error)) return FALSE; } else if (out_bytes_written) @@ -199,11 +188,8 @@ ot_gio_write_update_checksum (GOutputStream *out, } gboolean -ot_gio_splice_update_checksum (GOutputStream *out, - GInputStream *in, - OtChecksum *checksum, - GCancellable *cancellable, - GError **error) +ot_gio_splice_update_checksum (GOutputStream *out, GInputStream *in, OtChecksum *checksum, + GCancellable *cancellable, GError **error) { g_return_val_if_fail (out != NULL || checksum != NULL, FALSE); @@ -234,13 +220,12 @@ ot_gio_splice_update_checksum (GOutputStream *out, * all data read. */ gboolean -ot_gio_splice_get_checksum (GOutputStream *out, - GInputStream *in, - guchar **out_csum, - GCancellable *cancellable, - GError **error) +ot_gio_splice_get_checksum (GOutputStream *out, GInputStream *in, guchar **out_csum, + GCancellable *cancellable, GError **error) { - g_auto(OtChecksum) checksum = { 0, }; + g_auto (OtChecksum) checksum = { + 0, + }; ot_checksum_init (&checksum); if (!ot_gio_splice_update_checksum (out, in, &checksum, cancellable, error)) @@ -254,31 +239,31 @@ ot_gio_splice_get_checksum (GOutputStream *out, } char * -ot_checksum_file_at (int dfd, - const char *path, - GChecksumType checksum_type, - GCancellable *cancellable, - GError **error) +ot_checksum_file_at (int dfd, const char *path, GChecksumType checksum_type, + GCancellable *cancellable, GError **error) { - g_autoptr(GInputStream) in = NULL; + g_autoptr (GInputStream) in = NULL; if (!ot_openat_read_stream (dfd, path, TRUE, &in, cancellable, error)) return FALSE; - g_auto(OtChecksum) checksum = { 0, }; + g_auto (OtChecksum) checksum = { + 0, + }; ot_checksum_init (&checksum); if (!ot_gio_splice_update_checksum (NULL, in, &checksum, cancellable, error)) return FALSE; - char hexdigest[_OSTREE_SHA256_STRING_LEN+1]; + char hexdigest[_OSTREE_SHA256_STRING_LEN + 1]; ot_checksum_get_hexdigest (&checksum, hexdigest, sizeof (hexdigest)); return g_strdup (hexdigest); } void -ot_checksum_bytes (GBytes *data, - guint8 out_digest[_OSTREE_SHA256_DIGEST_LEN]) +ot_checksum_bytes (GBytes *data, guint8 out_digest[_OSTREE_SHA256_DIGEST_LEN]) { - g_auto(OtChecksum) hasher = { 0, }; + g_auto (OtChecksum) hasher = { + 0, + }; ot_checksum_init (&hasher); ot_checksum_update_bytes (&hasher, data); ot_checksum_get_digest (&hasher, out_digest, _OSTREE_SHA256_DIGEST_LEN); diff --git a/src/libotutil/ot-checksum-utils.h b/src/libotutil/ot-checksum-utils.h index d1be20bf..3ee66ce3 100644 --- a/src/libotutil/ot-checksum-utils.h +++ b/src/libotutil/ot-checksum-utils.h @@ -29,7 +29,8 @@ void ot_bin2hex (char *out_buf, const guint8 *inbuf, gsize len); guchar *ot_csum_from_gchecksum (GChecksum *checksum); -struct OtChecksum { +struct OtChecksum +{ gboolean initialized; guint uints[2]; gpointer data[2]; @@ -48,53 +49,32 @@ typedef struct OtChecksum OtChecksum; #endif void ot_checksum_init (OtChecksum *checksum); -void ot_checksum_update (OtChecksum *checksum, - const guint8 *buf, - size_t len); +void ot_checksum_update (OtChecksum *checksum, const guint8 *buf, size_t len); static inline void -ot_checksum_update_bytes (OtChecksum *checksum, - GBytes *buf) +ot_checksum_update_bytes (OtChecksum *checksum, GBytes *buf) { gsize len; const guint8 *bufdata = g_bytes_get_data (buf, &len); ot_checksum_update (checksum, bufdata, len); } -void ot_checksum_get_digest (OtChecksum *checksum, - guint8 *buf, - size_t buflen); -void ot_checksum_get_hexdigest (OtChecksum *checksum, - char *buf, - size_t buflen); +void ot_checksum_get_digest (OtChecksum *checksum, guint8 *buf, size_t buflen); +void ot_checksum_get_hexdigest (OtChecksum *checksum, char *buf, size_t buflen); void ot_checksum_clear (OtChecksum *checksum); -G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(OtChecksum, ot_checksum_clear) +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (OtChecksum, ot_checksum_clear) -gboolean ot_gio_write_update_checksum (GOutputStream *out, - gconstpointer data, - gsize len, - gsize *out_bytes_written, - OtChecksum *checksum, - GCancellable *cancellable, - GError **error); +gboolean ot_gio_write_update_checksum (GOutputStream *out, gconstpointer data, gsize len, + gsize *out_bytes_written, OtChecksum *checksum, + GCancellable *cancellable, GError **error); -gboolean ot_gio_splice_get_checksum (GOutputStream *out, - GInputStream *in, - guchar **out_csum, - GCancellable *cancellable, - GError **error); +gboolean ot_gio_splice_get_checksum (GOutputStream *out, GInputStream *in, guchar **out_csum, + GCancellable *cancellable, GError **error); -gboolean ot_gio_splice_update_checksum (GOutputStream *out, - GInputStream *in, - OtChecksum *checksum, - GCancellable *cancellable, - GError **error); +gboolean ot_gio_splice_update_checksum (GOutputStream *out, GInputStream *in, OtChecksum *checksum, + GCancellable *cancellable, GError **error); -char * ot_checksum_file_at (int dfd, - const char *path, - GChecksumType checksum_type, - GCancellable *cancellable, - GError **error); +char *ot_checksum_file_at (int dfd, const char *path, GChecksumType checksum_type, + GCancellable *cancellable, GError **error); -void ot_checksum_bytes (GBytes *data, - guint8 out_digest[_OSTREE_SHA256_DIGEST_LEN]); +void ot_checksum_bytes (GBytes *data, guint8 out_digest[_OSTREE_SHA256_DIGEST_LEN]); G_END_DECLS diff --git a/src/libotutil/ot-fs-utils.c b/src/libotutil/ot-fs-utils.c index 935b1bbc..efbb2f20 100644 --- a/src/libotutil/ot-fs-utils.c +++ b/src/libotutil/ot-fs-utils.c @@ -19,12 +19,12 @@ #include "config.h" -#include "ot-fs-utils.h" #include "libglnx.h" -#include -#include +#include "ot-fs-utils.h" #include #include +#include +#include /* Convert a fd-relative path to a GFile* - use * for legacy code. @@ -40,13 +40,10 @@ ot_fdrel_to_gfile (int dfd, const char *path) * of @target_info. */ gboolean -ot_readlinkat_gfile_info (int dfd, - const char *path, - GFileInfo *target_info, - GCancellable *cancellable, - GError **error) +ot_readlinkat_gfile_info (int dfd, const char *path, GFileInfo *target_info, + GCancellable *cancellable, GError **error) { - char targetbuf[PATH_MAX+1]; + char targetbuf[PATH_MAX + 1]; ssize_t len; if (TEMP_FAILURE_RETRY (len = readlinkat (dfd, path, targetbuf, sizeof (targetbuf) - 1)) < 0) @@ -72,12 +69,8 @@ ot_readlinkat_gfile_info (int dfd, * symlink path components are always followed. */ gboolean -ot_openat_read_stream (int dfd, - const char *path, - gboolean follow, - GInputStream **out_istream, - GCancellable *cancellable, - GError **error) +ot_openat_read_stream (int dfd, const char *path, gboolean follow, GInputStream **out_istream, + GCancellable *cancellable, GError **error) { glnx_autofd int fd = -1; if (!glnx_openat_rdonly (dfd, path, follow, &fd, error)) @@ -88,9 +81,7 @@ ot_openat_read_stream (int dfd, /* Like unlinkat() but ignore ENOENT */ gboolean -ot_ensure_unlinked_at (int dfd, - const char *path, - GError **error) +ot_ensure_unlinked_at (int dfd, const char *path, GError **error) { if (unlinkat (dfd, path, 0) != 0) { @@ -101,10 +92,7 @@ ot_ensure_unlinked_at (int dfd, } gboolean -ot_openat_ignore_enoent (int dfd, - const char *path, - int *out_fd, - GError **error) +ot_openat_ignore_enoent (int dfd, const char *path, int *out_fd, GError **error) { int target_fd = openat (dfd, path, O_CLOEXEC | O_RDONLY); if (target_fd < 0) @@ -121,11 +109,8 @@ ot_openat_ignore_enoent (int dfd, * @out_exists to %FALSE, and return successfully. */ gboolean -ot_dfd_iter_init_allow_noent (int dfd, - const char *path, - GLnxDirFdIterator *dfd_iter, - gboolean *out_exists, - GError **error) +ot_dfd_iter_init_allow_noent (int dfd, const char *path, GLnxDirFdIterator *dfd_iter, + gboolean *out_exists, GError **error) { glnx_autofd int fd = glnx_opendirat_with_errno (dfd, path, TRUE); if (fd < 0) @@ -141,7 +126,8 @@ ot_dfd_iter_init_allow_noent (int dfd, return TRUE; } -typedef struct { +typedef struct +{ gpointer addr; gsize len; } MapData; @@ -150,7 +136,7 @@ static void map_data_destroy (gpointer data) { MapData *mdata = data; - (void) munmap (mdata->addr, mdata->len); + (void)munmap (mdata->addr, mdata->len); g_free (mdata); } @@ -158,9 +144,7 @@ map_data_destroy (gpointer data) * starting at offset @start. If the file is large enough, mmap() may be used. */ GBytes * -ot_fd_readall_or_mmap (int fd, - goffset start, - GError **error) +ot_fd_readall_or_mmap (int fd, goffset start, GError **error) { struct stat stbuf; if (!glnx_fstat (fd, &stbuf, error)) @@ -170,14 +154,14 @@ ot_fd_readall_or_mmap (int fd, if (start > stbuf.st_size) return g_bytes_new_static (NULL, 0); const gsize len = stbuf.st_size - start; - if (len > 16*1024) + if (len > 16 * 1024) { /* The reason we don't use g_mapped_file_new_from_fd() here * is it doesn't support passing an offset, which is actually * used by the static delta code. */ gpointer map = mmap (NULL, len, PROT_READ, MAP_PRIVATE, fd, start); - if (map == (void*)-1) + if (map == (void *)-1) return glnx_null_throw_errno_prefix (error, "mmap"); MapData *mdata = g_new (MapData, 1); @@ -198,41 +182,38 @@ ot_fd_readall_or_mmap (int fd, * Useful for potentially large but transient files. */ GBytes * -ot_map_anonymous_tmpfile_from_content (GInputStream *instream, - GCancellable *cancellable, - GError **error) +ot_map_anonymous_tmpfile_from_content (GInputStream *instream, GCancellable *cancellable, + GError **error) { - g_auto(GLnxTmpfile) tmpf = { 0, }; + g_auto (GLnxTmpfile) tmpf = { + 0, + }; if (!glnx_open_anonymous_tmpfile (O_RDWR | O_CLOEXEC, &tmpf, error)) return NULL; - g_autoptr(GOutputStream) out = g_unix_output_stream_new (tmpf.fd, FALSE); - gssize n_bytes_written = g_output_stream_splice (out, instream, - G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | - G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, - cancellable, error); + g_autoptr (GOutputStream) out = g_unix_output_stream_new (tmpf.fd, FALSE); + gssize n_bytes_written = g_output_stream_splice ( + out, instream, G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, + cancellable, error); if (n_bytes_written < 0) return NULL; - g_autoptr(GMappedFile) mfile = g_mapped_file_new_from_fd (tmpf.fd, FALSE, error); + g_autoptr (GMappedFile) mfile = g_mapped_file_new_from_fd (tmpf.fd, FALSE, error); if (!mfile) return NULL; return g_mapped_file_get_bytes (mfile); } gboolean -ot_parse_file_by_line (const char *path, - gboolean (*cb)(const char*, void*, GError**), - void *cbdata, - GCancellable *cancellable, - GError **error) +ot_parse_file_by_line (const char *path, gboolean (*cb) (const char *, void *, GError **), + void *cbdata, GCancellable *cancellable, GError **error) { - g_autofree char *contents = - glnx_file_get_contents_utf8_at (AT_FDCWD, path, NULL, cancellable, error); + g_autofree char *contents + = glnx_file_get_contents_utf8_at (AT_FDCWD, path, NULL, cancellable, error); if (!contents) return FALSE; - g_auto(GStrv) lines = g_strsplit (contents, "\n", -1); + g_auto (GStrv) lines = g_strsplit (contents, "\n", -1); for (char **iter = lines; iter && *iter; iter++) { /* skip empty lines at least */ @@ -249,13 +230,12 @@ ot_parse_file_by_line (const char *path, /* Calculate the size of the files contained in a directory. Symlinks are not * followed. */ gboolean -ot_get_dir_size (int dfd, - const char *path, - guint64 *out_size, - GCancellable *cancellable, - GError **error) +ot_get_dir_size (int dfd, const char *path, guint64 *out_size, 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)) return FALSE; diff --git a/src/libotutil/ot-fs-utils.h b/src/libotutil/ot-fs-utils.h index f719381d..b64adce2 100644 --- a/src/libotutil/ot-fs-utils.h +++ b/src/libotutil/ot-fs-utils.h @@ -19,8 +19,8 @@ #pragma once -#include "ot-unix-utils.h" #include "libglnx.h" +#include "ot-unix-utils.h" G_BEGIN_DECLS @@ -28,7 +28,8 @@ G_BEGIN_DECLS * function. Mostly only necessary to handle * deletion of temporary symlinks. */ -typedef struct { +typedef struct +{ int dfd; char *path; } OtCleanupUnlinkat; @@ -44,62 +45,37 @@ ot_cleanup_unlinkat (OtCleanupUnlinkat *cleanup) { if (cleanup->path) { - (void) unlinkat (cleanup->dfd, cleanup->path, 0); + (void)unlinkat (cleanup->dfd, cleanup->path, 0); ot_cleanup_unlinkat_clear (cleanup); } } -G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(OtCleanupUnlinkat, ot_cleanup_unlinkat) +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (OtCleanupUnlinkat, ot_cleanup_unlinkat) -GFile * ot_fdrel_to_gfile (int dfd, const char *path); +GFile *ot_fdrel_to_gfile (int dfd, const char *path); -gboolean ot_readlinkat_gfile_info (int dfd, - const char *path, - GFileInfo *target_info, - GCancellable *cancellable, - GError **error); +gboolean ot_readlinkat_gfile_info (int dfd, const char *path, GFileInfo *target_info, + GCancellable *cancellable, GError **error); -gboolean ot_openat_read_stream (int dfd, - const char *path, - gboolean follow, - GInputStream **out_istream, - GCancellable *cancellable, - GError **error); - -gboolean ot_ensure_unlinked_at (int dfd, - const char *path, +gboolean ot_openat_read_stream (int dfd, const char *path, gboolean follow, + GInputStream **out_istream, GCancellable *cancellable, GError **error); -gboolean ot_openat_ignore_enoent (int dfd, - const char *path, - int *out_fd, - GError **error); - -gboolean ot_dfd_iter_init_allow_noent (int dfd, - const char *path, - GLnxDirFdIterator *dfd_iter, - gboolean *out_exists, - GError **error); - -GBytes * -ot_map_anonymous_tmpfile_from_content (GInputStream *instream, - GCancellable *cancellable, - GError **error); - -GBytes *ot_fd_readall_or_mmap (int fd, goffset offset, - GError **error); - -gboolean -ot_parse_file_by_line (const char *path, - gboolean (*cb)(const char*, void*, GError**), - void *cbdata, - GCancellable *cancellable, - GError **error); - -gboolean -ot_get_dir_size (int dfd, - const char *path, - guint64 *out_size, - GCancellable *cancellable, - GError **error); +gboolean ot_ensure_unlinked_at (int dfd, const char *path, GError **error); + +gboolean ot_openat_ignore_enoent (int dfd, const char *path, int *out_fd, GError **error); + +gboolean ot_dfd_iter_init_allow_noent (int dfd, const char *path, GLnxDirFdIterator *dfd_iter, + gboolean *out_exists, GError **error); + +GBytes *ot_map_anonymous_tmpfile_from_content (GInputStream *instream, GCancellable *cancellable, + GError **error); + +GBytes *ot_fd_readall_or_mmap (int fd, goffset offset, GError **error); + +gboolean ot_parse_file_by_line (const char *path, gboolean (*cb) (const char *, void *, GError **), + void *cbdata, GCancellable *cancellable, GError **error); + +gboolean ot_get_dir_size (int dfd, const char *path, guint64 *out_size, GCancellable *cancellable, + GError **error); G_END_DECLS diff --git a/src/libotutil/ot-gio-utils.c b/src/libotutil/ot-gio-utils.c index 56926fe5..d3d9765c 100644 --- a/src/libotutil/ot-gio-utils.c +++ b/src/libotutil/ot-gio-utils.c @@ -21,10 +21,10 @@ #include "config.h" +#include #include #include #include -#include #include @@ -35,9 +35,7 @@ #endif GFile * -ot_gfile_resolve_path_printf (GFile *path, - const char *format, - ...) +ot_gfile_resolve_path_printf (GFile *path, const char *format, ...) { va_list args; g_autofree char *relpath = NULL; @@ -55,18 +53,14 @@ ot_gfile_resolve_path_printf (GFile *path, * Like g_file_replace_contents(), except always uses fdatasync(). */ gboolean -ot_gfile_replace_contents_fsync (GFile *path, - GBytes *contents, - GCancellable *cancellable, - GError **error) +ot_gfile_replace_contents_fsync (GFile *path, GBytes *contents, GCancellable *cancellable, + GError **error) { gsize len; - const guint8*buf = g_bytes_get_data (contents, &len); + const guint8 *buf = g_bytes_get_data (contents, &len); - return glnx_file_replace_contents_at (AT_FDCWD, gs_file_get_path_cached (path), - buf, len, - GLNX_FILE_REPLACE_DATASYNC_NEW, - cancellable, error); + return glnx_file_replace_contents_at (AT_FDCWD, gs_file_get_path_cached (path), buf, len, + GLNX_FILE_REPLACE_DATASYNC_NEW, cancellable, error); } /** @@ -76,9 +70,7 @@ ot_gfile_replace_contents_fsync (GFile *path, * exist. */ gboolean -ot_gfile_ensure_unlinked (GFile *path, - GCancellable *cancellable, - GError **error) +ot_gfile_ensure_unlinked (GFile *path, GCancellable *cancellable, GError **error) { g_assert (path); const char *pathc = gs_file_get_path_cached (path); @@ -94,11 +86,8 @@ ot_gfile_ensure_unlinked (GFile *path, #if !GLIB_CHECK_VERSION(2, 44, 0) gboolean -ot_file_enumerator_iterate (GFileEnumerator *direnum, - GFileInfo **out_info, - GFile **out_child, - GCancellable *cancellable, - GError **error) +ot_file_enumerator_iterate (GFileEnumerator *direnum, GFileInfo **out_info, GFile **out_child, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; GError *temp_error = NULL; @@ -127,17 +116,19 @@ ot_file_enumerator_iterate (GFileEnumerator *direnum, } else if (*out_info != NULL) { - g_object_set_qdata_full ((GObject*)direnum, cached_info_quark, *out_info, (GDestroyNotify)g_object_unref); + g_object_set_qdata_full ((GObject *)direnum, cached_info_quark, *out_info, + (GDestroyNotify)g_object_unref); if (out_child != NULL) { const char *name = g_file_info_get_name (*out_info); *out_child = g_file_get_child (g_file_enumerator_get_container (direnum), name); - g_object_set_qdata_full ((GObject*)direnum, cached_child_quark, *out_child, (GDestroyNotify)g_object_unref); + g_object_set_qdata_full ((GObject *)direnum, cached_child_quark, *out_child, + (GDestroyNotify)g_object_unref); } } ret = TRUE; - out: +out: return ret; } @@ -162,7 +153,7 @@ ot_file_get_path_cached (GFile *file) G_LOCK (pathname_cache); - path = g_object_get_qdata ((GObject*)file, _file_path_quark); + path = g_object_get_qdata ((GObject *)file, _file_path_quark); if (!path) { path = g_file_get_path (file); @@ -171,7 +162,8 @@ ot_file_get_path_cached (GFile *file) G_UNLOCK (pathname_cache); return NULL; } - g_object_set_qdata_full ((GObject*)file, _file_path_quark, (char*)path, (GDestroyNotify)g_free); + g_object_set_qdata_full ((GObject *)file, _file_path_quark, (char *)path, + (GDestroyNotify)g_free); } G_UNLOCK (pathname_cache); diff --git a/src/libotutil/ot-gio-utils.h b/src/libotutil/ot-gio-utils.h index 27c1d2d9..99287137 100644 --- a/src/libotutil/ot-gio-utils.h +++ b/src/libotutil/ot-gio-utils.h @@ -29,49 +29,35 @@ G_BEGIN_DECLS * readlink(). Other things require opening the file, or also * stat()ing the parent directory. */ -#define OSTREE_GIO_FAST_QUERYINFO ("standard::name,standard::type,standard::size,standard::is-symlink,standard::symlink-target," \ - "unix::device,unix::inode,unix::mode,unix::uid,unix::gid,unix::rdev") +#define OSTREE_GIO_FAST_QUERYINFO \ + ("standard::name,standard::type,standard::size,standard::is-symlink,standard::symlink-target," \ + "unix::device,unix::inode,unix::mode,unix::uid,unix::gid,unix::rdev") -GFile * ot_gfile_resolve_path_printf (GFile *path, - const char *format, - ...) G_GNUC_PRINTF(2, 3); +GFile *ot_gfile_resolve_path_printf (GFile *path, const char *format, ...) G_GNUC_PRINTF (2, 3); -gboolean ot_gfile_replace_contents_fsync (GFile *path, - GBytes *contents, - GCancellable *cancellable, - GError **error); +gboolean ot_gfile_replace_contents_fsync (GFile *path, GBytes *contents, GCancellable *cancellable, + GError **error); -gboolean ot_gfile_ensure_unlinked (GFile *path, - GCancellable *cancellable, - GError **error); +gboolean ot_gfile_ensure_unlinked (GFile *path, GCancellable *cancellable, GError **error); #if !GLIB_CHECK_VERSION(2, 44, 0) -gboolean -ot_file_enumerator_iterate (GFileEnumerator *direnum, - GFileInfo **out_info, - GFile **out_child, - GCancellable *cancellable, - GError **error); +gboolean ot_file_enumerator_iterate (GFileEnumerator *direnum, GFileInfo **out_info, + GFile **out_child, GCancellable *cancellable, GError **error); #else static inline gboolean -ot_file_enumerator_iterate (GFileEnumerator *direnum, - GFileInfo **out_info, - GFile **out_child, - GCancellable *cancellable, - GError **error) +ot_file_enumerator_iterate (GFileEnumerator *direnum, GFileInfo **out_info, GFile **out_child, + GCancellable *cancellable, GError **error) { G_GNUC_BEGIN_IGNORE_DEPRECATIONS; - return (g_file_enumerator_iterate) (direnum, out_info, out_child, cancellable, error); + return (g_file_enumerator_iterate)(direnum, out_info, out_child, cancellable, error); G_GNUC_END_IGNORE_DEPRECATIONS; } #endif #define g_file_enumerator_iterate ot_file_enumerator_iterate -const char * -ot_file_get_path_cached (GFile *file); +const char *ot_file_get_path_cached (GFile *file); -static inline -const char * +static inline const char * gs_file_get_path_cached (GFile *file) { return ot_file_get_path_cached (file); diff --git a/src/libotutil/ot-gpg-utils.c b/src/libotutil/ot-gpg-utils.c index fd65e120..bb91a771 100644 --- a/src/libotutil/ot-gpg-utils.c +++ b/src/libotutil/ot-gpg-utils.c @@ -24,14 +24,13 @@ #include -#include #include "libglnx.h" #include "zbase32.h" +#include /* Like glnx_throw_errno_prefix, but takes @gpg_error */ gboolean -ot_gpgme_throw (gpgme_error_t gpg_error, GError **error, - const char *fmt, ...) +ot_gpgme_throw (gpgme_error_t gpg_error, GError **error, const char *fmt, ...) { if (error == NULL) return FALSE; @@ -42,32 +41,28 @@ ot_gpgme_throw (gpgme_error_t gpg_error, GError **error, /* XXX This list is incomplete. Add cases as needed. */ switch (gpgme_err_code (gpg_error)) { - /* special case - shouldn't be here */ - case GPG_ERR_NO_ERROR: - g_assert_not_reached (); - - /* special case - abort on out-of-memory */ - case GPG_ERR_ENOMEM: - (void) gpg_strerror_r (gpg_error, errbuf, sizeof (errbuf)); - errbuf[sizeof(errbuf)-1] = '\0'; - g_error ("%s: %s", - gpgme_strsource (gpg_error), - errbuf); - - case GPG_ERR_INV_VALUE: - errcode = G_IO_ERROR_INVALID_ARGUMENT; - break; - - default: - errcode = G_IO_ERROR_FAILED; - break; + /* special case - shouldn't be here */ + case GPG_ERR_NO_ERROR: + g_assert_not_reached (); + + /* special case - abort on out-of-memory */ + case GPG_ERR_ENOMEM: + (void)gpg_strerror_r (gpg_error, errbuf, sizeof (errbuf)); + errbuf[sizeof (errbuf) - 1] = '\0'; + g_error ("%s: %s", gpgme_strsource (gpg_error), errbuf); + + case GPG_ERR_INV_VALUE: + errcode = G_IO_ERROR_INVALID_ARGUMENT; + break; + + default: + errcode = G_IO_ERROR_FAILED; + break; } - (void) gpg_strerror_r (gpg_error, errbuf, sizeof (errbuf)); - errbuf[sizeof(errbuf)-1] = '\0'; - g_set_error (error, G_IO_ERROR, errcode, "%s: %s", - gpgme_strsource (gpg_error), - errbuf); + (void)gpg_strerror_r (gpg_error, errbuf, sizeof (errbuf)); + errbuf[sizeof (errbuf) - 1] = '\0'; + g_set_error (error, G_IO_ERROR, errcode, "%s: %s", gpgme_strsource (gpg_error), errbuf); va_list args; va_start (args, fmt); glnx_real_set_prefix_error_va (*error, fmt, args); @@ -77,11 +72,9 @@ ot_gpgme_throw (gpgme_error_t gpg_error, GError **error, } gboolean -ot_gpgme_ctx_tmp_home_dir (gpgme_ctx_t gpgme_ctx, - char **out_tmp_home_dir, - GOutputStream **out_pubring_stream, - GCancellable *cancellable, - GError **error) +ot_gpgme_ctx_tmp_home_dir (gpgme_ctx_t gpgme_ctx, char **out_tmp_home_dir, + GOutputStream **out_pubring_stream, GCancellable *cancellable, + GError **error) { g_autofree char *tmp_home_dir = NULL; gpgme_error_t gpg_error; @@ -105,9 +98,7 @@ ot_gpgme_ctx_tmp_home_dir (gpgme_ctx_t gpgme_ctx, /* Not documented, but gpgme_ctx_set_engine_info() accepts NULL for * the executable file name, which leaves the old setting unchanged. */ - gpg_error = gpgme_ctx_set_engine_info (gpgme_ctx, - GPGME_PROTOCOL_OpenPGP, - NULL, tmp_home_dir); + gpg_error = gpgme_ctx_set_engine_info (gpgme_ctx, GPGME_PROTOCOL_OpenPGP, NULL, tmp_home_dir); if (gpg_error != GPG_ERR_NO_ERROR) { ot_gpgme_throw (gpg_error, error, "gpgme_ctx_set_engine_info"); @@ -117,15 +108,13 @@ ot_gpgme_ctx_tmp_home_dir (gpgme_ctx_t gpgme_ctx, if (out_pubring_stream != NULL) { GFileOutputStream *pubring_stream; - g_autoptr(GFile) pubring_file = NULL; + g_autoptr (GFile) pubring_file = NULL; g_autofree char *pubring_path = NULL; pubring_path = g_build_filename (tmp_home_dir, "pubring.gpg", NULL); pubring_file = g_file_new_for_path (pubring_path); - pubring_stream = g_file_create (pubring_file, - G_FILE_CREATE_NONE, - cancellable, error); + pubring_stream = g_file_create (pubring_file, G_FILE_CREATE_NONE, cancellable, error); if (pubring_stream == NULL) goto out; @@ -142,7 +131,7 @@ out: if (!ret) { /* Clean up our mess on error. */ - (void) glnx_shutil_rm_rf_at (AT_FDCWD, tmp_home_dir, NULL, NULL); + (void)glnx_shutil_rm_rf_at (AT_FDCWD, tmp_home_dir, NULL, NULL); } return ret; @@ -159,98 +148,98 @@ set_errno_from_gio_error (GError *error) switch (error->code) { - case G_IO_ERROR_FAILED: - errno = EIO; - break; - case G_IO_ERROR_NOT_FOUND: - errno = ENOENT; - break; - case G_IO_ERROR_EXISTS: - errno = EEXIST; - break; - case G_IO_ERROR_IS_DIRECTORY: - errno = EISDIR; - break; - case G_IO_ERROR_NOT_DIRECTORY: - errno = ENOTDIR; - break; - case G_IO_ERROR_NOT_EMPTY: - errno = ENOTEMPTY; - break; - case G_IO_ERROR_NOT_REGULAR_FILE: - case G_IO_ERROR_NOT_SYMBOLIC_LINK: - case G_IO_ERROR_NOT_MOUNTABLE_FILE: - errno = EBADF; - break; - case G_IO_ERROR_FILENAME_TOO_LONG: - errno = ENAMETOOLONG; - break; - case G_IO_ERROR_INVALID_FILENAME: - errno = EINVAL; - break; - case G_IO_ERROR_TOO_MANY_LINKS: - errno = EMLINK; - break; - case G_IO_ERROR_NO_SPACE: - errno = ENOSPC; - break; - case G_IO_ERROR_INVALID_ARGUMENT: - errno = EINVAL; - break; - case G_IO_ERROR_PERMISSION_DENIED: - errno = EPERM; - break; - case G_IO_ERROR_NOT_SUPPORTED: - errno = ENOTSUP; - break; - case G_IO_ERROR_NOT_MOUNTED: - errno = ENOENT; - break; - case G_IO_ERROR_ALREADY_MOUNTED: - errno = EALREADY; - break; - case G_IO_ERROR_CLOSED: - errno = EBADF; - break; - case G_IO_ERROR_CANCELLED: - errno = EINTR; - break; - case G_IO_ERROR_PENDING: - errno = EALREADY; - break; - case G_IO_ERROR_READ_ONLY: - errno = EACCES; - break; - case G_IO_ERROR_CANT_CREATE_BACKUP: - errno = EIO; - break; - case G_IO_ERROR_WRONG_ETAG: - errno = EACCES; - break; - case G_IO_ERROR_TIMED_OUT: - errno = EIO; - break; - case G_IO_ERROR_WOULD_RECURSE: - errno = ELOOP; - break; - case G_IO_ERROR_BUSY: - errno = EBUSY; - break; - case G_IO_ERROR_WOULD_BLOCK: - errno = EWOULDBLOCK; - break; - case G_IO_ERROR_HOST_NOT_FOUND: - errno = EHOSTDOWN; - break; - case G_IO_ERROR_WOULD_MERGE: - errno = EIO; - break; - case G_IO_ERROR_FAILED_HANDLED: - errno = 0; - break; - default: - errno = EIO; - break; + case G_IO_ERROR_FAILED: + errno = EIO; + break; + case G_IO_ERROR_NOT_FOUND: + errno = ENOENT; + break; + case G_IO_ERROR_EXISTS: + errno = EEXIST; + break; + case G_IO_ERROR_IS_DIRECTORY: + errno = EISDIR; + break; + case G_IO_ERROR_NOT_DIRECTORY: + errno = ENOTDIR; + break; + case G_IO_ERROR_NOT_EMPTY: + errno = ENOTEMPTY; + break; + case G_IO_ERROR_NOT_REGULAR_FILE: + case G_IO_ERROR_NOT_SYMBOLIC_LINK: + case G_IO_ERROR_NOT_MOUNTABLE_FILE: + errno = EBADF; + break; + case G_IO_ERROR_FILENAME_TOO_LONG: + errno = ENAMETOOLONG; + break; + case G_IO_ERROR_INVALID_FILENAME: + errno = EINVAL; + break; + case G_IO_ERROR_TOO_MANY_LINKS: + errno = EMLINK; + break; + case G_IO_ERROR_NO_SPACE: + errno = ENOSPC; + break; + case G_IO_ERROR_INVALID_ARGUMENT: + errno = EINVAL; + break; + case G_IO_ERROR_PERMISSION_DENIED: + errno = EPERM; + break; + case G_IO_ERROR_NOT_SUPPORTED: + errno = ENOTSUP; + break; + case G_IO_ERROR_NOT_MOUNTED: + errno = ENOENT; + break; + case G_IO_ERROR_ALREADY_MOUNTED: + errno = EALREADY; + break; + case G_IO_ERROR_CLOSED: + errno = EBADF; + break; + case G_IO_ERROR_CANCELLED: + errno = EINTR; + break; + case G_IO_ERROR_PENDING: + errno = EALREADY; + break; + case G_IO_ERROR_READ_ONLY: + errno = EACCES; + break; + case G_IO_ERROR_CANT_CREATE_BACKUP: + errno = EIO; + break; + case G_IO_ERROR_WRONG_ETAG: + errno = EACCES; + break; + case G_IO_ERROR_TIMED_OUT: + errno = EIO; + break; + case G_IO_ERROR_WOULD_RECURSE: + errno = ELOOP; + break; + case G_IO_ERROR_BUSY: + errno = EBUSY; + break; + case G_IO_ERROR_WOULD_BLOCK: + errno = EWOULDBLOCK; + break; + case G_IO_ERROR_HOST_NOT_FOUND: + errno = EHOSTDOWN; + break; + case G_IO_ERROR_WOULD_MERGE: + errno = EIO; + break; + case G_IO_ERROR_FAILED_HANDLED: + errno = 0; + break; + default: + errno = EIO; + break; } } @@ -263,8 +252,7 @@ data_read_cb (void *handle, void *buffer, size_t size) g_return_val_if_fail (G_IS_INPUT_STREAM (input_stream), -1); - if (!g_input_stream_read_all (input_stream, buffer, size, - &bytes_read, NULL, &local_error)) + if (!g_input_stream_read_all (input_stream, buffer, size, &bytes_read, NULL, &local_error)) { set_errno_from_gio_error (local_error); g_clear_error (&local_error); @@ -283,8 +271,7 @@ data_write_cb (void *handle, const void *buffer, size_t size) g_return_val_if_fail (G_IS_OUTPUT_STREAM (output_stream), -1); - if (g_output_stream_write_all (output_stream, buffer, size, - &bytes_written, NULL, &local_error)) + if (g_output_stream_write_all (output_stream, buffer, size, &bytes_written, NULL, &local_error)) { (void)g_output_stream_flush (output_stream, NULL, &local_error); } @@ -308,27 +295,27 @@ data_seek_cb (void *handle, off_t offset, int whence) off_t position = -1; GError *local_error = NULL; - g_return_val_if_fail (G_IS_INPUT_STREAM (stream) || - G_IS_OUTPUT_STREAM (stream), -1); + g_return_val_if_fail (G_IS_INPUT_STREAM (stream) || G_IS_OUTPUT_STREAM (stream), -1); - if (!G_IS_SEEKABLE (stream)) { - errno = EOPNOTSUPP; - goto out; - } + if (!G_IS_SEEKABLE (stream)) + { + errno = EOPNOTSUPP; + goto out; + } switch (whence) { - case SEEK_SET: - seek_type = G_SEEK_SET; - break; - case SEEK_CUR: - seek_type = G_SEEK_CUR; - break; - case SEEK_END: - seek_type = G_SEEK_END; - break; - default: - g_assert_not_reached (); + case SEEK_SET: + seek_type = G_SEEK_SET; + break; + case SEEK_CUR: + seek_type = G_SEEK_CUR; + break; + case SEEK_END: + seek_type = G_SEEK_END; + break; + default: + g_assert_not_reached (); } seekable = G_SEEKABLE (stream); @@ -351,25 +338,15 @@ data_release_cb (void *handle) { GObject *stream = handle; - g_return_if_fail (G_IS_INPUT_STREAM (stream) || - G_IS_OUTPUT_STREAM (stream)); + g_return_if_fail (G_IS_INPUT_STREAM (stream) || G_IS_OUTPUT_STREAM (stream)); g_object_unref (stream); } -static struct gpgme_data_cbs data_input_cbs = { - data_read_cb, - NULL, - data_seek_cb, - data_release_cb -}; +static struct gpgme_data_cbs data_input_cbs = { data_read_cb, NULL, data_seek_cb, data_release_cb }; -static struct gpgme_data_cbs data_output_cbs = { - NULL, - data_write_cb, - data_seek_cb, - data_release_cb -}; +static struct gpgme_data_cbs data_output_cbs + = { NULL, data_write_cb, data_seek_cb, data_release_cb }; gpgme_data_t ot_gpgme_data_input (GInputStream *input_stream) @@ -416,14 +393,13 @@ ot_gpgme_data_output (GOutputStream *output_stream) } gpgme_ctx_t -ot_gpgme_new_ctx (const char *homedir, - GError **error) +ot_gpgme_new_ctx (const char *homedir, GError **error) { gpgme_error_t err; - g_auto(gpgme_ctx_t) context = NULL; + g_auto (gpgme_ctx_t) context = NULL; if ((err = gpgme_new (&context)) != GPG_ERR_NO_ERROR) - return ot_gpgme_throw (err, error, "Unable to create gpg context"), NULL; + return ot_gpgme_throw (err, error, "Unable to create gpg context"), NULL; if (homedir != NULL) { @@ -440,9 +416,7 @@ ot_gpgme_new_ctx (const char *homedir, } static gboolean -get_gnupg_version (guint *major, - guint *minor, - guint *patch) +get_gnupg_version (guint *major, guint *minor, guint *patch) { g_return_val_if_fail (major != NULL, FALSE); g_return_val_if_fail (minor != NULL, FALSE); @@ -452,8 +426,8 @@ get_gnupg_version (guint *major, gpgme_error_t err = gpgme_get_engine_info (&info); if (err != GPG_ERR_NO_ERROR) { - g_debug ("Failed to get GPGME engine info: %s: %s", - gpgme_strsource (err), gpgme_strerror (err)); + g_debug ("Failed to get GPGME engine info: %s: %s", gpgme_strsource (err), + gpgme_strerror (err)); return FALSE; } @@ -473,7 +447,7 @@ get_gnupg_version (guint *major, return FALSE; } - g_auto(GStrv) parts = g_strsplit (gnupg_version, ".", 4); + g_auto (GStrv) parts = g_strsplit (gnupg_version, ".", 4); if (g_strv_length (parts) < 3) { g_debug ("Less than 3 components in GnuPG version \"%s\"", gnupg_version); @@ -498,9 +472,8 @@ ot_gpgme_kill_agent (const char *homedir) guint gnupg_major = 0, gnupg_minor = 0, gnupg_patch = 0; if (get_gnupg_version (&gnupg_major, &gnupg_minor, &gnupg_patch)) { - if ((gnupg_major > 2) || - (gnupg_major == 2 && gnupg_minor > 1) || - (gnupg_major == 2 && gnupg_minor == 1 && gnupg_patch >= 17)) + if ((gnupg_major > 2) || (gnupg_major == 2 && gnupg_minor > 1) + || (gnupg_major == 2 && gnupg_minor == 1 && gnupg_patch >= 17)) { /* Note early return */ g_debug ("GnuPG >= 2.1.17, skipping gpg-agent cleanup in %s", homedir); @@ -509,7 +482,7 @@ ot_gpgme_kill_agent (const char *homedir) } /* Run gpg-connect-agent killagent /bye */ - g_autoptr(GPtrArray) argv = g_ptr_array_new (); + g_autoptr (GPtrArray) argv = g_ptr_array_new (); g_ptr_array_add (argv, "gpg-connect-agent"); g_ptr_array_add (argv, "--homedir"); g_ptr_array_add (argv, (gpointer)homedir); @@ -517,13 +490,13 @@ ot_gpgme_kill_agent (const char *homedir) g_ptr_array_add (argv, "/bye"); g_ptr_array_add (argv, NULL); - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; GSpawnFlags flags = G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL; gint proc_status = 0; g_autofree gchar *proc_stderr = NULL; g_debug ("Killing gpg-agent in %s", homedir); - if (!g_spawn_sync (NULL, (char **)argv->pdata, NULL, flags, NULL, NULL, - NULL, &proc_stderr, &proc_status, &local_error)) + if (!g_spawn_sync (NULL, (char **)argv->pdata, NULL, flags, NULL, NULL, NULL, &proc_stderr, + &proc_status, &local_error)) { g_debug ("Spawning gpg-connect-agent failed: %s", local_error->message); return; @@ -533,8 +506,7 @@ ot_gpgme_kill_agent (const char *homedir) /* Dump out stderr on failures */ g_printerr ("%s", proc_stderr); - g_debug ("Killing GPG agent with gpg-connect-agent failed: %s", - local_error->message); + g_debug ("Killing GPG agent with gpg-connect-agent failed: %s", local_error->message); return; } } @@ -549,7 +521,7 @@ encode_wkd_local (const char *local) guint8 digest[20] = { 0 }; gsize len = sizeof (digest); - g_autoptr(GChecksum) checksum = g_checksum_new (G_CHECKSUM_SHA1); + g_autoptr (GChecksum) checksum = g_checksum_new (G_CHECKSUM_SHA1); g_checksum_update (checksum, (const guchar *)local, -1); g_checksum_get_digest (checksum, digest, &len); @@ -568,18 +540,15 @@ encode_wkd_local (const char *local) * https://datatracker.ietf.org/doc/html/draft-koch-openpgp-webkey-service */ gboolean -ot_gpg_wkd_urls (const char *email, - char **out_advanced_url, - char **out_direct_url, - GError **error) +ot_gpg_wkd_urls (const char *email, char **out_advanced_url, char **out_direct_url, GError **error) { g_return_val_if_fail (email != NULL, FALSE); - g_auto(GStrv) email_parts = g_strsplit (email, "@", -1); + g_auto (GStrv) email_parts = g_strsplit (email, "@", -1); if (g_strv_length (email_parts) != 2) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, - "Invalid email address \"%s\"", email); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Invalid email address \"%s\"", + email); return FALSE; } @@ -588,21 +557,17 @@ ot_gpg_wkd_urls (const char *email, g_autofree char *local_encoded = encode_wkd_local (local_lowered); g_autofree char *local_escaped = g_uri_escape_string (email_parts[0], NULL, FALSE); - g_autofree char *advanced_url = g_strdup_printf ("https://openpgpkey.%s" - "/.well-known/openpgpkey" - "/%s/hu/%s?l=%s", - email_parts[1], - domain_lowered, - local_encoded, - local_escaped); + g_autofree char *advanced_url + = g_strdup_printf ("https://openpgpkey.%s" + "/.well-known/openpgpkey" + "/%s/hu/%s?l=%s", + email_parts[1], domain_lowered, local_encoded, local_escaped); g_debug ("GPG UID \"%s\" advanced WKD URL: %s", email, advanced_url); g_autofree char *direct_url = g_strdup_printf ("https://%s" "/.well-known/openpgpkey" "/hu/%s?l=%s", - email_parts[1], - local_encoded, - local_escaped); + email_parts[1], local_encoded, local_escaped); g_debug ("GPG UID \"%s\" direct WKD URL: %s", email, direct_url); if (out_advanced_url != NULL) diff --git a/src/libotutil/ot-gpg-utils.h b/src/libotutil/ot-gpg-utils.h index ee1b1270..039a2f31 100644 --- a/src/libotutil/ot-gpg-utils.h +++ b/src/libotutil/ot-gpg-utils.h @@ -19,36 +19,31 @@ #pragma once -#include -#include #include "libglnx.h" +#include +#include G_BEGIN_DECLS -G_DEFINE_AUTO_CLEANUP_FREE_FUNC(gpgme_data_t, gpgme_data_release, NULL) -G_DEFINE_AUTO_CLEANUP_FREE_FUNC(gpgme_ctx_t, gpgme_release, NULL) -G_DEFINE_AUTO_CLEANUP_FREE_FUNC(gpgme_key_t, gpgme_key_unref, NULL) +G_DEFINE_AUTO_CLEANUP_FREE_FUNC (gpgme_data_t, gpgme_data_release, NULL) +G_DEFINE_AUTO_CLEANUP_FREE_FUNC (gpgme_ctx_t, gpgme_release, NULL) +G_DEFINE_AUTO_CLEANUP_FREE_FUNC (gpgme_key_t, gpgme_key_unref, NULL) -gboolean ot_gpgme_throw (gpgme_error_t gpg_error, GError **error, - const char *fmt, ...) G_GNUC_PRINTF (3, 4); +gboolean ot_gpgme_throw (gpgme_error_t gpg_error, GError **error, const char *fmt, ...) + G_GNUC_PRINTF (3, 4); -gboolean ot_gpgme_ctx_tmp_home_dir (gpgme_ctx_t gpgme_ctx, - char **out_tmp_home_dir, - GOutputStream **out_pubring_stream, - GCancellable *cancellable, - GError **error); +gboolean ot_gpgme_ctx_tmp_home_dir (gpgme_ctx_t gpgme_ctx, char **out_tmp_home_dir, + GOutputStream **out_pubring_stream, GCancellable *cancellable, + GError **error); gpgme_data_t ot_gpgme_data_input (GInputStream *input_stream); gpgme_data_t ot_gpgme_data_output (GOutputStream *output_stream); -gpgme_ctx_t ot_gpgme_new_ctx (const char *homedir, - GError **error); +gpgme_ctx_t ot_gpgme_new_ctx (const char *homedir, GError **error); void ot_gpgme_kill_agent (const char *homedir); -gboolean ot_gpg_wkd_urls (const char *email, - char **out_advanced_url, - char **out_direct_url, - GError **error); +gboolean ot_gpg_wkd_urls (const char *email, char **out_advanced_url, char **out_direct_url, + GError **error); G_END_DECLS diff --git a/src/libotutil/ot-keyfile-utils.c b/src/libotutil/ot-keyfile-utils.c index 066fe380..141b2f7a 100644 --- a/src/libotutil/ot-keyfile-utils.c +++ b/src/libotutil/ot-keyfile-utils.c @@ -29,16 +29,12 @@ static gboolean is_notfound (GError *error) { return g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND) - || g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND); + || g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND); } gboolean -ot_keyfile_get_boolean_with_default (GKeyFile *keyfile, - const char *section, - const char *value, - gboolean default_value, - gboolean *out_bool, - GError **error) +ot_keyfile_get_boolean_with_default (GKeyFile *keyfile, const char *section, const char *value, + gboolean default_value, gboolean *out_bool, GError **error) { g_return_val_if_fail (keyfile != NULL, FALSE); g_return_val_if_fail (section != NULL, FALSE); @@ -65,12 +61,8 @@ ot_keyfile_get_boolean_with_default (GKeyFile *keyfile, } gboolean -ot_keyfile_get_value_with_default (GKeyFile *keyfile, - const char *section, - const char *value, - const char *default_value, - char **out_value, - GError **error) +ot_keyfile_get_value_with_default (GKeyFile *keyfile, const char *section, const char *value, + const char *default_value, char **out_value, GError **error) { g_return_val_if_fail (keyfile != NULL, FALSE); g_return_val_if_fail (section != NULL, FALSE); @@ -93,17 +85,14 @@ ot_keyfile_get_value_with_default (GKeyFile *keyfile, } } - ot_transfer_out_value(out_value, &ret_value); + ot_transfer_out_value (out_value, &ret_value); return TRUE; } gboolean -ot_keyfile_get_value_with_default_group_optional (GKeyFile *keyfile, - const char *section, - const char *value, - const char *default_value, - char **out_value, - GError **error) +ot_keyfile_get_value_with_default_group_optional (GKeyFile *keyfile, const char *section, + const char *value, const char *default_value, + char **out_value, GError **error) { g_return_val_if_fail (keyfile != NULL, FALSE); g_return_val_if_fail (section != NULL, FALSE); @@ -111,7 +100,8 @@ ot_keyfile_get_value_with_default_group_optional (GKeyFile *keyfile, GError *local_error = NULL; g_autofree char *ret_value = NULL; - if (!ot_keyfile_get_value_with_default (keyfile, section, value, default_value, &ret_value, &local_error)) + if (!ot_keyfile_get_value_with_default (keyfile, section, value, default_value, &ret_value, + &local_error)) { if (g_error_matches (local_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) { @@ -125,7 +115,7 @@ ot_keyfile_get_value_with_default_group_optional (GKeyFile *keyfile, } } - ot_transfer_out_value(out_value, &ret_value); + ot_transfer_out_value (out_value, &ret_value); return TRUE; } @@ -136,24 +126,20 @@ ot_keyfile_get_value_with_default_group_optional (GKeyFile *keyfile, * * Returns TRUE on success, FALSE on error. */ gboolean -ot_keyfile_get_string_list_with_separator_choice (GKeyFile *keyfile, - const char *section, - const char *key, - const char *separators, - char ***out_value, - GError **error) +ot_keyfile_get_string_list_with_separator_choice (GKeyFile *keyfile, const char *section, + const char *key, const char *separators, + char ***out_value, GError **error) { g_return_val_if_fail (keyfile != NULL, FALSE); g_return_val_if_fail (section != NULL, FALSE); g_return_val_if_fail (key != NULL, FALSE); g_return_val_if_fail (separators != NULL, FALSE); - g_autofree char *value_str = NULL; - if (!ot_keyfile_get_value_with_default (keyfile, section, key, NULL, - &value_str, error)) + g_autofree char *value_str = NULL; + if (!ot_keyfile_get_value_with_default (keyfile, section, key, NULL, &value_str, error)) return FALSE; - g_auto(GStrv) value_list = NULL; + g_auto (GStrv) value_list = NULL; if (value_str) { gchar sep = '\0'; @@ -175,8 +161,8 @@ ot_keyfile_get_string_list_with_separator_choice (GKeyFile *keyfile, } else if (sep_count == 1) { - if (!ot_keyfile_get_string_list_with_default (keyfile, section, key, - sep, NULL, &value_list, error)) + if (!ot_keyfile_get_string_list_with_default (keyfile, section, key, sep, NULL, + &value_list, error)) return FALSE; } else @@ -190,15 +176,11 @@ ot_keyfile_get_string_list_with_separator_choice (GKeyFile *keyfile, } gboolean -ot_keyfile_get_string_list_with_default (GKeyFile *keyfile, - const char *section, - const char *key, - char separator, - char **default_value, - char ***out_value, - GError **error) +ot_keyfile_get_string_list_with_default (GKeyFile *keyfile, const char *section, const char *key, + char separator, char **default_value, char ***out_value, + GError **error) { - g_autoptr(GError) temp_error = NULL; + g_autoptr (GError) temp_error = NULL; g_return_val_if_fail (keyfile != NULL, FALSE); g_return_val_if_fail (section != NULL, FALSE); @@ -206,8 +188,7 @@ ot_keyfile_get_string_list_with_default (GKeyFile *keyfile, g_key_file_set_list_separator (keyfile, separator); - g_auto(GStrv) ret_value = g_key_file_get_string_list (keyfile, section, - key, NULL, &temp_error); + g_auto (GStrv) ret_value = g_key_file_get_string_list (keyfile, section, key, NULL, &temp_error); if (temp_error) { @@ -228,11 +209,9 @@ ot_keyfile_get_string_list_with_default (GKeyFile *keyfile, } gboolean -ot_keyfile_copy_group (GKeyFile *source_keyfile, - GKeyFile *target_keyfile, - const char *group_name) +ot_keyfile_copy_group (GKeyFile *source_keyfile, GKeyFile *target_keyfile, const char *group_name) { - g_auto(GStrv) keys = NULL; + g_auto (GStrv) keys = NULL; gsize length, ii; gboolean ret = FALSE; @@ -255,6 +234,6 @@ ot_keyfile_copy_group (GKeyFile *source_keyfile, ret = TRUE; - out: +out: return ret; } diff --git a/src/libotutil/ot-keyfile-utils.h b/src/libotutil/ot-keyfile-utils.h index 3b4f6560..ae70f1c7 100644 --- a/src/libotutil/ot-keyfile-utils.h +++ b/src/libotutil/ot-keyfile-utils.h @@ -25,51 +25,29 @@ G_BEGIN_DECLS -gboolean -ot_keyfile_get_boolean_with_default (GKeyFile *keyfile, - const char *section, - const char *value, - gboolean default_value, - gboolean *out_bool, - GError **error); - - -gboolean -ot_keyfile_get_value_with_default (GKeyFile *keyfile, - const char *section, - const char *value, - const char *default_value, - char **out_value, - GError **error); - -gboolean -ot_keyfile_get_value_with_default_group_optional (GKeyFile *keyfile, - const char *section, - const char *value, - const char *default_value, - char **out_value, - GError **error); - -gboolean -ot_keyfile_get_string_list_with_separator_choice (GKeyFile *keyfile, - const char *section, - const char *key, - const char *separators, - char ***out_value_list, - GError **error); - -gboolean -ot_keyfile_get_string_list_with_default (GKeyFile *keyfile, - const char *section, - const char *key, - char separator, - char **default_value, - char ***out_value, - GError **error); - -gboolean -ot_keyfile_copy_group (GKeyFile *source_keyfile, - GKeyFile *target_keyfile, - const char *group_name); +gboolean ot_keyfile_get_boolean_with_default (GKeyFile *keyfile, const char *section, + const char *value, gboolean default_value, + gboolean *out_bool, GError **error); + +gboolean ot_keyfile_get_value_with_default (GKeyFile *keyfile, const char *section, + const char *value, const char *default_value, + char **out_value, GError **error); + +gboolean ot_keyfile_get_value_with_default_group_optional (GKeyFile *keyfile, const char *section, + const char *value, + const char *default_value, + char **out_value, GError **error); + +gboolean ot_keyfile_get_string_list_with_separator_choice (GKeyFile *keyfile, const char *section, + const char *key, const char *separators, + char ***out_value_list, GError **error); + +gboolean ot_keyfile_get_string_list_with_default (GKeyFile *keyfile, const char *section, + const char *key, char separator, + char **default_value, char ***out_value, + GError **error); + +gboolean ot_keyfile_copy_group (GKeyFile *source_keyfile, GKeyFile *target_keyfile, + const char *group_name); G_END_DECLS diff --git a/src/libotutil/ot-tool-util.c b/src/libotutil/ot-tool-util.c index 33e87663..0e772c28 100644 --- a/src/libotutil/ot-tool-util.c +++ b/src/libotutil/ot-tool-util.c @@ -19,23 +19,17 @@ #include "config.h" -#include "otutil.h" #include "ot-tool-util.h" +#include "otutil.h" gboolean -ot_parse_boolean (const char *value, - gboolean *out_parsed, - GError **error) +ot_parse_boolean (const char *value, gboolean *out_parsed, GError **error) { -#define ARG_EQ(x, y) (g_ascii_strcasecmp(x, y) == 0) - if (ARG_EQ(value, "1") - || ARG_EQ(value, "true") - || ARG_EQ(value, "yes")) +#define ARG_EQ(x, y) (g_ascii_strcasecmp (x, y) == 0) + if (ARG_EQ (value, "1") || ARG_EQ (value, "true") || ARG_EQ (value, "yes")) *out_parsed = TRUE; - else if (ARG_EQ(value, "0") - || ARG_EQ(value, "false") - || ARG_EQ(value, "no") - || ARG_EQ(value, "none")) + else if (ARG_EQ (value, "0") || ARG_EQ (value, "false") || ARG_EQ (value, "no") + || ARG_EQ (value, "none")) *out_parsed = FALSE; else { @@ -46,10 +40,7 @@ ot_parse_boolean (const char *value, } gboolean -ot_parse_keyvalue (const char *keyvalue, - char **out_key, - char **out_value, - GError **error) +ot_parse_keyvalue (const char *keyvalue, char **out_key, char **out_value, GError **error) { const char *eq = strchr (keyvalue, '='); if (!eq) @@ -62,8 +53,10 @@ ot_parse_keyvalue (const char *keyvalue, } /** - * Note: temporarily copied from GLib: https://github.com/GNOME/glib/blob/a419146578a42c760cff684292465b38df855f75/glib/garray.c#L1664 - * See documentation at: https://developer.gnome.org/glib/stable/glib-Pointer-Arrays.html#g-ptr-array-find-with-equal-func + * Note: temporarily copied from GLib: + * https://github.com/GNOME/glib/blob/a419146578a42c760cff684292465b38df855f75/glib/garray.c#L1664 + * See documentation at: + * https://developer.gnome.org/glib/stable/glib-Pointer-Arrays.html#g-ptr-array-find-with-equal-func * * ot_ptr_array_find_with_equal_func: (skip) * @haystack: pointer array to be searched @@ -88,10 +81,8 @@ ot_parse_keyvalue (const char *keyvalue, * Since: 2.54 */ gboolean -ot_ptr_array_find_with_equal_func (GPtrArray *haystack, - gconstpointer needle, - GEqualFunc equal_func, - guint *index_) +ot_ptr_array_find_with_equal_func (GPtrArray *haystack, gconstpointer needle, GEqualFunc equal_func, + guint *index_) { guint i; diff --git a/src/libotutil/ot-tool-util.h b/src/libotutil/ot-tool-util.h index be15c010..6d0a1528 100644 --- a/src/libotutil/ot-tool-util.h +++ b/src/libotutil/ot-tool-util.h @@ -23,19 +23,9 @@ G_BEGIN_DECLS -gboolean -ot_parse_boolean (const char *value, - gboolean *out_parsed, - GError **error); -gboolean -ot_parse_keyvalue (const char *keyvalue, - char **out_key, - char **out_value, - GError **error); -gboolean -ot_ptr_array_find_with_equal_func (GPtrArray *haystack, - gconstpointer needle, - GEqualFunc equal_func, - guint *index_); +gboolean ot_parse_boolean (const char *value, gboolean *out_parsed, GError **error); +gboolean ot_parse_keyvalue (const char *keyvalue, char **out_key, char **out_value, GError **error); +gboolean ot_ptr_array_find_with_equal_func (GPtrArray *haystack, gconstpointer needle, + GEqualFunc equal_func, guint *index_); G_END_DECLS diff --git a/src/libotutil/ot-unix-utils.c b/src/libotutil/ot-unix-utils.c index 58539864..33cd1c02 100644 --- a/src/libotutil/ot-unix-utils.c +++ b/src/libotutil/ot-unix-utils.c @@ -24,22 +24,21 @@ #include "otutil.h" #include -#include #include +#include +#include +#include +#include #include #include -#include #include -#include -#include /* Ensure that a pathname component @name does not contain the special Unix * entries `.` or `..`, and does not contain `/`. */ gboolean -ot_util_filename_validate (const char *name, - GError **error) +ot_util_filename_validate (const char *name, GError **error) { if (name == NULL) return glnx_throw (error, "Invalid NULL filename"); @@ -55,25 +54,26 @@ ot_util_filename_validate (const char *name, } static GPtrArray * -ot_split_string_ptrarray (const char *str, - char c) +ot_split_string_ptrarray (const char *str, char c) { GPtrArray *ret = g_ptr_array_new_with_free_func (g_free); const char *p; - do { - p = strchr (str, '/'); - if (!p) - { - g_ptr_array_add (ret, g_strdup (str)); - str = NULL; - } - else - { - g_ptr_array_add (ret, g_strndup (str, p - str)); - str = p + 1; - } - } while (str && *str); + do + { + p = strchr (str, '/'); + if (!p) + { + g_ptr_array_add (ret, g_strdup (str)); + str = NULL; + } + else + { + g_ptr_array_add (ret, g_strndup (str, p - str)); + str = p + 1; + } + } + while (str && *str); return ret; } @@ -82,17 +82,15 @@ ot_split_string_ptrarray (const char *str, * validating that it does not have backreferences (`..`) etc. */ gboolean -ot_util_path_split_validate (const char *path, - GPtrArray **out_components, - GError **error) +ot_util_path_split_validate (const char *path, GPtrArray **out_components, GError **error) { if (strlen (path) > PATH_MAX) return glnx_throw (error, "Path '%s' is too long", path); - g_autoptr(GPtrArray) ret_components = ot_split_string_ptrarray (path, '/'); + g_autoptr (GPtrArray) ret_components = ot_split_string_ptrarray (path, '/'); /* Canonicalize by removing '.' and '', throw an error on .. */ - for (int i = ret_components->len-1; i >= 0; i--) + for (int i = ret_components->len - 1; i >= 0; i--) { const char *name = ret_components->pdata[i]; if (strcmp (name, "..") == 0) @@ -101,6 +99,6 @@ ot_util_path_split_validate (const char *path, g_ptr_array_remove_index (ret_components, i); } - ot_transfer_out_value(out_components, &ret_components); + ot_transfer_out_value (out_components, &ret_components); return TRUE; } diff --git a/src/libotutil/ot-unix-utils.h b/src/libotutil/ot-unix-utils.h index 46fb49ad..3e4be2f9 100644 --- a/src/libotutil/ot-unix-utils.h +++ b/src/libotutil/ot-unix-utils.h @@ -24,14 +24,14 @@ #include /* I just put all this shit here. Sue me. */ -#include -#include -#include -#include #include -#include +#include #include #include +#include +#include +#include +#include G_BEGIN_DECLS diff --git a/src/libotutil/ot-variant-builder.c b/src/libotutil/ot-variant-builder.c index 955bf2ee..68b3a3be 100644 --- a/src/libotutil/ot-variant-builder.c +++ b/src/libotutil/ot-variant-builder.c @@ -21,8 +21,8 @@ #include "config.h" -#include "ot-variant-builder.h" #include "libglnx/libglnx.h" +#include "ot-variant-builder.h" /***************************************************************************************** * This code is copied from gvariant in glib. With the following copyright: @@ -48,13 +48,12 @@ typedef struct _GVariantTypeInfo GVariantTypeInfo; -#define G_VARIANT_TYPE_INFO_CHAR_MAYBE 'm' -#define G_VARIANT_TYPE_INFO_CHAR_ARRAY 'a' -#define G_VARIANT_TYPE_INFO_CHAR_TUPLE '(' +#define G_VARIANT_TYPE_INFO_CHAR_MAYBE 'm' +#define G_VARIANT_TYPE_INFO_CHAR_ARRAY 'a' +#define G_VARIANT_TYPE_INFO_CHAR_TUPLE '(' #define G_VARIANT_TYPE_INFO_CHAR_DICT_ENTRY '{' -#define G_VARIANT_TYPE_INFO_CHAR_VARIANT 'v' -#define g_variant_type_info_get_type_char(info) \ - (g_variant_type_info_get_type_string(info)[0]) +#define G_VARIANT_TYPE_INFO_CHAR_VARIANT 'v' +#define g_variant_type_info_get_type_char(info) (g_variant_type_info_get_type_string (info)[0]) struct _GVariantTypeInfo { @@ -73,9 +72,9 @@ typedef struct guint8 ending_type; } GVariantMemberInfo; -#define G_VARIANT_MEMBER_ENDING_FIXED 0 -#define G_VARIANT_MEMBER_ENDING_LAST 1 -#define G_VARIANT_MEMBER_ENDING_OFFSET 2 +#define G_VARIANT_MEMBER_ENDING_FIXED 0 +#define G_VARIANT_MEMBER_ENDING_LAST 1 +#define G_VARIANT_MEMBER_ENDING_OFFSET 2 typedef struct { @@ -102,34 +101,34 @@ typedef struct /* Hard-code the base types in a constant array */ static const GVariantTypeInfo g_variant_type_info_basic_table[24] = { -#define fixed_aligned(x) x, x - 1 -#define not_a_type 0, -#define unaligned 0, 0 -#define aligned(x) 0, x - 1 - /* 'b' */ { fixed_aligned(1) }, /* boolean */ +#define fixed_aligned(x) x, x - 1 +#define not_a_type 0, +#define unaligned 0, 0 +#define aligned(x) 0, x - 1 + /* 'b' */ { fixed_aligned (1) }, /* boolean */ /* 'c' */ { not_a_type }, - /* 'd' */ { fixed_aligned(8) }, /* double */ + /* 'd' */ { fixed_aligned (8) }, /* double */ /* 'e' */ { not_a_type }, /* 'f' */ { not_a_type }, - /* 'g' */ { unaligned }, /* signature string */ - /* 'h' */ { fixed_aligned(4) }, /* file handle (int32) */ - /* 'i' */ { fixed_aligned(4) }, /* int32 */ + /* 'g' */ { unaligned }, /* signature string */ + /* 'h' */ { fixed_aligned (4) }, /* file handle (int32) */ + /* 'i' */ { fixed_aligned (4) }, /* int32 */ /* 'j' */ { not_a_type }, /* 'k' */ { not_a_type }, /* 'l' */ { not_a_type }, /* 'm' */ { not_a_type }, - /* 'n' */ { fixed_aligned(2) }, /* int16 */ - /* 'o' */ { unaligned }, /* object path string */ + /* 'n' */ { fixed_aligned (2) }, /* int16 */ + /* 'o' */ { unaligned }, /* object path string */ /* 'p' */ { not_a_type }, - /* 'q' */ { fixed_aligned(2) }, /* uint16 */ + /* 'q' */ { fixed_aligned (2) }, /* uint16 */ /* 'r' */ { not_a_type }, - /* 's' */ { unaligned }, /* string */ - /* 't' */ { fixed_aligned(8) }, /* uint64 */ - /* 'u' */ { fixed_aligned(4) }, /* uint32 */ - /* 'v' */ { aligned(8) }, /* variant */ + /* 's' */ { unaligned }, /* string */ + /* 't' */ { fixed_aligned (8) }, /* uint64 */ + /* 'u' */ { fixed_aligned (4) }, /* uint32 */ + /* 'v' */ { aligned (8) }, /* variant */ /* 'w' */ { not_a_type }, - /* 'x' */ { fixed_aligned(8) }, /* int64 */ - /* 'y' */ { fixed_aligned(1) }, /* byte */ + /* 'x' */ { fixed_aligned (8) }, /* int64 */ + /* 'y' */ { fixed_aligned (1) }, /* byte */ #undef fixed_aligned #undef not_a_type #undef unaligned @@ -139,15 +138,15 @@ static const GVariantTypeInfo g_variant_type_info_basic_table[24] = { static GRecMutex g_variant_type_info_lock; static GHashTable *g_variant_type_info_table; -static GVariantTypeInfo * g_variant_type_info_ref (GVariantTypeInfo *info); +static GVariantTypeInfo *g_variant_type_info_ref (GVariantTypeInfo *info); static void g_variant_type_info_unref (GVariantTypeInfo *info); -static GVariantTypeInfo * g_variant_type_info_get (const GVariantType *type); +static GVariantTypeInfo *g_variant_type_info_get (const GVariantType *type); #define GV_ARRAY_INFO_CLASS 'a' static ArrayInfo * GV_ARRAY_INFO (GVariantTypeInfo *info) { - return (ArrayInfo *) info; + return (ArrayInfo *)info; } static void @@ -156,7 +155,7 @@ array_info_free (GVariantTypeInfo *info) ArrayInfo *array_info; g_assert (info->container_class == GV_ARRAY_INFO_CLASS); - array_info = (ArrayInfo *) info; + array_info = (ArrayInfo *)info; g_variant_type_info_unref (array_info->element); g_slice_free (ArrayInfo, array_info); @@ -174,7 +173,7 @@ array_info_new (const GVariantType *type) info->container.info.alignment = info->element->alignment; info->container.info.fixed_size = 0; - return (ContainerInfo *) info; + return (ContainerInfo *)info; } /* == tuple == */ @@ -182,7 +181,7 @@ array_info_new (const GVariantType *type) static TupleInfo * GV_TUPLE_INFO (GVariantTypeInfo *info) { - return (TupleInfo *) info; + return (TupleInfo *)info; } static void @@ -192,20 +191,17 @@ tuple_info_free (GVariantTypeInfo *info) gint i; g_assert (info->container_class == GV_TUPLE_INFO_CLASS); - tuple_info = (TupleInfo *) info; + tuple_info = (TupleInfo *)info; for (i = 0; i < tuple_info->n_members; i++) g_variant_type_info_unref (tuple_info->members[i].type_info); - g_slice_free1 (sizeof (GVariantMemberInfo) * tuple_info->n_members, - tuple_info->members); + g_slice_free1 (sizeof (GVariantMemberInfo) * tuple_info->n_members, tuple_info->members); g_slice_free (TupleInfo, tuple_info); } static void -tuple_allocate_members (const GVariantType *type, - GVariantMemberInfo **members, - gsize *n_members) +tuple_allocate_members (const GVariantType *type, GVariantMemberInfo **members, gsize *n_members) { const GVariantType *item_type; gsize i = 0; @@ -237,10 +233,7 @@ tuple_allocate_members (const GVariantType *type, * range and %FALSE is returned if not. */ static gboolean -tuple_get_item (TupleInfo *info, - GVariantMemberInfo *item, - gsize *d, - gsize *e) +tuple_get_item (TupleInfo *info, GVariantMemberInfo *item, gsize *d, gsize *e) { if (&info->members[info->n_members] == item) return FALSE; @@ -268,11 +261,7 @@ tuple_get_item (TupleInfo *info, * computation and more compact storage. */ static void -tuple_table_append (GVariantMemberInfo **items, - gsize i, - gsize a, - gsize b, - gsize c) +tuple_table_append (GVariantMemberInfo **items, gsize i, gsize a, gsize b, gsize c) { GVariantMemberInfo *item = (*items)++; @@ -303,9 +292,8 @@ tuple_table_append (GVariantMemberInfo **items, * ends up saving us 'two pointer sizes' per item in each tuple when * allocating using GSlice. */ - a += ~b & c; /* take the "aligned" part of 'c' and add to 'a' */ - c &= b; /* chop 'c' to contain only the unaligned part */ - + a += ~b & c; /* take the "aligned" part of 'c' and add to 'a' */ + c &= b; /* chop 'c' to contain only the unaligned part */ /* Finally, we made one last adjustment. Recall: * @@ -362,8 +350,7 @@ tuple_table_append (GVariantMemberInfo **items, } static gsize -tuple_align (gsize offset, - guint alignment) +tuple_align (gsize offset, guint alignment) { return offset + ((-offset) & alignment); } @@ -418,9 +405,9 @@ tuple_generate_table (TupleInfo *info) { /* align to 'd' */ if (d <= b) - c = tuple_align (c, d); /* rule 1 */ + c = tuple_align (c, d); /* rule 1 */ else - a += tuple_align (c, b), b = d, c = 0; /* rule 2 */ + a += tuple_align (c, b), b = d, c = 0; /* rule 2 */ /* the start of the item is at this point (ie: right after we * have aligned for it). store this information in the table. @@ -438,7 +425,7 @@ tuple_generate_table (TupleInfo *info) i++, a = b = c = 0; else /* fixed size */ - c += e; /* rule 3 */ + c += e; /* rule 3 */ } } @@ -476,9 +463,8 @@ tuple_set_base_info (TupleInfo *info) * the alignment requirement (to make packing into arrays * easier) so we round up to that here. */ - base->fixed_size = - tuple_align (((m->a & m->b) | m->c) + m->type_info->fixed_size, - base->alignment); + base->fixed_size + = tuple_align (((m->a & m->b) | m->c) + m->type_info->fixed_size, base->alignment); else /* else, the tuple is not fixed size */ base->fixed_size = 0; @@ -521,12 +507,11 @@ tuple_info_new (const GVariantType *type) tuple_generate_table (info); tuple_set_base_info (info); - return (ContainerInfo *) info; + return (ContainerInfo *)info; } static const GVariantMemberInfo * -g_variant_type_info_member_info (GVariantTypeInfo *info, - gsize index) +g_variant_type_info_member_info (GVariantTypeInfo *info, gsize index) { TupleInfo *tuple_info = GV_TUPLE_INFO (info); @@ -547,7 +532,7 @@ g_variant_type_info_ref (GVariantTypeInfo *info) { if (info->container_class) { - ContainerInfo *container = (ContainerInfo *) info; + ContainerInfo *container = (ContainerInfo *)info; g_assert_cmpint (container->ref_count, >, 0); g_atomic_int_inc (&container->ref_count); @@ -561,13 +546,12 @@ g_variant_type_info_unref (GVariantTypeInfo *info) { if (info->container_class) { - ContainerInfo *container = (ContainerInfo *) info; + ContainerInfo *container = (ContainerInfo *)info; g_rec_mutex_lock (&g_variant_type_info_lock); if (g_atomic_int_dec_and_test (&container->ref_count)) { - g_hash_table_remove (g_variant_type_info_table, - container->type_string); + g_hash_table_remove (g_variant_type_info_table, container->type_string); if (g_hash_table_size (g_variant_type_info_table) == 0) { g_hash_table_unref (g_variant_type_info_table); @@ -598,10 +582,9 @@ g_variant_type_info_get (const GVariantType *type) type_char = g_variant_type_peek_string (type)[0]; - if (type_char == G_VARIANT_TYPE_INFO_CHAR_MAYBE || - type_char == G_VARIANT_TYPE_INFO_CHAR_ARRAY || - type_char == G_VARIANT_TYPE_INFO_CHAR_TUPLE || - type_char == G_VARIANT_TYPE_INFO_CHAR_DICT_ENTRY) + if (type_char == G_VARIANT_TYPE_INFO_CHAR_MAYBE || type_char == G_VARIANT_TYPE_INFO_CHAR_ARRAY + || type_char == G_VARIANT_TYPE_INFO_CHAR_TUPLE + || type_char == G_VARIANT_TYPE_INFO_CHAR_DICT_ENTRY) { GVariantTypeInfo *info; gchar *type_string; @@ -611,16 +594,15 @@ g_variant_type_info_get (const GVariantType *type) g_rec_mutex_lock (&g_variant_type_info_lock); if (g_variant_type_info_table == NULL) - g_variant_type_info_table = g_hash_table_new (g_str_hash, - g_str_equal); + g_variant_type_info_table = g_hash_table_new (g_str_hash, g_str_equal); info = g_hash_table_lookup (g_variant_type_info_table, type_string); if (info == NULL) { ContainerInfo *container; - if (type_char == G_VARIANT_TYPE_INFO_CHAR_MAYBE || - type_char == G_VARIANT_TYPE_INFO_CHAR_ARRAY) + if (type_char == G_VARIANT_TYPE_INFO_CHAR_MAYBE + || type_char == G_VARIANT_TYPE_INFO_CHAR_ARRAY) { container = array_info_new (type); } @@ -629,7 +611,7 @@ g_variant_type_info_get (const GVariantType *type) container = tuple_info_new (type); } - info = (GVariantTypeInfo *) container; + info = (GVariantTypeInfo *)container; container->type_string = type_string; container->ref_count = 1; @@ -656,14 +638,12 @@ g_variant_type_info_get (const GVariantType *type) info = g_variant_type_info_basic_table + index; - return (GVariantTypeInfo *) info; + return (GVariantTypeInfo *)info; } } static inline void -gvs_write_unaligned_le (guchar *bytes, - gsize value, - guint size) +gvs_write_unaligned_le (guchar *bytes, gsize value, guint size) { union { @@ -694,8 +674,7 @@ gvs_get_offset_size (gsize size) } static gsize -gvs_calculate_total_size (gsize body_size, - gsize offsets) +gvs_calculate_total_size (gsize body_size, gsize offsets) { if (body_size + 1 * offsets <= G_MAXUINT8) return body_size + 1 * offsets; @@ -709,14 +688,14 @@ gvs_calculate_total_size (gsize body_size, return body_size + 8 * offsets; } - /***************************************************************************************** * End of glib code *****************************************************************************************/ typedef struct _OtVariantBuilderInfo OtVariantBuilderInfo; -struct _OtVariantBuilderInfo { +struct _OtVariantBuilderInfo +{ OtVariantBuilderInfo *parent; OtVariantBuilder *builder; GVariantType *type; @@ -743,9 +722,10 @@ struct _OtVariantBuilderInfo { * (ie: maybe, array, variant) '0' if not (ie: tuple, dict entry) */ guint uniform_item_types : 1; -} ; +}; -struct _OtVariantBuilder { +struct _OtVariantBuilder +{ gint ref_count; int fd; @@ -760,7 +740,7 @@ ot_variant_builder_info_new (OtVariantBuilder *builder, const GVariantType *type { g_assert (g_variant_type_is_container (type)); - OtVariantBuilderInfo *info = (OtVariantBuilderInfo *) g_slice_new0 (OtVariantBuilderInfo); + OtVariantBuilderInfo *info = (OtVariantBuilderInfo *)g_slice_new0 (OtVariantBuilderInfo); info->builder = builder; info->type = g_variant_type_copy (type); @@ -769,7 +749,7 @@ ot_variant_builder_info_new (OtVariantBuilder *builder, const GVariantType *type info->n_children = 0; info->child_ends = g_array_new (FALSE, TRUE, sizeof (guint64)); - switch (*(const gchar *) type) + switch (*(const gchar *)type) { case G_VARIANT_CLASS_VARIANT: info->uniform_item_types = TRUE; @@ -780,24 +760,21 @@ ot_variant_builder_info_new (OtVariantBuilder *builder, const GVariantType *type case G_VARIANT_CLASS_ARRAY: info->uniform_item_types = TRUE; - info->expected_type = - g_variant_type_element (info->type); + info->expected_type = g_variant_type_element (info->type); info->min_items = 0; info->max_items = -1; break; case G_VARIANT_CLASS_MAYBE: info->uniform_item_types = TRUE; - info->expected_type = - g_variant_type_element (info->type); + info->expected_type = g_variant_type_element (info->type); info->min_items = 0; info->max_items = 1; break; case G_VARIANT_CLASS_DICT_ENTRY: info->uniform_item_types = FALSE; - info->expected_type = - g_variant_type_key (info->type); + info->expected_type = g_variant_type_key (info->type); info->min_items = 2; info->max_items = 2; break; @@ -810,8 +787,7 @@ ot_variant_builder_info_new (OtVariantBuilder *builder, const GVariantType *type break; case G_VARIANT_CLASS_TUPLE: /* a definite tuple type was given */ - info->expected_type = - g_variant_type_first (info->type); + info->expected_type = g_variant_type_first (info->type); info->min_items = g_variant_type_n_items (type); info->max_items = info->min_items; info->uniform_item_types = FALSE; @@ -819,7 +795,7 @@ ot_variant_builder_info_new (OtVariantBuilder *builder, const GVariantType *type default: g_assert_not_reached (); - } + } return info; } @@ -838,12 +814,11 @@ ot_variant_builder_info_free (OtVariantBuilderInfo *info) } OtVariantBuilder * -ot_variant_builder_new (const GVariantType *type, - int fd) +ot_variant_builder_new (const GVariantType *type, int fd) { g_assert (g_variant_type_is_container (type)); - OtVariantBuilder *builder = (OtVariantBuilder *) g_slice_new0 (OtVariantBuilder); + OtVariantBuilder *builder = (OtVariantBuilder *)g_slice_new0 (OtVariantBuilder); builder->head = ot_variant_builder_info_new (builder, type); builder->ref_count = 1; @@ -873,9 +848,7 @@ ot_variant_builder_ref (OtVariantBuilder *builder) /* This is called before adding a child to the container. It updates the internal state and does the needed alignment */ static gboolean -ot_variant_builder_pre_add (OtVariantBuilderInfo *info, - const GVariantType *type, - GError **error) +ot_variant_builder_pre_add (OtVariantBuilderInfo *info, const GVariantType *type, GError **error) { guint alignment = 0; @@ -883,12 +856,10 @@ ot_variant_builder_pre_add (OtVariantBuilderInfo *info, { /* advance our expected type pointers */ if (info->expected_type) - info->expected_type = - g_variant_type_next (info->expected_type); + info->expected_type = g_variant_type_next (info->expected_type); if (info->prev_item_type) - info->prev_item_type = - g_variant_type_next (info->prev_item_type); + info->prev_item_type = g_variant_type_next (info->prev_item_type); } else { @@ -897,8 +868,7 @@ ot_variant_builder_pre_add (OtVariantBuilderInfo *info, info->prev_item_type = info->prev_item_type_base; } - if (g_variant_type_is_tuple (info->type) || - g_variant_type_is_dict_entry (info->type)) + if (g_variant_type_is_tuple (info->type) || g_variant_type_is_dict_entry (info->type)) { const GVariantMemberInfo *member_info; @@ -941,15 +911,12 @@ ot_variant_builder_add_child_end (OtVariantBuilderInfo *info) table if needed */ static gboolean -ot_variant_builder_post_add (OtVariantBuilderInfo *info, - const GVariantType *type, - guint64 bytes_added, - GError **error) +ot_variant_builder_post_add (OtVariantBuilderInfo *info, const GVariantType *type, + guint64 bytes_added, GError **error) { info->offset += bytes_added; - if (g_variant_type_is_tuple (info->type) || - g_variant_type_is_dict_entry (info->type)) + if (g_variant_type_is_tuple (info->type) || g_variant_type_is_dict_entry (info->type)) { const GVariantMemberInfo *member_info; @@ -985,24 +952,16 @@ ot_variant_builder_post_add (OtVariantBuilderInfo *info, } gboolean -ot_variant_builder_add_from_fd (OtVariantBuilder *builder, - const GVariantType *type, - int fd, - guint64 size, - GError **error) +ot_variant_builder_add_from_fd (OtVariantBuilder *builder, const GVariantType *type, int fd, + guint64 size, GError **error) { OtVariantBuilderInfo *info = builder->head; - g_return_val_if_fail (info->n_children < info->max_items, - FALSE); - g_return_val_if_fail (!info->expected_type || - g_variant_type_is_subtype_of (type, - info->expected_type), - FALSE); - g_return_val_if_fail (!info->prev_item_type || - g_variant_type_is_subtype_of (info->prev_item_type, - type), - FALSE); + g_return_val_if_fail (info->n_children < info->max_items, FALSE); + g_return_val_if_fail ( + !info->expected_type || g_variant_type_is_subtype_of (type, info->expected_type), FALSE); + g_return_val_if_fail ( + !info->prev_item_type || g_variant_type_is_subtype_of (info->prev_item_type, type), FALSE); if (!ot_variant_builder_pre_add (info, type, error)) return FALSE; @@ -1017,25 +976,18 @@ ot_variant_builder_add_from_fd (OtVariantBuilder *builder, } gboolean -ot_variant_builder_add_value (OtVariantBuilder *builder, - GVariant *value, - GError **error) +ot_variant_builder_add_value (OtVariantBuilder *builder, GVariant *value, GError **error) { OtVariantBuilderInfo *info = builder->head; gconstpointer data; gsize data_size; /* We ref-sink value, just like g_variant_builder_add_value does */ - g_autoptr(GVariant) keep_around_until_return G_GNUC_UNUSED = g_variant_ref_sink (value); + g_autoptr (GVariant) keep_around_until_return G_GNUC_UNUSED = g_variant_ref_sink (value); - g_return_val_if_fail (info->n_children < info->max_items, + g_return_val_if_fail (info->n_children < info->max_items, FALSE); + g_return_val_if_fail (!info->expected_type || g_variant_is_of_type (value, info->expected_type), FALSE); - g_return_val_if_fail (!info->expected_type || - g_variant_is_of_type (value, - info->expected_type), - FALSE); - g_return_val_if_fail (!info->prev_item_type || - g_variant_is_of_type (value, - info->prev_item_type), + g_return_val_if_fail (!info->prev_item_type || g_variant_is_of_type (value, info->prev_item_type), FALSE); if (!ot_variant_builder_pre_add (info, g_variant_get_type (value), error)) @@ -1057,10 +1009,7 @@ ot_variant_builder_add_value (OtVariantBuilder *builder, } gboolean -ot_variant_builder_add (OtVariantBuilder *builder, - GError **error, - const gchar *format_string, - ...) +ot_variant_builder_add (OtVariantBuilder *builder, GError **error, const gchar *format_string, ...) { GVariant *variant; va_list ap; @@ -1072,21 +1021,14 @@ ot_variant_builder_add (OtVariantBuilder *builder, return ot_variant_builder_add_value (builder, variant, error); } - gboolean -ot_variant_builder_open (OtVariantBuilder *builder, - const GVariantType *type, - GError **error) +ot_variant_builder_open (OtVariantBuilder *builder, const GVariantType *type, GError **error) { OtVariantBuilderInfo *info = builder->head; g_assert (info->n_children < info->max_items); - g_assert (!info->expected_type || - g_variant_type_is_subtype_of (type, - info->expected_type)); - g_assert (!info->prev_item_type || - g_variant_type_is_subtype_of (info->prev_item_type, - type)); + g_assert (!info->expected_type || g_variant_type_is_subtype_of (type, info->expected_type)); + g_assert (!info->prev_item_type || g_variant_type_is_subtype_of (info->prev_item_type, type)); if (!ot_variant_builder_pre_add (info, type, error)) return FALSE; @@ -1101,13 +1043,11 @@ ot_variant_builder_open (OtVariantBuilder *builder, { if (!new_info->uniform_item_types) /* tuples and dict entries */ - new_info->prev_item_type = - g_variant_type_first (info->prev_item_type); + new_info->prev_item_type = g_variant_type_first (info->prev_item_type); else if (!g_variant_type_is_variant (new_info->type)) /* maybes and arrays */ - new_info->prev_item_type = - g_variant_type_element (info->prev_item_type); + new_info->prev_item_type = g_variant_type_element (info->prev_item_type); } builder->head = new_info; @@ -1115,8 +1055,7 @@ ot_variant_builder_open (OtVariantBuilder *builder, } gboolean -ot_variant_builder_close (OtVariantBuilder *builder, - GError **error) +ot_variant_builder_close (OtVariantBuilder *builder, GError **error) { OtVariantBuilderInfo *info = builder->head; OtVariantBuilderInfo *parent; @@ -1140,22 +1079,18 @@ ot_variant_builder_close (OtVariantBuilder *builder, } gboolean -ot_variant_builder_end (OtVariantBuilder *builder, - GError **error) +ot_variant_builder_end (OtVariantBuilder *builder, GError **error) { OtVariantBuilderInfo *info = builder->head; gboolean add_offset_table = FALSE; gboolean reverse_offset_table = FALSE; - g_return_val_if_fail (info->n_children >= info->min_items, - FALSE); - g_return_val_if_fail (!info->uniform_item_types || - info->prev_item_type != NULL || - g_variant_type_is_definite (info->type), + g_return_val_if_fail (info->n_children >= info->min_items, FALSE); + g_return_val_if_fail (!info->uniform_item_types || info->prev_item_type != NULL + || g_variant_type_is_definite (info->type), FALSE); - if (g_variant_type_is_tuple (info->type) || - g_variant_type_is_dict_entry (info->type)) + if (g_variant_type_is_tuple (info->type) || g_variant_type_is_dict_entry (info->type)) { add_offset_table = TRUE; reverse_offset_table = TRUE; diff --git a/src/libotutil/ot-variant-builder.h b/src/libotutil/ot-variant-builder.h index ed59eeea..4acda3f3 100644 --- a/src/libotutil/ot-variant-builder.h +++ b/src/libotutil/ot-variant-builder.h @@ -29,32 +29,19 @@ G_BEGIN_DECLS typedef struct _OtVariantBuilder OtVariantBuilder; -OtVariantBuilder *ot_variant_builder_new (const GVariantType *type, - int fd); -void ot_variant_builder_unref (OtVariantBuilder *builder); -OtVariantBuilder *ot_variant_builder_ref (OtVariantBuilder *builder); -gboolean ot_variant_builder_end (OtVariantBuilder *builder, - GError **error); -gboolean ot_variant_builder_open (OtVariantBuilder *builder, - const GVariantType *type, - GError **error); -gboolean ot_variant_builder_close (OtVariantBuilder *builder, - GError **error); -gboolean ot_variant_builder_add_from_fd (OtVariantBuilder *builder, - const GVariantType *type, - int fd, - guint64 size, - GError **error); -gboolean ot_variant_builder_add_value (OtVariantBuilder *builder, - GVariant *value, - GError **error); -gboolean ot_variant_builder_add (OtVariantBuilder *builder, - GError **error, - const gchar *format_string, - ...); -void ot_variant_builder_add_parsed (OtVariantBuilder *builder, - const gchar *format, - ...); +OtVariantBuilder *ot_variant_builder_new (const GVariantType *type, int fd); +void ot_variant_builder_unref (OtVariantBuilder *builder); +OtVariantBuilder *ot_variant_builder_ref (OtVariantBuilder *builder); +gboolean ot_variant_builder_end (OtVariantBuilder *builder, GError **error); +gboolean ot_variant_builder_open (OtVariantBuilder *builder, const GVariantType *type, + GError **error); +gboolean ot_variant_builder_close (OtVariantBuilder *builder, GError **error); +gboolean ot_variant_builder_add_from_fd (OtVariantBuilder *builder, const GVariantType *type, + int fd, guint64 size, GError **error); +gboolean ot_variant_builder_add_value (OtVariantBuilder *builder, GVariant *value, GError **error); +gboolean ot_variant_builder_add (OtVariantBuilder *builder, GError **error, + const gchar *format_string, ...); +void ot_variant_builder_add_parsed (OtVariantBuilder *builder, const gchar *format, ...); G_DEFINE_AUTOPTR_CLEANUP_FUNC (OtVariantBuilder, ot_variant_builder_unref) diff --git a/src/libotutil/ot-variant-utils.c b/src/libotutil/ot-variant-utils.c index 29b64357..32e8e0be 100644 --- a/src/libotutil/ot-variant-utils.c +++ b/src/libotutil/ot-variant-utils.c @@ -21,8 +21,8 @@ #include "config.h" -#include #include +#include #include @@ -32,20 +32,18 @@ GVariant * ot_gvariant_new_empty_string_dict (void) { - g_auto(GVariantBuilder) builder = OT_VARIANT_BUILDER_INITIALIZER; + g_auto (GVariantBuilder) builder = OT_VARIANT_BUILDER_INITIALIZER; g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); return g_variant_builder_end (&builder); } - /* Create a new GVariant of type ay from the raw @data pointer */ GVariant * -ot_gvariant_new_bytearray (const guchar *data, - gsize len) +ot_gvariant_new_bytearray (const guchar *data, gsize len) { gpointer data_copy = g_memdup2 (data, len); - GVariant *ret = g_variant_new_from_data (G_VARIANT_TYPE ("ay"), data_copy, - len, FALSE, g_free, data_copy); + GVariant *ret + = g_variant_new_from_data (G_VARIANT_TYPE ("ay"), data_copy, len, FALSE, g_free, data_copy); return ret; } @@ -56,8 +54,8 @@ ot_gvariant_new_ay_bytes (GBytes *bytes) gsize size; gconstpointer data = g_bytes_get_data (bytes, &size); g_bytes_ref (bytes); - return g_variant_new_from_data (G_VARIANT_TYPE ("ay"), data, size, - TRUE, (GDestroyNotify)g_bytes_unref, bytes); + return g_variant_new_from_data (G_VARIANT_TYPE ("ay"), data, size, TRUE, + (GDestroyNotify)g_bytes_unref, bytes); } /* Create a GVariant in @out_variant that is backed by @@ -66,14 +64,10 @@ ot_gvariant_new_ay_bytes (GBytes *bytes) * by the GVariant core; see g_variant_new_from_data(). */ gboolean -ot_variant_read_fd (int fd, - goffset start, - const GVariantType *type, - gboolean trusted, - GVariant **out_variant, - GError **error) +ot_variant_read_fd (int fd, goffset start, const GVariantType *type, gboolean trusted, + GVariant **out_variant, GError **error) { - g_autoptr(GBytes) bytes = ot_fd_readall_or_mmap (fd, start, error); + g_autoptr (GBytes) bytes = ot_fd_readall_or_mmap (fd, start, error); if (!bytes) return FALSE; @@ -85,8 +79,7 @@ ot_variant_read_fd (int fd, * for a new variant, inherting the data from @variant. */ GVariantBuilder * -ot_util_variant_builder_from_variant (GVariant *variant, - const GVariantType *type) +ot_util_variant_builder_from_variant (GVariant *variant, const GVariantType *type) { GVariantBuilder *builder = g_variant_builder_new (type); @@ -95,7 +88,7 @@ ot_util_variant_builder_from_variant (GVariant *variant, const int n = g_variant_n_children (variant); for (int i = 0; i < n; i++) { - g_autoptr(GVariant) child = g_variant_get_child_value (variant, i); + g_autoptr (GVariant) child = g_variant_get_child_value (variant, i); g_variant_builder_add_value (builder, child); } } @@ -116,9 +109,7 @@ ot_util_variant_builder_from_variant (GVariant *variant, * Returns: %TRUE if found, %FALSE otherwise */ gboolean -ot_variant_bsearch_str (GVariant *array, - const char *str, - int *out_pos) +ot_variant_bsearch_str (GVariant *array, const char *str, int *out_pos) { const gsize n = g_variant_n_children (array); if (n == 0) @@ -133,7 +124,7 @@ ot_variant_bsearch_str (GVariant *array, imid = (imin + imax) / 2; - g_autoptr(GVariant) child = g_variant_get_child_value (array, imid); + g_autoptr (GVariant) child = g_variant_get_child_value (array, imid); g_variant_get_child (child, 0, "&s", &cur, NULL); int cmp = strcmp (cur, str); diff --git a/src/libotutil/ot-variant-utils.h b/src/libotutil/ot-variant-utils.h index b12682ed..7556a212 100644 --- a/src/libotutil/ot-variant-utils.h +++ b/src/libotutil/ot-variant-utils.h @@ -25,26 +25,17 @@ G_BEGIN_DECLS -GVariant *ot_gvariant_new_bytearray (const guchar *data, - gsize len); +GVariant *ot_gvariant_new_bytearray (const guchar *data, gsize len); GVariant *ot_gvariant_new_ay_bytes (GBytes *bytes); GVariant *ot_gvariant_new_empty_string_dict (void); -gboolean ot_variant_read_fd (int fd, - goffset offset, - const GVariantType *type, - gboolean trusted, - GVariant **out_variant, - GError **error); +gboolean ot_variant_read_fd (int fd, goffset offset, const GVariantType *type, gboolean trusted, + GVariant **out_variant, GError **error); -GVariantBuilder *ot_util_variant_builder_from_variant (GVariant *variant, - const GVariantType *type); +GVariantBuilder *ot_util_variant_builder_from_variant (GVariant *variant, const GVariantType *type); -gboolean -ot_variant_bsearch_str (GVariant *array, - const char *str, - int *out_pos); +gboolean ot_variant_bsearch_str (GVariant *array, const char *str, int *out_pos); G_END_DECLS diff --git a/src/libotutil/otutil.h b/src/libotutil/otutil.h index 4279bc15..27f84103 100644 --- a/src/libotutil/otutil.h +++ b/src/libotutil/otutil.h @@ -22,9 +22,9 @@ #pragma once #include +#include #include /* Yeah...let's just do that here. */ #include -#include #ifdef HAVE_LIBSYSTEMD #include @@ -32,9 +32,21 @@ /* https://bugzilla.gnome.org/show_bug.cgi?id=766370 */ #if !GLIB_CHECK_VERSION(2, 49, 3) -#define OT_VARIANT_BUILDER_INITIALIZER {{0,}} +#define OT_VARIANT_BUILDER_INITIALIZER \ + { \ + { \ + 0, \ + } \ + } #else -#define OT_VARIANT_BUILDER_INITIALIZER {{{0,}}} +#define OT_VARIANT_BUILDER_INITIALIZER \ + { \ + { \ + { \ + 0, \ + } \ + } \ + } #endif static inline const char * @@ -45,20 +57,27 @@ ot_booltostr (int b) #define ot_gobject_refz(o) (o ? g_object_ref (o) : o) -#define ot_transfer_out_value(outp, srcp) G_STMT_START { \ - if (outp) \ - { \ - *outp = *srcp; \ - *(srcp) = NULL; \ - } \ - } G_STMT_END; +#define ot_transfer_out_value(outp, srcp) \ + G_STMT_START \ + { \ + if (outp) \ + { \ + *outp = *srcp; \ + *(srcp) = NULL; \ + } \ + } \ + G_STMT_END; #ifdef HAVE_LIBSYSTEMD -#define ot_journal_send(...) sd_journal_send(__VA_ARGS__) -#define ot_journal_print(...) sd_journal_print(__VA_ARGS__) +#define ot_journal_send(...) sd_journal_send (__VA_ARGS__) +#define ot_journal_print(...) sd_journal_print (__VA_ARGS__) #else -#define ot_journal_send(...) {} -#define ot_journal_print(...) {} +#define ot_journal_send(...) \ + { \ + } +#define ot_journal_print(...) \ + { \ + } #endif typedef GMainContext GMainContextPopDefault; @@ -85,17 +104,16 @@ _ostree_main_context_new_default (void) G_DEFINE_AUTOPTR_CLEANUP_FUNC (GMainContextPopDefault, _ostree_main_context_pop_default_destroy) - -#include -#include +#include +#include #include +#include +#include #include +#include #include -#include #include -#include -#include -#include +#include #ifndef OSTREE_DISABLE_GPGME #include diff --git a/src/libotutil/zbase32.c b/src/libotutil/zbase32.c index b92168b4..acd8a920 100644 --- a/src/libotutil/zbase32.c +++ b/src/libotutil/zbase32.c @@ -7,116 +7,133 @@ #include "zbase32.h" #include -#include -#include #include /* XXX only for debug printfs */ +#include +#include -static const char*const chars="ybndrfg8ejkmcpqxot1uwisza345h769"; +static const char *const chars = "ybndrfg8ejkmcpqxot1uwisza345h769"; /* Types from zstr */ /** * A zstr is simply an unsigned int length and a pointer to a buffer of * unsigned chars. */ -typedef struct { - size_t len; /* the length of the string (not counting the null-terminating character) */ - unsigned char* buf; /* pointer to the first byte */ +typedef struct +{ + size_t len; /* the length of the string (not counting the null-terminating character) */ + unsigned char *buf; /* pointer to the first byte */ } zstr; /** * A zstr is simply an unsigned int length and a pointer to a buffer of * const unsigned chars. */ -typedef struct { - size_t len; /* the length of the string (not counting the null-terminating character) */ - const unsigned char* buf; /* pointer to the first byte */ +typedef struct +{ + size_t len; /* the length of the string (not counting the null-terminating character) */ + const unsigned char *buf; /* pointer to the first byte */ } czstr; /* Functions from zstr */ static zstr -new_z(const size_t len) +new_z (const size_t len) { - zstr result; - result.buf = (unsigned char *)malloc(len+1); - if (result.buf == NULL) { - result.len = 0; - return result; - } - result.len = len; - result.buf[len] = '\0'; - return result; + zstr result; + result.buf = (unsigned char *)malloc (len + 1); + if (result.buf == NULL) + { + result.len = 0; + return result; + } + result.len = len; + result.buf[len] = '\0'; + return result; } /* Functions from zutil */ static size_t -divceil(size_t n, size_t d) +divceil (size_t n, size_t d) { - return n/d+((n%d)!=0); + return n / d + ((n % d) != 0); } -static zstr b2a_l_extra_Duffy(const czstr os, const size_t lengthinbits) +static zstr +b2a_l_extra_Duffy (const czstr os, const size_t lengthinbits) { - zstr result = new_z(divceil(os.len*8, 5)); /* if lengthinbits is not a multiple of 8 then this is allocating space for 0, 1, or 2 extra quintets that will be truncated at the end of this function if they are not needed */ - if (result.buf == NULL) - return result; + zstr result = new_z ( + divceil (os.len * 8, 5)); /* if lengthinbits is not a multiple of 8 then this is allocating + space for 0, 1, or 2 extra quintets that will be truncated at + the end of this function if they are not needed */ + if (result.buf == NULL) + return result; - unsigned char* resp = result.buf + result.len; /* pointer into the result buffer, initially pointing to the "one-past-the-end" quintet */ - const unsigned char* osp = os.buf + os.len; /* pointer into the os buffer, initially pointing to the "one-past-the-end" octet */ + unsigned char *resp = result.buf + result.len; /* pointer into the result buffer, initially + pointing to the "one-past-the-end" quintet */ + const unsigned char *osp = os.buf + os.len; /* pointer into the os buffer, initially pointing to + the "one-past-the-end" octet */ - /* Now this is a real live Duff's device. You gotta love it. */ - unsigned long x=0; /* to hold up to 32 bits worth of the input */ - switch ((osp - os.buf) % 5) { - case 0: - do { - x = *--osp; - *--resp = chars[x % 32]; /* The least sig 5 bits go into the final quintet. */ - x /= 32; /* ... now we have 3 bits worth in x... */ - case 4: - x |= ((unsigned long)(*--osp)) << 3; /* ... now we have 11 bits worth in x... */ - *--resp = chars[x % 32]; - x /= 32; /* ... now we have 6 bits worth in x... */ - *--resp = chars[x % 32]; - x /= 32; /* ... now we have 1 bits worth in x... */ - case 3: - x |= ((unsigned long)(*--osp)) << 1; /* The 8 bits from the 2-indexed octet. So now we have 9 bits worth in x... */ - *--resp = chars[x % 32]; - x /= 32; /* ... now we have 4 bits worth in x... */ - case 2: - x |= ((unsigned long)(*--osp)) << 4; /* The 8 bits from the 1-indexed octet. So now we have 12 bits worth in x... */ - *--resp = chars[x%32]; - x /= 32; /* ... now we have 7 bits worth in x... */ - *--resp = chars[x%32]; - x /= 32; /* ... now we have 2 bits worth in x... */ - case 1: - x |= ((unsigned long)(*--osp)) << 2; /* The 8 bits from the 0-indexed octet. So now we have 10 bits worth in x... */ - *--resp = chars[x%32]; - x /= 32; /* ... now we have 5 bits worth in x... */ - *--resp = chars[x]; - } while (osp > os.buf); - } /* switch ((osp - os.buf) % 5) */ + /* Now this is a real live Duff's device. You gotta love it. */ + unsigned long x = 0; /* to hold up to 32 bits worth of the input */ + switch ((osp - os.buf) % 5) + { + case 0: + do + { + x = *--osp; + *--resp = chars[x % 32]; /* The least sig 5 bits go into the final quintet. */ + x /= 32; /* ... now we have 3 bits worth in x... */ + case 4: + x |= ((unsigned long)(*--osp)) << 3; /* ... now we have 11 bits worth in x... */ + *--resp = chars[x % 32]; + x /= 32; /* ... now we have 6 bits worth in x... */ + *--resp = chars[x % 32]; + x /= 32; /* ... now we have 1 bits worth in x... */ + case 3: + x |= ((unsigned long)(*--osp)) << 1; /* The 8 bits from the 2-indexed octet. So now we + have 9 bits worth in x... */ + *--resp = chars[x % 32]; + x /= 32; /* ... now we have 4 bits worth in x... */ + case 2: + x |= ((unsigned long)(*--osp)) << 4; /* The 8 bits from the 1-indexed octet. So now we + have 12 bits worth in x... */ + *--resp = chars[x % 32]; + x /= 32; /* ... now we have 7 bits worth in x... */ + *--resp = chars[x % 32]; + x /= 32; /* ... now we have 2 bits worth in x... */ + case 1: + x |= ((unsigned long)(*--osp)) << 2; /* The 8 bits from the 0-indexed octet. So now we + have 10 bits worth in x... */ + *--resp = chars[x % 32]; + x /= 32; /* ... now we have 5 bits worth in x... */ + *--resp = chars[x]; + } + while (osp > os.buf); + } /* switch ((osp - os.buf) % 5) */ - /* truncate any unused trailing zero quintets */ - result.len = divceil(lengthinbits, 5); - result.buf[result.len] = '\0'; - return result; + /* truncate any unused trailing zero quintets */ + result.len = divceil (lengthinbits, 5); + result.buf[result.len] = '\0'; + return result; } -static zstr b2a_l(const czstr os, const size_t lengthinbits) +static zstr +b2a_l (const czstr os, const size_t lengthinbits) { - return b2a_l_extra_Duffy(os, lengthinbits); + return b2a_l_extra_Duffy (os, lengthinbits); } -static zstr b2a(const czstr os) +static zstr +b2a (const czstr os) { - return b2a_l(os, os.len*8); + return b2a_l (os, os.len * 8); } char * -zbase32_encode(const unsigned char *data, size_t length) +zbase32_encode (const unsigned char *data, size_t length) { - czstr input = { length, data }; - zstr output = b2a(input); - return (char *)output.buf; + czstr input = { length, data }; + zstr output = b2a (input); + return (char *)output.buf; } /** diff --git a/src/libotutil/zbase32.h b/src/libotutil/zbase32.h index 162a2c7e..f5d27b45 100644 --- a/src/libotutil/zbase32.h +++ b/src/libotutil/zbase32.h @@ -7,12 +7,12 @@ #ifndef __INCL_base32_h #define __INCL_base32_h -static char const* const base32_h_cvsid = "$Id: base32.h,v 1.11 2003/12/15 01:16:19 zooko Exp $"; +static char const *const base32_h_cvsid = "$Id: base32.h,v 1.11 2003/12/15 01:16:19 zooko Exp $"; static int const base32_vermaj = 0; static int const base32_vermin = 9; static int const base32_vermicro = 12; -static char const* const base32_vernum = "0.9.12"; +static char const *const base32_vernum = "0.9.12"; #include #include @@ -23,7 +23,7 @@ static char const* const base32_vernum = "0.9.12"; * * @return an allocated string containing the zbase-32 encoded representation */ -char *zbase32_encode(const unsigned char *data, size_t length); +char *zbase32_encode (const unsigned char *data, size_t length); #endif /* #ifndef __INCL_base32_h */ diff --git a/src/ostree/main.c b/src/ostree/main.c index 0b886c1f..edb8a7a0 100644 --- a/src/ostree/main.c +++ b/src/ostree/main.c @@ -35,99 +35,55 @@ static OstreeCommand commands[] = { * admin command may have their own * admin flag */ - { "admin", OSTREE_BUILTIN_FLAG_NO_REPO, - ostree_builtin_admin, + { "admin", OSTREE_BUILTIN_FLAG_NO_REPO, ostree_builtin_admin, "Commands for managing a host system booted with ostree" }, - { "cat", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_cat, - "Concatenate contents of files"}, - { "checkout", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_checkout, + { "cat", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_cat, "Concatenate contents of files" }, + { "checkout", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_checkout, "Check out a commit into a filesystem tree" }, - { "checksum", OSTREE_BUILTIN_FLAG_NO_REPO, - ostree_builtin_checksum, + { "checksum", OSTREE_BUILTIN_FLAG_NO_REPO, ostree_builtin_checksum, "Checksum a file or directory" }, - { "commit", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_commit, - "Commit a new revision" }, - { "config", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_config, + { "commit", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_commit, "Commit a new revision" }, + { "config", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_config, "Change repo configuration settings" }, - { "diff", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_diff, - "Compare directory TARGETDIR against revision REV"}, - { "export", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_export, + { "diff", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_diff, + "Compare directory TARGETDIR against revision REV" }, + { "export", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_export, "Stream COMMIT to stdout in tar format" }, - { "find-remotes", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_find_remotes, + { "find-remotes", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_find_remotes, "Find remotes to serve the given refs" }, - { "create-usb", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_create_usb, + { "create-usb", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_create_usb, "Copy the refs to a USB stick" }, - { "fsck", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_fsck, - "Check the repository for consistency" }, + { "fsck", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_fsck, "Check the repository for consistency" }, #ifndef OSTREE_DISABLE_GPGME - { "gpg-sign", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_gpg_sign, - "Sign a commit" }, + { "gpg-sign", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_gpg_sign, "Sign a commit" }, #endif /* OSTREE_DISABLE_GPGME */ - { "init", OSTREE_BUILTIN_FLAG_NO_CHECK, - ostree_builtin_init, + { "init", OSTREE_BUILTIN_FLAG_NO_CHECK, ostree_builtin_init, "Initialize a new empty repository" }, - { "log", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_log, - "Show log starting at commit or ref" }, - { "ls", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_ls, - "List file paths" }, - { "prune", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_prune, - "Search for unreachable objects" }, - { "pull-local", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_pull_local, - "Copy data from SRC_REPO" }, + { "log", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_log, "Show log starting at commit or ref" }, + { "ls", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_ls, "List file paths" }, + { "prune", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_prune, "Search for unreachable objects" }, + { "pull-local", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_pull_local, "Copy data from SRC_REPO" }, #ifdef HAVE_LIBCURL_OR_LIBSOUP - { "pull", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_pull, - "Download data from remote repository" }, + { "pull", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_pull, "Download data from remote repository" }, #endif - { "refs", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_refs, - "List refs" }, - { "remote", OSTREE_BUILTIN_FLAG_NO_REPO, - ostree_builtin_remote, + { "refs", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_refs, "List refs" }, + { "remote", OSTREE_BUILTIN_FLAG_NO_REPO, ostree_builtin_remote, "Remote commands that may involve internet access" }, - { "reset", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_reset, - "Reset a REF to a previous COMMIT" }, - { "rev-parse", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_rev_parse, - "Output the target of a rev" }, - { "sign", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_sign, - "Sign a commit" }, - { "show", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_show, - "Output a metadata object" }, - { "static-delta", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_static_delta, + { "reset", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_reset, "Reset a REF to a previous COMMIT" }, + { "rev-parse", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_rev_parse, "Output the target of a rev" }, + { "sign", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_sign, "Sign a commit" }, + { "show", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_show, "Output a metadata object" }, + { "static-delta", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_static_delta, "Static delta related commands" }, - { "summary", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_summary, - "Manage summary metadata" }, + { "summary", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_summary, "Manage summary metadata" }, #if defined(HAVE_LIBSOUP_OR_LIBSOUP3) && defined(BUILDOPT_ENABLE_TRIVIAL_HTTPD_CMDLINE) - { "trivial-httpd", OSTREE_BUILTIN_FLAG_NONE, - ostree_builtin_trivial_httpd, - NULL }, + { "trivial-httpd", OSTREE_BUILTIN_FLAG_NONE, ostree_builtin_trivial_httpd, NULL }, #endif { NULL } }; int -main (int argc, - char **argv) +main (int argc, char **argv) { g_assert (argc > 0); diff --git a/src/ostree/ostree-trivial-httpd.c b/src/ostree/ostree-trivial-httpd.c index 855d2cea..facc1527 100644 --- a/src/ostree/ostree-trivial-httpd.c +++ b/src/ostree/ostree-trivial-httpd.c @@ -23,28 +23,31 @@ #include -#include "ot-main.h" -#include "ot-builtins.h" #include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" #include "otutil.h" -#include #include -#include -#include +#include #include +#include +#include -#if ! SOUP_CHECK_VERSION (3, 0, 0) -# define SoupServerMessage SoupMessage -# define soup_server_message_get_method(msg) ((msg)->method) -# define soup_server_message_get_request_headers(msg) ((msg)->request_headers) -# define soup_server_message_get_response_headers(msg) ((msg)->response_headers) -# define soup_server_message_get_response_body(msg) ((msg)->response_body) -# define soup_server_message_set_status(msg, status) soup_message_set_status(msg, status) -# define soup_server_message_set_redirect(msg, status, uri) soup_message_set_redirect(msg, status, uri) -# define soup_server_message_set_response(msg, ct, ru, rb, rl) soup_message_set_response(msg, ct, ru, rb, rl) +#if !SOUP_CHECK_VERSION(3, 0, 0) +#define SoupServerMessage SoupMessage +#define soup_server_message_get_method(msg) ((msg)->method) +#define soup_server_message_get_request_headers(msg) ((msg)->request_headers) +#define soup_server_message_get_response_headers(msg) ((msg)->response_headers) +#define soup_server_message_get_response_body(msg) ((msg)->response_body) +#define soup_server_message_set_status(msg, status) soup_message_set_status (msg, status) +#define soup_server_message_set_redirect(msg, status, uri) \ + soup_message_set_redirect (msg, status, uri) +#define soup_server_message_set_response(msg, ct, ru, rb, rl) \ + soup_message_set_response (msg, ct, ru, rb, rl) #else -# define soup_server_message_set_status(msg, status) soup_server_message_set_status(msg, status, NULL) +#define soup_server_message_set_status(msg, status) \ + soup_server_message_set_status (msg, status, NULL) #endif static char *opt_port_file = NULL; @@ -66,7 +69,8 @@ static gboolean opt_require_basic_auth; static guint emitted_random_500s_count = 0; static guint emitted_random_408s_count = 0; -typedef struct { +typedef struct +{ int root_dfd; gboolean running; GOutputStream *log; @@ -77,30 +81,41 @@ typedef struct { * man page (man/ostree-trivial-httpd.xml) when changing the option list. */ -static GOptionEntry options[] = { - { "daemonize", 'd', 0, G_OPTION_ARG_NONE, &opt_daemonize, "Fork into background when ready", NULL }, - { "autoexit", 0, 0, G_OPTION_ARG_NONE, &opt_autoexit, "Automatically exit when directory is deleted", NULL }, - { "port", 'P', 0, G_OPTION_ARG_INT, &opt_port, "Use the specified TCP port", "PORT" }, - { "port-file", 'p', 0, G_OPTION_ARG_FILENAME, &opt_port_file, "Write port number to PATH (- for standard output)", "PATH" }, - { "force-range-requests", 0, 0, G_OPTION_ARG_NONE, &opt_force_ranges, "Force range requests by only serving half of files", NULL }, - { "require-basic-auth", 0, 0, G_OPTION_ARG_NONE, &opt_require_basic_auth, "Require username foouser, password barpw", NULL }, - { "random-500s", 0, 0, G_OPTION_ARG_INT, &opt_random_500s_percentage, "Generate random HTTP 500 errors approximately for PERCENTAGE requests", "PERCENTAGE" }, - { "random-500s-max", 0, 0, G_OPTION_ARG_INT, &opt_random_500s_max, "Limit HTTP 500 errors to MAX (default 100)", "MAX" }, - { "random-408s", 0, 0, G_OPTION_ARG_INT, &opt_random_408s_percentage, "Generate random HTTP 408 errors approximately for PERCENTAGE requests", "PERCENTAGE" }, - { "random-408s-max", 0, 0, G_OPTION_ARG_INT, &opt_random_408s_max, "Limit HTTP 408 errors to MAX (default 100)", "MAX" }, - { "log-file", 0, 0, G_OPTION_ARG_FILENAME, &opt_log, "Put logs here (use - for stdout)", "PATH" }, - { "expected-cookies", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_expected_cookies, "Expect given cookies in the http request", "KEY=VALUE" }, - { "expected-header", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_expected_headers, "Expect given headers in the http request", "KEY=VALUE" }, - { NULL } -}; - -static void -httpd_log (OtTrivialHttpd *httpd, const gchar *format, ...) __attribute__ ((format(printf, 2, 3))); +static GOptionEntry options[] + = { { "daemonize", 'd', 0, G_OPTION_ARG_NONE, &opt_daemonize, "Fork into background when ready", + NULL }, + { "autoexit", 0, 0, G_OPTION_ARG_NONE, &opt_autoexit, + "Automatically exit when directory is deleted", NULL }, + { "port", 'P', 0, G_OPTION_ARG_INT, &opt_port, "Use the specified TCP port", "PORT" }, + { "port-file", 'p', 0, G_OPTION_ARG_FILENAME, &opt_port_file, + "Write port number to PATH (- for standard output)", "PATH" }, + { "force-range-requests", 0, 0, G_OPTION_ARG_NONE, &opt_force_ranges, + "Force range requests by only serving half of files", NULL }, + { "require-basic-auth", 0, 0, G_OPTION_ARG_NONE, &opt_require_basic_auth, + "Require username foouser, password barpw", NULL }, + { "random-500s", 0, 0, G_OPTION_ARG_INT, &opt_random_500s_percentage, + "Generate random HTTP 500 errors approximately for PERCENTAGE requests", "PERCENTAGE" }, + { "random-500s-max", 0, 0, G_OPTION_ARG_INT, &opt_random_500s_max, + "Limit HTTP 500 errors to MAX (default 100)", "MAX" }, + { "random-408s", 0, 0, G_OPTION_ARG_INT, &opt_random_408s_percentage, + "Generate random HTTP 408 errors approximately for PERCENTAGE requests", "PERCENTAGE" }, + { "random-408s-max", 0, 0, G_OPTION_ARG_INT, &opt_random_408s_max, + "Limit HTTP 408 errors to MAX (default 100)", "MAX" }, + { "log-file", 0, 0, G_OPTION_ARG_FILENAME, &opt_log, "Put logs here (use - for stdout)", + "PATH" }, + { "expected-cookies", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_expected_cookies, + "Expect given cookies in the http request", "KEY=VALUE" }, + { "expected-header", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_expected_headers, + "Expect given headers in the http request", "KEY=VALUE" }, + { NULL } }; + +static void httpd_log (OtTrivialHttpd *httpd, const gchar *format, ...) + __attribute__ ((format (printf, 2, 3))); static void httpd_log (OtTrivialHttpd *httpd, const gchar *format, ...) { - g_autoptr(GString) str = NULL; + g_autoptr (GString) str = NULL; va_list args; gsize written; @@ -108,7 +123,7 @@ httpd_log (OtTrivialHttpd *httpd, const gchar *format, ...) return; { - g_autoptr(GDateTime) now = g_date_time_new_now_local (); + g_autoptr (GDateTime) now = g_date_time_new_now_local (); g_autofree char *timestamp = g_date_time_format (now, "%F %T"); str = g_string_new (timestamp); g_string_append_printf (str, ".%06d - ", g_date_time_get_microsecond (now)); @@ -131,12 +146,13 @@ compare_strings (gconstpointer a, gconstpointer b) } static GString * -get_directory_listing (int dfd, - const char *path) +get_directory_listing (int dfd, const char *path) { - g_autoptr(GPtrArray) entries = g_ptr_array_new_with_free_func (g_free); - g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; - g_autoptr(GError) local_error = NULL; + g_autoptr (GPtrArray) entries = g_ptr_array_new_with_free_func (g_free); + g_auto (GLnxDirFdIterator) dfd_iter = { + 0, + }; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; guint i; char *escaped; @@ -169,13 +185,12 @@ get_directory_listing (int dfd, g_free (escaped); for (i = 0; i < entries->len; i++) { - g_string_append_printf (listing, "%s
\r\n", - (char *)entries->pdata[i], + g_string_append_printf (listing, "%s
\r\n", (char *)entries->pdata[i], (char *)entries->pdata[i]); g_free (g_steal_pointer (&entries->pdata[i])); } g_string_append (listing, "\r\n\r\n"); - out: +out: if (local_error) g_printerr ("%s\n", local_error->message); return listing; @@ -218,7 +233,7 @@ close_socket (SoupServerMessage *msg, gpointer user_data) static gchar * calculate_etag (GMappedFile *mapping) { - g_autoptr(GBytes) bytes = g_mapped_file_get_bytes (mapping); + g_autoptr (GBytes) bytes = g_mapped_file_get_bytes (mapping); g_autofree gchar *checksum = g_compute_checksum_for_bytes (G_CHECKSUM_SHA256, bytes); return g_strconcat ("\"", checksum, "\"", NULL); } @@ -234,12 +249,11 @@ _server_cookies_from_request (SoupServerMessage *msg) const char *header; const char *host; - header = soup_message_headers_get_one (soup_server_message_get_request_headers (msg), - "Cookie"); + header = soup_message_headers_get_one (soup_server_message_get_request_headers (msg), "Cookie"); if (!header) return NULL; -#if ! SOUP_CHECK_VERSION (3, 0, 0) +#if !SOUP_CHECK_VERSION(3, 0, 0) host = soup_uri_get_host (soup_message_get_uri (msg)); #else host = g_uri_get_host (soup_server_message_get_uri (msg)); @@ -249,7 +263,8 @@ _server_cookies_from_request (SoupServerMessage *msg) while (g_hash_table_iter_next (&iter, &name, &value)) { - if (!name || !value) continue; + if (!name || !value) + continue; cookie = soup_cookie_new (name, value, host, NULL, 0); cookies = g_slist_prepend (cookies, cookie); } @@ -260,17 +275,11 @@ _server_cookies_from_request (SoupServerMessage *msg) } static void -#if ! SOUP_CHECK_VERSION (3, 0, 0) -do_get (OtTrivialHttpd *self, - SoupServer *server, - SoupServerMessage *msg, - const char *path, +#if !SOUP_CHECK_VERSION(3, 0, 0) +do_get (OtTrivialHttpd *self, SoupServer *server, SoupServerMessage *msg, const char *path, SoupClientContext *context) #else -do_get (OtTrivialHttpd *self, - SoupServer *server, - SoupServerMessage *msg, - const char *path) +do_get (OtTrivialHttpd *self, SoupServer *server, SoupServerMessage *msg, const char *path) #endif { char *slash; @@ -285,18 +294,18 @@ do_get (OtTrivialHttpd *self, GSList *l; int i; - for (i = 0 ; opt_expected_cookies[i] != NULL; i++) + for (i = 0; opt_expected_cookies[i] != NULL; i++) { gboolean found = FALSE; gchar *k = opt_expected_cookies[i]; gchar *v = strchr (k, '=') + 1; - for (l = cookies; l != NULL ; l = g_slist_next (l)) + for (l = cookies; l != NULL; l = g_slist_next (l)) { SoupCookie *c = l->data; - if (!strncmp (k, soup_cookie_get_name (c), v - k - 1) && - !strcmp (v, soup_cookie_get_value (c))) + if (!strncmp (k, soup_cookie_get_name (c), v - k - 1) + && !strcmp (v, soup_cookie_get_value (c))) { found = TRUE; break; @@ -316,7 +325,7 @@ do_get (OtTrivialHttpd *self, if (opt_expected_headers) { - for (int i = 0 ; opt_expected_headers[i] != NULL; i++) + for (int i = 0; opt_expected_headers[i] != NULL; i++) { const gchar *kv = opt_expected_headers[i]; const gchar *eq = strchr (kv, '='); @@ -326,7 +335,8 @@ do_get (OtTrivialHttpd *self, { g_autofree char *k = g_strndup (kv, eq - kv); const gchar *expected_v = eq + 1; - const gchar *found_v = soup_message_headers_get_one (soup_server_message_get_request_headers (msg), k); + const gchar *found_v + = soup_message_headers_get_one (soup_server_message_get_request_headers (msg), k); if (!found_v) { @@ -350,17 +360,15 @@ do_get (OtTrivialHttpd *self, goto out; } - if (opt_random_500s_percentage > 0 && - emitted_random_500s_count < opt_random_500s_max && - g_random_int_range (0, 100) < opt_random_500s_percentage) + if (opt_random_500s_percentage > 0 && emitted_random_500s_count < opt_random_500s_max + && g_random_int_range (0, 100) < opt_random_500s_percentage) { emitted_random_500s_count++; soup_server_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR); goto out; } - else if (opt_random_408s_percentage > 0 && - emitted_random_408s_count < opt_random_408s_max && - g_random_int_range (0, 100) < opt_random_408s_percentage) + else if (opt_random_408s_percentage > 0 && emitted_random_408s_count < opt_random_408s_max + && g_random_int_range (0, 100) < opt_random_408s_percentage) { emitted_random_408s_count++; soup_server_message_set_status (msg, SOUP_STATUS_REQUEST_TIMEOUT); @@ -397,13 +405,12 @@ do_get (OtTrivialHttpd *self, { g_autofree char *redir_uri = NULL; -#if ! SOUP_CHECK_VERSION (3, 0, 0) +#if !SOUP_CHECK_VERSION(3, 0, 0) redir_uri = g_strdup_printf ("%s/", soup_uri_get_path (soup_message_get_uri (msg))); #else redir_uri = g_strdup_printf ("%s/", g_uri_get_path (soup_server_message_get_uri (msg))); #endif - soup_server_message_set_redirect (msg, SOUP_STATUS_MOVED_PERMANENTLY, - redir_uri); + soup_server_message_set_redirect (msg, SOUP_STATUS_MOVED_PERMANENTLY, redir_uri); } else { @@ -411,7 +418,7 @@ do_get (OtTrivialHttpd *self, if (fstatat (self->root_dfd, index_realpath, &stbuf, 0) != -1) { g_autofree char *index_path = g_strconcat (path, "/index.html", NULL); -#if ! SOUP_CHECK_VERSION (3, 0, 0) +#if !SOUP_CHECK_VERSION(3, 0, 0) do_get (self, server, msg, index_path, context); #else do_get (self, server, msg, index_path); @@ -420,9 +427,8 @@ do_get (OtTrivialHttpd *self, else { GString *listing = get_directory_listing (self->root_dfd, path); - soup_server_message_set_response (msg, "text/html", - SOUP_MEMORY_TAKE, - listing->str, listing->len); + soup_server_message_set_response (msg, "text/html", SOUP_MEMORY_TAKE, listing->str, + listing->len); soup_server_message_set_status (msg, SOUP_STATUS_OK); g_string_free (listing, FALSE); } @@ -443,20 +449,23 @@ do_get (OtTrivialHttpd *self, goto out; } - g_autoptr(GMappedFile) mapping = g_mapped_file_new_from_fd (fd, FALSE, NULL); + g_autoptr (GMappedFile) mapping = g_mapped_file_new_from_fd (fd, FALSE, NULL); if (!mapping) { soup_server_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR); goto out; } - (void) close (fd); fd = -1; + (void)close (fd); + fd = -1; /* Send caching headers */ - g_autoptr(GDateTime) last_modified = g_date_time_new_from_unix_utc (stbuf.st_mtim.tv_sec); + g_autoptr (GDateTime) last_modified = g_date_time_new_from_unix_utc (stbuf.st_mtim.tv_sec); if (last_modified != NULL) { - g_autofree gchar *formatted = g_date_time_format (last_modified, "%a, %d %b %Y %H:%M:%S GMT"); - soup_message_headers_append (soup_server_message_get_response_headers (msg), "Last-Modified", formatted); + g_autofree gchar *formatted + = g_date_time_format (last_modified, "%a, %d %b %Y %H:%M:%S GMT"); + soup_message_headers_append (soup_server_message_get_response_headers (msg), + "Last-Modified", formatted); } g_autofree gchar *etag = calculate_etag (mapping); @@ -471,12 +480,14 @@ do_get (OtTrivialHttpd *self, gboolean have_ranges; file_size = g_mapped_file_get_length (mapping); - have_ranges = soup_message_headers_get_ranges(soup_server_message_get_request_headers (msg), file_size, &ranges, &ranges_length); + have_ranges = soup_message_headers_get_ranges ( + soup_server_message_get_request_headers (msg), file_size, &ranges, &ranges_length); if (opt_force_ranges && !have_ranges && g_strrstr (path, "/objects") != NULL) { GSocket *sock; - buffer_length = file_size/2; - soup_message_headers_set_content_length (soup_server_message_get_response_headers (msg), file_size); + buffer_length = file_size / 2; + soup_message_headers_set_content_length ( + soup_server_message_get_response_headers (msg), file_size); soup_message_headers_append (soup_server_message_get_response_headers (msg), "Connection", "close"); @@ -485,7 +496,7 @@ do_get (OtTrivialHttpd *self, * the declared Content-Length. Instead, we * forcibly close the socket at that point. */ -#if ! SOUP_CHECK_VERSION (3, 0, 0) +#if !SOUP_CHECK_VERSION(3, 0, 0) sock = soup_client_context_get_gsocket (context); #else sock = soup_server_message_get_socket (msg); @@ -500,19 +511,20 @@ do_get (OtTrivialHttpd *self, if (ranges_length > 0 && ranges[0].start >= file_size) { soup_server_message_set_status (msg, SOUP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE); - soup_message_headers_free_ranges (soup_server_message_get_request_headers (msg), ranges); + soup_message_headers_free_ranges (soup_server_message_get_request_headers (msg), + ranges); goto out; } - soup_message_headers_free_ranges (soup_server_message_get_request_headers (msg), ranges); + soup_message_headers_free_ranges (soup_server_message_get_request_headers (msg), + ranges); } -#if ! SOUP_CHECK_VERSION (3, 0, 0) +#if !SOUP_CHECK_VERSION(3, 0, 0) if (buffer_length > 0) { SoupBuffer *buffer; buffer = soup_buffer_new_with_owner (g_mapped_file_get_contents (mapping), - buffer_length, - g_mapped_file_ref (mapping), + buffer_length, g_mapped_file_ref (mapping), (GDestroyNotify)g_mapped_file_unref); soup_message_body_append_buffer (msg->response_body, buffer); soup_buffer_free (buffer); @@ -546,10 +558,10 @@ do_get (OtTrivialHttpd *self, } /* Check client’s caching headers. */ - const gchar *if_modified_since = soup_message_headers_get_one (soup_server_message_get_request_headers (msg), - "If-Modified-Since"); - const gchar *if_none_match = soup_message_headers_get_one (soup_server_message_get_request_headers (msg), - "If-None-Match"); + const gchar *if_modified_since = soup_message_headers_get_one ( + soup_server_message_get_request_headers (msg), "If-Modified-Since"); + const gchar *if_none_match = soup_message_headers_get_one ( + soup_server_message_get_request_headers (msg), "If-None-Match"); if (if_none_match != NULL && etag != NULL) { @@ -565,18 +577,19 @@ do_get (OtTrivialHttpd *self, } else if (if_modified_since != NULL && last_modified != NULL) { - g_autoptr(GDateTime) if_modified_since_dt = NULL; -#if ! SOUP_CHECK_VERSION (3, 0, 0) + g_autoptr (GDateTime) if_modified_since_dt = NULL; +#if !SOUP_CHECK_VERSION(3, 0, 0) SoupDate *if_modified_since_sd = soup_date_new_from_string (if_modified_since); if (if_modified_since_sd != NULL) - if_modified_since_dt = g_date_time_new_from_unix_utc (soup_date_to_time_t (if_modified_since_sd)); + if_modified_since_dt + = g_date_time_new_from_unix_utc (soup_date_to_time_t (if_modified_since_sd)); #else if_modified_since_dt = soup_date_time_new_from_http_string (if_modified_since); #endif - if (if_modified_since_dt != NULL && - g_date_time_compare (last_modified, if_modified_since_dt) <= 0) + if (if_modified_since_dt != NULL + && g_date_time_compare (last_modified, if_modified_since_dt) <= 0) { soup_server_message_set_status (msg, SOUP_STATUS_NOT_MODIFIED); soup_message_body_truncate (soup_server_message_get_response_body (msg)); @@ -591,16 +604,13 @@ do_get (OtTrivialHttpd *self, soup_server_message_set_status (msg, SOUP_STATUS_OK); } } - out: +out: { -#if ! SOUP_CHECK_VERSION (3, 0, 0) +#if !SOUP_CHECK_VERSION(3, 0, 0) guint status = 0; g_autofree gchar *reason = NULL; - g_object_get (msg, - "status-code", &status, - "reason-phrase", &reason, - NULL); + g_object_get (msg, "status-code", &status, "reason-phrase", &reason, NULL); #else guint status = soup_server_message_get_status (msg); const char *reason = soup_server_message_get_reason_phrase (msg); @@ -612,20 +622,19 @@ do_get (OtTrivialHttpd *self, } static void -#if ! SOUP_CHECK_VERSION (3, 0, 0) -httpd_callback (SoupServer *server, SoupServerMessage *msg, - const char *path, GHashTable *query, +#if !SOUP_CHECK_VERSION(3, 0, 0) +httpd_callback (SoupServer *server, SoupServerMessage *msg, const char *path, GHashTable *query, SoupClientContext *context, gpointer data) #else -httpd_callback (SoupServer *server, SoupServerMessage *msg, - const char *path, GHashTable *query, gpointer data) +httpd_callback (SoupServer *server, SoupServerMessage *msg, const char *path, GHashTable *query, + gpointer data) #endif { OtTrivialHttpd *self = data; const char *meth = soup_server_message_get_method (msg); - if (!strcmp (meth, "GET") || !strcmp(meth, "HEAD")) -#if ! SOUP_CHECK_VERSION (3, 0, 0) + if (!strcmp (meth, "GET") || !strcmp (meth, "HEAD")) +#if !SOUP_CHECK_VERSION(3, 0, 0) do_get (self, server, msg, path, context); #else do_get (self, server, msg, path); @@ -635,17 +644,14 @@ httpd_callback (SoupServer *server, SoupServerMessage *msg, } static gboolean -basic_auth_callback (SoupAuthDomain *auth_domain, SoupServerMessage *msg, - const char *username, const char *password, gpointer data) +basic_auth_callback (SoupAuthDomain *auth_domain, SoupServerMessage *msg, const char *username, + const char *password, gpointer data) { - return g_str_equal (username, "foouser") && g_str_equal (password, "barpw"); + return g_str_equal (username, "foouser") && g_str_equal (password, "barpw"); } static void -on_dir_changed (GFileMonitor *mon, - GFile *file, - GFile *other, - GFileMonitorEvent event, +on_dir_changed (GFileMonitor *mon, GFile *file, GFile *other, GFileMonitorEvent event, gpointer user_data) { OtTrivialHttpd *self = user_data; @@ -662,13 +668,15 @@ static gboolean run (int argc, char **argv, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; - g_autoptr(GOptionContext) context = NULL; + g_autoptr (GOptionContext) context = NULL; const char *dirpath; - OtTrivialHttpd appstruct = { 0, }; + OtTrivialHttpd appstruct = { + 0, + }; OtTrivialHttpd *app = &appstruct; int pipefd[2] = { -1, -1 }; glnx_unref_object SoupServer *server = NULL; - g_autoptr(GFileMonitor) dirmon = NULL; + g_autoptr (GFileMonitor) dirmon = NULL; context = g_option_context_new ("[DIR] - Simple webserver"); g_option_context_add_main_entries (context, options, NULL); @@ -688,21 +696,22 @@ run (int argc, char **argv, GCancellable *cancellable, GError **error) if (!(opt_random_500s_percentage >= 0 && opt_random_500s_percentage <= 99)) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Invalid --random-500s=%u", opt_random_500s_percentage); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid --random-500s=%u", + opt_random_500s_percentage); goto out; } if (!(opt_random_408s_percentage >= 0 && opt_random_408s_percentage <= 99)) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Invalid --random-408s=%u", opt_random_408s_percentage); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid --random-408s=%u", + opt_random_408s_percentage); goto out; } if (opt_daemonize && (g_strcmp0 (opt_log, "-") == 0)) { - ot_util_usage_error (context, "Cannot use --log-file=- and --daemonize at the same time", error); + ot_util_usage_error (context, "Cannot use --log-file=- and --daemonize at the same time", + error); goto out; } @@ -719,7 +728,7 @@ run (int argc, char **argv, GCancellable *cancellable, GError **error) goto out; } - pid_t pid = fork(); + pid_t pid = fork (); if (pid == -1) { glnx_set_error_from_errno (error); @@ -784,14 +793,11 @@ run (int argc, char **argv, GCancellable *cancellable, GError **error) } else { - g_autoptr(GFile) log_file = NULL; - GFileOutputStream* log_stream; + g_autoptr (GFile) log_file = NULL; + GFileOutputStream *log_stream; log_file = g_file_new_for_path (opt_log); - log_stream = g_file_create (log_file, - G_FILE_CREATE_PRIVATE, - cancellable, - error); + log_stream = g_file_create (log_file, G_FILE_CREATE_PRIVATE, cancellable, error); if (!log_stream) goto out; stream = G_OUTPUT_STREAM (log_stream); @@ -805,22 +811,19 @@ run (int argc, char **argv, GCancellable *cancellable, GError **error) if (!soup_server_listen_all (server, opt_port, 0, error)) goto out; #else - server = soup_server_new (SOUP_SERVER_PORT, opt_port, - SOUP_SERVER_SERVER_HEADER, "ostree-httpd ", + server = soup_server_new (SOUP_SERVER_PORT, opt_port, SOUP_SERVER_SERVER_HEADER, "ostree-httpd ", NULL); #endif if (opt_require_basic_auth) { -#if ! SOUP_CHECK_VERSION (3, 0, 0) - glnx_unref_object SoupAuthDomain *auth_domain = - soup_auth_domain_basic_new (SOUP_AUTH_DOMAIN_REALM, "auth-test", - SOUP_AUTH_DOMAIN_ADD_PATH, "/", - SOUP_AUTH_DOMAIN_BASIC_AUTH_CALLBACK, basic_auth_callback, - NULL); +#if !SOUP_CHECK_VERSION(3, 0, 0) + glnx_unref_object SoupAuthDomain *auth_domain = soup_auth_domain_basic_new ( + SOUP_AUTH_DOMAIN_REALM, "auth-test", SOUP_AUTH_DOMAIN_ADD_PATH, "/", + SOUP_AUTH_DOMAIN_BASIC_AUTH_CALLBACK, basic_auth_callback, NULL); #else - glnx_unref_object SoupAuthDomain *auth_domain = - soup_auth_domain_basic_new ("realm", "auth-test", NULL); + glnx_unref_object SoupAuthDomain *auth_domain + = soup_auth_domain_basic_new ("realm", "auth-test", NULL); soup_auth_domain_add_path (auth_domain, "/"); soup_auth_domain_basic_set_auth_callback (auth_domain, basic_auth_callback, NULL, NULL); #endif @@ -833,8 +836,8 @@ run (int argc, char **argv, GCancellable *cancellable, GError **error) g_autofree char *portstr = NULL; #if SOUP_CHECK_VERSION(2, 48, 0) GSList *listeners = soup_server_get_listeners (server); - g_autoptr(GSocket) listener = NULL; - g_autoptr(GSocketAddress) addr = NULL; + g_autoptr (GSocket) listener = NULL; + g_autoptr (GSocketAddress) addr = NULL; g_assert (listeners); listener = g_object_ref (listeners->data); @@ -846,7 +849,8 @@ run (int argc, char **argv, GCancellable *cancellable, GError **error) g_assert (G_IS_INET_SOCKET_ADDRESS (addr)); - portstr = g_strdup_printf ("%u\n", g_inet_socket_address_get_port ((GInetSocketAddress*)addr)); + portstr + = g_strdup_printf ("%u\n", g_inet_socket_address_get_port ((GInetSocketAddress *)addr)); #else portstr = g_strdup_printf ("%u\n", soup_server_get_port (server)); #endif @@ -881,17 +885,17 @@ run (int argc, char **argv, GCancellable *cancellable, GError **error) goto out; } /* Daemonising: close stdout/stderr so $() et al work on us */ - if (freopen("/dev/null", "r", stdin) == NULL) + if (freopen ("/dev/null", "r", stdin) == NULL) { glnx_set_prefix_error_from_errno (error, "%s", "freopen: "); goto out; } - if (freopen("/dev/null", "w", stdout) == NULL) + if (freopen ("/dev/null", "w", stdout) == NULL) { glnx_set_prefix_error_from_errno (error, "%s", "freopen: "); goto out; } - if (freopen("/dev/null", "w", stderr) == NULL) + if (freopen ("/dev/null", "w", stderr) == NULL) { glnx_set_prefix_error_from_errno (error, "%s", "freopen: "); goto out; @@ -902,14 +906,12 @@ run (int argc, char **argv, GCancellable *cancellable, GError **error) if (opt_autoexit) { gboolean is_symlink = FALSE; - g_autoptr(GFile) root = NULL; - g_autoptr(GFileInfo) info = NULL; + g_autoptr (GFile) root = NULL; + g_autoptr (GFileInfo) info = NULL; root = g_file_new_for_path (dirpath); - info = g_file_query_info (root, - G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - cancellable, error); + info = g_file_query_info (root, G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!info) goto out; @@ -929,7 +931,7 @@ run (int argc, char **argv, GCancellable *cancellable, GError **error) g_main_context_iteration (NULL, TRUE); ret = TRUE; - out: +out: if (pipefd[0] >= 0) { /* Read end in the parent. This should only be open on errors. */ @@ -942,21 +944,20 @@ run (int argc, char **argv, GCancellable *cancellable, GError **error) g_assert_false (ret); guint8 buf = 1; g_debug ("Writing %u to parent", buf); - (void) TEMP_FAILURE_RETRY (write (pipefd[1], &buf, 1)); + (void)TEMP_FAILURE_RETRY (write (pipefd[1], &buf, 1)); glnx_close_fd (&pipefd[1]); } if (app->root_dfd != -1) - (void) close (app->root_dfd); + (void)close (app->root_dfd); g_clear_object (&app->log); return ret; } int -main (int argc, - char **argv) +main (int argc, char **argv) { - g_autoptr(GError) error = NULL; - g_autoptr(GCancellable) cancellable = NULL; + g_autoptr (GError) error = NULL; + g_autoptr (GCancellable) cancellable = NULL; setlocale (LC_ALL, ""); @@ -964,10 +965,8 @@ main (int argc, if (!run (argc, argv, cancellable, &error)) { - g_printerr ("%s%serror:%s%s %s\n", - ot_get_red_start (), ot_get_bold_start (), - ot_get_bold_end (), ot_get_red_end (), - error->message); + g_printerr ("%s%serror:%s%s %s\n", ot_get_red_start (), ot_get_bold_start (), + ot_get_bold_end (), ot_get_red_end (), error->message); return 1; } diff --git a/src/ostree/ot-admin-builtin-boot-complete.c b/src/ostree/ot-admin-builtin-boot-complete.c index 5d50c028..4599606c 100644 --- a/src/ostree/ot-admin-builtin-boot-complete.c +++ b/src/ostree/ot-admin-builtin-boot-complete.c @@ -21,20 +21,19 @@ #include -#include "ot-main.h" +#include "ostree.h" #include "ot-admin-builtins.h" #include "ot-admin-functions.h" -#include "ostree.h" +#include "ot-main.h" #include "otutil.h" #include "ostree-cmd-private.h" -static GOptionEntry options[] = { - { NULL } -}; +static GOptionEntry options[] = { { NULL } }; gboolean -ot_admin_builtin_boot_complete (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_builtin_boot_complete (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { /* Just a sanity check; we shouldn't be called outside of the service though. */ @@ -44,14 +43,14 @@ ot_admin_builtin_boot_complete (int argc, char **argv, OstreeCommandInvocation * // We must have been invoked via systemd which should have set up a mount namespace. g_assert (getenv ("INVOCATION_ID")); - g_autoptr(GOptionContext) context = g_option_context_new (""); - g_autoptr(OstreeSysroot) sysroot = NULL; + g_autoptr (GOptionContext) context = g_option_context_new (""); + g_autoptr (OstreeSysroot) sysroot = NULL; if (!ostree_admin_option_context_parse (context, options, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, - invocation, &sysroot, cancellable, error)) + OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, invocation, &sysroot, + cancellable, error)) return FALSE; - if (!ostree_cmd__private__()->ostree_boot_complete (sysroot, cancellable, error)) + if (!ostree_cmd__private__ ()->ostree_boot_complete (sysroot, cancellable, error)) return FALSE; return TRUE; diff --git a/src/ostree/ot-admin-builtin-cleanup.c b/src/ostree/ot-admin-builtin-cleanup.c index 94d3224c..b2d34231 100644 --- a/src/ostree/ot-admin-builtin-cleanup.c +++ b/src/ostree/ot-admin-builtin-cleanup.c @@ -21,26 +21,25 @@ #include "config.h" -#include "ot-main.h" +#include "ostree.h" #include "ot-admin-builtins.h" #include "ot-admin-functions.h" -#include "ostree.h" +#include "ot-main.h" #include -static GOptionEntry options[] = { - { NULL } -}; +static GOptionEntry options[] = { { NULL } }; gboolean -ot_admin_builtin_cleanup (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_builtin_cleanup (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new (""); + g_autoptr (GOptionContext) context = g_option_context_new (""); - g_autoptr(OstreeSysroot) sysroot = NULL; + g_autoptr (OstreeSysroot) sysroot = NULL; if (!ostree_admin_option_context_parse (context, options, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, - invocation, &sysroot, cancellable, error)) + OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, invocation, &sysroot, + cancellable, error)) return FALSE; if (!ostree_sysroot_cleanup (sysroot, cancellable, error)) diff --git a/src/ostree/ot-admin-builtin-deploy.c b/src/ostree/ot-admin-builtin-deploy.c index 28a5d9e8..00204ffd 100644 --- a/src/ostree/ot-admin-builtin-deploy.c +++ b/src/ostree/ot-admin-builtin-deploy.c @@ -23,10 +23,10 @@ #include "ostree-sysroot-private.h" -#include "ot-main.h" +#include "ostree.h" #include "ot-admin-builtins.h" #include "ot-admin-functions.h" -#include "ostree.h" +#include "ot-main.h" #include "otutil.h" #include @@ -49,35 +49,51 @@ static gboolean opt_kernel_arg_none; static char **opt_overlay_initrds; static GOptionEntry options[] = { - { "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Use a different operating system root than the current one", "OSNAME" }, - { "origin-file", 0, 0, G_OPTION_ARG_FILENAME, &opt_origin_path, "Specify origin file", "FILENAME" }, - { "no-prune", 0, 0, G_OPTION_ARG_NONE, &opt_no_prune, "Don't prune the repo when done", NULL}, - { "no-merge", 0, 0, G_OPTION_ARG_NONE, &opt_no_merge, "Do not apply configuration (/etc and kernel arguments) from booted deployment", NULL}, + { "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, + "Use a different operating system root than the current one", "OSNAME" }, + { "origin-file", 0, 0, G_OPTION_ARG_FILENAME, &opt_origin_path, "Specify origin file", + "FILENAME" }, + { "no-prune", 0, 0, G_OPTION_ARG_NONE, &opt_no_prune, "Don't prune the repo when done", NULL }, + { "no-merge", 0, 0, G_OPTION_ARG_NONE, &opt_no_merge, + "Do not apply configuration (/etc and kernel arguments) from booted deployment", NULL }, { "retain", 0, 0, G_OPTION_ARG_NONE, &opt_retain, "Do not delete previous deployments", NULL }, { "stage", 0, 0, G_OPTION_ARG_NONE, &opt_stage, "Complete deployment at OS shutdown", NULL }, - { "lock-finalization", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_lock_finalization, "Prevent automatic deployment finalization on shutdown", NULL }, - { "retain-pending", 0, 0, G_OPTION_ARG_NONE, &opt_retain_pending, "Do not delete pending deployments", NULL }, - { "retain-rollback", 0, 0, G_OPTION_ARG_NONE, &opt_retain_rollback, "Do not delete rollback deployments", NULL }, - { "not-as-default", 0, 0, G_OPTION_ARG_NONE, &opt_not_as_default, "Append rather than prepend new deployment", NULL }, - { "karg-proc-cmdline", 0, 0, G_OPTION_ARG_NONE, &opt_kernel_proc_cmdline, "Import current /proc/cmdline", NULL }, - { "karg", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_kernel_argv, "Set kernel argument, like root=/dev/sda1; this overrides any earlier argument with the same name", "NAME=VALUE" }, - { "karg-append", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_kernel_argv_append, "Append kernel argument; useful with e.g. console= that can be used multiple times", "NAME=VALUE" }, - { "karg-none", 0, 0, G_OPTION_ARG_NONE, &opt_kernel_arg_none, "Do not import kernel arguments", NULL }, - { "karg-delete", 0, 0, G_OPTION_ARG_STRING, &opt_kernel_argv_delete, "Delete kernel argument if exists", "NAME=VALUE" }, - { "overlay-initrd", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_overlay_initrds, "Overlay iniramfs file", "FILE" }, + { "lock-finalization", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_lock_finalization, + "Prevent automatic deployment finalization on shutdown", NULL }, + { "retain-pending", 0, 0, G_OPTION_ARG_NONE, &opt_retain_pending, + "Do not delete pending deployments", NULL }, + { "retain-rollback", 0, 0, G_OPTION_ARG_NONE, &opt_retain_rollback, + "Do not delete rollback deployments", NULL }, + { "not-as-default", 0, 0, G_OPTION_ARG_NONE, &opt_not_as_default, + "Append rather than prepend new deployment", NULL }, + { "karg-proc-cmdline", 0, 0, G_OPTION_ARG_NONE, &opt_kernel_proc_cmdline, + "Import current /proc/cmdline", NULL }, + { "karg", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_kernel_argv, + "Set kernel argument, like root=/dev/sda1; this overrides any earlier argument with the same " + "name", + "NAME=VALUE" }, + { "karg-append", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_kernel_argv_append, + "Append kernel argument; useful with e.g. console= that can be used multiple times", + "NAME=VALUE" }, + { "karg-none", 0, 0, G_OPTION_ARG_NONE, &opt_kernel_arg_none, "Do not import kernel arguments", + NULL }, + { "karg-delete", 0, 0, G_OPTION_ARG_STRING, &opt_kernel_argv_delete, + "Delete kernel argument if exists", "NAME=VALUE" }, + { "overlay-initrd", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_overlay_initrds, + "Overlay iniramfs file", "FILE" }, { NULL } }; gboolean -ot_admin_builtin_deploy (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_builtin_deploy (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = - g_option_context_new ("REFSPEC"); + g_autoptr (GOptionContext) context = g_option_context_new ("REFSPEC"); - g_autoptr(OstreeSysroot) sysroot = NULL; + g_autoptr (OstreeSysroot) sysroot = NULL; if (!ostree_admin_option_context_parse (context, options, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, - invocation, &sysroot, cancellable, error)) + OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, invocation, &sysroot, + cancellable, error)) return FALSE; if (argc < 2) @@ -88,7 +104,8 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeCommandInvocation *invocat if (opt_kernel_proc_cmdline && opt_kernel_arg_none) { - ot_util_usage_error (context, "Can't specify both --karg-proc-cmdline and --karg-none", error); + ot_util_usage_error (context, "Can't specify both --karg-proc-cmdline and --karg-none", + error); return FALSE; } @@ -111,11 +128,10 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeCommandInvocation *invocat /* Find the currently booted deployment, if any; we will ensure it * is present in the new deployment list. */ - if (!ot_admin_require_booted_deployment_or_osname (sysroot, opt_osname, - cancellable, error)) + if (!ot_admin_require_booted_deployment_or_osname (sysroot, opt_osname, cancellable, error)) return glnx_prefix_error (error, "Looking for booted deployment"); - g_autoptr(GKeyFile) origin = NULL; + g_autoptr (GKeyFile) origin = NULL; if (opt_origin_path) { origin = g_key_file_new (); @@ -132,8 +148,8 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeCommandInvocation *invocat if (!ostree_repo_resolve_rev (repo, refspec, FALSE, &revision, error)) return FALSE; - g_autoptr(OstreeDeployment) merge_deployment = - opt_no_merge ? NULL : ostree_sysroot_get_merge_deployment (sysroot, opt_osname); + g_autoptr (OstreeDeployment) merge_deployment + = opt_no_merge ? NULL : ostree_sysroot_get_merge_deployment (sysroot, opt_osname); /* Here we perform cleanup of any leftover data from previous * partial failures. This avoids having to call @@ -148,7 +164,7 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeCommandInvocation *invocat /* Initial set of kernel arguments; the default is to use the merge * deployment, unless --karg-none or --karg-proc-cmdline are specified. */ - g_autoptr(OstreeKernelArgs) kargs = NULL; + g_autoptr (OstreeKernelArgs) kargs = NULL; if (opt_kernel_arg_none) { kargs = ostree_kernel_args_new (); @@ -159,10 +175,12 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeCommandInvocation *invocat if (!ostree_kernel_args_append_proc_cmdline (kargs, cancellable, error)) return FALSE; } - else if (merge_deployment && (opt_kernel_argv || opt_kernel_argv_append || opt_kernel_argv_delete)) + else if (merge_deployment + && (opt_kernel_argv || opt_kernel_argv_append || opt_kernel_argv_delete)) { OstreeBootconfigParser *bootconfig = ostree_deployment_get_bootconfig (merge_deployment); - g_auto(GStrv) previous_args = g_strsplit (ostree_bootconfig_parser_get (bootconfig, "options"), " ", -1); + g_auto (GStrv) previous_args + = g_strsplit (ostree_bootconfig_parser_get (bootconfig, "options"), " ", -1); kargs = ostree_kernel_args_new (); ostree_kernel_args_append_argv (kargs, previous_args); } @@ -191,7 +209,7 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeCommandInvocation *invocat return FALSE; } - g_autoptr(GPtrArray) overlay_initrd_chksums = NULL; + g_autoptr (GPtrArray) overlay_initrd_chksums = NULL; for (char **it = opt_overlay_initrds; it && *it; it++) { const char *path = *it; @@ -212,14 +230,14 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeCommandInvocation *invocat if (overlay_initrd_chksums) g_ptr_array_add (overlay_initrd_chksums, NULL); - g_auto(GStrv) kargs_strv = kargs ? ostree_kernel_args_to_strv (kargs) : NULL; + g_auto (GStrv) kargs_strv = kargs ? ostree_kernel_args_to_strv (kargs) : NULL; OstreeSysrootDeployTreeOpts opts = { .override_kernel_argv = kargs_strv, - .overlay_initrds = overlay_initrd_chksums ? (char**)overlay_initrd_chksums->pdata : NULL, + .overlay_initrds = overlay_initrd_chksums ? (char **)overlay_initrd_chksums->pdata : NULL, }; - g_autoptr(OstreeDeployment) new_deployment = NULL; + g_autoptr (OstreeDeployment) new_deployment = NULL; if (opt_stage) { if (opt_retain_pending || opt_retain_rollback) @@ -243,16 +261,15 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeCommandInvocation *invocat /* use old API if we can to exercise it in CI */ if (!overlay_initrd_chksums) { - if (!ostree_sysroot_stage_tree (sysroot, opt_osname, revision, origin, - merge_deployment, kargs_strv, &new_deployment, - cancellable, error)) + if (!ostree_sysroot_stage_tree (sysroot, opt_osname, revision, origin, merge_deployment, + kargs_strv, &new_deployment, cancellable, error)) return FALSE; } else { - if (!ostree_sysroot_stage_tree_with_options (sysroot, opt_osname, revision, - origin, merge_deployment, &opts, - &new_deployment, cancellable, error)) + if (!ostree_sysroot_stage_tree_with_options (sysroot, opt_osname, revision, origin, + merge_deployment, &opts, &new_deployment, + cancellable, error)) return FALSE; } g_assert (new_deployment); @@ -262,22 +279,21 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeCommandInvocation *invocat /* use old API if we can to exercise it in CI */ if (!overlay_initrd_chksums) { - if (!ostree_sysroot_deploy_tree (sysroot, opt_osname, revision, origin, - merge_deployment, kargs_strv, &new_deployment, - cancellable, error)) + if (!ostree_sysroot_deploy_tree (sysroot, opt_osname, revision, origin, merge_deployment, + kargs_strv, &new_deployment, cancellable, error)) return FALSE; } else { - if (!ostree_sysroot_deploy_tree_with_options (sysroot, opt_osname, revision, - origin, merge_deployment, &opts, - &new_deployment, cancellable, - error)) + if (!ostree_sysroot_deploy_tree_with_options (sysroot, opt_osname, revision, origin, + merge_deployment, &opts, &new_deployment, + cancellable, error)) return FALSE; } g_assert (new_deployment); - OstreeSysrootSimpleWriteDeploymentFlags flags = OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NO_CLEAN; + OstreeSysrootSimpleWriteDeploymentFlags flags + = OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NO_CLEAN; if (opt_retain) flags |= OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN; else diff --git a/src/ostree/ot-admin-builtin-diff.c b/src/ostree/ot-admin-builtin-diff.c index 73e49d4e..8a123a22 100644 --- a/src/ostree/ot-admin-builtin-diff.c +++ b/src/ostree/ot-admin-builtin-diff.c @@ -21,58 +21,59 @@ #include "config.h" -#include "ot-main.h" +#include "ostree.h" #include "ot-admin-builtins.h" #include "ot-admin-functions.h" -#include "ostree.h" +#include "ot-main.h" #include static char *opt_osname; -static GOptionEntry options[] = { - { "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Use a different operating system root than the current one", "OSNAME" }, - { NULL } -}; +static GOptionEntry options[] + = { { "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, + "Use a different operating system root than the current one", "OSNAME" }, + { NULL } }; gboolean -ot_admin_builtin_diff (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_builtin_diff (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new (""); + g_autoptr (GOptionContext) context = g_option_context_new (""); - g_autoptr(OstreeSysroot) sysroot = NULL; + g_autoptr (OstreeSysroot) sysroot = NULL; if (!ostree_admin_option_context_parse (context, options, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, + OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER + | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, invocation, &sysroot, cancellable, error)) return FALSE; - if (!ot_admin_require_booted_deployment_or_osname (sysroot, opt_osname, - cancellable, error)) + if (!ot_admin_require_booted_deployment_or_osname (sysroot, opt_osname, cancellable, error)) return FALSE; - g_autoptr(OstreeDeployment) deployment = NULL; + g_autoptr (OstreeDeployment) deployment = NULL; if (opt_osname != NULL) { deployment = ostree_sysroot_get_merge_deployment (sysroot, opt_osname); if (deployment == NULL) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "No deployment for OS '%s'", opt_osname); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "No deployment for OS '%s'", + opt_osname); return FALSE; } } else deployment = g_object_ref (ostree_sysroot_get_booted_deployment (sysroot)); - g_autoptr(GFile) deployment_dir = ostree_sysroot_get_deployment_directory (sysroot, deployment); - g_autoptr(GFile) orig_etc_path = g_file_resolve_relative_path (deployment_dir, "usr/etc"); - g_autoptr(GFile) new_etc_path = g_file_resolve_relative_path (deployment_dir, "etc"); - g_autoptr(GPtrArray) modified = g_ptr_array_new_with_free_func ((GDestroyNotify) ostree_diff_item_unref); - g_autoptr(GPtrArray) removed = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); - g_autoptr(GPtrArray) added = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); - if (!ostree_diff_dirs (OSTREE_DIFF_FLAGS_IGNORE_XATTRS, - orig_etc_path, new_etc_path, modified, removed, added, - cancellable, error)) + g_autoptr (GFile) deployment_dir = ostree_sysroot_get_deployment_directory (sysroot, deployment); + g_autoptr (GFile) orig_etc_path = g_file_resolve_relative_path (deployment_dir, "usr/etc"); + g_autoptr (GFile) new_etc_path = g_file_resolve_relative_path (deployment_dir, "etc"); + g_autoptr (GPtrArray) modified + = g_ptr_array_new_with_free_func ((GDestroyNotify)ostree_diff_item_unref); + g_autoptr (GPtrArray) removed = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref); + g_autoptr (GPtrArray) added = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref); + if (!ostree_diff_dirs (OSTREE_DIFF_FLAGS_IGNORE_XATTRS, orig_etc_path, new_etc_path, modified, + removed, added, cancellable, error)) return FALSE; ostree_diff_print (orig_etc_path, new_etc_path, modified, removed, added); diff --git a/src/ostree/ot-admin-builtin-finalize-staged.c b/src/ostree/ot-admin-builtin-finalize-staged.c index e408f447..a60f4687 100644 --- a/src/ostree/ot-admin-builtin-finalize-staged.c +++ b/src/ostree/ot-admin-builtin-finalize-staged.c @@ -25,10 +25,10 @@ #include #include -#include "ot-main.h" +#include "ostree.h" #include "ot-admin-builtins.h" #include "ot-admin-functions.h" -#include "ostree.h" +#include "ot-main.h" #include "otutil.h" #include "ostree-cmd-private.h" @@ -36,16 +36,16 @@ static gboolean opt_hold; -static GOptionEntry options[] = { - { "hold", 0, 0, G_OPTION_ARG_NONE, &opt_hold, "Hold /boot open during finalization", NULL }, - { NULL } -}; +static GOptionEntry options[] + = { { "hold", 0, 0, G_OPTION_ARG_NONE, &opt_hold, "Hold /boot open during finalization", NULL }, + { NULL } }; /* Called by ostree-finalize-staged.service, and in turn * invokes a cmdprivate function inside the shared library. */ gboolean -ot_admin_builtin_finalize_staged (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_builtin_finalize_staged (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { /* Just a sanity check; we shouldn't be called outside of the service though. */ @@ -53,23 +53,23 @@ ot_admin_builtin_finalize_staged (int argc, char **argv, OstreeCommandInvocation if (fstatat (AT_FDCWD, OSTREE_PATH_BOOTED, &stbuf, 0) < 0) return TRUE; - g_autoptr(GOptionContext) context = g_option_context_new (""); - g_autoptr(OstreeSysroot) sysroot = NULL; + g_autoptr (GOptionContext) context = g_option_context_new (""); + g_autoptr (OstreeSysroot) sysroot = NULL; /* First parse the args without loading the sysroot to see what options are * set. */ if (!ostree_admin_option_context_parse (context, options, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_NO_LOAD, - invocation, &sysroot, cancellable, error)) + OSTREE_ADMIN_BUILTIN_FLAG_NO_LOAD, invocation, &sysroot, + cancellable, error)) return FALSE; if (opt_hold) { /* Load the sysroot unlocked so that a separate namespace isn't * created. */ - if (!ostree_admin_sysroot_load (sysroot, - OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, - cancellable, error)) + if (!ostree_admin_sysroot_load ( + sysroot, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, + cancellable, error)) return FALSE; /* In case it's an automount, open /boot so that the automount doesn't @@ -93,12 +93,11 @@ ot_admin_builtin_finalize_staged (int argc, char **argv, OstreeCommandInvocation { /* Load the sysroot with the normal flags and actually finalize the * deployment. */ - if (!ostree_admin_sysroot_load (sysroot, - OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, - cancellable, error)) + if (!ostree_admin_sysroot_load (sysroot, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, cancellable, + error)) return FALSE; - if (!ostree_cmd__private__()->ostree_finalize_staged (sysroot, cancellable, error)) + if (!ostree_cmd__private__ ()->ostree_finalize_staged (sysroot, cancellable, error)) return FALSE; } diff --git a/src/ostree/ot-admin-builtin-init-fs.c b/src/ostree/ot-admin-builtin-init-fs.c index 87f46cb9..bf00f19e 100644 --- a/src/ostree/ot-admin-builtin-init-fs.c +++ b/src/ostree/ot-admin-builtin-init-fs.c @@ -21,29 +21,29 @@ #include "config.h" -#include "ot-main.h" #include "ot-admin-builtins.h" #include "ot-admin-functions.h" +#include "ot-main.h" #include "otutil.h" #include static gboolean opt_modern; -static GOptionEntry options[] = { - { "modern", 0, 0, G_OPTION_ARG_NONE, &opt_modern, "Only create /boot and /ostree", NULL }, - { NULL } -}; +static GOptionEntry options[] + = { { "modern", 0, 0, G_OPTION_ARG_NONE, &opt_modern, "Only create /boot and /ostree", NULL }, + { NULL } }; gboolean -ot_admin_builtin_init_fs (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_builtin_init_fs (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("PATH"); + g_autoptr (GOptionContext) context = g_option_context_new ("PATH"); if (!ostree_admin_option_context_parse (context, options, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | - OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED | - OSTREE_ADMIN_BUILTIN_FLAG_NO_SYSROOT, + OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER + | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED + | OSTREE_ADMIN_BUILTIN_FLAG_NO_SYSROOT, invocation, NULL, cancellable, error)) return FALSE; @@ -70,20 +70,18 @@ ot_admin_builtin_init_fs (int argc, char **argv, OstreeCommandInvocation *invoca */ if (!opt_modern) { - const char *traditional_toplevels[] = {"boot", "dev", "home", "proc", "run", "sys"}; + const char *traditional_toplevels[] = { "boot", "dev", "home", "proc", "run", "sys" }; for (guint i = 0; i < G_N_ELEMENTS (traditional_toplevels); i++) { - if (!glnx_shutil_mkdir_p_at (root_dfd, traditional_toplevels[i], 0755, - cancellable, error)) + if (!glnx_shutil_mkdir_p_at (root_dfd, traditional_toplevels[i], 0755, cancellable, + error)) return FALSE; } - if (!glnx_shutil_mkdir_p_at (root_dfd, "root", 0700, - cancellable, error)) + if (!glnx_shutil_mkdir_p_at (root_dfd, "root", 0700, cancellable, error)) return FALSE; - if (!glnx_shutil_mkdir_p_at (root_dfd, "tmp", 01777, - cancellable, error)) + if (!glnx_shutil_mkdir_p_at (root_dfd, "tmp", 01777, cancellable, error)) return FALSE; if (fchmodat (root_dfd, "tmp", 01777, 0) == -1) { @@ -92,8 +90,8 @@ ot_admin_builtin_init_fs (int argc, char **argv, OstreeCommandInvocation *invoca } } - g_autoptr(GFile) dir = g_file_new_for_path (sysroot_path); - g_autoptr(OstreeSysroot) sysroot = ostree_sysroot_new (dir); + g_autoptr (GFile) dir = g_file_new_for_path (sysroot_path); + g_autoptr (OstreeSysroot) sysroot = ostree_sysroot_new (dir); if (!ostree_sysroot_ensure_initialized (sysroot, cancellable, error)) return FALSE; diff --git a/src/ostree/ot-admin-builtin-instutil.c b/src/ostree/ot-admin-builtin-instutil.c index b946a96b..d697cb00 100644 --- a/src/ostree/ot-admin-builtin-instutil.c +++ b/src/ostree/ot-admin-builtin-instutil.c @@ -19,26 +19,23 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" -#include "ot-admin-instutil-builtins.h" +#include "ostree.h" #include "ot-admin-builtins.h" #include "ot-admin-functions.h" -#include "ostree.h" +#include "ot-admin-instutil-builtins.h" +#include "ot-builtins.h" +#include "ot-main.h" #include static OstreeCommand admin_instutil_subcommands[] = { #ifdef HAVE_SELINUX { "selinux-ensure-labeled", OSTREE_BUILTIN_FLAG_NO_REPO, - ot_admin_instutil_builtin_selinux_ensure_labeled, - "Relabel all or part of a deployment" }, + ot_admin_instutil_builtin_selinux_ensure_labeled, "Relabel all or part of a deployment" }, #endif - { "set-kargs", OSTREE_BUILTIN_FLAG_NO_REPO, - ot_admin_instutil_builtin_set_kargs, - "Set new kernel command line arguments(Not stable)" }, - { "grub2-generate", OSTREE_BUILTIN_FLAG_NO_REPO, - ot_admin_instutil_builtin_grub2_generate, + { "set-kargs", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_instutil_builtin_set_kargs, + "Set new kernel command line arguments(Not stable)" }, + { "grub2-generate", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_instutil_builtin_grub2_generate, "Generate GRUB2 configuration from given BLS entries" }, { NULL, 0, NULL, NULL } }; @@ -49,7 +46,7 @@ ostree_admin_instutil_option_context_new_with_commands (void) OstreeCommand *command = admin_instutil_subcommands; GOptionContext *context = g_option_context_new ("COMMAND"); - g_autoptr(GString) summary = g_string_new ("Builtin \"admin instutil\" Commands:"); + g_autoptr (GString) summary = g_string_new ("Builtin \"admin instutil\" Commands:"); while (command->name != NULL) { @@ -69,7 +66,8 @@ ostree_admin_instutil_option_context_new_with_commands (void) } gboolean -ot_admin_builtin_instutil (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_builtin_instutil (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { const char *subcommand_name = NULL; int in, out; @@ -107,13 +105,13 @@ ot_admin_builtin_instutil (int argc, char **argv, OstreeCommandInvocation *invoc if (!subcommand->name) { - g_autoptr(GOptionContext) context = - ostree_admin_instutil_option_context_new_with_commands (); + g_autoptr (GOptionContext) context + = ostree_admin_instutil_option_context_new_with_commands (); /* This will not return for some options (e.g. --version). */ if (ostree_admin_option_context_parse (context, NULL, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_NO_SYSROOT, - invocation, NULL, cancellable, error)) + OSTREE_ADMIN_BUILTIN_FLAG_NO_SYSROOT, invocation, NULL, + cancellable, error)) { if (subcommand_name == NULL) { diff --git a/src/ostree/ot-admin-builtin-kargs.c b/src/ostree/ot-admin-builtin-kargs.c index 4afef294..c4d440bd 100644 --- a/src/ostree/ot-admin-builtin-kargs.c +++ b/src/ostree/ot-admin-builtin-kargs.c @@ -20,10 +20,10 @@ #include "config.h" -#include "ot-main.h" #include "ot-admin-builtins.h" #include "ot-admin-functions.h" #include "ot-admin-kargs-builtins.h" +#include "ot-main.h" #include "otutil.h" #include @@ -31,7 +31,7 @@ static OstreeCommand admin_kargs_subcommands[] = { { "edit-in-place", OSTREE_BUILTIN_FLAG_NO_REPO | OSTREE_BUILTIN_FLAG_HIDDEN, ot_admin_kargs_builtin_edit_in_place, - "Set new kernel command line arguments in place (applies to all deployments by default)" }, + "Set new kernel command line arguments in place (applies to all deployments by default)" }, { NULL, 0, NULL, NULL } }; @@ -41,7 +41,7 @@ ostree_admin_kargs_option_context_new_with_commands (void) OstreeCommand *command = admin_kargs_subcommands; GOptionContext *context = g_option_context_new ("COMMAND"); - g_autoptr(GString) summary = g_string_new ("Builtin \"admin kargs\" Commands:"); + g_autoptr (GString) summary = g_string_new ("Builtin \"admin kargs\" Commands:"); while (command->name != NULL) { @@ -61,7 +61,8 @@ ostree_admin_kargs_option_context_new_with_commands (void) } gboolean -ot_admin_builtin_kargs (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_builtin_kargs (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { const char *subcommand_name = NULL; int in, out; @@ -98,13 +99,12 @@ ot_admin_builtin_kargs (int argc, char **argv, OstreeCommandInvocation *invocati if (!subcommand->name) { - g_autoptr(GOptionContext) context = - ostree_admin_kargs_option_context_new_with_commands (); + g_autoptr (GOptionContext) context = ostree_admin_kargs_option_context_new_with_commands (); /* This will not return for some options (e.g. --version). */ if (ostree_admin_option_context_parse (context, NULL, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_NO_SYSROOT, - invocation, NULL, cancellable, error)) + OSTREE_ADMIN_BUILTIN_FLAG_NO_SYSROOT, invocation, NULL, + cancellable, error)) { if (subcommand_name == NULL) { diff --git a/src/ostree/ot-admin-builtin-os-init.c b/src/ostree/ot-admin-builtin-os-init.c index 05311532..8588138f 100644 --- a/src/ostree/ot-admin-builtin-os-init.c +++ b/src/ostree/ot-admin-builtin-os-init.c @@ -21,25 +21,25 @@ #include "config.h" -#include "ot-main.h" #include "ot-admin-builtins.h" #include "ot-admin-functions.h" +#include "ot-main.h" #include "otutil.h" #include -static GOptionEntry options[] = { - { NULL } -}; +static GOptionEntry options[] = { { NULL } }; gboolean -ot_admin_builtin_os_init (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_builtin_os_init (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("OSNAME"); + g_autoptr (GOptionContext) context = g_option_context_new ("OSNAME"); - g_autoptr(OstreeSysroot) sysroot = NULL; + g_autoptr (OstreeSysroot) sysroot = NULL; if (!ostree_admin_option_context_parse (context, options, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, + OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER + | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, invocation, &sysroot, cancellable, error)) return FALSE; diff --git a/src/ostree/ot-admin-builtin-pin.c b/src/ostree/ot-admin-builtin-pin.c index 301e1aab..362df44c 100644 --- a/src/ostree/ot-admin-builtin-pin.c +++ b/src/ostree/ot-admin-builtin-pin.c @@ -21,27 +21,26 @@ #include -#include "ot-main.h" +#include "ostree.h" #include "ot-admin-builtins.h" #include "ot-admin-functions.h" -#include "ostree.h" +#include "ot-main.h" #include "otutil.h" static gboolean opt_unpin; -static GOptionEntry options[] = { - { "unpin", 'u', 0, G_OPTION_ARG_NONE, &opt_unpin, "Unset pin", NULL }, - { NULL } -}; +static GOptionEntry options[] + = { { "unpin", 'u', 0, G_OPTION_ARG_NONE, &opt_unpin, "Unset pin", NULL }, { NULL } }; gboolean -ot_admin_builtin_pin (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_builtin_pin (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("INDEX"); - g_autoptr(OstreeSysroot) sysroot = NULL; + g_autoptr (GOptionContext) context = g_option_context_new ("INDEX"); + g_autoptr (OstreeSysroot) sysroot = NULL; if (!ostree_admin_option_context_parse (context, options, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, - invocation, &sysroot, cancellable, error)) + OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, invocation, &sysroot, + cancellable, error)) return FALSE; if (argc < 2) @@ -62,7 +61,8 @@ ot_admin_builtin_pin (int argc, char **argv, OstreeCommandInvocation *invocation if (errno == ERANGE) return glnx_throw (error, "Index too large: %s", deploy_index_str); - g_autoptr(OstreeDeployment) target_deployment = ot_admin_get_indexed_deployment (sysroot, deploy_index, error); + g_autoptr (OstreeDeployment) target_deployment + = ot_admin_get_indexed_deployment (sysroot, deploy_index, error); if (!target_deployment) return FALSE; @@ -70,14 +70,17 @@ ot_admin_builtin_pin (int argc, char **argv, OstreeCommandInvocation *invocation const gboolean desired_pin = !opt_unpin; if (current_pin == desired_pin) { - g_print ("Deployment %s is already %s\n", deploy_index_str, current_pin ? "pinned" : "unpinned"); + g_print ("Deployment %s is already %s\n", deploy_index_str, + current_pin ? "pinned" : "unpinned"); } else - { - if (!ostree_sysroot_deployment_set_pinned (sysroot, target_deployment, desired_pin, error)) - return FALSE; - g_print ("Deployment %s is now %s\n", deploy_index_str, desired_pin ? "pinned" : "unpinned"); - } + { + if (!ostree_sysroot_deployment_set_pinned (sysroot, target_deployment, desired_pin, + error)) + return FALSE; + g_print ("Deployment %s is now %s\n", deploy_index_str, + desired_pin ? "pinned" : "unpinned"); + } } return TRUE; diff --git a/src/ostree/ot-admin-builtin-set-origin.c b/src/ostree/ot-admin-builtin-set-origin.c index 91184cd6..84772cce 100644 --- a/src/ostree/ot-admin-builtin-set-origin.c +++ b/src/ostree/ot-admin-builtin-set-origin.c @@ -19,42 +19,44 @@ #include "config.h" -#include "ot-main.h" +#include "ostree.h" #include "ot-admin-builtins.h" #include "ot-admin-functions.h" -#include "ostree.h" +#include "ot-main.h" #include "otutil.h" -#include -#include #include +#include +#include static int opt_index = -1; static char **opt_set; -static GOptionEntry options[] = { - { "set", 's', 0, G_OPTION_ARG_STRING_ARRAY, &opt_set, "Set config option KEY=VALUE for remote", "KEY=VALUE" }, - { "index", 0, 0, G_OPTION_ARG_INT, &opt_index, "Operate on the deployment INDEX, starting from zero", "INDEX" }, - { NULL } -}; +static GOptionEntry options[] + = { { "set", 's', 0, G_OPTION_ARG_STRING_ARRAY, &opt_set, + "Set config option KEY=VALUE for remote", "KEY=VALUE" }, + { "index", 0, 0, G_OPTION_ARG_INT, &opt_index, + "Operate on the deployment INDEX, starting from zero", "INDEX" }, + { NULL } }; gboolean -ot_admin_builtin_set_origin (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_builtin_set_origin (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; - g_autoptr(GOptionContext) context = NULL; + g_autoptr (GOptionContext) context = NULL; const char *remotename = NULL; const char *url = NULL; const char *branch = NULL; - g_autoptr(OstreeRepo) repo = NULL; - g_autoptr(OstreeSysroot) sysroot = NULL; - g_autoptr(OstreeDeployment) target_deployment = NULL; + g_autoptr (OstreeRepo) repo = NULL; + g_autoptr (OstreeSysroot) sysroot = NULL; + g_autoptr (OstreeDeployment) target_deployment = NULL; context = g_option_context_new ("REMOTENAME URL [BRANCH]"); if (!ostree_admin_option_context_parse (context, options, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, - invocation, &sysroot, cancellable, error)) + OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, invocation, &sysroot, + cancellable, error)) goto out; if (argc < 3) @@ -86,10 +88,10 @@ ot_admin_builtin_set_origin (int argc, char **argv, OstreeCommandInvocation *inv goto out; } - { char **iter; - g_autoptr(GVariantBuilder) optbuilder = - g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); - g_autoptr(GVariant) remote_options = NULL; + { + char **iter; + g_autoptr (GVariantBuilder) optbuilder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); + g_autoptr (GVariant) remote_options = NULL; for (iter = opt_set; iter && *iter; iter++) { @@ -100,21 +102,19 @@ ot_admin_builtin_set_origin (int argc, char **argv, OstreeCommandInvocation *inv if (!ot_parse_keyvalue (keyvalue, &subkey, &subvalue, error)) goto out; - g_variant_builder_add (optbuilder, "{s@v}", - subkey, g_variant_new_variant (g_variant_new_string (subvalue))); + g_variant_builder_add (optbuilder, "{s@v}", subkey, + g_variant_new_variant (g_variant_new_string (subvalue))); } remote_options = g_variant_ref_sink (g_variant_builder_end (optbuilder)); - if (!ostree_repo_remote_change (repo, NULL, - OSTREE_REPO_REMOTE_CHANGE_ADD_IF_NOT_EXISTS, - remotename, url, - remote_options, - cancellable, error)) + if (!ostree_repo_remote_change (repo, NULL, OSTREE_REPO_REMOTE_CHANGE_ADD_IF_NOT_EXISTS, + remotename, url, remote_options, cancellable, error)) goto out; } - { GKeyFile *old_origin = ostree_deployment_get_origin (target_deployment); + { + GKeyFile *old_origin = ostree_deployment_get_origin (target_deployment); g_autofree char *origin_refspec = g_key_file_get_string (old_origin, "origin", "refspec", NULL); g_autofree char *origin_remote = NULL; g_autofree char *origin_ref = NULL; @@ -122,18 +122,20 @@ ot_admin_builtin_set_origin (int argc, char **argv, OstreeCommandInvocation *inv if (!ostree_parse_refspec (origin_refspec, &origin_remote, &origin_ref, error)) goto out; - { g_autofree char *new_refspec = g_strconcat (remotename, ":", branch ? branch : origin_ref, NULL); - g_autoptr(GKeyFile) new_origin = NULL; + { + g_autofree char *new_refspec + = g_strconcat (remotename, ":", branch ? branch : origin_ref, NULL); + g_autoptr (GKeyFile) new_origin = NULL; new_origin = ostree_sysroot_origin_new_from_refspec (sysroot, new_refspec); - if (!ostree_sysroot_write_origin_file (sysroot, target_deployment, new_origin, - cancellable, error)) + if (!ostree_sysroot_write_origin_file (sysroot, target_deployment, new_origin, cancellable, + error)) goto out; } } ret = TRUE; - out: +out: return ret; } diff --git a/src/ostree/ot-admin-builtin-status.c b/src/ostree/ot-admin-builtin-status.c index 672882bd..3addfd16 100644 --- a/src/ostree/ot-admin-builtin-status.c +++ b/src/ostree/ot-admin-builtin-status.c @@ -21,25 +21,23 @@ #include "config.h" -#include "ot-main.h" +#include "libglnx.h" +#include "ostree.h" #include "ot-admin-builtins.h" #include "ot-admin-functions.h" -#include "ostree.h" -#include "libglnx.h" +#include "ot-main.h" #include static gboolean opt_verify; -static GOptionEntry options[] = { - { "verify", 'V', 0, G_OPTION_ARG_NONE, &opt_verify, "Print the commit verification status", NULL }, - { NULL } -}; +static GOptionEntry options[] = { { "verify", 'V', 0, G_OPTION_ARG_NONE, &opt_verify, + "Print the commit verification status", NULL }, + { NULL } }; #ifndef OSTREE_DISABLE_GPGME static gboolean -deployment_get_gpg_verify (OstreeDeployment *deployment, - OstreeRepo *repo) +deployment_get_gpg_verify (OstreeDeployment *deployment, OstreeRepo *repo) { /* XXX Something like this could be added to the OstreeDeployment * API in libostree if the OstreeRepo parameter is acceptable. */ @@ -59,38 +57,32 @@ deployment_get_gpg_verify (OstreeDeployment *deployment, gboolean gpg_verify = FALSE; if (remote) - (void) ostree_repo_remote_get_gpg_verify (repo, remote, &gpg_verify, NULL); + (void)ostree_repo_remote_get_gpg_verify (repo, remote, &gpg_verify, NULL); return gpg_verify; } #endif /* OSTREE_DISABLE_GPGME */ - static gboolean -deployment_print_status (OstreeSysroot *sysroot, - OstreeRepo *repo, - OstreeDeployment *deployment, - gboolean is_booted, - gboolean is_pending, - gboolean is_rollback, - GCancellable *cancellable, - GError **error) +deployment_print_status (OstreeSysroot *sysroot, OstreeRepo *repo, OstreeDeployment *deployment, + gboolean is_booted, gboolean is_pending, gboolean is_rollback, + GCancellable *cancellable, GError **error) { const char *ref = ostree_deployment_get_csum (deployment); /* Load the backing commit; shouldn't normally fail, but if it does, * we stumble on. */ - g_autoptr(GVariant) commit = NULL; - (void)ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, ref, - &commit, NULL); - g_autoptr(GVariant) commit_metadata = NULL; + g_autoptr (GVariant) commit = NULL; + (void)ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, ref, &commit, NULL); + g_autoptr (GVariant) commit_metadata = NULL; if (commit) commit_metadata = g_variant_get_child_value (commit, 0); - g_autoptr(GVariant) commit_detached_metadata = NULL; + g_autoptr (GVariant) commit_detached_metadata = NULL; if (commit) { - if (!ostree_repo_read_commit_detached_metadata (repo, ref, &commit_detached_metadata, cancellable, error)) + if (!ostree_repo_read_commit_detached_metadata (repo, ref, &commit_detached_metadata, + cancellable, error)) return FALSE; } @@ -98,8 +90,9 @@ deployment_print_status (OstreeSysroot *sysroot, const char *source_title = NULL; if (commit_metadata) { - (void) g_variant_lookup (commit_metadata, OSTREE_COMMIT_META_KEY_VERSION, "&s", &version); - (void) g_variant_lookup (commit_metadata, OSTREE_COMMIT_META_KEY_SOURCE_TITLE, "&s", &source_title); + (void)g_variant_lookup (commit_metadata, OSTREE_COMMIT_META_KEY_VERSION, "&s", &version); + (void)g_variant_lookup (commit_metadata, OSTREE_COMMIT_META_KEY_SOURCE_TITLE, "&s", + &source_title); } GKeyFile *origin = ostree_deployment_get_origin (deployment); @@ -111,11 +104,8 @@ deployment_print_status (OstreeSysroot *sysroot, deployment_status = " (pending)"; else if (is_rollback) deployment_status = " (rollback)"; - g_print ("%c %s %s.%d%s\n", - is_booted ? '*' : ' ', - ostree_deployment_get_osname (deployment), - ostree_deployment_get_csum (deployment), - ostree_deployment_get_deployserial (deployment), + g_print ("%c %s %s.%d%s\n", is_booted ? '*' : ' ', ostree_deployment_get_osname (deployment), + ostree_deployment_get_csum (deployment), ostree_deployment_get_deployserial (deployment), deployment_status); if (version) g_print (" Version: %s\n", version); @@ -127,8 +117,8 @@ deployment_print_status (OstreeSysroot *sysroot, break; default: g_print (" %s%sUnlocked: %s%s%s\n", ot_get_red_start (), ot_get_bold_start (), - ostree_deployment_unlocked_state_to_string (unlocked), - ot_get_bold_end (), ot_get_red_end ()); + ostree_deployment_unlocked_state_to_string (unlocked), ot_get_bold_end (), + ot_get_red_end ()); } if (ostree_deployment_is_pinned (deployment)) g_print (" Pinned: yes\n"); @@ -148,14 +138,13 @@ deployment_print_status (OstreeSysroot *sysroot, #ifndef OSTREE_DISABLE_GPGME if (!opt_verify && deployment_get_gpg_verify (deployment, repo)) { - g_autoptr(GString) output_buffer = g_string_sized_new (256); + g_autoptr (GString) output_buffer = g_string_sized_new (256); /* Print any digital signatures on this commit. */ const char *osname = ostree_deployment_get_osname (deployment); - g_autoptr(GError) local_error = NULL; - g_autoptr(OstreeGpgVerifyResult) result = - ostree_repo_verify_commit_for_remote (repo, ref, osname, - cancellable, &local_error); + g_autoptr (GError) local_error = NULL; + g_autoptr (OstreeGpgVerifyResult) result + = ostree_repo_verify_commit_for_remote (repo, ref, osname, cancellable, &local_error); /* G_IO_ERROR_NOT_FOUND just means the commit is not signed. */ if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) @@ -172,8 +161,8 @@ deployment_print_status (OstreeSysroot *sysroot, const guint n_signatures = ostree_gpg_verify_result_count_all (result); for (guint jj = 0; jj < n_signatures; jj++) { - ostree_gpg_verify_result_describe (result, jj, output_buffer, " GPG: ", - OSTREE_GPG_SIGNATURE_FORMAT_DEFAULT); + ostree_gpg_verify_result_describe (result, jj, output_buffer, + " GPG: ", OSTREE_GPG_SIGNATURE_FORMAT_DEFAULT); } g_print ("%s", output_buffer->str); @@ -196,11 +185,13 @@ deployment_print_status (OstreeSysroot *sysroot, if (remote == NULL) return glnx_throw (error, "Cannot verify deployment without remote"); - g_autoptr(GBytes) commit_data = g_variant_get_data_as_bytes (commit); - g_autoptr(GBytes) commit_detached_metadata_bytes = - commit_detached_metadata ? g_variant_get_data_as_bytes (commit_detached_metadata) : NULL; + g_autoptr (GBytes) commit_data = g_variant_get_data_as_bytes (commit); + g_autoptr (GBytes) commit_detached_metadata_bytes + = commit_detached_metadata ? g_variant_get_data_as_bytes (commit_detached_metadata) + : NULL; g_autofree char *verify_text = NULL; - if (!ostree_repo_signature_verify_commit_data (repo, remote, commit_data, commit_detached_metadata_bytes, 0, &verify_text, error)) + if (!ostree_repo_signature_verify_commit_data ( + repo, remote, commit_data, commit_detached_metadata_bytes, 0, &verify_text, error)) return FALSE; g_print ("%s\n", verify_text); } @@ -209,28 +200,28 @@ deployment_print_status (OstreeSysroot *sysroot, } gboolean -ot_admin_builtin_status (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_builtin_status (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new (""); + g_autoptr (GOptionContext) context = g_option_context_new (""); - g_autoptr(OstreeSysroot) sysroot = NULL; + g_autoptr (OstreeSysroot) sysroot = NULL; if (!ostree_admin_option_context_parse (context, options, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, - invocation, &sysroot, cancellable, error)) + OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, invocation, &sysroot, + cancellable, error)) return FALSE; - g_autoptr(OstreeRepo) repo = NULL; + g_autoptr (OstreeRepo) repo = NULL; if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error)) return FALSE; - g_autoptr(GPtrArray) deployments = ostree_sysroot_get_deployments (sysroot); + g_autoptr (GPtrArray) deployments = ostree_sysroot_get_deployments (sysroot); OstreeDeployment *booted_deployment = ostree_sysroot_get_booted_deployment (sysroot); - g_autoptr(OstreeDeployment) pending_deployment = NULL; - g_autoptr(OstreeDeployment) rollback_deployment = NULL; + g_autoptr (OstreeDeployment) pending_deployment = NULL; + g_autoptr (OstreeDeployment) rollback_deployment = NULL; if (booted_deployment) - ostree_sysroot_query_deployments_for (sysroot, NULL, &pending_deployment, - &rollback_deployment); + ostree_sysroot_query_deployments_for (sysroot, NULL, &pending_deployment, &rollback_deployment); if (deployments->len == 0) { @@ -241,12 +232,9 @@ ot_admin_builtin_status (int argc, char **argv, OstreeCommandInvocation *invocat for (guint i = 0; i < deployments->len; i++) { OstreeDeployment *deployment = deployments->pdata[i]; - if (!deployment_print_status (sysroot, repo, deployment, - deployment == booted_deployment, + if (!deployment_print_status (sysroot, repo, deployment, deployment == booted_deployment, deployment == pending_deployment, - deployment == rollback_deployment, - cancellable, - error)) + deployment == rollback_deployment, cancellable, error)) return FALSE; } } diff --git a/src/ostree/ot-admin-builtin-switch.c b/src/ostree/ot-admin-builtin-switch.c index d29e7039..cb41cac5 100644 --- a/src/ostree/ot-admin-builtin-switch.c +++ b/src/ostree/ot-admin-builtin-switch.c @@ -19,34 +19,34 @@ #include "config.h" -#include "ot-main.h" +#include "ostree.h" #include "ot-admin-builtins.h" #include "ot-admin-functions.h" -#include "ostree.h" +#include "ot-main.h" #include "otutil.h" -#include -#include #include +#include +#include static gboolean opt_reboot; static char *opt_osname; -static GOptionEntry options[] = { - { "reboot", 'r', 0, G_OPTION_ARG_NONE, &opt_reboot, "Reboot after switching trees", NULL }, - { "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Use a different operating system root than the current one", "OSNAME" }, - { NULL } -}; +static GOptionEntry options[] + = { { "reboot", 'r', 0, G_OPTION_ARG_NONE, &opt_reboot, "Reboot after switching trees", NULL }, + { "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, + "Use a different operating system root than the current one", "OSNAME" }, + { NULL } }; gboolean -ot_admin_builtin_switch (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_builtin_switch (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = - g_option_context_new ("REFSPEC"); - g_autoptr(OstreeSysroot) sysroot = NULL; + g_autoptr (GOptionContext) context = g_option_context_new ("REFSPEC"); + g_autoptr (OstreeSysroot) sysroot = NULL; if (!ostree_admin_option_context_parse (context, options, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, - invocation, &sysroot, cancellable, error)) + OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, invocation, &sysroot, + cancellable, error)) return FALSE; if (argc < 2) @@ -57,10 +57,8 @@ ot_admin_builtin_switch (int argc, char **argv, OstreeCommandInvocation *invocat const char *new_provided_refspec = argv[1]; - g_autoptr(OstreeSysrootUpgrader) upgrader = - ostree_sysroot_upgrader_new_for_os_with_flags (sysroot, opt_osname, - OSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED, - cancellable, error); + g_autoptr (OstreeSysrootUpgrader) upgrader = ostree_sysroot_upgrader_new_for_os_with_flags ( + sysroot, opt_osname, OSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED, cancellable, error); if (!upgrader) return FALSE; @@ -77,7 +75,7 @@ ot_admin_builtin_switch (int argc, char **argv, OstreeCommandInvocation *invocat if (g_str_has_suffix (new_provided_refspec, ":")) { new_remote = g_strdup (new_provided_refspec); - new_remote[strlen(new_remote)-1] = '\0'; + new_remote[strlen (new_remote) - 1] = '\0'; new_ref = g_strdup (origin_ref); } else @@ -86,7 +84,7 @@ ot_admin_builtin_switch (int argc, char **argv, OstreeCommandInvocation *invocat return FALSE; } - const char* remote = new_remote ?: origin_remote; + const char *remote = new_remote ?: origin_remote; g_autofree char *new_refspec = NULL; if (remote) new_refspec = g_strconcat (remote, ":", new_ref, NULL); @@ -95,30 +93,32 @@ ot_admin_builtin_switch (int argc, char **argv, OstreeCommandInvocation *invocat if (strcmp (origin_refspec, new_refspec) == 0) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Old and new refs are equal: %s", new_refspec); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Old and new refs are equal: %s", + new_refspec); return FALSE; } - g_autoptr(GKeyFile) new_origin = ostree_sysroot_origin_new_from_refspec (sysroot, new_refspec); + g_autoptr (GKeyFile) new_origin = ostree_sysroot_origin_new_from_refspec (sysroot, new_refspec); if (!ostree_sysroot_upgrader_set_origin (upgrader, new_origin, cancellable, error)) return FALSE; - { g_auto(GLnxConsoleRef) console = { 0, }; + { + g_auto (GLnxConsoleRef) console = { + 0, + }; glnx_console_lock (&console); - g_autoptr(OstreeAsyncProgress) progress = NULL; + g_autoptr (OstreeAsyncProgress) progress = NULL; if (console.is_tty) - progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console); + progress = ostree_async_progress_new_and_connect ( + ostree_repo_pull_default_console_progress_changed, &console); /* Always allow older...there's not going to be a chronological * relationship necessarily. */ gboolean changed; - if (!ostree_sysroot_upgrader_pull (upgrader, 0, - OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_ALLOW_OLDER, - progress, &changed, - cancellable, error)) + if (!ostree_sysroot_upgrader_pull (upgrader, 0, OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_ALLOW_OLDER, + progress, &changed, cancellable, error)) return FALSE; if (progress) diff --git a/src/ostree/ot-admin-builtin-undeploy.c b/src/ostree/ot-admin-builtin-undeploy.c index c079c83f..ab028d41 100644 --- a/src/ostree/ot-admin-builtin-undeploy.c +++ b/src/ostree/ot-admin-builtin-undeploy.c @@ -21,25 +21,24 @@ #include -#include "ot-main.h" +#include "ostree.h" #include "ot-admin-builtins.h" #include "ot-admin-functions.h" -#include "ostree.h" +#include "ot-main.h" #include "otutil.h" -static GOptionEntry options[] = { - { NULL } -}; +static GOptionEntry options[] = { { NULL } }; gboolean -ot_admin_builtin_undeploy (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_builtin_undeploy (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("INDEX"); + g_autoptr (GOptionContext) context = g_option_context_new ("INDEX"); - g_autoptr(OstreeSysroot) sysroot = NULL; + g_autoptr (OstreeSysroot) sysroot = NULL; if (!ostree_admin_option_context_parse (context, options, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, - invocation, &sysroot, cancellable, error)) + OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, invocation, &sysroot, + cancellable, error)) return FALSE; if (argc < 2) @@ -48,13 +47,13 @@ ot_admin_builtin_undeploy (int argc, char **argv, OstreeCommandInvocation *invoc return FALSE; } - g_autoptr(GPtrArray) current_deployments = ostree_sysroot_get_deployments (sysroot); + g_autoptr (GPtrArray) current_deployments = ostree_sysroot_get_deployments (sysroot); const char *deploy_index_str = argv[1]; int deploy_index = atoi (deploy_index_str); - g_autoptr(OstreeDeployment) target_deployment = - ot_admin_get_indexed_deployment (sysroot, deploy_index, error); + g_autoptr (OstreeDeployment) target_deployment + = ot_admin_get_indexed_deployment (sysroot, deploy_index, error); if (!target_deployment) return FALSE; @@ -67,8 +66,7 @@ ot_admin_builtin_undeploy (int argc, char **argv, OstreeCommandInvocation *invoc g_ptr_array_remove_index (current_deployments, deploy_index); - if (!ostree_sysroot_write_deployments (sysroot, current_deployments, - cancellable, error)) + if (!ostree_sysroot_write_deployments (sysroot, current_deployments, cancellable, error)) return FALSE; g_print ("Deleted deployment %s.%d\n", ostree_deployment_get_csum (target_deployment), diff --git a/src/ostree/ot-admin-builtin-unlock.c b/src/ostree/ot-admin-builtin-unlock.c index 393d6be3..d0c41453 100644 --- a/src/ostree/ot-admin-builtin-unlock.c +++ b/src/ostree/ot-admin-builtin-unlock.c @@ -19,33 +19,34 @@ #include "config.h" -#include "ot-main.h" +#include "ostree.h" #include "ot-admin-builtins.h" #include "ot-admin-functions.h" -#include "ostree.h" +#include "ot-main.h" #include "otutil.h" -#include #include +#include static gboolean opt_hotfix; static gboolean opt_transient; -static GOptionEntry options[] = { - { "hotfix", 0, 0, G_OPTION_ARG_NONE, &opt_hotfix, "Retain changes across reboots", NULL }, - { "transient", 0, 0, G_OPTION_ARG_NONE, &opt_transient, "Mount overlayfs read-only by default", NULL }, - { NULL } -}; +static GOptionEntry options[] + = { { "hotfix", 0, 0, G_OPTION_ARG_NONE, &opt_hotfix, "Retain changes across reboots", NULL }, + { "transient", 0, 0, G_OPTION_ARG_NONE, &opt_transient, + "Mount overlayfs read-only by default", NULL }, + { NULL } }; gboolean -ot_admin_builtin_unlock (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_builtin_unlock (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new (""); + g_autoptr (GOptionContext) context = g_option_context_new (""); - g_autoptr(OstreeSysroot) sysroot = NULL; + g_autoptr (OstreeSysroot) sysroot = NULL; if (!ostree_admin_option_context_parse (context, options, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, - invocation, &sysroot, cancellable, error)) + OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, invocation, &sysroot, + cancellable, error)) return FALSE; if (argc > 1) @@ -70,8 +71,8 @@ ot_admin_builtin_unlock (int argc, char **argv, OstreeCommandInvocation *invocat else target_state = OSTREE_DEPLOYMENT_UNLOCKED_DEVELOPMENT; - if (!ostree_sysroot_deployment_unlock (sysroot, booted_deployment, - target_state, cancellable, error)) + if (!ostree_sysroot_deployment_unlock (sysroot, booted_deployment, target_state, cancellable, + error)) return FALSE; switch (target_state) diff --git a/src/ostree/ot-admin-builtin-upgrade.c b/src/ostree/ot-admin-builtin-upgrade.c index 3ed71efb..11710429 100644 --- a/src/ostree/ot-admin-builtin-upgrade.c +++ b/src/ostree/ot-admin-builtin-upgrade.c @@ -21,15 +21,15 @@ #include "config.h" -#include "ot-main.h" +#include "ostree.h" #include "ot-admin-builtins.h" #include "ot-admin-functions.h" -#include "ostree.h" +#include "ot-main.h" #include "otutil.h" -#include -#include #include +#include +#include static gboolean opt_reboot; static gboolean opt_allow_downgrade; @@ -40,25 +40,31 @@ static char *opt_osname; static char *opt_override_commit; static GOptionEntry options[] = { - { "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Use a different operating system root than the current one", "OSNAME" }, + { "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, + "Use a different operating system root than the current one", "OSNAME" }, { "reboot", 'r', 0, G_OPTION_ARG_NONE, &opt_reboot, "Reboot after a successful upgrade", NULL }, - { "allow-downgrade", 0, 0, G_OPTION_ARG_NONE, &opt_allow_downgrade, "Permit deployment of chronologically older trees", NULL }, - { "override-commit", 0, 0, G_OPTION_ARG_STRING, &opt_override_commit, "Deploy CHECKSUM instead of the latest tree", "CHECKSUM" }, - { "pull-only", 0, 0, G_OPTION_ARG_NONE, &opt_pull_only, "Do not create a deployment, just download", NULL }, + { "allow-downgrade", 0, 0, G_OPTION_ARG_NONE, &opt_allow_downgrade, + "Permit deployment of chronologically older trees", NULL }, + { "override-commit", 0, 0, G_OPTION_ARG_STRING, &opt_override_commit, + "Deploy CHECKSUM instead of the latest tree", "CHECKSUM" }, + { "pull-only", 0, 0, G_OPTION_ARG_NONE, &opt_pull_only, + "Do not create a deployment, just download", NULL }, { "deploy-only", 0, 0, G_OPTION_ARG_NONE, &opt_deploy_only, "Do not pull, only deploy", NULL }, - { "stage", 0, 0, G_OPTION_ARG_NONE, &opt_stage, "Enable staging (finalization at reboot time)", NULL }, + { "stage", 0, 0, G_OPTION_ARG_NONE, &opt_stage, "Enable staging (finalization at reboot time)", + NULL }, { NULL } }; gboolean -ot_admin_builtin_upgrade (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_builtin_upgrade (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new (""); + g_autoptr (GOptionContext) context = g_option_context_new (""); - g_autoptr(OstreeSysroot) sysroot = NULL; + g_autoptr (OstreeSysroot) sysroot = NULL; if (!ostree_admin_option_context_parse (context, options, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, - invocation, &sysroot, cancellable, error)) + OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, invocation, &sysroot, + cancellable, error)) return FALSE; if (opt_pull_only && opt_deploy_only) @@ -78,13 +84,12 @@ ot_admin_builtin_upgrade (int argc, char **argv, OstreeCommandInvocation *invoca if (opt_stage) flags |= OSTREE_SYSROOT_UPGRADER_FLAGS_STAGE; - g_autoptr(OstreeSysrootUpgrader) upgrader = - ostree_sysroot_upgrader_new_for_os_with_flags (sysroot, opt_osname, flags, - cancellable, error); + g_autoptr (OstreeSysrootUpgrader) upgrader = ostree_sysroot_upgrader_new_for_os_with_flags ( + sysroot, opt_osname, flags, cancellable, error); if (!upgrader) return FALSE; - g_autoptr(GKeyFile) origin = ostree_sysroot_upgrader_dup_origin (upgrader); + g_autoptr (GKeyFile) origin = ostree_sysroot_upgrader_dup_origin (upgrader); if (origin != NULL) { /* Should we consider requiring --discard-hotfix here? */ @@ -92,9 +97,7 @@ ot_admin_builtin_upgrade (int argc, char **argv, OstreeCommandInvocation *invoca if (opt_override_commit != NULL) { /* Override the commit to pull and deploy. */ - g_key_file_set_string (origin, "origin", - "override-commit", - opt_override_commit); + g_key_file_set_string (origin, "origin", "override-commit", opt_override_commit); } if (!ostree_sysroot_upgrader_set_origin (upgrader, origin, NULL, error)) @@ -106,18 +109,21 @@ ot_admin_builtin_upgrade (int argc, char **argv, OstreeCommandInvocation *invoca if (opt_deploy_only) upgraderpullflags |= OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_SYNTHETIC; - { g_auto(GLnxConsoleRef) console = { 0, }; + { + g_auto (GLnxConsoleRef) console = { + 0, + }; glnx_console_lock (&console); - g_autoptr(OstreeAsyncProgress) progress = NULL; + g_autoptr (OstreeAsyncProgress) progress = NULL; if (console.is_tty) - progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console); + progress = ostree_async_progress_new_and_connect ( + ostree_repo_pull_default_console_progress_changed, &console); if (opt_allow_downgrade) upgraderpullflags |= OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_ALLOW_OLDER; - if (!ostree_sysroot_upgrader_pull (upgrader, 0, upgraderpullflags, - progress, &changed, + if (!ostree_sysroot_upgrader_pull (upgrader, 0, upgraderpullflags, progress, &changed, cancellable, error)) { /* In the pull-only case, we do a cleanup here to ensure that if @@ -129,7 +135,7 @@ ot_admin_builtin_upgrade (int argc, char **argv, OstreeCommandInvocation *invoca * isn't directly referenced. */ if (opt_pull_only) - (void) ostree_sysroot_cleanup (sysroot, NULL, NULL); + (void)ostree_sysroot_cleanup (sysroot, NULL, NULL); return FALSE; } diff --git a/src/ostree/ot-admin-builtins.h b/src/ostree/ot-admin-builtins.h index 10af1ec2..d2ad836c 100644 --- a/src/ostree/ot-admin-builtins.h +++ b/src/ostree/ot-admin-builtins.h @@ -25,28 +25,28 @@ G_BEGIN_DECLS -#define BUILTINPROTO(name) gboolean ot_admin_builtin_ ## name (int argc, char **argv, \ - OstreeCommandInvocation *invocation, \ - GCancellable *cancellable, GError **error) +#define BUILTINPROTO(name) \ + gboolean ot_admin_builtin_##name (int argc, char **argv, OstreeCommandInvocation *invocation, \ + GCancellable *cancellable, GError **error) -BUILTINPROTO(selinux_ensure_labeled); -BUILTINPROTO(os_init); -BUILTINPROTO(install); -BUILTINPROTO(instutil); -BUILTINPROTO(init_fs); -BUILTINPROTO(undeploy); -BUILTINPROTO(deploy); -BUILTINPROTO(cleanup); -BUILTINPROTO(pin); -BUILTINPROTO(finalize_staged); -BUILTINPROTO(boot_complete); -BUILTINPROTO(unlock); -BUILTINPROTO(status); -BUILTINPROTO(set_origin); -BUILTINPROTO(diff); -BUILTINPROTO(switch); -BUILTINPROTO(upgrade); -BUILTINPROTO(kargs); +BUILTINPROTO (selinux_ensure_labeled); +BUILTINPROTO (os_init); +BUILTINPROTO (install); +BUILTINPROTO (instutil); +BUILTINPROTO (init_fs); +BUILTINPROTO (undeploy); +BUILTINPROTO (deploy); +BUILTINPROTO (cleanup); +BUILTINPROTO (pin); +BUILTINPROTO (finalize_staged); +BUILTINPROTO (boot_complete); +BUILTINPROTO (unlock); +BUILTINPROTO (status); +BUILTINPROTO (set_origin); +BUILTINPROTO (diff); +BUILTINPROTO (switch); +BUILTINPROTO (upgrade); +BUILTINPROTO (kargs); #undef BUILTINPROTO diff --git a/src/ostree/ot-admin-functions.c b/src/ostree/ot-admin-functions.c index 8c7cd135..e54fe8d9 100644 --- a/src/ostree/ot-admin-functions.c +++ b/src/ostree/ot-admin-functions.c @@ -22,20 +22,18 @@ #include "config.h" #include "libglnx.h" +#include "ostree.h" #include "ot-admin-functions.h" #include "otutil.h" -#include "ostree.h" gboolean -ot_admin_require_booted_deployment_or_osname (OstreeSysroot *sysroot, - const char *osname, - GCancellable *cancellable, - GError **error) +ot_admin_require_booted_deployment_or_osname (OstreeSysroot *sysroot, const char *osname, + GCancellable *cancellable, GError **error) { - OstreeDeployment *booted_deployment = - ostree_sysroot_get_booted_deployment (sysroot); + OstreeDeployment *booted_deployment = ostree_sysroot_get_booted_deployment (sysroot); if (booted_deployment == NULL && osname == NULL) - return glnx_throw (error, "Not currently booted into an OSTree system and no --os= argument given"); + return glnx_throw (error, + "Not currently booted into an OSTree system and no --os= argument given"); return TRUE; } @@ -51,7 +49,7 @@ ot_admin_require_booted_deployment_or_osname (OstreeSysroot *sysroot, char * ot_admin_checksum_version (GVariant *checksum) { - g_autoptr(GVariant) metadata = NULL; + g_autoptr (GVariant) metadata = NULL; const char *ret = NULL; metadata = g_variant_get_child_value (checksum, 0); @@ -63,18 +61,14 @@ ot_admin_checksum_version (GVariant *checksum) } OstreeDeployment * -ot_admin_get_indexed_deployment (OstreeSysroot *sysroot, - int index, - GError **error) +ot_admin_get_indexed_deployment (OstreeSysroot *sysroot, int index, GError **error) { - g_autoptr(GPtrArray) current_deployments = - ostree_sysroot_get_deployments (sysroot); + g_autoptr (GPtrArray) current_deployments = ostree_sysroot_get_deployments (sysroot); if (index < 0) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "Invalid index %d", index); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Invalid index %d", index); return NULL; } if (index >= current_deployments->len) @@ -88,7 +82,8 @@ ot_admin_get_indexed_deployment (OstreeSysroot *sysroot, return g_object_ref (current_deployments->pdata[index]); } -struct ContextState { +struct ContextState +{ GMainContext *mainctx; gboolean running; }; @@ -101,17 +96,14 @@ on_sysroot_lock_timeout (gpointer user_data) } static void -on_sysroot_lock_acquired (OstreeSysroot *sysroot, - GAsyncResult *result, - struct ContextState *state) +on_sysroot_lock_acquired (OstreeSysroot *sysroot, GAsyncResult *result, struct ContextState *state) { state->running = FALSE; g_main_context_wakeup (state->mainctx); } gboolean -ot_admin_sysroot_lock (OstreeSysroot *sysroot, - GError **error) +ot_admin_sysroot_lock (OstreeSysroot *sysroot, GError **error) { gboolean ret = FALSE; gboolean acquired; @@ -134,14 +126,15 @@ ot_admin_sysroot_lock (OstreeSysroot *sysroot, on_sysroot_lock_timeout (&state); - ostree_sysroot_lock_async (sysroot, NULL, (GAsyncReadyCallback)on_sysroot_lock_acquired, &state); + ostree_sysroot_lock_async (sysroot, NULL, (GAsyncReadyCallback)on_sysroot_lock_acquired, + &state); while (state.running) g_main_context_iteration (state.mainctx, TRUE); } ret = TRUE; - out: +out: g_main_context_pop_thread_default (state.mainctx); g_main_context_unref (state.mainctx); return ret; diff --git a/src/ostree/ot-admin-functions.h b/src/ostree/ot-admin-functions.h index f2cbc0be..50aef161 100644 --- a/src/ostree/ot-admin-functions.h +++ b/src/ostree/ot-admin-functions.h @@ -26,26 +26,16 @@ G_BEGIN_DECLS -gboolean -ot_admin_require_booted_deployment_or_osname (OstreeSysroot *sysroot, - const char *osname, - GCancellable *cancellable, - GError **error); - -char * -ot_admin_checksum_version (GVariant *checksum); - -OstreeDeployment * -ot_admin_get_indexed_deployment (OstreeSysroot *sysroot, - int index, - GError **error); - -gboolean -ot_admin_sysroot_lock (OstreeSysroot *sysroot, - GError **error); - -gboolean -ot_admin_execve_reboot (OstreeSysroot *sysroot, - GError **error); +gboolean ot_admin_require_booted_deployment_or_osname (OstreeSysroot *sysroot, const char *osname, + GCancellable *cancellable, GError **error); + +char *ot_admin_checksum_version (GVariant *checksum); + +OstreeDeployment *ot_admin_get_indexed_deployment (OstreeSysroot *sysroot, int index, + GError **error); + +gboolean ot_admin_sysroot_lock (OstreeSysroot *sysroot, GError **error); + +gboolean ot_admin_execve_reboot (OstreeSysroot *sysroot, GError **error); G_END_DECLS diff --git a/src/ostree/ot-admin-instutil-builtin-grub2-generate.c b/src/ostree/ot-admin-instutil-builtin-grub2-generate.c index 0f259bee..0f8a8636 100644 --- a/src/ostree/ot-admin-instutil-builtin-grub2-generate.c +++ b/src/ostree/ot-admin-instutil-builtin-grub2-generate.c @@ -17,42 +17,43 @@ #include "config.h" -#include #include +#include -#include "ot-main.h" -#include "ot-admin-instutil-builtins.h" #include "ostree-cmd-private.h" +#include "ot-admin-instutil-builtins.h" +#include "ot-main.h" #include "otutil.h" -static GOptionEntry options[] = { - { NULL } -}; +static GOptionEntry options[] = { { NULL } }; gboolean -ot_admin_instutil_builtin_grub2_generate (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_instutil_builtin_grub2_generate (int argc, char **argv, + OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; guint bootversion; - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeSysroot) sysroot = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeSysroot) sysroot = NULL; context = g_option_context_new ("[BOOTVERSION]"); if (!ostree_admin_option_context_parse (context, options, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, + OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER + | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, invocation, &sysroot, cancellable, error)) goto out; if (argc >= 2) { - bootversion = (guint) g_ascii_strtoull (argv[1], NULL, 10); + bootversion = (guint)g_ascii_strtoull (argv[1], NULL, 10); if (!(bootversion == 0 || bootversion == 1)) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Invalid bootversion: %u", bootversion); - goto out; + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid bootversion: %u", + bootversion); + goto out; } } else @@ -65,10 +66,11 @@ ot_admin_instutil_builtin_grub2_generate (int argc, char **argv, OstreeCommandIn g_assert (bootversion == 0 || bootversion == 1); } - if (!ostree_cmd__private__()->ostree_generate_grub2_config (sysroot, bootversion, 1, cancellable, error)) + if (!ostree_cmd__private__ ()->ostree_generate_grub2_config (sysroot, bootversion, 1, cancellable, + error)) goto out; ret = TRUE; - out: +out: return ret; } diff --git a/src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c b/src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c index e324da9e..bc226fb7 100644 --- a/src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c +++ b/src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c @@ -17,16 +17,16 @@ #include "config.h" -#include #include +#include -#include "ot-main.h" #include "ot-admin-instutil-builtins.h" +#include "ot-main.h" #include "otutil.h" static char * -ptrarray_path_join (GPtrArray *path) +ptrarray_path_join (GPtrArray *path) { GString *path_buf; @@ -50,58 +50,44 @@ ptrarray_path_join (GPtrArray *path) } static gboolean -relabel_one_path (OstreeSePolicy *sepolicy, - GFile *path, - GFileInfo *info, - GPtrArray *path_parts, - GCancellable *cancellable, - GError **error) +relabel_one_path (OstreeSePolicy *sepolicy, GFile *path, GFileInfo *info, GPtrArray *path_parts, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; g_autofree char *relpath = NULL; g_autofree char *new_label = NULL; relpath = ptrarray_path_join (path_parts); - if (!ostree_sepolicy_restorecon (sepolicy, relpath, - info, path, - OSTREE_SEPOLICY_RESTORECON_FLAGS_ALLOW_NOLABEL | - OSTREE_SEPOLICY_RESTORECON_FLAGS_KEEP_EXISTING, - &new_label, - cancellable, error)) + if (!ostree_sepolicy_restorecon (sepolicy, relpath, info, path, + OSTREE_SEPOLICY_RESTORECON_FLAGS_ALLOW_NOLABEL + | OSTREE_SEPOLICY_RESTORECON_FLAGS_KEEP_EXISTING, + &new_label, cancellable, error)) { g_prefix_error (error, "Setting context of %s: ", gs_file_get_path_cached (path)); goto out; } if (new_label) - g_print ("Set label of '%s' (as '%s') to '%s'\n", - gs_file_get_path_cached (path), - relpath, + g_print ("Set label of '%s' (as '%s') to '%s'\n", gs_file_get_path_cached (path), relpath, new_label); ret = TRUE; - out: +out: return ret; } static gboolean -relabel_recursively (OstreeSePolicy *sepolicy, - GFile *dir, - GFileInfo *dir_info, - GPtrArray *path_parts, - GCancellable *cancellable, - GError **error) +relabel_recursively (OstreeSePolicy *sepolicy, GFile *dir, GFileInfo *dir_info, + GPtrArray *path_parts, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; - g_autoptr(GFileEnumerator) direnum = NULL; + g_autoptr (GFileEnumerator) direnum = NULL; - if (!relabel_one_path (sepolicy, dir, dir_info, path_parts, - cancellable, error)) + if (!relabel_one_path (sepolicy, dir, dir_info, path_parts, cancellable, error)) goto out; direnum = g_file_enumerate_children (dir, OSTREE_GIO_FAST_QUERYINFO, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - cancellable, error); + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!direnum) goto out; @@ -111,25 +97,22 @@ relabel_recursively (OstreeSePolicy *sepolicy, GFile *child; GFileType ftype; - if (!g_file_enumerator_iterate (direnum, &file_info, &child, - cancellable, error)) + if (!g_file_enumerator_iterate (direnum, &file_info, &child, cancellable, error)) goto out; if (file_info == NULL) break; - g_ptr_array_add (path_parts, (char*)g_file_info_get_name (file_info)); + g_ptr_array_add (path_parts, (char *)g_file_info_get_name (file_info)); ftype = g_file_info_get_file_type (file_info); if (ftype == G_FILE_TYPE_DIRECTORY) { - if (!relabel_recursively (sepolicy, child, file_info, path_parts, - cancellable, error)) + if (!relabel_recursively (sepolicy, child, file_info, path_parts, cancellable, error)) goto out; } else { - if (!relabel_one_path (sepolicy, child, file_info, path_parts, - cancellable, error)) + if (!relabel_one_path (sepolicy, child, file_info, path_parts, cancellable, error)) goto out; } @@ -137,70 +120,65 @@ relabel_recursively (OstreeSePolicy *sepolicy, } ret = TRUE; - out: +out: return ret; } static gboolean -selinux_relabel_dir (OstreeSePolicy *sepolicy, - GFile *dir, - const char *prefix, - GCancellable *cancellable, - GError **error) +selinux_relabel_dir (OstreeSePolicy *sepolicy, GFile *dir, const char *prefix, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; - g_autoptr(GPtrArray) path_parts = g_ptr_array_new (); - g_autoptr(GFileInfo) root_info = NULL; + g_autoptr (GPtrArray) path_parts = g_ptr_array_new (); + g_autoptr (GFileInfo) root_info = NULL; root_info = g_file_query_info (dir, OSTREE_GIO_FAST_QUERYINFO, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - cancellable, error); + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!root_info) goto out; - g_ptr_array_add (path_parts, (char*)prefix); - if (!relabel_recursively (sepolicy, dir, root_info, path_parts, - cancellable, error)) + g_ptr_array_add (path_parts, (char *)prefix); + if (!relabel_recursively (sepolicy, dir, root_info, path_parts, cancellable, error)) { g_prefix_error (error, "Relabeling /%s: ", prefix); goto out; } ret = TRUE; - out: +out: return ret; } -static GOptionEntry options[] = { - { NULL } -}; +static GOptionEntry options[] = { { NULL } }; gboolean -ot_admin_instutil_builtin_selinux_ensure_labeled (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_instutil_builtin_selinux_ensure_labeled (int argc, char **argv, + OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; const char *policy_name; - g_autoptr(GFile) subpath = NULL; + g_autoptr (GFile) subpath = NULL; const char *prefix = NULL; - g_autoptr(OstreeSePolicy) sepolicy = NULL; - g_autoptr(GPtrArray) deployments = NULL; + g_autoptr (OstreeSePolicy) sepolicy = NULL; + g_autoptr (GPtrArray) deployments = NULL; OstreeDeployment *first_deployment; - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeSysroot) sysroot = NULL; - g_autoptr(GFile) deployment_path = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeSysroot) sysroot = NULL; + g_autoptr (GFile) deployment_path = NULL; context = g_option_context_new ("[SUBPATH PREFIX]"); if (!ostree_admin_option_context_parse (context, options, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, + OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER + | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, invocation, &sysroot, cancellable, error)) goto out; deployments = ostree_sysroot_get_deployments (sysroot); if (deployments->len == 0) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Unable to find a deployment in sysroot"); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unable to find a deployment in sysroot"); goto out; } first_deployment = deployments->pdata[0]; @@ -225,8 +203,7 @@ ot_admin_instutil_builtin_selinux_ensure_labeled (int argc, char **argv, OstreeC if (policy_name) { g_print ("Relabeling using policy '%s'\n", policy_name); - if (!selinux_relabel_dir (sepolicy, subpath, prefix, - cancellable, error)) + if (!selinux_relabel_dir (sepolicy, subpath, prefix, cancellable, error)) goto out; } else @@ -234,6 +211,6 @@ ot_admin_instutil_builtin_selinux_ensure_labeled (int argc, char **argv, OstreeC gs_file_get_path_cached (deployment_path)); ret = TRUE; - out: +out: return ret; } diff --git a/src/ostree/ot-admin-instutil-builtin-set-kargs.c b/src/ostree/ot-admin-instutil-builtin-set-kargs.c index ff773c3b..90a69b42 100644 --- a/src/ostree/ot-admin-instutil-builtin-set-kargs.c +++ b/src/ostree/ot-admin-instutil-builtin-set-kargs.c @@ -17,51 +17,57 @@ #include "config.h" -#include #include +#include -#include "ot-main.h" #include "ot-admin-instutil-builtins.h" +#include "ot-main.h" -#include "otutil.h" #include "ostree.h" +#include "otutil.h" static gboolean opt_proc_cmdline; static gboolean opt_merge; static char **opt_replace; static char **opt_append; -static GOptionEntry options[] = { - { "import-proc-cmdline", 0, 0, G_OPTION_ARG_NONE, &opt_proc_cmdline, "Import current /proc/cmdline", NULL }, - { "merge", 0, 0, G_OPTION_ARG_NONE, &opt_merge, "Merge with previous command line", NULL }, - { "replace", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_replace, "Set kernel argument, like root=/dev/sda1; this overrides any earlier argument with the same name", "NAME=VALUE" }, - { "append", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_append, "Append kernel argument; useful with e.g. console= that can be used multiple times", "NAME=VALUE" }, - { NULL } -}; +static GOptionEntry options[] + = { { "import-proc-cmdline", 0, 0, G_OPTION_ARG_NONE, &opt_proc_cmdline, + "Import current /proc/cmdline", NULL }, + { "merge", 0, 0, G_OPTION_ARG_NONE, &opt_merge, "Merge with previous command line", NULL }, + { "replace", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_replace, + "Set kernel argument, like root=/dev/sda1; this overrides any earlier argument with the " + "same name", + "NAME=VALUE" }, + { "append", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_append, + "Append kernel argument; useful with e.g. console= that can be used multiple times", + "NAME=VALUE" }, + { NULL } }; gboolean -ot_admin_instutil_builtin_set_kargs (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_instutil_builtin_set_kargs (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; guint i; - g_autoptr(GPtrArray) deployments = NULL; + g_autoptr (GPtrArray) deployments = NULL; OstreeDeployment *first_deployment = NULL; - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeSysroot) sysroot = NULL; - g_autoptr(OstreeKernelArgs) kargs = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeSysroot) sysroot = NULL; + g_autoptr (OstreeKernelArgs) kargs = NULL; context = g_option_context_new ("ARGS"); if (!ostree_admin_option_context_parse (context, options, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, + OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER + | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, invocation, &sysroot, cancellable, error)) goto out; deployments = ostree_sysroot_get_deployments (sysroot); if (deployments->len == 0) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Unable to find a deployment in sysroot"); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unable to find a deployment in sysroot"); goto out; } first_deployment = deployments->pdata[0]; @@ -79,7 +85,8 @@ ot_admin_instutil_builtin_set_kargs (int argc, char **argv, OstreeCommandInvocat else if (opt_merge) { OstreeBootconfigParser *bootconfig = ostree_deployment_get_bootconfig (first_deployment); - g_auto(GStrv) previous_args = g_strsplit (ostree_bootconfig_parser_get (bootconfig, "options"), " ", -1); + g_auto (GStrv) previous_args + = g_strsplit (ostree_bootconfig_parser_get (bootconfig, "options"), " ", -1); ostree_kernel_args_append_argv (kargs, previous_args); } @@ -98,15 +105,14 @@ ot_admin_instutil_builtin_set_kargs (int argc, char **argv, OstreeCommandInvocat ostree_kernel_args_append (kargs, argv[i]); { - g_auto(GStrv) kargs_strv = ostree_kernel_args_to_strv (kargs); + g_auto (GStrv) kargs_strv = ostree_kernel_args_to_strv (kargs); - if (!ostree_sysroot_deployment_set_kargs (sysroot, first_deployment, - kargs_strv, - cancellable, error)) + if (!ostree_sysroot_deployment_set_kargs (sysroot, first_deployment, kargs_strv, cancellable, + error)) goto out; } ret = TRUE; - out: +out: return ret; } diff --git a/src/ostree/ot-admin-instutil-builtins.h b/src/ostree/ot-admin-instutil-builtins.h index 832193db..746809e0 100644 --- a/src/ostree/ot-admin-instutil-builtins.h +++ b/src/ostree/ot-admin-instutil-builtins.h @@ -23,8 +23,15 @@ G_BEGIN_DECLS -gboolean ot_admin_instutil_builtin_selinux_ensure_labeled (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); -gboolean ot_admin_instutil_builtin_set_kargs (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); -gboolean ot_admin_instutil_builtin_grub2_generate (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); +gboolean ot_admin_instutil_builtin_selinux_ensure_labeled (int argc, char **argv, + OstreeCommandInvocation *invocation, + GCancellable *cancellable, + GError **error); +gboolean ot_admin_instutil_builtin_set_kargs (int argc, char **argv, + OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error); +gboolean ot_admin_instutil_builtin_grub2_generate (int argc, char **argv, + OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error); G_END_DECLS diff --git a/src/ostree/ot-admin-kargs-builtin-edit-in-place.c b/src/ostree/ot-admin-kargs-builtin-edit-in-place.c index f7125e2c..cd434a7b 100644 --- a/src/ostree/ot-admin-kargs-builtin-edit-in-place.c +++ b/src/ostree/ot-admin-kargs-builtin-edit-in-place.c @@ -18,36 +18,36 @@ #include "config.h" -#include "ot-main.h" #include "ot-admin-kargs-builtins.h" +#include "ot-main.h" #include "ostree.h" #include "otutil.h" static char **opt_kargs_edit_in_place_append; -static GOptionEntry options[] = { - { "append-if-missing", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_kargs_edit_in_place_append, "Append kernel arguments if they do not exist", "NAME=VALUE" }, - { NULL } -}; +static GOptionEntry options[] + = { { "append-if-missing", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_kargs_edit_in_place_append, + "Append kernel arguments if they do not exist", "NAME=VALUE" }, + { NULL } }; gboolean -ot_admin_kargs_builtin_edit_in_place (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_admin_kargs_builtin_edit_in_place (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(OstreeSysroot) sysroot = NULL; + g_autoptr (OstreeSysroot) sysroot = NULL; - g_autoptr(GOptionContext) context = g_option_context_new ("ARGS"); + g_autoptr (GOptionContext) context = g_option_context_new ("ARGS"); if (!ostree_admin_option_context_parse (context, options, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, - invocation, &sysroot, cancellable, error)) + OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, invocation, &sysroot, + cancellable, error)) return FALSE; - g_autoptr(GPtrArray) deployments = ostree_sysroot_get_deployments (sysroot); + g_autoptr (GPtrArray) deployments = ostree_sysroot_get_deployments (sysroot); if (deployments->len == 0) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Unable to find a deployment in sysroot"); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unable to find a deployment in sysroot"); return FALSE; } @@ -56,7 +56,8 @@ ot_admin_kargs_builtin_edit_in_place (int argc, char **argv, OstreeCommandInvoca { OstreeDeployment *deployment = deployments->pdata[i]; OstreeBootconfigParser *bootconfig = ostree_deployment_get_bootconfig (deployment); - g_autoptr(OstreeKernelArgs) kargs = ostree_kernel_args_from_string (ostree_bootconfig_parser_get (bootconfig, "options")); + g_autoptr (OstreeKernelArgs) kargs + = ostree_kernel_args_from_string (ostree_bootconfig_parser_get (bootconfig, "options")); if (opt_kargs_edit_in_place_append) { @@ -72,7 +73,6 @@ ot_admin_kargs_builtin_edit_in_place (int argc, char **argv, OstreeCommandInvoca if (!ostree_sysroot_deployment_set_kargs_in_place (sysroot, deployment, new_options, cancellable, error)) return FALSE; - } return TRUE; diff --git a/src/ostree/ot-admin-kargs-builtins.h b/src/ostree/ot-admin-kargs-builtins.h index 5d345f2a..139e81d0 100644 --- a/src/ostree/ot-admin-kargs-builtins.h +++ b/src/ostree/ot-admin-kargs-builtins.h @@ -24,11 +24,12 @@ G_BEGIN_DECLS -#define BUILTINPROTO(name) gboolean ot_admin_kargs_builtin_ ## name (int argc, char **argv, \ - OstreeCommandInvocation *invocation, \ - GCancellable *cancellable, GError **error) +#define BUILTINPROTO(name) \ + gboolean ot_admin_kargs_builtin_##name (int argc, char **argv, \ + OstreeCommandInvocation *invocation, \ + GCancellable *cancellable, GError **error) -BUILTINPROTO(edit_in_place); +BUILTINPROTO (edit_in_place); #undef BUILTINPROTO diff --git a/src/ostree/ot-builtin-admin.c b/src/ostree/ot-builtin-admin.c index 73e18d15..4d3c3364 100644 --- a/src/ostree/ot-builtin-admin.c +++ b/src/ostree/ot-builtin-admin.c @@ -21,64 +21,45 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" +#include "ostree-repo-file.h" +#include "ostree.h" #include "ot-admin-builtins.h" #include "ot-admin-functions.h" -#include "ostree.h" -#include "ostree-repo-file.h" +#include "ot-builtins.h" +#include "ot-main.h" #include static OstreeCommand admin_subcommands[] = { - { "cleanup", OSTREE_BUILTIN_FLAG_NO_REPO, - ot_admin_builtin_cleanup, + { "cleanup", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_builtin_cleanup, "Delete untagged deployments and repository objects" }, - { "config-diff", OSTREE_BUILTIN_FLAG_NO_REPO, - ot_admin_builtin_diff, + { "config-diff", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_builtin_diff, "Diff current /etc configuration versus default" }, - { "deploy", OSTREE_BUILTIN_FLAG_NO_REPO, - ot_admin_builtin_deploy, + { "deploy", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_builtin_deploy, "Checkout revision REFSPEC as the new default deployment" }, { "finalize-staged", OSTREE_BUILTIN_FLAG_NO_REPO | OSTREE_BUILTIN_FLAG_HIDDEN, - ot_admin_builtin_finalize_staged, - "Internal command to run at shutdown time" }, + ot_admin_builtin_finalize_staged, "Internal command to run at shutdown time" }, { "boot-complete", OSTREE_BUILTIN_FLAG_NO_REPO | OSTREE_BUILTIN_FLAG_HIDDEN, - ot_admin_builtin_boot_complete, - "Internal command to run at boot after an update was applied" }, - { "init-fs", OSTREE_BUILTIN_FLAG_NO_REPO, - ot_admin_builtin_init_fs, + ot_admin_builtin_boot_complete, "Internal command to run at boot after an update was applied" }, + { "init-fs", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_builtin_init_fs, "Initialize a root filesystem" }, - { "instutil", OSTREE_BUILTIN_FLAG_NO_REPO | OSTREE_BUILTIN_FLAG_HIDDEN, - ot_admin_builtin_instutil, + { "instutil", OSTREE_BUILTIN_FLAG_NO_REPO | OSTREE_BUILTIN_FLAG_HIDDEN, ot_admin_builtin_instutil, "Deprecated commands intended for installer programs" }, - { "os-init", OSTREE_BUILTIN_FLAG_NO_REPO, - ot_admin_builtin_os_init, + { "os-init", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_builtin_os_init, "Initialize empty state for given operating system" }, - { "pin", OSTREE_BUILTIN_FLAG_NO_REPO, - ot_admin_builtin_pin, + { "pin", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_builtin_pin, "Change the \"pinning\" state of a deployment" }, - { "set-origin", OSTREE_BUILTIN_FLAG_NO_REPO, - ot_admin_builtin_set_origin, + { "set-origin", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_builtin_set_origin, "Set Origin and create a new origin file" }, - { "status", OSTREE_BUILTIN_FLAG_NO_REPO, - ot_admin_builtin_status, - "List deployments" }, - { "switch", OSTREE_BUILTIN_FLAG_NO_REPO, - ot_admin_builtin_switch, + { "status", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_builtin_status, "List deployments" }, + { "switch", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_builtin_switch, "Construct new tree from REFSPEC and deploy it" }, - { "undeploy", OSTREE_BUILTIN_FLAG_NO_REPO, - ot_admin_builtin_undeploy, - "Delete deployment INDEX" }, - { "unlock", OSTREE_BUILTIN_FLAG_NO_REPO, - ot_admin_builtin_unlock, + { "undeploy", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_builtin_undeploy, "Delete deployment INDEX" }, + { "unlock", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_builtin_unlock, "Make the current deployment mutable (as a hotfix or development)" }, - { "upgrade", OSTREE_BUILTIN_FLAG_NO_REPO, - ot_admin_builtin_upgrade, + { "upgrade", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_builtin_upgrade, "Construct new tree from current origin and deploy it, if it changed" }, - { "kargs", OSTREE_BUILTIN_FLAG_NO_REPO, - ot_admin_builtin_kargs, - "Change kernel arguments" }, + { "kargs", OSTREE_BUILTIN_FLAG_NO_REPO, ot_admin_builtin_kargs, "Change kernel arguments" }, { NULL, 0, NULL, NULL } }; @@ -88,7 +69,7 @@ ostree_admin_option_context_new_with_commands (void) OstreeCommand *command = admin_subcommands; GOptionContext *context = g_option_context_new ("--print-current-dir|COMMAND"); - g_autoptr(GString) summary = g_string_new ("Builtin \"admin\" Commands:"); + g_autoptr (GString) summary = g_string_new ("Builtin \"admin\" Commands:"); while (command->name != NULL) { @@ -107,7 +88,8 @@ ostree_admin_option_context_new_with_commands (void) } gboolean -ostree_builtin_admin (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_admin (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; const char *subcommand_name = NULL; @@ -154,15 +136,15 @@ ostree_builtin_admin (int argc, char **argv, OstreeCommandInvocation *invocation if (!subcommand->name) { - g_autoptr(GOptionContext) context = NULL; + g_autoptr (GOptionContext) context = NULL; g_autofree char *help = NULL; context = ostree_admin_option_context_new_with_commands (); /* This will not return for some options (e.g. --version). */ if (ostree_admin_option_context_parse (context, NULL, &argc, &argv, - OSTREE_ADMIN_BUILTIN_FLAG_NO_SYSROOT, - invocation, NULL, cancellable, error)) + OSTREE_ADMIN_BUILTIN_FLAG_NO_SYSROOT, invocation, NULL, + cancellable, error)) { if (subcommand_name == NULL) { @@ -190,6 +172,6 @@ ostree_builtin_admin (int argc, char **argv, OstreeCommandInvocation *invocation goto out; ret = TRUE; - out: +out: return ret; } diff --git a/src/ostree/ot-builtin-cat.c b/src/ostree/ot-builtin-cat.c index 6d9736ea..58201b7c 100644 --- a/src/ostree/ot-builtin-cat.c +++ b/src/ostree/ot-builtin-cat.c @@ -21,9 +21,9 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" #include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" #include "otutil.h" #include @@ -38,28 +38,28 @@ static GOptionEntry options[] = { }; static gboolean -cat_one_file (GFile *f, - GOutputStream *stdout_stream, - GCancellable *cancellable, - GError **error) +cat_one_file (GFile *f, GOutputStream *stdout_stream, GCancellable *cancellable, GError **error) { - g_autoptr(GInputStream) in = (GInputStream*)g_file_read (f, cancellable, error); + g_autoptr (GInputStream) in = (GInputStream *)g_file_read (f, cancellable, error); if (!in) return FALSE; - if (g_output_stream_splice (stdout_stream, in, G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE, - cancellable, error) < 0) + if (g_output_stream_splice (stdout_stream, in, G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE, cancellable, + error) + < 0) return FALSE; return TRUE; } gboolean -ostree_builtin_cat (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_cat (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("COMMIT PATH..."); - g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + g_autoptr (GOptionContext) context = g_option_context_new ("COMMIT PATH..."); + g_autoptr (OstreeRepo) repo = NULL; + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) return FALSE; if (argc <= 2) @@ -69,15 +69,15 @@ ostree_builtin_cat (int argc, char **argv, OstreeCommandInvocation *invocation, } const char *rev = argv[1]; - g_autoptr(GFile) root = NULL; + g_autoptr (GFile) root = NULL; if (!ostree_repo_read_commit (repo, rev, &root, NULL, NULL, error)) return FALSE; - g_autoptr(GOutputStream) stdout_stream = g_unix_output_stream_new (1, FALSE); + g_autoptr (GOutputStream) stdout_stream = g_unix_output_stream_new (1, FALSE); for (int i = 2; i < argc; i++) { - g_autoptr(GFile) f = g_file_resolve_relative_path (root, argv[i]); + g_autoptr (GFile) f = g_file_resolve_relative_path (root, argv[i]); if (!cat_one_file (f, stdout_stream, cancellable, error)) return FALSE; diff --git a/src/ostree/ot-builtin-checkout.c b/src/ostree/ot-builtin-checkout.c index bfa43885..dfaec755 100644 --- a/src/ostree/ot-builtin-checkout.c +++ b/src/ostree/ot-builtin-checkout.c @@ -21,12 +21,12 @@ #include "config.h" -#include #include +#include -#include "ot-main.h" -#include "ot-builtins.h" #include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" #include "otutil.h" static gboolean opt_user_mode; @@ -50,10 +50,7 @@ static char *opt_selinux_policy; static char *opt_selinux_prefix; static gboolean -parse_fsync_cb (const char *option_name, - const char *value, - gpointer data, - GError **error) +parse_fsync_cb (const char *option_name, const char *value, gpointer data, GError **error) { gboolean val; @@ -71,32 +68,51 @@ parse_fsync_cb (const char *option_name, */ static GOptionEntry options[] = { - { "user-mode", 'U', 0, G_OPTION_ARG_NONE, &opt_user_mode, "Do not change file ownership or initialize extended attributes", NULL }, - { "disable-cache", 0, 0, G_OPTION_ARG_NONE, &opt_disable_cache, "Do not update or use the internal repository uncompressed object cache", NULL }, + { "user-mode", 'U', 0, G_OPTION_ARG_NONE, &opt_user_mode, + "Do not change file ownership or initialize extended attributes", NULL }, + { "disable-cache", 0, 0, G_OPTION_ARG_NONE, &opt_disable_cache, + "Do not update or use the internal repository uncompressed object cache", NULL }, { "subpath", 0, 0, G_OPTION_ARG_FILENAME, &opt_subpath, "Checkout sub-directory PATH", "PATH" }, - { "union", 0, 0, G_OPTION_ARG_NONE, &opt_union, "Keep existing directories, overwrite existing files", NULL }, - { "union-add", 0, 0, G_OPTION_ARG_NONE, &opt_union_add, "Keep existing files/directories, only add new", NULL }, - { "union-identical", 0, 0, G_OPTION_ARG_NONE, &opt_union_identical, "When layering checkouts, error out if a file would be replaced with a different version, but add new files and directories", NULL }, - { "whiteouts", 0, 0, G_OPTION_ARG_NONE, &opt_whiteouts, "Process 'whiteout' (Docker style) entries", NULL }, - { "process-passthrough-whiteouts", 0, 0, G_OPTION_ARG_NONE, &opt_process_passthrough_whiteouts, "Enable overlayfs whiteout extraction into char 0:0 devices", NULL }, - { "allow-noent", 0, 0, G_OPTION_ARG_NONE, &opt_allow_noent, "Do nothing if specified path does not exist", NULL }, - { "from-stdin", 0, 0, G_OPTION_ARG_NONE, &opt_from_stdin, "Process many checkouts from standard input", NULL }, - { "from-file", 0, 0, G_OPTION_ARG_STRING, &opt_from_file, "Process many checkouts from input file", "FILE" }, - { "fsync", 0, 0, G_OPTION_ARG_CALLBACK, parse_fsync_cb, "Specify how to invoke fsync()", "POLICY" }, - { "require-hardlinks", 'H', 0, G_OPTION_ARG_NONE, &opt_require_hardlinks, "Do not fall back to full copies if hardlinking fails", NULL }, - { "force-copy-zerosized", 'z', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_force_copy_zerosized, "Do not hardlink zero-sized files", NULL }, - { "force-copy", 'C', 0, G_OPTION_ARG_NONE, &opt_force_copy, "Never hardlink (but may reflink if available)", NULL }, - { "bareuseronly-dirs", 'M', 0, G_OPTION_ARG_NONE, &opt_bareuseronly_dirs, "Suppress mode bits outside of 0775 for directories (suid, world writable, etc.)", NULL }, - { "skip-list", 0, 0, G_OPTION_ARG_FILENAME, &opt_skiplist_file, "File containing list of files to skip", "FILE" }, - { "selinux-policy", 0, 0, G_OPTION_ARG_FILENAME, &opt_selinux_policy, "Set SELinux labels based on policy in root filesystem PATH (may be /); implies --force-copy", "PATH" }, - { "selinux-prefix", 0, 0, G_OPTION_ARG_STRING, &opt_selinux_prefix, "When setting SELinux labels, prefix all paths by PREFIX", "PREFIX" }, + { "union", 0, 0, G_OPTION_ARG_NONE, &opt_union, + "Keep existing directories, overwrite existing files", NULL }, + { "union-add", 0, 0, G_OPTION_ARG_NONE, &opt_union_add, + "Keep existing files/directories, only add new", NULL }, + { "union-identical", 0, 0, G_OPTION_ARG_NONE, &opt_union_identical, + "When layering checkouts, error out if a file would be replaced with a different version, but " + "add new files and directories", + NULL }, + { "whiteouts", 0, 0, G_OPTION_ARG_NONE, &opt_whiteouts, + "Process 'whiteout' (Docker style) entries", NULL }, + { "process-passthrough-whiteouts", 0, 0, G_OPTION_ARG_NONE, &opt_process_passthrough_whiteouts, + "Enable overlayfs whiteout extraction into char 0:0 devices", NULL }, + { "allow-noent", 0, 0, G_OPTION_ARG_NONE, &opt_allow_noent, + "Do nothing if specified path does not exist", NULL }, + { "from-stdin", 0, 0, G_OPTION_ARG_NONE, &opt_from_stdin, + "Process many checkouts from standard input", NULL }, + { "from-file", 0, 0, G_OPTION_ARG_STRING, &opt_from_file, + "Process many checkouts from input file", "FILE" }, + { "fsync", 0, 0, G_OPTION_ARG_CALLBACK, parse_fsync_cb, "Specify how to invoke fsync()", + "POLICY" }, + { "require-hardlinks", 'H', 0, G_OPTION_ARG_NONE, &opt_require_hardlinks, + "Do not fall back to full copies if hardlinking fails", NULL }, + { "force-copy-zerosized", 'z', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_force_copy_zerosized, + "Do not hardlink zero-sized files", NULL }, + { "force-copy", 'C', 0, G_OPTION_ARG_NONE, &opt_force_copy, + "Never hardlink (but may reflink if available)", NULL }, + { "bareuseronly-dirs", 'M', 0, G_OPTION_ARG_NONE, &opt_bareuseronly_dirs, + "Suppress mode bits outside of 0775 for directories (suid, world writable, etc.)", NULL }, + { "skip-list", 0, 0, G_OPTION_ARG_FILENAME, &opt_skiplist_file, + "File containing list of files to skip", "FILE" }, + { "selinux-policy", 0, 0, G_OPTION_ARG_FILENAME, &opt_selinux_policy, + "Set SELinux labels based on policy in root filesystem PATH (may be /); implies --force-copy", + "PATH" }, + { "selinux-prefix", 0, 0, G_OPTION_ARG_STRING, &opt_selinux_prefix, + "When setting SELinux labels, prefix all paths by PREFIX", "PREFIX" }, { NULL } }; static gboolean -handle_skiplist_line (const char *line, - void *data, - GError **error) +handle_skiplist_line (const char *line, void *data, GError **error) { GHashTable *files = data; g_hash_table_add (files, g_strdup (line)); @@ -104,10 +120,7 @@ handle_skiplist_line (const char *line, } static OstreeRepoCheckoutFilterResult -checkout_filter (OstreeRepo *self, - const char *path, - struct stat *st_buf, - gpointer user_data) +checkout_filter (OstreeRepo *self, const char *path, struct stat *st_buf, gpointer user_data) { GHashTable *skiplist = user_data; if (g_hash_table_contains (skiplist, path)) @@ -116,25 +129,22 @@ checkout_filter (OstreeRepo *self, } static gboolean -process_one_checkout (OstreeRepo *repo, - const char *resolved_commit, - const char *subpath, - const char *destination, - GCancellable *cancellable, - GError **error) +process_one_checkout (OstreeRepo *repo, const char *resolved_commit, const char *subpath, + const char *destination, GCancellable *cancellable, GError **error) { /* This strange code structure is to preserve testing * coverage of both `ostree_repo_checkout_tree` and * `ostree_repo_checkout_at` until such time as we have a more * convenient infrastructure for testing C APIs with data. */ - if (opt_disable_cache || opt_whiteouts || opt_require_hardlinks || - opt_union_add || opt_force_copy || opt_force_copy_zerosized || - opt_bareuseronly_dirs || opt_union_identical || - opt_skiplist_file || opt_selinux_policy || opt_selinux_prefix || - opt_process_passthrough_whiteouts) + if (opt_disable_cache || opt_whiteouts || opt_require_hardlinks || opt_union_add || opt_force_copy + || opt_force_copy_zerosized || opt_bareuseronly_dirs || opt_union_identical + || opt_skiplist_file || opt_selinux_policy || opt_selinux_prefix + || opt_process_passthrough_whiteouts) { - OstreeRepoCheckoutAtOptions checkout_options = { 0, }; + OstreeRepoCheckoutAtOptions checkout_options = { + 0, + }; /* do this early so option checking also catches force copy conflicts */ if (opt_selinux_policy) @@ -170,7 +180,7 @@ process_one_checkout (OstreeRepo *repo, if (subpath) checkout_options.subpath = subpath; - g_autoptr(OstreeSePolicy) policy = NULL; + g_autoptr (OstreeSePolicy) policy = NULL; if (opt_selinux_policy) { glnx_autofd int rootfs_dfd = -1; @@ -183,8 +193,8 @@ process_one_checkout (OstreeRepo *repo, checkout_options.sepolicy_prefix = opt_selinux_prefix; } - g_autoptr(GHashTable) skip_list = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + g_autoptr (GHashTable) skip_list + = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); if (opt_skiplist_file) { if (!ot_parse_file_by_line (opt_skiplist_file, handle_skiplist_line, skip_list, @@ -199,35 +209,31 @@ process_one_checkout (OstreeRepo *repo, checkout_options.force_copy_zerosized = opt_force_copy_zerosized; checkout_options.bareuseronly_dirs = opt_bareuseronly_dirs; - if (!ostree_repo_checkout_at (repo, &checkout_options, - AT_FDCWD, destination, - resolved_commit, + if (!ostree_repo_checkout_at (repo, &checkout_options, AT_FDCWD, destination, resolved_commit, cancellable, error)) return FALSE; } else { GError *tmp_error = NULL; - g_autoptr(GFile) root = NULL; - g_autoptr(GFile) destination_file = g_file_new_for_path (destination); + g_autoptr (GFile) root = NULL; + g_autoptr (GFile) destination_file = g_file_new_for_path (destination); if (!ostree_repo_read_commit (repo, resolved_commit, &root, NULL, cancellable, error)) return FALSE; - g_autoptr(GFile) subtree = NULL; + g_autoptr (GFile) subtree = NULL; if (subpath) subtree = g_file_resolve_relative_path (root, subpath); else subtree = g_object_ref (root); - g_autoptr(GFileInfo) file_info - = g_file_query_info (subtree, OSTREE_GIO_FAST_QUERYINFO, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - cancellable, &tmp_error); + g_autoptr (GFileInfo) file_info + = g_file_query_info (subtree, OSTREE_GIO_FAST_QUERYINFO, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, &tmp_error); if (!file_info) { - if (opt_allow_noent - && g_error_matches (tmp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) + if (opt_allow_noent && g_error_matches (tmp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { g_clear_error (&tmp_error); /* Note early return */ @@ -242,8 +248,7 @@ process_one_checkout (OstreeRepo *repo, if (!ostree_repo_checkout_tree (repo, opt_user_mode ? OSTREE_REPO_CHECKOUT_MODE_USER : 0, opt_union ? OSTREE_REPO_CHECKOUT_OVERWRITE_UNION_FILES : 0, - destination_file, - OSTREE_REPO_FILE (subtree), file_info, + destination_file, OSTREE_REPO_FILE (subtree), file_info, cancellable, error)) return FALSE; } @@ -252,46 +257,44 @@ process_one_checkout (OstreeRepo *repo, } static gboolean -process_many_checkouts (OstreeRepo *repo, - const char *target, - GCancellable *cancellable, - GError **error) +process_many_checkouts (OstreeRepo *repo, const char *target, GCancellable *cancellable, + GError **error) { gboolean ret = FALSE; gsize len; GError *temp_error = NULL; - g_autoptr(GInputStream) instream = NULL; - g_autoptr(GDataInputStream) datastream = NULL; + g_autoptr (GInputStream) instream = NULL; + g_autoptr (GDataInputStream) datastream = NULL; g_autofree char *revision = NULL; g_autofree char *subpath = NULL; g_autofree char *resolved_commit = NULL; if (opt_from_stdin) { - instream = (GInputStream*)g_unix_input_stream_new (0, FALSE); + instream = (GInputStream *)g_unix_input_stream_new (0, FALSE); } else { - g_autoptr(GFile) f = g_file_new_for_path (opt_from_file); + g_autoptr (GFile) f = g_file_new_for_path (opt_from_file); - instream = (GInputStream*)g_file_read (f, cancellable, error); + instream = (GInputStream *)g_file_read (f, cancellable, error); if (!instream) goto out; } datastream = g_data_input_stream_new (instream); - while ((revision = g_data_input_stream_read_upto (datastream, "", 1, &len, - cancellable, &temp_error)) != NULL) + while ( + (revision = g_data_input_stream_read_upto (datastream, "", 1, &len, cancellable, &temp_error)) + != NULL) { if (revision[0] == '\0') break; /* Read the null byte */ - (void) g_data_input_stream_read_byte (datastream, cancellable, NULL); + (void)g_data_input_stream_read_byte (datastream, cancellable, NULL); g_free (subpath); - subpath = g_data_input_stream_read_upto (datastream, "", 1, &len, - cancellable, &temp_error); + subpath = g_data_input_stream_read_upto (datastream, "", 1, &len, cancellable, &temp_error); if (temp_error) { g_propagate_error (error, temp_error); @@ -299,13 +302,12 @@ process_many_checkouts (OstreeRepo *repo, } /* Read the null byte */ - (void) g_data_input_stream_read_byte (datastream, cancellable, NULL); + (void)g_data_input_stream_read_byte (datastream, cancellable, NULL); if (!ostree_repo_resolve_rev (repo, revision, FALSE, &resolved_commit, error)) goto out; - if (!process_one_checkout (repo, resolved_commit, subpath, target, - cancellable, error)) + if (!process_one_checkout (repo, resolved_commit, subpath, target, cancellable, error)) { g_prefix_error (error, "Processing tree %s: ", resolved_commit); goto out; @@ -320,16 +322,18 @@ process_many_checkouts (OstreeRepo *repo, } ret = TRUE; - out: +out: return ret; } gboolean -ostree_builtin_checkout (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_checkout (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("COMMIT [DESTINATION]"); - g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + g_autoptr (GOptionContext) context = g_option_context_new ("COMMIT [DESTINATION]"); + g_autoptr (OstreeRepo) repo = NULL; + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) return FALSE; if (opt_disable_fsync) @@ -362,9 +366,8 @@ ostree_builtin_checkout (int argc, char **argv, OstreeCommandInvocation *invocat if (!ostree_repo_resolve_rev (repo, commit, FALSE, &resolved_commit, error)) return FALSE; - if (!process_one_checkout (repo, resolved_commit, opt_subpath, - destination, - cancellable, error)) + if (!process_one_checkout (repo, resolved_commit, opt_subpath, destination, cancellable, + error)) return FALSE; } diff --git a/src/ostree/ot-builtin-checksum.c b/src/ostree/ot-builtin-checksum.c index 576fbfde..b3b15c26 100644 --- a/src/ostree/ot-builtin-checksum.c +++ b/src/ostree/ot-builtin-checksum.c @@ -21,9 +21,9 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" #include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" #include @@ -34,30 +34,28 @@ static gboolean opt_ignore_xattrs; -static GOptionEntry options[] = { - { "ignore-xattrs", 0, 0, G_OPTION_ARG_NONE, &opt_ignore_xattrs, "Don't include xattrs in checksum", NULL }, - { NULL } -}; +static GOptionEntry options[] = { { "ignore-xattrs", 0, 0, G_OPTION_ARG_NONE, &opt_ignore_xattrs, + "Don't include xattrs in checksum", NULL }, + { NULL } }; -typedef struct { +typedef struct +{ GError **error; gboolean success; GMainLoop *loop; } AsyncChecksumData; static void -on_checksum_received (GObject *obj, - GAsyncResult *result, - gpointer user_data) +on_checksum_received (GObject *obj, GAsyncResult *result, gpointer user_data) { AsyncChecksumData *data = user_data; g_autofree guchar *csum_bytes = NULL; - data->success = - ostree_checksum_file_async_finish ((GFile*)obj, result, &csum_bytes, data->error); + data->success + = ostree_checksum_file_async_finish ((GFile *)obj, result, &csum_bytes, data->error); if (data->success) { - char csum[OSTREE_SHA256_STRING_LEN+1]; + char csum[OSTREE_SHA256_STRING_LEN + 1]; ostree_checksum_inplace_from_bytes (csum_bytes, csum); g_print ("%s\n", csum); } @@ -66,12 +64,12 @@ on_checksum_received (GObject *obj, } gboolean -ostree_builtin_checksum (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_checksum (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = - g_option_context_new ("PATH"); - if (!ostree_option_context_parse (context, options, &argc, &argv, - invocation, NULL, cancellable, error)) + g_autoptr (GOptionContext) context = g_option_context_new ("PATH"); + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, NULL, cancellable, + error)) return FALSE; if (argc < 2) @@ -81,23 +79,24 @@ ostree_builtin_checksum (int argc, char **argv, OstreeCommandInvocation *invocat /* for test coverage, use the async API if no flags are needed */ if (!opt_ignore_xattrs) { - g_autoptr(GFile) f = g_file_new_for_path (path); - g_autoptr(GMainLoop) loop = g_main_loop_new (NULL, FALSE); + g_autoptr (GFile) f = g_file_new_for_path (path); + g_autoptr (GMainLoop) loop = g_main_loop_new (NULL, FALSE); - AsyncChecksumData data = { 0, }; + AsyncChecksumData data = { + 0, + }; data.loop = loop; data.error = error; - ostree_checksum_file_async (f, OSTREE_OBJECT_TYPE_FILE, G_PRIORITY_DEFAULT, - cancellable, on_checksum_received, &data); + ostree_checksum_file_async (f, OSTREE_OBJECT_TYPE_FILE, G_PRIORITY_DEFAULT, cancellable, + on_checksum_received, &data); g_main_loop_run (data.loop); return data.success; } g_autofree char *checksum = NULL; if (!ostree_checksum_file_at (AT_FDCWD, path, NULL, OSTREE_OBJECT_TYPE_FILE, - OSTREE_CHECKSUM_FLAGS_IGNORE_XATTRS, &checksum, - cancellable, error)) + OSTREE_CHECKSUM_FLAGS_IGNORE_XATTRS, &checksum, cancellable, error)) return FALSE; g_print ("%s\n", checksum); diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c index 1db2e2bc..8f56779f 100644 --- a/src/ostree/ot-builtin-commit.c +++ b/src/ostree/ot-builtin-commit.c @@ -21,15 +21,15 @@ #include "config.h" -#include "ot-main.h" +#include "ostree-libarchive-private.h" +#include "ostree-repo-private.h" +#include "ostree-sign.h" +#include "ostree.h" #include "ot-builtins.h" #include "ot-editor.h" -#include "ostree.h" +#include "ot-main.h" #include "otutil.h" #include "parse-datetime.h" -#include "ostree-repo-private.h" -#include "ostree-libarchive-private.h" -#include "ostree-sign.h" static char *opt_subject; static char *opt_body; @@ -74,10 +74,7 @@ static gboolean opt_disable_fsync; static char *opt_timestamp; static gboolean -parse_fsync_cb (const char *option_name, - const char *value, - gpointer data, - GError **error) +parse_fsync_cb (const char *option_name, const char *value, gpointer data, GError **error) { gboolean val; if (!ot_parse_boolean (value, &val, error)) @@ -93,61 +90,95 @@ parse_fsync_cb (const char *option_name, */ static GOptionEntry options[] = { - { "parent", 0, 0, G_OPTION_ARG_STRING, &opt_parent, "Parent commit checksum, or \"none\"", "COMMIT" }, + { "parent", 0, 0, G_OPTION_ARG_STRING, &opt_parent, "Parent commit checksum, or \"none\"", + "COMMIT" }, { "subject", 's', 0, G_OPTION_ARG_STRING, &opt_subject, "One line subject", "SUBJECT" }, { "body", 'm', 0, G_OPTION_ARG_STRING, &opt_body, "Full description", "BODY" }, - { "body-file", 'F', 0, G_OPTION_ARG_FILENAME, &opt_body_file, "Commit message from FILE path", "FILE" }, - { "editor", 'e', 0, G_OPTION_ARG_NONE, &opt_editor, "Use an editor to write the commit message", NULL }, + { "body-file", 'F', 0, G_OPTION_ARG_FILENAME, &opt_body_file, "Commit message from FILE path", + "FILE" }, + { "editor", 'e', 0, G_OPTION_ARG_NONE, &opt_editor, "Use an editor to write the commit message", + NULL }, { "branch", 'b', 0, G_OPTION_ARG_STRING, &opt_branch, "Branch", "BRANCH" }, { "orphan", 0, 0, G_OPTION_ARG_NONE, &opt_orphan, "Create a commit without writing a ref", NULL }, - { "no-bindings", 0, 0, G_OPTION_ARG_NONE, &opt_no_bindings, "Do not write any ref bindings", NULL }, - { "bind-ref", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_bind_refs, "Add a ref to ref binding commit metadata", "BRANCH" }, - { "base", 0, 0, G_OPTION_ARG_STRING, &opt_base, "Start from the given commit as a base (no modifiers apply)", "REV" }, - { "tree", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_trees, "Overlay the given argument as a tree", "dir=PATH or tar=TARFILE or ref=COMMIT" }, - { "add-metadata-string", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_metadata_strings, "Add a key/value pair to metadata", "KEY=VALUE" }, - { "add-metadata", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_metadata_variants, "Add a key/value pair to metadata, where the KEY is a string, and VALUE is in GVariant Text Format", "KEY=VALUE" }, - { "keep-metadata", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_metadata_keep, "Keep metadata KEY and its associated VALUE from parent", "KEY" }, - { "add-detached-metadata-string", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_detached_metadata_strings, "Add a key/value pair to detached metadata", "KEY=VALUE" }, + { "no-bindings", 0, 0, G_OPTION_ARG_NONE, &opt_no_bindings, "Do not write any ref bindings", + NULL }, + { "bind-ref", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_bind_refs, + "Add a ref to ref binding commit metadata", "BRANCH" }, + { "base", 0, 0, G_OPTION_ARG_STRING, &opt_base, + "Start from the given commit as a base (no modifiers apply)", "REV" }, + { "tree", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_trees, "Overlay the given argument as a tree", + "dir=PATH or tar=TARFILE or ref=COMMIT" }, + { "add-metadata-string", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_metadata_strings, + "Add a key/value pair to metadata", "KEY=VALUE" }, + { "add-metadata", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_metadata_variants, + "Add a key/value pair to metadata, where the KEY is a string, and VALUE is in GVariant Text " + "Format", + "KEY=VALUE" }, + { "keep-metadata", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_metadata_keep, + "Keep metadata KEY and its associated VALUE from parent", "KEY" }, + { "add-detached-metadata-string", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_detached_metadata_strings, + "Add a key/value pair to detached metadata", "KEY=VALUE" }, { "owner-uid", 0, 0, G_OPTION_ARG_INT, &opt_owner_uid, "Set file ownership user id", "UID" }, { "owner-gid", 0, 0, G_OPTION_ARG_INT, &opt_owner_gid, "Set file ownership group id", "GID" }, - { "canonical-permissions", 0, 0, G_OPTION_ARG_NONE, &opt_canonical_permissions, "Canonicalize permissions in the same way bare-user does for hardlinked files", NULL }, - { "bootable", 0, 0, G_OPTION_ARG_NONE, &opt_bootable, "Flag this commit as a bootable OSTree (e.g. contains a Linux kernel)", NULL }, - { "mode-ro-executables", 0, 0, G_OPTION_ARG_NONE, &opt_ro_executables, "Ensure executable files are not writable", NULL }, - { "no-xattrs", 0, 0, G_OPTION_ARG_NONE, &opt_no_xattrs, "Do not import extended attributes", NULL }, - { "selinux-policy", 0, 0, G_OPTION_ARG_FILENAME, &opt_selinux_policy, "Set SELinux labels based on policy in root filesystem PATH (may be /)", "PATH" }, - { "selinux-policy-from-base", 'P', 0, G_OPTION_ARG_NONE, &opt_selinux_policy_from_base, "Set SELinux labels based on first --tree argument", NULL }, - { "link-checkout-speedup", 0, 0, G_OPTION_ARG_NONE, &opt_link_checkout_speedup, "Optimize for commits of trees composed of hardlinks into the repository", NULL }, - { "devino-canonical", 'I', 0, G_OPTION_ARG_NONE, &opt_devino_canonical, "Assume hardlinked objects are unmodified. Implies --link-checkout-speedup", NULL }, - { "tar-autocreate-parents", 0, 0, G_OPTION_ARG_NONE, &opt_tar_autocreate_parents, "When loading tar archives, automatically create parent directories as needed", NULL }, - { "tar-pathname-filter", 0, 0, G_OPTION_ARG_STRING, &opt_tar_pathname_filter, "When loading tar archives, use REGEX,REPLACEMENT against path names", "REGEX,REPLACEMENT" }, - { "skip-if-unchanged", 0, 0, G_OPTION_ARG_NONE, &opt_skip_if_unchanged, "If the contents are unchanged from previous commit, do nothing", NULL }, - { "statoverride", 0, 0, G_OPTION_ARG_FILENAME, &opt_statoverride_file, "File containing list of modifications to make to permissions", "PATH" }, - { "skip-list", 0, 0, G_OPTION_ARG_FILENAME, &opt_skiplist_file, "File containing list of files to skip", "PATH" }, - { "consume", 0, 0, G_OPTION_ARG_NONE, &opt_consume, "Consume (delete) content after commit (for local directories)", NULL }, - { "table-output", 0, 0, G_OPTION_ARG_NONE, &opt_table_output, "Output more information in a KEY: VALUE format", NULL }, + { "canonical-permissions", 0, 0, G_OPTION_ARG_NONE, &opt_canonical_permissions, + "Canonicalize permissions in the same way bare-user does for hardlinked files", NULL }, + { "bootable", 0, 0, G_OPTION_ARG_NONE, &opt_bootable, + "Flag this commit as a bootable OSTree (e.g. contains a Linux kernel)", NULL }, + { "mode-ro-executables", 0, 0, G_OPTION_ARG_NONE, &opt_ro_executables, + "Ensure executable files are not writable", NULL }, + { "no-xattrs", 0, 0, G_OPTION_ARG_NONE, &opt_no_xattrs, "Do not import extended attributes", + NULL }, + { "selinux-policy", 0, 0, G_OPTION_ARG_FILENAME, &opt_selinux_policy, + "Set SELinux labels based on policy in root filesystem PATH (may be /)", "PATH" }, + { "selinux-policy-from-base", 'P', 0, G_OPTION_ARG_NONE, &opt_selinux_policy_from_base, + "Set SELinux labels based on first --tree argument", NULL }, + { "link-checkout-speedup", 0, 0, G_OPTION_ARG_NONE, &opt_link_checkout_speedup, + "Optimize for commits of trees composed of hardlinks into the repository", NULL }, + { "devino-canonical", 'I', 0, G_OPTION_ARG_NONE, &opt_devino_canonical, + "Assume hardlinked objects are unmodified. Implies --link-checkout-speedup", NULL }, + { "tar-autocreate-parents", 0, 0, G_OPTION_ARG_NONE, &opt_tar_autocreate_parents, + "When loading tar archives, automatically create parent directories as needed", NULL }, + { "tar-pathname-filter", 0, 0, G_OPTION_ARG_STRING, &opt_tar_pathname_filter, + "When loading tar archives, use REGEX,REPLACEMENT against path names", "REGEX,REPLACEMENT" }, + { "skip-if-unchanged", 0, 0, G_OPTION_ARG_NONE, &opt_skip_if_unchanged, + "If the contents are unchanged from previous commit, do nothing", NULL }, + { "statoverride", 0, 0, G_OPTION_ARG_FILENAME, &opt_statoverride_file, + "File containing list of modifications to make to permissions", "PATH" }, + { "skip-list", 0, 0, G_OPTION_ARG_FILENAME, &opt_skiplist_file, + "File containing list of files to skip", "PATH" }, + { "consume", 0, 0, G_OPTION_ARG_NONE, &opt_consume, + "Consume (delete) content after commit (for local directories)", NULL }, + { "table-output", 0, 0, G_OPTION_ARG_NONE, &opt_table_output, + "Output more information in a KEY: VALUE format", NULL }, #ifndef OSTREE_DISABLE_GPGME - { "gpg-sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_gpg_key_ids, "GPG Key ID to sign the commit with", "KEY-ID"}, - { "gpg-homedir", 0, 0, G_OPTION_ARG_FILENAME, &opt_gpg_homedir, "GPG Homedir to use when looking for keyrings", "HOMEDIR"}, + { "gpg-sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_gpg_key_ids, + "GPG Key ID to sign the commit with", "KEY-ID" }, + { "gpg-homedir", 0, 0, G_OPTION_ARG_FILENAME, &opt_gpg_homedir, + "GPG Homedir to use when looking for keyrings", "HOMEDIR" }, #endif - { "sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_key_ids, "Sign the commit with", "KEY_ID"}, - { "sign-type", 0, 0, G_OPTION_ARG_STRING, &opt_sign_name, "Signature type to use (defaults to 'ed25519')", "NAME"}, - { "generate-sizes", 0, 0, G_OPTION_ARG_NONE, &opt_generate_sizes, "Generate size information along with commit metadata", NULL }, - { "disable-fsync", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", NULL }, - { "fsync", 0, 0, G_OPTION_ARG_CALLBACK, parse_fsync_cb, "Specify how to invoke fsync()", "POLICY" }, - { "timestamp", 0, 0, G_OPTION_ARG_STRING, &opt_timestamp, "Override the timestamp of the commit", "TIMESTAMP" }, + { "sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_key_ids, "Sign the commit with", "KEY_ID" }, + { "sign-type", 0, 0, G_OPTION_ARG_STRING, &opt_sign_name, + "Signature type to use (defaults to 'ed25519')", "NAME" }, + { "generate-sizes", 0, 0, G_OPTION_ARG_NONE, &opt_generate_sizes, + "Generate size information along with commit metadata", NULL }, + { "disable-fsync", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_disable_fsync, + "Do not invoke fsync()", NULL }, + { "fsync", 0, 0, G_OPTION_ARG_CALLBACK, parse_fsync_cb, "Specify how to invoke fsync()", + "POLICY" }, + { "timestamp", 0, 0, G_OPTION_ARG_STRING, &opt_timestamp, "Override the timestamp of the commit", + "TIMESTAMP" }, { NULL } }; -struct CommitFilterData { +struct CommitFilterData +{ GHashTable *mode_adds; GHashTable *mode_overrides; GHashTable *skip_list; }; static gboolean -handle_statoverride_line (const char *line, - void *data, - GError **error) +handle_statoverride_line (const char *line, void *data, GError **error) { struct CommitFilterData *cf = data; const char *spc = strchr (line, ' '); @@ -157,23 +188,20 @@ handle_statoverride_line (const char *line, if (g_str_has_prefix (line, "=")) { - guint mode_override = (guint32)(gint32)g_ascii_strtod (line+1, NULL); + guint mode_override = (guint32)(gint32)g_ascii_strtod (line + 1, NULL); g_hash_table_insert (cf->mode_overrides, g_strdup (fn), - GUINT_TO_POINTER((gint32)mode_override)); + GUINT_TO_POINTER ((gint32)mode_override)); } else { guint mode_add = (guint32)(gint32)g_ascii_strtod (line, NULL); - g_hash_table_insert (cf->mode_adds, g_strdup (fn), - GUINT_TO_POINTER((gint32)mode_add)); + g_hash_table_insert (cf->mode_adds, g_strdup (fn), GUINT_TO_POINTER ((gint32)mode_add)); } return TRUE; } static gboolean -handle_skiplist_line (const char *line, - void *data, - GError **error) +handle_skiplist_line (const char *line, void *data, GError **error) { GHashTable *files = data; g_hash_table_add (files, g_strdup (line)); @@ -181,10 +209,7 @@ handle_skiplist_line (const char *line, } static OstreeRepoCommitFilterResult -commit_filter (OstreeRepo *self, - const char *path, - GFileInfo *file_info, - gpointer user_data) +commit_filter (OstreeRepo *self, const char *path, GFileInfo *file_info, gpointer user_data) { struct CommitFilterData *data = user_data; GHashTable *mode_adds = data->mode_adds; @@ -207,16 +232,14 @@ commit_filter (OstreeRepo *self, if (mode_adds && g_hash_table_lookup_extended (mode_adds, path, NULL, &value)) { guint mode_add = GPOINTER_TO_UINT (value); - g_file_info_set_attribute_uint32 (file_info, "unix::mode", - mode | mode_add); + g_file_info_set_attribute_uint32 (file_info, "unix::mode", mode | mode_add); g_hash_table_remove (mode_adds, path); } else if (mode_overrides && g_hash_table_lookup_extended (mode_overrides, path, NULL, &value)) { guint current_fmt = g_file_info_get_attribute_uint32 (file_info, "unix::mode") & S_IFMT; guint mode_override = GPOINTER_TO_UINT (value); - g_file_info_set_attribute_uint32 (file_info, "unix::mode", - current_fmt | mode_override); + g_file_info_set_attribute_uint32 (file_info, "unix::mode", current_fmt | mode_override); g_hash_table_remove (mode_adds, path); } @@ -230,23 +253,20 @@ commit_filter (OstreeRepo *self, } #ifdef HAVE_LIBARCHIVE -typedef struct { +typedef struct +{ GRegex *regex; const char *replacement; } TranslatePathnameData; /* Implement --tar-pathname-filter */ static char * -handle_translate_pathname (OstreeRepo *repo, - const struct stat *stbuf, - const char *path, +handle_translate_pathname (OstreeRepo *repo, const struct stat *stbuf, const char *path, gpointer user_data) { TranslatePathnameData *tpdata = user_data; - g_autoptr(GError) tmp_error = NULL; - char *ret = - g_regex_replace (tpdata->regex, path, -1, 0, - tpdata->replacement, 0, &tmp_error); + g_autoptr (GError) tmp_error = NULL; + char *ret = g_regex_replace (tpdata->regex, path, -1, 0, tpdata->replacement, 0, &tmp_error); g_assert_no_error (tmp_error); g_assert (ret); return ret; @@ -254,22 +274,17 @@ handle_translate_pathname (OstreeRepo *repo, #endif static gboolean -commit_editor (OstreeRepo *repo, - const char *branch, - char **subject, - char **body, - GCancellable *cancellable, - GError **error) +commit_editor (OstreeRepo *repo, const char *branch, char **subject, char **body, + GCancellable *cancellable, GError **error) { - g_autofree char *input = g_strdup_printf ("\n" + g_autofree char *input = g_strdup_printf ( + "\n" "# Please enter the commit message for your changes. The first line will\n" "# become the subject, and the remainder the body. Lines starting\n" "# with '#' will be ignored, and an empty message aborts the commit." - "%s%s%s%s%s%s\n" - , branch ? "\n#\n# Branch: " : "", branch ? branch : "" - , *subject ? "\n" : "", *subject ? *subject : "" - , *body ? "\n" : "", *body ? *body : "" - ); + "%s%s%s%s%s%s\n", + branch ? "\n#\n# Branch: " : "", branch ? branch : "", *subject ? "\n" : "", + *subject ? *subject : "", *body ? "\n" : "", *body ? *body : ""); *subject = NULL; *body = NULL; @@ -278,8 +293,8 @@ commit_editor (OstreeRepo *repo, if (output == NULL) return FALSE; - g_auto(GStrv) lines = g_strsplit (output, "\n", -1); - g_autoptr(GString) bodybuf = NULL; + g_auto (GStrv) lines = g_strsplit (output, "\n", -1); + g_autoptr (GString) bodybuf = NULL; for (guint i = 0; lines[i] != NULL; i++) { g_strchomp (lines[i]); @@ -323,12 +338,10 @@ commit_editor (OstreeRepo *repo, } static gboolean -parse_keyvalue_strings (GVariantBuilder *builder, - char **strings, - gboolean is_gvariant_print, - GError **error) +parse_keyvalue_strings (GVariantBuilder *builder, char **strings, gboolean is_gvariant_print, + GError **error) { - for (char ** iter = strings; *iter; iter++) + for (char **iter = strings; *iter; iter++) { const char *s = *iter; const char *eq = strchr (s, '='); @@ -338,23 +351,21 @@ parse_keyvalue_strings (GVariantBuilder *builder, const char *value = eq + 1; if (is_gvariant_print) { - g_autoptr(GVariant) variant = g_variant_parse (NULL, value, NULL, NULL, error); + g_autoptr (GVariant) variant = g_variant_parse (NULL, value, NULL, NULL, error); if (!variant) return glnx_prefix_error (error, "Parsing %s", s); g_variant_builder_add (builder, "{sv}", key, variant); } else - g_variant_builder_add (builder, "{sv}", key, - g_variant_new_string (value)); + g_variant_builder_add (builder, "{sv}", key, g_variant_new_string (value)); } return TRUE; } static void -add_collection_binding (OstreeRepo *repo, - GVariantBuilder *metadata_builder) +add_collection_binding (OstreeRepo *repo, GVariantBuilder *metadata_builder) { const char *collection_id = ostree_repo_get_collection_id (repo); @@ -379,67 +390,68 @@ add_ref_binding (GVariantBuilder *metadata_builder) { g_assert (opt_branch != NULL || opt_orphan); - g_autoptr(GPtrArray) refs = g_ptr_array_new (); + g_autoptr (GPtrArray) refs = g_ptr_array_new (); if (opt_branch != NULL) g_ptr_array_add (refs, opt_branch); for (char **iter = opt_bind_refs; iter != NULL && *iter != NULL; ++iter) g_ptr_array_add (refs, *iter); g_ptr_array_sort (refs, compare_strings); - g_autoptr(GVariant) refs_v = g_variant_new_strv ((const char *const *)refs->pdata, - refs->len); + g_autoptr (GVariant) refs_v = g_variant_new_strv ((const char *const *)refs->pdata, refs->len); g_variant_builder_add (metadata_builder, "{s@v}", OSTREE_COMMIT_META_KEY_REF_BINDING, g_variant_new_variant (g_steal_pointer (&refs_v))); } /* Note if you're using the API, you currently need to do this yourself */ static void -fill_bindings (OstreeRepo *repo, - GVariant *metadata, - GVariant **out_metadata) +fill_bindings (OstreeRepo *repo, GVariant *metadata, GVariant **out_metadata) { - g_autoptr(GVariantBuilder) metadata_builder = - ot_util_variant_builder_from_variant (metadata, G_VARIANT_TYPE_VARDICT); + g_autoptr (GVariantBuilder) metadata_builder + = ot_util_variant_builder_from_variant (metadata, G_VARIANT_TYPE_VARDICT); add_ref_binding (metadata_builder); /* Allow the collection ID to be overridden using * --add-metadata-string=ostree.collection-binding=blah */ - if (metadata == NULL || - !g_variant_lookup (metadata, OSTREE_COMMIT_META_KEY_COLLECTION_BINDING, "*", NULL)) + if (metadata == NULL + || !g_variant_lookup (metadata, OSTREE_COMMIT_META_KEY_COLLECTION_BINDING, "*", NULL)) add_collection_binding (repo, metadata_builder); *out_metadata = g_variant_ref_sink (g_variant_builder_end (metadata_builder)); } gboolean -ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeRepo) repo = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeRepo) repo = NULL; gboolean ret = FALSE; gboolean skip_commit = FALSE; - g_autoptr(GFile) object_to_commit = NULL; + g_autoptr (GFile) object_to_commit = NULL; g_autofree char *parent = NULL; g_autofree char *commit_checksum = NULL; - g_autoptr(GFile) root = NULL; - g_autoptr(GVariant) metadata = NULL; - g_autoptr(GVariant) detached_metadata = NULL; - g_autoptr(OstreeMutableTree) mtree = NULL; + g_autoptr (GFile) root = NULL; + g_autoptr (GVariant) metadata = NULL; + g_autoptr (GVariant) detached_metadata = NULL; + g_autoptr (OstreeMutableTree) mtree = NULL; g_autofree char *tree_type = NULL; - g_autoptr(GHashTable) mode_adds = NULL; - g_autoptr(GHashTable) mode_overrides = NULL; - g_autoptr(GHashTable) skip_list = NULL; + g_autoptr (GHashTable) mode_adds = NULL; + g_autoptr (GHashTable) mode_overrides = NULL; + g_autoptr (GHashTable) skip_list = NULL; OstreeRepoCommitModifierFlags flags = 0; - g_autoptr(OstreeSePolicy) policy = NULL; - g_autoptr(OstreeRepoCommitModifier) modifier = NULL; + g_autoptr (OstreeSePolicy) policy = NULL; + g_autoptr (OstreeRepoCommitModifier) modifier = NULL; OstreeRepoTransactionStats stats; - struct CommitFilterData filter_data = { 0, }; + struct CommitFilterData filter_data = { + 0, + }; g_autofree char *commit_body = NULL; g_autoptr (OstreeSign) sign = NULL; context = g_option_context_new ("[PATH]"); - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) goto out; if (!ostree_ensure_repo_writable (repo, error)) @@ -447,18 +459,20 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio if (opt_statoverride_file) { - filter_data.mode_adds = mode_adds = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - filter_data.mode_overrides = mode_overrides = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - if (!ot_parse_file_by_line (opt_statoverride_file, handle_statoverride_line, - &filter_data, cancellable, error)) + filter_data.mode_adds = mode_adds + = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + filter_data.mode_overrides = mode_overrides + = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + if (!ot_parse_file_by_line (opt_statoverride_file, handle_statoverride_line, &filter_data, + cancellable, error)) goto out; } if (opt_skiplist_file) { skip_list = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - if (!ot_parse_file_by_line (opt_skiplist_file, handle_skiplist_line, - skip_list, cancellable, error)) + if (!ot_parse_file_by_line (opt_skiplist_file, handle_skiplist_line, skip_list, cancellable, + error)) goto out; } @@ -487,10 +501,11 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio if (g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY)) { /* A folder exists with the specified ref name, - * which is handled by _ostree_repo_write_ref */ + * which is handled by _ostree_repo_write_ref */ g_clear_error (error); } - else goto out; + else + goto out; } } @@ -504,31 +519,30 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio if (opt_metadata_strings || opt_metadata_variants || opt_metadata_keep || opt_bootable) { - g_autoptr(GVariantBuilder) builder = - g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); + g_autoptr (GVariantBuilder) builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); - if (opt_metadata_strings && - !parse_keyvalue_strings (builder, opt_metadata_strings, FALSE, error)) - goto out; + if (opt_metadata_strings + && !parse_keyvalue_strings (builder, opt_metadata_strings, FALSE, error)) + goto out; - if (opt_metadata_variants && - !parse_keyvalue_strings (builder, opt_metadata_variants, TRUE, error)) + if (opt_metadata_variants + && !parse_keyvalue_strings (builder, opt_metadata_variants, TRUE, error)) goto out; if (opt_metadata_keep) { g_assert (parent); - g_autoptr(GVariant) parent_commit = NULL; + g_autoptr (GVariant) parent_commit = NULL; if (!ostree_repo_load_commit (repo, parent, &parent_commit, NULL, error)) goto out; - g_auto(GVariantDict) dict; + g_auto (GVariantDict) dict; g_variant_dict_init (&dict, g_variant_get_child_value (parent_commit, 0)); for (char **keyp = opt_metadata_keep; keyp && *keyp; keyp++) { const char *key = *keyp; - g_autoptr(GVariant) val = g_variant_dict_lookup_value (&dict, key, NULL); + g_autoptr (GVariant) val = g_variant_dict_lookup_value (&dict, key, NULL); if (!val) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, @@ -545,8 +559,7 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio if (opt_detached_metadata_strings) { - g_autoptr(GVariantBuilder) builder = - g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); + g_autoptr (GVariantBuilder) builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); if (!parse_keyvalue_strings (builder, opt_detached_metadata_strings, FALSE, error)) goto out; @@ -587,20 +600,13 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio if (opt_disable_fsync) ostree_repo_set_disable_fsync (repo, TRUE); - if (flags != 0 - || opt_owner_uid >= 0 - || opt_owner_gid >= 0 - || opt_statoverride_file != NULL - || opt_skiplist_file != NULL - || opt_no_xattrs - || opt_ro_executables - || opt_selinux_policy + if (flags != 0 || opt_owner_uid >= 0 || opt_owner_gid >= 0 || opt_statoverride_file != NULL + || opt_skiplist_file != NULL || opt_no_xattrs || opt_ro_executables || opt_selinux_policy || opt_selinux_policy_from_base) { filter_data.mode_adds = mode_adds; filter_data.skip_list = skip_list; - modifier = ostree_repo_commit_modifier_new (flags, commit_filter, - &filter_data, NULL); + modifier = ostree_repo_commit_modifier_new (flags, commit_filter, &filter_data, NULL); if (opt_selinux_policy) { @@ -621,8 +627,8 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio } else if (opt_body_file) { - commit_body = glnx_file_get_contents_utf8_at (AT_FDCWD, opt_body_file, NULL, - cancellable, error); + commit_body + = glnx_file_get_contents_utf8_at (AT_FDCWD, opt_body_file, NULL, cancellable, error); if (!commit_body) goto out; } @@ -644,7 +650,8 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio if (opt_selinux_policy_from_base) { g_assert (modifier); - if (!ostree_repo_commit_modifier_set_sepolicy_from_commit (modifier, repo, opt_base, cancellable, error)) + if (!ostree_repo_commit_modifier_set_sepolicy_from_commit (modifier, repo, opt_base, + cancellable, error)) goto out; /* Don't try to handle it twice */ opt_selinux_policy_from_base = FALSE; @@ -655,7 +662,6 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio mtree = ostree_mutable_tree_new (); } - /* Convert implicit . or explicit path via argv into * --tree=dir= so that we only have one primary code path below. */ @@ -670,20 +676,20 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio opt_trees[0] = g_strconcat ("dir=", path, NULL); } - const char *const*tree_iter; + const char *const *tree_iter; const char *tree; const char *eq; g_assert (opt_trees && *opt_trees); - for (tree_iter = (const char *const*)opt_trees; *tree_iter; tree_iter++) + for (tree_iter = (const char *const *)opt_trees; *tree_iter; tree_iter++) { - const gboolean first = (tree_iter == (const char *const*)opt_trees); + const gboolean first = (tree_iter == (const char *const *)opt_trees); tree = *tree_iter; eq = strchr (tree, '='); if (!eq) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Missing type in tree specification '%s'", tree); + "Missing type in tree specification '%s'", tree); goto out; } g_free (tree_type); @@ -703,8 +709,8 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio goto out; ostree_repo_commit_modifier_set_sepolicy (modifier, policy); } - if (!ostree_repo_write_dfd_to_mtree (repo, AT_FDCWD, tree, mtree, modifier, - cancellable, error)) + if (!ostree_repo_write_dfd_to_mtree (repo, AT_FDCWD, tree, mtree, modifier, cancellable, + error)) goto out; } else if (strcmp (tree_type, "tar") == 0) @@ -718,9 +724,9 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio { if (strcmp (tree, "-") == 0) { - if (!ostree_repo_write_archive_to_mtree_from_fd (repo, STDIN_FILENO, mtree, modifier, - opt_tar_autocreate_parents, - cancellable, error)) + if (!ostree_repo_write_archive_to_mtree_from_fd ( + repo, STDIN_FILENO, mtree, modifier, opt_tar_autocreate_parents, + cancellable, error)) goto out; } else @@ -728,8 +734,8 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio object_to_commit = g_file_new_for_path (tree); if (!ostree_repo_write_archive_to_mtree (repo, object_to_commit, mtree, modifier, - opt_tar_autocreate_parents, - cancellable, error)) + opt_tar_autocreate_parents, cancellable, + error)) goto out; } } @@ -740,16 +746,19 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio if (!comma) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Missing ',' in --tar-pathname-filter"); + "Missing ',' in --tar-pathname-filter"); goto out; } const char *replacement = comma + 1; - g_autofree char *regexp_text = g_strndup (opt_tar_pathname_filter, comma - opt_tar_pathname_filter); + g_autofree char *regexp_text + = g_strndup (opt_tar_pathname_filter, comma - opt_tar_pathname_filter); /* Use new API if we have a pathname filter */ - OstreeRepoImportArchiveOptions opts = { 0, }; + OstreeRepoImportArchiveOptions opts = { + 0, + }; opts.autocreate_parents = opt_tar_autocreate_parents; opts.translate_pathname = handle_translate_pathname; - g_autoptr(GRegex) regexp = g_regex_new (regexp_text, 0, 0, error); + g_autoptr (GRegex) regexp = g_regex_new (regexp_text, 0, 0, error); TranslatePathnameData tpdata = { regexp, replacement }; if (!regexp) { @@ -758,7 +767,7 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio } opts.translate_pathname_user_data = &tpdata; - g_autoptr(OtAutoArchiveRead) archive; + g_autoptr (OtAutoArchiveRead) archive; if (strcmp (tree, "-") == 0) archive = ot_open_archive_read_fd (STDIN_FILENO, error); else @@ -766,12 +775,12 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio if (!archive) goto out; - if (!ostree_repo_import_archive_to_mtree (repo, &opts, archive, mtree, - modifier, cancellable, error)) + if (!ostree_repo_import_archive_to_mtree (repo, &opts, archive, mtree, modifier, + cancellable, error)) goto out; #else g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, - "This version of ostree is not compiled with libarchive support"); + "This version of ostree is not compiled with libarchive support"); goto out; #endif } @@ -781,20 +790,21 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio if (first && opt_selinux_policy_from_base) { g_assert (modifier); - if (!ostree_repo_commit_modifier_set_sepolicy_from_commit (modifier, repo, tree, cancellable, error)) + if (!ostree_repo_commit_modifier_set_sepolicy_from_commit (modifier, repo, tree, + cancellable, error)) goto out; } if (!ostree_repo_read_commit (repo, tree, &object_to_commit, NULL, cancellable, error)) goto out; if (!ostree_repo_write_directory_to_mtree (repo, object_to_commit, mtree, modifier, - cancellable, error)) + cancellable, error)) goto out; } else { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Invalid tree type specification '%s'", tree_type); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid tree type specification '%s'", + tree_type); goto out; } } @@ -808,10 +818,9 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio while (g_hash_table_iter_next (&hash_iter, &key, &value)) { - g_printerr ("Unmatched statoverride path: %s\n", (char*)key); + g_printerr ("Unmatched statoverride path: %s\n", (char *)key); } - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Unmatched statoverride paths"); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unmatched statoverride paths"); goto out; } @@ -824,10 +833,9 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio while (g_hash_table_iter_next (&hash_iter, &key, NULL)) { - g_printerr ("Unmatched skip-list path: %s\n", (char*)key); + g_printerr ("Unmatched skip-list path: %s\n", (char *)key); } - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Unmatched skip-list paths"); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unmatched skip-list paths"); goto out; } @@ -836,7 +844,7 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio if (opt_skip_if_unchanged && parent) { - g_autoptr(GFile) parent_root; + g_autoptr (GFile) parent_root; if (!ostree_repo_read_commit (repo, parent, &parent_root, NULL, cancellable, error)) goto out; @@ -849,14 +857,14 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio { if (!opt_no_bindings) { - g_autoptr(GVariant) old_metadata = g_steal_pointer (&metadata); + g_autoptr (GVariant) old_metadata = g_steal_pointer (&metadata); fill_bindings (repo, old_metadata, &metadata); } if (opt_bootable) { - g_autoptr(GVariant) old_metadata = g_steal_pointer (&metadata); - g_auto(GVariantDict) bootmeta; + g_autoptr (GVariant) old_metadata = g_steal_pointer (&metadata); + g_auto (GVariantDict) bootmeta; g_variant_dict_init (&bootmeta, old_metadata); if (!ostree_commit_metadata_for_bootable (root, &bootmeta, cancellable, error)) goto out; @@ -867,8 +875,8 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio if (!opt_timestamp) { if (!ostree_repo_write_commit (repo, parent, opt_subject, commit_body, metadata, - OSTREE_REPO_FILE (root), - &commit_checksum, cancellable, error)) + OSTREE_REPO_FILE (root), &commit_checksum, cancellable, + error)) goto out; } else @@ -876,23 +884,21 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio struct timespec ts; if (!parse_datetime (&ts, opt_timestamp, NULL)) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Could not parse '%s'", opt_timestamp); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Could not parse '%s'", + opt_timestamp); goto out; } guint64 timestamp = ts.tv_sec; if (!ostree_repo_write_commit_with_time (repo, parent, opt_subject, commit_body, metadata, - OSTREE_REPO_FILE (root), - timestamp, + OSTREE_REPO_FILE (root), timestamp, &commit_checksum, cancellable, error)) goto out; } if (detached_metadata) { - if (!ostree_repo_write_commit_detached_metadata (repo, commit_checksum, - detached_metadata, + if (!ostree_repo_write_commit_detached_metadata (repo, commit_checksum, detached_metadata, cancellable, error)) goto out; } @@ -915,13 +921,9 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio secret_key = g_variant_new_string (keyid); if (!ostree_sign_set_sk (sign, secret_key, error)) - goto out; + goto out; - if (!ostree_sign_commit (sign, - repo, - commit_checksum, - cancellable, - error)) + if (!ostree_sign_commit (sign, repo, commit_checksum, cancellable, error)) goto out; } } @@ -935,12 +937,8 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio { const char *keyid = *iter; - if (!ostree_repo_sign_commit (repo, - commit_checksum, - keyid, - opt_gpg_homedir, - cancellable, - error)) + if (!ostree_repo_sign_commit (repo, commit_checksum, keyid, opt_gpg_homedir, + cancellable, error)) goto out; } } @@ -975,7 +973,7 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio } ret = TRUE; - out: +out: if (repo) ostree_repo_abort_transaction (repo, cancellable, NULL); return ret; diff --git a/src/ostree/ot-builtin-config.c b/src/ostree/ot-builtin-config.c index 5c1334a5..ad90b4b2 100644 --- a/src/ostree/ot-builtin-config.c +++ b/src/ostree/ot-builtin-config.c @@ -21,35 +21,29 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" #include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" #include "otutil.h" -static char* opt_group; +static char *opt_group; /* ATTENTION: * Please remember to update the bash-completion script (bash/ostree) and * man page (man/ostree-config.xml) when changing the option list. */ -static GOptionEntry options[] = { - { "group", 0, 0, G_OPTION_ARG_STRING, &opt_group , "Group name", NULL }, - { NULL } -}; +static GOptionEntry options[] + = { { "group", 0, 0, G_OPTION_ARG_STRING, &opt_group, "Group name", NULL }, { NULL } }; static gboolean -split_key_string (const char *k, - char **out_section, - char **out_value, - GError **error) +split_key_string (const char *k, char **out_section, char **out_value, GError **error) { const char *dot = strchr (k, '.'); if (!dot) { - return glnx_throw (error, - "Key must be of the form \"sectionname.keyname\""); + return glnx_throw (error, "Key must be of the form \"sectionname.keyname\""); } *out_section = g_strndup (k, dot - k); @@ -59,13 +53,15 @@ split_key_string (const char *k, } gboolean -ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("(get KEY|set KEY VALUE|unset KEY)"); + g_autoptr (GOptionContext) context = g_option_context_new ("(get KEY|set KEY VALUE|unset KEY)"); - g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + g_autoptr (OstreeRepo) repo = NULL; + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) return FALSE; if (argc < 2) @@ -88,7 +84,7 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio g_autofree char *section = NULL; g_autofree char *key = NULL; - g_autoptr(GKeyFile) config = NULL; + g_autoptr (GKeyFile) config = NULL; const char *section_key; const char *value; if (!strcmp (op, "set")) @@ -97,25 +93,24 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio { if (argc < 4) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "GROUP name, KEY and VALUE must be specified"); - return FALSE; + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, + "GROUP name, KEY and VALUE must be specified"); + return FALSE; } - section = g_strdup(opt_group); - key = g_strdup(argv[2]); + section = g_strdup (opt_group); + key = g_strdup (argv[2]); value = argv[3]; } else { if (argc < 4) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "KEY and VALUE must be specified"); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "KEY and VALUE must be specified"); return FALSE; } section_key = argv[2]; value = argv[3]; - if(!split_key_string (section_key, §ion, &key, error)) + if (!split_key_string (section_key, §ion, &key, error)) return FALSE; } @@ -137,15 +132,14 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio "Group name and key must be specified"); return FALSE; } - section = g_strdup(opt_group); - key = g_strdup(argv[2]); + section = g_strdup (opt_group); + key = g_strdup (argv[2]); } else { - if(argc < 3) + if (argc < 3) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "KEY must be specified"); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "KEY must be specified"); return FALSE; } section_key = argv[2]; @@ -162,7 +156,7 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio } else if (!strcmp (op, "unset")) { - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; if (opt_group) { if (argc < 3) @@ -171,15 +165,14 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio "Group name and key must be specified"); return FALSE; } - section = g_strdup(opt_group); - key = g_strdup(argv[2]); + section = g_strdup (opt_group); + key = g_strdup (argv[2]); } else { if (argc < 3) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "KEY must be specified"); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "KEY must be specified"); return FALSE; } section_key = argv[2]; @@ -190,8 +183,8 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio config = ostree_repo_copy_config (repo); if (!g_key_file_remove_key (config, section, key, &local_error)) { - if (!g_error_matches (local_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND) && - !g_error_matches (local_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) + if (!g_error_matches (local_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND) + && !g_error_matches (local_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) { g_propagate_error (error, g_steal_pointer (&local_error)); return FALSE; @@ -203,8 +196,7 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio } else { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Unknown operation %s", op); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unknown operation %s", op); return FALSE; } diff --git a/src/ostree/ot-builtin-create-usb.c b/src/ostree/ot-builtin-create-usb.c index 6bd5f2ad..0c48295c 100644 --- a/src/ostree/ot-builtin-create-usb.c +++ b/src/ostree/ot-builtin-create-usb.c @@ -22,9 +22,9 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" #include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" #include "otutil.h" #include "ostree-remote-private.h" @@ -33,31 +33,32 @@ static gboolean opt_disable_fsync = FALSE; static char *opt_destination_repo = NULL; static char *opt_commit = NULL; -static GOptionEntry options[] = - { - { "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", NULL }, - { "destination-repo", 0, 0, G_OPTION_ARG_FILENAME, &opt_destination_repo, "Use custom repository directory within the mount", "DEST" }, - { "commit", 0, 0, G_OPTION_ARG_STRING, &opt_commit, "Pull a specific commit (only works when a single ref is specified)", "COMMIT" }, - { NULL } - }; +static GOptionEntry options[] + = { { "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", + NULL }, + { "destination-repo", 0, 0, G_OPTION_ARG_FILENAME, &opt_destination_repo, + "Use custom repository directory within the mount", "DEST" }, + { "commit", 0, 0, G_OPTION_ARG_STRING, &opt_commit, + "Pull a specific commit (only works when a single ref is specified)", "COMMIT" }, + { NULL } }; gboolean -ostree_builtin_create_usb (int argc, - char **argv, - OstreeCommandInvocation *invocation, - GCancellable *cancellable, - GError **error) +ostree_builtin_create_usb (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeAsyncProgress) progress = NULL; - g_auto(GLnxConsoleRef) console = { 0, }; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeAsyncProgress) progress = NULL; + g_auto (GLnxConsoleRef) console = { + 0, + }; context = g_option_context_new ("MOUNT-PATH COLLECTION-ID REF [COLLECTION-ID REF...]"); /* Parse options. */ - g_autoptr(OstreeRepo) src_repo = NULL; + g_autoptr (OstreeRepo) src_repo = NULL; - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &src_repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &src_repo, + cancellable, error)) return FALSE; if (argc < 2) @@ -74,13 +75,17 @@ ostree_builtin_create_usb (int argc, if (argc % 2 == 1) { - ot_util_usage_error (context, "Only complete COLLECTION-ID REF pairs may be specified", error); + ot_util_usage_error (context, "Only complete COLLECTION-ID REF pairs may be specified", + error); return FALSE; } if (opt_commit && argc > 4) { - ot_util_usage_error (context, "The --commit option can only be used when a single COLLECTION-ID REF pair is specified", error); + ot_util_usage_error ( + context, + "The --commit option can only be used when a single COLLECTION-ID REF pair is specified", + error); return FALSE; } @@ -95,12 +100,13 @@ ostree_builtin_create_usb (int argc, return FALSE; /* Read in the refs to add to the USB stick. */ - g_autoptr(GPtrArray) refs = g_ptr_array_new_full (argc, (GDestroyNotify) ostree_collection_ref_free); + g_autoptr (GPtrArray) refs + = g_ptr_array_new_full (argc, (GDestroyNotify)ostree_collection_ref_free); for (gsize i = 2; i < argc; i += 2) { - if (!ostree_validate_collection_id (argv[i], error) || - !ostree_validate_rev (argv[i + 1], error)) + if (!ostree_validate_collection_id (argv[i], error) + || !ostree_validate_rev (argv[i + 1], error)) return FALSE; g_ptr_array_add (refs, ostree_collection_ref_new (argv[i], argv[i + 1])); @@ -109,7 +115,8 @@ ostree_builtin_create_usb (int argc, /* Open the destination repository on the USB stick or create it if it doesn’t exist. * Check it’s below @mount_root_path, and that it’s not the same as the source * repository. */ - const char *dest_repo_path = (opt_destination_repo != NULL) ? opt_destination_repo : ".ostree/repo"; + const char *dest_repo_path + = (opt_destination_repo != NULL) ? opt_destination_repo : ".ostree/repo"; if (!glnx_shutil_mkdir_p_at (mount_root_dfd, dest_repo_path, 0755, cancellable, error)) return FALSE; @@ -122,8 +129,8 @@ ostree_builtin_create_usb (int argc, g_debug ("%s: Creating repository in mode %u", G_STRFUNC, mode); - g_autoptr(OstreeRepo) dest_repo = ostree_repo_create_at (mount_root_dfd, dest_repo_path, - mode, NULL, cancellable, error); + g_autoptr (OstreeRepo) dest_repo + = ostree_repo_create_at (mount_root_dfd, dest_repo_path, mode, NULL, cancellable, error); if (dest_repo == NULL) return FALSE; @@ -159,19 +166,20 @@ ostree_builtin_create_usb (int argc, { const OstreeCollectionRef *ref = g_ptr_array_index (refs, i); - g_variant_builder_add (&refs_builder, "(sss)", - ref->collection_id, ref->ref_name, opt_commit ?: ""); + g_variant_builder_add (&refs_builder, "(sss)", ref->collection_id, ref->ref_name, + opt_commit ?: ""); } { GVariantBuilder builder; - g_autoptr(GVariant) opts = NULL; + g_autoptr (GVariant) opts = NULL; OstreeRepoPullFlags flags = OSTREE_REPO_PULL_FLAGS_MIRROR; glnx_console_lock (&console); if (console.is_tty) - progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console); + progress = ostree_async_progress_new_and_connect ( + ostree_repo_pull_default_console_progress_changed, &console); g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); @@ -185,10 +193,8 @@ ostree_builtin_create_usb (int argc, g_autofree char *src_repo_uri = g_file_get_uri (ostree_repo_get_path (src_repo)); - if (!ostree_repo_pull_with_options (dest_repo, src_repo_uri, - opts, - progress, - cancellable, error)) + if (!ostree_repo_pull_with_options (dest_repo, src_repo_uri, opts, progress, cancellable, + error)) { ostree_repo_abort_transaction (dest_repo, cancellable, NULL); return FALSE; @@ -208,8 +214,7 @@ ostree_builtin_create_usb (int argc, /* Add the symlinks .ostree/repos.d/@symlink_name → @dest_repo_path, unless * the @dest_repo_path is a well-known one like ostree/repo, in which case no * symlink is necessary; #OstreeRepoFinderMount always looks there. */ - if (!g_str_equal (dest_repo_path, "ostree/repo") && - !g_str_equal (dest_repo_path, ".ostree/repo")) + if (!g_str_equal (dest_repo_path, "ostree/repo") && !g_str_equal (dest_repo_path, ".ostree/repo")) { if (!glnx_shutil_mkdir_p_at (mount_root_dfd, ".ostree/repos.d", 0755, cancellable, error)) return FALSE; @@ -219,7 +224,8 @@ ostree_builtin_create_usb (int argc, GLnxDirFdIterator repos_iter; gboolean need_symlink = TRUE; - if (!glnx_dirfd_iterator_init_at (mount_root_dfd, ".ostree/repos.d", TRUE, &repos_iter, error)) + if (!glnx_dirfd_iterator_init_at (mount_root_dfd, ".ostree/repos.d", TRUE, &repos_iter, + error)) return FALSE; while (TRUE) @@ -246,7 +252,8 @@ ostree_builtin_create_usb (int argc, if (need_symlink) { /* Relative to .ostree/repos.d. */ - g_autofree char *relative_dest_repo_path = g_build_filename ("..", "..", dest_repo_path, NULL); + g_autofree char *relative_dest_repo_path + = g_build_filename ("..", "..", dest_repo_path, NULL); guint i; const guint max_attempts = 100; @@ -254,9 +261,11 @@ ostree_builtin_create_usb (int argc, { g_autofree char *symlink_path = g_strdup_printf (".ostree/repos.d/%02u-generated", i); - int ret = TEMP_FAILURE_RETRY (symlinkat (relative_dest_repo_path, mount_root_dfd, symlink_path)); + int ret = TEMP_FAILURE_RETRY ( + symlinkat (relative_dest_repo_path, mount_root_dfd, symlink_path)); if (ret < 0 && errno != EEXIST) - return glnx_throw_errno_prefix (error, "symlinkat(%s → %s)", symlink_path, relative_dest_repo_path); + return glnx_throw_errno_prefix (error, "symlinkat(%s → %s)", symlink_path, + relative_dest_repo_path); else if (ret >= 0) break; } @@ -269,8 +278,8 @@ ostree_builtin_create_usb (int argc, /* Report success to the user. */ g_autofree char *src_repo_path = g_file_get_path (ostree_repo_get_path (src_repo)); - g_print ("Copied %u/%u refs successfully from ‘%s’ to ‘%s’ repository in ‘%s’.\n", refs->len, refs->len, - src_repo_path, dest_repo_path, mount_root_path); + g_print ("Copied %u/%u refs successfully from ‘%s’ to ‘%s’ repository in ‘%s’.\n", refs->len, + refs->len, src_repo_path, dest_repo_path, mount_root_path); return TRUE; } diff --git a/src/ostree/ot-builtin-diff.c b/src/ostree/ot-builtin-diff.c index 9c918348..2060dc74 100644 --- a/src/ostree/ot-builtin-diff.c +++ b/src/ostree/ot-builtin-diff.c @@ -21,9 +21,9 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" #include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" #include "otutil.h" static gboolean opt_stats; @@ -37,27 +37,24 @@ static gint opt_owner_gid = -1; * man page (man/ostree-diff.xml) when changing the option list. */ -static GOptionEntry options[] = { - { "stats", 0, 0, G_OPTION_ARG_NONE, &opt_stats, "Print various statistics", NULL }, - { "fs-diff", 0, 0, G_OPTION_ARG_NONE, &opt_fs_diff, "Print filesystem diff", NULL }, - { "no-xattrs", 0, 0, G_OPTION_ARG_NONE, &opt_no_xattrs, "Skip output of extended attributes", NULL }, - { "owner-uid", 0, 0, G_OPTION_ARG_INT, &opt_owner_uid, "Use file ownership user id for local files", "UID" }, - { "owner-gid", 0, 0, G_OPTION_ARG_INT, &opt_owner_gid, "Use file ownership group id for local files", "GID" }, - { NULL } -}; +static GOptionEntry options[] + = { { "stats", 0, 0, G_OPTION_ARG_NONE, &opt_stats, "Print various statistics", NULL }, + { "fs-diff", 0, 0, G_OPTION_ARG_NONE, &opt_fs_diff, "Print filesystem diff", NULL }, + { "no-xattrs", 0, 0, G_OPTION_ARG_NONE, &opt_no_xattrs, + "Skip output of extended attributes", NULL }, + { "owner-uid", 0, 0, G_OPTION_ARG_INT, &opt_owner_uid, + "Use file ownership user id for local files", "UID" }, + { "owner-gid", 0, 0, G_OPTION_ARG_INT, &opt_owner_gid, + "Use file ownership group id for local files", "GID" }, + { NULL } }; static gboolean -parse_file_or_commit (OstreeRepo *repo, - const char *arg, - GFile **out_file, - GCancellable *cancellable, - GError **error) +parse_file_or_commit (OstreeRepo *repo, const char *arg, GFile **out_file, + GCancellable *cancellable, GError **error) { - g_autoptr(GFile) ret_file = NULL; + g_autoptr (GFile) ret_file = NULL; - if (g_str_has_prefix (arg, "/") - || g_str_has_prefix (arg, "./") - ) + if (g_str_has_prefix (arg, "/") || g_str_has_prefix (arg, "./")) { ret_file = g_file_new_for_path (arg); } @@ -90,11 +87,8 @@ reachable_set_intersect (GHashTable *a, GHashTable *b) } static gboolean -object_set_total_size (OstreeRepo *repo, - GHashTable *reachable, - guint64 *out_total, - GCancellable *cancellable, - GError **error) +object_set_total_size (OstreeRepo *repo, GHashTable *reachable, guint64 *out_total, + GCancellable *cancellable, GError **error) { GHashTableIter hashiter; gpointer key, value; @@ -110,8 +104,7 @@ object_set_total_size (OstreeRepo *repo, guint64 size; ostree_object_name_deserialize (v, &csum, &objtype); - if (!ostree_repo_query_object_storage_size (repo, objtype, csum, &size, - cancellable, error)) + if (!ostree_repo_query_object_storage_size (repo, objtype, csum, &size, cancellable, error)) return FALSE; *out_total += size; } @@ -120,12 +113,14 @@ object_set_total_size (OstreeRepo *repo, } gboolean -ostree_builtin_diff (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_diff (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("REV_OR_DIR REV_OR_DIR"); + g_autoptr (GOptionContext) context = g_option_context_new ("REV_OR_DIR REV_OR_DIR"); - g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + g_autoptr (OstreeRepo) repo = NULL; + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) return FALSE; if (argc < 2) @@ -133,8 +128,7 @@ ostree_builtin_diff (int argc, char **argv, OstreeCommandInvocation *invocation, gchar *help = g_option_context_get_help (context, TRUE, NULL); g_printerr ("%s\n", help); g_free (help); - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "REV must be specified"); + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "REV must be specified"); return FALSE; } @@ -156,11 +150,11 @@ ostree_builtin_diff (int argc, char **argv, OstreeCommandInvocation *invocation, if (!opt_stats && !opt_fs_diff) opt_fs_diff = TRUE; - g_autoptr(GFile) srcf = NULL; - g_autoptr(GFile) targetf = NULL; - g_autoptr(GPtrArray) modified = NULL; - g_autoptr(GPtrArray) removed = NULL; - g_autoptr(GPtrArray) added = NULL; + g_autoptr (GFile) srcf = NULL; + g_autoptr (GFile) targetf = NULL; + g_autoptr (GPtrArray) modified = NULL; + g_autoptr (GPtrArray) removed = NULL; + g_autoptr (GPtrArray) added = NULL; if (opt_fs_diff) { @@ -179,8 +173,8 @@ ostree_builtin_diff (int argc, char **argv, OstreeCommandInvocation *invocation, added = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref); OstreeDiffDirsOptions diff_opts = { opt_owner_uid, opt_owner_gid }; - if (!ostree_diff_dirs_with_options (diff_flags, srcf, targetf, modified, removed, - added, &diff_opts, cancellable, error)) + if (!ostree_diff_dirs_with_options (diff_flags, srcf, targetf, modified, removed, added, + &diff_opts, cancellable, error)) return FALSE; ostree_diff_print (srcf, targetf, modified, removed, added); @@ -188,9 +182,9 @@ ostree_builtin_diff (int argc, char **argv, OstreeCommandInvocation *invocation, if (opt_stats) { - g_autoptr(GHashTable) reachable_a = NULL; - g_autoptr(GHashTable) reachable_b = NULL; - g_autoptr(GHashTable) reachable_intersection = NULL; + g_autoptr (GHashTable) reachable_a = NULL; + g_autoptr (GHashTable) reachable_b = NULL; + g_autoptr (GHashTable) reachable_intersection = NULL; g_autofree char *rev_a = NULL; g_autofree char *rev_b = NULL; g_autofree char *size = NULL; @@ -217,8 +211,7 @@ ostree_builtin_diff (int argc, char **argv, OstreeCommandInvocation *invocation, g_print ("Common Object Count: %u\n", g_hash_table_size (reachable_intersection)); - if (!object_set_total_size (repo, reachable_intersection, &total_common, - cancellable, error)) + if (!object_set_total_size (repo, reachable_intersection, &total_common, cancellable, error)) return FALSE; size = g_format_size_full (total_common, 0); g_print ("Common Object Size: %s\n", size); diff --git a/src/ostree/ot-builtin-export.c b/src/ostree/ot-builtin-export.c index a8929ec1..00d77cc3 100644 --- a/src/ostree/ot-builtin-export.c +++ b/src/ostree/ot-builtin-export.c @@ -19,12 +19,12 @@ #include "config.h" -#include "otutil.h" -#include "ot-main.h" -#include "ot-builtins.h" #include "ostree-libarchive-private.h" -#include "ostree.h" #include "ostree-repo-file.h" +#include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" +#include "otutil.h" #ifdef HAVE_LIBARCHIVE #include @@ -41,45 +41,49 @@ static gboolean opt_no_xattrs; * man page (man/ostree-export.xml) when changing the option list. */ -static GOptionEntry options[] = { - { "no-xattrs", 0, 0, G_OPTION_ARG_NONE, &opt_no_xattrs, "Skip output of extended attributes", NULL }, - { "subpath", 0, 0, G_OPTION_ARG_FILENAME, &opt_subpath, "Checkout sub-directory PATH", "PATH" }, - { "prefix", 0, 0, G_OPTION_ARG_FILENAME, &opt_prefix, "Add PATH as prefix to archive pathnames", "PATH" }, - { "output", 'o', 0, G_OPTION_ARG_FILENAME, &opt_output_path, "Output to PATH ", "PATH" }, - { NULL } -}; +static GOptionEntry options[] + = { { "no-xattrs", 0, 0, G_OPTION_ARG_NONE, &opt_no_xattrs, + "Skip output of extended attributes", NULL }, + { "subpath", 0, 0, G_OPTION_ARG_FILENAME, &opt_subpath, "Checkout sub-directory PATH", + "PATH" }, + { "prefix", 0, 0, G_OPTION_ARG_FILENAME, &opt_prefix, + "Add PATH as prefix to archive pathnames", "PATH" }, + { "output", 'o', 0, G_OPTION_ARG_FILENAME, &opt_output_path, "Output to PATH ", "PATH" }, + { NULL } }; #ifdef HAVE_LIBARCHIVE static void -propagate_libarchive_error (GError **error, - struct archive *a) +propagate_libarchive_error (GError **error, struct archive *a) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "%s", archive_error_string (a)); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s", archive_error_string (a)); } #endif gboolean -ostree_builtin_export (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_export (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeRepo) repo = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeRepo) repo = NULL; gboolean ret = FALSE; - g_autoptr(GFile) root = NULL; - g_autoptr(GFile) subtree = NULL; + g_autoptr (GFile) root = NULL; + g_autoptr (GFile) subtree = NULL; g_autofree char *commit = NULL; - g_autoptr(GVariant) commit_data = NULL; + g_autoptr (GVariant) commit_data = NULL; #ifdef HAVE_LIBARCHIVE const char *rev; - g_autoptr(OtAutoArchiveWrite) a = NULL; - OstreeRepoExportArchiveOptions opts = { 0, }; + g_autoptr (OtAutoArchiveWrite) a = NULL; + OstreeRepoExportArchiveOptions opts = { + 0, + }; #endif context = g_option_context_new ("COMMIT"); - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) goto out; #ifdef HAVE_LIBARCHIVE @@ -143,8 +147,8 @@ ostree_builtin_export (int argc, char **argv, OstreeCommandInvocation *invocatio opts.path_prefix = opt_prefix; - if (!ostree_repo_export_tree_to_archive (repo, &opts, (OstreeRepoFile*)subtree, a, - cancellable, error)) + if (!ostree_repo_export_tree_to_archive (repo, &opts, (OstreeRepoFile *)subtree, a, cancellable, + error)) goto out; if (archive_write_close (a) != ARCHIVE_OK) @@ -160,6 +164,6 @@ ostree_builtin_export (int argc, char **argv, OstreeCommandInvocation *invocatio #endif ret = TRUE; - out: +out: return ret; } diff --git a/src/ostree/ot-builtin-find-remotes.c b/src/ostree/ot-builtin-find-remotes.c index 03ab1bef..b13ab4e4 100644 --- a/src/ostree/ot-builtin-find-remotes.c +++ b/src/ostree/ot-builtin-find-remotes.c @@ -22,9 +22,9 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" #include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" #include "otutil.h" #include "ostree-remote-private.h" @@ -35,20 +35,21 @@ static gboolean opt_disable_fsync = FALSE; static gboolean opt_pull = FALSE; static gboolean opt_mirror = FALSE; -static GOptionEntry options[] = - { - { "cache-dir", 0, 0, G_OPTION_ARG_FILENAME, &opt_cache_dir, "Use custom cache dir", NULL }, - { "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", NULL }, - { "finders", 0, 0, G_OPTION_ARG_STRING, &opt_finders, "Use the specified comma separated list of finders (e.g. config,lan,mount)", "FINDERS" }, - { "pull", 0, 0, G_OPTION_ARG_NONE, &opt_pull, "Pull the updates after finding them", NULL }, - { "mirror", 0, 0, G_OPTION_ARG_NONE, &opt_mirror, "Do a mirror pull (see ostree pull --mirror)", NULL}, - { NULL } - }; +static GOptionEntry options[] + = { { "cache-dir", 0, 0, G_OPTION_ARG_FILENAME, &opt_cache_dir, "Use custom cache dir", NULL }, + { "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", + NULL }, + { "finders", 0, 0, G_OPTION_ARG_STRING, &opt_finders, + "Use the specified comma separated list of finders (e.g. config,lan,mount)", "FINDERS" }, + { "pull", 0, 0, G_OPTION_ARG_NONE, &opt_pull, "Pull the updates after finding them", NULL }, + { "mirror", 0, 0, G_OPTION_ARG_NONE, &opt_mirror, + "Do a mirror pull (see ostree pull --mirror)", NULL }, + { NULL } }; static gchar * uint64_secs_to_iso8601 (guint64 secs) { - g_autoptr(GDateTime) dt = g_date_time_new_from_unix_utc (secs); + g_autoptr (GDateTime) dt = g_date_time_new_from_unix_utc (secs); if (dt != NULL) return g_date_time_format (dt, "%FT%TZ"); @@ -57,21 +58,20 @@ uint64_secs_to_iso8601 (guint64 secs) } static gchar * -format_ref_to_checksum (GHashTable *ref_to_checksum /* (element-type OstreeCollectionRef utf8) */, +format_ref_to_checksum (GHashTable *ref_to_checksum /* (element-type OstreeCollectionRef utf8) */, const gchar *line_prefix) { GHashTableIter iter; const OstreeCollectionRef *ref; const gchar *checksum; - g_autoptr(GString) out = NULL; + g_autoptr (GString) out = NULL; g_hash_table_iter_init (&iter, ref_to_checksum); out = g_string_new (""); - while (g_hash_table_iter_next (&iter, (gpointer *) &ref, (gpointer *) &checksum)) - g_string_append_printf (out, "%s - (%s, %s) = %s\n", - line_prefix, ref->collection_id, ref->ref_name, - (checksum != NULL) ? checksum : "(not found)"); + while (g_hash_table_iter_next (&iter, (gpointer *)&ref, (gpointer *)&checksum)) + g_string_append_printf (out, "%s - (%s, %s) = %s\n", line_prefix, ref->collection_id, + ref->ref_name, (checksum != NULL) ? checksum : "(not found)"); return g_string_free (g_steal_pointer (&out), FALSE); } @@ -79,7 +79,7 @@ format_ref_to_checksum (GHashTable *ref_to_checksum /* (element-type OstreeCol static gchar * remote_get_uri (OstreeRemote *remote) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; g_autofree gchar *uri = NULL; uri = g_key_file_get_string (remote->options, remote->group, "url", &error); @@ -90,8 +90,7 @@ remote_get_uri (OstreeRemote *remote) /* Add each key from @keys_input to @set iff its value is non-%NULL. */ static void -add_keys_to_set_if_non_null (GHashTable *set, - GHashTable *keys_input) +add_keys_to_set_if_non_null (GHashTable *set, GHashTable *keys_input) { GHashTableIter iter; gpointer key, value; @@ -104,9 +103,7 @@ add_keys_to_set_if_non_null (GHashTable *set, } static void -get_result_cb (GObject *obj, - GAsyncResult *result, - gpointer user_data) +get_result_cb (GObject *obj, GAsyncResult *result, gpointer user_data) { GAsyncResult **result_out = user_data; *result_out = g_object_ref (result); @@ -121,19 +118,16 @@ collection_ref_free0 (OstreeCollectionRef *ref) } static gboolean -validate_finders_list (const char **finders, - GOptionContext *context, - GError **error) +validate_finders_list (const char **finders, GOptionContext *context, GError **error) { - typedef struct { + typedef struct + { gchar *finder_name; gboolean already_used; } Finder; - Finder valid_finders[] = { - {.finder_name = "config", .already_used = FALSE}, - {.finder_name = "lan", .already_used = FALSE}, - {.finder_name = "mount", .already_used = FALSE} - }; + Finder valid_finders[] = { { .finder_name = "config", .already_used = FALSE }, + { .finder_name = "lan", .already_used = FALSE }, + { .finder_name = "mount", .already_used = FALSE } }; if (finders == NULL || *finders == NULL) { @@ -157,7 +151,8 @@ validate_finders_list (const char **finders, if (!is_valid_finder) { g_autofree gchar *error_msg = NULL; - error_msg = g_strdup_printf ("Unknown or duplicate finder type given in --finders option: ‘%s’", *iter); + error_msg = g_strdup_printf ( + "Unknown or duplicate finder type given in --finders option: ‘%s’", *iter); ot_util_usage_error (context, error_msg, error); return FALSE; } @@ -167,33 +162,33 @@ validate_finders_list (const char **finders, } gboolean -ostree_builtin_find_remotes (int argc, - char **argv, - OstreeCommandInvocation *invocation, - GCancellable *cancellable, - GError **error) +ostree_builtin_find_remotes (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeRepo) repo = NULL; - g_autoptr(GPtrArray) refs = NULL; /* (element-type OstreeCollectionRef) */ - g_autoptr(GPtrArray) finders = NULL; /* (element-type OstreeRepoFinder) */ - g_autoptr(OstreeRepoFinder) finder_config = NULL; - g_autoptr(OstreeRepoFinder) finder_mount = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeRepo) repo = NULL; + g_autoptr (GPtrArray) refs = NULL; /* (element-type OstreeCollectionRef) */ + g_autoptr (GPtrArray) finders = NULL; /* (element-type OstreeRepoFinder) */ + g_autoptr (OstreeRepoFinder) finder_config = NULL; + g_autoptr (OstreeRepoFinder) finder_mount = NULL; #ifdef HAVE_AVAHI - g_autoptr(OstreeRepoFinder) finder_avahi = NULL; -#endif /* HAVE_AVAHI */ - g_autoptr(OstreeAsyncProgress) progress = NULL; + g_autoptr (OstreeRepoFinder) finder_avahi = NULL; +#endif /* HAVE_AVAHI */ + g_autoptr (OstreeAsyncProgress) progress = NULL; gsize i; - g_autoptr(GAsyncResult) find_result = NULL, pull_result = NULL; - g_auto(OstreeRepoFinderResultv) results = NULL; - g_auto(GLnxConsoleRef) console = { 0, }; - g_autoptr(GHashTable) refs_found = NULL; /* set (element-type OstreeCollectionRef) */ - g_autoptr(GVariant) pull_options = NULL; + g_autoptr (GAsyncResult) find_result = NULL, pull_result = NULL; + g_auto (OstreeRepoFinderResultv) results = NULL; + g_auto (GLnxConsoleRef) console = { + 0, + }; + g_autoptr (GHashTable) refs_found = NULL; /* set (element-type OstreeCollectionRef) */ + g_autoptr (GVariant) pull_options = NULL; context = g_option_context_new ("COLLECTION-ID REF [COLLECTION-ID REF...]"); /* Parse options. */ - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) return FALSE; if (!ostree_ensure_repo_writable (repo, error)) @@ -207,7 +202,8 @@ ostree_builtin_find_remotes (int argc, if (argc % 2 == 0) { - ot_util_usage_error (context, "Only complete COLLECTION-ID REF pairs may be specified", error); + ot_util_usage_error (context, "Only complete COLLECTION-ID REF pairs may be specified", + error); return FALSE; } @@ -220,17 +216,17 @@ ostree_builtin_find_remotes (int argc, if (opt_disable_fsync) ostree_repo_set_disable_fsync (repo, TRUE); - if (opt_cache_dir && - !ostree_repo_set_cache_dir (repo, AT_FDCWD, opt_cache_dir, cancellable, error)) + if (opt_cache_dir + && !ostree_repo_set_cache_dir (repo, AT_FDCWD, opt_cache_dir, cancellable, error)) return FALSE; /* Read in the refs to search for remotes for. */ - refs = g_ptr_array_new_full (argc, (GDestroyNotify) collection_ref_free0); + refs = g_ptr_array_new_full (argc, (GDestroyNotify)collection_ref_free0); for (i = 1; i < argc; i += 2) { - if (!ostree_validate_collection_id (argv[i], error) || - !ostree_validate_rev (argv[i + 1], error)) + if (!ostree_validate_collection_id (argv[i], error) + || !ostree_validate_rev (argv[i + 1], error)) return FALSE; g_ptr_array_add (refs, ostree_collection_ref_new (argv[i], argv[i + 1])); @@ -241,7 +237,7 @@ ostree_builtin_find_remotes (int argc, /* Build the array of OstreeRepoFinder instances */ if (opt_finders != NULL) { - g_auto(GStrv) finders_strings = NULL; + g_auto (GStrv) finders_strings = NULL; finders_strings = g_strsplit (opt_finders, ",", 0); if (!validate_finders_list ((const char **)finders_strings, context, error)) @@ -264,10 +260,11 @@ ostree_builtin_find_remotes (int argc, { #ifdef HAVE_AVAHI GMainContext *main_context = g_main_context_get_thread_default (); - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; finder_avahi = OSTREE_REPO_FINDER (ostree_repo_finder_avahi_new (main_context)); - ostree_repo_finder_avahi_start (OSTREE_REPO_FINDER_AVAHI (finder_avahi), &local_error); + ostree_repo_finder_avahi_start (OSTREE_REPO_FINDER_AVAHI (finder_avahi), + &local_error); if (local_error != NULL) { @@ -277,9 +274,11 @@ ostree_builtin_find_remotes (int argc, else g_ptr_array_add (finders, finder_avahi); #else - ot_util_usage_error (context, "LAN repo finder requested but ostree was compiled without Avahi support", error); + ot_util_usage_error ( + context, + "LAN repo finder requested but ostree was compiled without Avahi support", error); return FALSE; -#endif /* HAVE_AVAHI */ +#endif /* HAVE_AVAHI */ } else g_assert_not_reached (); @@ -291,14 +290,13 @@ ostree_builtin_find_remotes (int argc, glnx_console_lock (&console); if (console.is_tty) - progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console); + progress = ostree_async_progress_new_and_connect ( + ostree_repo_pull_default_console_progress_changed, &console); - ostree_repo_find_remotes_async (repo, - (const OstreeCollectionRef * const *) refs->pdata, - NULL /* no options */, - finders != NULL ? (OstreeRepoFinder **) finders->pdata : NULL, - progress, cancellable, - get_result_cb, &find_result); + ostree_repo_find_remotes_async (repo, (const OstreeCollectionRef *const *)refs->pdata, + NULL /* no options */, + finders != NULL ? (OstreeRepoFinder **)finders->pdata : NULL, + progress, cancellable, get_result_cb, &find_result); while (find_result == NULL) g_main_context_iteration (NULL, TRUE); @@ -312,8 +310,8 @@ ostree_builtin_find_remotes (int argc, ostree_async_progress_finish (progress); /* Print results and work out which refs were not found. */ - refs_found = g_hash_table_new_full (ostree_collection_ref_hash, - ostree_collection_ref_equal, NULL, NULL); + refs_found + = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, NULL, NULL); for (i = 0; results[i] != NULL; i++) { @@ -350,7 +348,7 @@ ostree_builtin_find_remotes (int argc, g_print ("%u/%u refs were found.\n", g_hash_table_size (refs_found), refs->len - 1); /* Print out the refs which weren’t found. */ - if (g_hash_table_size (refs_found) != refs->len - 1 /* NULL terminator */) + if (g_hash_table_size (refs_found) != refs->len - 1 /* NULL terminator */) { g_print ("Refs not found in any remote:\n"); @@ -371,21 +369,21 @@ ostree_builtin_find_remotes (int argc, g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); if (opt_mirror) - g_variant_builder_add (&builder, "{s@v}", "flags", - g_variant_new_variant (g_variant_new_int32 (OSTREE_REPO_PULL_FLAGS_MIRROR))); + g_variant_builder_add ( + &builder, "{s@v}", "flags", + g_variant_new_variant (g_variant_new_int32 (OSTREE_REPO_PULL_FLAGS_MIRROR))); pull_options = g_variant_ref_sink (g_variant_builder_end (&builder)); } /* Run the pull operation. */ if (console.is_tty) - progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console); + progress = ostree_async_progress_new_and_connect ( + ostree_repo_pull_default_console_progress_changed, &console); - ostree_repo_pull_from_remotes_async (repo, - (const OstreeRepoFinderResult * const *) results, - pull_options, - progress, cancellable, - get_result_cb, &pull_result); + ostree_repo_pull_from_remotes_async (repo, (const OstreeRepoFinderResult *const *)results, + pull_options, progress, cancellable, get_result_cb, + &pull_result); while (pull_result == NULL) g_main_context_iteration (NULL, TRUE); diff --git a/src/ostree/ot-builtin-fsck.c b/src/ostree/ot-builtin-fsck.c index bb9e8563..cd3c7768 100644 --- a/src/ostree/ot-builtin-fsck.c +++ b/src/ostree/ot-builtin-fsck.c @@ -22,10 +22,10 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" -#include "ostree.h" #include "ostree-cmd-private.h" +#include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" #include "otutil.h" static gboolean opt_quiet; @@ -40,31 +40,28 @@ static gboolean opt_verify_back_refs; * man page (man/ostree-fsck.xml) when changing the option list. */ -static GOptionEntry options[] = { - { "add-tombstones", 0, 0, G_OPTION_ARG_NONE, &opt_add_tombstones, "Add tombstones for missing commits", NULL }, - { "quiet", 'q', 0, G_OPTION_ARG_NONE, &opt_quiet, "Only print error messages", NULL }, - { "all", 'a', 0, G_OPTION_ARG_NONE, &opt_all, "Don't stop on first error", NULL }, - { "delete", 0, 0, G_OPTION_ARG_NONE, &opt_delete, "Remove corrupted objects", NULL }, - { "verify-bindings", 0, 0, G_OPTION_ARG_NONE, &opt_verify_bindings, "Verify ref bindings", NULL }, - { "verify-back-refs", 0, 0, G_OPTION_ARG_NONE, &opt_verify_back_refs, "Verify back-references (implies --verify-bindings)", NULL }, - { NULL } -}; +static GOptionEntry options[] + = { { "add-tombstones", 0, 0, G_OPTION_ARG_NONE, &opt_add_tombstones, + "Add tombstones for missing commits", NULL }, + { "quiet", 'q', 0, G_OPTION_ARG_NONE, &opt_quiet, "Only print error messages", NULL }, + { "all", 'a', 0, G_OPTION_ARG_NONE, &opt_all, "Don't stop on first error", NULL }, + { "delete", 0, 0, G_OPTION_ARG_NONE, &opt_delete, "Remove corrupted objects", NULL }, + { "verify-bindings", 0, 0, G_OPTION_ARG_NONE, &opt_verify_bindings, "Verify ref bindings", + NULL }, + { "verify-back-refs", 0, 0, G_OPTION_ARG_NONE, &opt_verify_back_refs, + "Verify back-references (implies --verify-bindings)", NULL }, + { NULL } }; static gboolean -fsck_one_object (OstreeRepo *repo, - const char *checksum, - OstreeObjectType objtype, - GHashTable *object_parents, - GVariant *key, - gboolean *out_found_corruption, - GCancellable *cancellable, - GError **error) +fsck_one_object (OstreeRepo *repo, const char *checksum, OstreeObjectType objtype, + GHashTable *object_parents, GVariant *key, gboolean *out_found_corruption, + GCancellable *cancellable, GError **error) { - g_autoptr(GError) temp_error = NULL; + g_autoptr (GError) temp_error = NULL; if (!ostree_repo_fsck_object (repo, objtype, checksum, cancellable, &temp_error)) { gboolean object_missing = FALSE; - g_auto(GStrv) parent_commits = NULL; + g_auto (GStrv) parent_commits = NULL; g_autofree char *parent_commits_str = NULL; if (object_parents) @@ -92,7 +89,7 @@ fsck_one_object (OstreeRepo *repo, if (opt_delete) { g_printerr ("%s\n", temp_error->message); - (void) ostree_repo_delete_object (repo, objtype, checksum, cancellable, NULL); + (void)ostree_repo_delete_object (repo, objtype, checksum, cancellable, NULL); object_missing = TRUE; } else if (opt_all) @@ -120,13 +117,14 @@ fsck_one_object (OstreeRepo *repo, { const char *parent_commit = parent_commits[i]; OstreeRepoCommitState state; - if (!ostree_repo_load_commit (repo, parent_commit, NULL, - &state, error)) + if (!ostree_repo_load_commit (repo, parent_commit, NULL, &state, error)) return FALSE; if ((state & OSTREE_REPO_COMMIT_STATE_PARTIAL) == 0) { g_printerr ("Marking commit as partial: %s\n", parent_commit); - if (!ostree_repo_mark_commit_partial_reason (repo, parent_commit, TRUE, OSTREE_REPO_COMMIT_STATE_FSCK_PARTIAL, error)) + if (!ostree_repo_mark_commit_partial_reason ( + repo, parent_commit, TRUE, OSTREE_REPO_COMMIT_STATE_FSCK_PARTIAL, + error)) return FALSE; } } @@ -138,14 +136,12 @@ fsck_one_object (OstreeRepo *repo, } static gboolean -fsck_reachable_objects_from_commits (OstreeRepo *repo, - GHashTable *commits, - gboolean *out_found_corruption, - GCancellable *cancellable, - GError **error) +fsck_reachable_objects_from_commits (OstreeRepo *repo, GHashTable *commits, + gboolean *out_found_corruption, GCancellable *cancellable, + GError **error) { - g_autoptr(GHashTable) reachable_objects = ostree_repo_traverse_new_reachable (); - g_autoptr(GHashTable) object_parents = ostree_repo_traverse_new_parents (); + g_autoptr (GHashTable) reachable_objects = ostree_repo_traverse_new_reachable (); + g_autoptr (GHashTable) object_parents = ostree_repo_traverse_new_parents (); GHashTableIter hash_iter; gpointer key, value; @@ -160,12 +156,14 @@ fsck_reachable_objects_from_commits (OstreeRepo *repo, g_assert (objtype == OSTREE_OBJECT_TYPE_COMMIT); - if (!ostree_repo_traverse_commit_union_with_parents (repo, checksum, 0, reachable_objects, object_parents, - cancellable, error)) + if (!ostree_repo_traverse_commit_union_with_parents (repo, checksum, 0, reachable_objects, + object_parents, cancellable, error)) return FALSE; } - g_auto(GLnxConsoleRef) console = { 0, }; + g_auto (GLnxConsoleRef) console = { + 0, + }; glnx_console_lock (&console); const guint count = g_hash_table_size (reachable_objects); @@ -179,8 +177,7 @@ fsck_reachable_objects_from_commits (OstreeRepo *repo, ostree_object_name_deserialize (serialized_key, &checksum, &objtype); - if (!fsck_one_object (repo, checksum, objtype, - object_parents, serialized_key, + if (!fsck_one_object (repo, checksum, objtype, object_parents, serialized_key, out_found_corruption, cancellable, error)) return FALSE; @@ -194,27 +191,21 @@ fsck_reachable_objects_from_commits (OstreeRepo *repo, /* Check that a given commit object is valid for the ref it was looked up via. * @collection_id will be %NULL for normal refs, and non-%NULL for collection–refs. */ static gboolean -fsck_commit_for_ref (OstreeRepo *repo, - const char *checksum, - const char *collection_id, - const char *ref_name, - gboolean *found_corruption, - GCancellable *cancellable, - GError **error) +fsck_commit_for_ref (OstreeRepo *repo, const char *checksum, const char *collection_id, + const char *ref_name, gboolean *found_corruption, GCancellable *cancellable, + GError **error) { - if (!fsck_one_object (repo, checksum, OSTREE_OBJECT_TYPE_COMMIT, - NULL, NULL, found_corruption, + if (!fsck_one_object (repo, checksum, OSTREE_OBJECT_TYPE_COMMIT, NULL, NULL, found_corruption, cancellable, error)) return FALSE; /* Check the commit exists. */ - g_autoptr(GVariant) commit = NULL; - if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, - checksum, &commit, error)) + g_autoptr (GVariant) commit = NULL; + if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, checksum, &commit, error)) { if (collection_id != NULL) - return glnx_prefix_error (error, "Loading commit for ref (%s, %s)", - collection_id, ref_name); + return glnx_prefix_error (error, "Loading commit for ref (%s, %s)", collection_id, + ref_name); else return glnx_prefix_error (error, "Loading commit for ref %s", ref_name); } @@ -222,7 +213,8 @@ fsck_commit_for_ref (OstreeRepo *repo, /* Check its bindings. */ if (opt_verify_bindings) { - if (!ostree_cmd__private__ ()->ostree_repo_verify_bindings (collection_id, ref_name, commit, error)) + if (!ostree_cmd__private__ ()->ostree_repo_verify_bindings (collection_id, ref_name, commit, + error)) return glnx_prefix_error (error, "Commit %s", checksum); } @@ -237,60 +229,52 @@ fsck_one_commit (OstreeRepo *repo, const char *checksum, GVariant *commit, GPtrA * for this commit resolve back to this commit. */ if (opt_verify_back_refs) { - g_autoptr(GVariant) metadata = g_variant_get_child_value (commit, 0); + g_autoptr (GVariant) metadata = g_variant_get_child_value (commit, 0); const char *collection_id = NULL; - if (!g_variant_lookup (metadata, - OSTREE_COMMIT_META_KEY_COLLECTION_BINDING, - "&s", + if (!g_variant_lookup (metadata, OSTREE_COMMIT_META_KEY_COLLECTION_BINDING, "&s", &collection_id)) collection_id = NULL; g_autofree const char **refs = NULL; - if (g_variant_lookup (metadata, - OSTREE_COMMIT_META_KEY_REF_BINDING, - "^a&s", - &refs)) + if (g_variant_lookup (metadata, OSTREE_COMMIT_META_KEY_REF_BINDING, "^a&s", &refs)) { for (const char **iter = refs; *iter != NULL; ++iter) { g_autofree char *checksum_for_ref = NULL; if (collection_id != NULL) { - const OstreeCollectionRef collection_ref = { (char *) collection_id, (char *) *iter }; - if (!ostree_repo_resolve_collection_ref (repo, &collection_ref, - TRUE, + const OstreeCollectionRef collection_ref + = { (char *)collection_id, (char *)*iter }; + if (!ostree_repo_resolve_collection_ref (repo, &collection_ref, TRUE, OSTREE_REPO_RESOLVE_REV_EXT_NONE, - &checksum_for_ref, - cancellable, - error)) + &checksum_for_ref, cancellable, error)) return FALSE; } else { - if (!ostree_repo_resolve_rev (repo, *iter, TRUE, - &checksum_for_ref, error)) + if (!ostree_repo_resolve_rev (repo, *iter, TRUE, &checksum_for_ref, error)) return FALSE; } if (checksum_for_ref == NULL) { if (collection_id != NULL) - return glnx_throw (error, - "Collection–ref (%s, %s) in bindings for commit %s does not exist", - collection_id, *iter, checksum); + return glnx_throw ( + error, "Collection–ref (%s, %s) in bindings for commit %s does not exist", + collection_id, *iter, checksum); else - return glnx_throw (error, - "Ref ‘%s’ in bindings for commit %s does not exist", + return glnx_throw (error, "Ref ‘%s’ in bindings for commit %s does not exist", *iter, checksum); } else if (g_strcmp0 (checksum_for_ref, checksum) != 0) { if (collection_id != NULL) return glnx_throw (error, - "Collection–ref (%s, %s) in bindings for commit %s does not resolve to that commit", + "Collection–ref (%s, %s) in bindings for commit %s does " + "not resolve to that commit", collection_id, *iter, checksum); else - return glnx_throw (error, - "Ref ‘%s’ in bindings for commit %s does not resolve to that commit", - *iter, checksum); + return glnx_throw ( + error, "Ref ‘%s’ in bindings for commit %s does not resolve to that commit", + *iter, checksum); } } } @@ -301,7 +285,7 @@ fsck_one_commit (OstreeRepo *repo, const char *checksum, GVariant *commit, GPtrA g_autofree char *parent = ostree_commit_get_parent (commit); if (parent) { - g_autoptr(GVariant) parent_commit = NULL; + g_autoptr (GVariant) parent_commit = NULL; if (!ostree_repo_load_variant_if_exists (repo, OSTREE_OBJECT_TYPE_COMMIT, parent, &parent_commit, error)) return FALSE; @@ -314,22 +298,23 @@ fsck_one_commit (OstreeRepo *repo, const char *checksum, GVariant *commit, GPtrA } gboolean -ostree_builtin_fsck (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_fsck (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(OstreeRepo) repo = NULL; + g_autoptr (OstreeRepo) repo = NULL; gboolean found_corruption = FALSE; - g_autoptr(GOptionContext) context = g_option_context_new (""); - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + g_autoptr (GOptionContext) context = g_option_context_new (""); + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) return FALSE; if (!opt_quiet) g_print ("Validating refs...\n"); /* Validate that the commit for each ref is available */ - g_autoptr(GHashTable) all_refs = NULL; - if (!ostree_repo_list_refs (repo, NULL, &all_refs, - cancellable, error)) + g_autoptr (GHashTable) all_refs = NULL; + if (!ostree_repo_list_refs (repo, NULL, &all_refs, cancellable, error)) return FALSE; GHashTableIter hash_iter; @@ -342,26 +327,26 @@ ostree_builtin_fsck (int argc, char **argv, OstreeCommandInvocation *invocation, g_autofree char *ref_name = NULL; if (!ostree_parse_refspec (refspec, NULL, &ref_name, error)) return FALSE; - if (!fsck_commit_for_ref (repo, checksum, NULL, ref_name, - &found_corruption, cancellable, error)) + if (!fsck_commit_for_ref (repo, checksum, NULL, ref_name, &found_corruption, cancellable, + error)) return FALSE; } if (!opt_quiet) g_print ("Validating refs in collections...\n"); - g_autoptr(GHashTable) all_collection_refs = NULL; /* (element-type OstreeCollectionRef utf8) */ + g_autoptr (GHashTable) all_collection_refs = NULL; /* (element-type OstreeCollectionRef utf8) */ if (!ostree_repo_list_collection_refs (repo, NULL, &all_collection_refs, - OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES, - cancellable, error)) + OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES, cancellable, + error)) return FALSE; g_hash_table_iter_init (&hash_iter, all_collection_refs); while (g_hash_table_iter_next (&hash_iter, &key, &value)) { const OstreeCollectionRef *ref = key; - if (!fsck_commit_for_ref (repo, value, ref->collection_id, ref->ref_name, - &found_corruption, cancellable, error)) + if (!fsck_commit_for_ref (repo, value, ref->collection_id, ref->ref_name, &found_corruption, + cancellable, error)) return FALSE; } @@ -369,14 +354,14 @@ ostree_builtin_fsck (int argc, char **argv, OstreeCommandInvocation *invocation, g_print ("Enumerating commits...\n"); // Find all commit objects, including partial ones - g_autoptr(GHashTable) all_commits = NULL; + g_autoptr (GHashTable) all_commits = NULL; if (!ostree_repo_list_commit_objects_starting_with (repo, "", &all_commits, cancellable, error)) return FALSE; // And gather a set of non-partial commits for further analysis - g_autoptr(GHashTable) commits = g_hash_table_new_full (ostree_hash_object_name, g_variant_equal, - (GDestroyNotify)g_variant_unref, NULL); + g_autoptr (GHashTable) commits = g_hash_table_new_full (ostree_hash_object_name, g_variant_equal, + (GDestroyNotify)g_variant_unref, NULL); - g_autoptr(GPtrArray) tombstones = NULL; + g_autoptr (GPtrArray) tombstones = NULL; if (opt_add_tombstones) tombstones = g_ptr_array_new_with_free_func (g_free); @@ -392,7 +377,7 @@ ostree_builtin_fsck (int argc, char **argv, OstreeCommandInvocation *invocation, const char *checksum; OstreeObjectType objtype; OstreeRepoCommitState commitstate = 0; - g_autoptr(GVariant) commit = NULL; + g_autoptr (GVariant) commit = NULL; ostree_object_name_deserialize (serialized_key, &checksum, &objtype); @@ -412,7 +397,7 @@ ostree_builtin_fsck (int argc, char **argv, OstreeCommandInvocation *invocation, } else g_hash_table_add (commits, g_variant_ref (serialized_key)); - } + } g_clear_pointer (&all_commits, g_hash_table_unref); @@ -420,8 +405,7 @@ ostree_builtin_fsck (int argc, char **argv, OstreeCommandInvocation *invocation, g_print ("Verifying content integrity of %u commit objects...\n", (guint)g_hash_table_size (commits)); - if (!fsck_reachable_objects_from_commits (repo, commits, &found_corruption, - cancellable, error)) + if (!fsck_reachable_objects_from_commits (repo, commits, &found_corruption, cancellable, error)) return FALSE; if (opt_add_tombstones) @@ -437,7 +421,8 @@ ostree_builtin_fsck (int argc, char **argv, OstreeCommandInvocation *invocation, { const char *checksum = tombstones->pdata[i]; g_print ("Adding tombstone for commit %s\n", checksum); - if (!ostree_repo_delete_object (repo, OSTREE_OBJECT_TYPE_COMMIT, checksum, cancellable, error)) + if (!ostree_repo_delete_object (repo, OSTREE_OBJECT_TYPE_COMMIT, checksum, cancellable, + error)) return FALSE; } } diff --git a/src/ostree/ot-builtin-gpg-sign.c b/src/ostree/ot-builtin-gpg-sign.c index 48aa4699..a0ddf2af 100644 --- a/src/ostree/ot-builtin-gpg-sign.c +++ b/src/ostree/ot-builtin-gpg-sign.c @@ -21,11 +21,11 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" +#include "ostree-core-private.h" #include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" #include "otutil.h" -#include "ostree-core-private.h" static gboolean opt_delete; static char *opt_gpg_homedir; @@ -35,11 +35,11 @@ static char *opt_gpg_homedir; * man page (man/ostree-gpg-sign.xml) when changing the option list. */ -static GOptionEntry options[] = { - { "delete", 'd', 0, G_OPTION_ARG_NONE, &opt_delete, "Delete signatures having any of the GPG KEY-IDs" }, - { "gpg-homedir", 0, 0, G_OPTION_ARG_FILENAME, &opt_gpg_homedir, "GPG Homedir to use when looking for keyrings", "HOMEDIR" }, - { NULL } -}; +static GOptionEntry options[] = { { "delete", 'd', 0, G_OPTION_ARG_NONE, &opt_delete, + "Delete signatures having any of the GPG KEY-IDs" }, + { "gpg-homedir", 0, 0, G_OPTION_ARG_FILENAME, &opt_gpg_homedir, + "GPG Homedir to use when looking for keyrings", "HOMEDIR" }, + { NULL } }; static void usage_error (GOptionContext *context, const char *message, GError **error) @@ -50,19 +50,14 @@ usage_error (GOptionContext *context, const char *message, GError **error) } static gboolean -delete_signatures (OstreeRepo *repo, - const char *commit_checksum, - const char * const *key_ids, - guint n_key_ids, - guint *out_n_deleted, - GCancellable *cancellable, - GError **error) +delete_signatures (OstreeRepo *repo, const char *commit_checksum, const char *const *key_ids, + guint n_key_ids, guint *out_n_deleted, GCancellable *cancellable, GError **error) { GVariantDict metadata_dict; - g_autoptr(OstreeGpgVerifyResult) result = NULL; - g_autoptr(GVariant) old_metadata = NULL; - g_autoptr(GVariant) new_metadata = NULL; - g_autoptr(GVariant) signature_data = NULL; + g_autoptr (OstreeGpgVerifyResult) result = NULL; + g_autoptr (GVariant) old_metadata = NULL; + g_autoptr (GVariant) new_metadata = NULL; + g_autoptr (GVariant) signature_data = NULL; GVariantIter iter; GVariant *child; GQueue signatures = G_QUEUE_INIT; @@ -80,17 +75,13 @@ delete_signatures (OstreeRepo *repo, * OTOH, would this really be a useful addition to libostree? */ - if (!ostree_repo_read_commit_detached_metadata (repo, - commit_checksum, - &old_metadata, - cancellable, + if (!ostree_repo_read_commit_detached_metadata (repo, commit_checksum, &old_metadata, cancellable, error)) goto out; g_variant_dict_init (&metadata_dict, old_metadata); - signature_data = g_variant_dict_lookup_value (&metadata_dict, - _OSTREE_METADATA_GPGSIGS_NAME, + signature_data = g_variant_dict_lookup_value (&metadata_dict, _OSTREE_METADATA_GPGSIGS_NAME, G_VARIANT_TYPE ("aay")); /* Taking the approach of deleting whatever matches we find for the @@ -108,9 +99,8 @@ delete_signatures (OstreeRepo *repo, * XXX Reading detached metadata from disk twice here. Another reason * to move this into libostree? */ - result = ostree_repo_verify_commit_ext (repo, commit_checksum, - NULL, NULL, - cancellable, &local_error); + result = ostree_repo_verify_commit_ext (repo, commit_checksum, NULL, NULL, cancellable, + &local_error); if (result == NULL) { g_variant_dict_clear (&metadata_dict); @@ -169,21 +159,17 @@ delete_signatures (OstreeRepo *repo, while (!g_queue_is_empty (&signatures)) { - g_autoptr(GVariant) sigchild = g_queue_pop_head (&signatures); + g_autoptr (GVariant) sigchild = g_queue_pop_head (&signatures); g_variant_builder_add_value (&signature_builder, sigchild); } - g_variant_dict_insert_value (&metadata_dict, - _OSTREE_METADATA_GPGSIGS_NAME, + g_variant_dict_insert_value (&metadata_dict, _OSTREE_METADATA_GPGSIGS_NAME, g_variant_builder_end (&signature_builder)); } /* Commit the new metadata. */ new_metadata = g_variant_dict_end (&metadata_dict); - if (!ostree_repo_write_commit_detached_metadata (repo, - commit_checksum, - new_metadata, - cancellable, + if (!ostree_repo_write_commit_detached_metadata (repo, commit_checksum, new_metadata, cancellable, error)) goto out; @@ -199,13 +185,15 @@ out: } gboolean -ostree_builtin_gpg_sign (int argc, char **argv,OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_gpg_sign (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("COMMIT KEY-ID..."); + g_autoptr (GOptionContext) context = g_option_context_new ("COMMIT KEY-ID..."); - g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + g_autoptr (OstreeRepo) repo = NULL; + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) return FALSE; if (argc < 2) @@ -232,8 +220,7 @@ ostree_builtin_gpg_sign (int argc, char **argv,OstreeCommandInvocation *invocati { guint n_deleted = 0; - if (!delete_signatures (repo, resolved_commit, - (const char * const *) key_ids, n_key_ids, + if (!delete_signatures (repo, resolved_commit, (const char *const *)key_ids, n_key_ids, &n_deleted, cancellable, error)) return FALSE; @@ -243,8 +230,8 @@ ostree_builtin_gpg_sign (int argc, char **argv,OstreeCommandInvocation *invocati for (int ii = 0; ii < n_key_ids; ii++) { - if (!ostree_repo_sign_commit (repo, resolved_commit, key_ids[ii], - opt_gpg_homedir, cancellable, error)) + if (!ostree_repo_sign_commit (repo, resolved_commit, key_ids[ii], opt_gpg_homedir, + cancellable, error)) return FALSE; } diff --git a/src/ostree/ot-builtin-init.c b/src/ostree/ot-builtin-init.c index a699a55a..379c2b98 100644 --- a/src/ostree/ot-builtin-init.c +++ b/src/ostree/ot-builtin-init.c @@ -21,9 +21,9 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" #include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" static char *opt_mode = "bare"; static char *opt_collection_id = NULL; @@ -33,24 +33,28 @@ static char *opt_collection_id = NULL; * man page (man/ostree-init.xml) when changing the option list. */ -static GOptionEntry options[] = { - { "mode", 0, 0, G_OPTION_ARG_STRING, &opt_mode, "Initialize repository in given mode (bare, bare-user, bare-user-only, archive)", NULL }, - { "collection-id", 0, 0, G_OPTION_ARG_STRING, &opt_collection_id, - "Globally unique ID for this repository as an collection of refs for redistribution to other repositories", "COLLECTION-ID" }, - { NULL } -}; +static GOptionEntry options[] + = { { "mode", 0, 0, G_OPTION_ARG_STRING, &opt_mode, + "Initialize repository in given mode (bare, bare-user, bare-user-only, archive)", NULL }, + { "collection-id", 0, 0, G_OPTION_ARG_STRING, &opt_collection_id, + "Globally unique ID for this repository as an collection of refs for redistribution to " + "other repositories", + "COLLECTION-ID" }, + { NULL } }; gboolean -ostree_builtin_init (int argc, char **argv,OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_init (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeRepo) repo = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeRepo) repo = NULL; gboolean ret = FALSE; OstreeRepoMode mode; context = g_option_context_new (""); - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) goto out; if (!ostree_repo_mode_from_string (opt_mode, &mode, error)) @@ -62,6 +66,6 @@ ostree_builtin_init (int argc, char **argv,OstreeCommandInvocation *invocation, goto out; ret = TRUE; - out: +out: return ret; } diff --git a/src/ostree/ot-builtin-log.c b/src/ostree/ot-builtin-log.c index c75656df..0b59bf8a 100644 --- a/src/ostree/ot-builtin-log.c +++ b/src/ostree/ot-builtin-log.c @@ -21,10 +21,10 @@ #include "config.h" -#include "ot-main.h" +#include "ostree.h" #include "ot-builtins.h" #include "ot-dump.h" -#include "ostree.h" +#include "ot-main.h" #include "otutil.h" static gboolean opt_raw; @@ -34,25 +34,19 @@ static gboolean opt_raw; * man page (man/ostree-log.xml) when changing the option list. */ -static GOptionEntry options[] = { - { "raw", 0, 0, G_OPTION_ARG_NONE, &opt_raw, "Show raw variant data" }, - { NULL } -}; +static GOptionEntry options[] + = { { "raw", 0, 0, G_OPTION_ARG_NONE, &opt_raw, "Show raw variant data" }, { NULL } }; static gboolean -log_commit (OstreeRepo *repo, - const gchar *checksum, - gboolean is_recurse, - OstreeDumpFlags flags, - GError **error) +log_commit (OstreeRepo *repo, const gchar *checksum, gboolean is_recurse, OstreeDumpFlags flags, + GError **error) { - g_autoptr(GVariant) variant = NULL; + g_autoptr (GVariant) variant = NULL; g_autofree char *parent = NULL; gboolean ret = FALSE; GError *local_error = NULL; - if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, checksum, - &variant, &local_error)) + if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, checksum, &variant, &local_error)) { if (is_recurse && g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { @@ -80,14 +74,11 @@ out: } gboolean -ostree_builtin_log (int argc, - char **argv, - OstreeCommandInvocation *invocation, - GCancellable *cancellable, - GError **error) +ostree_builtin_log (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeRepo) repo = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeRepo) repo = NULL; gboolean ret = FALSE; const char *rev; g_autofree char *checksum = NULL; @@ -95,7 +86,8 @@ ostree_builtin_log (int argc, context = g_option_context_new ("REV"); - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) goto out; if (opt_raw) @@ -115,6 +107,6 @@ ostree_builtin_log (int argc, goto out; ret = TRUE; - out: +out: return ret; } diff --git a/src/ostree/ot-builtin-ls.c b/src/ostree/ot-builtin-ls.c index 2a7d1cdc..780bc016 100644 --- a/src/ostree/ot-builtin-ls.c +++ b/src/ostree/ot-builtin-ls.c @@ -21,10 +21,10 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" -#include "ostree.h" #include "ostree-repo-file.h" +#include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" #include "otutil.h" static gboolean opt_dironly; @@ -38,27 +38,26 @@ static gboolean opt_nul_filenames_only; * man page (man/ostree-ls.xml) when changing the option list. */ -static GOptionEntry options[] = { - { "dironly", 'd', 0, G_OPTION_ARG_NONE, &opt_dironly, "Do not recurse into directory arguments", NULL }, - { "recursive", 'R', 0, G_OPTION_ARG_NONE, &opt_recursive, "Print directories recursively", NULL }, - { "checksum", 'C', 0, G_OPTION_ARG_NONE, &opt_checksum, "Print checksum", NULL }, - { "xattrs", 'X', 0, G_OPTION_ARG_NONE, &opt_xattrs, "Print extended attributes", NULL }, - { "nul-filenames-only", 0, 0, G_OPTION_ARG_NONE, &opt_nul_filenames_only, "Print only filenames, NUL separated", NULL }, - { NULL } -}; +static GOptionEntry options[] + = { { "dironly", 'd', 0, G_OPTION_ARG_NONE, &opt_dironly, + "Do not recurse into directory arguments", NULL }, + { "recursive", 'R', 0, G_OPTION_ARG_NONE, &opt_recursive, "Print directories recursively", + NULL }, + { "checksum", 'C', 0, G_OPTION_ARG_NONE, &opt_checksum, "Print checksum", NULL }, + { "xattrs", 'X', 0, G_OPTION_ARG_NONE, &opt_xattrs, "Print extended attributes", NULL }, + { "nul-filenames-only", 0, 0, G_OPTION_ARG_NONE, &opt_nul_filenames_only, + "Print only filenames, NUL separated", NULL }, + { NULL } }; static gboolean -print_one_file_text (GFile *f, - GFileInfo *file_info, - GCancellable *cancellable, - GError **error) +print_one_file_text (GFile *f, GFileInfo *file_info, GCancellable *cancellable, GError **error) { - g_autoptr(GString) buf = g_string_new (""); + g_autoptr (GString) buf = g_string_new (""); char type_c; guint32 mode; guint32 type; - if (!ostree_repo_file_ensure_resolved ((OstreeRepoFile*)f, error)) + if (!ostree_repo_file_ensure_resolved ((OstreeRepoFile *)f, error)) return FALSE; type_c = '?'; @@ -76,9 +75,9 @@ print_one_file_text (GFile *f, type_c = 'l'; break; case G_FILE_TYPE_SPECIAL: - if (S_ISCHR(mode)) + if (S_ISCHR (mode)) type_c = 'c'; - else if (S_ISBLK(mode)) + else if (S_ISBLK (mode)) type_c = 'b'; break; case G_FILE_TYPE_UNKNOWN: @@ -87,8 +86,7 @@ print_one_file_text (GFile *f, return glnx_throw (error, "Invalid file type"); } g_string_append_c (buf, type_c); - g_string_append_printf (buf, "0%04o %u %u %6" G_GUINT64_FORMAT " ", - mode & ~S_IFMT, + g_string_append_printf (buf, "0%04o %u %u %6" G_GUINT64_FORMAT " ", mode & ~S_IFMT, g_file_info_get_attribute_uint32 (file_info, "unix::uid"), g_file_info_get_attribute_uint32 (file_info, "unix::gid"), g_file_info_get_attribute_uint64 (file_info, "standard::size")); @@ -96,8 +94,9 @@ print_one_file_text (GFile *f, if (opt_checksum) { if (type == G_FILE_TYPE_DIRECTORY) - g_string_append_printf (buf, "%s ", ostree_repo_file_tree_get_contents_checksum ((OstreeRepoFile*)f)); - g_string_append_printf (buf, "%s ", ostree_repo_file_get_checksum ((OstreeRepoFile*)f)); + g_string_append_printf (buf, "%s ", + ostree_repo_file_tree_get_contents_checksum ((OstreeRepoFile *)f)); + g_string_append_printf (buf, "%s ", ostree_repo_file_get_checksum ((OstreeRepoFile *)f)); } if (opt_xattrs) @@ -105,7 +104,7 @@ print_one_file_text (GFile *f, GVariant *xattrs; char *formatted; - if (!ostree_repo_file_get_xattrs ((OstreeRepoFile*)f, &xattrs, cancellable, error)) + if (!ostree_repo_file_get_xattrs ((OstreeRepoFile *)f, &xattrs, cancellable, error)) return FALSE; formatted = g_variant_print (xattrs, TRUE); @@ -119,7 +118,9 @@ print_one_file_text (GFile *f, g_string_append (buf, gs_file_get_path_cached (f)); if (type == G_FILE_TYPE_SYMBOLIC_LINK) - g_string_append_printf (buf, " -> %s", g_file_info_get_attribute_byte_string (file_info, "standard::symlink-target")); + g_string_append_printf ( + buf, " -> %s", + g_file_info_get_attribute_byte_string (file_info, "standard::symlink-target")); g_print ("%s\n", buf->str); @@ -127,14 +128,11 @@ print_one_file_text (GFile *f, } static gboolean -print_one_file_binary (GFile *f, - GFileInfo *file_info, - GCancellable *cancellable, - GError **error) +print_one_file_binary (GFile *f, GFileInfo *file_info, GCancellable *cancellable, GError **error) { const char *path; - if (!ostree_repo_file_ensure_resolved ((OstreeRepoFile*)f, error)) + if (!ostree_repo_file_ensure_resolved ((OstreeRepoFile *)f, error)) return FALSE; path = gs_file_get_path_cached (f); @@ -146,10 +144,7 @@ print_one_file_binary (GFile *f, } static gboolean -print_one_file (GFile *f, - GFileInfo *file_info, - GCancellable *cancellable, - GError **error) +print_one_file (GFile *f, GFileInfo *file_info, GCancellable *cancellable, GError **error) { if (opt_nul_filenames_only) return print_one_file_binary (f, file_info, cancellable, error); @@ -158,14 +153,11 @@ print_one_file (GFile *f, } static gboolean -print_directory_recurse (GFile *f, - int depth, - GCancellable *cancellable, - GError **error) +print_directory_recurse (GFile *f, int depth, GCancellable *cancellable, GError **error) { - g_autoptr(GFileEnumerator) dir_enum = NULL; - g_autoptr(GFile) child = NULL; - g_autoptr(GFileInfo) child_info = NULL; + g_autoptr (GFileEnumerator) dir_enum = NULL; + g_autoptr (GFile) child = NULL; + g_autoptr (GFileInfo) child_info = NULL; GError *temp_error = NULL; if (depth > 0) @@ -176,9 +168,7 @@ print_directory_recurse (GFile *f, g_assert (depth == -1); dir_enum = g_file_enumerate_children (f, OSTREE_GIO_FAST_QUERYINFO, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - NULL, - error); + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, error); if (dir_enum == NULL) return FALSE; @@ -208,22 +198,18 @@ print_directory_recurse (GFile *f, } static gboolean -print_one_argument (OstreeRepo *repo, - GFile *root, - const char *arg, - GCancellable *cancellable, - GError **error) +print_one_argument (OstreeRepo *repo, GFile *root, const char *arg, GCancellable *cancellable, + GError **error) { g_assert (root != NULL); g_assert (arg != NULL); - g_autoptr(GFile) f = g_file_resolve_relative_path (root, arg); + g_autoptr (GFile) f = g_file_resolve_relative_path (root, arg); if (f == NULL) return glnx_throw (error, "Failed to resolve path '%s'", arg); - g_autoptr(GFileInfo) file_info = NULL; - file_info = g_file_query_info (f, OSTREE_GIO_FAST_QUERYINFO, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + g_autoptr (GFileInfo) file_info = NULL; + file_info = g_file_query_info (f, OSTREE_GIO_FAST_QUERYINFO, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (file_info == NULL) return FALSE; @@ -249,17 +235,19 @@ print_one_argument (OstreeRepo *repo, } gboolean -ostree_builtin_ls (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_ls (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeRepo) repo = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeRepo) repo = NULL; const char *rev; int i; - g_autoptr(GFile) root = NULL; + g_autoptr (GFile) root = NULL; context = g_option_context_new ("COMMIT [PATH...]"); - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) return FALSE; if (argc <= 1) diff --git a/src/ostree/ot-builtin-prune.c b/src/ostree/ot-builtin-prune.c index e641c18b..1416ed84 100644 --- a/src/ostree/ot-builtin-prune.c +++ b/src/ostree/ot-builtin-prune.c @@ -22,9 +22,9 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" #include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" #include "otutil.h" #include "parse-datetime.h" @@ -44,29 +44,39 @@ static gboolean opt_commit_only; */ static GOptionEntry options[] = { - { "no-prune", 0, 0, G_OPTION_ARG_NONE, &opt_no_prune, "Only display unreachable objects; don't delete", NULL }, - { "refs-only", 0, 0, G_OPTION_ARG_NONE, &opt_refs_only, "Only compute reachability via refs", NULL }, - { "depth", 0, 0, G_OPTION_ARG_INT, &opt_depth, "Only traverse DEPTH parents for each commit (default: -1=infinite)", "DEPTH" }, - { "delete-commit", 0, 0, G_OPTION_ARG_STRING, &opt_delete_commit, "Specify a commit to delete", "COMMIT" }, - { "keep-younger-than", 0, 0, G_OPTION_ARG_STRING, &opt_keep_younger_than, "Prune all commits older than the specified date", "DATE" }, - { "static-deltas-only", 0, 0, G_OPTION_ARG_NONE, &opt_static_deltas_only, "Change the behavior of delete-commit and keep-younger-than to prune only static deltas" }, - { "retain-branch-depth", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_retain_branch_depth, "Additionally retain BRANCH=DEPTH commits", "BRANCH=DEPTH" }, - { "only-branch", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_only_branches, "Only prune BRANCH (may be specified multiple times)", "BRANCH" }, - { "commit-only", 0, 0, G_OPTION_ARG_NONE, &opt_commit_only, "Only traverse and delete commit objects.", NULL }, + { "no-prune", 0, 0, G_OPTION_ARG_NONE, &opt_no_prune, + "Only display unreachable objects; don't delete", NULL }, + { "refs-only", 0, 0, G_OPTION_ARG_NONE, &opt_refs_only, "Only compute reachability via refs", + NULL }, + { "depth", 0, 0, G_OPTION_ARG_INT, &opt_depth, + "Only traverse DEPTH parents for each commit (default: -1=infinite)", "DEPTH" }, + { "delete-commit", 0, 0, G_OPTION_ARG_STRING, &opt_delete_commit, "Specify a commit to delete", + "COMMIT" }, + { "keep-younger-than", 0, 0, G_OPTION_ARG_STRING, &opt_keep_younger_than, + "Prune all commits older than the specified date", "DATE" }, + { "static-deltas-only", 0, 0, G_OPTION_ARG_NONE, &opt_static_deltas_only, + "Change the behavior of delete-commit and keep-younger-than to prune only static deltas" }, + { "retain-branch-depth", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_retain_branch_depth, + "Additionally retain BRANCH=DEPTH commits", "BRANCH=DEPTH" }, + { "only-branch", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_only_branches, + "Only prune BRANCH (may be specified multiple times)", "BRANCH" }, + { "commit-only", 0, 0, G_OPTION_ARG_NONE, &opt_commit_only, + "Only traverse and delete commit objects.", NULL }, { NULL } }; static gboolean -delete_commit (OstreeRepo *repo, const char *commit_to_delete, GCancellable *cancellable, GError **error) +delete_commit (OstreeRepo *repo, const char *commit_to_delete, GCancellable *cancellable, + GError **error) { - g_autoptr(GHashTable) refs = NULL; /* (element-type utf8 utf8) */ - g_autoptr(GHashTable) collection_refs = NULL; /* (element-type OstreeCollectionRef utf8) */ + g_autoptr (GHashTable) refs = NULL; /* (element-type utf8 utf8) */ + g_autoptr (GHashTable) collection_refs = NULL; /* (element-type OstreeCollectionRef utf8) */ /* Check refs which are not in a collection. */ if (!ostree_repo_list_refs (repo, NULL, &refs, cancellable, error)) return FALSE; - GLNX_HASH_TABLE_FOREACH_KV(refs, const char *, ref, const char *, commit) + GLNX_HASH_TABLE_FOREACH_KV (refs, const char *, ref, const char *, commit) { if (g_strcmp0 (commit_to_delete, commit) == 0) return glnx_throw (error, "Commit '%s' is referenced by '%s'", commit_to_delete, ref); @@ -74,32 +84,31 @@ delete_commit (OstreeRepo *repo, const char *commit_to_delete, GCancellable *can /* And check refs which *are* in a collection. */ if (!ostree_repo_list_collection_refs (repo, NULL, &collection_refs, - OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES, - cancellable, error)) + OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES, cancellable, + error)) return FALSE; - GLNX_HASH_TABLE_FOREACH_KV (collection_refs, const OstreeCollectionRef*, ref, - const char *, commit) + GLNX_HASH_TABLE_FOREACH_KV (collection_refs, const OstreeCollectionRef *, ref, const char *, + commit) { if (g_strcmp0 (commit_to_delete, commit) == 0) - return glnx_throw (error, "Commit '%s' is referenced by (%s, %s)", - commit_to_delete, ref->collection_id, ref->ref_name); + return glnx_throw (error, "Commit '%s' is referenced by (%s, %s)", commit_to_delete, + ref->collection_id, ref->ref_name); } if (!ot_enable_tombstone_commits (repo, error)) return FALSE; - if (!ostree_repo_delete_object (repo, OSTREE_OBJECT_TYPE_COMMIT, commit_to_delete, cancellable, error)) + if (!ostree_repo_delete_object (repo, OSTREE_OBJECT_TYPE_COMMIT, commit_to_delete, cancellable, + error)) return FALSE; return TRUE; } static gboolean -traverse_keep_younger_than (OstreeRepo *repo, const char *checksum, - struct timespec *ts, - GHashTable *reachable, - GCancellable *cancellable, GError **error) +traverse_keep_younger_than (OstreeRepo *repo, const char *checksum, struct timespec *ts, + GHashTable *reachable, GCancellable *cancellable, GError **error) { g_autofree char *next_checksum = g_strdup (checksum); OstreeRepoCommitTraverseFlags traverse_flags = OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE; @@ -109,13 +118,13 @@ traverse_keep_younger_than (OstreeRepo *repo, const char *checksum, /* This is the first commit in our loop, which has a ref pointing to it. We * don't want to auto-prune it. */ - if (!ostree_repo_traverse_commit_with_flags (repo, traverse_flags, checksum, 0, reachable, - NULL, cancellable, error)) + if (!ostree_repo_traverse_commit_with_flags (repo, traverse_flags, checksum, 0, reachable, NULL, + cancellable, error)) return FALSE; while (TRUE) { - g_autoptr(GVariant) commit = NULL; + g_autoptr (GVariant) commit = NULL; if (!ostree_repo_load_variant_if_exists (repo, OSTREE_OBJECT_TYPE_COMMIT, next_checksum, &commit, error)) return FALSE; @@ -127,8 +136,8 @@ traverse_keep_younger_than (OstreeRepo *repo, const char *checksum, if (commit_timestamp >= ts->tv_sec) { /* It's newer, traverse it */ - if (!ostree_repo_traverse_commit_with_flags (repo, traverse_flags, next_checksum, 0, reachable, - NULL, cancellable, error)) + if (!ostree_repo_traverse_commit_with_flags (repo, traverse_flags, next_checksum, 0, + reachable, NULL, cancellable, error)) return FALSE; g_free (next_checksum); @@ -146,11 +155,13 @@ traverse_keep_younger_than (OstreeRepo *repo, const char *checksum, } gboolean -ostree_builtin_prune (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_prune (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new (""); - g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + g_autoptr (GOptionContext) context = g_option_context_new (""); + g_autoptr (OstreeRepo) repo = NULL; + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) return FALSE; if (!opt_no_prune && !ostree_ensure_repo_writable (repo, error)) @@ -163,16 +174,17 @@ ostree_builtin_prune (int argc, char **argv, OstreeCommandInvocation *invocation { if (opt_no_prune) { - ot_util_usage_error (context, "Cannot specify both --delete-commit and --no-prune", error); + ot_util_usage_error (context, "Cannot specify both --delete-commit and --no-prune", + error); return FALSE; } - if (opt_static_deltas_only) - { - if(!ostree_repo_prune_static_deltas (repo, opt_delete_commit, cancellable, error)) - return FALSE; - } - else if (!delete_commit (repo, opt_delete_commit, cancellable, error)) - return FALSE; + if (opt_static_deltas_only) + { + if (!ostree_repo_prune_static_deltas (repo, opt_delete_commit, cancellable, error)) + return FALSE; + } + else if (!delete_commit (repo, opt_delete_commit, cancellable, error)) + return FALSE; } else { @@ -181,7 +193,8 @@ ostree_builtin_prune (int argc, char **argv, OstreeCommandInvocation *invocation * https://github.com/ostreedev/ostree/issues/1479 */ if (opt_static_deltas_only) - return glnx_throw (error, "--static-deltas-only requires --delete-commit; see https://github.com/ostreedev/ostree/issues/1479"); + return glnx_throw (error, "--static-deltas-only requires --delete-commit; see " + "https://github.com/ostreedev/ostree/issues/1479"); } OstreeRepoPruneFlags pruneflags = 0; @@ -201,9 +214,8 @@ ostree_builtin_prune (int argc, char **argv, OstreeCommandInvocation *invocation guint64 objsize_total; if (!(opt_retain_branch_depth || opt_keep_younger_than || opt_only_branches)) { - if (!ostree_repo_prune (repo, pruneflags, opt_depth, - &n_objects_total, &n_objects_pruned, &objsize_total, - cancellable, error)) + if (!ostree_repo_prune (repo, pruneflags, opt_depth, &n_objects_total, &n_objects_pruned, + &objsize_total, cancellable, error)) return FALSE; } else @@ -212,15 +224,18 @@ ostree_builtin_prune (int argc, char **argv, OstreeCommandInvocation *invocation * While we do this, we can't let new content in since it'll race with * reachability calculations and we may immediately nuke it. So push an * exclusive lock now. */ - g_autoptr(OstreeRepoAutoLock) lock = - ostree_repo_auto_lock_push (repo, OSTREE_REPO_LOCK_EXCLUSIVE, cancellable, error); + g_autoptr (OstreeRepoAutoLock) lock + = ostree_repo_auto_lock_push (repo, OSTREE_REPO_LOCK_EXCLUSIVE, cancellable, error); if (!lock) return FALSE; - g_autoptr(GHashTable) all_refs = NULL; - g_autoptr(GHashTable) reachable = ostree_repo_traverse_new_reachable (); - g_autoptr(GHashTable) retain_branch_depth = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - struct timespec keep_younger_than_ts = {0, }; + g_autoptr (GHashTable) all_refs = NULL; + g_autoptr (GHashTable) reachable = ostree_repo_traverse_new_reachable (); + g_autoptr (GHashTable) retain_branch_depth + = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + struct timespec keep_younger_than_ts = { + 0, + }; GHashTableIter hash_iter; gpointer key, value; @@ -259,8 +274,7 @@ ostree_builtin_prune (int argc, char **argv, OstreeCommandInvocation *invocation /* We start from the refs */ /* FIXME: Do we also want to look at ostree_repo_list_collection_refs()? */ - if (!ostree_repo_list_refs (repo, NULL, &all_refs, - cancellable, error)) + if (!ostree_repo_list_refs (repo, NULL, &all_refs, cancellable, error)) return FALSE; /* Process --only-branch. Note this combines with --retain-branch-depth; one @@ -275,14 +289,14 @@ ostree_builtin_prune (int argc, char **argv, OstreeCommandInvocation *invocation if (opt_only_branches) { /* Turn --only-branch into a set */ - g_autoptr(GHashTable) only_branches_set = g_hash_table_new (g_str_hash, g_str_equal); + g_autoptr (GHashTable) only_branches_set = g_hash_table_new (g_str_hash, g_str_equal); for (char **iter = opt_only_branches; iter && *iter; iter++) { const char *ref = *iter; /* Ensure the specified branch exists */ if (!ostree_repo_resolve_rev (repo, ref, FALSE, NULL, error)) return FALSE; - g_hash_table_add (only_branches_set, (char*)ref); + g_hash_table_add (only_branches_set, (char *)ref); } /* Iterate over all refs, add equivalent of --retain-branch-depth=$ref=-1 @@ -291,10 +305,11 @@ ostree_builtin_prune (int argc, char **argv, OstreeCommandInvocation *invocation */ GLNX_HASH_TABLE_FOREACH (all_refs, const char *, ref) { - if (!g_hash_table_contains (only_branches_set, ref) && - !g_hash_table_contains (retain_branch_depth, ref)) + if (!g_hash_table_contains (only_branches_set, ref) + && !g_hash_table_contains (retain_branch_depth, ref)) { - g_hash_table_insert (retain_branch_depth, g_strdup (ref), GINT_TO_POINTER ((int)-1)); + g_hash_table_insert (retain_branch_depth, g_strdup (ref), + GINT_TO_POINTER ((int)-1)); } } } @@ -318,54 +333,48 @@ ostree_builtin_prune (int argc, char **argv, OstreeCommandInvocation *invocation * --retain-branch-depth=myos/x86_64/dev=5 */ if (depthp) - depth = GPOINTER_TO_INT(depthp); + depth = GPOINTER_TO_INT (depthp); else if (opt_keep_younger_than) { - if (!traverse_keep_younger_than (repo, checksum, - &keep_younger_than_ts, - reachable, + if (!traverse_keep_younger_than (repo, checksum, &keep_younger_than_ts, reachable, cancellable, error)) return FALSE; /* Okay, we handled the younger-than case; the other * two fall through to plain depth-based handling below. */ - continue; /* Note again, we're skipping the below bit */ + continue; /* Note again, we're skipping the below bit */ } else depth = opt_depth; /* No --retain-branch-depth for this branch, use the global default */ g_debug ("Finding objects to keep for commit %s", checksum); - if (!ostree_repo_traverse_commit_with_flags (repo, traverse_flags, checksum, depth, reachable, - NULL, cancellable, error)) + if (!ostree_repo_traverse_commit_with_flags (repo, traverse_flags, checksum, depth, + reachable, NULL, cancellable, error)) return FALSE; } /* We've gathered the reachable set; start the prune ✀ */ - { OstreeRepoPruneOptions opts = { pruneflags, reachable }; - if (!ostree_repo_prune_from_reachable (repo, &opts, - &n_objects_total, - &n_objects_pruned, - &objsize_total, - cancellable, error)) + { + OstreeRepoPruneOptions opts = { pruneflags, reachable }; + if (!ostree_repo_prune_from_reachable (repo, &opts, &n_objects_total, &n_objects_pruned, + &objsize_total, cancellable, error)) return FALSE; } } g_autofree char *formatted_freed_size = g_format_size_full (objsize_total, 0); if (opt_commit_only) - g_print("Total (commit only) objects: %u\n", n_objects_total); + g_print ("Total (commit only) objects: %u\n", n_objects_total); else g_print ("Total objects: %u\n", n_objects_total); if (n_objects_pruned == 0) g_print ("No unreachable objects\n"); else if (pruneflags & OSTREE_REPO_PRUNE_FLAGS_NO_PRUNE) - g_print ("Would delete: %u objects, freeing %s\n", - n_objects_pruned, formatted_freed_size); + g_print ("Would delete: %u objects, freeing %s\n", n_objects_pruned, formatted_freed_size); else - g_print ("Deleted %u objects, %s freed\n", - n_objects_pruned, formatted_freed_size); + g_print ("Deleted %u objects, %s freed\n", n_objects_pruned, formatted_freed_size); return TRUE; } diff --git a/src/ostree/ot-builtin-pull-local.c b/src/ostree/ot-builtin-pull-local.c index a49445da..6ea8da05 100644 --- a/src/ostree/ot-builtin-pull-local.c +++ b/src/ostree/ot-builtin-pull-local.c @@ -21,12 +21,12 @@ #include "config.h" -#include #include +#include -#include "ot-main.h" -#include "ot-builtins.h" #include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" #include "otutil.h" static char *opt_remote; @@ -46,45 +46,55 @@ static int opt_depth = 0; * man page (man/ostree-pull-local.xml) when changing the option list. */ -static GOptionEntry options[] = { - { "commit-metadata-only", 0, 0, G_OPTION_ARG_NONE, &opt_commit_only, "Fetch only the commit metadata", NULL }, - { "remote", 0, 0, G_OPTION_ARG_STRING, &opt_remote, "Add REMOTE to refspec", "REMOTE" }, - { "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", NULL }, - { "per-object-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_per_object_fsync, "Perform writes in such a way that avoids stalling concurrent processes", NULL }, - { "untrusted", 0, 0, G_OPTION_ARG_NONE, &opt_untrusted, "Verify checksums of local sources (always enabled for HTTP pulls)", NULL }, - { "bareuseronly-files", 0, 0, G_OPTION_ARG_NONE, &opt_bareuseronly_files, "Reject regular files with mode outside of 0775 (world writable, suid, etc.)", NULL }, - { "require-static-deltas", 0, 0, G_OPTION_ARG_NONE, &opt_require_static_deltas, "Require static deltas", NULL }, - { "gpg-verify", 0, 0, G_OPTION_ARG_NONE, &opt_gpg_verify, "GPG verify commits (must specify --remote)", NULL }, - { "gpg-verify-summary", 0, 0, G_OPTION_ARG_NONE, &opt_gpg_verify_summary, "GPG verify summary (must specify --remote)", NULL }, - { "disable-verify-bindings", 0, 0, G_OPTION_ARG_NONE, &opt_disable_verify_bindings, "Do not verify commit bindings", NULL }, - { "depth", 0, 0, G_OPTION_ARG_INT, &opt_depth, "Traverse DEPTH parents (-1=infinite) (default: 0)", "DEPTH" }, - { NULL } -}; +static GOptionEntry options[] + = { { "commit-metadata-only", 0, 0, G_OPTION_ARG_NONE, &opt_commit_only, + "Fetch only the commit metadata", NULL }, + { "remote", 0, 0, G_OPTION_ARG_STRING, &opt_remote, "Add REMOTE to refspec", "REMOTE" }, + { "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", + NULL }, + { "per-object-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_per_object_fsync, + "Perform writes in such a way that avoids stalling concurrent processes", NULL }, + { "untrusted", 0, 0, G_OPTION_ARG_NONE, &opt_untrusted, + "Verify checksums of local sources (always enabled for HTTP pulls)", NULL }, + { "bareuseronly-files", 0, 0, G_OPTION_ARG_NONE, &opt_bareuseronly_files, + "Reject regular files with mode outside of 0775 (world writable, suid, etc.)", NULL }, + { "require-static-deltas", 0, 0, G_OPTION_ARG_NONE, &opt_require_static_deltas, + "Require static deltas", NULL }, + { "gpg-verify", 0, 0, G_OPTION_ARG_NONE, &opt_gpg_verify, + "GPG verify commits (must specify --remote)", NULL }, + { "gpg-verify-summary", 0, 0, G_OPTION_ARG_NONE, &opt_gpg_verify_summary, + "GPG verify summary (must specify --remote)", NULL }, + { "disable-verify-bindings", 0, 0, G_OPTION_ARG_NONE, &opt_disable_verify_bindings, + "Do not verify commit bindings", NULL }, + { "depth", 0, 0, G_OPTION_ARG_INT, &opt_depth, + "Traverse DEPTH parents (-1=infinite) (default: 0)", "DEPTH" }, + { NULL } }; /* See canonical version of this in ot-builtin-pull.c */ static void -noninteractive_console_progress_changed (OstreeAsyncProgress *progress, - gpointer user_data) +noninteractive_console_progress_changed (OstreeAsyncProgress *progress, gpointer user_data) { /* We do nothing here - we just want the final status */ } gboolean -ostree_builtin_pull_local (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_pull_local (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeRepo) repo = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeRepo) repo = NULL; int i; const char *src_repo_arg; g_autofree char *src_repo_uri = NULL; - g_autoptr(OstreeAsyncProgress) progress = NULL; - g_autoptr(GPtrArray) refs_to_fetch = NULL; + g_autoptr (OstreeAsyncProgress) progress = NULL; + g_autoptr (GPtrArray) refs_to_fetch = NULL; OstreeRepoPullFlags pullflags = 0; context = g_option_context_new ("SRC_REPO [REFS...]"); - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) goto out; if (!ostree_ensure_repo_writable (repo, error)) @@ -95,8 +105,7 @@ ostree_builtin_pull_local (int argc, char **argv, OstreeCommandInvocation *invoc gchar *help = g_option_context_get_help (context, TRUE, NULL); g_printerr ("%s\n", help); g_free (help); - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "DESTINATION must be specified"); + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "DESTINATION must be specified"); goto out; } @@ -122,9 +131,9 @@ ostree_builtin_pull_local (int argc, char **argv, OstreeCommandInvocation *invoc if (argc == 2) { - g_autoptr(GFile) src_repo_path = g_file_new_for_path (src_repo_arg); - g_autoptr(OstreeRepo) src_repo = ostree_repo_new (src_repo_path); - g_autoptr(GHashTable) refs_to_clone = NULL; + g_autoptr (GFile) src_repo_path = g_file_new_for_path (src_repo_arg); + g_autoptr (OstreeRepo) src_repo = ostree_repo_new (src_repo_path); + g_autoptr (GHashTable) refs_to_clone = NULL; refs_to_fetch = g_ptr_array_new_with_free_func (g_free); @@ -133,11 +142,11 @@ ostree_builtin_pull_local (int argc, char **argv, OstreeCommandInvocation *invoc /* FIXME: This should grow support for pulling refs from refs/mirrors on * a local repository, using ostree_repo_list_collection_refs(). */ - if (!ostree_repo_list_refs (src_repo, NULL, &refs_to_clone, - cancellable, error)) + if (!ostree_repo_list_refs (src_repo, NULL, &refs_to_clone, cancellable, error)) goto out; - { GHashTableIter hashiter; + { + GHashTableIter hashiter; gpointer hkey, hvalue; g_hash_table_iter_init (&hashiter, refs_to_clone); @@ -153,14 +162,17 @@ ostree_builtin_pull_local (int argc, char **argv, OstreeCommandInvocation *invoc { const char *ref = argv[i]; - g_ptr_array_add (refs_to_fetch, (char*)ref); + g_ptr_array_add (refs_to_fetch, (char *)ref); } g_ptr_array_add (refs_to_fetch, NULL); } - { GVariantBuilder builder; - g_autoptr(GVariant) opts = NULL; - g_auto(GLnxConsoleRef) console = { 0, }; + { + GVariantBuilder builder; + g_autoptr (GVariant) opts = NULL; + g_auto (GLnxConsoleRef) console = { + 0, + }; glnx_console_lock (&console); @@ -168,21 +180,24 @@ ostree_builtin_pull_local (int argc, char **argv, OstreeCommandInvocation *invoc g_variant_builder_add (&builder, "{s@v}", "flags", g_variant_new_variant (g_variant_new_int32 (pullflags))); - g_variant_builder_add (&builder, "{s@v}", "refs", - g_variant_new_variant (g_variant_new_strv ((const char *const*) refs_to_fetch->pdata, -1))); + g_variant_builder_add ( + &builder, "{s@v}", "refs", + g_variant_new_variant (g_variant_new_strv ((const char *const *)refs_to_fetch->pdata, -1))); if (opt_remote) g_variant_builder_add (&builder, "{s@v}", "override-remote-name", g_variant_new_variant (g_variant_new_string (opt_remote))); - g_variant_builder_add (&builder, "{s@v}", "require-static-deltas", - g_variant_new_variant (g_variant_new_boolean (opt_require_static_deltas))); + g_variant_builder_add ( + &builder, "{s@v}", "require-static-deltas", + g_variant_new_variant (g_variant_new_boolean (opt_require_static_deltas))); if (opt_gpg_verify) g_variant_builder_add (&builder, "{s@v}", "gpg-verify", g_variant_new_variant (g_variant_new_boolean (TRUE))); if (opt_gpg_verify_summary) g_variant_builder_add (&builder, "{s@v}", "gpg-verify-summary", g_variant_new_variant (g_variant_new_boolean (TRUE))); - g_variant_builder_add (&builder, "{s@v}", "disable-verify-bindings", - g_variant_new_variant (g_variant_new_boolean (opt_disable_verify_bindings))); + g_variant_builder_add ( + &builder, "{s@v}", "disable-verify-bindings", + g_variant_new_variant (g_variant_new_boolean (opt_disable_verify_bindings))); g_variant_builder_add (&builder, "{s@v}", "depth", g_variant_new_variant (g_variant_new_int32 (opt_depth))); /* local pulls always disable signapi verification. If you don't want this, use @@ -193,19 +208,18 @@ ostree_builtin_pull_local (int argc, char **argv, OstreeCommandInvocation *invoc g_variant_builder_add (&builder, "{s@v}", "disable-sign-verify-summary", g_variant_new_variant (g_variant_new_boolean (TRUE))); if (opt_per_object_fsync) - g_variant_builder_add (&builder, "{s@v}", "per-object-fsync", - g_variant_new_variant (g_variant_new_boolean (TRUE))); + g_variant_builder_add (&builder, "{s@v}", "per-object-fsync", + g_variant_new_variant (g_variant_new_boolean (TRUE))); if (console.is_tty) - progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console); + progress = ostree_async_progress_new_and_connect ( + ostree_repo_pull_default_console_progress_changed, &console); else - progress = ostree_async_progress_new_and_connect (noninteractive_console_progress_changed, &console); + progress = ostree_async_progress_new_and_connect (noninteractive_console_progress_changed, + &console); opts = g_variant_ref_sink (g_variant_builder_end (&builder)); - if (!ostree_repo_pull_with_options (repo, src_repo_uri, - opts, - progress, - cancellable, error)) + if (!ostree_repo_pull_with_options (repo, src_repo_uri, opts, progress, cancellable, error)) goto out; if (!console.is_tty) @@ -219,7 +233,7 @@ ostree_builtin_pull_local (int argc, char **argv, OstreeCommandInvocation *invoc } ret = TRUE; - out: +out: if (repo) ostree_repo_abort_transaction (repo, cancellable, NULL); return ret; diff --git a/src/ostree/ot-builtin-pull.c b/src/ostree/ot-builtin-pull.c index 07671e54..bb4be037 100644 --- a/src/ostree/ot-builtin-pull.c +++ b/src/ostree/ot-builtin-pull.c @@ -21,9 +21,9 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" #include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" #include "otutil.h" static gboolean opt_disable_fsync; @@ -37,55 +37,73 @@ static gboolean opt_untrusted; static gboolean opt_http_trusted; static gboolean opt_timestamp_check; static gboolean opt_disable_verify_bindings; -static char* opt_timestamp_check_from_rev; +static char *opt_timestamp_check_from_rev; static gboolean opt_bareuseronly_files; -static char** opt_subpaths; -static char** opt_http_headers; -static char* opt_cache_dir; -static char* opt_append_user_agent; +static char **opt_subpaths; +static char **opt_http_headers; +static char *opt_cache_dir; +static char *opt_append_user_agent; static int opt_depth = 0; static int opt_frequency = 0; static int opt_network_retries = -1; -static char* opt_url; -static char** opt_localcache_repos; +static char *opt_url; +static char **opt_localcache_repos; /* ATTENTION: * Please remember to update the bash-completion script (bash/ostree) and * man page (man/ostree-pull.xml) when changing the option list. */ -static GOptionEntry options[] = { - { "commit-metadata-only", 0, 0, G_OPTION_ARG_NONE, &opt_commit_only, "Fetch only the commit metadata", NULL }, - { "cache-dir", 0, 0, G_OPTION_ARG_FILENAME, &opt_cache_dir, "Use custom cache dir", NULL }, - { "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", NULL }, - { "per-object-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_per_object_fsync, "Perform writes in such a way that avoids stalling concurrent processes", NULL }, - { "disable-static-deltas", 0, 0, G_OPTION_ARG_NONE, &opt_disable_static_deltas, "Do not use static deltas", NULL }, - { "require-static-deltas", 0, 0, G_OPTION_ARG_NONE, &opt_require_static_deltas, "Require static deltas", NULL }, - { "mirror", 0, 0, G_OPTION_ARG_NONE, &opt_mirror, "Write refs suitable for a mirror and fetches all refs if none provided", NULL }, - { "subpath", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_subpaths, "Only pull the provided subpath(s)", NULL }, - { "untrusted", 0, 0, G_OPTION_ARG_NONE, &opt_untrusted, "Verify checksums of local sources (always enabled for HTTP pulls)", NULL }, - { "http-trusted", 0, 0, G_OPTION_ARG_NONE, &opt_http_trusted, "Do not verify checksums of HTTP sources (mostly useful when mirroring)", NULL }, - { "bareuseronly-files", 0, 0, G_OPTION_ARG_NONE, &opt_bareuseronly_files, "Reject regular files with mode outside of 0775 (world writable, suid, etc.)", NULL }, - { "dry-run", 0, 0, G_OPTION_ARG_NONE, &opt_dry_run, "Only print information on what will be downloaded (requires static deltas)", NULL }, - { "depth", 0, 0, G_OPTION_ARG_INT, &opt_depth, "Traverse DEPTH parents (-1=infinite) (default: 0)", "DEPTH" }, - { "url", 0, 0, G_OPTION_ARG_STRING, &opt_url, "Pull objects from this URL instead of the one from the remote config", "URL" }, - { "http-header", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_http_headers, "Add NAME=VALUE as HTTP header to all requests", "NAME=VALUE" }, - { "update-frequency", 0, 0, G_OPTION_ARG_INT, &opt_frequency, "Sets the update frequency, in milliseconds (0=1000ms) (default: 0)", "FREQUENCY" }, - { "network-retries", 0, 0, G_OPTION_ARG_INT, &opt_network_retries, "Specifies how many times each download should be retried upon error (default: 5)", "N"}, - { "localcache-repo", 'L', 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_localcache_repos, "Add REPO as local cache source for objects during this pull", "REPO" }, - { "timestamp-check", 'T', 0, G_OPTION_ARG_NONE, &opt_timestamp_check, "Require fetched commits to have newer timestamps", NULL }, - { "timestamp-check-from-rev", 0, 0, G_OPTION_ARG_STRING, &opt_timestamp_check_from_rev, "Require fetched commits to have newer timestamps than given rev", NULL }, - { "disable-verify-bindings", 0, 0, G_OPTION_ARG_NONE, &opt_disable_verify_bindings, "Do not verify commit bindings", NULL }, - /* let's leave this hidden for now; we just need it for tests */ - { "append-user-agent", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &opt_append_user_agent, "Append string to user agent", NULL }, - { NULL } - }; +static GOptionEntry options[] + = { { "commit-metadata-only", 0, 0, G_OPTION_ARG_NONE, &opt_commit_only, + "Fetch only the commit metadata", NULL }, + { "cache-dir", 0, 0, G_OPTION_ARG_FILENAME, &opt_cache_dir, "Use custom cache dir", NULL }, + { "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", + NULL }, + { "per-object-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_per_object_fsync, + "Perform writes in such a way that avoids stalling concurrent processes", NULL }, + { "disable-static-deltas", 0, 0, G_OPTION_ARG_NONE, &opt_disable_static_deltas, + "Do not use static deltas", NULL }, + { "require-static-deltas", 0, 0, G_OPTION_ARG_NONE, &opt_require_static_deltas, + "Require static deltas", NULL }, + { "mirror", 0, 0, G_OPTION_ARG_NONE, &opt_mirror, + "Write refs suitable for a mirror and fetches all refs if none provided", NULL }, + { "subpath", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_subpaths, + "Only pull the provided subpath(s)", NULL }, + { "untrusted", 0, 0, G_OPTION_ARG_NONE, &opt_untrusted, + "Verify checksums of local sources (always enabled for HTTP pulls)", NULL }, + { "http-trusted", 0, 0, G_OPTION_ARG_NONE, &opt_http_trusted, + "Do not verify checksums of HTTP sources (mostly useful when mirroring)", NULL }, + { "bareuseronly-files", 0, 0, G_OPTION_ARG_NONE, &opt_bareuseronly_files, + "Reject regular files with mode outside of 0775 (world writable, suid, etc.)", NULL }, + { "dry-run", 0, 0, G_OPTION_ARG_NONE, &opt_dry_run, + "Only print information on what will be downloaded (requires static deltas)", NULL }, + { "depth", 0, 0, G_OPTION_ARG_INT, &opt_depth, + "Traverse DEPTH parents (-1=infinite) (default: 0)", "DEPTH" }, + { "url", 0, 0, G_OPTION_ARG_STRING, &opt_url, + "Pull objects from this URL instead of the one from the remote config", "URL" }, + { "http-header", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_http_headers, + "Add NAME=VALUE as HTTP header to all requests", "NAME=VALUE" }, + { "update-frequency", 0, 0, G_OPTION_ARG_INT, &opt_frequency, + "Sets the update frequency, in milliseconds (0=1000ms) (default: 0)", "FREQUENCY" }, + { "network-retries", 0, 0, G_OPTION_ARG_INT, &opt_network_retries, + "Specifies how many times each download should be retried upon error (default: 5)", "N" }, + { "localcache-repo", 'L', 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_localcache_repos, + "Add REPO as local cache source for objects during this pull", "REPO" }, + { "timestamp-check", 'T', 0, G_OPTION_ARG_NONE, &opt_timestamp_check, + "Require fetched commits to have newer timestamps", NULL }, + { "timestamp-check-from-rev", 0, 0, G_OPTION_ARG_STRING, &opt_timestamp_check_from_rev, + "Require fetched commits to have newer timestamps than given rev", NULL }, + { "disable-verify-bindings", 0, 0, G_OPTION_ARG_NONE, &opt_disable_verify_bindings, + "Do not verify commit bindings", NULL }, + /* let's leave this hidden for now; we just need it for tests */ + { "append-user-agent", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &opt_append_user_agent, + "Append string to user agent", NULL }, + { NULL } }; #ifndef OSTREE_DISABLE_GPGME static void -gpg_verify_result_cb (OstreeRepo *repo, - const char *checksum, - OstreeGpgVerifyResult *result, +gpg_verify_result_cb (OstreeRepo *repo, const char *checksum, OstreeGpgVerifyResult *result, GLnxConsoleRef *console) { /* Temporarily place the tty back in normal mode before printing GPG @@ -103,8 +121,7 @@ gpg_verify_result_cb (OstreeRepo *repo, static gboolean printed_console_progress; static void -dry_run_console_progress_changed (OstreeAsyncProgress *progress, - gpointer user_data) +dry_run_console_progress_changed (OstreeAsyncProgress *progress, gpointer user_data) { guint fetched_delta_parts, total_delta_parts; guint fetched_delta_part_fallbacks, total_delta_part_fallbacks; @@ -113,17 +130,15 @@ dry_run_console_progress_changed (OstreeAsyncProgress *progress, g_assert (!printed_console_progress); printed_console_progress = TRUE; - ostree_async_progress_get (progress, - /* Number of parts */ - "fetched-delta-parts", "u", &fetched_delta_parts, - "total-delta-parts", "u", &total_delta_parts, - "fetched-delta-fallbacks", "u", &fetched_delta_part_fallbacks, - "total-delta-fallbacks", "u", &total_delta_part_fallbacks, - /* Size variables */ - "fetched-delta-part-size", "t", &fetched_delta_part_size, - "total-delta-part-size", "t", &total_delta_part_size, - "total-delta-part-usize", "t", &total_delta_part_usize, - NULL); + ostree_async_progress_get ( + progress, + /* Number of parts */ + "fetched-delta-parts", "u", &fetched_delta_parts, "total-delta-parts", "u", + &total_delta_parts, "fetched-delta-fallbacks", "u", &fetched_delta_part_fallbacks, + "total-delta-fallbacks", "u", &total_delta_part_fallbacks, + /* Size variables */ + "fetched-delta-part-size", "t", &fetched_delta_part_size, "total-delta-part-size", "t", + &total_delta_part_size, "total-delta-part-usize", "t", &total_delta_part_usize, NULL); /* Fold the count of deltaparts + fallbacks for simplicity; if changing this, * please change ostree_repo_pull_default_console_progress_changed() first. @@ -131,46 +146,44 @@ dry_run_console_progress_changed (OstreeAsyncProgress *progress, fetched_delta_parts += fetched_delta_part_fallbacks; total_delta_parts += total_delta_part_fallbacks; - g_autoptr(GString) buf = g_string_new (""); + g_autoptr (GString) buf = g_string_new (""); - { g_autofree char *formatted_fetched = - g_format_size (fetched_delta_part_size); - g_autofree char *formatted_size = - g_format_size (total_delta_part_size); - g_autofree char *formatted_usize = - g_format_size (total_delta_part_usize); + { + g_autofree char *formatted_fetched = g_format_size (fetched_delta_part_size); + g_autofree char *formatted_size = g_format_size (total_delta_part_size); + g_autofree char *formatted_usize = g_format_size (total_delta_part_usize); g_string_append_printf (buf, "Delta update: %u/%u parts, %s/%s, %s total uncompressed", - fetched_delta_parts, total_delta_parts, - formatted_fetched, formatted_size, - formatted_usize); + fetched_delta_parts, total_delta_parts, formatted_fetched, + formatted_size, formatted_usize); } g_print ("%s\n", buf->str); } static void -noninteractive_console_progress_changed (OstreeAsyncProgress *progress, - gpointer user_data) +noninteractive_console_progress_changed (OstreeAsyncProgress *progress, gpointer user_data) { /* We do nothing here - we just want the final status */ } gboolean -ostree_builtin_pull (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_pull (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeRepo) repo = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeRepo) repo = NULL; gboolean ret = FALSE; g_autofree char *remote = NULL; OstreeRepoPullFlags pullflags = 0; - g_autoptr(GPtrArray) refs_to_fetch = NULL; - g_autoptr(GPtrArray) override_commit_ids = NULL; - g_autoptr(OstreeAsyncProgress) progress = NULL; + g_autoptr (GPtrArray) refs_to_fetch = NULL; + g_autoptr (GPtrArray) override_commit_ids = NULL; + g_autoptr (OstreeAsyncProgress) progress = NULL; gulong signal_handler_id = 0; context = g_option_context_new ("REMOTE [BRANCH...]"); - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) goto out; if (!ostree_ensure_repo_writable (repo, error)) @@ -271,8 +284,10 @@ ostree_builtin_pull (int argc, char **argv, OstreeCommandInvocation *invocation, { GVariantBuilder builder; - g_autoptr(GVariant) pull_options = NULL; - g_auto(GLnxConsoleRef) console = { 0, }; + g_autoptr (GVariant) pull_options = NULL; + g_auto (GLnxConsoleRef) console = { + 0, + }; g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); glnx_console_lock (&console); @@ -288,14 +303,16 @@ ostree_builtin_pull (int argc, char **argv, OstreeCommandInvocation *invocation, g_variant_builder_add (&builder, "{s@v}", "subdir", g_variant_new_variant (g_variant_new_string (opt_subpaths[0]))); else - g_variant_builder_add (&builder, "{s@v}", "subdirs", - g_variant_new_variant (g_variant_new_strv ((const char *const*) opt_subpaths, -1))); + g_variant_builder_add ( + &builder, "{s@v}", "subdirs", + g_variant_new_variant (g_variant_new_strv ((const char *const *)opt_subpaths, -1))); } g_variant_builder_add (&builder, "{s@v}", "flags", g_variant_new_variant (g_variant_new_int32 (pullflags))); if (refs_to_fetch) g_variant_builder_add (&builder, "{s@v}", "refs", - g_variant_new_variant (g_variant_new_strv ((const char *const*) refs_to_fetch->pdata, -1))); + g_variant_new_variant (g_variant_new_strv ( + (const char *const *)refs_to_fetch->pdata, -1))); g_variant_builder_add (&builder, "{s@v}", "depth", g_variant_new_variant (g_variant_new_int32 (opt_depth))); @@ -306,11 +323,13 @@ ostree_builtin_pull (int argc, char **argv, OstreeCommandInvocation *invocation, g_variant_builder_add (&builder, "{s@v}", "n-network-retries", g_variant_new_variant (g_variant_new_uint32 (opt_network_retries))); - g_variant_builder_add (&builder, "{s@v}", "disable-static-deltas", - g_variant_new_variant (g_variant_new_boolean (opt_disable_static_deltas))); + g_variant_builder_add ( + &builder, "{s@v}", "disable-static-deltas", + g_variant_new_variant (g_variant_new_boolean (opt_disable_static_deltas))); - g_variant_builder_add (&builder, "{s@v}", "require-static-deltas", - g_variant_new_variant (g_variant_new_boolean (opt_require_static_deltas))); + g_variant_builder_add ( + &builder, "{s@v}", "require-static-deltas", + g_variant_new_variant (g_variant_new_boolean (opt_require_static_deltas))); g_variant_builder_add (&builder, "{s@v}", "dry-run", g_variant_new_variant (g_variant_new_boolean (opt_dry_run))); @@ -318,20 +337,25 @@ ostree_builtin_pull (int argc, char **argv, OstreeCommandInvocation *invocation, g_variant_builder_add (&builder, "{s@v}", "timestamp-check", g_variant_new_variant (g_variant_new_boolean (opt_timestamp_check))); if (opt_timestamp_check_from_rev) - g_variant_builder_add (&builder, "{s@v}", "timestamp-check-from-rev", - g_variant_new_variant (g_variant_new_string (opt_timestamp_check_from_rev))); + g_variant_builder_add ( + &builder, "{s@v}", "timestamp-check-from-rev", + g_variant_new_variant (g_variant_new_string (opt_timestamp_check_from_rev))); if (override_commit_ids) - g_variant_builder_add (&builder, "{s@v}", "override-commit-ids", - g_variant_new_variant (g_variant_new_strv ((const char*const*)override_commit_ids->pdata, override_commit_ids->len))); + g_variant_builder_add ( + &builder, "{s@v}", "override-commit-ids", + g_variant_new_variant (g_variant_new_strv ( + (const char *const *)override_commit_ids->pdata, override_commit_ids->len))); if (opt_localcache_repos) g_variant_builder_add (&builder, "{s@v}", "localcache-repos", - g_variant_new_variant (g_variant_new_strv ((const char*const*)opt_localcache_repos, -1))); + g_variant_new_variant (g_variant_new_strv ( + (const char *const *)opt_localcache_repos, -1))); if (opt_per_object_fsync) g_variant_builder_add (&builder, "{s@v}", "per-object-fsync", g_variant_new_variant (g_variant_new_boolean (TRUE))); - g_variant_builder_add (&builder, "{s@v}", "disable-verify-bindings", - g_variant_new_variant (g_variant_new_boolean (opt_disable_verify_bindings))); + g_variant_builder_add ( + &builder, "{s@v}", "disable-verify-bindings", + g_variant_new_variant (g_variant_new_boolean (opt_disable_verify_bindings))); if (opt_http_headers) { GVariantBuilder hdr_builder; @@ -344,8 +368,7 @@ ostree_builtin_pull (int argc, char **argv, OstreeCommandInvocation *invocation, g_autofree char *key = NULL; if (!eq) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Missing '=' in --http-header"); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Missing '=' in --http-header"); goto out; } key = g_strndup (kv, eq - kv); @@ -362,9 +385,11 @@ ostree_builtin_pull (int argc, char **argv, OstreeCommandInvocation *invocation, if (!opt_dry_run) { if (console.is_tty) - progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console); + progress = ostree_async_progress_new_and_connect ( + ostree_repo_pull_default_console_progress_changed, &console); else - progress = ostree_async_progress_new_and_connect (noninteractive_console_progress_changed, &console); + progress = ostree_async_progress_new_and_connect (noninteractive_console_progress_changed, + &console); } else { @@ -375,15 +400,13 @@ ostree_builtin_pull (int argc, char **argv, OstreeCommandInvocation *invocation, { #ifndef OSTREE_DISABLE_GPGME signal_handler_id = g_signal_connect (repo, "gpg-verify-result", - G_CALLBACK (gpg_verify_result_cb), - &console); + G_CALLBACK (gpg_verify_result_cb), &console); #endif /* OSTREE_DISABLE_GPGME */ } pull_options = g_variant_ref_sink (g_variant_builder_end (&builder)); - if (!ostree_repo_pull_with_options (repo, remote, pull_options, - progress, cancellable, error)) + if (!ostree_repo_pull_with_options (repo, remote, pull_options, progress, cancellable, error)) goto out; if (!console.is_tty && !opt_dry_run) @@ -401,7 +424,7 @@ ostree_builtin_pull (int argc, char **argv, OstreeCommandInvocation *invocation, } ret = TRUE; - out: +out: if (signal_handler_id > 0) g_signal_handler_disconnect (repo, signal_handler_id); return ret; diff --git a/src/ostree/ot-builtin-refs.c b/src/ostree/ot-builtin-refs.c index c49d7507..ec345b5c 100644 --- a/src/ostree/ot-builtin-refs.c +++ b/src/ostree/ot-builtin-refs.c @@ -21,9 +21,9 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" #include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" static gboolean opt_delete; static gboolean opt_list; @@ -39,19 +39,22 @@ static gboolean opt_force; */ static GOptionEntry options[] = { - { "delete", 0, 0, G_OPTION_ARG_NONE, &opt_delete, "Delete refs which match PREFIX, rather than listing them", NULL }, + { "delete", 0, 0, G_OPTION_ARG_NONE, &opt_delete, + "Delete refs which match PREFIX, rather than listing them", NULL }, { "list", 0, 0, G_OPTION_ARG_NONE, &opt_list, "Do not remove the prefix from the refs", NULL }, { "revision", 'r', 0, G_OPTION_ARG_NONE, &opt_revision, "Show revisions in listing", NULL }, - { "alias", 'A', 0, G_OPTION_ARG_NONE, &opt_alias, "If used with --create, create an alias, otherwise just list aliases", NULL }, - { "create", 0, 0, G_OPTION_ARG_STRING, &opt_create, "Create a new ref for an existing commit", "NEWREF" }, - { "collections", 'c', 0, G_OPTION_ARG_NONE, &opt_collections, "Enable listing collection IDs for refs", NULL }, + { "alias", 'A', 0, G_OPTION_ARG_NONE, &opt_alias, + "If used with --create, create an alias, otherwise just list aliases", NULL }, + { "create", 0, 0, G_OPTION_ARG_STRING, &opt_create, "Create a new ref for an existing commit", + "NEWREF" }, + { "collections", 'c', 0, G_OPTION_ARG_NONE, &opt_collections, + "Enable listing collection IDs for refs", NULL }, { "force", 0, 0, G_OPTION_ARG_NONE, &opt_force, "Overwrite existing refs when creating", NULL }, { NULL } }; static int -collection_ref_cmp (OstreeCollectionRef *a, - OstreeCollectionRef *b) +collection_ref_cmp (OstreeCollectionRef *a, OstreeCollectionRef *b) { int ret = g_strcmp0 (a->collection_id, b->collection_id); if (ret == 0) @@ -60,26 +63,22 @@ collection_ref_cmp (OstreeCollectionRef *a, } static gboolean -do_ref_with_collections (OstreeRepo *repo, - const char *refspec_prefix, - GCancellable *cancellable, - GError **error) +do_ref_with_collections (OstreeRepo *repo, const char *refspec_prefix, GCancellable *cancellable, + GError **error) { - g_autoptr(GHashTable) refs = NULL; /* (element-type OstreeCollectionRef utf8) */ + g_autoptr (GHashTable) refs = NULL; /* (element-type OstreeCollectionRef utf8) */ GHashTableIter hashiter; gpointer hashkey, hashvalue; gboolean ret = FALSE; - if (!ostree_repo_list_collection_refs (repo, - (!opt_create) ? refspec_prefix : NULL, - &refs, OSTREE_REPO_LIST_REFS_EXT_NONE, - cancellable, error)) + if (!ostree_repo_list_collection_refs (repo, (!opt_create) ? refspec_prefix : NULL, &refs, + OSTREE_REPO_LIST_REFS_EXT_NONE, cancellable, error)) goto out; if (!opt_delete && !opt_create) { - g_autoptr(GList) ordered_keys = g_hash_table_get_keys (refs); - ordered_keys = g_list_sort (ordered_keys, (GCompareFunc) collection_ref_cmp); + g_autoptr (GList) ordered_keys = g_hash_table_get_keys (refs); + ordered_keys = g_list_sort (ordered_keys, (GCompareFunc)collection_ref_cmp); for (GList *iter = ordered_keys; iter != NULL; iter = iter->next) { @@ -101,7 +100,8 @@ do_ref_with_collections (OstreeRepo *repo, g_autofree char *checksum = NULL; g_autofree char *checksum_existing = NULL; - if (!ostree_repo_resolve_rev_ext (repo, opt_create, TRUE, OSTREE_REPO_RESOLVE_REV_EXT_NONE, &checksum_existing, error)) + if (!ostree_repo_resolve_rev_ext (repo, opt_create, TRUE, OSTREE_REPO_RESOLVE_REV_EXT_NONE, + &checksum_existing, error)) { if (g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY)) { @@ -109,7 +109,8 @@ do_ref_with_collections (OstreeRepo *repo, * which is handled by _ostree_repo_write_ref */ g_clear_error (error); } - else goto out; + else + goto out; } if (!opt_force && checksum_existing != NULL) @@ -124,7 +125,7 @@ do_ref_with_collections (OstreeRepo *repo, /* This is technically an abuse of the refspec syntax: collection IDs * should not be treated like remote names. */ - g_auto(GStrv) parts = g_strsplit (opt_create, ":", 2); + g_auto (GStrv) parts = g_strsplit (opt_create, ":", 2); const char *collection_id = parts[0]; const char *ref_name = parts[1]; if (!ostree_validate_collection_id (collection_id, error)) @@ -132,9 +133,8 @@ do_ref_with_collections (OstreeRepo *repo, if (!ostree_validate_rev (ref_name, error)) goto out; - const OstreeCollectionRef ref = { (gchar *) collection_id, (gchar *) ref_name }; - if (!ostree_repo_set_collection_ref_immediate (repo, &ref, checksum, - cancellable, error)) + const OstreeCollectionRef ref = { (gchar *)collection_id, (gchar *)ref_name }; + if (!ostree_repo_set_collection_ref_immediate (repo, &ref, checksum, cancellable, error)) goto out; } else @@ -145,20 +145,20 @@ do_ref_with_collections (OstreeRepo *repo, { const OstreeCollectionRef *ref = hashkey; - if (!ostree_repo_set_collection_ref_immediate (repo, ref, NULL, - cancellable, error)) + if (!ostree_repo_set_collection_ref_immediate (repo, ref, NULL, cancellable, error)) goto out; } } ret = TRUE; - out: +out: return ret; } -static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellable *cancellable, GError **error) +static gboolean +do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellable *cancellable, GError **error) { - g_autoptr(GHashTable) refs = NULL; - g_autoptr(GHashTable) ref_aliases = NULL; + g_autoptr (GHashTable) refs = NULL; + g_autoptr (GHashTable) ref_aliases = NULL; GHashTableIter hashiter; gpointer hashkey, hashvalue; gboolean ret = FALSE; @@ -174,8 +174,7 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab */ if (opt_alias || opt_delete) { - if (!ostree_repo_list_refs_ext (repo, NULL, &ref_aliases, - OSTREE_REPO_LIST_REFS_EXT_ALIASES, + if (!ostree_repo_list_refs_ext (repo, NULL, &ref_aliases, OSTREE_REPO_LIST_REFS_EXT_ALIASES, cancellable, error)) goto out; } @@ -187,8 +186,7 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab OstreeRepoListRefsExtFlags flags = OSTREE_REPO_LIST_REFS_EXT_NONE; if (opt_alias) flags |= OSTREE_REPO_LIST_REFS_EXT_ALIASES; - if (!ostree_repo_list_refs_ext (repo, refspec_prefix, &refs, flags, - cancellable, error)) + if (!ostree_repo_list_refs_ext (repo, refspec_prefix, &refs, flags, cancellable, error)) goto out; } else if (opt_create) @@ -202,8 +200,8 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab if (is_list) { - g_autoptr(GList) ordered_keys = g_hash_table_get_keys (refs); - ordered_keys = g_list_sort (ordered_keys, (GCompareFunc) g_strcmp0); + g_autoptr (GList) ordered_keys = g_hash_table_get_keys (refs); + ordered_keys = g_list_sort (ordered_keys, (GCompareFunc)g_strcmp0); for (GList *iter = ordered_keys; iter != NULL; iter = iter->next) { @@ -232,7 +230,8 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab g_autofree char *remote = NULL; g_autofree char *ref = NULL; - if (!ostree_repo_resolve_rev_ext (repo, opt_create, TRUE, OSTREE_REPO_RESOLVE_REV_EXT_NONE, &checksum_existing, error)) + if (!ostree_repo_resolve_rev_ext (repo, opt_create, TRUE, OSTREE_REPO_RESOLVE_REV_EXT_NONE, + &checksum_existing, error)) { if (g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY)) { @@ -240,7 +239,8 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab * which is handled by _ostree_repo_write_ref */ g_clear_error (error); } - else goto out; + else + goto out; } /* We want to allow replacing an existing alias or a normal ref when @@ -264,8 +264,8 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab if (!g_hash_table_contains (refs, refspec_prefix)) return glnx_throw (error, "Cannot create alias to non-existent ref: %s", refspec_prefix); - if (!ostree_repo_set_alias_ref_immediate (repo, remote, ref, refspec_prefix, - cancellable, error)) + if (!ostree_repo_set_alias_ref_immediate (repo, remote, ref, refspec_prefix, cancellable, + error)) goto out; } else @@ -273,8 +273,7 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab if (!ostree_repo_resolve_rev (repo, refspec_prefix, FALSE, &checksum, error)) goto out; - if (!ostree_repo_set_ref_immediate (repo, remote, ref, checksum, - cancellable, error)) + if (!ostree_repo_set_ref_immediate (repo, remote, ref, checksum, cancellable, error)) goto out; } } @@ -292,8 +291,7 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab goto out; /* Look for alias if it exists for a ref we want to delete */ - GLNX_HASH_TABLE_FOREACH_KV (ref_aliases, const char *, - ref_alias, const char *, value) + GLNX_HASH_TABLE_FOREACH_KV (ref_aliases, const char *, ref_alias, const char *, value) { if (!strcmp (ref, value)) { @@ -302,27 +300,28 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab goto out; } } - if (!ostree_repo_set_ref_immediate (repo, remote, ref, NULL, - cancellable, error)) + if (!ostree_repo_set_ref_immediate (repo, remote, ref, NULL, cancellable, error)) goto out; } } ret = TRUE; - out: +out: return ret; } gboolean -ostree_builtin_refs (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_refs (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeRepo) repo = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeRepo) repo = NULL; int i; context = g_option_context_new ("[PREFIX]"); - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) goto out; if (argc >= 2) @@ -358,7 +357,7 @@ ostree_builtin_refs (int argc, char **argv, OstreeCommandInvocation *invocation, } ret = TRUE; - out: +out: if (repo) ostree_repo_abort_transaction (repo, cancellable, NULL); return ret; diff --git a/src/ostree/ot-builtin-remote.c b/src/ostree/ot-builtin-remote.c index 0e14bb16..f50e09b2 100644 --- a/src/ostree/ot-builtin-remote.c +++ b/src/ostree/ot-builtin-remote.c @@ -21,48 +21,31 @@ #include "config.h" -#include "ot-main.h" #include "ot-builtins.h" +#include "ot-main.h" #include "ot-remote-builtins.h" static OstreeCommand remote_subcommands[] = { - { "add", OSTREE_BUILTIN_FLAG_NO_REPO, - ot_remote_builtin_add, - "Add a remote repository" }, - { "delete", OSTREE_BUILTIN_FLAG_NO_REPO, - ot_remote_builtin_delete, - "Delete a remote repository" }, - { "show-url", OSTREE_BUILTIN_FLAG_NONE, - ot_remote_builtin_show_url, + { "add", OSTREE_BUILTIN_FLAG_NO_REPO, ot_remote_builtin_add, "Add a remote repository" }, + { "delete", OSTREE_BUILTIN_FLAG_NO_REPO, ot_remote_builtin_delete, "Delete a remote repository" }, + { "show-url", OSTREE_BUILTIN_FLAG_NONE, ot_remote_builtin_show_url, "Show remote repository URL" }, - { "list", OSTREE_BUILTIN_FLAG_NONE, - ot_remote_builtin_list, - "List remote repository names" }, + { "list", OSTREE_BUILTIN_FLAG_NONE, ot_remote_builtin_list, "List remote repository names" }, #ifndef OSTREE_DISABLE_GPGME - { "gpg-import", OSTREE_BUILTIN_FLAG_NONE, - ot_remote_builtin_gpg_import, - "Import GPG keys" }, - { "gpg-list-keys", OSTREE_BUILTIN_FLAG_NONE, - ot_remote_builtin_list_gpg_keys, + { "gpg-import", OSTREE_BUILTIN_FLAG_NONE, ot_remote_builtin_gpg_import, "Import GPG keys" }, + { "gpg-list-keys", OSTREE_BUILTIN_FLAG_NONE, ot_remote_builtin_list_gpg_keys, "Show remote GPG keys" }, #endif /* OSTREE_DISABLE_GPGME */ #ifdef HAVE_LIBCURL_OR_LIBSOUP - { "add-cookie", OSTREE_BUILTIN_FLAG_NONE, - ot_remote_builtin_add_cookie, + { "add-cookie", OSTREE_BUILTIN_FLAG_NONE, ot_remote_builtin_add_cookie, "Add a cookie to remote" }, - { "delete-cookie", OSTREE_BUILTIN_FLAG_NONE, - ot_remote_builtin_delete_cookie, + { "delete-cookie", OSTREE_BUILTIN_FLAG_NONE, ot_remote_builtin_delete_cookie, "Remove one cookie from remote" }, - { "list-cookies", OSTREE_BUILTIN_FLAG_NONE, - ot_remote_builtin_list_cookies, + { "list-cookies", OSTREE_BUILTIN_FLAG_NONE, ot_remote_builtin_list_cookies, "Show remote repository cookies" }, #endif - { "refs", OSTREE_BUILTIN_FLAG_NONE, - ot_remote_builtin_refs, - "List remote refs" }, - { "summary", OSTREE_BUILTIN_FLAG_NONE, - ot_remote_builtin_summary, - "Show remote summary" }, + { "refs", OSTREE_BUILTIN_FLAG_NONE, ot_remote_builtin_refs, "List remote refs" }, + { "summary", OSTREE_BUILTIN_FLAG_NONE, ot_remote_builtin_summary, "Show remote summary" }, { NULL, 0, NULL, NULL } }; @@ -72,7 +55,7 @@ remote_option_context_new_with_commands (void) OstreeCommand *subcommand = remote_subcommands; GOptionContext *context = g_option_context_new ("COMMAND"); - g_autoptr(GString) summary = g_string_new ("Builtin \"remote\" Commands:"); + g_autoptr (GString) summary = g_string_new ("Builtin \"remote\" Commands:"); while (subcommand->name != NULL) { @@ -91,10 +74,11 @@ remote_option_context_new_with_commands (void) } gboolean -ostree_builtin_remote (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_remote (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { const char *subcommand_name = NULL; - int in,out; + int in, out; for (in = 1, out = 1; in < argc; in++, out++) { /* The non-option is the command, take it out of the arguments */ @@ -128,14 +112,13 @@ ostree_builtin_remote (int argc, char **argv, OstreeCommandInvocation *invocatio if (!subcommand->name) { - g_autoptr(GOptionContext) context = NULL; + g_autoptr (GOptionContext) context = NULL; g_autofree char *help = NULL; context = remote_option_context_new_with_commands (); /* This will not return for some options (e.g. --version). */ - if (ostree_option_context_parse (context, NULL, &argc, &argv, - invocation, NULL, cancellable, + if (ostree_option_context_parse (context, NULL, &argc, &argv, invocation, NULL, cancellable, error)) { if (subcommand_name == NULL) diff --git a/src/ostree/ot-builtin-reset.c b/src/ostree/ot-builtin-reset.c index 591eed12..86c5d9cd 100644 --- a/src/ostree/ot-builtin-reset.c +++ b/src/ostree/ot-builtin-reset.c @@ -21,9 +21,9 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" #include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" #include "otutil.h" /* ATTENTION: @@ -31,20 +31,15 @@ * man page (man/ostree-reset.xml) when changing the option list. */ -static GOptionEntry options[] = { - { NULL } -}; +static GOptionEntry options[] = { { NULL } }; gboolean -ostree_builtin_reset (int argc, - char **argv, - OstreeCommandInvocation *invocation, - GCancellable *cancellable, - GError **error) +ostree_builtin_reset (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeRepo) repo = NULL; - g_autoptr(GHashTable) known_refs = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeRepo) repo = NULL; + g_autoptr (GHashTable) known_refs = NULL; gboolean ret = FALSE; const char *ref; const char *target = NULL; @@ -53,7 +48,8 @@ ostree_builtin_reset (int argc, /* FIXME: Add support for collection–refs. */ context = g_option_context_new ("REF COMMIT"); - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) goto out; if (!ostree_ensure_repo_writable (repo, error)) @@ -88,7 +84,7 @@ ostree_builtin_reset (int argc, goto out; ret = TRUE; - out: +out: if (repo) ostree_repo_abort_transaction (repo, cancellable, NULL); return ret; diff --git a/src/ostree/ot-builtin-rev-parse.c b/src/ostree/ot-builtin-rev-parse.c index 7da0a01b..e94012dd 100644 --- a/src/ostree/ot-builtin-rev-parse.c +++ b/src/ostree/ot-builtin-rev-parse.c @@ -21,9 +21,9 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" #include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" #include "otutil.h" #include @@ -34,17 +34,20 @@ static gboolean opt_single; -static GOptionEntry options[] = { - { "single", 'S', 0, G_OPTION_ARG_NONE, &opt_single, "If the repository has exactly one commit, then print it; any other case will result in an error", NULL }, - { NULL } -}; +static GOptionEntry options[] = { { "single", 'S', 0, G_OPTION_ARG_NONE, &opt_single, + "If the repository has exactly one commit, then print it; any " + "other case will result in an error", + NULL }, + { NULL } }; gboolean -ostree_builtin_rev_parse (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_rev_parse (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("REV"); - g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + g_autoptr (GOptionContext) context = g_option_context_new ("REV"); + g_autoptr (OstreeRepo) repo = NULL; + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) return FALSE; if (opt_single) @@ -55,12 +58,12 @@ ostree_builtin_rev_parse (int argc, char **argv, OstreeCommandInvocation *invoca return FALSE; } - g_autoptr(GHashTable) objects = NULL; + g_autoptr (GHashTable) objects = NULL; if (!ostree_repo_list_commit_objects_starting_with (repo, "", &objects, cancellable, error)) return FALSE; GVariant *found = NULL; - GLNX_HASH_TABLE_FOREACH (objects, GVariant*, key) + GLNX_HASH_TABLE_FOREACH (objects, GVariant *, key) { if (found) return glnx_throw (error, "Multiple commit objects found"); diff --git a/src/ostree/ot-builtin-show.c b/src/ostree/ot-builtin-show.c index 9346a7b3..d59407f8 100644 --- a/src/ostree/ot-builtin-show.c +++ b/src/ostree/ot-builtin-show.c @@ -21,16 +21,16 @@ #include "config.h" -#include "ot-main.h" +#include "ostree.h" #include "ot-builtins.h" #include "ot-dump.h" -#include "ostree.h" +#include "ot-main.h" #include "otutil.h" static gboolean opt_print_related; -static char* opt_print_variant_type; -static char* opt_print_metadata_key; -static char* opt_print_detached_metadata_key; +static char *opt_print_variant_type; +static char *opt_print_metadata_key; +static char *opt_print_detached_metadata_key; static gboolean opt_list_metadata_keys; static gboolean opt_list_detached_metadata_keys; static gboolean opt_print_sizes; @@ -44,27 +44,34 @@ static char *opt_gpg_verify_remote; * man page (man/ostree-show.xml) when changing the option list. */ -static GOptionEntry options[] = { - { "print-related", 0, 0, G_OPTION_ARG_NONE, &opt_print_related, "Show the \"related\" commits", NULL }, - { "print-variant-type", 0, 0, G_OPTION_ARG_STRING, &opt_print_variant_type, "Memory map OBJECT (in this case a filename) to the GVariant type string", "TYPE" }, - { "list-metadata-keys", 0, 0, G_OPTION_ARG_NONE, &opt_list_metadata_keys, "List the available metadata keys", NULL }, - { "print-metadata-key", 0, 0, G_OPTION_ARG_STRING, &opt_print_metadata_key, "Print string value of metadata key", "KEY" }, - { "list-detached-metadata-keys", 0, 0, G_OPTION_ARG_NONE, &opt_list_detached_metadata_keys, "List the available detached metadata keys", NULL }, - { "print-detached-metadata-key", 0, 0, G_OPTION_ARG_STRING, &opt_print_detached_metadata_key, "Print string value of detached metadata key", "KEY" }, - { "print-sizes", 0, 0, G_OPTION_ARG_NONE, &opt_print_sizes, "Show the commit size metadata", NULL }, - { "raw", 0, 0, G_OPTION_ARG_NONE, &opt_raw, "Show raw variant data" }, - { "no-byteswap", 'B', 0, G_OPTION_ARG_NONE, &opt_no_byteswap, "Do not automatically convert variant data from big endian" }, - { "gpg-homedir", 0, 0, G_OPTION_ARG_FILENAME, &opt_gpg_homedir, "GPG Homedir to use when looking for keyrings", "HOMEDIR"}, - { "gpg-verify-remote", 0, 0, G_OPTION_ARG_STRING, &opt_gpg_verify_remote, "Use REMOTE name for GPG configuration", "REMOTE"}, - { NULL } -}; +static GOptionEntry options[] + = { { "print-related", 0, 0, G_OPTION_ARG_NONE, &opt_print_related, + "Show the \"related\" commits", NULL }, + { "print-variant-type", 0, 0, G_OPTION_ARG_STRING, &opt_print_variant_type, + "Memory map OBJECT (in this case a filename) to the GVariant type string", "TYPE" }, + { "list-metadata-keys", 0, 0, G_OPTION_ARG_NONE, &opt_list_metadata_keys, + "List the available metadata keys", NULL }, + { "print-metadata-key", 0, 0, G_OPTION_ARG_STRING, &opt_print_metadata_key, + "Print string value of metadata key", "KEY" }, + { "list-detached-metadata-keys", 0, 0, G_OPTION_ARG_NONE, &opt_list_detached_metadata_keys, + "List the available detached metadata keys", NULL }, + { "print-detached-metadata-key", 0, 0, G_OPTION_ARG_STRING, + &opt_print_detached_metadata_key, "Print string value of detached metadata key", "KEY" }, + { "print-sizes", 0, 0, G_OPTION_ARG_NONE, &opt_print_sizes, "Show the commit size metadata", + NULL }, + { "raw", 0, 0, G_OPTION_ARG_NONE, &opt_raw, "Show raw variant data" }, + { "no-byteswap", 'B', 0, G_OPTION_ARG_NONE, &opt_no_byteswap, + "Do not automatically convert variant data from big endian" }, + { "gpg-homedir", 0, 0, G_OPTION_ARG_FILENAME, &opt_gpg_homedir, + "GPG Homedir to use when looking for keyrings", "HOMEDIR" }, + { "gpg-verify-remote", 0, 0, G_OPTION_ARG_STRING, &opt_gpg_verify_remote, + "Use REMOTE name for GPG configuration", "REMOTE" }, + { NULL } }; static gboolean -do_print_variant_generic (const GVariantType *type, - const char *filename, - GError **error) +do_print_variant_generic (const GVariantType *type, const char *filename, GError **error) { - g_autoptr(GVariant) variant = NULL; + g_autoptr (GVariant) variant = NULL; glnx_autofd int fd = -1; if (!glnx_openat_rdonly (AT_FDCWD, filename, TRUE, &fd, error)) @@ -77,22 +84,18 @@ do_print_variant_generic (const GVariantType *type, } static gboolean -do_print_related (OstreeRepo *repo, - const char *rev, - const char *resolved_rev, - GError **error) +do_print_related (OstreeRepo *repo, const char *rev, const char *resolved_rev, GError **error) { - g_autoptr(GVariant) variant = NULL; - if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, - resolved_rev, &variant, error)) + g_autoptr (GVariant) variant = NULL; + if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, resolved_rev, &variant, error)) return FALSE; /* PARSE OSTREE_SERIALIZED_COMMIT_VARIANT */ - g_autoptr(GVariant) related = g_variant_get_child_value (variant, 2); - g_autoptr(GVariantIter) viter = g_variant_iter_new (related); + g_autoptr (GVariant) related = g_variant_get_child_value (variant, 2); + g_autoptr (GVariantIter) viter = g_variant_iter_new (related); const char *name; - GVariant* csum_v; + GVariant *csum_v; while (g_variant_iter_loop (viter, "(&s@ay)", &name, &csum_v)) { g_autofree char *checksum = ostree_checksum_from_bytes_v (csum_v); @@ -102,29 +105,24 @@ do_print_related (OstreeRepo *repo, } static gboolean -get_metadata (OstreeRepo *repo, - const char *resolved_rev, - gboolean detached, - GVariant **out_metadata, - GError **error) +get_metadata (OstreeRepo *repo, const char *resolved_rev, gboolean detached, + GVariant **out_metadata, GError **error) { g_assert (out_metadata != NULL); - g_autoptr(GVariant) commit = NULL; - g_autoptr(GVariant) metadata = NULL; + g_autoptr (GVariant) commit = NULL; + g_autoptr (GVariant) metadata = NULL; if (!detached) { - if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, - resolved_rev, &commit, error)) + if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, resolved_rev, &commit, error)) return FALSE; /* PARSE OSTREE_SERIALIZED_COMMIT_VARIANT */ metadata = g_variant_get_child_value (commit, 0); } else { - if (!ostree_repo_read_commit_detached_metadata (repo, resolved_rev, &metadata, - NULL, error)) + if (!ostree_repo_read_commit_detached_metadata (repo, resolved_rev, &metadata, NULL, error)) return FALSE; if (metadata == NULL) { @@ -140,34 +138,31 @@ get_metadata (OstreeRepo *repo, } static gint -strptr_cmp (gconstpointer a, - gconstpointer b) +strptr_cmp (gconstpointer a, gconstpointer b) { - const char *a_str = *((const char **) a); - const char *b_str = *((const char **) b); + const char *a_str = *((const char **)a); + const char *b_str = *((const char **)b); return g_strcmp0 (a_str, b_str); } static gboolean -do_list_metadata_keys (OstreeRepo *repo, - const char *resolved_rev, - gboolean detached, - GError **error) +do_list_metadata_keys (OstreeRepo *repo, const char *resolved_rev, gboolean detached, + GError **error) { - g_autoptr(GVariant) metadata = NULL; + g_autoptr (GVariant) metadata = NULL; if (!get_metadata (repo, resolved_rev, detached, &metadata, error)) return FALSE; GVariantIter iter; const char *key = NULL; - g_autoptr(GPtrArray) keys = g_ptr_array_new (); + g_autoptr (GPtrArray) keys = g_ptr_array_new (); g_variant_iter_init (&iter, metadata); while (g_variant_iter_loop (&iter, "{&s@v}", &key, NULL)) - g_ptr_array_add (keys, (gpointer) key); + g_ptr_array_add (keys, (gpointer)key); g_ptr_array_sort (keys, strptr_cmp); - for (guint i = 0; i < keys-> len; i++) + for (guint i = 0; i < keys->len; i++) { key = keys->pdata[i]; g_print ("%s\n", key); @@ -177,21 +172,17 @@ do_list_metadata_keys (OstreeRepo *repo, } static gboolean -do_print_metadata_key (OstreeRepo *repo, - const char *resolved_rev, - gboolean detached, - const char *key, - GError **error) +do_print_metadata_key (OstreeRepo *repo, const char *resolved_rev, gboolean detached, + const char *key, GError **error) { - g_autoptr(GVariant) metadata = NULL; + g_autoptr (GVariant) metadata = NULL; if (!get_metadata (repo, resolved_rev, detached, &metadata, error)) return FALSE; - g_autoptr(GVariant) value = g_variant_lookup_value (metadata, key, NULL); + g_autoptr (GVariant) value = g_variant_lookup_value (metadata, key, NULL); if (!value) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "No such metadata key '%s'", key); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "No such metadata key '%s'", key); return FALSE; } @@ -206,19 +197,16 @@ do_print_metadata_key (OstreeRepo *repo, } static gboolean -do_print_sizes (OstreeRepo *repo, - const char *rev, - GError **error) +do_print_sizes (OstreeRepo *repo, const char *rev, GError **error) { - g_autoptr(GVariant) commit = NULL; - if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, rev, - &commit, error)) + g_autoptr (GVariant) commit = NULL; + if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, rev, &commit, error)) { g_prefix_error (error, "Failed to read commit: "); return FALSE; } - g_autoptr(GPtrArray) sizes = NULL; + g_autoptr (GPtrArray) sizes = NULL; if (!ostree_commit_get_object_sizes (commit, &sizes, error)) return FALSE; @@ -237,8 +225,7 @@ do_print_sizes (OstreeRepo *repo, objects++; gboolean exists; - if (!ostree_repo_has_object (repo, entry->objtype, entry->checksum, - &exists, NULL, error)) + if (!ostree_repo_has_object (repo, entry->objtype, entry->checksum, &exists, NULL, error)) return FALSE; if (!exists) @@ -257,24 +244,18 @@ do_print_sizes (OstreeRepo *repo, g_print ("Compressed size (needed/total): %s/%s\n" "Unpacked size (needed/total): %s/%s\n" "Number of objects (needed/total): %" G_GSIZE_FORMAT "/%" G_GSIZE_FORMAT "\n", - new_archived_str, archived_str, - new_unpacked_str, unpacked_str, - new_objects, objects); + new_archived_str, archived_str, new_unpacked_str, unpacked_str, new_objects, objects); return TRUE; } static gboolean -print_object (OstreeRepo *repo, - OstreeObjectType objtype, - const char *checksum, - GError **error) +print_object (OstreeRepo *repo, OstreeObjectType objtype, const char *checksum, GError **error) { OstreeDumpFlags flags = OSTREE_DUMP_NONE; - g_autoptr(GVariant) variant = NULL; - if (!ostree_repo_load_variant (repo, objtype, checksum, - &variant, error)) + g_autoptr (GVariant) variant = NULL; + if (!ostree_repo_load_variant (repo, objtype, checksum, &variant, error)) return FALSE; if (opt_raw) flags |= OSTREE_DUMP_RAW; @@ -285,9 +266,10 @@ print_object (OstreeRepo *repo, #ifndef OSTREE_DISABLE_GPGME if (objtype == OSTREE_OBJECT_TYPE_COMMIT) { - g_autoptr(OstreeGpgVerifyResult) result = NULL; - g_autoptr(GError) local_error = NULL; - g_autoptr(GFile) gpg_homedir = opt_gpg_homedir ? g_file_new_for_path (opt_gpg_homedir) : NULL; + g_autoptr (OstreeGpgVerifyResult) result = NULL; + g_autoptr (GError) local_error = NULL; + g_autoptr (GFile) gpg_homedir + = opt_gpg_homedir ? g_file_new_for_path (opt_gpg_homedir) : NULL; if (opt_gpg_verify_remote) { @@ -296,8 +278,7 @@ print_object (OstreeRepo *repo, } else { - result = ostree_repo_verify_commit_ext (repo, checksum, - gpg_homedir, NULL, NULL, + result = ostree_repo_verify_commit_ext (repo, checksum, gpg_homedir, NULL, NULL, &local_error); } @@ -315,7 +296,7 @@ print_object (OstreeRepo *repo, guint n_sigs = ostree_gpg_verify_result_count_all (result); g_print ("Found %u signature%s:\n", n_sigs, n_sigs == 1 ? "" : "s"); - g_autoptr(GString) buffer = g_string_sized_new (256); + g_autoptr (GString) buffer = g_string_sized_new (256); for (guint ii = 0; ii < n_sigs; ii++) { g_string_append_c (buffer, '\n'); @@ -332,20 +313,15 @@ print_object (OstreeRepo *repo, } static gboolean -print_if_found (OstreeRepo *repo, - OstreeObjectType objtype, - const char *checksum, - gboolean *inout_was_found, - GCancellable *cancellable, - GError **error) +print_if_found (OstreeRepo *repo, OstreeObjectType objtype, const char *checksum, + gboolean *inout_was_found, GCancellable *cancellable, GError **error) { gboolean have_object = FALSE; if (*inout_was_found) return TRUE; - if (!ostree_repo_has_object (repo, objtype, checksum, &have_object, - cancellable, error)) + if (!ostree_repo_has_object (repo, objtype, checksum, &have_object, cancellable, error)) return FALSE; if (have_object) { @@ -358,12 +334,14 @@ print_if_found (OstreeRepo *repo, } gboolean -ostree_builtin_show (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_show (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("OBJECT"); + g_autoptr (GOptionContext) context = g_option_context_new ("OBJECT"); - g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + g_autoptr (OstreeRepo) repo = NULL; + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) return FALSE; if (argc <= 1) @@ -423,25 +401,22 @@ ostree_builtin_show (int argc, char **argv, OstreeCommandInvocation *invocation, } else { - if (!print_if_found (repo, OSTREE_OBJECT_TYPE_COMMIT, rev, - &found, cancellable, error)) + if (!print_if_found (repo, OSTREE_OBJECT_TYPE_COMMIT, rev, &found, cancellable, error)) return FALSE; - if (!print_if_found (repo, OSTREE_OBJECT_TYPE_DIR_META, rev, - &found, cancellable, error)) + if (!print_if_found (repo, OSTREE_OBJECT_TYPE_DIR_META, rev, &found, cancellable, error)) return FALSE; - if (!print_if_found (repo, OSTREE_OBJECT_TYPE_DIR_TREE, rev, - &found, cancellable, error)) + if (!print_if_found (repo, OSTREE_OBJECT_TYPE_DIR_TREE, rev, &found, cancellable, error)) return FALSE; if (!found) { - g_autoptr(GFileInfo) finfo = NULL; - g_autoptr(GVariant) xattrs = NULL; + g_autoptr (GFileInfo) finfo = NULL; + g_autoptr (GVariant) xattrs = NULL; - if (!ostree_repo_load_file (repo, rev, NULL, &finfo, &xattrs, - cancellable, error)) + if (!ostree_repo_load_file (repo, rev, NULL, &finfo, &xattrs, cancellable, error)) return FALSE; - g_print ("Object: %s\nType: %s\n", rev, ostree_object_type_to_string (OSTREE_OBJECT_TYPE_FILE)); + g_print ("Object: %s\nType: %s\n", rev, + ostree_object_type_to_string (OSTREE_OBJECT_TYPE_FILE)); GFileType filetype = g_file_info_get_file_type (finfo); g_print ("File Type: "); switch (filetype) diff --git a/src/ostree/ot-builtin-sign.c b/src/ostree/ot-builtin-sign.c index f4e5c0e5..cd331a48 100644 --- a/src/ostree/ot-builtin-sign.c +++ b/src/ostree/ot-builtin-sign.c @@ -24,12 +24,12 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" -#include "ostree.h" -#include "otutil.h" #include "ostree-core-private.h" #include "ostree-sign.h" +#include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" +#include "otutil.h" static gboolean opt_delete; static gboolean opt_verify; @@ -42,16 +42,19 @@ static char *opt_keysdir; * man page (man/ostree-sign.xml) when changing the option list. */ -static GOptionEntry options[] = { - { "delete", 'd', 0, G_OPTION_ARG_NONE, &opt_delete, "Delete signatures having any of the KEY-IDs", NULL}, - { "verify", 0, 0, G_OPTION_ARG_NONE, &opt_verify, "Verify signatures", NULL}, - { "sign-type", 's', 0, G_OPTION_ARG_STRING, &opt_sign_name, "Signature type to use (defaults to 'ed25519')", "NAME"}, +static GOptionEntry options[] + = { { "delete", 'd', 0, G_OPTION_ARG_NONE, &opt_delete, + "Delete signatures having any of the KEY-IDs", NULL }, + { "verify", 0, 0, G_OPTION_ARG_NONE, &opt_verify, "Verify signatures", NULL }, + { "sign-type", 's', 0, G_OPTION_ARG_STRING, &opt_sign_name, + "Signature type to use (defaults to 'ed25519')", "NAME" }, #if defined(HAVE_LIBSODIUM) - { "keys-file", 0, 0, G_OPTION_ARG_STRING, &opt_filename, "Read key(s) from file", "NAME"}, - { "keys-dir", 0, 0, G_OPTION_ARG_STRING, &opt_keysdir, "Redefine system-wide directories with public and revoked keys for verification", "NAME"}, + { "keys-file", 0, 0, G_OPTION_ARG_STRING, &opt_filename, "Read key(s) from file", "NAME" }, + { "keys-dir", 0, 0, G_OPTION_ARG_STRING, &opt_keysdir, + "Redefine system-wide directories with public and revoked keys for verification", + "NAME" }, #endif - { NULL } -}; + { NULL } }; static void usage_error (GOptionContext *context, const char *message, GError **error) @@ -62,7 +65,8 @@ usage_error (GOptionContext *context, const char *message, GError **error) } gboolean -ostree_builtin_sign (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_sign (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { g_autoptr (GOptionContext) context = NULL; g_autoptr (OstreeRepo) repo = NULL; @@ -76,8 +80,8 @@ ostree_builtin_sign (int argc, char **argv, OstreeCommandInvocation *invocation, context = g_option_context_new ("COMMIT KEY-ID..."); - - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) goto out; if (argc < 2) @@ -89,9 +93,7 @@ ostree_builtin_sign (int argc, char **argv, OstreeCommandInvocation *invocation, commit = argv[1]; /* Verification could be done via system files with public keys */ - if (!opt_verify && - !opt_filename && - argc < 3) + if (!opt_verify && !opt_filename && argc < 3) { usage_error (context, "Need at least one KEY-ID to sign with", error); goto out; @@ -119,18 +121,13 @@ ostree_builtin_sign (int argc, char **argv, OstreeCommandInvocation *invocation, { g_autoptr (GError) local_error = NULL; - // Pass the key as a string - pk = g_variant_new_string(key_ids[ii]); + pk = g_variant_new_string (key_ids[ii]); if (!ostree_sign_set_pk (sign, pk, &local_error)) continue; - if (ostree_sign_commit_verify (sign, - repo, - resolved_commit, - &success_message, - cancellable, + if (ostree_sign_commit_verify (sign, repo, resolved_commit, &success_message, cancellable, &local_error)) { g_assert (success_message); @@ -142,18 +139,14 @@ ostree_builtin_sign (int argc, char **argv, OstreeCommandInvocation *invocation, else { // Pass the key as a string - sk = g_variant_new_string(key_ids[ii]); + sk = g_variant_new_string (key_ids[ii]); if (!ostree_sign_set_sk (sign, sk, error)) { ret = FALSE; goto out; } - ret = ostree_sign_commit (sign, - repo, - resolved_commit, - cancellable, - error); + ret = ostree_sign_commit (sign, repo, resolved_commit, cancellable, error); if (ret != TRUE) goto out; } @@ -168,22 +161,20 @@ ostree_builtin_sign (int argc, char **argv, OstreeCommandInvocation *invocation, g_autoptr (GVariant) sign_options = NULL; builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); - /* Use custom directory with public and revoked keys instead of system-wide directories */ + /* Use custom directory with public and revoked keys instead of system-wide directories + */ if (opt_keysdir) g_variant_builder_add (builder, "{sv}", "basedir", g_variant_new_string (opt_keysdir)); /* The last chance for verification source -- system files */ if (opt_filename) - g_variant_builder_add (builder, "{sv}", "filename", g_variant_new_string (opt_filename)); + g_variant_builder_add (builder, "{sv}", "filename", + g_variant_new_string (opt_filename)); sign_options = g_variant_builder_end (builder); if (!ostree_sign_load_pk (sign, sign_options, error)) goto out; - if (ostree_sign_commit_verify (sign, - repo, - resolved_commit, - &success_message, - cancellable, + if (ostree_sign_commit_verify (sign, repo, resolved_commit, &success_message, cancellable, error)) { g_print ("%s\n", success_message); @@ -213,14 +204,15 @@ ostree_builtin_sign (int argc, char **argv, OstreeCommandInvocation *invocation, if (key_stream_in == NULL) goto out; - key_data_in = g_data_input_stream_new (G_INPUT_STREAM(key_stream_in)); + key_data_in = g_data_input_stream_new (G_INPUT_STREAM (key_stream_in)); g_assert (key_data_in != NULL); /* Use simple file format with just a list of base64 public keys per line */ while (TRUE) { gsize len = 0; - g_autofree char *line = g_data_input_stream_read_line (key_data_in, &len, NULL, error); + g_autofree char *line + = g_data_input_stream_read_line (key_data_in, &len, NULL, error); g_autoptr (GVariant) sk = NULL; if (*error != NULL) @@ -229,20 +221,15 @@ ostree_builtin_sign (int argc, char **argv, OstreeCommandInvocation *invocation, if (line == NULL) break; - // Pass the key as a string - sk = g_variant_new_string(line); + sk = g_variant_new_string (line); if (!ostree_sign_set_sk (sign, sk, error)) { ret = FALSE; goto out; } - ret = ostree_sign_commit (sign, - repo, - resolved_commit, - cancellable, - error); + ret = ostree_sign_commit (sign, repo, resolved_commit, cancellable, error); if (ret != TRUE) goto out; } @@ -250,9 +237,7 @@ ostree_builtin_sign (int argc, char **argv, OstreeCommandInvocation *invocation, } // No valid signature found if (opt_verify && (ret != TRUE) && (*error == NULL)) - g_set_error_literal (error, - G_IO_ERROR, G_IO_ERROR_FAILED, - "No valid signatures found"); + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "No valid signatures found"); out: /* It is possible to have an error due multiple signatures check */ diff --git a/src/ostree/ot-builtin-static-delta.c b/src/ostree/ot-builtin-static-delta.c index a5483c17..a10040bd 100644 --- a/src/ostree/ot-builtin-static-delta.c +++ b/src/ostree/ot-builtin-static-delta.c @@ -19,10 +19,9 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" -#include "ostree.h" #include "ostree-cmd-private.h" +#include "ostree.h" +#include "ot-builtins.h" #include "ot-main.h" #include "otutil.h" @@ -43,43 +42,35 @@ static char *opt_sign_name; static char *opt_keysfilename; static char *opt_keysdir; -#define BUILTINPROTO(name) static gboolean ot_static_delta_builtin_ ## name (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +#define BUILTINPROTO(name) \ + static gboolean ot_static_delta_builtin_##name (int argc, char **argv, \ + OstreeCommandInvocation *invocation, \ + GCancellable *cancellable, GError **error) -BUILTINPROTO(list); -BUILTINPROTO(show); -BUILTINPROTO(delete); -BUILTINPROTO(generate); -BUILTINPROTO(apply_offline); -BUILTINPROTO(verify); -BUILTINPROTO(indexes); -BUILTINPROTO(reindex); +BUILTINPROTO (list); +BUILTINPROTO (show); +BUILTINPROTO (delete); +BUILTINPROTO (generate); +BUILTINPROTO (apply_offline); +BUILTINPROTO (verify); +BUILTINPROTO (indexes); +BUILTINPROTO (reindex); #undef BUILTINPROTO static OstreeCommand static_delta_subcommands[] = { - { "list", OSTREE_BUILTIN_FLAG_NONE, - ot_static_delta_builtin_list, - "List static delta files" }, - { "show", OSTREE_BUILTIN_FLAG_NONE, - ot_static_delta_builtin_show, - "Dump information on a delta" }, - { "delete", OSTREE_BUILTIN_FLAG_NONE, - ot_static_delta_builtin_delete, - "Remove a delta" }, - { "generate", OSTREE_BUILTIN_FLAG_NONE, - ot_static_delta_builtin_generate, + { "list", OSTREE_BUILTIN_FLAG_NONE, ot_static_delta_builtin_list, "List static delta files" }, + { "show", OSTREE_BUILTIN_FLAG_NONE, ot_static_delta_builtin_show, "Dump information on a delta" }, + { "delete", OSTREE_BUILTIN_FLAG_NONE, ot_static_delta_builtin_delete, "Remove a delta" }, + { "generate", OSTREE_BUILTIN_FLAG_NONE, ot_static_delta_builtin_generate, "Generate static delta files" }, - { "apply-offline", OSTREE_BUILTIN_FLAG_NONE, - ot_static_delta_builtin_apply_offline, + { "apply-offline", OSTREE_BUILTIN_FLAG_NONE, ot_static_delta_builtin_apply_offline, "Apply static delta file" }, - { "verify", OSTREE_BUILTIN_FLAG_NONE, - ot_static_delta_builtin_verify, + { "verify", OSTREE_BUILTIN_FLAG_NONE, ot_static_delta_builtin_verify, "Verify static delta signatures" }, - { "indexes", OSTREE_BUILTIN_FLAG_NONE, - ot_static_delta_builtin_indexes, + { "indexes", OSTREE_BUILTIN_FLAG_NONE, ot_static_delta_builtin_indexes, "List static delta indexes" }, - { "reindex", OSTREE_BUILTIN_FLAG_NONE, - ot_static_delta_builtin_reindex, + { "reindex", OSTREE_BUILTIN_FLAG_NONE, ot_static_delta_builtin_reindex, "Regenerate static delta indexes" }, { NULL, 0, NULL, NULL } }; @@ -95,55 +86,63 @@ static GOptionEntry generate_options[] = { { "inline", 0, 0, G_OPTION_ARG_NONE, &opt_inline, "Inline delta parts into main delta", NULL }, { "to", 0, 0, G_OPTION_ARG_STRING, &opt_to_rev, "Create delta to revision REV", "REV" }, { "disable-bsdiff", 0, 0, G_OPTION_ARG_NONE, &opt_disable_bsdiff, "Disable use of bsdiff", NULL }, - { "if-not-exists", 'n', 0, G_OPTION_ARG_NONE, &opt_if_not_exists, "Only generate if a delta does not already exist", NULL }, - { "set-endianness", 0, 0, G_OPTION_ARG_STRING, &opt_endianness, "Choose metadata endianness ('l' or 'B')", "ENDIAN" }, - { "swap-endianness", 0, 0, G_OPTION_ARG_NONE, &opt_swap_endianness, "Swap metadata endianness from host order", NULL }, - { "min-fallback-size", 0, 0, G_OPTION_ARG_STRING, &opt_min_fallback_size, "Minimum uncompressed size in megabytes for individual HTTP request", NULL}, - { "max-bsdiff-size", 0, 0, G_OPTION_ARG_STRING, &opt_max_bsdiff_size, "Maximum size in megabytes to consider bsdiff compression for input files", NULL}, - { "max-chunk-size", 0, 0, G_OPTION_ARG_STRING, &opt_max_chunk_size, "Maximum size of delta chunks in megabytes", NULL}, - { "filename", 0, 0, G_OPTION_ARG_FILENAME, &opt_filename, "Write the delta content to PATH (a directory). If not specified, the OSTree repository is used", "PATH"}, - { "sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_key_ids, "Sign the delta with", "KEY_ID"}, - { "sign-type", 0, 0, G_OPTION_ARG_STRING, &opt_sign_name, "Signature type to use (defaults to 'ed25519')", "NAME"}, + { "if-not-exists", 'n', 0, G_OPTION_ARG_NONE, &opt_if_not_exists, + "Only generate if a delta does not already exist", NULL }, + { "set-endianness", 0, 0, G_OPTION_ARG_STRING, &opt_endianness, + "Choose metadata endianness ('l' or 'B')", "ENDIAN" }, + { "swap-endianness", 0, 0, G_OPTION_ARG_NONE, &opt_swap_endianness, + "Swap metadata endianness from host order", NULL }, + { "min-fallback-size", 0, 0, G_OPTION_ARG_STRING, &opt_min_fallback_size, + "Minimum uncompressed size in megabytes for individual HTTP request", NULL }, + { "max-bsdiff-size", 0, 0, G_OPTION_ARG_STRING, &opt_max_bsdiff_size, + "Maximum size in megabytes to consider bsdiff compression for input files", NULL }, + { "max-chunk-size", 0, 0, G_OPTION_ARG_STRING, &opt_max_chunk_size, + "Maximum size of delta chunks in megabytes", NULL }, + { "filename", 0, 0, G_OPTION_ARG_FILENAME, &opt_filename, + "Write the delta content to PATH (a directory). If not specified, the OSTree repository is " + "used", + "PATH" }, + { "sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_key_ids, "Sign the delta with", "KEY_ID" }, + { "sign-type", 0, 0, G_OPTION_ARG_STRING, &opt_sign_name, + "Signature type to use (defaults to 'ed25519')", "NAME" }, #if defined(HAVE_LIBSODIUM) - { "keys-file", 0, 0, G_OPTION_ARG_STRING, &opt_keysfilename, "Read key(s) from file", "NAME"}, + { "keys-file", 0, 0, G_OPTION_ARG_STRING, &opt_keysfilename, "Read key(s) from file", "NAME" }, #endif { NULL } }; static GOptionEntry apply_offline_options[] = { - { "sign-type", 0, 0, G_OPTION_ARG_STRING, &opt_sign_name, "Signature type to use (defaults to 'ed25519')", "NAME"}, + { "sign-type", 0, 0, G_OPTION_ARG_STRING, &opt_sign_name, + "Signature type to use (defaults to 'ed25519')", "NAME" }, #if defined(HAVE_LIBSODIUM) - { "keys-file", 0, 0, G_OPTION_ARG_STRING, &opt_keysfilename, "Read key(s) from file", "NAME"}, - { "keys-dir", 0, 0, G_OPTION_ARG_STRING, &opt_keysdir, "Redefine system-wide directories with public and revoked keys for verification", "NAME"}, + { "keys-file", 0, 0, G_OPTION_ARG_STRING, &opt_keysfilename, "Read key(s) from file", "NAME" }, + { "keys-dir", 0, 0, G_OPTION_ARG_STRING, &opt_keysdir, + "Redefine system-wide directories with public and revoked keys for verification", "NAME" }, #endif { NULL } }; -static GOptionEntry list_options[] = { - { NULL } -}; +static GOptionEntry list_options[] = { { NULL } }; static GOptionEntry verify_options[] = { - { "sign-type", 0, 0, G_OPTION_ARG_STRING, &opt_sign_name, "Signature type to use (defaults to 'ed25519')", "NAME"}, + { "sign-type", 0, 0, G_OPTION_ARG_STRING, &opt_sign_name, + "Signature type to use (defaults to 'ed25519')", "NAME" }, #if defined(HAVE_LIBSODIUM) - { "keys-file", 0, 0, G_OPTION_ARG_STRING, &opt_keysfilename, "Read key(s) from file", "NAME"}, - { "keys-dir", 0, 0, G_OPTION_ARG_STRING, &opt_keysdir, "Redefine system-wide directories with public and revoked keys for verification", "NAME"}, + { "keys-file", 0, 0, G_OPTION_ARG_STRING, &opt_keysfilename, "Read key(s) from file", "NAME" }, + { "keys-dir", 0, 0, G_OPTION_ARG_STRING, &opt_keysdir, + "Redefine system-wide directories with public and revoked keys for verification", "NAME" }, #endif { NULL } }; -static GOptionEntry indexes_options[] = { - { NULL } -}; +static GOptionEntry indexes_options[] = { { NULL } }; -static GOptionEntry reindex_options[] = { - { "to", 0, 0, G_OPTION_ARG_STRING, &opt_to_rev, "Only update delta index to revision REV", "REV" }, - { NULL } -}; +static GOptionEntry reindex_options[] = { { "to", 0, 0, G_OPTION_ARG_STRING, &opt_to_rev, + "Only update delta index to revision REV", "REV" }, + { NULL } }; static void -static_delta_usage (char **argv, - gboolean is_error) +static_delta_usage (char **argv, gboolean is_error) { OstreeCommand *command = static_delta_subcommands; void (*print_func) (const gchar *format, ...); @@ -168,15 +167,16 @@ static_delta_usage (char **argv, } static gboolean -ot_static_delta_builtin_list (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_static_delta_builtin_list (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(OstreeRepo) repo = NULL; - g_autoptr(GOptionContext) context = g_option_context_new (""); - if (!ostree_option_context_parse (context, list_options, &argc, &argv, - invocation, &repo, cancellable, error)) + g_autoptr (OstreeRepo) repo = NULL; + g_autoptr (GOptionContext) context = g_option_context_new (""); + if (!ostree_option_context_parse (context, list_options, &argc, &argv, invocation, &repo, + cancellable, error)) return FALSE; - g_autoptr(GPtrArray) delta_names = NULL; + g_autoptr (GPtrArray) delta_names = NULL; if (!ostree_repo_list_static_delta_names (repo, &delta_names, cancellable, error)) return FALSE; @@ -185,22 +185,23 @@ ot_static_delta_builtin_list (int argc, char **argv, OstreeCommandInvocation *in else { for (guint i = 0; i < delta_names->len; i++) - g_print ("%s\n", (char*)delta_names->pdata[i]); + g_print ("%s\n", (char *)delta_names->pdata[i]); } return TRUE; } static gboolean -ot_static_delta_builtin_indexes (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_static_delta_builtin_indexes (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(OstreeRepo) repo = NULL; - g_autoptr(GOptionContext) context = g_option_context_new (""); - if (!ostree_option_context_parse (context, indexes_options, &argc, &argv, - invocation, &repo, cancellable, error)) + g_autoptr (OstreeRepo) repo = NULL; + g_autoptr (GOptionContext) context = g_option_context_new (""); + if (!ostree_option_context_parse (context, indexes_options, &argc, &argv, invocation, &repo, + cancellable, error)) return FALSE; - g_autoptr(GPtrArray) indexes = NULL; + g_autoptr (GPtrArray) indexes = NULL; if (!ostree_repo_list_static_delta_indexes (repo, &indexes, cancellable, error)) return FALSE; @@ -209,19 +210,21 @@ ot_static_delta_builtin_indexes (int argc, char **argv, OstreeCommandInvocation else { for (guint i = 0; i < indexes->len; i++) - g_print ("%s\n", (char*)indexes->pdata[i]); + g_print ("%s\n", (char *)indexes->pdata[i]); } return TRUE; } static gboolean -ot_static_delta_builtin_reindex (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_static_delta_builtin_reindex (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new (""); + g_autoptr (GOptionContext) context = g_option_context_new (""); - g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, reindex_options, &argc, &argv, invocation, &repo, cancellable, error)) + g_autoptr (OstreeRepo) repo = NULL; + if (!ostree_option_context_parse (context, reindex_options, &argc, &argv, invocation, &repo, + cancellable, error)) return FALSE; if (!ostree_repo_static_delta_reindex (repo, 0, opt_to_rev, cancellable, error)) @@ -230,21 +233,21 @@ ot_static_delta_builtin_reindex (int argc, char **argv, OstreeCommandInvocation return TRUE; } - static gboolean -ot_static_delta_builtin_show (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_static_delta_builtin_show (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new (""); + g_autoptr (GOptionContext) context = g_option_context_new (""); - g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, list_options, &argc, &argv, invocation, &repo, cancellable, error)) + g_autoptr (OstreeRepo) repo = NULL; + if (!ostree_option_context_parse (context, list_options, &argc, &argv, invocation, &repo, + cancellable, error)) return FALSE; if (argc < 3) { - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "DELTA must be specified"); + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "DELTA must be specified"); return FALSE; } @@ -257,18 +260,19 @@ ot_static_delta_builtin_show (int argc, char **argv, OstreeCommandInvocation *in } static gboolean -ot_static_delta_builtin_delete (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_static_delta_builtin_delete (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new (""); + g_autoptr (GOptionContext) context = g_option_context_new (""); - g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, list_options, &argc, &argv, invocation, &repo, cancellable, error)) + g_autoptr (OstreeRepo) repo = NULL; + if (!ostree_option_context_parse (context, list_options, &argc, &argv, invocation, &repo, + cancellable, error)) return FALSE; if (argc < 3) { - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "DELTA must be specified"); + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "DELTA must be specified"); return FALSE; } @@ -280,13 +284,14 @@ ot_static_delta_builtin_delete (int argc, char **argv, OstreeCommandInvocation * return TRUE; } - static gboolean -ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("[TO]"); - g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, generate_options, &argc, &argv, invocation, &repo, cancellable, error)) + g_autoptr (GOptionContext) context = g_option_context_new ("[TO]"); + g_autoptr (OstreeRepo) repo = NULL; + if (!ostree_option_context_parse (context, generate_options, &argc, &argv, invocation, &repo, + cancellable, error)) return FALSE; if (!ostree_ensure_repo_writable (repo, error)) @@ -297,8 +302,7 @@ ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation if (argc < 3 && opt_to_rev == NULL) { - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "TO revision must be specified"); + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "TO revision must be specified"); return FALSE; } else @@ -307,7 +311,7 @@ ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation g_autofree char *from_resolved = NULL; g_autofree char *to_resolved = NULL; g_autofree char *from_parent_str = NULL; - g_autoptr(GVariantBuilder) parambuilder = NULL; + g_autoptr (GVariantBuilder) parambuilder = NULL; int endianness; g_assert (opt_to_rev); @@ -343,8 +347,11 @@ ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation if (opt_if_not_exists) { gboolean does_exist; - g_autofree char *delta_id = from_resolved ? g_strconcat (from_resolved, "-", to_resolved, NULL) : g_strdup (to_resolved); - if (!ostree_cmd__private__ ()->ostree_static_delta_query_exists (repo, delta_id, &does_exist, cancellable, error)) + g_autofree char *delta_id = from_resolved + ? g_strconcat (from_resolved, "-", to_resolved, NULL) + : g_strdup (to_resolved); + if (!ostree_cmd__private__ ()->ostree_static_delta_query_exists ( + repo, delta_id, &does_exist, cancellable, error)) return FALSE; if (does_exist) { @@ -361,8 +368,8 @@ ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation endianness = G_BIG_ENDIAN; else { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Invalid endianness '%s'", opt_endianness); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid endianness '%s'", + opt_endianness); return FALSE; } } @@ -386,31 +393,34 @@ ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation parambuilder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); if (opt_min_fallback_size) - g_variant_builder_add (parambuilder, "{sv}", - "min-fallback-size", g_variant_new_uint32 (g_ascii_strtoull (opt_min_fallback_size, NULL, 10))); + g_variant_builder_add ( + parambuilder, "{sv}", "min-fallback-size", + g_variant_new_uint32 (g_ascii_strtoull (opt_min_fallback_size, NULL, 10))); if (opt_max_bsdiff_size) - g_variant_builder_add (parambuilder, "{sv}", - "max-bsdiff-size", g_variant_new_uint32 (g_ascii_strtoull (opt_max_bsdiff_size, NULL, 10))); + g_variant_builder_add ( + parambuilder, "{sv}", "max-bsdiff-size", + g_variant_new_uint32 (g_ascii_strtoull (opt_max_bsdiff_size, NULL, 10))); if (opt_max_chunk_size) - g_variant_builder_add (parambuilder, "{sv}", - "max-chunk-size", g_variant_new_uint32 (g_ascii_strtoull (opt_max_chunk_size, NULL, 10))); + g_variant_builder_add ( + parambuilder, "{sv}", "max-chunk-size", + g_variant_new_uint32 (g_ascii_strtoull (opt_max_chunk_size, NULL, 10))); if (opt_disable_bsdiff) - g_variant_builder_add (parambuilder, "{sv}", - "bsdiff-enabled", g_variant_new_boolean (FALSE)); + g_variant_builder_add (parambuilder, "{sv}", "bsdiff-enabled", + g_variant_new_boolean (FALSE)); if (opt_inline) - g_variant_builder_add (parambuilder, "{sv}", - "inline-parts", g_variant_new_boolean (TRUE)); + g_variant_builder_add (parambuilder, "{sv}", "inline-parts", g_variant_new_boolean (TRUE)); if (opt_filename) - g_variant_builder_add (parambuilder, "{sv}", - "filename", g_variant_new_bytestring (opt_filename)); + g_variant_builder_add (parambuilder, "{sv}", "filename", + g_variant_new_bytestring (opt_filename)); g_variant_builder_add (parambuilder, "{sv}", "verbose", g_variant_new_boolean (TRUE)); if (opt_endianness || opt_swap_endianness) - g_variant_builder_add (parambuilder, "{sv}", "endianness", g_variant_new_uint32 (endianness)); + g_variant_builder_add (parambuilder, "{sv}", "endianness", + g_variant_new_uint32 (endianness)); if (opt_key_ids || opt_keysfilename) { - g_autoptr(GPtrArray) key_ids = g_ptr_array_new (); + g_autoptr (GPtrArray) key_ids = g_ptr_array_new (); for (char **iter = opt_key_ids; iter != NULL && *iter != NULL; ++iter) g_ptr_array_add (key_ids, *iter); @@ -424,7 +434,8 @@ ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation if (!g_file_test (opt_keysfilename, G_FILE_TEST_IS_REGULAR)) { g_warning ("Can't open file '%s' with keys", opt_keysfilename); - return glnx_throw (error, "File object '%s' is not a regular file", opt_keysfilename); + return glnx_throw (error, "File object '%s' is not a regular file", + opt_keysfilename); } keyfile = g_file_new_for_path (opt_keysfilename); @@ -432,14 +443,15 @@ ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation if (key_stream_in == NULL) return FALSE; - key_data_in = g_data_input_stream_new (G_INPUT_STREAM(key_stream_in)); + key_data_in = g_data_input_stream_new (G_INPUT_STREAM (key_stream_in)); g_assert (key_data_in != NULL); /* Use simple file format with just a list of base64 public keys per line */ while (TRUE) { gsize len = 0; - g_autofree char *line = g_data_input_stream_read_line (key_data_in, &len, NULL, error); + g_autofree char *line + = g_data_input_stream_read_line (key_data_in, &len, NULL, error); g_autoptr (GVariant) sk = NULL; if (*error != NULL) @@ -453,8 +465,8 @@ ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation } } - g_autoptr(GVariant) key_ids_v = g_variant_new_strv ((const char *const *)key_ids->pdata, - key_ids->len); + g_autoptr (GVariant) key_ids_v + = g_variant_new_strv ((const char *const *)key_ids->pdata, key_ids->len); g_variant_builder_add (parambuilder, "{s@v}", "sign-key-ids", g_variant_new_variant (g_steal_pointer (&key_ids_v))); } @@ -465,30 +477,31 @@ ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation g_print ("Generating static delta:\n"); g_print (" From: %s\n", from_resolved ? from_resolved : "empty"); g_print (" To: %s\n", to_resolved); - { g_autoptr(GVariant) params = g_variant_ref_sink (g_variant_builder_end (parambuilder)); + { + g_autoptr (GVariant) params = g_variant_ref_sink (g_variant_builder_end (parambuilder)); if (!ostree_repo_static_delta_generate (repo, OSTREE_STATIC_DELTA_GENERATE_OPT_MAJOR, - from_resolved, to_resolved, NULL, - params, + from_resolved, to_resolved, NULL, params, cancellable, error)) return FALSE; } - } return TRUE; } static gboolean -ot_static_delta_builtin_apply_offline (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_static_delta_builtin_apply_offline (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeRepo) repo = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeRepo) repo = NULL; g_autoptr (OstreeSign) sign = NULL; char **key_ids; int n_key_ids; context = g_option_context_new (""); - if (!ostree_option_context_parse (context, apply_offline_options, &argc, &argv, invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, apply_offline_options, &argc, &argv, invocation, &repo, + cancellable, error)) return FALSE; if (!ostree_ensure_repo_writable (repo, error)) @@ -496,8 +509,7 @@ ot_static_delta_builtin_apply_offline (int argc, char **argv, OstreeCommandInvoc if (argc < 3) { - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "PATH must be specified"); + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "PATH must be specified"); return FALSE; } @@ -516,8 +528,8 @@ ot_static_delta_builtin_apply_offline (int argc, char **argv, OstreeCommandInvoc n_key_ids = argc - 3; for (int i = 0; i < n_key_ids; i++) { - g_autoptr (GVariant) pk = g_variant_new_string(key_ids[i]); - if (!ostree_sign_add_pk(sign, pk, error)) + g_autoptr (GVariant) pk = g_variant_new_string (key_ids[i]); + if (!ostree_sign_add_pk (sign, pk, error)) return FALSE; } if ((n_key_ids == 0) || opt_keysfilename) @@ -525,21 +537,24 @@ ot_static_delta_builtin_apply_offline (int argc, char **argv, OstreeCommandInvoc g_autoptr (GVariantBuilder) builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); g_autoptr (GVariant) options = NULL; - /* Use custom directory with public and revoked keys instead of system-wide directories */ + /* Use custom directory with public and revoked keys instead of system-wide directories + */ if (opt_keysdir) g_variant_builder_add (builder, "{sv}", "basedir", g_variant_new_string (opt_keysdir)); /* The last chance for verification source -- system files */ if (opt_keysfilename) - g_variant_builder_add (builder, "{sv}", "filename", g_variant_new_string (opt_keysfilename)); + g_variant_builder_add (builder, "{sv}", "filename", + g_variant_new_string (opt_keysfilename)); options = g_variant_builder_end (builder); if (!ostree_sign_load_pk (sign, options, error)) { - /* If it fails to load system default public keys, consider there no signature engine */ + /* If it fails to load system default public keys, consider there no signature engine + */ if (!opt_keysdir && !opt_keysfilename) { - g_clear_error(error); - g_clear_object(&sign); + g_clear_error (error); + g_clear_object (&sign); } else return FALSE; @@ -548,12 +563,13 @@ ot_static_delta_builtin_apply_offline (int argc, char **argv, OstreeCommandInvoc } const char *patharg = argv[2]; - g_autoptr(GFile) path = g_file_new_for_path (patharg); + g_autoptr (GFile) path = g_file_new_for_path (patharg); if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error)) return FALSE; - if (!ostree_repo_static_delta_execute_offline_with_signature (repo, path, sign, FALSE, cancellable, error)) + if (!ostree_repo_static_delta_execute_offline_with_signature (repo, path, sign, FALSE, + cancellable, error)) return FALSE; if (!ostree_repo_commit_transaction (repo, NULL, cancellable, error)) @@ -563,7 +579,8 @@ ot_static_delta_builtin_apply_offline (int argc, char **argv, OstreeCommandInvoc } static gboolean -ot_static_delta_builtin_verify (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_static_delta_builtin_verify (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { g_autoptr (GOptionContext) context = g_option_context_new ("STATIC-DELTA-FILE [KEY-ID...]"); g_autoptr (OstreeRepo) repo = NULL; @@ -571,13 +588,13 @@ ot_static_delta_builtin_verify (int argc, char **argv, OstreeCommandInvocation * char **key_ids; int n_key_ids; - if (!ostree_option_context_parse (context, verify_options, &argc, &argv, invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, verify_options, &argc, &argv, invocation, &repo, + cancellable, error)) return FALSE; if (argc < 3) { - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "DELTA must be specified"); + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "DELTA must be specified"); return FALSE; } @@ -588,7 +605,7 @@ ot_static_delta_builtin_verify (int argc, char **argv, OstreeCommandInvocation * g_autoptr (OstreeSign) sign = ostree_sign_get_by_name (opt_sign_name, error); if (!sign) { - g_print("Sign-type not supported\n"); + g_print ("Sign-type not supported\n"); return FALSE; } @@ -596,8 +613,8 @@ ot_static_delta_builtin_verify (int argc, char **argv, OstreeCommandInvocation * n_key_ids = argc - 3; for (int i = 0; i < n_key_ids; i++) { - g_autoptr (GVariant) pk = g_variant_new_string(key_ids[i]); - if (!ostree_sign_add_pk(sign, pk, error)) + g_autoptr (GVariant) pk = g_variant_new_string (key_ids[i]); + if (!ostree_sign_add_pk (sign, pk, error)) return FALSE; } if ((n_key_ids == 0) || opt_keysfilename) @@ -611,7 +628,8 @@ ot_static_delta_builtin_verify (int argc, char **argv, OstreeCommandInvocation * g_variant_builder_add (builder, "{sv}", "basedir", g_variant_new_string (opt_keysdir)); /* The last chance for verification source -- system files */ if (opt_keysfilename) - g_variant_builder_add (builder, "{sv}", "filename", g_variant_new_string (opt_keysfilename)); + g_variant_builder_add (builder, "{sv}", "filename", + g_variant_new_string (opt_keysfilename)); options = g_variant_builder_end (builder); if (!ostree_sign_load_pk (sign, options, error)) @@ -625,7 +643,8 @@ ot_static_delta_builtin_verify (int argc, char **argv, OstreeCommandInvocation * } gboolean -ostree_builtin_static_delta (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_static_delta (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { gboolean want_help = FALSE; const char *cmdname = NULL; diff --git a/src/ostree/ot-builtin-summary.c b/src/ostree/ot-builtin-summary.c index b0a2a6ed..df980df8 100644 --- a/src/ostree/ot-builtin-summary.c +++ b/src/ostree/ot-builtin-summary.c @@ -20,12 +20,12 @@ #include "config.h" #include "ostree-repo-private.h" +#include "ostree-sign.h" +#include "ostree.h" +#include "ot-builtins.h" #include "ot-dump.h" #include "ot-main.h" -#include "ot-builtins.h" -#include "ostree.h" #include "otutil.h" -#include "ostree-sign.h" static gboolean opt_update, opt_view, opt_raw; static gboolean opt_list_metadata_keys; @@ -41,27 +41,33 @@ static char **opt_metadata; * man page (man/ostree-summary.xml) when changing the option list. */ -static GOptionEntry options[] = { - { "update", 'u', 0, G_OPTION_ARG_NONE, &opt_update, "Update the summary", NULL }, - { "view", 'v', 0, G_OPTION_ARG_NONE, &opt_view, "View the local summary file", NULL }, - { "raw", 0, 0, G_OPTION_ARG_NONE, &opt_raw, "View the raw bytes of the summary file", NULL }, - { "list-metadata-keys", 0, 0, G_OPTION_ARG_NONE, &opt_list_metadata_keys, "List the available metadata keys", NULL }, - { "print-metadata-key", 0, 0, G_OPTION_ARG_STRING, &opt_print_metadata_key, "Print string value of metadata key", "KEY" }, - { "gpg-sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_gpg_key_ids, "GPG Key ID to sign the summary with", "KEY-ID"}, - { "gpg-homedir", 0, 0, G_OPTION_ARG_FILENAME, &opt_gpg_homedir, "GPG Homedir to use when looking for keyrings", "HOMEDIR"}, - { "sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_key_ids, "Key ID to sign the summary with", "KEY-ID"}, - { "sign-type", 0, 0, G_OPTION_ARG_STRING, &opt_sign_name, "Signature type to use (defaults to 'ed25519')", "NAME"}, - { "add-metadata", 'm', 0, G_OPTION_ARG_STRING_ARRAY, &opt_metadata, "Additional metadata field to add to the summary", "KEY=VALUE" }, - { NULL } -}; +static GOptionEntry options[] + = { { "update", 'u', 0, G_OPTION_ARG_NONE, &opt_update, "Update the summary", NULL }, + { "view", 'v', 0, G_OPTION_ARG_NONE, &opt_view, "View the local summary file", NULL }, + { "raw", 0, 0, G_OPTION_ARG_NONE, &opt_raw, "View the raw bytes of the summary file", + NULL }, + { "list-metadata-keys", 0, 0, G_OPTION_ARG_NONE, &opt_list_metadata_keys, + "List the available metadata keys", NULL }, + { "print-metadata-key", 0, 0, G_OPTION_ARG_STRING, &opt_print_metadata_key, + "Print string value of metadata key", "KEY" }, + { "gpg-sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_gpg_key_ids, + "GPG Key ID to sign the summary with", "KEY-ID" }, + { "gpg-homedir", 0, 0, G_OPTION_ARG_FILENAME, &opt_gpg_homedir, + "GPG Homedir to use when looking for keyrings", "HOMEDIR" }, + { "sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_key_ids, "Key ID to sign the summary with", + "KEY-ID" }, + { "sign-type", 0, 0, G_OPTION_ARG_STRING, &opt_sign_name, + "Signature type to use (defaults to 'ed25519')", "NAME" }, + { "add-metadata", 'm', 0, G_OPTION_ARG_STRING_ARRAY, &opt_metadata, + "Additional metadata field to add to the summary", "KEY=VALUE" }, + { NULL } }; /* Take arguments of the form KEY=VALUE and put them into an a{sv} variant. The * value arguments must be parsable using g_variant_parse(). */ static GVariant * -build_additional_metadata (const char * const *args, - GError **error) +build_additional_metadata (const char *const *args, GError **error) { - g_autoptr(GVariantBuilder) builder = NULL; + g_autoptr (GVariantBuilder) builder = NULL; builder = g_variant_builder_new (G_VARIANT_TYPE_VARDICT); @@ -70,11 +76,10 @@ build_additional_metadata (const char * const *args, const gchar *equals = strchr (args[i], '='); g_autofree gchar *key = NULL; const gchar *value_str; - g_autoptr(GVariant) value = NULL; + g_autoptr (GVariant) value = NULL; if (equals == NULL) - return glnx_null_throw (error, - "Missing '=' in KEY=VALUE metadata '%s'", args[i]); + return glnx_null_throw (error, "Missing '=' in KEY=VALUE metadata '%s'", args[i]); key = g_strndup (args[i], equals - args[i]); value_str = equals + 1; @@ -90,13 +95,11 @@ build_additional_metadata (const char * const *args, } static gboolean -get_summary_data (OstreeRepo *repo, - GBytes **out_summary_data, - GError **error) +get_summary_data (OstreeRepo *repo, GBytes **out_summary_data, GError **error) { g_assert (out_summary_data != NULL); - g_autoptr(GBytes) summary_data = NULL; + g_autoptr (GBytes) summary_data = NULL; glnx_autofd int fd = -1; if (!glnx_openat_rdonly (repo->repo_dir_fd, "summary", TRUE, &fd, error)) return FALSE; @@ -110,16 +113,18 @@ get_summary_data (OstreeRepo *repo, } gboolean -ostree_builtin_summary (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_summary (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeRepo) repo = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeRepo) repo = NULL; g_autoptr (OstreeSign) sign = NULL; OstreeDumpFlags flags = OSTREE_DUMP_NONE; context = g_option_context_new (""); - if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, + error)) return FALSE; /* Initialize crypto system */ @@ -134,34 +139,36 @@ ostree_builtin_summary (int argc, char **argv, OstreeCommandInvocation *invocati if (opt_update) { - g_autoptr(GVariant) additional_metadata = NULL; + g_autoptr (GVariant) additional_metadata = NULL; if (!ostree_ensure_repo_writable (repo, error)) return FALSE; if (opt_metadata != NULL) { - additional_metadata = build_additional_metadata ((const char * const *) opt_metadata, error); + additional_metadata + = build_additional_metadata ((const char *const *)opt_metadata, error); if (additional_metadata == NULL) return FALSE; } /* Regenerate and sign the repo metadata. */ - g_auto(GVariantBuilder) metadata_opts_builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT); - g_autoptr(GVariant) metadata_opts = NULL; + g_auto (GVariantBuilder) metadata_opts_builder + = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_VARDICT); + g_autoptr (GVariant) metadata_opts = NULL; if (opt_gpg_key_ids != NULL) g_variant_builder_add (&metadata_opts_builder, "{sv}", "gpg-key-ids", - g_variant_new_strv ((const char * const *) opt_gpg_key_ids, -1)); + g_variant_new_strv ((const char *const *)opt_gpg_key_ids, -1)); if (opt_gpg_homedir != NULL) g_variant_builder_add (&metadata_opts_builder, "{sv}", "gpg-homedir", g_variant_new_string (opt_gpg_homedir)); if (opt_key_ids != NULL) { - g_auto(GVariantBuilder) sk_builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_ARRAY); + g_auto (GVariantBuilder) sk_builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE_ARRAY); /* Currently only strings are used as keys for supported * signature types. */ - for (const char * const *iter = (const char * const *) opt_key_ids; + for (const char *const *iter = (const char *const *)opt_key_ids; iter != NULL && *iter != NULL; iter++) { const char *key_id = *iter; @@ -176,13 +183,13 @@ ostree_builtin_summary (int argc, char **argv, OstreeCommandInvocation *invocati g_variant_new_string (opt_sign_name)); metadata_opts = g_variant_ref_sink (g_variant_builder_end (&metadata_opts_builder)); - if (!ostree_repo_regenerate_metadata (repo, additional_metadata, metadata_opts, - cancellable, error)) + if (!ostree_repo_regenerate_metadata (repo, additional_metadata, metadata_opts, cancellable, + error)) return FALSE; } else if (opt_view || opt_raw) { - g_autoptr(GBytes) summary_data = NULL; + g_autoptr (GBytes) summary_data = NULL; if (opt_raw) flags |= OSTREE_DUMP_RAW; @@ -194,7 +201,7 @@ ostree_builtin_summary (int argc, char **argv, OstreeCommandInvocation *invocati } else if (opt_list_metadata_keys) { - g_autoptr(GBytes) summary_data = NULL; + g_autoptr (GBytes) summary_data = NULL; if (!get_summary_data (repo, &summary_data, error)) return FALSE; @@ -203,7 +210,7 @@ ostree_builtin_summary (int argc, char **argv, OstreeCommandInvocation *invocati } else if (opt_print_metadata_key) { - g_autoptr(GBytes) summary_data = NULL; + g_autoptr (GBytes) summary_data = NULL; if (!get_summary_data (repo, &summary_data, error)) return FALSE; diff --git a/src/ostree/ot-builtin-trivial-httpd.c b/src/ostree/ot-builtin-trivial-httpd.c index 71c286b3..b5e84007 100644 --- a/src/ostree/ot-builtin-trivial-httpd.c +++ b/src/ostree/ot-builtin-trivial-httpd.c @@ -19,21 +19,22 @@ #include "config.h" -#include "ot-main.h" -#include "ot-builtins.h" #include "ostree.h" +#include "ot-builtins.h" +#include "ot-main.h" #include "otutil.h" gboolean -ostree_builtin_trivial_httpd (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ostree_builtin_trivial_httpd (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GPtrArray) new_argv = g_ptr_array_new (); + g_autoptr (GPtrArray) new_argv = g_ptr_array_new (); g_ptr_array_add (new_argv, PKGLIBEXECDIR "/ostree-trivial-httpd"); for (int i = 1; i < argc; i++) g_ptr_array_add (new_argv, argv[i]); g_ptr_array_add (new_argv, NULL); - execvp (new_argv->pdata[0], (char**)new_argv->pdata); + execvp (new_argv->pdata[0], (char **)new_argv->pdata); /* Fall through on error */ glnx_set_error_from_errno (error); return FALSE; diff --git a/src/ostree/ot-builtins.h b/src/ostree/ot-builtins.h index 63b1ea38..4d15b7a2 100644 --- a/src/ostree/ot-builtins.h +++ b/src/ostree/ot-builtins.h @@ -28,38 +28,40 @@ G_BEGIN_DECLS -#define BUILTINPROTO(name) gboolean ostree_builtin_ ## name (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +#define BUILTINPROTO(name) \ + gboolean ostree_builtin_##name (int argc, char **argv, OstreeCommandInvocation *invocation, \ + GCancellable *cancellable, GError **error) -BUILTINPROTO(admin); -BUILTINPROTO(cat); -BUILTINPROTO(config); -BUILTINPROTO(checkout); -BUILTINPROTO(checksum); -BUILTINPROTO(commit); -BUILTINPROTO(diff); -BUILTINPROTO(export); -BUILTINPROTO(find_remotes); -BUILTINPROTO(create_usb); +BUILTINPROTO (admin); +BUILTINPROTO (cat); +BUILTINPROTO (config); +BUILTINPROTO (checkout); +BUILTINPROTO (checksum); +BUILTINPROTO (commit); +BUILTINPROTO (diff); +BUILTINPROTO (export); +BUILTINPROTO (find_remotes); +BUILTINPROTO (create_usb); #ifndef OSTREE_DISABLE_GPGME -BUILTINPROTO(gpg_sign); +BUILTINPROTO (gpg_sign); #endif -BUILTINPROTO(init); -BUILTINPROTO(log); -BUILTINPROTO(pull); -BUILTINPROTO(pull_local); -BUILTINPROTO(ls); -BUILTINPROTO(prune); -BUILTINPROTO(refs); -BUILTINPROTO(reset); -BUILTINPROTO(fsck); -BUILTINPROTO(sign); -BUILTINPROTO(show); -BUILTINPROTO(static_delta); -BUILTINPROTO(summary); -BUILTINPROTO(rev_parse); -BUILTINPROTO(remote); -BUILTINPROTO(write_refs); -BUILTINPROTO(trivial_httpd); +BUILTINPROTO (init); +BUILTINPROTO (log); +BUILTINPROTO (pull); +BUILTINPROTO (pull_local); +BUILTINPROTO (ls); +BUILTINPROTO (prune); +BUILTINPROTO (refs); +BUILTINPROTO (reset); +BUILTINPROTO (fsck); +BUILTINPROTO (sign); +BUILTINPROTO (show); +BUILTINPROTO (static_delta); +BUILTINPROTO (summary); +BUILTINPROTO (rev_parse); +BUILTINPROTO (remote); +BUILTINPROTO (write_refs); +BUILTINPROTO (trivial_httpd); #undef BUILTINPROTO diff --git a/src/ostree/ot-dump.c b/src/ostree/ot-dump.c index 4cfac811..2ff2fe2e 100644 --- a/src/ostree/ot-dump.c +++ b/src/ostree/ot-dump.c @@ -27,15 +27,15 @@ #include "ostree-repo-private.h" #include "ostree-repo-static-delta-private.h" +#include "ot-admin-functions.h" #include "ot-dump.h" #include "otutil.h" -#include "ot-admin-functions.h" void ot_dump_variant (GVariant *variant) { g_autofree char *formatted_variant = NULL; - g_autoptr(GVariant) byteswapped = NULL; + g_autoptr (GVariant) byteswapped = NULL; if (G_BYTE_ORDER != G_BIG_ENDIAN) { @@ -50,9 +50,7 @@ ot_dump_variant (GVariant *variant) } static gchar * -format_timestamp (guint64 timestamp, - gboolean local_tz, - GError **error) +format_timestamp (guint64 timestamp, gboolean local_tz, GError **error) { GDateTime *dt; gchar *str; @@ -70,7 +68,7 @@ format_timestamp (guint64 timestamp, /* Convert to local time and display in the locale's preferred * representation. */ - g_autoptr(GDateTime) dt_local = g_date_time_to_local (dt); + g_autoptr (GDateTime) dt_local = g_date_time_to_local (dt); str = g_date_time_format (dt_local, "%c"); } else @@ -86,8 +84,8 @@ format_timestamp (guint64 timestamp, static gchar * uint64_secs_to_iso8601 (guint64 secs) { - g_autoptr(GDateTime) dt = g_date_time_new_from_unix_utc (secs); - g_autoptr(GDateTime) local = (dt != NULL) ? g_date_time_to_local (dt) : NULL; + g_autoptr (GDateTime) dt = g_date_time_new_from_unix_utc (secs); + g_autoptr (GDateTime) local = (dt != NULL) ? g_date_time_to_local (dt) : NULL; if (local != NULL) return g_date_time_format (local, "%FT%T%:::z"); @@ -98,7 +96,7 @@ uint64_secs_to_iso8601 (guint64 secs) static void dump_indented_lines (const gchar *data) { - const char* indent = " "; + const char *indent = " "; const gchar *pos; for (;;) @@ -119,8 +117,7 @@ dump_indented_lines (const gchar *data) } static void -dump_commit (GVariant *variant, - OstreeDumpFlags flags) +dump_commit (GVariant *variant, OstreeDumpFlags flags) { const gchar *subject; const gchar *body; @@ -128,11 +125,11 @@ dump_commit (GVariant *variant, g_autofree char *parent = NULL; g_autofree char *str = NULL; g_autofree char *version = NULL; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; /* See OSTREE_COMMIT_GVARIANT_FORMAT */ - g_variant_get (variant, "(a{sv}aya(say)&s&stayay)", NULL, NULL, NULL, - &subject, &body, ×tamp, NULL, NULL); + g_variant_get (variant, "(a{sv}aya(say)&s&stayay)", NULL, NULL, NULL, &subject, &body, ×tamp, + NULL, NULL); timestamp = GUINT64_FROM_BE (timestamp); str = format_timestamp (timestamp, FALSE, &local_error); @@ -142,7 +139,7 @@ dump_commit (GVariant *variant, errx (1, "Failed to read commit: %s", local_error->message); } - if ((parent = ostree_commit_get_parent(variant))) + if ((parent = ostree_commit_get_parent (variant))) { g_print ("Parent: %s\n", parent); } @@ -175,10 +172,8 @@ dump_commit (GVariant *variant, } void -ot_dump_object (OstreeObjectType objtype, - const char *checksum, - GVariant *variant, - OstreeDumpFlags flags) +ot_dump_object (OstreeObjectType objtype, const char *checksum, GVariant *variant, + OstreeDumpFlags flags) { g_print ("%s %s\n", ostree_object_type_to_string (objtype), checksum); @@ -194,22 +189,19 @@ ot_dump_object (OstreeObjectType objtype, } switch (objtype) - { + { case OSTREE_OBJECT_TYPE_COMMIT: dump_commit (variant, flags); break; /* TODO: Others could be implemented here */ default: break; - } + } } static void -dump_summary_ref (const char *collection_id, - const char *ref_name, - guint64 commit_size, - GVariant *csum_v, - GVariantIter *metadata) +dump_summary_ref (const char *collection_id, const char *ref_name, guint64 commit_size, + GVariant *csum_v, GVariantIter *metadata) { const guchar *csum_bytes; GError *csum_error = NULL; @@ -228,7 +220,7 @@ dump_summary_ref (const char *collection_id, csum_bytes = ostree_checksum_bytes_peek_validate (csum_v, &csum_error); if (csum_error == NULL) { - char csum[OSTREE_SHA256_STRING_LEN+1]; + char csum[OSTREE_SHA256_STRING_LEN + 1]; ostree_checksum_inplace_from_bytes (csum_bytes, csum); g_print (" %s\n", csum); @@ -268,8 +260,7 @@ dump_summary_ref (const char *collection_id, } static void -dump_summary_refs (const gchar *collection_id, - GVariant *refs) +dump_summary_refs (const gchar *collection_id, GVariant *refs) { GVariantIter iter; GVariant *value; @@ -284,12 +275,11 @@ dump_summary_refs (const gchar *collection_id, if (ref_name != NULL) { - g_autoptr(GVariant) csum_v = NULL; - g_autoptr(GVariantIter) metadata = NULL; + g_autoptr (GVariant) csum_v = NULL; + g_autoptr (GVariantIter) metadata = NULL; guint64 commit_size; - g_variant_get_child (value, 1, "(t@aya{sv})", - &commit_size, &csum_v, &metadata); + g_variant_get_child (value, 1, "(t@aya{sv})", &commit_size, &csum_v, &metadata); dump_summary_ref (collection_id, ref_name, commit_size, csum_v, metadata); @@ -301,20 +291,18 @@ dump_summary_refs (const gchar *collection_id, } void -ot_dump_summary_bytes (GBytes *summary_bytes, - OstreeDumpFlags flags) +ot_dump_summary_bytes (GBytes *summary_bytes, OstreeDumpFlags flags) { - g_autoptr(GVariant) summary = NULL; - g_autoptr(GVariant) refs = NULL; - g_autoptr(GVariant) exts = NULL; + g_autoptr (GVariant) summary = NULL; + g_autoptr (GVariant) refs = NULL; + g_autoptr (GVariant) exts = NULL; GVariantIter iter; GVariant *value; char *key; g_return_if_fail (summary_bytes != NULL); - summary = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, - summary_bytes, FALSE); + summary = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, summary_bytes, FALSE); if (flags & OSTREE_DUMP_RAW) { @@ -327,7 +315,7 @@ ot_dump_summary_bytes (GBytes *summary_bytes, /* Print the refs, including those with a collection ID specified. */ const gchar *main_collection_id; - g_autoptr(GVariant) collection_map = NULL; + g_autoptr (GVariant) collection_map = NULL; const gchar *collection_id; if (!g_variant_lookup (exts, OSTREE_SUMMARY_COLLECTION_ID, "&s", &main_collection_id)) @@ -335,10 +323,11 @@ ot_dump_summary_bytes (GBytes *summary_bytes, dump_summary_refs (main_collection_id, refs); - collection_map = g_variant_lookup_value (exts, OSTREE_SUMMARY_COLLECTION_MAP, G_VARIANT_TYPE ("a{sa(s(taya{sv}))}")); + collection_map = g_variant_lookup_value (exts, OSTREE_SUMMARY_COLLECTION_MAP, + G_VARIANT_TYPE ("a{sa(s(taya{sv}))}")); if (collection_map != NULL) { - g_autoptr(GVariant) collection_refs = NULL; + g_autoptr (GVariant) collection_refs = NULL; g_variant_iter_init (&iter, collection_map); while (g_variant_iter_loop (&iter, "{&s@a(s(taya{sv}))}", &collection_id, &collection_refs)) @@ -408,11 +397,10 @@ ot_dump_summary_bytes (GBytes *summary_bytes, } static gint -strptr_cmp (gconstpointer a, - gconstpointer b) +strptr_cmp (gconstpointer a, gconstpointer b) { - const char *a_str = *((const char **) a); - const char *b_str = *((const char **) b); + const char *a_str = *((const char **)a); + const char *b_str = *((const char **)b); return g_strcmp0 (a_str, b_str); } @@ -420,22 +408,21 @@ strptr_cmp (gconstpointer a, void ot_dump_summary_metadata_keys (GBytes *summary_bytes) { - g_autoptr(GVariant) summary = NULL; - g_autoptr(GVariant) metadata = NULL; + g_autoptr (GVariant) summary = NULL; + g_autoptr (GVariant) metadata = NULL; - summary = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, - summary_bytes, FALSE); + summary = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, summary_bytes, FALSE); metadata = g_variant_get_child_value (summary, 1); GVariantIter iter; const char *key = NULL; - g_autoptr(GPtrArray) keys = g_ptr_array_new (); + g_autoptr (GPtrArray) keys = g_ptr_array_new (); g_variant_iter_init (&iter, metadata); while (g_variant_iter_loop (&iter, "{&s@v}", &key, NULL)) - g_ptr_array_add (keys, (gpointer) key); + g_ptr_array_add (keys, (gpointer)key); g_ptr_array_sort (keys, strptr_cmp); - for (guint i = 0; i < keys-> len; i++) + for (guint i = 0; i < keys->len; i++) { key = keys->pdata[i]; g_print ("%s\n", key); @@ -443,22 +430,18 @@ ot_dump_summary_metadata_keys (GBytes *summary_bytes) } gboolean -ot_dump_summary_metadata_key (GBytes *summary_bytes, - const char *key, - GError **error) +ot_dump_summary_metadata_key (GBytes *summary_bytes, const char *key, GError **error) { - g_autoptr(GVariant) summary = NULL; - g_autoptr(GVariant) metadata = NULL; - g_autoptr(GVariant) value = NULL; + g_autoptr (GVariant) summary = NULL; + g_autoptr (GVariant) metadata = NULL; + g_autoptr (GVariant) value = NULL; - summary = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, - summary_bytes, FALSE); + summary = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, summary_bytes, FALSE); metadata = g_variant_get_child_value (summary, 1); value = g_variant_lookup_value (metadata, key, NULL); if (!value) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "No such metadata key '%s'", key); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "No such metadata key '%s'", key); return FALSE; } @@ -468,9 +451,7 @@ ot_dump_summary_metadata_key (GBytes *summary_bytes, } static gboolean -dump_gpg_subkey (GVariant *subkey, - gboolean primary, - GError **error) +dump_gpg_subkey (GVariant *subkey, gboolean primary, GError **error) { const gchar *fingerprint = NULL; gint64 created = 0; @@ -478,64 +459,53 @@ dump_gpg_subkey (GVariant *subkey, gboolean revoked = FALSE; gboolean expired = FALSE; gboolean invalid = FALSE; - (void) g_variant_lookup (subkey, "fingerprint", "&s", &fingerprint); - (void) g_variant_lookup (subkey, "created", "x", &created); - (void) g_variant_lookup (subkey, "expires", "x", &expires); - (void) g_variant_lookup (subkey, "revoked", "b", &revoked); - (void) g_variant_lookup (subkey, "expired", "b", &expired); - (void) g_variant_lookup (subkey, "invalid", "b", &invalid); + (void)g_variant_lookup (subkey, "fingerprint", "&s", &fingerprint); + (void)g_variant_lookup (subkey, "created", "x", &created); + (void)g_variant_lookup (subkey, "expires", "x", &expires); + (void)g_variant_lookup (subkey, "revoked", "b", &revoked); + (void)g_variant_lookup (subkey, "expired", "b", &expired); + (void)g_variant_lookup (subkey, "invalid", "b", &invalid); /* Convert timestamps from big endian if needed */ created = GINT64_FROM_BE (created); expires = GINT64_FROM_BE (expires); - g_print ("%s: %s%s%s\n", - primary ? "Key" : " Subkey", - fingerprint, - revoked ? " (revoked)" : "", + g_print ("%s: %s%s%s\n", primary ? "Key" : " Subkey", fingerprint, revoked ? " (revoked)" : "", invalid ? " (invalid)" : ""); - g_autofree gchar *created_str = format_timestamp (created, TRUE, - error); + g_autofree gchar *created_str = format_timestamp (created, TRUE, error); if (created_str == NULL) return FALSE; - g_print ("%sCreated: %s\n", - primary ? " " : " ", - created_str); + g_print ("%sCreated: %s\n", primary ? " " : " ", created_str); if (expires > 0) { - g_autofree gchar *expires_str = format_timestamp (expires, TRUE, - error); + g_autofree gchar *expires_str = format_timestamp (expires, TRUE, error); if (expires_str == NULL) return FALSE; - g_print ("%s%s: %s\n", - primary ? " " : " ", - expired ? "Expired" : "Expires", - expires_str); + g_print ("%s%s: %s\n", primary ? " " : " ", expired ? "Expired" : "Expires", expires_str); } return TRUE; } gboolean -ot_dump_gpg_key (GVariant *key, - GError **error) +ot_dump_gpg_key (GVariant *key, GError **error) { if (!g_variant_is_of_type (key, OSTREE_GPG_KEY_GVARIANT_FORMAT)) return glnx_throw (error, "GPG key variant type doesn't match '%s'", OSTREE_GPG_KEY_GVARIANT_STRING); - g_autoptr(GVariant) subkeys_v = g_variant_get_child_value (key, 0); + g_autoptr (GVariant) subkeys_v = g_variant_get_child_value (key, 0); GVariantIter subkeys_iter; g_variant_iter_init (&subkeys_iter, subkeys_v); - g_autoptr(GVariant) primary_key = NULL; + g_autoptr (GVariant) primary_key = NULL; g_variant_iter_next (&subkeys_iter, "@a{sv}", &primary_key); if (!dump_gpg_subkey (primary_key, TRUE, error)) return FALSE; - g_autoptr(GVariant) uids_v = g_variant_get_child_value (key, 1); + g_autoptr (GVariant) uids_v = g_variant_get_child_value (key, 1); GVariantIter uids_iter; g_variant_iter_init (&uids_iter, uids_v); GVariant *uid_v = NULL; @@ -544,18 +514,15 @@ ot_dump_gpg_key (GVariant *key, const gchar *uid = NULL; gboolean revoked = FALSE; gboolean invalid = FALSE; - (void) g_variant_lookup (uid_v, "uid", "&s", &uid); - (void) g_variant_lookup (uid_v, "revoked", "b", &revoked); - (void) g_variant_lookup (uid_v, "invalid", "b", &invalid); - g_print (" UID: %s%s%s\n", - uid, - revoked ? " (revoked)" : "", - invalid ? " (invalid)" : ""); + (void)g_variant_lookup (uid_v, "uid", "&s", &uid); + (void)g_variant_lookup (uid_v, "revoked", "b", &revoked); + (void)g_variant_lookup (uid_v, "invalid", "b", &invalid); + g_print (" UID: %s%s%s\n", uid, revoked ? " (revoked)" : "", invalid ? " (invalid)" : ""); const char *advanced_url = NULL; const char *direct_url = NULL; - (void) g_variant_lookup (uid_v, "advanced_url", "m&s", &advanced_url); - (void) g_variant_lookup (uid_v, "direct_url", "m&s", &direct_url); + (void)g_variant_lookup (uid_v, "advanced_url", "m&s", &advanced_url); + (void)g_variant_lookup (uid_v, "direct_url", "m&s", &direct_url); g_print (" Advanced update URL: %s\n", advanced_url ?: ""); g_print (" Direct update URL: %s\n", direct_url ?: ""); } diff --git a/src/ostree/ot-dump.h b/src/ostree/ot-dump.h index da1a2cb2..8022e97c 100644 --- a/src/ostree/ot-dump.h +++ b/src/ostree/ot-dump.h @@ -25,27 +25,22 @@ #include "ostree-core.h" -typedef enum { +typedef enum +{ OSTREE_DUMP_NONE = (1 << 0), OSTREE_DUMP_RAW = (1 << 1), OSTREE_DUMP_UNSWAPPED = (1 << 2), } OstreeDumpFlags; -void ot_dump_variant (GVariant *variant); +void ot_dump_variant (GVariant *variant); -void ot_dump_object (OstreeObjectType objtype, - const char *checksum, - GVariant *variant, - OstreeDumpFlags flags); +void ot_dump_object (OstreeObjectType objtype, const char *checksum, GVariant *variant, + OstreeDumpFlags flags); -void ot_dump_summary_bytes (GBytes *summary_bytes, - OstreeDumpFlags flags); +void ot_dump_summary_bytes (GBytes *summary_bytes, OstreeDumpFlags flags); void ot_dump_summary_metadata_keys (GBytes *summary_bytes); -gboolean ot_dump_summary_metadata_key (GBytes *summary_bytes, - const char *key, - GError **error); +gboolean ot_dump_summary_metadata_key (GBytes *summary_bytes, const char *key, GError **error); -gboolean ot_dump_gpg_key (GVariant *key, - GError **error); +gboolean ot_dump_gpg_key (GVariant *key, GError **error); diff --git a/src/ostree/ot-editor.c b/src/ostree/ot-editor.c index 706a5299..7b2e2512 100644 --- a/src/ostree/ot-editor.c +++ b/src/ostree/ot-editor.c @@ -22,11 +22,11 @@ #include "config.h" #include "libglnx.h" -#include "otutil.h" #include "ot-editor.h" +#include "otutil.h" -#include #include +#include #ifndef DEFAULT_EDITOR #define DEFAULT_EDITOR "vi" @@ -56,14 +56,11 @@ get_editor (void) } char * -ot_editor_prompt (OstreeRepo *repo, - const char *input, - GCancellable *cancellable, - GError **error) +ot_editor_prompt (OstreeRepo *repo, const char *input, GCancellable *cancellable, GError **error) { glnx_unref_object GSubprocess *proc = NULL; - g_autoptr(GFile) file = NULL; - g_autoptr(GFileIOStream) io = NULL; + g_autoptr (GFile) file = NULL; + g_autoptr (GFileIOStream) io = NULL; GOutputStream *output; const char *editor; char *ret = NULL; @@ -82,8 +79,8 @@ ot_editor_prompt (OstreeRepo *repo, goto out; output = g_io_stream_get_output_stream (G_IO_STREAM (io)); - if (!g_output_stream_write_all (output, input, strlen (input), NULL, cancellable, error) || - !g_io_stream_close (G_IO_STREAM (io), cancellable, error)) + if (!g_output_stream_write_all (output, input, strlen (input), NULL, cancellable, error) + || !g_io_stream_close (G_IO_STREAM (io), cancellable, error)) goto out; { @@ -91,8 +88,7 @@ ot_editor_prompt (OstreeRepo *repo, args = g_strconcat (editor, " ", quoted_file, NULL); } - proc = g_subprocess_new (G_SUBPROCESS_FLAGS_STDIN_INHERIT, error, - "/bin/sh", "-c", args, NULL); + proc = g_subprocess_new (G_SUBPROCESS_FLAGS_STDIN_INHERIT, error, "/bin/sh", "-c", args, NULL); if (!g_subprocess_wait_check (proc, cancellable, error)) { @@ -100,11 +96,11 @@ ot_editor_prompt (OstreeRepo *repo, goto out; } - ret = glnx_file_get_contents_utf8_at (AT_FDCWD, gs_file_get_path_cached (file), NULL, - cancellable, error); + ret = glnx_file_get_contents_utf8_at (AT_FDCWD, gs_file_get_path_cached (file), NULL, cancellable, + error); out: if (file) - (void )g_file_delete (file, NULL, NULL); + (void)g_file_delete (file, NULL, NULL); return ret; } diff --git a/src/ostree/ot-editor.h b/src/ostree/ot-editor.h index c096bed4..eb65dd0e 100644 --- a/src/ostree/ot-editor.h +++ b/src/ostree/ot-editor.h @@ -25,5 +25,5 @@ #include "ostree.h" -char * ot_editor_prompt (OstreeRepo *repo, const char *input, - GCancellable *cancellable, GError **error); +char *ot_editor_prompt (OstreeRepo *repo, const char *input, GCancellable *cancellable, + GError **error); diff --git a/src/ostree/ot-main.c b/src/ostree/ot-main.c index da4735b6..59a3fcba 100644 --- a/src/ostree/ot-main.c +++ b/src/ostree/ot-main.c @@ -26,12 +26,12 @@ #include #include #include -#include #include +#include -#include "ot-main.h" #include "ostree.h" #include "ot-admin-functions.h" +#include "ot-main.h" #include "otutil.h" static char *opt_repo; @@ -44,21 +44,25 @@ static gboolean opt_print_current_dir; // to find where to put files. Maybe we can make it printed by the CLI? #define _OSTREE_EXT_DIR PKGLIBEXECDIR "/ext" -static GOptionEntry global_entries[] = { - { "verbose", 'v', 0, G_OPTION_ARG_NONE, &opt_verbose, "Print debug information during command processing", NULL }, - { "version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Print version information and exit", NULL }, - { NULL } -}; +static GOptionEntry global_entries[] + = { { "verbose", 'v', 0, G_OPTION_ARG_NONE, &opt_verbose, + "Print debug information during command processing", NULL }, + { "version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Print version information and exit", + NULL }, + { NULL } }; -static GOptionEntry repo_entry[] = { - { "repo", 0, 0, G_OPTION_ARG_FILENAME, &opt_repo, "Path to OSTree repository (defaults to current directory or /sysroot/ostree/repo)", "PATH" }, - { NULL } -}; +static GOptionEntry repo_entry[] + = { { "repo", 0, 0, G_OPTION_ARG_FILENAME, &opt_repo, + "Path to OSTree repository (defaults to current directory or /sysroot/ostree/repo)", + "PATH" }, + { NULL } }; static GOptionEntry global_admin_entries[] = { /* No description since it's hidden from --help output. */ - { "print-current-dir", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_print_current_dir, NULL, NULL }, - { "sysroot", 0, 0, G_OPTION_ARG_FILENAME, &opt_sysroot, "Create a new OSTree sysroot at PATH", "PATH" }, + { "print-current-dir", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_print_current_dir, NULL, + NULL }, + { "sysroot", 0, 0, G_OPTION_ARG_FILENAME, &opt_sysroot, "Create a new OSTree sysroot at PATH", + "PATH" }, { NULL } }; @@ -67,7 +71,7 @@ ostree_option_context_new_with_commands (OstreeCommand *commands) { GOptionContext *context = g_option_context_new ("COMMAND"); - g_autoptr(GString) summary = g_string_new ("Builtin Commands:"); + g_autoptr (GString) summary = g_string_new ("Builtin Commands:"); while (commands->name != NULL) { @@ -75,7 +79,7 @@ ostree_option_context_new_with_commands (OstreeCommand *commands) { g_string_append_printf (summary, "\n %-18s", commands->name); - if (commands->description != NULL ) + if (commands->description != NULL) g_string_append_printf (summary, "%s", commands->description); } @@ -88,11 +92,9 @@ ostree_option_context_new_with_commands (OstreeCommand *commands) } int -ostree_usage (OstreeCommand *commands, - gboolean is_error) +ostree_usage (OstreeCommand *commands, gboolean is_error) { - g_autoptr(GOptionContext) context = - ostree_option_context_new_with_commands (commands); + g_autoptr (GOptionContext) context = ostree_option_context_new_with_commands (commands); g_option_context_add_main_entries (context, global_entries, NULL); g_autofree char *help = g_option_context_get_help (context, FALSE, NULL); @@ -109,8 +111,7 @@ ostree_usage (OstreeCommand *commands, * if so, and return *out_ns = TRUE. Otherwise, *out_ns = FALSE. */ static gboolean -maybe_setup_mount_namespace (gboolean *out_ns, - GError **error) +maybe_setup_mount_namespace (gboolean *out_ns, GError **error) { *out_ns = FALSE; @@ -132,9 +133,7 @@ maybe_setup_mount_namespace (gboolean *out_ns, } static void -message_handler (const gchar *log_domain, - GLogLevelFlags log_level, - const gchar *message, +message_handler (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data) { /* Make this look like normal console output */ @@ -145,11 +144,9 @@ message_handler (const gchar *log_domain, } int -ostree_main (int argc, - char **argv, - OstreeCommand *commands) +ostree_main (int argc, char **argv, OstreeCommand *commands) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; setlocale (LC_ALL, ""); @@ -159,16 +156,13 @@ ostree_main (int argc, if (error != NULL) { - g_printerr ("%s%serror:%s%s %s\n", - ot_get_red_start (), ot_get_bold_start (), - ot_get_bold_end (), ot_get_red_end (), - error->message); + g_printerr ("%s%serror:%s%s %s\n", ot_get_red_start (), ot_get_bold_start (), + ot_get_bold_end (), ot_get_red_end (), error->message); } return ret; } - /** * ostree_command_lookup_external: * @argc: number of entries in @argv @@ -183,9 +177,7 @@ ostree_main (int argc, * external command if found, or %NULL otherwise. */ gchar * -ostree_command_lookup_external (int argc, - char **argv, - OstreeCommand *commands) +ostree_command_lookup_external (int argc, char **argv, OstreeCommand *commands) { g_assert (commands != NULL); @@ -196,10 +188,9 @@ ostree_command_lookup_external (int argc, for (guint arg_index = 1; arg_index < argc; arg_index++) { char *current_arg = argv[arg_index]; - if (current_arg == NULL || - g_str_has_prefix (current_arg, "-") || - g_strcmp0 (current_arg, "") == 0) - continue; + if (current_arg == NULL || g_str_has_prefix (current_arg, "-") + || g_strcmp0 (current_arg, "") == 0) + continue; for (guint cmd_index = 0; commands[cmd_index].name != NULL; cmd_index++) { @@ -207,7 +198,6 @@ ostree_command_lookup_external (int argc, return NULL; } - g_autofree gchar *ext_command = g_strdup_printf ("ostree-%s", current_arg); /* First, search in our libdir /usr/lib/ostree/ostree-$cmd */ @@ -218,7 +208,7 @@ ostree_command_lookup_external (int argc, /* Otherwise, look in $PATH */ if (g_find_program_in_path (ext_command) == NULL) - return NULL; + return NULL; return g_steal_pointer (&ext_command); } @@ -236,23 +226,17 @@ ostree_command_lookup_external (int argc, int ostree_command_exec_external (char **argv) { - int r = execvp(argv[0], argv); + int r = execvp (argv[0], argv); g_assert (r == -1); setlocale (LC_ALL, ""); - g_printerr ("%s%serror:%s%s: Executing %s: %s\n", - ot_get_red_start (), ot_get_bold_start (), - ot_get_bold_end (), ot_get_red_end (), - argv[0], - g_strerror (errno)); + g_printerr ("%s%serror:%s%s: Executing %s: %s\n", ot_get_red_start (), ot_get_bold_start (), + ot_get_bold_end (), ot_get_red_end (), argv[0], g_strerror (errno)); return 1; } int -ostree_run (int argc, - char **argv, - OstreeCommand *commands, - GError **res_error) +ostree_run (int argc, char **argv, OstreeCommand *commands, GError **res_error) { GError *error = NULL; GCancellable *cancellable = NULL; @@ -266,7 +250,7 @@ ostree_run (int argc, /* avoid gvfs (http://bugzilla.gnome.org/show_bug.cgi?id=526454) */ if (!g_setenv ("GIO_USE_VFS", "local", TRUE)) { - (void) glnx_throw (res_error, "Failed to set environment variable GIO_USE_FVS"); + (void)glnx_throw (res_error, "Failed to set environment variable GIO_USE_FVS"); return 1; } @@ -306,21 +290,20 @@ ostree_run (int argc, if (!command->fn) { - g_autoptr(GOptionContext) context = - ostree_option_context_new_with_commands (commands); + g_autoptr (GOptionContext) context = ostree_option_context_new_with_commands (commands); /* This will not return for some options (e.g. --version). */ - if (ostree_option_context_parse (context, NULL, &argc, &argv, NULL, NULL, cancellable, &error)) + if (ostree_option_context_parse (context, NULL, &argc, &argv, NULL, NULL, cancellable, + &error)) { if (command_name == NULL) { - g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED, - "No command specified"); + g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED, "No command specified"); } else { - g_set_error (&error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Unknown command '%s'", command_name); + g_set_error (&error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unknown command '%s'", + command_name); } } @@ -337,7 +320,7 @@ ostree_run (int argc, goto out; success = TRUE; - out: +out: g_assert (success || error); if (error) @@ -350,17 +333,14 @@ ostree_run (int argc, /* Process a --repo arg. */ static OstreeRepo * -parse_repo_option (GOptionContext *context, - const char *repo_path, - gboolean skip_repo_open, - GCancellable *cancellable, - GError **error) +parse_repo_option (GOptionContext *context, const char *repo_path, gboolean skip_repo_open, + GCancellable *cancellable, GError **error) { - g_autoptr(OstreeRepo) repo = NULL; + g_autoptr (OstreeRepo) repo = NULL; if (repo_path == NULL) { - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; repo = ostree_repo_new_default (); if (!ostree_repo_open (repo, cancellable, &local_error)) @@ -384,7 +364,7 @@ parse_repo_option (GOptionContext *context, } else { - g_autoptr(GFile) repo_file = g_file_new_for_path (repo_path); + g_autoptr (GFile) repo_file = g_file_new_for_path (repo_path); repo = ostree_repo_new (repo_file); if (!skip_repo_open) @@ -397,15 +377,15 @@ parse_repo_option (GOptionContext *context, return g_steal_pointer (&repo); } -/* Process a --repo arg, determining if we should remount /sysroot; used below, and for the remote builtins */ +/* Process a --repo arg, determining if we should remount /sysroot; used below, and for the remote + * builtins */ static OstreeRepo * -parse_repo_option_and_maybe_remount (GOptionContext *context, - const char *repo_path, - gboolean skip_repo_open, - GCancellable *cancellable, - GError **error) +parse_repo_option_and_maybe_remount (GOptionContext *context, const char *repo_path, + gboolean skip_repo_open, GCancellable *cancellable, + GError **error) { - g_autoptr(OstreeRepo) repo = parse_repo_option (context, repo_path, skip_repo_open, cancellable, error); + g_autoptr (OstreeRepo) repo + = parse_repo_option (context, repo_path, skip_repo_open, cancellable, error); if (!repo) return NULL; @@ -436,19 +416,16 @@ parse_repo_option_and_maybe_remount (GOptionContext *context, /* Used by the remote builtins which are special in taking --sysroot or --repo */ gboolean -ostree_parse_sysroot_or_repo_option (GOptionContext *context, - const char *sysroot_path, - const char *repo_path, - OstreeSysroot **out_sysroot, - OstreeRepo **out_repo, - GCancellable *cancellable, +ostree_parse_sysroot_or_repo_option (GOptionContext *context, const char *sysroot_path, + const char *repo_path, OstreeSysroot **out_sysroot, + OstreeRepo **out_repo, GCancellable *cancellable, GError **error) { - g_autoptr(OstreeSysroot) sysroot = NULL; - g_autoptr(OstreeRepo) repo = NULL; + g_autoptr (OstreeSysroot) sysroot = NULL; + g_autoptr (OstreeRepo) repo = NULL; if (sysroot_path) { - g_autoptr(GFile) sysroot_file = g_file_new_for_path (sysroot_path); + g_autoptr (GFile) sysroot_file = g_file_new_for_path (sysroot_path); sysroot = ostree_sysroot_new (sysroot_file); if (!ostree_sysroot_load (sysroot, cancellable, error)) return FALSE; @@ -468,18 +445,14 @@ ostree_parse_sysroot_or_repo_option (GOptionContext *context, } gboolean -ostree_option_context_parse (GOptionContext *context, - const GOptionEntry *main_entries, - int *argc, - char ***argv, - OstreeCommandInvocation *invocation, - OstreeRepo **out_repo, - GCancellable *cancellable, - GError **error) +ostree_option_context_parse (GOptionContext *context, const GOptionEntry *main_entries, int *argc, + char ***argv, OstreeCommandInvocation *invocation, + OstreeRepo **out_repo, GCancellable *cancellable, GError **error) { - g_autoptr(OstreeRepo) repo = NULL; + g_autoptr (OstreeRepo) repo = NULL; /* When invocation is NULL, do not fetch repo */ - const OstreeBuiltinFlags flags = invocation ? invocation->command->flags : OSTREE_BUILTIN_FLAG_NO_REPO; + const OstreeBuiltinFlags flags + = invocation ? invocation->command->flags : OSTREE_BUILTIN_FLAG_NO_REPO; if (invocation && invocation->command->description != NULL) { @@ -495,9 +468,10 @@ ostree_option_context_parse (GOptionContext *context, { /* TODO: remove this part once we deduplicate the ostree_option_context_new_with_commands * function from other root commands( command with subcommands). Because - * we can directly add the summary inside the ostree_option_context_new_with_commands function. + * we can directly add the summary inside the ostree_option_context_new_with_commands + * function. */ - g_autoptr(GString) new_summary_string = g_string_new (context_summary); + g_autoptr (GString) new_summary_string = g_string_new (context_summary); g_string_prepend (new_summary_string, "\n\n"); g_string_prepend (new_summary_string, invocation->command->description); @@ -539,7 +513,7 @@ ostree_option_context_parse (GOptionContext *context, { /* This should now be YAML, like `docker version`, so it's both nice to read * possible to parse */ - g_auto(GStrv) features = g_strsplit (OSTREE_FEATURES, " ", -1); + g_auto (GStrv) features = g_strsplit (OSTREE_FEATURES, " ", -1); g_print ("%s:\n", PACKAGE_NAME); g_print (" Version: '%s'\n", PACKAGE_VERSION); if (strlen (OSTREE_GITREV) > 0) @@ -558,8 +532,8 @@ ostree_option_context_parse (GOptionContext *context, if (!(flags & OSTREE_BUILTIN_FLAG_NO_REPO)) { - repo = parse_repo_option_and_maybe_remount (context, opt_repo, (flags & OSTREE_BUILTIN_FLAG_NO_CHECK) > 0, - cancellable, error); + repo = parse_repo_option_and_maybe_remount ( + context, opt_repo, (flags & OSTREE_BUILTIN_FLAG_NO_CHECK) > 0, cancellable, error); if (!repo) return FALSE; } @@ -571,18 +545,14 @@ ostree_option_context_parse (GOptionContext *context, } static void -on_sysroot_journal_msg (OstreeSysroot *sysroot, - const char *msg, - void *dummy) +on_sysroot_journal_msg (OstreeSysroot *sysroot, const char *msg, void *dummy) { g_print ("%s\n", msg); } gboolean -ostree_admin_sysroot_load (OstreeSysroot *sysroot, - OstreeAdminBuiltinFlags flags, - GCancellable *cancellable, - GError **error) +ostree_admin_sysroot_load (OstreeSysroot *sysroot, OstreeAdminBuiltinFlags flags, + GCancellable *cancellable, GError **error) { if ((flags & OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED) == 0) { @@ -617,23 +587,18 @@ ostree_admin_sysroot_load (OstreeSysroot *sysroot, } gboolean -ostree_admin_option_context_parse (GOptionContext *context, - const GOptionEntry *main_entries, - int *argc, - char ***argv, - OstreeAdminBuiltinFlags flags, - OstreeCommandInvocation *invocation, - OstreeSysroot **out_sysroot, - GCancellable *cancellable, - GError **error) +ostree_admin_option_context_parse (GOptionContext *context, const GOptionEntry *main_entries, + int *argc, char ***argv, OstreeAdminBuiltinFlags flags, + OstreeCommandInvocation *invocation, OstreeSysroot **out_sysroot, + GCancellable *cancellable, GError **error) { /* Entries are listed in --help output in the order added. We add the * main entries ourselves so that we can add the --sysroot entry first. */ g_option_context_add_main_entries (context, global_admin_entries, NULL); - if (!ostree_option_context_parse (context, main_entries, argc, argv, - invocation, NULL, cancellable, error)) + if (!ostree_option_context_parse (context, main_entries, argc, argv, invocation, NULL, + cancellable, error)) return FALSE; if (!opt_print_current_dir && (flags & OSTREE_ADMIN_BUILTIN_FLAG_NO_SYSROOT)) @@ -643,11 +608,11 @@ ostree_admin_option_context_parse (GOptionContext *context, return TRUE; } - g_autoptr(GFile) sysroot_path = NULL; + g_autoptr (GFile) sysroot_path = NULL; if (opt_sysroot != NULL) sysroot_path = g_file_new_for_path (opt_sysroot); - g_autoptr(OstreeSysroot) sysroot = ostree_sysroot_new (sysroot_path); + g_autoptr (OstreeSysroot) sysroot = ostree_sysroot_new (sysroot_path); if (!ostree_sysroot_initialize (sysroot, error)) return FALSE; g_signal_connect (sysroot, "journal-msg", G_CALLBACK (on_sysroot_journal_msg), NULL); @@ -660,9 +625,9 @@ ostree_admin_option_context_parse (GOptionContext *context, if (opt_print_current_dir) { - g_autoptr(GPtrArray) deployments = NULL; + g_autoptr (GPtrArray) deployments = NULL; OstreeDeployment *first_deployment; - g_autoptr(GFile) deployment_file = NULL; + g_autoptr (GFile) deployment_file = NULL; g_autofree char *deployment_path = NULL; deployments = ostree_sysroot_get_deployments (sysroot); @@ -691,8 +656,7 @@ ostree_admin_option_context_parse (GOptionContext *context, } gboolean -ostree_ensure_repo_writable (OstreeRepo *repo, - GError **error) +ostree_ensure_repo_writable (OstreeRepo *repo, GError **error) { if (!ostree_repo_is_writable (repo, error)) return glnx_prefix_error (error, "Cannot write to repository"); @@ -706,10 +670,9 @@ ostree_print_gpg_verify_result (OstreeGpgVerifyResult *result) guint n_sigs = ostree_gpg_verify_result_count_all (result); /* XXX If we ever add internationalization, use ngettext() here. */ - g_print ("GPG: Verification enabled, found %u signature%s:\n", - n_sigs, n_sigs == 1 ? "" : "s"); + g_print ("GPG: Verification enabled, found %u signature%s:\n", n_sigs, n_sigs == 1 ? "" : "s"); - g_autoptr(GString) buffer = g_string_sized_new (256); + g_autoptr (GString) buffer = g_string_sized_new (256); for (guint ii = 0; ii < n_sigs; ii++) { @@ -729,7 +692,8 @@ ot_enable_tombstone_commits (OstreeRepo *repo, GError **error) GKeyFile *config = ostree_repo_get_config (repo); tombstone_commits = g_key_file_get_boolean (config, "core", "tombstone-commits", NULL); - /* tombstone_commits is FALSE either if it is not found or it is really set to FALSE in the config file. */ + /* tombstone_commits is FALSE either if it is not found or it is really set to FALSE in the + * config file. */ if (!tombstone_commits) { g_key_file_set_boolean (config, "core", "tombstone-commits", TRUE); diff --git a/src/ostree/ot-main.h b/src/ostree/ot-main.h index e296501a..8df1ca8e 100644 --- a/src/ostree/ot-main.h +++ b/src/ostree/ot-main.h @@ -24,14 +24,16 @@ #include "libglnx.h" #include "ostree.h" -typedef enum { +typedef enum +{ OSTREE_BUILTIN_FLAG_NONE = 0, OSTREE_BUILTIN_FLAG_NO_REPO = 1 << 0, OSTREE_BUILTIN_FLAG_NO_CHECK = 1 << 1, OSTREE_BUILTIN_FLAG_HIDDEN = 1 << 2, } OstreeBuiltinFlags; -typedef enum { +typedef enum +{ OSTREE_ADMIN_BUILTIN_FLAG_NONE = 0, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER = (1 << 0), OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED = (1 << 1), @@ -39,13 +41,14 @@ typedef enum { OSTREE_ADMIN_BUILTIN_FLAG_NO_LOAD = (1 << 3), } OstreeAdminBuiltinFlags; - typedef struct OstreeCommandInvocation OstreeCommandInvocation; -typedef struct { +typedef struct +{ const char *name; OstreeBuiltinFlags flags; - gboolean (*fn) (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); + gboolean (*fn) (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error); const char *description; } OstreeCommand; @@ -55,7 +58,8 @@ typedef struct { * In the future if we want to add something new we won't need to * touch every prototype */ -struct OstreeCommandInvocation { +struct OstreeCommandInvocation +{ OstreeCommand *command; }; @@ -65,37 +69,29 @@ int ostree_run (int argc, char **argv, OstreeCommand *commands, GError **error); int ostree_usage (OstreeCommand *commands, gboolean is_error); -char* ostree_command_lookup_external (int argc, char **argv, OstreeCommand *commands); +char *ostree_command_lookup_external (int argc, char **argv, OstreeCommand *commands); int ostree_command_exec_external (char **argv); -gboolean ostree_parse_sysroot_or_repo_option (GOptionContext *context, - const char *sysroot_path, - const char *repo_path, - OstreeSysroot **out_sysroot, - OstreeRepo **out_repo, - GCancellable *cancellable, +gboolean ostree_parse_sysroot_or_repo_option (GOptionContext *context, const char *sysroot_path, + const char *repo_path, OstreeSysroot **out_sysroot, + OstreeRepo **out_repo, GCancellable *cancellable, GError **error); -gboolean ostree_option_context_parse (GOptionContext *context, - const GOptionEntry *main_entries, - int *argc, char ***argv, - OstreeCommandInvocation *invocation, - OstreeRepo **out_repo, - GCancellable *cancellable, GError **error); +gboolean ostree_option_context_parse (GOptionContext *context, const GOptionEntry *main_entries, + int *argc, char ***argv, OstreeCommandInvocation *invocation, + OstreeRepo **out_repo, GCancellable *cancellable, + GError **error); gboolean ostree_admin_option_context_parse (GOptionContext *context, - const GOptionEntry *main_entries, - int *argc, char ***argv, - OstreeAdminBuiltinFlags flags, + const GOptionEntry *main_entries, int *argc, + char ***argv, OstreeAdminBuiltinFlags flags, OstreeCommandInvocation *invocation, - OstreeSysroot **out_sysroot, - GCancellable *cancellable, GError **error); + OstreeSysroot **out_sysroot, GCancellable *cancellable, + GError **error); -gboolean ostree_admin_sysroot_load (OstreeSysroot *sysroot, - OstreeAdminBuiltinFlags flags, - GCancellable *cancellable, - GError **error); +gboolean ostree_admin_sysroot_load (OstreeSysroot *sysroot, OstreeAdminBuiltinFlags flags, + GCancellable *cancellable, GError **error); gboolean ostree_ensure_repo_writable (OstreeRepo *repo, GError **error); @@ -104,16 +100,17 @@ void ostree_print_gpg_verify_result (OstreeGpgVerifyResult *result); gboolean ot_enable_tombstone_commits (OstreeRepo *repo, GError **error); /* Copied from rpm-ostree's rpmostree-libbuiltin.h */ -#define TERM_ESCAPE_SEQUENCE(type,seq) \ - static inline const char* ot_get_##type (void) { \ - if (glnx_stdout_is_tty ()) \ - return seq; \ - return ""; \ +#define TERM_ESCAPE_SEQUENCE(type, seq) \ + static inline const char *ot_get_##type (void) \ + { \ + if (glnx_stdout_is_tty ()) \ + return seq; \ + return ""; \ } -TERM_ESCAPE_SEQUENCE(red_start, "\x1b[31m") -TERM_ESCAPE_SEQUENCE(red_end, "\x1b[22m") -TERM_ESCAPE_SEQUENCE(bold_start, "\x1b[1m") -TERM_ESCAPE_SEQUENCE(bold_end, "\x1b[0m") +TERM_ESCAPE_SEQUENCE (red_start, "\x1b[31m") +TERM_ESCAPE_SEQUENCE (red_end, "\x1b[22m") +TERM_ESCAPE_SEQUENCE (bold_start, "\x1b[1m") +TERM_ESCAPE_SEQUENCE (bold_end, "\x1b[0m") #undef TERM_ESCAPE_SEQUENCE diff --git a/src/ostree/ot-remote-builtin-add-cookie.c b/src/ostree/ot-remote-builtin-add-cookie.c index 30aeacb3..900520dc 100644 --- a/src/ostree/ot-remote-builtin-add-cookie.c +++ b/src/ostree/ot-remote-builtin-add-cookie.c @@ -22,9 +22,9 @@ #include "otutil.h" +#include "ostree-repo-private.h" #include "ot-main.h" #include "ot-remote-builtins.h" -#include "ostree-repo-private.h" #include "ot-remote-cookie-util.h" /* ATTENTION: @@ -32,22 +32,22 @@ * man page (man/ostree-remote.xml) when changing the option list. */ -static GOptionEntry option_entries[] = { - { NULL } -}; +static GOptionEntry option_entries[] = { { NULL } }; gboolean -ot_remote_builtin_add_cookie (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_remote_builtin_add_cookie (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("NAME DOMAIN PATH COOKIE_NAME VALUE"); - g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - invocation, &repo, cancellable, error)) + g_autoptr (GOptionContext) context = g_option_context_new ("NAME DOMAIN PATH COOKIE_NAME VALUE"); + g_autoptr (OstreeRepo) repo = NULL; + if (!ostree_option_context_parse (context, option_entries, &argc, &argv, invocation, &repo, + cancellable, error)) return FALSE; if (argc < 6) { - ot_util_usage_error (context, "NAME, DOMAIN, PATH, COOKIE_NAME and VALUE must be specified", error); + ot_util_usage_error (context, "NAME, DOMAIN, PATH, COOKIE_NAME and VALUE must be specified", + error); return FALSE; } @@ -57,7 +57,8 @@ ot_remote_builtin_add_cookie (int argc, char **argv, OstreeCommandInvocation *in const char *cookie_name = argv[4]; const char *value = argv[5]; g_autofree char *cookie_file = g_strdup_printf ("%s.cookies.txt", remote_name); - if (!ot_add_cookie_at (ostree_repo_get_dfd (repo), cookie_file, domain, path, cookie_name, value, error)) + if (!ot_add_cookie_at (ostree_repo_get_dfd (repo), cookie_file, domain, path, cookie_name, value, + error)) return FALSE; return TRUE; diff --git a/src/ostree/ot-remote-builtin-add.c b/src/ostree/ot-remote-builtin-add.c index f07005f6..63b84a1e 100644 --- a/src/ostree/ot-remote-builtin-add.c +++ b/src/ostree/ot-remote-builtin-add.c @@ -42,41 +42,52 @@ static char *opt_repo; * man page (man/ostree-remote.xml) when changing the option list. */ -static GOptionEntry option_entries[] = { - { "set", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_set, "Set config option KEY=VALUE for remote", "KEY=VALUE" }, - { "no-gpg-verify", 0, 0, G_OPTION_ARG_NONE, &opt_no_gpg_verify, "Disable GPG verification", NULL }, - { "no-sign-verify", 0, 0, G_OPTION_ARG_NONE, &opt_no_sign_verify, "Disable signature verification", NULL }, - { "sign-verify", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_sign_verify, "Verify signatures using KEYTYPE=inline:PUBKEY or KEYTYPE=file:/path/to/key", "KEYTYPE=[inline|file]:PUBKEY" }, - { "if-not-exists", 0, 0, G_OPTION_ARG_NONE, &opt_if_not_exists, "Do nothing if the provided remote exists", NULL }, - { "force", 0, 0, G_OPTION_ARG_NONE, &opt_force, "Replace the provided remote if it exists", NULL }, - { "gpg-import", 0, 0, G_OPTION_ARG_FILENAME, &opt_gpg_import, "Import GPG key from FILE", "FILE" }, - { "custom-backend", 0, 0, G_OPTION_ARG_STRING, &opt_custom_backend, "This remote has content not fetched via libostree", "NAME" }, - { "contenturl", 0, 0, G_OPTION_ARG_STRING, &opt_contenturl, "Use URL when fetching content", "URL" }, - { "collection-id", 0, 0, G_OPTION_ARG_STRING, &opt_collection_id, - "Globally unique ID for this repository as an collection of refs for redistribution to other repositories", "COLLECTION-ID" }, - { "repo", 0, 0, G_OPTION_ARG_FILENAME, &opt_repo, "Path to OSTree repository (defaults to /sysroot/ostree/repo)", "PATH" }, - { "sysroot", 0, 0, G_OPTION_ARG_FILENAME, &opt_sysroot, "Use sysroot at PATH (overrides --repo)", "PATH" }, - { NULL } -}; +static GOptionEntry option_entries[] + = { { "set", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_set, + "Set config option KEY=VALUE for remote", "KEY=VALUE" }, + { "no-gpg-verify", 0, 0, G_OPTION_ARG_NONE, &opt_no_gpg_verify, "Disable GPG verification", + NULL }, + { "no-sign-verify", 0, 0, G_OPTION_ARG_NONE, &opt_no_sign_verify, + "Disable signature verification", NULL }, + { "sign-verify", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_sign_verify, + "Verify signatures using KEYTYPE=inline:PUBKEY or KEYTYPE=file:/path/to/key", + "KEYTYPE=[inline|file]:PUBKEY" }, + { "if-not-exists", 0, 0, G_OPTION_ARG_NONE, &opt_if_not_exists, + "Do nothing if the provided remote exists", NULL }, + { "force", 0, 0, G_OPTION_ARG_NONE, &opt_force, "Replace the provided remote if it exists", + NULL }, + { "gpg-import", 0, 0, G_OPTION_ARG_FILENAME, &opt_gpg_import, "Import GPG key from FILE", + "FILE" }, + { "custom-backend", 0, 0, G_OPTION_ARG_STRING, &opt_custom_backend, + "This remote has content not fetched via libostree", "NAME" }, + { "contenturl", 0, 0, G_OPTION_ARG_STRING, &opt_contenturl, "Use URL when fetching content", + "URL" }, + { "collection-id", 0, 0, G_OPTION_ARG_STRING, &opt_collection_id, + "Globally unique ID for this repository as an collection of refs for redistribution to " + "other repositories", + "COLLECTION-ID" }, + { "repo", 0, 0, G_OPTION_ARG_FILENAME, &opt_repo, + "Path to OSTree repository (defaults to /sysroot/ostree/repo)", "PATH" }, + { "sysroot", 0, 0, G_OPTION_ARG_FILENAME, &opt_sysroot, + "Use sysroot at PATH (overrides --repo)", "PATH" }, + { NULL } }; static char * -add_verify_opt (GVariantBuilder *builder, - const char *keyspec, - GError **error) +add_verify_opt (GVariantBuilder *builder, const char *keyspec, GError **error) { - g_auto(GStrv) parts = g_strsplit (keyspec, "=", 2); + g_auto (GStrv) parts = g_strsplit (keyspec, "=", 2); g_assert (parts && *parts); const char *keytype = parts[0]; if (!parts[1]) return glnx_null_throw (error, "Failed to parse KEYTYPE=[inline|file]:DATA in %s", keyspec); - g_autoptr(OstreeSign) sign = ostree_sign_get_by_name (keytype, error); + g_autoptr (OstreeSign) sign = ostree_sign_get_by_name (keytype, error); if (!sign) return NULL; const char *rest = parts[1]; g_assert (!parts[2]); - g_auto(GStrv) keyparts = g_strsplit (rest, ":", 2); + g_auto (GStrv) keyparts = g_strsplit (rest, ":", 2); g_assert (keyparts && *keyparts); const char *keyref = keyparts[0]; g_assert (keyref); @@ -89,33 +100,32 @@ add_verify_opt (GVariantBuilder *builder, return glnx_null_throw (error, "Invalid key reference %s, expected inline|file", keyref); g_assert (keyparts[1] && !keyparts[2]); - g_variant_builder_add (builder, "{s@v}", - optname, + g_variant_builder_add (builder, "{s@v}", optname, g_variant_new_variant (g_variant_new_string (keyparts[1]))); return g_strdup (ostree_sign_get_name (sign)); } gboolean -ot_remote_builtin_add (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_remote_builtin_add (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeSysroot) sysroot = NULL; - g_autoptr(OstreeRepo) repo = NULL; - g_autoptr(GString) sign_verify = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeSysroot) sysroot = NULL; + g_autoptr (OstreeRepo) repo = NULL; + g_autoptr (GString) sign_verify = NULL; const char *remote_name; const char *remote_url = NULL; - g_autoptr(GVariantBuilder) optbuilder = NULL; - g_autoptr(GVariant) options = NULL; + g_autoptr (GVariantBuilder) optbuilder = NULL; + g_autoptr (GVariant) options = NULL; gboolean ret = FALSE; context = g_option_context_new ("NAME [metalink=|mirrorlist=]URL [BRANCH...]"); - if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - invocation, NULL, cancellable, error)) + if (!ostree_option_context_parse (context, option_entries, &argc, &argv, invocation, NULL, + cancellable, error)) goto out; - if (!ostree_parse_sysroot_or_repo_option (context, opt_sysroot, opt_repo, - &sysroot, &repo, + if (!ostree_parse_sysroot_or_repo_option (context, opt_sysroot, opt_repo, &sysroot, &repo, cancellable, error)) goto out; @@ -142,9 +152,7 @@ ot_remote_builtin_add (int argc, char **argv, OstreeCommandInvocation *invocatio if (opt_if_not_exists && opt_force) { - ot_util_usage_error (context, - "Can only specify one of --if-not-exists and --force", - error); + ot_util_usage_error (context, "Can only specify one of --if-not-exists and --force", error); goto out; } @@ -152,16 +160,16 @@ ot_remote_builtin_add (int argc, char **argv, OstreeCommandInvocation *invocatio if (argc > 3) { - g_autoptr(GPtrArray) branchesp = g_ptr_array_new (); + g_autoptr (GPtrArray) branchesp = g_ptr_array_new (); int i; for (i = 3; i < argc; i++) g_ptr_array_add (branchesp, argv[i]); g_ptr_array_add (branchesp, NULL); - g_variant_builder_add (optbuilder, "{s@v}", - "branches", - g_variant_new_variant (g_variant_new_strv ((const char*const*)branchesp->pdata, -1))); + g_variant_builder_add ( + optbuilder, "{s@v}", "branches", + g_variant_new_variant (g_variant_new_strv ((const char *const *)branchesp->pdata, -1))); } /* We could just make users use --set instead for this since it's a string, @@ -169,11 +177,11 @@ ot_remote_builtin_add (int argc, char **argv, OstreeCommandInvocation *invocatio * --set=contenturl=mirrorlist=... */ if (opt_contenturl != NULL) - g_variant_builder_add (optbuilder, "{s@v}", - "contenturl", g_variant_new_variant (g_variant_new_string (opt_contenturl))); + g_variant_builder_add (optbuilder, "{s@v}", "contenturl", + g_variant_new_variant (g_variant_new_string (opt_contenturl))); if (opt_custom_backend != NULL) - g_variant_builder_add (optbuilder, "{s@v}", - "custom-backend", g_variant_new_variant (g_variant_new_string (opt_custom_backend))); + g_variant_builder_add (optbuilder, "{s@v}", "custom-backend", + g_variant_new_variant (g_variant_new_string (opt_custom_backend))); for (char **iter = opt_set; iter && *iter; iter++) { @@ -184,15 +192,14 @@ ot_remote_builtin_add (int argc, char **argv, OstreeCommandInvocation *invocatio if (!ot_parse_keyvalue (keyvalue, &subkey, &subvalue, error)) goto out; - g_variant_builder_add (optbuilder, "{s@v}", - subkey, g_variant_new_variant (g_variant_new_string (subvalue))); + g_variant_builder_add (optbuilder, "{s@v}", subkey, + g_variant_new_variant (g_variant_new_string (subvalue))); } #ifndef OSTREE_DISABLE_GPGME /* No signature verification implies no verification for GPG signature as well */ if (opt_no_gpg_verify || opt_no_sign_verify) - g_variant_builder_add (optbuilder, "{s@v}", - "gpg-verify", + g_variant_builder_add (optbuilder, "{s@v}", "gpg-verify", g_variant_new_variant (g_variant_new_boolean (FALSE))); #endif /* OSTREE_DISABLE_GPGME */ @@ -200,9 +207,8 @@ ot_remote_builtin_add (int argc, char **argv, OstreeCommandInvocation *invocatio { if (opt_sign_verify) return glnx_throw (error, "Cannot specify both --sign-verify and --no-sign-verify"); - g_variant_builder_add (optbuilder, "{s@v}", - "sign-verify", - g_variant_new_variant (g_variant_new_boolean (FALSE))); + g_variant_builder_add (optbuilder, "{s@v}", "sign-verify", + g_variant_new_variant (g_variant_new_boolean (FALSE))); } for (char **iter = opt_sign_verify; iter && *iter; iter++) @@ -222,13 +228,13 @@ ot_remote_builtin_add (int argc, char **argv, OstreeCommandInvocation *invocatio } } if (sign_verify != NULL) - g_variant_builder_add (optbuilder, "{s@v}", - "sign-verify", - g_variant_new_variant (g_variant_new_string (sign_verify->str))); + g_variant_builder_add (optbuilder, "{s@v}", "sign-verify", + g_variant_new_variant (g_variant_new_string (sign_verify->str))); if (opt_collection_id != NULL) - g_variant_builder_add (optbuilder, "{s@v}", "collection-id", - g_variant_new_variant (g_variant_new_take_string (g_steal_pointer (&opt_collection_id)))); + g_variant_builder_add ( + optbuilder, "{s@v}", "collection-id", + g_variant_new_variant (g_variant_new_take_string (g_steal_pointer (&opt_collection_id)))); options = g_variant_ref_sink (g_variant_builder_end (optbuilder)); @@ -239,9 +245,7 @@ ot_remote_builtin_add (int argc, char **argv, OstreeCommandInvocation *invocatio changeop = OSTREE_REPO_REMOTE_CHANGE_REPLACE; else changeop = OSTREE_REPO_REMOTE_CHANGE_ADD; - if (!ostree_repo_remote_change (repo, NULL, changeop, - remote_name, remote_url, - options, + if (!ostree_repo_remote_change (repo, NULL, changeop, remote_name, remote_url, options, cancellable, error)) goto out; @@ -254,27 +258,27 @@ ot_remote_builtin_add (int argc, char **argv, OstreeCommandInvocation *invocatio * know whether the remote already existed. We import regardless. */ if (opt_gpg_import != NULL) { - g_autoptr(GFile) file = NULL; - g_autoptr(GInputStream) input_stream = NULL; + g_autoptr (GFile) file = NULL; + g_autoptr (GInputStream) input_stream = NULL; guint imported = 0; file = g_file_new_for_path (opt_gpg_import); - input_stream = (GInputStream *) g_file_read (file, cancellable, error); + input_stream = (GInputStream *)g_file_read (file, cancellable, error); if (input_stream == NULL) goto out; - if (!ostree_repo_remote_gpg_import (repo, remote_name, input_stream, - NULL, &imported, cancellable, error)) + if (!ostree_repo_remote_gpg_import (repo, remote_name, input_stream, NULL, &imported, + cancellable, error)) goto out; /* XXX If we ever add internationalization, use ngettext() here. */ - g_print ("Imported %u GPG key%s to remote \"%s\"\n", - imported, (imported == 1) ? "" : "s", remote_name); + g_print ("Imported %u GPG key%s to remote \"%s\"\n", imported, (imported == 1) ? "" : "s", + remote_name); } #endif /* OSTREE_DISABLE_GPGME */ ret = TRUE; - out: +out: return ret; } diff --git a/src/ostree/ot-remote-builtin-delete-cookie.c b/src/ostree/ot-remote-builtin-delete-cookie.c index 0c22caa2..f79854ea 100644 --- a/src/ostree/ot-remote-builtin-delete-cookie.c +++ b/src/ostree/ot-remote-builtin-delete-cookie.c @@ -23,9 +23,9 @@ #include "otutil.h" #include +#include "ostree-repo-private.h" #include "ot-main.h" #include "ot-remote-builtins.h" -#include "ostree-repo-private.h" #include "ot-remote-cookie-util.h" /* ATTENTION: @@ -33,18 +33,17 @@ * man page (man/ostree-remote.xml) when changing the option list. */ -static GOptionEntry option_entries[] = { - { NULL } -}; +static GOptionEntry option_entries[] = { { NULL } }; gboolean -ot_remote_builtin_delete_cookie (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_remote_builtin_delete_cookie (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(OstreeRepo) repo = NULL; - g_autoptr(GOptionContext) context = g_option_context_new ("NAME DOMAIN PATH COOKIE_NAME"); + g_autoptr (OstreeRepo) repo = NULL; + g_autoptr (GOptionContext) context = g_option_context_new ("NAME DOMAIN PATH COOKIE_NAME"); - if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, option_entries, &argc, &argv, invocation, &repo, + cancellable, error)) return FALSE; if (argc < 5) @@ -58,7 +57,8 @@ ot_remote_builtin_delete_cookie (int argc, char **argv, OstreeCommandInvocation const char *path = argv[3]; const char *cookie_name = argv[4]; g_autofree char *cookie_file = g_strdup_printf ("%s.cookies.txt", remote_name); - if (!ot_delete_cookie_at (ostree_repo_get_dfd (repo), cookie_file, domain, path, cookie_name, error)) + if (!ot_delete_cookie_at (ostree_repo_get_dfd (repo), cookie_file, domain, path, cookie_name, + error)) return FALSE; return TRUE; diff --git a/src/ostree/ot-remote-builtin-delete.c b/src/ostree/ot-remote-builtin-delete.c index eb60783c..e5e310f3 100644 --- a/src/ostree/ot-remote-builtin-delete.c +++ b/src/ostree/ot-remote-builtin-delete.c @@ -33,27 +33,29 @@ static char *opt_repo; * man page (man/ostree-remote.xml) when changing the option list. */ -static GOptionEntry option_entries[] = { - { "if-exists", 0, 0, G_OPTION_ARG_NONE, &opt_if_exists, "Do nothing if the provided remote does not exist", NULL }, - { "repo", 0, 0, G_OPTION_ARG_FILENAME, &opt_repo, "Path to OSTree repository (defaults to /sysroot/ostree/repo)", "PATH" }, - { "sysroot", 0, 0, G_OPTION_ARG_FILENAME, &opt_sysroot, "Use sysroot at PATH (overrides --repo)", "PATH" }, - { NULL } -}; +static GOptionEntry option_entries[] + = { { "if-exists", 0, 0, G_OPTION_ARG_NONE, &opt_if_exists, + "Do nothing if the provided remote does not exist", NULL }, + { "repo", 0, 0, G_OPTION_ARG_FILENAME, &opt_repo, + "Path to OSTree repository (defaults to /sysroot/ostree/repo)", "PATH" }, + { "sysroot", 0, 0, G_OPTION_ARG_FILENAME, &opt_sysroot, + "Use sysroot at PATH (overrides --repo)", "PATH" }, + { NULL } }; gboolean -ot_remote_builtin_delete (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_remote_builtin_delete (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("NAME"); + g_autoptr (GOptionContext) context = g_option_context_new ("NAME"); - if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - invocation, NULL, cancellable, error)) + if (!ostree_option_context_parse (context, option_entries, &argc, &argv, invocation, NULL, + cancellable, error)) return FALSE; - g_autoptr(OstreeSysroot) sysroot = NULL; - g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_parse_sysroot_or_repo_option (context, opt_sysroot, opt_repo, - &sysroot, &repo, + g_autoptr (OstreeSysroot) sysroot = NULL; + g_autoptr (OstreeRepo) repo = NULL; + if (!ostree_parse_sysroot_or_repo_option (context, opt_sysroot, opt_repo, &sysroot, &repo, cancellable, error)) return FALSE; @@ -66,10 +68,9 @@ ot_remote_builtin_delete (int argc, char **argv, OstreeCommandInvocation *invoca const char *remote_name = argv[1]; if (!ostree_repo_remote_change (repo, NULL, - opt_if_exists ? OSTREE_REPO_REMOTE_CHANGE_DELETE_IF_EXISTS : - OSTREE_REPO_REMOTE_CHANGE_DELETE, - remote_name, NULL, NULL, - cancellable, error)) + opt_if_exists ? OSTREE_REPO_REMOTE_CHANGE_DELETE_IF_EXISTS + : OSTREE_REPO_REMOTE_CHANGE_DELETE, + remote_name, NULL, NULL, cancellable, error)) return FALSE; return TRUE; diff --git a/src/ostree/ot-remote-builtin-gpg-import.c b/src/ostree/ot-remote-builtin-gpg-import.c index ba4aa3b4..0d9744e5 100644 --- a/src/ostree/ot-remote-builtin-gpg-import.c +++ b/src/ostree/ot-remote-builtin-gpg-import.c @@ -19,8 +19,8 @@ #include "config.h" -#include #include +#include #include "otutil.h" @@ -38,18 +38,16 @@ static char **opt_keyrings; * man page (man/ostree-remote.xml) when changing the option list. */ -static GOptionEntry option_entries[] = { - { "keyring", 'k', 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_keyrings, "Import keys from a keyring file (repeatable)", "FILE" }, - { "stdin", 0, 0, G_OPTION_ARG_NONE, &opt_stdin, "Import keys from standard input", NULL }, - { NULL } -}; +static GOptionEntry option_entries[] + = { { "keyring", 'k', 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_keyrings, + "Import keys from a keyring file (repeatable)", "FILE" }, + { "stdin", 0, 0, G_OPTION_ARG_NONE, &opt_stdin, "Import keys from standard input", NULL }, + { NULL } }; static gboolean -open_source_stream (GInputStream **out_source_stream, - GCancellable *cancellable, - GError **error) +open_source_stream (GInputStream **out_source_stream, GCancellable *cancellable, GError **error) { - g_autoptr(GInputStream) source_stream = NULL; + g_autoptr (GInputStream) source_stream = NULL; guint n_keyrings = 0; gboolean ret = FALSE; @@ -62,14 +60,14 @@ open_source_stream (GInputStream **out_source_stream, } else { - g_autoptr(GPtrArray) streams = NULL; + g_autoptr (GPtrArray) streams = NULL; guint ii; streams = g_ptr_array_new_with_free_func (g_object_unref); for (ii = 0; ii < n_keyrings; ii++) { - g_autoptr(GFile) file = NULL; + g_autoptr (GFile) file = NULL; GFileInputStream *input_stream = NULL; file = g_file_new_for_path (opt_keyrings[ii]); @@ -82,8 +80,8 @@ open_source_stream (GInputStream **out_source_stream, g_ptr_array_add (streams, input_stream); } - /* Chain together all the --keyring options as one long stream. */ - source_stream = (GInputStream *) ostree_chain_input_stream_new (streams); + /* Chain together all the --keyring options as one long stream. */ + source_stream = (GInputStream *)ostree_chain_input_stream_new (streams); } *out_source_stream = g_steal_pointer (&source_stream); @@ -95,20 +93,21 @@ out: } gboolean -ot_remote_builtin_gpg_import (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_remote_builtin_gpg_import (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeRepo) repo = NULL; - g_autoptr(GInputStream) source_stream = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeRepo) repo = NULL; + g_autoptr (GInputStream) source_stream = NULL; const char *remote_name; - const char * const *key_ids; + const char *const *key_ids; guint imported = 0; gboolean ret = FALSE; context = g_option_context_new ("NAME [KEY-ID...]"); - if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, option_entries, &argc, &argv, invocation, &repo, + cancellable, error)) goto out; if (argc < 2) @@ -124,21 +123,21 @@ ot_remote_builtin_gpg_import (int argc, char **argv, OstreeCommandInvocation *in } remote_name = argv[1]; - key_ids = (argc > 2) ? (const char * const *) argv + 2 : NULL; + key_ids = (argc > 2) ? (const char *const *)argv + 2 : NULL; if (!open_source_stream (&source_stream, cancellable, error)) goto out; - if (!ostree_repo_remote_gpg_import (repo, remote_name, source_stream, - key_ids, &imported, cancellable, error)) + if (!ostree_repo_remote_gpg_import (repo, remote_name, source_stream, key_ids, &imported, + cancellable, error)) goto out; /* XXX If we ever add internationalization, use ngettext() here. */ - g_print ("Imported %u GPG key%s to remote \"%s\"\n", - imported, (imported == 1) ? "" : "s", remote_name); + g_print ("Imported %u GPG key%s to remote \"%s\"\n", imported, (imported == 1) ? "" : "s", + remote_name); ret = TRUE; - out: +out: return ret; } diff --git a/src/ostree/ot-remote-builtin-gpg-list-keys.c b/src/ostree/ot-remote-builtin-gpg-list-keys.c index d0a388ee..8bd4c6b1 100644 --- a/src/ostree/ot-remote-builtin-gpg-list-keys.c +++ b/src/ostree/ot-remote-builtin-gpg-list-keys.c @@ -21,8 +21,8 @@ #include "otutil.h" -#include "ot-main.h" #include "ot-dump.h" +#include "ot-main.h" #include "ot-remote-builtins.h" /* ATTENTION: @@ -30,28 +30,22 @@ * man page (man/ostree-remote.xml) when changing the option list. */ -static GOptionEntry option_entries[] = { - { NULL } -}; +static GOptionEntry option_entries[] = { { NULL } }; gboolean -ot_remote_builtin_list_gpg_keys (int argc, - char **argv, - OstreeCommandInvocation *invocation, - GCancellable *cancellable, - GError **error) +ot_remote_builtin_list_gpg_keys (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("NAME"); - g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - invocation, &repo, cancellable, error)) + g_autoptr (GOptionContext) context = g_option_context_new ("NAME"); + g_autoptr (OstreeRepo) repo = NULL; + if (!ostree_option_context_parse (context, option_entries, &argc, &argv, invocation, &repo, + cancellable, error)) return FALSE; const char *remote_name = (argc > 1) ? argv[1] : NULL; - g_autoptr(GPtrArray) keys = NULL; - if (!ostree_repo_remote_get_gpg_keys (repo, remote_name, NULL, &keys, - cancellable, error)) + g_autoptr (GPtrArray) keys = NULL; + if (!ostree_repo_remote_get_gpg_keys (repo, remote_name, NULL, &keys, cancellable, error)) return FALSE; for (guint i = 0; i < keys->len; i++) diff --git a/src/ostree/ot-remote-builtin-list-cookies.c b/src/ostree/ot-remote-builtin-list-cookies.c index 04e7573b..2e576d50 100644 --- a/src/ostree/ot-remote-builtin-list-cookies.c +++ b/src/ostree/ot-remote-builtin-list-cookies.c @@ -22,9 +22,9 @@ #include "otutil.h" +#include "ostree-repo-private.h" #include "ot-main.h" #include "ot-remote-builtins.h" -#include "ostree-repo-private.h" #include "ot-remote-cookie-util.h" /* ATTENTION: @@ -32,18 +32,17 @@ * man page (man/ostree-remote.xml) when changing the option list. */ -static GOptionEntry option_entries[] = { - { NULL } -}; +static GOptionEntry option_entries[] = { { NULL } }; gboolean -ot_remote_builtin_list_cookies (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_remote_builtin_list_cookies (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(OstreeRepo) repo = NULL; - g_autoptr(GOptionContext) context = g_option_context_new ("NAME"); + g_autoptr (OstreeRepo) repo = NULL; + g_autoptr (GOptionContext) context = g_option_context_new ("NAME"); - if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, option_entries, &argc, &argv, invocation, &repo, + cancellable, error)) return FALSE; if (argc < 2) diff --git a/src/ostree/ot-remote-builtin-list.c b/src/ostree/ot-remote-builtin-list.c index b8e875d4..31c60ec0 100644 --- a/src/ostree/ot-remote-builtin-list.c +++ b/src/ostree/ot-remote-builtin-list.c @@ -29,23 +29,23 @@ static gboolean opt_show_urls; * man page (man/ostree-remote.xml) when changing the option list. */ -static GOptionEntry option_entries[] = { - { "show-urls", 'u', 0, G_OPTION_ARG_NONE, &opt_show_urls, "Show remote URLs in list", NULL }, - { NULL } -}; +static GOptionEntry option_entries[] = { { "show-urls", 'u', 0, G_OPTION_ARG_NONE, &opt_show_urls, + "Show remote URLs in list", NULL }, + { NULL } }; gboolean -ot_remote_builtin_list (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_remote_builtin_list (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new (""); + g_autoptr (GOptionContext) context = g_option_context_new (""); - g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - invocation, &repo, cancellable, error)) + g_autoptr (OstreeRepo) repo = NULL; + if (!ostree_option_context_parse (context, option_entries, &argc, &argv, invocation, &repo, + cancellable, error)) return FALSE; guint n_remotes = 0; - g_auto(GStrv) remotes = ostree_repo_remote_list (repo, &n_remotes); + g_auto (GStrv) remotes = ostree_repo_remote_list (repo, &n_remotes); if (opt_show_urls) { diff --git a/src/ostree/ot-remote-builtin-refs.c b/src/ostree/ot-remote-builtin-refs.c index 24ad0776..103c9134 100644 --- a/src/ostree/ot-remote-builtin-refs.c +++ b/src/ostree/ot-remote-builtin-refs.c @@ -25,27 +25,27 @@ #include "ot-remote-builtins.h" static gboolean opt_revision; -static char* opt_cache_dir; +static char *opt_cache_dir; /* ATTENTION: * Please remember to update the bash-completion script (bash/ostree) and * man page (man/ostree-remote.xml) when changing the option list. */ -static GOptionEntry option_entries[] = { - { "revision", 'r', 0, G_OPTION_ARG_NONE, &opt_revision, "Show revisions in listing", NULL }, - { "cache-dir", 0, 0, G_OPTION_ARG_FILENAME, &opt_cache_dir, "Use custom cache dir", NULL }, - { NULL } -}; +static GOptionEntry option_entries[] + = { { "revision", 'r', 0, G_OPTION_ARG_NONE, &opt_revision, "Show revisions in listing", NULL }, + { "cache-dir", 0, 0, G_OPTION_ARG_FILENAME, &opt_cache_dir, "Use custom cache dir", NULL }, + { NULL } }; gboolean -ot_remote_builtin_refs (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_remote_builtin_refs (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = g_option_context_new ("NAME"); + g_autoptr (GOptionContext) context = g_option_context_new ("NAME"); - g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - invocation, &repo, cancellable, error)) + g_autoptr (OstreeRepo) repo = NULL; + if (!ostree_option_context_parse (context, option_entries, &argc, &argv, invocation, &repo, + cancellable, error)) return FALSE; if (argc < 2) @@ -61,17 +61,17 @@ ot_remote_builtin_refs (int argc, char **argv, OstreeCommandInvocation *invocati } const char *remote_name = argv[1]; - g_autoptr(GHashTable) refs = NULL; + g_autoptr (GHashTable) refs = NULL; if (!ostree_repo_remote_list_refs (repo, remote_name, &refs, cancellable, error)) return FALSE; else { - g_autoptr(GList) ordered_keys = NULL; + g_autoptr (GList) ordered_keys = NULL; GList *iter = NULL; ordered_keys = g_hash_table_get_keys (refs); - ordered_keys = g_list_sort (ordered_keys, (GCompareFunc) strcmp); + ordered_keys = g_list_sort (ordered_keys, (GCompareFunc)strcmp); for (iter = ordered_keys; iter; iter = iter->next) { diff --git a/src/ostree/ot-remote-builtin-show-url.c b/src/ostree/ot-remote-builtin-show-url.c index f63908a9..f8316536 100644 --- a/src/ostree/ot-remote-builtin-show-url.c +++ b/src/ostree/ot-remote-builtin-show-url.c @@ -29,23 +29,22 @@ * man page (man/ostree-remote.xml) when changing the option list. */ -static GOptionEntry option_entries[] = { - { NULL } -}; +static GOptionEntry option_entries[] = { { NULL } }; gboolean -ot_remote_builtin_show_url (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_remote_builtin_show_url (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeRepo) repo = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeRepo) repo = NULL; const char *remote_name; g_autofree char *remote_url = NULL; gboolean ret = FALSE; context = g_option_context_new ("NAME"); - if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, option_entries, &argc, &argv, invocation, &repo, + cancellable, error)) goto out; if (argc < 2) @@ -62,6 +61,6 @@ ot_remote_builtin_show_url (int argc, char **argv, OstreeCommandInvocation *invo ret = TRUE; } - out: +out: return ret; } diff --git a/src/ostree/ot-remote-builtin-summary.c b/src/ostree/ot-remote-builtin-summary.c index 55ccc396..ec508cbb 100644 --- a/src/ostree/ot-remote-builtin-summary.c +++ b/src/ostree/ot-remote-builtin-summary.c @@ -21,37 +21,39 @@ #include "otutil.h" -#include "ot-main.h" #include "ot-dump.h" +#include "ot-main.h" #include "ot-remote-builtins.h" static gboolean opt_list_metadata_keys; static gboolean opt_raw; static char *opt_print_metadata_key; -static char* opt_cache_dir; +static char *opt_cache_dir; /* ATTENTION: * Please remember to update the bash-completion script (bash/ostree) and * man page (man/ostree-remote.xml) when changing the option list. */ -static GOptionEntry option_entries[] = { - { "list-metadata-keys", 0, 0, G_OPTION_ARG_NONE, &opt_list_metadata_keys, "List the available metadata keys", NULL }, - { "print-metadata-key", 0, 0, G_OPTION_ARG_STRING, &opt_print_metadata_key, "Print string value of metadata key", "KEY" }, - { "cache-dir", 0, 0, G_OPTION_ARG_FILENAME, &opt_cache_dir, "Use custom cache dir", NULL }, - { "raw", 0, 0, G_OPTION_ARG_NONE, &opt_raw, "Show raw variant data", NULL }, - { NULL } -}; +static GOptionEntry option_entries[] + = { { "list-metadata-keys", 0, 0, G_OPTION_ARG_NONE, &opt_list_metadata_keys, + "List the available metadata keys", NULL }, + { "print-metadata-key", 0, 0, G_OPTION_ARG_STRING, &opt_print_metadata_key, + "Print string value of metadata key", "KEY" }, + { "cache-dir", 0, 0, G_OPTION_ARG_FILENAME, &opt_cache_dir, "Use custom cache dir", NULL }, + { "raw", 0, 0, G_OPTION_ARG_NONE, &opt_raw, "Show raw variant data", NULL }, + { NULL } }; gboolean -ot_remote_builtin_summary (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) +ot_remote_builtin_summary (int argc, char **argv, OstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeRepo) repo = NULL; + g_autoptr (GOptionContext) context = NULL; + g_autoptr (OstreeRepo) repo = NULL; const char *remote_name; - g_autoptr(GBytes) summary_bytes = NULL; - g_autoptr(GBytes) signature_bytes = NULL; + g_autoptr (GBytes) summary_bytes = NULL; + g_autoptr (GBytes) signature_bytes = NULL; OstreeDumpFlags flags = OSTREE_DUMP_NONE; #ifndef OSTREE_DISABLE_GPGME gboolean gpg_verify_summary; @@ -60,8 +62,8 @@ ot_remote_builtin_summary (int argc, char **argv, OstreeCommandInvocation *invoc context = g_option_context_new ("NAME"); - if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - invocation, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, option_entries, &argc, &argv, invocation, &repo, + cancellable, error)) goto out; if (argc < 2) @@ -81,16 +83,13 @@ ot_remote_builtin_summary (int argc, char **argv, OstreeCommandInvocation *invoc if (opt_raw) flags |= OSTREE_DUMP_RAW; - if (!ostree_repo_remote_fetch_summary (repo, remote_name, - &summary_bytes, - &signature_bytes, + if (!ostree_repo_remote_fetch_summary (repo, remote_name, &summary_bytes, &signature_bytes, cancellable, error)) goto out; if (summary_bytes == NULL) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Remote server has no summary file"); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Remote server has no summary file"); goto out; } @@ -108,8 +107,7 @@ ot_remote_builtin_summary (int argc, char **argv, OstreeCommandInvocation *invoc ot_dump_summary_bytes (summary_bytes, flags); #ifndef OSTREE_DISABLE_GPGME - if (!ostree_repo_remote_get_gpg_verify_summary (repo, remote_name, - &gpg_verify_summary, + if (!ostree_repo_remote_get_gpg_verify_summary (repo, remote_name, &gpg_verify_summary, error)) goto out; @@ -123,17 +121,13 @@ ot_remote_builtin_summary (int argc, char **argv, OstreeCommandInvocation *invoc * option for raw signature data like "--raw-signatures". */ if (signature_bytes != NULL && !opt_raw) { - g_autoptr(OstreeGpgVerifyResult) result = NULL; + g_autoptr (OstreeGpgVerifyResult) result = NULL; /* The actual signed summary verification happens above in * ostree_repo_remote_fetch_summary(). Here we just parse * the signatures again for the purpose of printing. */ - result = ostree_repo_verify_summary (repo, - remote_name, - summary_bytes, - signature_bytes, - cancellable, - error); + result = ostree_repo_verify_summary (repo, remote_name, summary_bytes, signature_bytes, + cancellable, error); if (result == NULL) goto out; diff --git a/src/ostree/ot-remote-builtins.h b/src/ostree/ot-remote-builtins.h index 4a0482a7..0386478f 100644 --- a/src/ostree/ot-remote-builtins.h +++ b/src/ostree/ot-remote-builtins.h @@ -23,23 +23,23 @@ G_BEGIN_DECLS -#define BUILTINPROTO(name) gboolean ot_remote_builtin_ ## name (int argc, char **argv, \ - OstreeCommandInvocation *invocation, \ - GCancellable *cancellable, GError **error) +#define BUILTINPROTO(name) \ + gboolean ot_remote_builtin_##name (int argc, char **argv, OstreeCommandInvocation *invocation, \ + GCancellable *cancellable, GError **error) -BUILTINPROTO(add); -BUILTINPROTO(delete); -BUILTINPROTO(gpg_import); -BUILTINPROTO(list_gpg_keys); -BUILTINPROTO(list); +BUILTINPROTO (add); +BUILTINPROTO (delete); +BUILTINPROTO (gpg_import); +BUILTINPROTO (list_gpg_keys); +BUILTINPROTO (list); #ifdef HAVE_LIBCURL_OR_LIBSOUP -BUILTINPROTO(add_cookie); -BUILTINPROTO(list_cookies); -BUILTINPROTO(delete_cookie); +BUILTINPROTO (add_cookie); +BUILTINPROTO (list_cookies); +BUILTINPROTO (delete_cookie); #endif -BUILTINPROTO(show_url); -BUILTINPROTO(refs); -BUILTINPROTO(summary); +BUILTINPROTO (show_url); +BUILTINPROTO (refs); +BUILTINPROTO (summary); #undef BUILTINPROTO diff --git a/src/ostree/ot-remote-cookie-util.c b/src/ostree/ot-remote-cookie-util.c index 8cf1eb07..5b15dd3d 100644 --- a/src/ostree/ot-remote-cookie-util.c +++ b/src/ostree/ot-remote-cookie-util.c @@ -22,13 +22,14 @@ #include "ot-remote-cookie-util.h" -#include "otutil.h" +#include "ostree-repo-private.h" #include "ot-main.h" #include "ot-remote-builtins.h" -#include "ostree-repo-private.h" +#include "otutil.h" typedef struct OtCookieParser OtCookieParser; -struct OtCookieParser { +struct OtCookieParser +{ char *buf; char *iter; @@ -42,15 +43,11 @@ struct OtCookieParser { char *value; }; void ot_cookie_parser_free (OtCookieParser *parser); -G_DEFINE_AUTOPTR_CLEANUP_FUNC(OtCookieParser, ot_cookie_parser_free) +G_DEFINE_AUTOPTR_CLEANUP_FUNC (OtCookieParser, ot_cookie_parser_free) -gboolean -ot_parse_cookies_at (int dfd, const char *path, - OtCookieParser **out_parser, - GCancellable *cancellable, - GError **error); -gboolean -ot_parse_cookies_next (OtCookieParser *parser); +gboolean ot_parse_cookies_at (int dfd, const char *path, OtCookieParser **out_parser, + GCancellable *cancellable, GError **error); +gboolean ot_parse_cookies_next (OtCookieParser *parser); static void ot_cookie_parser_clear (OtCookieParser *parser) @@ -72,10 +69,8 @@ ot_cookie_parser_free (OtCookieParser *parser) } gboolean -ot_parse_cookies_at (int dfd, const char *path, - OtCookieParser **out_parser, - GCancellable *cancellable, - GError **error) +ot_parse_cookies_at (int dfd, const char *path, OtCookieParser **out_parser, + GCancellable *cancellable, GError **error) { OtCookieParser *parser; g_autofree char *cookies_content = NULL; @@ -120,14 +115,10 @@ ot_parse_cookies_next (OtCookieParser *parser) parser->iter = NULL; ot_cookie_parser_clear (parser); - if (sscanf (iter, "%ms\t%ms\t%ms\t%ms\t%llu\t%ms\t%ms", - &parser->domain, - &parser->flag, - &parser->path, - &parser->secure, - &parser->expiration, - &parser->name, - &parser->value) != 7) + if (sscanf (iter, "%ms\t%ms\t%ms\t%ms\t%llu\t%ms\t%ms", &parser->domain, &parser->flag, + &parser->path, &parser->secure, &parser->expiration, &parser->name, + &parser->value) + != 7) continue; parser->line = iter; @@ -138,69 +129,58 @@ ot_parse_cookies_next (OtCookieParser *parser) } gboolean -ot_add_cookie_at (int dfd, const char *jar_path, - const char *domain, const char *path, - const char *name, const char *value, - GError **error) +ot_add_cookie_at (int dfd, const char *jar_path, const char *domain, const char *path, + const char *name, const char *value, GError **error) { glnx_autofd int fd = openat (dfd, jar_path, O_WRONLY | O_APPEND | O_CREAT, 0644); if (fd < 0) return glnx_throw_errno_prefix (error, "open(%s)", jar_path); - g_autoptr(GDateTime) now = g_date_time_new_now_utc (); - g_autoptr(GDateTime) expires = g_date_time_add_years (now, 25); + g_autoptr (GDateTime) now = g_date_time_new_now_utc (); + g_autoptr (GDateTime) expires = g_date_time_add_years (now, 25); /* Adapted from soup-cookie-jar-text.c:write_cookie() */ - g_autofree char *buf = g_strdup_printf ("%s\t%s\t%s\t%s\t%llu\t%s\t%s\n", - domain, - *domain == '.' ? "TRUE" : "FALSE", - path, - "FALSE", - (long long unsigned)g_date_time_to_unix (expires), - name, - value); + g_autofree char *buf = g_strdup_printf ( + "%s\t%s\t%s\t%s\t%llu\t%s\t%s\n", domain, *domain == '.' ? "TRUE" : "FALSE", path, "FALSE", + (long long unsigned)g_date_time_to_unix (expires), name, value); if (glnx_loop_write (fd, buf, strlen (buf)) < 0) return glnx_throw_errno_prefix (error, "write"); return TRUE; } gboolean -ot_delete_cookie_at (int dfd, const char *jar_path, - const char *domain, const char *path, - const char *name, - GError **error) +ot_delete_cookie_at (int dfd, const char *jar_path, const char *domain, const char *path, + const char *name, GError **error) { gboolean found = FALSE; - g_auto(GLnxTmpfile) tmpf = { 0, }; - g_autoptr(OtCookieParser) parser = NULL; + g_auto (GLnxTmpfile) tmpf = { + 0, + }; + g_autoptr (OtCookieParser) parser = NULL; if (!ot_parse_cookies_at (dfd, jar_path, &parser, NULL, error)) return FALSE; g_assert (!strchr (jar_path, '/')); - if (!glnx_open_tmpfile_linkable_at (dfd, ".", O_WRONLY | O_CLOEXEC, - &tmpf, error)) + if (!glnx_open_tmpfile_linkable_at (dfd, ".", O_WRONLY | O_CLOEXEC, &tmpf, error)) return FALSE; while (ot_parse_cookies_next (parser)) { - if (strcmp (domain, parser->domain) == 0 && - strcmp (path, parser->path) == 0 && - strcmp (name, parser->name) == 0) + if (strcmp (domain, parser->domain) == 0 && strcmp (path, parser->path) == 0 + && strcmp (name, parser->name) == 0) { found = TRUE; /* Match, skip writing this one */ continue; } - if (glnx_loop_write (tmpf.fd, parser->line, strlen (parser->line)) < 0 || - glnx_loop_write (tmpf.fd, "\n", 1) < 0) + if (glnx_loop_write (tmpf.fd, parser->line, strlen (parser->line)) < 0 + || glnx_loop_write (tmpf.fd, "\n", 1) < 0) return glnx_throw_errno_prefix (error, "write"); } - if (!glnx_link_tmpfile_at (&tmpf, GLNX_LINK_TMPFILE_REPLACE, - dfd, jar_path, - error)) + if (!glnx_link_tmpfile_at (&tmpf, GLNX_LINK_TMPFILE_REPLACE, dfd, jar_path, error)) return FALSE; if (!found) @@ -209,18 +189,17 @@ ot_delete_cookie_at (int dfd, const char *jar_path, return TRUE; } - gboolean ot_list_cookies_at (int dfd, const char *jar_path, GError **error) { - g_autoptr(OtCookieParser) parser = NULL; + g_autoptr (OtCookieParser) parser = NULL; if (!ot_parse_cookies_at (AT_FDCWD, jar_path, &parser, NULL, error)) return FALSE; while (ot_parse_cookies_next (parser)) { - g_autoptr(GDateTime) expires = g_date_time_new_from_unix_utc (parser->expiration); + g_autoptr (GDateTime) expires = g_date_time_new_from_unix_utc (parser->expiration); g_autofree char *expires_str = NULL; if (expires != NULL) diff --git a/src/ostree/ot-remote-cookie-util.h b/src/ostree/ot-remote-cookie-util.h index 838714f6..e0a84a1a 100644 --- a/src/ostree/ot-remote-cookie-util.h +++ b/src/ostree/ot-remote-cookie-util.h @@ -23,19 +23,12 @@ G_BEGIN_DECLS -gboolean -ot_add_cookie_at (int dfd, const char *jar_path, - const char *domain, const char *path, - const char *name, const char *value, - GError **error); +gboolean ot_add_cookie_at (int dfd, const char *jar_path, const char *domain, const char *path, + const char *name, const char *value, GError **error); -gboolean -ot_delete_cookie_at (int dfd, const char *jar_path, - const char *domain, const char *path, - const char *name, - GError **error); +gboolean ot_delete_cookie_at (int dfd, const char *jar_path, const char *domain, const char *path, + const char *name, GError **error); -gboolean -ot_list_cookies_at (int dfd, const char *jar_path, GError **error); +gboolean ot_list_cookies_at (int dfd, const char *jar_path, GError **error); G_END_DECLS diff --git a/src/rofiles-fuse/main.c b/src/rofiles-fuse/main.c index 7f49dd88..937ee4a6 100644 --- a/src/rofiles-fuse/main.c +++ b/src/rofiles-fuse/main.c @@ -23,19 +23,19 @@ #error config.h needs to define FUSE_USE_VERSION #endif -#include -#include -#include -#include +#include #include -#include -#include #include #include +#include +#include +#include +#include +#include +#include +#include #include -#include #include -#include #include @@ -98,11 +98,11 @@ callback_readlink (const char *path, char *buf, size_t size) static int #if FUSE_USE_VERSION >= 31 -callback_readdir (const char *path, void *buf, fuse_fill_dir_t filler, - off_t offset, struct fuse_file_info *fi, enum fuse_readdir_flags flags) +callback_readdir (const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, + struct fuse_file_info *fi, enum fuse_readdir_flags flags) #else -callback_readdir (const char *path, void *buf, fuse_fill_dir_t filler, - off_t offset, struct fuse_file_info *fi) +callback_readdir (const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, + struct fuse_file_info *fi) #endif { DIR *dp; @@ -146,7 +146,7 @@ callback_readdir (const char *path, void *buf, fuse_fill_dir_t filler, #endif } - (void) closedir (dp); + (void)closedir (dp); return 0; } @@ -195,8 +195,7 @@ callback_symlink (const char *from, const char *to) if (fstatat (basefd, to, &stbuf, AT_SYMLINK_NOFOLLOW) == -1) { - fprintf (stderr, "Failed to find newly created symlink '%s': %s\n", - to, g_strerror (errno)); + fprintf (stderr, "Failed to find newly created symlink '%s': %s\n", to, g_strerror (errno)); exit (EXIT_FAILURE); } return 0; @@ -277,8 +276,7 @@ gioerror_to_errno (GIOErrorEnum e) } static int -verify_write_or_copyup (const char *path, const struct stat *stbuf, - gboolean *out_did_copyup) +verify_write_or_copyup (const char *path, const struct stat *stbuf, gboolean *out_did_copyup) { struct stat stbuf_local; @@ -303,7 +301,7 @@ verify_write_or_copyup (const char *path, const struct stat *stbuf, { if (opt_copyup) { - g_autoptr(GError) tmp_error = NULL; + g_autoptr (GError) tmp_error = NULL; if (!ostree_break_hardlink (basefd, path, FALSE, NULL, &tmp_error)) return -gioerror_to_errno ((GIOErrorEnum)tmp_error->code); if (out_did_copyup) @@ -320,12 +318,15 @@ verify_write_or_copyup (const char *path, const struct stat *stbuf, * to a relative path (even for the caller) and * perform either write verification or copy-up. */ -#define PATH_WRITE_ENTRYPOINT(path) do { \ - path = ENSURE_RELPATH (path); \ - int r = verify_write_or_copyup (path, NULL, NULL); \ - if (r != 0) \ - return r; \ - } while (0) +#define PATH_WRITE_ENTRYPOINT(path) \ + do \ + { \ + path = ENSURE_RELPATH (path); \ + int r = verify_write_or_copyup (path, NULL, NULL); \ + if (r != 0) \ + return r; \ + } \ + while (0) static int #if FUSE_USE_VERSION >= 31 @@ -368,7 +369,7 @@ callback_truncate (const char *path, off_t size) { PATH_WRITE_ENTRYPOINT (path); - glnx_autofd int fd = openat (basefd, path, O_NOFOLLOW|O_WRONLY); + glnx_autofd int fd = openat (basefd, path, O_NOFOLLOW | O_WRONLY); if (fd == -1) return -errno; @@ -422,7 +423,7 @@ do_open (const char *path, mode_t mode, struct fuse_file_info *finfo) if (fstat (fd, &stbuf) == -1) { - (void) close (fd); + (void)close (fd); return -errno; } @@ -430,20 +431,20 @@ do_open (const char *path, mode_t mode, struct fuse_file_info *finfo) int r = verify_write_or_copyup (path, &stbuf, &did_copyup); if (r != 0) { - (void) close (fd); + (void)close (fd); return r; } /* In the copyup case, we need to re-open */ if (did_copyup) { - (void) close (fd); + (void)close (fd); /* Note that unlike the initial open, we will pass through * O_TRUNC. More ideally in this copyup case we'd avoid copying * the whole file in the first place, but eh. It's not like we're * high performance anyways. */ - fd = openat (basefd, path, finfo->flags & ~(O_EXCL|O_CREAT), mode); + fd = openat (basefd, path, finfo->flags & ~(O_EXCL | O_CREAT), mode); if (fd == -1) return -errno; } @@ -456,7 +457,7 @@ do_open (const char *path, mode_t mode, struct fuse_file_info *finfo) { if (ftruncate (fd, 0) == -1) { - (void) close (fd); + (void)close (fd); return -errno; } } @@ -475,14 +476,14 @@ callback_open (const char *path, struct fuse_file_info *finfo) } static int -callback_create(const char *path, mode_t mode, struct fuse_file_info *finfo) +callback_create (const char *path, mode_t mode, struct fuse_file_info *finfo) { return do_open (path, mode, finfo); } static int -callback_read_buf (const char *path, struct fuse_bufvec **bufp, - size_t size, off_t offset, struct fuse_file_info *finfo) +callback_read_buf (const char *path, struct fuse_bufvec **bufp, size_t size, off_t offset, + struct fuse_file_info *finfo) { struct fuse_bufvec *src; @@ -501,8 +502,7 @@ callback_read_buf (const char *path, struct fuse_bufvec **bufp, } static int -callback_read (const char *path, char *buf, size_t size, off_t offset, - struct fuse_file_info *finfo) +callback_read (const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *finfo) { int r; r = pread (finfo->fh, buf, size, offset); @@ -546,7 +546,7 @@ callback_statfs (const char *path, struct statvfs *st_buf) static int callback_release (const char *path, struct fuse_file_info *finfo) { - (void) close (finfo->fh); + (void)close (finfo->fh); return 0; } @@ -573,8 +573,7 @@ callback_access (const char *path, int mode) } static int -callback_setxattr (const char *path, const char *name, const char *value, - size_t size, int flags) +callback_setxattr (const char *path, const char *name, const char *value, size_t size, int flags) { PATH_WRITE_ENTRYPOINT (path); @@ -587,8 +586,7 @@ callback_setxattr (const char *path, const char *name, const char *value, } static int -callback_getxattr (const char *path, const char *name, char *value, - size_t size) +callback_getxattr (const char *path, const char *name, char *value, size_t size) { path = ENSURE_RELPATH (path); @@ -634,40 +632,39 @@ callback_removexattr (const char *path, const char *name) return 0; } -struct fuse_operations callback_oper = { - .getattr = callback_getattr, - .readlink = callback_readlink, - .readdir = callback_readdir, - .mknod = callback_mknod, - .mkdir = callback_mkdir, - .symlink = callback_symlink, - .unlink = callback_unlink, - .rmdir = callback_rmdir, - .rename = callback_rename, - .link = callback_link, - .chmod = callback_chmod, - .chown = callback_chown, - .truncate = callback_truncate, - .utimens = callback_utimens, - .create = callback_create, - .open = callback_open, - .read_buf = callback_read_buf, - .read = callback_read, - .write_buf = callback_write_buf, - .write = callback_write, - .statfs = callback_statfs, - .release = callback_release, - .fsync = callback_fsync, - .access = callback_access, - - /* Extended attributes support for userland interaction */ - .setxattr = callback_setxattr, - .getxattr = callback_getxattr, - .listxattr = callback_listxattr, - .removexattr = callback_removexattr -}; - -enum { +struct fuse_operations callback_oper = { .getattr = callback_getattr, + .readlink = callback_readlink, + .readdir = callback_readdir, + .mknod = callback_mknod, + .mkdir = callback_mkdir, + .symlink = callback_symlink, + .unlink = callback_unlink, + .rmdir = callback_rmdir, + .rename = callback_rename, + .link = callback_link, + .chmod = callback_chmod, + .chown = callback_chown, + .truncate = callback_truncate, + .utimens = callback_utimens, + .create = callback_create, + .open = callback_open, + .read_buf = callback_read_buf, + .read = callback_read, + .write_buf = callback_write_buf, + .write = callback_write, + .statfs = callback_statfs, + .release = callback_release, + .fsync = callback_fsync, + .access = callback_access, + + /* Extended attributes support for userland interaction */ + .setxattr = callback_setxattr, + .getxattr = callback_getxattr, + .listxattr = callback_listxattr, + .removexattr = callback_removexattr }; + +enum +{ KEY_HELP, KEY_VERSION, KEY_COPYUP, @@ -679,26 +676,28 @@ usage (const char *progname) fprintf (stdout, "usage: %s basepath mountpoint [options]\n" "\n" - " Makes basepath visible at mountpoint such that files are read-only, directories are writable\n" + " Makes basepath visible at mountpoint such that files are read-only, directories " + "are writable\n" "\n" "general options:\n" " -o opt,[opt...] mount options\n" " -h --help print help\n" - "\n", progname); + "\n", + progname); } static int -rofs_parse_opt (void *data, const char *arg, int key, - struct fuse_args *outargs) +rofs_parse_opt (void *data, const char *arg, int key, struct fuse_args *outargs) { - (void) data; + (void)data; switch (key) { case FUSE_OPT_KEY_NONOPT: if (basefd == -1) { - basefd = openat (AT_FDCWD, arg, O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOCTTY); + basefd + = openat (AT_FDCWD, arg, O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOCTTY); if (basefd == -1) err (1, "opening rootfs %s", arg); return 0; @@ -722,14 +721,10 @@ rofs_parse_opt (void *data, const char *arg, int key, return 1; } -static struct fuse_opt rofs_opts[] = { - FUSE_OPT_KEY ("-h", KEY_HELP), - FUSE_OPT_KEY ("--help", KEY_HELP), - FUSE_OPT_KEY ("-V", KEY_VERSION), - FUSE_OPT_KEY ("--version", KEY_VERSION), - FUSE_OPT_KEY ("--copyup", KEY_COPYUP), - FUSE_OPT_END -}; +static struct fuse_opt rofs_opts[] + = { FUSE_OPT_KEY ("-h", KEY_HELP), FUSE_OPT_KEY ("--help", KEY_HELP), + FUSE_OPT_KEY ("-V", KEY_VERSION), FUSE_OPT_KEY ("--version", KEY_VERSION), + FUSE_OPT_KEY ("--copyup", KEY_COPYUP), FUSE_OPT_END }; int main (int argc, char *argv[]) diff --git a/src/switchroot/ostree-mount-util.h b/src/switchroot/ostree-mount-util.h index 92bc8027..9d79f0cb 100644 --- a/src/switchroot/ostree-mount-util.h +++ b/src/switchroot/ostree-mount-util.h @@ -22,13 +22,13 @@ #define __OSTREE_MOUNT_UTIL_H_ #include +#include +#include +#include #include +#include #include -#include #include -#include -#include -#include #define INITRAMFS_MOUNT_VAR "/run/ostree/initramfs-mount-var" #define _OSTREE_SYSROOT_READONLY_STAMP "/run/ostree-sysroot-ro.stamp" @@ -47,7 +47,7 @@ path_is_on_readonly_fs (const char *path) static inline char * read_proc_cmdline (void) { - FILE *f = fopen("/proc/cmdline", "r"); + FILE *f = fopen ("/proc/cmdline", "r"); char *cmdline = NULL; size_t len; @@ -64,8 +64,8 @@ read_proc_cmdline (void) */ len = strlen (cmdline); - if (cmdline[len-1] == '\n') - cmdline[len-1] = '\0'; + if (cmdline[len - 1] == '\n') + cmdline[len - 1] = '\0'; out: if (f) fclose (f); @@ -118,7 +118,7 @@ touch_run_ostree (void) */ if (fd == -1) return; - (void) close (fd); + (void)close (fd); } #endif /* __OSTREE_MOUNT_UTIL_H_ */ diff --git a/src/switchroot/ostree-prepare-root.c b/src/switchroot/ostree-prepare-root.c index a5fbc8a8..a8af4e21 100644 --- a/src/switchroot/ostree-prepare-root.c +++ b/src/switchroot/ostree-prepare-root.c @@ -51,22 +51,22 @@ #include "config.h" -#include -#include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include #include #include +#include #include -#include #include -#include -#include -#include +#include +#include +#include +#include +#include +#include #if defined(HAVE_LIBSYSTEMD) && !defined(OSTREE_PREPARE_ROOT_STATIC) #define USE_LIBSYSTEMD @@ -74,7 +74,8 @@ #ifdef USE_LIBSYSTEMD #include -#define OSTREE_PREPARE_ROOT_DEPLOYMENT_MSG SD_ID128_MAKE(71,70,33,6a,73,ba,46,01,ba,d3,1a,f8,88,aa,0d,f7) +#define OSTREE_PREPARE_ROOT_DEPLOYMENT_MSG \ + SD_ID128_MAKE (71, 70, 33, 6a, 73, ba, 46, 01, ba, d3, 1a, f8, 88, aa, 0d, f7) #endif #include "ostree-mount-util.h" @@ -82,9 +83,9 @@ static inline bool sysroot_is_configured_ro (const char *sysroot) { - char * config_path = NULL; + char *config_path = NULL; assert (asprintf (&config_path, "%s/ostree/repo/config", sysroot) != -1); - FILE *f = fopen(config_path, "r"); + FILE *f = fopen (config_path, "r"); if (!f) { fprintf (stderr, "Missing expected repo config: %s\n", config_path); @@ -119,8 +120,8 @@ sysroot_is_configured_ro (const char *sysroot) return ret; } -static char* -resolve_deploy_path (const char * root_mountpoint) +static char * +resolve_deploy_path (const char *root_mountpoint) { char destpath[PATH_MAX]; struct stat stbuf; @@ -130,7 +131,7 @@ resolve_deploy_path (const char * root_mountpoint) if (!ostree_target) errx (EXIT_FAILURE, "No OSTree target; expected ostree=/ostree/boot.N/..."); - if (snprintf (destpath, sizeof(destpath), "%s/%s", root_mountpoint, ostree_target) < 0) + if (snprintf (destpath, sizeof (destpath), "%s/%s", root_mountpoint, ostree_target) < 0) err (EXIT_FAILURE, "failed to assemble ostree target path"); if (lstat (destpath, &stbuf) < 0) err (EXIT_FAILURE, "Couldn't find specified OSTree root '%s'", destpath); @@ -141,28 +142,26 @@ resolve_deploy_path (const char * root_mountpoint) err (EXIT_FAILURE, "realpath(%s) failed", destpath); if (stat (deploy_path, &stbuf) < 0) err (EXIT_FAILURE, "stat(%s) failed", deploy_path); - /* Quiet logs if there's no journal */ + /* Quiet logs if there's no journal */ #ifdef USE_LIBSYSTEMD const char *resolved_path = deploy_path + strlen (root_mountpoint); sd_journal_send ("MESSAGE=Resolved OSTree target to: %s", deploy_path, "MESSAGE_ID=" SD_ID128_FORMAT_STR, - SD_ID128_FORMAT_VAL(OSTREE_PREPARE_ROOT_DEPLOYMENT_MSG), - "DEPLOYMENT_PATH=%s", resolved_path, - "DEPLOYMENT_DEVICE=%" PRIu64, (uint64_t) stbuf.st_dev, - "DEPLOYMENT_INODE=%" PRIu64, (uint64_t) stbuf.st_ino, - NULL); + SD_ID128_FORMAT_VAL (OSTREE_PREPARE_ROOT_DEPLOYMENT_MSG), "DEPLOYMENT_PATH=%s", + resolved_path, "DEPLOYMENT_DEVICE=%" PRIu64, (uint64_t)stbuf.st_dev, + "DEPLOYMENT_INODE=%" PRIu64, (uint64_t)stbuf.st_ino, NULL); #endif return deploy_path; } static int -pivot_root(const char * new_root, const char * put_old) +pivot_root (const char *new_root, const char *put_old) { - return syscall(__NR_pivot_root, new_root, put_old); + return syscall (__NR_pivot_root, new_root, put_old); } int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { char srcpath[PATH_MAX]; @@ -188,8 +187,7 @@ main(int argc, char *argv[]) root_arg = argv[1]; } #ifdef USE_LIBSYSTEMD - sd_journal_send ("MESSAGE=preparing sysroot at %s", root_arg, - NULL); + sd_journal_send ("MESSAGE=preparing sysroot at %s", root_arg, NULL); #endif struct stat stbuf; @@ -223,11 +221,8 @@ main(int argc, char *argv[]) const bool sysroot_currently_writable = !path_is_on_readonly_fs (root_arg); #ifdef USE_LIBSYSTEMD sd_journal_send ("MESSAGE=filesystem at %s currently writable: %d", root_arg, - (int)sysroot_currently_writable, - NULL); - sd_journal_send ("MESSAGE=sysroot.readonly configuration value: %d", - (int)sysroot_readonly, - NULL); + (int)sysroot_currently_writable, NULL); + sd_journal_send ("MESSAGE=sysroot.readonly configuration value: %d", (int)sysroot_readonly, NULL); #endif /* Work-around for a kernel bug: for some reason the kernel @@ -260,19 +255,19 @@ main(int argc, char *argv[]) int fd = open (_OSTREE_SYSROOT_READONLY_STAMP, O_WRONLY | O_CREAT | O_CLOEXEC, 0644); if (fd < 0) err (EXIT_FAILURE, "failed to create %s", _OSTREE_SYSROOT_READONLY_STAMP); - (void) close (fd); + (void)close (fd); } /* Prepare /boot. * If /boot is on the same partition, use a bind mount to make it visible * at /boot inside the deployment. */ - if (snprintf (srcpath, sizeof(srcpath), "%s/boot/loader", root_mountpoint) < 0) + if (snprintf (srcpath, sizeof (srcpath), "%s/boot/loader", root_mountpoint) < 0) err (EXIT_FAILURE, "failed to assemble /boot/loader path"); if (lstat (srcpath, &stbuf) == 0 && S_ISLNK (stbuf.st_mode)) { if (lstat ("boot", &stbuf) == 0 && S_ISDIR (stbuf.st_mode)) { - if (snprintf (srcpath, sizeof(srcpath), "%s/boot", root_mountpoint) < 0) + if (snprintf (srcpath, sizeof (srcpath), "%s/boot", root_mountpoint) < 0) err (EXIT_FAILURE, "failed to assemble /boot path"); if (mount (srcpath, "boot", NULL, MS_BIND | MS_SILENT, NULL) < 0) err (EXIT_FAILURE, "failed to bind mount %s to boot", srcpath); @@ -283,13 +278,13 @@ main(int argc, char *argv[]) * No action required if sysroot is writable. Otherwise, a bind-mount for * the deployment needs to be created and remounted as read/write. */ if (sysroot_readonly) - { - /* Bind-mount /etc (at deploy path), and remount as writable. */ - if (mount ("etc", "etc", NULL, MS_BIND | MS_SILENT, NULL) < 0) - err (EXIT_FAILURE, "failed to prepare /etc bind-mount at %s", srcpath); - if (mount ("etc", "etc", NULL, MS_BIND | MS_REMOUNT | MS_SILENT, NULL) < 0) - err (EXIT_FAILURE, "failed to make writable /etc bind-mount at %s", srcpath); - } + { + /* Bind-mount /etc (at deploy path), and remount as writable. */ + if (mount ("etc", "etc", NULL, MS_BIND | MS_SILENT, NULL) < 0) + err (EXIT_FAILURE, "failed to prepare /etc bind-mount at %s", srcpath); + if (mount ("etc", "etc", NULL, MS_BIND | MS_REMOUNT | MS_SILENT, NULL) < 0) + err (EXIT_FAILURE, "failed to make writable /etc bind-mount at %s", srcpath); + } /* Prepare /usr. * It may be either just a read-only bind-mount, or a persistent overlayfs. */ @@ -333,9 +328,9 @@ main(int argc, char *argv[]) err (EXIT_FAILURE, "failed to make writable /var bind-mount at %s", srcpath); } - /* When running under systemd, /var will be handled by a 'var.mount' unit outside - * of initramfs. - * Systemd auto-detection can be overridden by a marker file under /run. */ + /* When running under systemd, /var will be handled by a 'var.mount' unit outside + * of initramfs. + * Systemd auto-detection can be overridden by a marker file under /run. */ #ifdef HAVE_SYSTEMD_AND_LIBMOUNT bool mount_var = false; #else @@ -345,9 +340,9 @@ main(int argc, char *argv[]) mount_var = true; /* If required, bind-mount `/var` in the deployment to the "stateroot", which is - * the shared persistent directory for a set of deployments. More info: - * https://ostreedev.github.io/ostree/deployment/#stateroot-aka-osname-group-of-deployments-that-share-var - */ + * the shared persistent directory for a set of deployments. More info: + * https://ostreedev.github.io/ostree/deployment/#stateroot-aka-osname-group-of-deployments-that-share-var + */ if (mount_var) { if (mount ("../../var", "var", NULL, MS_BIND | MS_SILENT, NULL) < 0) @@ -362,7 +357,7 @@ main(int argc, char *argv[]) if (!running_as_pid1) touch_run_ostree (); - if (strcmp(root_mountpoint, "/") == 0) + if (strcmp (root_mountpoint, "/") == 0) { /* pivot_root rotates two mount points around. In this instance . (the * deploy location) becomes / and the existing / becomes /sysroot. We @@ -405,7 +400,8 @@ main(int argc, char *argv[]) if (sysroot_readonly) { - if (mount ("sysroot", "sysroot", NULL, MS_BIND | MS_REMOUNT | MS_RDONLY | MS_SILENT, NULL) < 0) + if (mount ("sysroot", "sysroot", NULL, MS_BIND | MS_REMOUNT | MS_RDONLY | MS_SILENT, NULL) + < 0) err (EXIT_FAILURE, "failed to make /sysroot read-only"); /* TODO(lucab): This will make the final '/' read-only. diff --git a/src/switchroot/ostree-remount.c b/src/switchroot/ostree-remount.c index a81c1b41..ba5a16b2 100644 --- a/src/switchroot/ostree-remount.c +++ b/src/switchroot/ostree-remount.c @@ -21,29 +21,28 @@ #include "config.h" -#include -#include +#include +#include +#include #include #include #include -#include +#include +#include +#include #include +#include +#include #include -#include -#include #include -#include -#include -#include #include -#include "ostree-mount-util.h" #include "glnx-backport-autocleanups.h" +#include "ostree-mount-util.h" static void -do_remount (const char *target, - bool writable) +do_remount (const char *target, bool writable) { struct stat stbuf; if (lstat (target, &stbuf) < 0) @@ -80,7 +79,7 @@ do_remount (const char *target, } int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { /* When systemd is in use this is normally created via the generator, but * we ensure it's created here as well for redundancy. @@ -115,16 +114,15 @@ main(int argc, char *argv[]) if (sysroot_configured_readonly) do_remount ("/etc", true); - /* If /var was created as as an OSTree default bind mount (instead of being a separate filesystem) - * then remounting the root mount read-only also remounted it. - * So just like /etc, we need to make it read-write by default. - * If it was a separate filesystem, we expect it to be writable anyways, - * so it doesn't hurt to remount it if so. - * - * And if we started out with a writable system root, then we need - * to ensure that the /var bind mount created by the systemd generator - * is writable too. - */ + /* If /var was created as as an OSTree default bind mount (instead of being a separate + * filesystem) then remounting the root mount read-only also remounted it. So just like /etc, we + * need to make it read-write by default. If it was a separate filesystem, we expect it to be + * writable anyways, so it doesn't hurt to remount it if so. + * + * And if we started out with a writable system root, then we need + * to ensure that the /var bind mount created by the systemd generator + * is writable too. + */ do_remount ("/var", true); exit (EXIT_SUCCESS); diff --git a/src/switchroot/ostree-system-generator.c b/src/switchroot/ostree-system-generator.c index bd0901bc..33e3d783 100644 --- a/src/switchroot/ostree-system-generator.c +++ b/src/switchroot/ostree-system-generator.c @@ -20,10 +20,10 @@ #include "config.h" #include -#include -#include #include #include +#include +#include #include @@ -37,10 +37,11 @@ static const char *arg_dest_late = "/tmp"; * lives inside libostree. */ int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { /* We conflict with the magic ostree-mount-deployment-var file for ostree-prepare-root */ - { struct stat stbuf; + { + struct stat stbuf; if (fstatat (AT_FDCWD, INITRAMFS_MOUNT_VAR, &stbuf, 0) == 0) { if (unlinkat (AT_FDCWD, INITRAMFS_MOUNT_VAR, 0) < 0) @@ -74,8 +75,10 @@ main(int argc, char *argv[]) */ touch_run_ostree (); - { g_autoptr(GError) local_error = NULL; - if (!ostree_cmd__private__()->ostree_system_generator (ostree_cmdline, arg_dest, NULL, arg_dest_late, &local_error)) + { + g_autoptr (GError) local_error = NULL; + if (!ostree_cmd__private__ ()->ostree_system_generator (ostree_cmdline, arg_dest, NULL, + arg_dest_late, &local_error)) errx (EXIT_FAILURE, "%s", local_error->message); } diff --git a/tests/libostreetest.c b/tests/libostreetest.c index 08abb9f1..a1953561 100644 --- a/tests/libostreetest.c +++ b/tests/libostreetest.c @@ -34,11 +34,11 @@ ot_test_run_libtest (const char *cmd, GError **error) g_assert (srcdir != NULL); g_assert (cmd != NULL); - g_autoptr(GPtrArray) argv = g_ptr_array_new (); + g_autoptr (GPtrArray) argv = g_ptr_array_new (); g_ptr_array_add (argv, "bash"); g_ptr_array_add (argv, "-c"); - g_autoptr(GString) cmdstr = g_string_new (""); + g_autoptr (GString) cmdstr = g_string_new (""); g_string_append (cmdstr, "set -xeuo pipefail; . "); g_string_append (cmdstr, srcdir); g_string_append (cmdstr, "/tests/libtest.sh; "); @@ -48,8 +48,8 @@ ot_test_run_libtest (const char *cmd, GError **error) g_ptr_array_add (argv, NULL); int estatus; - if (!g_spawn_sync (NULL, (char**)argv->pdata, NULL, G_SPAWN_SEARCH_PATH, - NULL, NULL, NULL, NULL, &estatus, error)) + if (!g_spawn_sync (NULL, (char **)argv->pdata, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, + &estatus, error)) return FALSE; if (!g_spawn_check_exit_status (estatus, error)) return FALSE; @@ -58,14 +58,13 @@ ot_test_run_libtest (const char *cmd, GError **error) } OstreeRepo * -ot_test_setup_repo (GCancellable *cancellable, - GError **error) +ot_test_setup_repo (GCancellable *cancellable, GError **error) { if (!ot_test_run_libtest ("setup_test_repository archive", error)) return NULL; - g_autoptr(GFile) repo_path = g_file_new_for_path ("repo"); - g_autoptr(OstreeRepo) ret_repo = ostree_repo_new (repo_path); + g_autoptr (GFile) repo_path = g_file_new_for_path ("repo"); + g_autoptr (OstreeRepo) ret_repo = ostree_repo_new (repo_path); if (!ostree_repo_open (ret_repo, cancellable, error)) return NULL; @@ -74,15 +73,16 @@ ot_test_setup_repo (GCancellable *cancellable, /* Determine whether we're able to relabel files. Needed for bare tests. */ gboolean -ot_check_relabeling (gboolean *can_relabel, - GError **error) +ot_check_relabeling (gboolean *can_relabel, GError **error) { - g_auto(GLnxTmpfile) tmpf = { 0, }; + g_auto (GLnxTmpfile) tmpf = { + 0, + }; if (!glnx_open_tmpfile_linkable_at (AT_FDCWD, ".", O_RDWR | O_CLOEXEC, &tmpf, error)) return FALSE; - g_autoptr(GError) local_error = NULL; - g_autoptr(GBytes) bytes = glnx_fgetxattr_bytes (tmpf.fd, "security.selinux", &local_error); + g_autoptr (GError) local_error = NULL; + g_autoptr (GBytes) bytes = glnx_fgetxattr_bytes (tmpf.fd, "security.selinux", &local_error); if (!bytes) { /* libglnx preserves errno. The EOPNOTSUPP case can't be part of a @@ -115,10 +115,11 @@ ot_check_relabeling (gboolean *can_relabel, /* Determine whether the filesystem supports getting/setting user xattrs. */ gboolean -ot_check_user_xattrs (gboolean *has_user_xattrs, - GError **error) +ot_check_user_xattrs (gboolean *has_user_xattrs, GError **error) { - g_auto(GLnxTmpfile) tmpf = { 0, }; + g_auto (GLnxTmpfile) tmpf = { + 0, + }; if (!glnx_open_tmpfile_linkable_at (AT_FDCWD, ".", O_RDWR | O_CLOEXEC, &tmpf, error)) return FALSE; @@ -137,13 +138,12 @@ ot_check_user_xattrs (gboolean *has_user_xattrs, } OstreeSysroot * -ot_test_setup_sysroot (GCancellable *cancellable, - GError **error) +ot_test_setup_sysroot (GCancellable *cancellable, GError **error) { if (!ot_test_run_libtest ("setup_os_repository \"archive\" \"syslinux\"", error)) return FALSE; - g_autoptr(GString) buf = g_string_new ("mutable-deployments"); + g_autoptr (GString) buf = g_string_new ("mutable-deployments"); gboolean can_relabel = FALSE; if (!ot_check_relabeling (&can_relabel, error)) @@ -158,6 +158,6 @@ ot_test_setup_sysroot (GCancellable *cancellable, if (!g_setenv ("OSTREE_SYSROOT_DEBUG", buf->str, TRUE)) return glnx_null_throw (error, "Failed to set environment variable OSTREE_SYSROOT_DEBUG"); - g_autoptr(GFile) sysroot_path = g_file_new_for_path ("sysroot"); + g_autoptr (GFile) sysroot_path = g_file_new_for_path ("sysroot"); return ostree_sysroot_new (sysroot_path); } diff --git a/tests/libostreetest.h b/tests/libostreetest.h index aacfe5ef..e593ac13 100644 --- a/tests/libostreetest.h +++ b/tests/libostreetest.h @@ -28,16 +28,12 @@ G_BEGIN_DECLS gboolean ot_test_run_libtest (const char *cmd, GError **error); -OstreeRepo *ot_test_setup_repo (GCancellable *cancellable, - GError **error); +OstreeRepo *ot_test_setup_repo (GCancellable *cancellable, GError **error); -gboolean ot_check_relabeling (gboolean *can_relabel, - GError **error); +gboolean ot_check_relabeling (gboolean *can_relabel, GError **error); -gboolean ot_check_user_xattrs (gboolean *has_user_xattrs, - GError **error); +gboolean ot_check_user_xattrs (gboolean *has_user_xattrs, GError **error); -OstreeSysroot *ot_test_setup_sysroot (GCancellable *cancellable, - GError **error); +OstreeSysroot *ot_test_setup_sysroot (GCancellable *cancellable, GError **error); G_END_DECLS diff --git a/tests/repo-finder-mount.c b/tests/repo-finder-mount.c index 66c4ecd7..68a0e3de 100644 --- a/tests/repo-finder-mount.c +++ b/tests/repo-finder-mount.c @@ -24,22 +24,20 @@ #include "config.h" #include -#include #include +#include #include #include #include "ostree-autocleanups.h" #include "ostree-remote-private.h" -#include "ostree-repo-finder.h" #include "ostree-repo-finder-mount.h" +#include "ostree-repo-finder.h" #include "ostree-types.h" #include "test-mock-gio.h" static void -result_cb (GObject *source_object, - GAsyncResult *result, - gpointer user_data) +result_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { GAsyncResult **result_out = user_data; *result_out = g_object_ref (result); @@ -54,33 +52,35 @@ collection_ref_free0 (OstreeCollectionRef *ref) int main (int argc, char **argv) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; setlocale (LC_ALL, ""); if (argc < 5 || (argc % 2) != 1) { - g_printerr ("Usage: %s REPO MOUNT-ROOT COLLECTION-ID REF-NAME [COLLECTION-ID REF-NAME …]\n", argv[0]); + g_printerr ("Usage: %s REPO MOUNT-ROOT COLLECTION-ID REF-NAME [COLLECTION-ID REF-NAME …]\n", + argv[0]); return 1; } - g_autoptr(GMainContext) context = g_main_context_new (); + g_autoptr (GMainContext) context = g_main_context_new (); g_main_context_push_thread_default (context); - g_autoptr(OstreeRepo) parent_repo = ostree_repo_open_at (AT_FDCWD, argv[1], NULL, &error); + g_autoptr (OstreeRepo) parent_repo = ostree_repo_open_at (AT_FDCWD, argv[1], NULL, &error); g_assert_no_error (error); /* Set up a mock volume. */ - g_autoptr(GFile) mount_root = g_file_new_for_commandline_arg (argv[2]); - g_autoptr(GMount) mount = G_MOUNT (ostree_mock_mount_new ("mount", mount_root)); + g_autoptr (GFile) mount_root = g_file_new_for_commandline_arg (argv[2]); + g_autoptr (GMount) mount = G_MOUNT (ostree_mock_mount_new ("mount", mount_root)); - g_autoptr(GList) mounts = g_list_prepend (NULL, mount); + g_autoptr (GList) mounts = g_list_prepend (NULL, mount); - g_autoptr(GVolumeMonitor) monitor = ostree_mock_volume_monitor_new (mounts, NULL); - g_autoptr(OstreeRepoFinderMount) finder = ostree_repo_finder_mount_new (monitor); + g_autoptr (GVolumeMonitor) monitor = ostree_mock_volume_monitor_new (mounts, NULL); + g_autoptr (OstreeRepoFinderMount) finder = ostree_repo_finder_mount_new (monitor); /* Resolve the refs. */ - g_autoptr(GPtrArray) refs = g_ptr_array_new_with_free_func ((GDestroyNotify) collection_ref_free0); + g_autoptr (GPtrArray) refs + = g_ptr_array_new_with_free_func ((GDestroyNotify)collection_ref_free0); for (gsize i = 3; i < argc; i += 2) { @@ -90,18 +90,18 @@ main (int argc, char **argv) g_ptr_array_add (refs, ostree_collection_ref_new (collection_id, ref_name)); } - g_ptr_array_add (refs, NULL); /* NULL terminator */ + g_ptr_array_add (refs, NULL); /* NULL terminator */ - g_autoptr(GAsyncResult) async_result = NULL; + g_autoptr (GAsyncResult) async_result = NULL; ostree_repo_finder_resolve_async (OSTREE_REPO_FINDER (finder), - (const OstreeCollectionRef * const *) refs->pdata, - parent_repo, NULL, result_cb, &async_result); + (const OstreeCollectionRef *const *)refs->pdata, parent_repo, + NULL, result_cb, &async_result); while (async_result == NULL) g_main_context_iteration (context, TRUE); - g_autoptr(GPtrArray) results = ostree_repo_finder_resolve_finish (OSTREE_REPO_FINDER (finder), - async_result, &error); + g_autoptr (GPtrArray) results + = ostree_repo_finder_resolve_finish (OSTREE_REPO_FINDER (finder), async_result, &error); g_assert_no_error (error); /* Check that the results are correct: the invalid refs should have been @@ -115,11 +115,9 @@ main (int argc, char **argv) g_hash_table_iter_init (&iter, result->ref_to_checksum); - while (g_hash_table_iter_next (&iter, (gpointer *) &ref, (gpointer *) &checksum)) - g_print ("%" G_GSIZE_FORMAT " %s %s %s %s\n", - i, ostree_remote_get_name (result->remote), - ref->collection_id, ref->ref_name, - checksum); + while (g_hash_table_iter_next (&iter, (gpointer *)&ref, (gpointer *)&checksum)) + g_print ("%" G_GSIZE_FORMAT " %s %s %s %s\n", i, ostree_remote_get_name (result->remote), + ref->collection_id, ref->ref_name, checksum); } g_main_context_pop_thread_default (context); diff --git a/tests/test-basic-c.c b/tests/test-basic-c.c index 7a6b8ee7..b9a15ef1 100644 --- a/tests/test-basic-c.c +++ b/tests/test-basic-c.c @@ -19,11 +19,11 @@ #include "config.h" -#include -#include +#include #include +#include +#include #include -#include #include "libglnx.h" #include "libostreetest.h" @@ -31,25 +31,21 @@ static void test_repo_is_not_system (gconstpointer data) { - OstreeRepo *repo = (void*)data; + OstreeRepo *repo = (void *)data; g_assert (!ostree_repo_is_system (repo)); } static GBytes * input_stream_to_bytes (GInputStream *input) { - g_autoptr(GOutputStream) mem_out_stream = NULL; - g_autoptr(GError) error = NULL; + g_autoptr (GOutputStream) mem_out_stream = NULL; + g_autoptr (GError) error = NULL; if (input == NULL) return g_bytes_new (NULL, 0); mem_out_stream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free); - g_output_stream_splice (mem_out_stream, - input, - G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, - NULL, - &error); + g_output_stream_splice (mem_out_stream, input, G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, NULL, &error); g_assert_no_error (error); return g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (mem_out_stream)); @@ -60,56 +56,41 @@ test_raw_file_to_archive_stream (gconstpointer data) { OstreeRepo *repo = OSTREE_REPO (data); g_autofree gchar *commit_checksum = NULL; - g_autoptr(GHashTable) reachable = NULL; - g_autoptr(GError) error = NULL; + g_autoptr (GHashTable) reachable = NULL; + g_autoptr (GError) error = NULL; /* branch name of the test repository, see setup_test_repository in libtest.sh */ const gchar *rev = "test2"; GHashTableIter iter; GVariant *serialized_object; guint checks = 0; - ostree_repo_resolve_rev (repo, - rev, - FALSE, - &commit_checksum, - &error); + ostree_repo_resolve_rev (repo, rev, FALSE, &commit_checksum, &error); g_assert_no_error (error); - ostree_repo_traverse_commit (repo, - commit_checksum, - -1, - &reachable, - NULL, - &error); + ostree_repo_traverse_commit (repo, commit_checksum, -1, &reachable, NULL, &error); g_assert_no_error (error); g_hash_table_iter_init (&iter, reachable); - while (g_hash_table_iter_next (&iter, (gpointer*)&serialized_object, NULL)) + while (g_hash_table_iter_next (&iter, (gpointer *)&serialized_object, NULL)) { const gchar *object_checksum; OstreeObjectType object_type; - g_autoptr(GInputStream) input = NULL; - g_autoptr(GFileInfo) info = NULL; - g_autoptr(GVariant) xattrs = NULL; - g_autoptr(GBytes) input_bytes = NULL; - g_autoptr(GInputStream) mem_input = NULL; - g_autoptr(GInputStream) zlib_stream = NULL; - g_autoptr(GBytes) zlib_bytes = NULL; - g_autoptr(GInputStream) mem_zlib = NULL; - g_autoptr(GInputStream) input2 = NULL; - g_autoptr(GFileInfo) info2 = NULL; - g_autoptr(GVariant) xattrs2 = NULL; - g_autoptr(GBytes) input2_bytes = NULL; + g_autoptr (GInputStream) input = NULL; + g_autoptr (GFileInfo) info = NULL; + g_autoptr (GVariant) xattrs = NULL; + g_autoptr (GBytes) input_bytes = NULL; + g_autoptr (GInputStream) mem_input = NULL; + g_autoptr (GInputStream) zlib_stream = NULL; + g_autoptr (GBytes) zlib_bytes = NULL; + g_autoptr (GInputStream) mem_zlib = NULL; + g_autoptr (GInputStream) input2 = NULL; + g_autoptr (GFileInfo) info2 = NULL; + g_autoptr (GVariant) xattrs2 = NULL; + g_autoptr (GBytes) input2_bytes = NULL; ostree_object_name_deserialize (serialized_object, &object_checksum, &object_type); if (object_type != OSTREE_OBJECT_TYPE_FILE) continue; - ostree_repo_load_file (repo, - object_checksum, - &input, - &info, - &xattrs, - NULL, - &error); + ostree_repo_load_file (repo, object_checksum, &input, &info, &xattrs, NULL, &error); g_assert_no_error (error); input_bytes = input_stream_to_bytes (input); @@ -121,44 +102,21 @@ test_raw_file_to_archive_stream (gconstpointer data) * GFileDescriptorBased interface. */ if (input != NULL) mem_input = g_memory_input_stream_new_from_bytes (input_bytes); - ostree_raw_file_to_archive_z2_stream (mem_input, - info, - xattrs, - &zlib_stream, - NULL, - &error); + ostree_raw_file_to_archive_z2_stream (mem_input, info, xattrs, &zlib_stream, NULL, &error); g_assert_no_error (error); zlib_bytes = input_stream_to_bytes (zlib_stream); mem_zlib = g_memory_input_stream_new_from_bytes (zlib_bytes); - ostree_content_stream_parse (FALSE, - mem_zlib, - g_bytes_get_size (zlib_bytes), - FALSE, - &input2, - &info2, - &xattrs2, - NULL, - &error); + ostree_content_stream_parse (FALSE, mem_zlib, g_bytes_get_size (zlib_bytes), FALSE, &input2, + &info2, &xattrs2, NULL, &error); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_FAILED); g_clear_error (&error); - g_seekable_seek (G_SEEKABLE (mem_zlib), - 0, - G_SEEK_SET, - NULL, - &error); + g_seekable_seek (G_SEEKABLE (mem_zlib), 0, G_SEEK_SET, NULL, &error); g_assert_no_error (error); - ostree_content_stream_parse (TRUE, - mem_zlib, - g_bytes_get_size (zlib_bytes), - FALSE, - &input2, - &info2, - &xattrs2, - NULL, - &error); + ostree_content_stream_parse (TRUE, mem_zlib, g_bytes_get_size (zlib_bytes), FALSE, &input2, + &info2, &xattrs2, NULL, &error); g_assert_no_error (error); input2_bytes = input_stream_to_bytes (input2); @@ -171,37 +129,38 @@ test_raw_file_to_archive_stream (gconstpointer data) g_assert_cmpint (checks, >, 0); } -static gboolean hi_content_stream_new (GInputStream **out_stream, - guint64 *out_length, - GError **error) +static gboolean +hi_content_stream_new (GInputStream **out_stream, guint64 *out_length, GError **error) { static const char hi[] = "hi"; - const size_t len = sizeof(hi)-1; - g_autoptr(GMemoryInputStream) hi_memstream = (GMemoryInputStream*)g_memory_input_stream_new_from_data (hi, len, NULL); - g_autoptr(GFileInfo) finfo = g_file_info_new (); + const size_t len = sizeof (hi) - 1; + g_autoptr (GMemoryInputStream) hi_memstream + = (GMemoryInputStream *)g_memory_input_stream_new_from_data (hi, len, NULL); + g_autoptr (GFileInfo) finfo = g_file_info_new (); g_file_info_set_attribute_uint32 (finfo, "standard::type", G_FILE_TYPE_REGULAR); g_file_info_set_attribute_boolean (finfo, "standard::is-symlink", FALSE); g_file_info_set_size (finfo, len); g_file_info_set_attribute_uint32 (finfo, "unix::uid", 0); g_file_info_set_attribute_uint32 (finfo, "unix::gid", 0); - g_file_info_set_attribute_uint32 (finfo, "unix::mode", S_IFREG|0644); - return ostree_raw_file_to_content_stream ((GInputStream*)hi_memstream, finfo, NULL, out_stream, out_length, NULL, error); + g_file_info_set_attribute_uint32 (finfo, "unix::mode", S_IFREG | 0644); + return ostree_raw_file_to_content_stream ((GInputStream *)hi_memstream, finfo, NULL, out_stream, + out_length, NULL, error); } static void test_validate_remotename (void) { - const char *valid[] = {"foo", "hello-world"}; - const char *invalid[] = {"foo/bar", ""}; - for (guint i = 0; i < G_N_ELEMENTS(valid); i++) + const char *valid[] = { "foo", "hello-world" }; + const char *invalid[] = { "foo/bar", "" }; + for (guint i = 0; i < G_N_ELEMENTS (valid); i++) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; g_assert (ostree_validate_remote_name (valid[i], &error)); g_assert_no_error (error); } - for (guint i = 0; i < G_N_ELEMENTS(invalid); i++) + for (guint i = 0; i < G_N_ELEMENTS (invalid); i++) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; g_assert (!ostree_validate_remote_name (invalid[i], &error)); g_assert (error != NULL); } @@ -211,39 +170,40 @@ static void test_object_writes (gconstpointer data) { OstreeRepo *repo = OSTREE_REPO (data); - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; - static const char hi_sha256[] = "2301b5923720c3edc1f0467addb5c287fd5559e3e0cd1396e7f1edb6b01be9f0"; + static const char hi_sha256[] + = "2301b5923720c3edc1f0467addb5c287fd5559e3e0cd1396e7f1edb6b01be9f0"; /* Successful content write */ - { g_autoptr(GInputStream) hi_memstream = NULL; + { + g_autoptr (GInputStream) hi_memstream = NULL; guint64 len; hi_content_stream_new (&hi_memstream, &len, &error); g_assert_no_error (error); g_autofree guchar *csum = NULL; - (void)ostree_repo_write_content (repo, hi_sha256, hi_memstream, len, &csum, - NULL, &error); + (void)ostree_repo_write_content (repo, hi_sha256, hi_memstream, len, &csum, NULL, &error); g_assert_no_error (error); } /* Invalid content write */ - { g_autoptr(GInputStream) hi_memstream = NULL; + { + g_autoptr (GInputStream) hi_memstream = NULL; guint64 len; hi_content_stream_new (&hi_memstream, &len, &error); g_assert_no_error (error); g_autofree guchar *csum = NULL; - static const char invalid_hi_sha256[] = "cafebabecafebabecafebabecafebabecafebabecafebabecafebabecafebabe"; - g_assert (!ostree_repo_write_content (repo, invalid_hi_sha256, hi_memstream, len, &csum, - NULL, &error)); + static const char invalid_hi_sha256[] + = "cafebabecafebabecafebabecafebabecafebabecafebabecafebabecafebabe"; + g_assert (!ostree_repo_write_content (repo, invalid_hi_sha256, hi_memstream, len, &csum, NULL, + &error)); g_assert (error); g_assert (strstr (error->message, "Corrupted file object")); } } static gboolean -impl_test_break_hardlink (int tmp_dfd, - const char *path, - GError **error) +impl_test_break_hardlink (int tmp_dfd, const char *path, GError **error) { const char *linkedpath = glnx_strjoina (path, ".link"); struct stat orig_stbuf; @@ -276,8 +236,8 @@ impl_test_break_hardlink (int tmp_dfd, g_assert_cmpint (orig_stbuf.st_dev, ==, stbuf.st_dev); g_assert_cmpint (orig_stbuf.st_ino, ==, stbuf.st_ino); - (void) unlinkat (tmp_dfd, path, 0); - (void) unlinkat (tmp_dfd, linkedpath, 0); + (void)unlinkat (tmp_dfd, path, 0); + (void)unlinkat (tmp_dfd, linkedpath, 0); return TRUE; } @@ -286,14 +246,12 @@ static void test_break_hardlink (void) { int tmp_dfd = AT_FDCWD; - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; /* Regular file */ const char hello_hardlinked_content[] = "hello hardlinked content"; - glnx_file_replace_contents_at (tmp_dfd, "test-hardlink", - (guint8*)hello_hardlinked_content, - strlen (hello_hardlinked_content), - GLNX_FILE_REPLACE_NODATASYNC, + glnx_file_replace_contents_at (tmp_dfd, "test-hardlink", (guint8 *)hello_hardlinked_content, + strlen (hello_hardlinked_content), GLNX_FILE_REPLACE_NODATASYNC, NULL, &error); g_assert_no_error (error); (void)impl_test_break_hardlink (tmp_dfd, "test-hardlink", &error); @@ -306,11 +264,8 @@ test_break_hardlink (void) g_assert_no_error (error); } -static GVariant* -xattr_cb (OstreeRepo *repo, - const char *path, - GFileInfo *file_info, - gpointer user_data) +static GVariant * +xattr_cb (OstreeRepo *repo, const char *path, GFileInfo *file_info, gpointer user_data) { GVariant *xattr = user_data; if (g_str_equal (path, "/baz/cow")) @@ -322,10 +277,10 @@ xattr_cb (OstreeRepo *repo, static void test_devino_cache_xattrs (void) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; gboolean ret = FALSE; - g_autoptr(GFile) repo_path = g_file_new_for_path ("repo"); + g_autoptr (GFile) repo_path = g_file_new_for_path ("repo"); /* re-initialize as bare */ ret = ot_test_run_libtest ("setup_test_repository bare", &error); @@ -349,7 +304,7 @@ test_devino_cache_xattrs (void) return; } - g_autoptr(OstreeRepo) repo = ostree_repo_new (repo_path); + g_autoptr (OstreeRepo) repo = ostree_repo_new (repo_path); ret = ostree_repo_open (repo, NULL, &error); g_assert_no_error (error); g_assert (ret); @@ -359,47 +314,47 @@ test_devino_cache_xattrs (void) g_assert_no_error (error); g_assert (ret); - g_autoptr(OstreeRepoDevInoCache) cache = ostree_repo_devino_cache_new (); + g_autoptr (OstreeRepoDevInoCache) cache = ostree_repo_devino_cache_new (); - OstreeRepoCheckoutAtOptions options = {0,}; + OstreeRepoCheckoutAtOptions options = { + 0, + }; options.no_copy_fallback = TRUE; options.devino_to_csum_cache = cache; ret = ostree_repo_checkout_at (repo, &options, AT_FDCWD, "checkout", csum, NULL, &error); g_assert_no_error (error); g_assert (ret); - g_autoptr(OstreeMutableTree) mtree = ostree_mutable_tree_new (); - g_autoptr(OstreeRepoCommitModifier) modifier = - ostree_repo_commit_modifier_new (0, NULL, NULL, NULL); + g_autoptr (OstreeMutableTree) mtree = ostree_mutable_tree_new (); + g_autoptr (OstreeRepoCommitModifier) modifier + = ostree_repo_commit_modifier_new (0, NULL, NULL, NULL); ostree_repo_commit_modifier_set_devino_cache (modifier, cache); - g_auto(GVariantBuilder) builder; - g_variant_builder_init (&builder, (GVariantType*)"a(ayay)"); - g_variant_builder_add (&builder, "(@ay@ay)", - g_variant_new_bytestring ("user.myattr"), + g_auto (GVariantBuilder) builder; + g_variant_builder_init (&builder, (GVariantType *)"a(ayay)"); + g_variant_builder_add (&builder, "(@ay@ay)", g_variant_new_bytestring ("user.myattr"), g_variant_new_bytestring ("data")); - g_autoptr(GVariant) orig_xattrs = g_variant_ref_sink (g_variant_builder_end (&builder)); + g_autoptr (GVariant) orig_xattrs = g_variant_ref_sink (g_variant_builder_end (&builder)); ret = ostree_repo_prepare_transaction (repo, NULL, NULL, &error); g_assert_no_error (error); g_assert (ret); ostree_repo_commit_modifier_set_xattr_callback (modifier, xattr_cb, NULL, orig_xattrs); - ret = ostree_repo_write_dfd_to_mtree (repo, AT_FDCWD, "checkout", - mtree, modifier, NULL, &error); + ret = ostree_repo_write_dfd_to_mtree (repo, AT_FDCWD, "checkout", mtree, modifier, NULL, &error); g_assert_no_error (error); g_assert (ret); - g_autoptr(GFile) root = NULL; + g_autoptr (GFile) root = NULL; ret = ostree_repo_write_mtree (repo, mtree, &root, NULL, &error); g_assert_no_error (error); g_assert (ret); /* now check that the final xattr matches */ - g_autoptr(GFile) baz_child = g_file_get_child (root, "baz"); - g_autoptr(GFile) cow_child = g_file_get_child (baz_child, "cow"); + g_autoptr (GFile) baz_child = g_file_get_child (root, "baz"); + g_autoptr (GFile) cow_child = g_file_get_child (baz_child, "cow"); - g_autoptr(GVariant) xattrs = NULL; + g_autoptr (GVariant) xattrs = NULL; ret = ostree_repo_file_get_xattrs (OSTREE_REPO_FILE (cow_child), &xattrs, NULL, &error); g_assert_no_error (error); g_assert (ret); @@ -408,13 +363,13 @@ test_devino_cache_xattrs (void) gsize n = g_variant_n_children (xattrs); for (gsize i = 0; i < n; i++) { - const guint8* name; - const guint8* value; + const guint8 *name; + const guint8 *value; g_variant_get_child (xattrs, i, "(^&ay^&ay)", &name, &value); - if (g_str_equal ((const char*)name, "user.myattr")) + if (g_str_equal ((const char *)name, "user.myattr")) { - g_assert_cmpstr ((const char*)value, ==, "data"); + g_assert_cmpstr ((const char *)value, ==, "data"); found_xattr = TRUE; break; } @@ -437,29 +392,28 @@ test_devino_cache_xattrs (void) static void test_big_metadata (void) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; gboolean ret = FALSE; - g_autoptr(GFile) repo_path = g_file_new_for_path ("repo"); + g_autoptr (GFile) repo_path = g_file_new_for_path ("repo"); /* init as bare-user-only so we run everywhere */ ret = ot_test_run_libtest ("setup_test_repository bare-user-only", &error); g_assert_no_error (error); g_assert (ret); - g_autoptr(OstreeRepo) repo = ostree_repo_new (repo_path); + g_autoptr (OstreeRepo) repo = ostree_repo_new (repo_path); ret = ostree_repo_open (repo, NULL, &error); g_assert_no_error (error); g_assert (ret); - g_autoptr(GFile) object_to_commit = NULL; + g_autoptr (GFile) object_to_commit = NULL; ret = ostree_repo_read_commit (repo, "test2", &object_to_commit, NULL, NULL, &error); g_assert_no_error (error); g_assert (ret); - g_autoptr(OstreeMutableTree) mtree = ostree_mutable_tree_new (); - ret = ostree_repo_write_directory_to_mtree (repo, object_to_commit, mtree, NULL, - NULL, &error); + g_autoptr (OstreeMutableTree) mtree = ostree_mutable_tree_new (); + ret = ostree_repo_write_directory_to_mtree (repo, object_to_commit, mtree, NULL, NULL, &error); g_assert_no_error (error); g_assert (ret); @@ -467,14 +421,14 @@ test_big_metadata (void) g_assert_cmpint (len, >, OSTREE_MAX_METADATA_SIZE); g_autofree char *large_buf = g_malloc (len); memset (large_buf, 0x42, len); - g_autoptr(GVariantBuilder) builder = - g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); + g_autoptr (GVariantBuilder) builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); g_autofree char *commit_checksum = NULL; - g_variant_builder_add (builder, "{sv}", "large-value", - g_variant_new_fixed_array ((GVariantType*)"y", - large_buf, len, sizeof (char))); + g_variant_builder_add ( + builder, "{sv}", "large-value", + g_variant_new_fixed_array ((GVariantType *)"y", large_buf, len, sizeof (char))); ret = ostree_repo_write_commit (repo, NULL, NULL, NULL, g_variant_builder_end (builder), - OSTREE_REPO_FILE (object_to_commit), &commit_checksum, NULL, &error); + OSTREE_REPO_FILE (object_to_commit), &commit_checksum, NULL, + &error); g_assert_no_error (error); g_assert (ret); } @@ -501,10 +455,12 @@ compare_xattrs (GVariant *orig, GVariant *new) static void test_read_xattrs (void) { - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; - g_auto(GLnxTmpDir) tmpd = { 0, }; + g_auto (GLnxTmpDir) tmpd = { + 0, + }; // Use /var/tmp to hope we get xattr support glnx_mkdtempat (AT_FDCWD, "/var/tmp/ostree-xattrs-test.XXXXXX", 0700, &tmpd, error); g_assert_no_error (local_error); @@ -512,20 +468,20 @@ test_read_xattrs (void) const char value[] = "foo"; { - g_autoptr(GVariant) current_xattrs = ostree_fs_get_all_xattrs (tmpd.fd, NULL, error); + g_autoptr (GVariant) current_xattrs = ostree_fs_get_all_xattrs (tmpd.fd, NULL, error); g_assert_no_error (local_error); int r = fsetxattr (tmpd.fd, "user.ostreetesting", value, sizeof (value), 0); if (r != 0) { - g_autofree gchar *message = g_strdup_printf ("Unable to set extended attributes in /var/tmp: %s", - g_strerror (errno)); + g_autofree gchar *message = g_strdup_printf ( + "Unable to set extended attributes in /var/tmp: %s", g_strerror (errno)); g_test_skip (message); return; } - g_autoptr(GVariant) new_xattrs = ostree_fs_get_all_xattrs (tmpd.fd, NULL, error); + g_autoptr (GVariant) new_xattrs = ostree_fs_get_all_xattrs (tmpd.fd, NULL, error); g_assert_no_error (local_error); compare_xattrs (current_xattrs, new_xattrs); @@ -536,9 +492,10 @@ test_read_xattrs (void) glnx_throw_errno_prefix (error, "symlinkat"); g_assert_no_error (local_error); - g_autoptr(GVariant) current_xattrs = ostree_fs_get_all_xattrs_at (tmpd.fd, "somelink", NULL, error); + g_autoptr (GVariant) current_xattrs + = ostree_fs_get_all_xattrs_at (tmpd.fd, "somelink", NULL, error); g_assert_no_error (local_error); - (void) current_xattrs; + (void)current_xattrs; // OK, can't do user. xattrs on symlinks unfortunately. @@ -549,16 +506,17 @@ test_read_xattrs (void) // glnx_throw_errno_prefix (error, "lsetxattr"); // g_assert_no_error (local_error); - // g_autoptr(GVariant) new_xattrs = ostree_fs_get_all_xattrs_at (tmpd.fd, "somelink", NULL, error); - // g_assert_no_error (local_error); + // g_autoptr(GVariant) new_xattrs = ostree_fs_get_all_xattrs_at (tmpd.fd, "somelink", NULL, + // error); g_assert_no_error (local_error); // compare_xattrs (current_xattrs, new_xattrs); } } -int main (int argc, char **argv) +int +main (int argc, char **argv) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; glnx_unref_object OstreeRepo *repo = NULL; g_test_init (&argc, &argv, NULL); @@ -576,8 +534,8 @@ int main (int argc, char **argv) g_test_add_func ("/big-metadata", test_big_metadata); g_test_add_func ("/read-xattrs", test_read_xattrs); - return g_test_run(); - out: + return g_test_run (); +out: if (error) g_error ("%s", error->message); return 1; diff --git a/tests/test-bloom.c b/tests/test-bloom.c index 970a882f..93f46ebf 100644 --- a/tests/test-bloom.c +++ b/tests/test-bloom.c @@ -31,8 +31,8 @@ static void test_bloom_init (void) { - g_autoptr(OstreeBloom) bloom = NULL; - g_autoptr(GBytes) bytes = NULL; + g_autoptr (OstreeBloom) bloom = NULL; + g_autoptr (GBytes) bytes = NULL; bloom = ostree_bloom_new (1, 1, ostree_str_bloom_hash); g_assert_cmpuint (ostree_bloom_get_size (bloom), ==, 1); @@ -53,18 +53,12 @@ test_bloom_init (void) static void test_bloom_construction (void) { - g_autoptr(OstreeBloom) bloom = NULL; - g_autoptr(OstreeBloom) immutable_bloom = NULL; - g_autoptr(GBytes) bytes = NULL; + g_autoptr (OstreeBloom) bloom = NULL; + g_autoptr (OstreeBloom) immutable_bloom = NULL; + g_autoptr (GBytes) bytes = NULL; gsize i; - const gchar *members[] = - { - "hello", "there", "these", "are", "test", "strings" - }; - const gchar *non_members[] = - { - "not", "an", "element" - }; + const gchar *members[] = { "hello", "there", "these", "are", "test", "strings" }; + const gchar *non_members[] = { "not", "an", "element" }; const gsize n_bytes = 256; const guint8 k = 8; const OstreeBloomHashFunc hash = ostree_str_bloom_hash; @@ -94,7 +88,7 @@ test_bloom_construction (void) static void test_bloom_empty (void) { - g_autoptr(OstreeBloom) bloom = NULL; + g_autoptr (OstreeBloom) bloom = NULL; const gsize n_bytes = 256; const guint8 k = 8; const OstreeBloomHashFunc hash = ostree_str_bloom_hash; @@ -111,12 +105,9 @@ test_bloom_empty (void) static void test_bloom_membership_during_construction (void) { - g_autoptr(OstreeBloom) bloom = NULL; + g_autoptr (OstreeBloom) bloom = NULL; gsize i, j; - const gchar *members[] = - { - "hello", "there", "these", "are", "test", "strings" - }; + const gchar *members[] = { "hello", "there", "these", "are", "test", "strings" }; const gsize n_bytes = 256; const guint8 k = 8; const OstreeBloomHashFunc hash = ostree_str_bloom_hash; @@ -140,14 +131,16 @@ test_bloom_membership_during_construction (void) } } -int main (int argc, char **argv) +int +main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); g_test_add_func ("/bloom/init", test_bloom_init); g_test_add_func ("/bloom/construction", test_bloom_construction); g_test_add_func ("/bloom/empty", test_bloom_empty); - g_test_add_func ("/bloom/membership-during-construction", test_bloom_membership_during_construction); + g_test_add_func ("/bloom/membership-during-construction", + test_bloom_membership_during_construction); - return g_test_run(); + return g_test_run (); } diff --git a/tests/test-bsdiff.c b/tests/test-bsdiff.c index 4a9ac6cb..2d6b4722 100644 --- a/tests/test-bsdiff.c +++ b/tests/test-bsdiff.c @@ -19,37 +19,29 @@ #include "config.h" -#include "libglnx.h" #include "bsdiff/bsdiff.h" #include "bsdiff/bspatch.h" +#include "libglnx.h" +#include #include #include -#include #include static int -bzpatch_read (const struct bspatch_stream* stream, void* buffer, int length) +bzpatch_read (const struct bspatch_stream *stream, void *buffer, int length) { GInputStream *in = stream->opaque; - if (length && ! g_input_stream_read (in, - buffer, - length, - NULL, - NULL)) + if (length && !g_input_stream_read (in, buffer, length, NULL, NULL)) return -1; return 0; } static int -bzdiff_write (struct bsdiff_stream* stream, const void* buffer, int size) +bzdiff_write (struct bsdiff_stream *stream, const void *buffer, int size) { GOutputStream *out = stream->opaque; - if (! g_output_stream_write (out, - buffer, - size, - NULL, - NULL)) + if (!g_output_stream_write (out, buffer, size, NULL, NULL)) return -1; return 0; @@ -59,7 +51,7 @@ static void test_bsdiff (void) { #define OLD_SIZE 512 -#define NEW_SIZE (512+24) +#define NEW_SIZE (512 + 24) struct bsdiff_stream bsdiff_stream; struct bspatch_stream bspatch_stream; @@ -67,8 +59,8 @@ test_bsdiff (void) g_autofree guint8 *old = g_new (guint8, OLD_SIZE); g_autofree guint8 *new = g_new (guint8, NEW_SIZE); g_autofree guint8 *new_generated = g_new0 (guint8, NEW_SIZE); - g_autoptr(GOutputStream) out = g_memory_output_stream_new_resizable (); - g_autoptr(GInputStream) in = NULL; + g_autoptr (GOutputStream) out = g_memory_output_stream_new_resizable (); + g_autoptr (GInputStream) in = NULL; new[0] = 'A'; for (i = 0; i < OLD_SIZE; i++) @@ -88,7 +80,8 @@ test_bsdiff (void) g_assert (g_output_stream_close (out, NULL, NULL)); /* Now generate NEW_GENERATED from OLD and OUT. */ - { g_autoptr(GBytes) bytes = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (out)); + { + g_autoptr (GBytes) bytes = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (out)); in = g_memory_input_stream_new_from_bytes (bytes); } bspatch_stream.read = bzpatch_read; @@ -99,9 +92,10 @@ test_bsdiff (void) g_assert_cmpint (memcmp (new, new_generated, NEW_SIZE), ==, 0); } -int main (int argc, char **argv) +int +main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); g_test_add_func ("/bsdiff", test_bsdiff); - return g_test_run(); + return g_test_run (); } diff --git a/tests/test-checksum.c b/tests/test-checksum.c index 85d1c262..fabd029a 100644 --- a/tests/test-checksum.c +++ b/tests/test-checksum.c @@ -20,11 +20,11 @@ #include "config.h" #include "libglnx.h" +#include "ostree-core-private.h" +#include #include #include -#include #include -#include "ostree-core-private.h" static void test_ostree_parse_delta_name (void) @@ -32,7 +32,8 @@ test_ostree_parse_delta_name (void) { g_autofree char *from = NULL; g_autofree char *to = NULL; - g_assert (_ostree_parse_delta_name ("30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d", &from, &to, NULL)); + g_assert (_ostree_parse_delta_name ( + "30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d", &from, &to, NULL)); g_assert_cmpstr (to, ==, "30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d"); g_assert_null (from); } @@ -40,7 +41,10 @@ test_ostree_parse_delta_name (void) { g_autofree char *from = NULL; g_autofree char *to = NULL; - g_assert (_ostree_parse_delta_name ("30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d-5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03", &from, &to, NULL)); + g_assert (_ostree_parse_delta_name ( + "30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d-" + "5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03", + &from, &to, NULL)); g_assert_cmpstr (from, ==, "30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d"); g_assert_cmpstr (to, ==, "5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03"); } @@ -64,7 +68,9 @@ test_ostree_parse_delta_name (void) { g_autofree char *from = NULL; g_autofree char *to = NULL; - g_assert (!_ostree_parse_delta_name ("GARBAGE-5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03", &from, &to, NULL)); + g_assert (!_ostree_parse_delta_name ( + "GARBAGE-5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03", &from, &to, + NULL)); g_assert_null (from); g_assert_null (to); } @@ -72,15 +78,18 @@ test_ostree_parse_delta_name (void) { g_autofree char *from = NULL; g_autofree char *to = NULL; - g_assert (!_ostree_parse_delta_name ("30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d-GARBAGE", &from, &to, NULL)); + g_assert (!_ostree_parse_delta_name ( + "30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d-GARBAGE", &from, &to, + NULL)); g_assert_null (from); g_assert_null (to); } } -int main (int argc, char **argv) +int +main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); g_test_add_func ("/ostree_parse_delta_name", test_ostree_parse_delta_name); - return g_test_run(); + return g_test_run (); } diff --git a/tests/test-commit-sign-sh-ext.c b/tests/test-commit-sign-sh-ext.c index c11bd0f1..3469471d 100644 --- a/tests/test-commit-sign-sh-ext.c +++ b/tests/test-commit-sign-sh-ext.c @@ -52,7 +52,7 @@ corrupt (GBytes *input) static gboolean run (GError **error) { - g_autoptr(OstreeRepo) repo = ostree_repo_open_at (AT_FDCWD, "repo", NULL, error); + g_autoptr (OstreeRepo) repo = ostree_repo_open_at (AT_FDCWD, "repo", NULL, error); if (!repo) return FALSE; @@ -60,45 +60,46 @@ run (GError **error) if (!ostree_repo_resolve_rev (repo, "origin:main", FALSE, &rev, error)) return FALSE; g_assert (rev); - g_autoptr(GVariant) commit = NULL; + g_autoptr (GVariant) commit = NULL; if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, rev, &commit, error)) return FALSE; g_assert (commit); - g_autoptr(GVariant) detached_meta = NULL; + g_autoptr (GVariant) detached_meta = NULL; if (!ostree_repo_read_commit_detached_metadata (repo, rev, &detached_meta, NULL, error)) return FALSE; g_assert (detached_meta); - g_autoptr(GBytes) commit_bytes = g_variant_get_data_as_bytes (commit); - g_autoptr(GBytes) detached_meta_bytes = g_variant_get_data_as_bytes (detached_meta); + g_autoptr (GBytes) commit_bytes = g_variant_get_data_as_bytes (commit); + g_autoptr (GBytes) detached_meta_bytes = g_variant_get_data_as_bytes (detached_meta); g_autofree char *verify_report = NULL; - if (!ostree_repo_signature_verify_commit_data (repo, "origin", commit_bytes, detached_meta_bytes, 0, - &verify_report, error)) + if (!ostree_repo_signature_verify_commit_data (repo, "origin", commit_bytes, detached_meta_bytes, + 0, &verify_report, error)) return FALSE; if (ostree_repo_signature_verify_commit_data (repo, "origin", commit_bytes, detached_meta_bytes, - OSTREE_REPO_VERIFY_FLAGS_NO_GPG | OSTREE_REPO_VERIFY_FLAGS_NO_SIGNAPI, + OSTREE_REPO_VERIFY_FLAGS_NO_GPG + | OSTREE_REPO_VERIFY_FLAGS_NO_SIGNAPI, &verify_report, error)) return glnx_throw (error, "Should not have validated"); assert_error_contains (error, "No commit verification types enabled"); // No signatures - g_autoptr(GBytes) empty = g_bytes_new_static ("", 0); + g_autoptr (GBytes) empty = g_bytes_new_static ("", 0); if (ostree_repo_signature_verify_commit_data (repo, "origin", commit_bytes, empty, 0, - &verify_report, error)) + &verify_report, error)) return glnx_throw (error, "Should not have validated"); assert_error_contains (error, "no signatures found"); // No such remote - if (ostree_repo_signature_verify_commit_data (repo, "nosuchremote", commit_bytes, detached_meta_bytes, 0, - &verify_report, error)) + if (ostree_repo_signature_verify_commit_data (repo, "nosuchremote", commit_bytes, + detached_meta_bytes, 0, &verify_report, error)) return glnx_throw (error, "Should not have validated"); assert_error_contains (error, "Remote \"nosuchremote\" not found"); // Corrupted commit - g_autoptr(GBytes) corrupted_commit = corrupt (commit_bytes); - if (ostree_repo_signature_verify_commit_data (repo, "origin", corrupted_commit, detached_meta_bytes, 0, - &verify_report, error)) + g_autoptr (GBytes) corrupted_commit = corrupt (commit_bytes); + if (ostree_repo_signature_verify_commit_data (repo, "origin", corrupted_commit, + detached_meta_bytes, 0, &verify_report, error)) return glnx_throw (error, "Should not have validated"); assert_error_contains (error, "BAD signature"); @@ -108,7 +109,7 @@ run (GError **error) int main (int argc, char **argv) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; if (!run (&error)) { g_printerr ("error: %s\n", error->message); diff --git a/tests/test-gpg-verify-result.c b/tests/test-gpg-verify-result.c index 8485b888..e7171a89 100644 --- a/tests/test-gpg-verify-result.c +++ b/tests/test-gpg-verify-result.c @@ -19,51 +19,55 @@ #include "config.h" -#include #include "libglnx.h" +#include #include "ostree-gpg-verify-result-private.h" #define assert_no_gpg_error(err, filename) \ - G_STMT_START { \ - if (err != GPG_ERR_NO_ERROR) { \ - g_autoptr(GString) string = g_string_new ("assertion failed "); \ - g_string_append_printf (string, "%s: %s ", gpgme_strsource (err), gpgme_strerror (err)); \ - g_string_append (string, filename ? filename : ""); \ - g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, string->str); \ - } \ - } G_STMT_END + G_STMT_START \ + { \ + if (err != GPG_ERR_NO_ERROR) \ + { \ + g_autoptr (GString) string = g_string_new ("assertion failed "); \ + g_string_append_printf (string, "%s: %s ", gpgme_strsource (err), gpgme_strerror (err)); \ + g_string_append (string, filename ? filename : ""); \ + g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, string->str); \ + } \ + } \ + G_STMT_END #define assert_str_contains(s1, s2) \ - G_STMT_START { \ + G_STMT_START \ + { \ const char *__s1 = (s1), *__s2 = (s2); \ - if (strstr (__s1, __s2) == NULL) { \ - g_autoptr(GString) string = g_string_new ("assertion failed (" #s1 " contains " #s2 "): "); \ - g_autofree char *__es1 = g_strescape (__s1, NULL); \ - g_autofree char *__es2 = g_strescape (__s2, NULL); \ - g_string_append_printf (string, "(\"%s\", \"%s\")", __es1, __es2); \ - g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, string->str); \ - } \ - } G_STMT_END - -typedef struct { + if (strstr (__s1, __s2) == NULL) \ + { \ + g_autoptr (GString) string \ + = g_string_new ("assertion failed (" #s1 " contains " #s2 "): "); \ + g_autofree char *__es1 = g_strescape (__s1, NULL); \ + g_autofree char *__es2 = g_strescape (__s2, NULL); \ + g_string_append_printf (string, "(\"%s\", \"%s\")", __es1, __es2); \ + g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, string->str); \ + } \ + } \ + G_STMT_END + +typedef struct +{ OstreeGpgVerifyResult *result; } TestFixture; static OstreeGpgSignatureAttr some_attributes[] = { - OSTREE_GPG_SIGNATURE_ATTR_VALID, - OSTREE_GPG_SIGNATURE_ATTR_SIG_EXPIRED, - OSTREE_GPG_SIGNATURE_ATTR_KEY_EXPIRED, - OSTREE_GPG_SIGNATURE_ATTR_KEY_REVOKED, - OSTREE_GPG_SIGNATURE_ATTR_KEY_MISSING, - OSTREE_GPG_SIGNATURE_ATTR_KEY_EXP_TIMESTAMP, + OSTREE_GPG_SIGNATURE_ATTR_VALID, OSTREE_GPG_SIGNATURE_ATTR_SIG_EXPIRED, + OSTREE_GPG_SIGNATURE_ATTR_KEY_EXPIRED, OSTREE_GPG_SIGNATURE_ATTR_KEY_REVOKED, + OSTREE_GPG_SIGNATURE_ATTR_KEY_MISSING, OSTREE_GPG_SIGNATURE_ATTR_KEY_EXP_TIMESTAMP, }; static void -test_fixture_setup (TestFixture *fixture, - gconstpointer user_data) +test_fixture_setup (TestFixture *fixture, gconstpointer user_data) { - const char * const *sig_files = user_data; + const char *const *sig_files = user_data; gpgme_error_t gpg_error; gpgme_data_t data_buffer; gpgme_data_t signature_buffer; @@ -81,8 +85,7 @@ test_fixture_setup (TestFixture *fixture, gboolean is_ok = g_setenv ("GNUPGHOME", homedir, TRUE); g_assert (is_ok == TRUE); - result = g_initable_new (OSTREE_TYPE_GPG_VERIFY_RESULT, - NULL, &local_error, NULL); + result = g_initable_new (OSTREE_TYPE_GPG_VERIFY_RESULT, NULL, &local_error, NULL); g_assert_no_error (local_error); g_autofree char *data_filename = g_build_filename (homedir, "lgpl2", NULL); @@ -102,15 +105,15 @@ test_fixture_setup (TestFixture *fixture, gpg_error = gpgme_data_new (&signature_buffer); assert_no_gpg_error (gpg_error, NULL); - for (const char * const *name = sig_files; *name != NULL; name++) + for (const char *const *name = sig_files; *name != NULL; name++) { g_autofree char *path = g_build_filename (homedir, *name, NULL); - g_autoptr(GFile) sig_file = g_file_new_for_path (path); + g_autoptr (GFile) sig_file = g_file_new_for_path (path); g_autofree char *contents = NULL; gsize len; - g_assert_true (g_file_load_contents (sig_file, NULL, &contents, - &len, NULL, &local_error)); + g_assert_true ( + g_file_load_contents (sig_file, NULL, &contents, &len, NULL, &local_error)); g_assert_no_error (local_error); char *cur = contents; @@ -127,8 +130,7 @@ test_fixture_setup (TestFixture *fixture, gpgme_data_seek (signature_buffer, 0, SEEK_SET); } - gpg_error = gpgme_op_verify (result->context, - signature_buffer, data_buffer, NULL); + gpg_error = gpgme_op_verify (result->context, signature_buffer, data_buffer, NULL); assert_no_gpg_error (gpg_error, NULL); result->details = gpgme_op_verify_result (result->context); @@ -141,15 +143,13 @@ test_fixture_setup (TestFixture *fixture, } static void -test_fixture_teardown (TestFixture *fixture, - gconstpointer user_data) +test_fixture_teardown (TestFixture *fixture, gconstpointer user_data) { g_clear_object (&fixture->result); } static void -test_check_counts (TestFixture *fixture, - gconstpointer user_data) +test_check_counts (TestFixture *fixture, gconstpointer user_data) { guint count_all; guint count_valid; @@ -162,8 +162,7 @@ test_check_counts (TestFixture *fixture, } static void -test_signature_lookup (TestFixture *fixture, - gconstpointer user_data) +test_signature_lookup (TestFixture *fixture, gconstpointer user_data) { /* Checking the signature with the revoked key for this case. */ guint expected_signature_index = 2; @@ -176,33 +175,29 @@ test_signature_lookup (TestFixture *fixture, /* Lookup full fingerprint. */ signature_index = 999999; - signature_found = ostree_gpg_verify_result_lookup (fixture->result, - fingerprint, - &signature_index); + signature_found + = ostree_gpg_verify_result_lookup (fixture->result, fingerprint, &signature_index); g_assert_true (signature_found); g_assert_cmpint (signature_index, ==, expected_signature_index); /* Lookup abbreviated key ID. */ signature_index = 999999; - signature_found = ostree_gpg_verify_result_lookup (fixture->result, - fingerprint + 32, - &signature_index); + signature_found + = ostree_gpg_verify_result_lookup (fixture->result, fingerprint + 32, &signature_index); g_assert_true (signature_found); g_assert_cmpint (signature_index, ==, expected_signature_index); /* Bogus fingerprint, index should remain unchanged. */ signature_index = expected_signature_index = 999999; fingerprint = "CAFEBABECAFEBABECAFEBABECAFEBABECAFEBABE"; - signature_found = ostree_gpg_verify_result_lookup (fixture->result, - fingerprint, - &signature_index); + signature_found + = ostree_gpg_verify_result_lookup (fixture->result, fingerprint, &signature_index); g_assert_false (signature_found); g_assert_cmpint (signature_index, ==, expected_signature_index); } static void -test_attribute_basics (TestFixture *fixture, - gconstpointer user_data) +test_attribute_basics (TestFixture *fixture, gconstpointer user_data) { guint n_signatures, ii; @@ -210,7 +205,7 @@ test_attribute_basics (TestFixture *fixture, for (ii = 0; ii < n_signatures; ii++) { - g_autoptr(GVariant) tuple = NULL; + g_autoptr (GVariant) tuple = NULL; const char *attr_string; const char *type_string; gboolean key_missing; @@ -222,31 +217,21 @@ test_attribute_basics (TestFixture *fixture, /* Check attributes which should be common to all signatures. */ - g_variant_get_child (tuple, - OSTREE_GPG_SIGNATURE_ATTR_PUBKEY_ALGO_NAME, - "&s", &attr_string); + g_variant_get_child (tuple, OSTREE_GPG_SIGNATURE_ATTR_PUBKEY_ALGO_NAME, "&s", &attr_string); g_assert_cmpstr (attr_string, ==, "RSA"); - g_variant_get_child (tuple, - OSTREE_GPG_SIGNATURE_ATTR_HASH_ALGO_NAME, - "&s", &attr_string); + g_variant_get_child (tuple, OSTREE_GPG_SIGNATURE_ATTR_HASH_ALGO_NAME, "&s", &attr_string); g_assert_cmpstr (attr_string, ==, "SHA1"); - g_variant_get_child (tuple, - OSTREE_GPG_SIGNATURE_ATTR_KEY_MISSING, - "b", &key_missing); + g_variant_get_child (tuple, OSTREE_GPG_SIGNATURE_ATTR_KEY_MISSING, "b", &key_missing); - g_variant_get_child (tuple, - OSTREE_GPG_SIGNATURE_ATTR_USER_NAME, - "&s", &attr_string); + g_variant_get_child (tuple, OSTREE_GPG_SIGNATURE_ATTR_USER_NAME, "&s", &attr_string); if (key_missing) g_assert_cmpstr (attr_string, ==, "[unknown name]"); else g_assert_cmpstr (attr_string, ==, "J. Random User"); - g_variant_get_child (tuple, - OSTREE_GPG_SIGNATURE_ATTR_USER_EMAIL, - "&s", &attr_string); + g_variant_get_child (tuple, OSTREE_GPG_SIGNATURE_ATTR_USER_EMAIL, "&s", &attr_string); if (key_missing) g_assert_cmpstr (attr_string, ==, "[unknown email]"); else @@ -255,11 +240,10 @@ test_attribute_basics (TestFixture *fixture, } static void -test_valid_signature (TestFixture *fixture, - gconstpointer user_data) +test_valid_signature (TestFixture *fixture, gconstpointer user_data) { guint signature_index = 0; - g_autoptr(GVariant) tuple = NULL; + g_autoptr (GVariant) tuple = NULL; gboolean valid; gboolean sig_expired; gboolean key_expired; @@ -267,17 +251,10 @@ test_valid_signature (TestFixture *fixture, gboolean key_missing; gint64 key_exp_timestamp; - tuple = ostree_gpg_verify_result_get (fixture->result, - signature_index, - some_attributes, + tuple = ostree_gpg_verify_result_get (fixture->result, signature_index, some_attributes, G_N_ELEMENTS (some_attributes)); - g_variant_get (tuple, "(bbbbbx)", - &valid, - &sig_expired, - &key_expired, - &key_revoked, - &key_missing, + g_variant_get (tuple, "(bbbbbx)", &valid, &sig_expired, &key_expired, &key_revoked, &key_missing, &key_exp_timestamp); g_assert_true (valid); @@ -289,11 +266,10 @@ test_valid_signature (TestFixture *fixture, } static void -test_expired_key (TestFixture *fixture, - gconstpointer user_data) +test_expired_key (TestFixture *fixture, gconstpointer user_data) { guint signature_index = 1; - g_autoptr(GVariant) tuple = NULL; + g_autoptr (GVariant) tuple = NULL; gboolean valid; gboolean sig_expired; gboolean key_expired; @@ -301,17 +277,10 @@ test_expired_key (TestFixture *fixture, gboolean key_missing; gint64 key_exp_timestamp; - tuple = ostree_gpg_verify_result_get (fixture->result, - signature_index, - some_attributes, + tuple = ostree_gpg_verify_result_get (fixture->result, signature_index, some_attributes, G_N_ELEMENTS (some_attributes)); - g_variant_get (tuple, "(bbbbbx)", - &valid, - &sig_expired, - &key_expired, - &key_revoked, - &key_missing, + g_variant_get (tuple, "(bbbbbx)", &valid, &sig_expired, &key_expired, &key_revoked, &key_missing, &key_exp_timestamp); g_assert_false (valid); @@ -323,11 +292,10 @@ test_expired_key (TestFixture *fixture, } static void -test_revoked_key (TestFixture *fixture, - gconstpointer user_data) +test_revoked_key (TestFixture *fixture, gconstpointer user_data) { guint signature_index = 2; - g_autoptr(GVariant) tuple = NULL; + g_autoptr (GVariant) tuple = NULL; gboolean valid; gboolean sig_expired; gboolean key_expired; @@ -335,17 +303,10 @@ test_revoked_key (TestFixture *fixture, gboolean key_missing; gint64 key_exp_timestamp; - tuple = ostree_gpg_verify_result_get (fixture->result, - signature_index, - some_attributes, + tuple = ostree_gpg_verify_result_get (fixture->result, signature_index, some_attributes, G_N_ELEMENTS (some_attributes)); - g_variant_get (tuple, "(bbbbbx)", - &valid, - &sig_expired, - &key_expired, - &key_revoked, - &key_missing, + g_variant_get (tuple, "(bbbbbx)", &valid, &sig_expired, &key_expired, &key_revoked, &key_missing, &key_exp_timestamp); g_assert_false (valid); @@ -357,11 +318,10 @@ test_revoked_key (TestFixture *fixture, } static void -test_missing_key (TestFixture *fixture, - gconstpointer user_data) +test_missing_key (TestFixture *fixture, gconstpointer user_data) { guint signature_index = 3; - g_autoptr(GVariant) tuple = NULL; + g_autoptr (GVariant) tuple = NULL; gboolean valid; gboolean sig_expired; gboolean key_expired; @@ -369,17 +329,10 @@ test_missing_key (TestFixture *fixture, gboolean key_missing; gint64 key_exp_timestamp; - tuple = ostree_gpg_verify_result_get (fixture->result, - signature_index, - some_attributes, + tuple = ostree_gpg_verify_result_get (fixture->result, signature_index, some_attributes, G_N_ELEMENTS (some_attributes)); - g_variant_get (tuple, "(bbbbbx)", - &valid, - &sig_expired, - &key_expired, - &key_revoked, - &key_missing, + g_variant_get (tuple, "(bbbbbx)", &valid, &sig_expired, &key_expired, &key_revoked, &key_missing, &key_exp_timestamp); g_assert_false (valid); @@ -391,11 +344,10 @@ test_missing_key (TestFixture *fixture, } static void -test_expired_signature (TestFixture *fixture, - gconstpointer user_data) +test_expired_signature (TestFixture *fixture, gconstpointer user_data) { guint signature_index = 4; - g_autoptr(GVariant) tuple = NULL; + g_autoptr (GVariant) tuple = NULL; gboolean valid; gboolean sig_expired; gboolean key_expired; @@ -403,17 +355,10 @@ test_expired_signature (TestFixture *fixture, gboolean key_missing; gint64 key_exp_timestamp; - tuple = ostree_gpg_verify_result_get (fixture->result, - signature_index, - some_attributes, + tuple = ostree_gpg_verify_result_get (fixture->result, signature_index, some_attributes, G_N_ELEMENTS (some_attributes)); - g_variant_get (tuple, "(bbbbbx)", - &valid, - &sig_expired, - &key_expired, - &key_revoked, - &key_missing, + g_variant_get (tuple, "(bbbbbx)", &valid, &sig_expired, &key_expired, &key_revoked, &key_missing, &key_exp_timestamp); g_assert_false (valid); @@ -425,71 +370,59 @@ test_expired_signature (TestFixture *fixture, } static void -test_require_valid_signature (TestFixture *fixture, - gconstpointer user_data) +test_require_valid_signature (TestFixture *fixture, gconstpointer user_data) { GError *error = NULL; - gboolean res = ostree_gpg_verify_result_require_valid_signature (fixture->result, - &error); + gboolean res = ostree_gpg_verify_result_require_valid_signature (fixture->result, &error); g_assert_true (res); g_assert_no_error (error); } static void -test_require_valid_signature_expired_key (TestFixture *fixture, - gconstpointer user_data) +test_require_valid_signature_expired_key (TestFixture *fixture, gconstpointer user_data) { GError *error = NULL; - gboolean res = ostree_gpg_verify_result_require_valid_signature (fixture->result, - &error); + gboolean res = ostree_gpg_verify_result_require_valid_signature (fixture->result, &error); g_assert_false (res); g_assert_error (error, OSTREE_GPG_ERROR, OSTREE_GPG_ERROR_EXPIRED_KEY); assert_str_contains (error->message, "Key expired"); } static void -test_require_valid_signature_revoked_key (TestFixture *fixture, - gconstpointer user_data) +test_require_valid_signature_revoked_key (TestFixture *fixture, gconstpointer user_data) { GError *error = NULL; - gboolean res = ostree_gpg_verify_result_require_valid_signature (fixture->result, - &error); + gboolean res = ostree_gpg_verify_result_require_valid_signature (fixture->result, &error); g_assert_false (res); g_assert_error (error, OSTREE_GPG_ERROR, OSTREE_GPG_ERROR_REVOKED_KEY); assert_str_contains (error->message, "Key revoked"); } static void -test_require_valid_signature_missing_key (TestFixture *fixture, - gconstpointer user_data) +test_require_valid_signature_missing_key (TestFixture *fixture, gconstpointer user_data) { GError *error = NULL; - gboolean res = ostree_gpg_verify_result_require_valid_signature (fixture->result, - &error); + gboolean res = ostree_gpg_verify_result_require_valid_signature (fixture->result, &error); g_assert_false (res); g_assert_error (error, OSTREE_GPG_ERROR, OSTREE_GPG_ERROR_MISSING_KEY); assert_str_contains (error->message, "public key not found"); } static void -test_require_valid_signature_expired_signature (TestFixture *fixture, - gconstpointer user_data) +test_require_valid_signature_expired_signature (TestFixture *fixture, gconstpointer user_data) { GError *error = NULL; - gboolean res = ostree_gpg_verify_result_require_valid_signature (fixture->result, - &error); + gboolean res = ostree_gpg_verify_result_require_valid_signature (fixture->result, &error); g_assert_false (res); g_assert_error (error, OSTREE_GPG_ERROR, OSTREE_GPG_ERROR_EXPIRED_SIGNATURE); assert_str_contains (error->message, "Signature expired"); } static void -test_require_valid_signature_expired_missing_key (TestFixture *fixture, - gconstpointer user_data) +test_require_valid_signature_expired_missing_key (TestFixture *fixture, gconstpointer user_data) { GError *error = NULL; - gboolean res = ostree_gpg_verify_result_require_valid_signature (fixture->result, - &error); + gboolean res = ostree_gpg_verify_result_require_valid_signature (fixture->result, &error); g_assert_false (res); /* @@ -506,110 +439,59 @@ main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); - (void) gpgme_check_version (NULL); + (void)gpgme_check_version (NULL); - g_test_add ("/gpg-verify-result/check-counts", - TestFixture, - NULL, - test_fixture_setup, - test_check_counts, - test_fixture_teardown); + g_test_add ("/gpg-verify-result/check-counts", TestFixture, NULL, test_fixture_setup, + test_check_counts, test_fixture_teardown); - g_test_add ("/gpg-verify-result/signature-lookup", - TestFixture, - NULL, - test_fixture_setup, - test_signature_lookup, - test_fixture_teardown); + g_test_add ("/gpg-verify-result/signature-lookup", TestFixture, NULL, test_fixture_setup, + test_signature_lookup, test_fixture_teardown); - g_test_add ("/gpg-verify-result/attribute-basics", - TestFixture, - NULL, - test_fixture_setup, - test_attribute_basics, - test_fixture_teardown); + g_test_add ("/gpg-verify-result/attribute-basics", TestFixture, NULL, test_fixture_setup, + test_attribute_basics, test_fixture_teardown); - g_test_add ("/gpg-verify-result/valid-signature", - TestFixture, - NULL, - test_fixture_setup, - test_valid_signature, - test_fixture_teardown); + g_test_add ("/gpg-verify-result/valid-signature", TestFixture, NULL, test_fixture_setup, + test_valid_signature, test_fixture_teardown); - g_test_add ("/gpg-verify-result/expired-key", - TestFixture, - NULL, - test_fixture_setup, - test_expired_key, - test_fixture_teardown); + g_test_add ("/gpg-verify-result/expired-key", TestFixture, NULL, test_fixture_setup, + test_expired_key, test_fixture_teardown); - g_test_add ("/gpg-verify-result/revoked-key", - TestFixture, - NULL, - test_fixture_setup, - test_revoked_key, - test_fixture_teardown); + g_test_add ("/gpg-verify-result/revoked-key", TestFixture, NULL, test_fixture_setup, + test_revoked_key, test_fixture_teardown); - g_test_add ("/gpg-verify-result/missing-key", - TestFixture, - NULL, - test_fixture_setup, - test_missing_key, - test_fixture_teardown); + g_test_add ("/gpg-verify-result/missing-key", TestFixture, NULL, test_fixture_setup, + test_missing_key, test_fixture_teardown); - g_test_add ("/gpg-verify-result/expired-signature", - TestFixture, - NULL, - test_fixture_setup, - test_expired_signature, - test_fixture_teardown); + g_test_add ("/gpg-verify-result/expired-signature", TestFixture, NULL, test_fixture_setup, + test_expired_signature, test_fixture_teardown); - g_test_add ("/gpg-verify-result/require-valid-signature", - TestFixture, - NULL, - test_fixture_setup, - test_require_valid_signature, - test_fixture_teardown); + g_test_add ("/gpg-verify-result/require-valid-signature", TestFixture, NULL, test_fixture_setup, + test_require_valid_signature, test_fixture_teardown); const char *expired_key_files[] = { "lgpl2.sig1", NULL }; - g_test_add ("/gpg-verify-result/require-valid-signature-expired-key", - TestFixture, - expired_key_files, - test_fixture_setup, - test_require_valid_signature_expired_key, + g_test_add ("/gpg-verify-result/require-valid-signature-expired-key", TestFixture, + expired_key_files, test_fixture_setup, test_require_valid_signature_expired_key, test_fixture_teardown); const char *revoked_key_files[] = { "lgpl2.sig2", NULL }; - g_test_add ("/gpg-verify-result/require-valid-signature-revoked-key", - TestFixture, - revoked_key_files, - test_fixture_setup, - test_require_valid_signature_revoked_key, + g_test_add ("/gpg-verify-result/require-valid-signature-revoked-key", TestFixture, + revoked_key_files, test_fixture_setup, test_require_valid_signature_revoked_key, test_fixture_teardown); const char *missing_key_files[] = { "lgpl2.sig3", NULL }; - g_test_add ("/gpg-verify-result/require-valid-signature-missing-key", - TestFixture, - missing_key_files, - test_fixture_setup, - test_require_valid_signature_missing_key, + g_test_add ("/gpg-verify-result/require-valid-signature-missing-key", TestFixture, + missing_key_files, test_fixture_setup, test_require_valid_signature_missing_key, test_fixture_teardown); const char *expired_signature_files[] = { "lgpl2.sig4", NULL }; - g_test_add ("/gpg-verify-result/require-valid-signature-expired-signature", - TestFixture, - expired_signature_files, - test_fixture_setup, - test_require_valid_signature_expired_signature, - test_fixture_teardown); + g_test_add ("/gpg-verify-result/require-valid-signature-expired-signature", TestFixture, + expired_signature_files, test_fixture_setup, + test_require_valid_signature_expired_signature, test_fixture_teardown); const char *expired_missing_key_files[] = { "lgpl2.sig1", "lgpl2.sig3", NULL }; - g_test_add ("/gpg-verify-result/require-valid-signature-expired-missing-key", - TestFixture, - expired_missing_key_files, - test_fixture_setup, - test_require_valid_signature_expired_missing_key, - test_fixture_teardown); + g_test_add ("/gpg-verify-result/require-valid-signature-expired-missing-key", TestFixture, + expired_missing_key_files, test_fixture_setup, + test_require_valid_signature_expired_missing_key, test_fixture_teardown); return g_test_run (); } diff --git a/tests/test-include-ostree-h.c b/tests/test-include-ostree-h.c index e23dc185..45b2c055 100644 --- a/tests/test-include-ostree-h.c +++ b/tests/test-include-ostree-h.c @@ -32,12 +32,13 @@ test_include_ostree_h_compiled (void) } /* Just ensure that we can compile with ostree.h included */ -int main (int argc, char **argv) +int +main (int argc, char **argv) { setlocale (LC_ALL, ""); g_test_init (&argc, &argv, NULL); g_test_add_func ("/include-ostree-h/compiled", test_include_ostree_h_compiled); - return g_test_run(); + return g_test_run (); } diff --git a/tests/test-kargs.c b/tests/test-kargs.c index 92441fb6..f233620c 100644 --- a/tests/test-kargs.c +++ b/tests/test-kargs.c @@ -22,25 +22,22 @@ #include "otutil.h" static gboolean -check_string_existance (OstreeKernelArgs *karg, - const char *string_to_find) +check_string_existance (OstreeKernelArgs *karg, const char *string_to_find) { - g_autofree gchar* string_with_spaces = ostree_kernel_args_to_string (karg); - g_auto(GStrv) string_list = g_strsplit (string_with_spaces, " ", -1); - return g_strv_contains ((const char* const*) string_list, string_to_find); + g_autofree gchar *string_with_spaces = ostree_kernel_args_to_string (karg); + g_auto (GStrv) string_list = g_strsplit (string_with_spaces, " ", -1); + return g_strv_contains ((const char *const *)string_list, string_to_find); } 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; @@ -49,9 +46,10 @@ kernel_args_entry_key_equal (gconstpointer data, static void test_kargs_delete (void) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; gboolean ret; - __attribute__((cleanup(ostree_kernel_args_cleanup))) OstreeKernelArgs *karg = ostree_kernel_args_new (); + __attribute__ ((cleanup (ostree_kernel_args_cleanup))) OstreeKernelArgs *karg + = ostree_kernel_args_new (); ostree_kernel_args_append (karg, "single_key=test"); ostree_kernel_args_append (karg, "test=firstval"); @@ -96,7 +94,8 @@ test_kargs_delete (void) g_assert (ret); /* verify the value array is properly updated */ GPtrArray *kargs_array = _ostree_kernel_arg_get_key_array (karg); - g_assert (!ot_ptr_array_find_with_equal_func (kargs_array, "single_key", kernel_args_entry_value_equal, NULL)); + g_assert (!ot_ptr_array_find_with_equal_func (kargs_array, "single_key", + kernel_args_entry_value_equal, NULL)); g_assert (!check_string_existance (karg, "single_key")); /* Delete specific key/value pair */ @@ -146,9 +145,10 @@ test_kargs_delete (void) static void test_kargs_replace (void) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; gboolean ret; - __attribute__((cleanup(ostree_kernel_args_cleanup))) OstreeKernelArgs *karg = ostree_kernel_args_new (); + __attribute__ ((cleanup (ostree_kernel_args_cleanup))) OstreeKernelArgs *karg + = ostree_kernel_args_new (); ostree_kernel_args_append (karg, "single_key"); ostree_kernel_args_append (karg, "test=firstval"); @@ -198,7 +198,8 @@ test_kargs_replace (void) static void test_kargs_append (void) { - __attribute__((cleanup(ostree_kernel_args_cleanup))) OstreeKernelArgs *append_arg = ostree_kernel_args_new (); + __attribute__ ((cleanup (ostree_kernel_args_cleanup))) OstreeKernelArgs *append_arg + = ostree_kernel_args_new (); /* Some valid cases (key=value) pair */ ostree_kernel_args_append (append_arg, "test=valid"); ostree_kernel_args_append (append_arg, "test=secondvalid"); @@ -211,43 +212,49 @@ test_kargs_append (void) * we have yet to find the conversion kargs to string fully "functional" */ GHashTable *kargs_table = _ostree_kernel_arg_get_kargs_table (append_arg); - GLNX_HASH_TABLE_FOREACH_KV (kargs_table, const char*, key, GPtrArray*, value_array) + GLNX_HASH_TABLE_FOREACH_KV (kargs_table, const char *, key, GPtrArray *, value_array) { if (g_str_equal (key, "test")) { - g_assert (ot_ptr_array_find_with_equal_func (value_array, "valid", kernel_args_entry_value_equal, NULL)); - g_assert (ot_ptr_array_find_with_equal_func (value_array, "secondvalid", kernel_args_entry_value_equal, NULL)); - g_assert (ot_ptr_array_find_with_equal_func (value_array, "", kernel_args_entry_value_equal, NULL)); - g_assert (ot_ptr_array_find_with_equal_func (value_array, NULL, kernel_args_entry_value_equal, NULL)); + g_assert (ot_ptr_array_find_with_equal_func (value_array, "valid", + kernel_args_entry_value_equal, NULL)); + g_assert (ot_ptr_array_find_with_equal_func (value_array, "secondvalid", + kernel_args_entry_value_equal, NULL)); + g_assert (ot_ptr_array_find_with_equal_func (value_array, "", + kernel_args_entry_value_equal, NULL)); + g_assert (ot_ptr_array_find_with_equal_func (value_array, NULL, + kernel_args_entry_value_equal, NULL)); } else { g_assert_cmpstr (key, ==, "second_test"); - g_assert (ot_ptr_array_find_with_equal_func (value_array, NULL, kernel_args_entry_value_equal, NULL)); + g_assert (ot_ptr_array_find_with_equal_func (value_array, NULL, + kernel_args_entry_value_equal, NULL)); } } /* verify the value array is properly updated */ GPtrArray *kargs_array = _ostree_kernel_arg_get_key_array (append_arg); - g_assert (ot_ptr_array_find_with_equal_func (kargs_array, "test", kernel_args_entry_key_equal, NULL)); - g_assert (ot_ptr_array_find_with_equal_func (kargs_array, "second_test", kernel_args_entry_key_equal, NULL)); + g_assert ( + ot_ptr_array_find_with_equal_func (kargs_array, "test", kernel_args_entry_key_equal, NULL)); + g_assert (ot_ptr_array_find_with_equal_func (kargs_array, "second_test", + kernel_args_entry_key_equal, NULL)); /* Up till this point, we verified that the above was all correct, we then * check ostree_kernel_args_to_string has the right result */ - g_autofree gchar* kargs_str = ostree_kernel_args_to_string (append_arg); - g_auto(GStrv) kargs_list = g_strsplit(kargs_str, " ", -1); - g_assert (g_strv_contains ((const char* const *)kargs_list, "test=valid")); - g_assert (g_strv_contains ((const char* const *)kargs_list, "test=secondvalid")); - g_assert (g_strv_contains ((const char* const *)kargs_list, "test=")); - g_assert (g_strv_contains ((const char* const *)kargs_list, "test")); - g_assert (g_strv_contains ((const char* const *)kargs_list, "second_test")); + g_autofree gchar *kargs_str = ostree_kernel_args_to_string (append_arg); + g_auto (GStrv) kargs_list = g_strsplit (kargs_str, " ", -1); + g_assert (g_strv_contains ((const char *const *)kargs_list, "test=valid")); + g_assert (g_strv_contains ((const char *const *)kargs_list, "test=secondvalid")); + g_assert (g_strv_contains ((const char *const *)kargs_list, "test=")); + g_assert (g_strv_contains ((const char *const *)kargs_list, "test")); + g_assert (g_strv_contains ((const char *const *)kargs_list, "second_test")); g_assert_cmpint (5, ==, g_strv_length (kargs_list)); } int -main (int argc, - char *argv[]) +main (int argc, char *argv[]) { g_test_init (&argc, &argv, NULL); diff --git a/tests/test-keyfile-utils.c b/tests/test-keyfile-utils.c index 49ac10fd..198e71d2 100644 --- a/tests/test-keyfile-utils.c +++ b/tests/test-keyfile-utils.c @@ -19,57 +19,41 @@ #include "config.h" #include "libglnx.h" +#include "ot-keyfile-utils.h" +#include #include #include -#include #include -#include "ot-keyfile-utils.h" static GKeyFile *g_keyfile; static void test_get_boolean_with_default (void) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; gboolean out = FALSE; - g_assert (ot_keyfile_get_boolean_with_default (g_keyfile, - "section", - "a_boolean_true", - FALSE, - &out, - &error)); + g_assert (ot_keyfile_get_boolean_with_default (g_keyfile, "section", "a_boolean_true", FALSE, + &out, &error)); g_assert_true (out); - g_assert (ot_keyfile_get_boolean_with_default (g_keyfile, - "section", - "a_boolean_false", - TRUE, - &out, - &error)); + g_assert (ot_keyfile_get_boolean_with_default (g_keyfile, "section", "a_boolean_false", TRUE, + &out, &error)); g_assert_false (out); - g_assert (ot_keyfile_get_boolean_with_default (g_keyfile, - "section", - "a_not_existing_boolean", - TRUE, - &out, - &error)); + g_assert (ot_keyfile_get_boolean_with_default (g_keyfile, "section", "a_not_existing_boolean", + TRUE, &out, &error)); g_assert_true (out); g_clear_error (&error); - g_assert (ot_keyfile_get_boolean_with_default (g_keyfile, - "a_fake_section", - "a_boolean_true", - FALSE, - &out, - &error)); + g_assert (ot_keyfile_get_boolean_with_default (g_keyfile, "a_fake_section", "a_boolean_true", + FALSE, &out, &error)); } static void test_get_value_with_default (void) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; g_autofree char *out = NULL; GLogLevelFlags always_fatal_mask; const char *section = "section"; @@ -77,55 +61,31 @@ test_get_value_with_default (void) /* Avoid that g_return_val_if_fail causes the test to fail. */ always_fatal_mask = g_log_set_always_fatal (0); - g_assert_false (ot_keyfile_get_value_with_default (g_keyfile, - NULL, - "value_foo", - "none", - &out, - &error)); + g_assert_false ( + ot_keyfile_get_value_with_default (g_keyfile, NULL, "value_foo", "none", &out, &error)); g_clear_pointer (&out, g_free); - g_assert_false (ot_keyfile_get_value_with_default (g_keyfile, - section, - NULL, - "none", - &out, - &error)); + g_assert_false ( + ot_keyfile_get_value_with_default (g_keyfile, section, NULL, "none", &out, &error)); g_clear_pointer (&out, g_free); - g_assert_false (ot_keyfile_get_value_with_default (g_keyfile, - section, - NULL, - "something", - &out, - &error)); + g_assert_false ( + ot_keyfile_get_value_with_default (g_keyfile, section, NULL, "something", &out, &error)); g_clear_pointer (&out, g_free); /* Restore the old mask. */ g_log_set_always_fatal (always_fatal_mask); - g_assert (ot_keyfile_get_value_with_default (g_keyfile, - section, - "value_foo", - "none", - &out, - &error)); + g_assert ( + ot_keyfile_get_value_with_default (g_keyfile, section, "value_foo", "none", &out, &error)); g_assert_cmpstr (out, ==, "foo"); g_clear_pointer (&out, g_free); - g_assert (ot_keyfile_get_value_with_default (g_keyfile, - section, - "a_not_existing_value", - "correct", - &out, - &error)); + g_assert (ot_keyfile_get_value_with_default (g_keyfile, section, "a_not_existing_value", + "correct", &out, &error)); g_assert_cmpstr (out, ==, "correct"); g_clear_pointer (&out, g_free); - g_assert (ot_keyfile_get_value_with_default (g_keyfile, - "a_fake_section", - "a_value_true", - "no value", - &out, - &error)); + g_assert (ot_keyfile_get_value_with_default (g_keyfile, "a_fake_section", "a_value_true", + "no value", &out, &error)); g_assert_cmpstr (out, ==, "no value"); g_clear_pointer (&out, g_free); } @@ -133,63 +93,39 @@ test_get_value_with_default (void) static void test_get_value_with_default_group_optional (void) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; g_autofree char *out = NULL; GLogLevelFlags always_fatal_mask; const char *section = "section"; -/* Avoid that g_return_val_if_fail causes the test to fail. */ + /* Avoid that g_return_val_if_fail causes the test to fail. */ always_fatal_mask = g_log_set_always_fatal (0); - g_assert_false (ot_keyfile_get_value_with_default_group_optional (g_keyfile, - NULL, - "value_foo", - "none", - &out, - &error)); + g_assert_false (ot_keyfile_get_value_with_default_group_optional (g_keyfile, NULL, "value_foo", + "none", &out, &error)); g_clear_pointer (&out, g_free); - g_assert_false (ot_keyfile_get_value_with_default_group_optional (g_keyfile, - section, - NULL, - "none", - &out, - &error)); + g_assert_false (ot_keyfile_get_value_with_default_group_optional (g_keyfile, section, NULL, + "none", &out, &error)); g_clear_pointer (&out, g_free); - g_assert_false (ot_keyfile_get_value_with_default_group_optional (g_keyfile, - section, - NULL, - "something", - &out, - &error)); + g_assert_false (ot_keyfile_get_value_with_default_group_optional (g_keyfile, section, NULL, + "something", &out, &error)); g_clear_pointer (&out, g_free); /* Restore the old mask. */ g_log_set_always_fatal (always_fatal_mask); - g_assert (ot_keyfile_get_value_with_default_group_optional (g_keyfile, - section, - "value_foo", - "none", - &out, - &error)); + g_assert (ot_keyfile_get_value_with_default_group_optional (g_keyfile, section, "value_foo", + "none", &out, &error)); g_assert_cmpstr (out, ==, "foo"); g_clear_pointer (&out, g_free); - g_assert (ot_keyfile_get_value_with_default_group_optional (g_keyfile, - section, - "a_not_existing_value", - "correct", - &out, - &error)); + g_assert (ot_keyfile_get_value_with_default_group_optional ( + g_keyfile, section, "a_not_existing_value", "correct", &out, &error)); g_assert_cmpstr (out, ==, "correct"); g_clear_pointer (&out, g_free); - g_assert (ot_keyfile_get_value_with_default_group_optional (g_keyfile, - "an_optional_section", - "a_value_true", - "no value", - &out, - &error)); + g_assert (ot_keyfile_get_value_with_default_group_optional ( + g_keyfile, "an_optional_section", "a_value_true", "no value", &out, &error)); g_clear_error (&error); g_clear_pointer (&out, g_free); } @@ -204,7 +140,7 @@ test_copy_group (void) /* Avoid that g_return_val_if_fail causes the test to fail. */ always_fatal_mask = g_log_set_always_fatal (0); - g_autoptr(GKeyFile) tmp = g_key_file_new (); + g_autoptr (GKeyFile) tmp = g_key_file_new (); g_assert_false (ot_keyfile_copy_group (NULL, tmp, section)); g_assert_false (ot_keyfile_copy_group (g_keyfile, NULL, section)); @@ -215,9 +151,9 @@ test_copy_group (void) g_assert_true (ot_keyfile_copy_group (g_keyfile, tmp, section)); - g_auto(GStrv) keys = g_key_file_get_keys (g_keyfile, section, &length, NULL); + g_auto (GStrv) keys = g_key_file_get_keys (g_keyfile, section, &length, NULL); g_strfreev (g_key_file_get_keys (tmp, section, &length2, NULL)); - g_assert_cmpint(length, ==, length2); + g_assert_cmpint (length, ==, length2); for (gsize ii = 0; ii < length; ii++) { @@ -225,7 +161,6 @@ test_copy_group (void) g_autofree char *value2 = g_key_file_get_value (g_keyfile, section, keys[ii], NULL); g_assert_cmpstr (value, ==, value2); } - } static void @@ -238,7 +173,8 @@ fill_keyfile (GKeyFile *file) g_key_file_set_value (file, "section", "value_bar", "bar"); } -int main (int argc, char **argv) +int +main (int argc, char **argv) { int ret; g_test_init (&argc, &argv, NULL); @@ -247,10 +183,11 @@ int main (int argc, char **argv) g_test_add_func ("/keyfile-utils/get-boolean-with-default", test_get_boolean_with_default); g_test_add_func ("/keyfile-utils/get-value-with-default", test_get_value_with_default); - g_test_add_func ("/keyfile-utils/get-value-with-default-group-optional", test_get_value_with_default_group_optional); + g_test_add_func ("/keyfile-utils/get-value-with-default-group-optional", + test_get_value_with_default_group_optional); g_test_add_func ("/keyfile-utils/copy-group", test_copy_group); - ret = g_test_run(); + ret = g_test_run (); g_key_file_free (g_keyfile); diff --git a/tests/test-libarchive-import.c b/tests/test-libarchive-import.c index a89fcc24..86536fc2 100644 --- a/tests/test-libarchive-import.c +++ b/tests/test-libarchive-import.c @@ -19,17 +19,18 @@ #include "config.h" #include "libglnx.h" +#include #include #include -#include #include -#include #include "ostree-libarchive-private.h" #include #include +#include -typedef struct { +typedef struct +{ OstreeRepo *repo; int fd; int fd_empty; @@ -41,7 +42,7 @@ static void test_data_init (TestData *td) { GError *error = NULL; - g_autoptr(OtAutoArchiveWrite) a = archive_write_new (); + g_autoptr (OtAutoArchiveWrite) a = archive_write_new (); struct archive_entry *ae; uid_t uid = getuid (); gid_t gid = getgid (); @@ -50,7 +51,7 @@ test_data_init (TestData *td) g_assert_cmpint (0, ==, chdir (td->tmpd)); td->fd = openat (AT_FDCWD, "foo.tar.gz", O_CREAT | O_EXCL | O_RDWR | O_CLOEXEC, 0644); - (void) unlink ("foo.tar.gz"); + (void)unlink ("foo.tar.gz"); g_assert_no_error (error); g_assert (td->fd >= 0); @@ -122,7 +123,7 @@ test_data_init (TestData *td) td->fd_empty = openat (AT_FDCWD, "empty.tar.gz", O_CREAT | O_EXCL | O_RDWR | O_CLOEXEC, 0644); g_assert (td->fd_empty >= 0); - (void) unlink ("empty.tar.gz"); + (void)unlink ("empty.tar.gz"); g_assert_cmpint (ARCHIVE_OK, ==, archive_write_free (a)); a = archive_write_new (); @@ -133,7 +134,8 @@ test_data_init (TestData *td) g_assert_cmpint (0, ==, archive_write_open_fd (a, td->fd_empty)); g_assert_cmpint (ARCHIVE_OK, ==, archive_write_close (a)); - { g_autoptr(GFile) repopath = g_file_new_for_path ("repo"); + { + g_autoptr (GFile) repopath = g_file_new_for_path ("repo"); td->repo = ostree_repo_new (repopath); g_assert_cmpint (0, ==, mkdir ("repo", 0755)); @@ -172,10 +174,12 @@ test_archive_setup (int fd, struct archive *a) static void test_libarchive_noautocreate_empty (gconstpointer data) { - TestData *td = (void*)data; + TestData *td = (void *)data; GError *error = NULL; - g_autoptr(OtAutoArchiveRead) a = archive_read_new (); - OstreeRepoImportArchiveOptions opts = { 0, }; + g_autoptr (OtAutoArchiveRead) a = archive_read_new (); + OstreeRepoImportArchiveOptions opts = { + 0, + }; glnx_unref_object OstreeMutableTree *mtree = ostree_mutable_tree_new (); if (td->skip_all != NULL) @@ -194,10 +198,12 @@ test_libarchive_noautocreate_empty (gconstpointer data) static void test_libarchive_autocreate_empty (gconstpointer data) { - TestData *td = (void*)data; - g_autoptr(GError) error = NULL; - g_autoptr(OtAutoArchiveRead) a = archive_read_new (); - OstreeRepoImportArchiveOptions opts = { 0, }; + TestData *td = (void *)data; + g_autoptr (GError) error = NULL; + g_autoptr (OtAutoArchiveRead) a = archive_read_new (); + OstreeRepoImportArchiveOptions opts = { + 0, + }; glnx_unref_object OstreeMutableTree *mtree = ostree_mutable_tree_new (); if (td->skip_all != NULL) @@ -218,10 +224,12 @@ test_libarchive_autocreate_empty (gconstpointer data) static void test_libarchive_error_device_file (gconstpointer data) { - TestData *td = (void*)data; - g_autoptr(GError) error = NULL; - g_autoptr(OtAutoArchiveRead) a = archive_read_new (); - OstreeRepoImportArchiveOptions opts = { 0, }; + TestData *td = (void *)data; + g_autoptr (GError) error = NULL; + g_autoptr (OtAutoArchiveRead) a = archive_read_new (); + OstreeRepoImportArchiveOptions opts = { + 0, + }; glnx_unref_object OstreeMutableTree *mtree = ostree_mutable_tree_new (); if (td->skip_all != NULL) @@ -244,9 +252,8 @@ skip_if_no_xattr (TestData *td) if (setxattr (td->tmpd, "user.test-xattr-support", "yes", 4, 0) != 0) { int saved_errno = errno; - g_autofree gchar *message - = g_strdup_printf ("unable to setxattr on \"%s\": %s", - td->tmpd, g_strerror (saved_errno)); + g_autofree gchar *message = g_strdup_printf ("unable to setxattr on \"%s\": %s", td->tmpd, + g_strerror (saved_errno)); g_test_skip (message); return TRUE; } @@ -255,29 +262,23 @@ skip_if_no_xattr (TestData *td) } static gboolean -import_write_and_ref (OstreeRepo *repo, - OstreeRepoImportArchiveOptions *opts, - struct archive *a, - const char *ref, - OstreeRepoCommitModifier *modifier, - GError **error) +import_write_and_ref (OstreeRepo *repo, OstreeRepoImportArchiveOptions *opts, struct archive *a, + const char *ref, OstreeRepoCommitModifier *modifier, GError **error) { - g_autoptr(OstreeMutableTree) mtree = ostree_mutable_tree_new (); + g_autoptr (OstreeMutableTree) mtree = ostree_mutable_tree_new (); if (!ostree_repo_prepare_transaction (repo, NULL, NULL, error)) return FALSE; - if (!ostree_repo_import_archive_to_mtree (repo, opts, a, mtree, modifier, - NULL, error)) + if (!ostree_repo_import_archive_to_mtree (repo, opts, a, mtree, modifier, NULL, error)) return FALSE; - g_autoptr(GFile) root = NULL; + g_autoptr (GFile) root = NULL; if (!ostree_repo_write_mtree (repo, mtree, &root, NULL, error)) return FALSE; g_autofree char *commit_checksum = NULL; - if (!ostree_repo_write_commit (repo, NULL, "", "", NULL, - OSTREE_REPO_FILE (root), + if (!ostree_repo_write_commit (repo, NULL, "", "", NULL, OSTREE_REPO_FILE (root), &commit_checksum, NULL, error)) return FALSE; @@ -292,10 +293,12 @@ import_write_and_ref (OstreeRepo *repo, static void test_libarchive_ignore_device_file (gconstpointer data) { - TestData *td = (void*)data; - g_autoptr(GError) error = NULL; - g_autoptr(OtAutoArchiveRead) a = archive_read_new (); - OstreeRepoImportArchiveOptions opts = { 0, }; + TestData *td = (void *)data; + g_autoptr (GError) error = NULL; + g_autoptr (OtAutoArchiveRead) a = archive_read_new (); + OstreeRepoImportArchiveOptions opts = { + 0, + }; if (skip_if_no_xattr (td)) goto out; @@ -328,7 +331,7 @@ test_libarchive_ignore_device_file (gconstpointer data) g_assert (error != NULL); g_clear_error (&error); - out: +out: g_assert_no_error (error); } @@ -360,10 +363,12 @@ check_ostree_convention (GError *error) static void test_libarchive_ostree_convention (gconstpointer data) { - TestData *td = (void*)data; + TestData *td = (void *)data; GError *error = NULL; - g_autoptr(OtAutoArchiveRead) a = archive_read_new (); - OstreeRepoImportArchiveOptions opts = { 0, }; + g_autoptr (OtAutoArchiveRead) a = archive_read_new (); + OstreeRepoImportArchiveOptions opts = { + 0, + }; if (skip_if_no_xattr (td)) goto out; @@ -386,21 +391,17 @@ test_libarchive_ostree_convention (gconstpointer data) if (!check_ostree_convention (error)) goto out; - out: +out: g_assert_no_error (error); } -static GVariant* -xattr_cb (OstreeRepo *repo, - const char *path, - GFileInfo *file_info, - gpointer user_data) +static GVariant * +xattr_cb (OstreeRepo *repo, const char *path, GFileInfo *file_info, gpointer user_data) { - g_auto(GVariantBuilder) builder; - g_variant_builder_init (&builder, (GVariantType*)"a(ayay)"); + g_auto (GVariantBuilder) builder; + g_variant_builder_init (&builder, (GVariantType *)"a(ayay)"); if (strcmp (path, "/anotherfile") == 0) - g_variant_builder_add (&builder, "(@ay@ay)", - g_variant_new_bytestring ("user.data"), + g_variant_builder_add (&builder, "(@ay@ay)", g_variant_new_bytestring ("user.data"), g_variant_new_bytestring ("mydata")); return g_variant_ref_sink (g_variant_builder_end (&builder)); } @@ -408,11 +409,11 @@ xattr_cb (OstreeRepo *repo, static void test_libarchive_xattr_callback (gconstpointer data) { - TestData *td = (void*)data; + TestData *td = (void *)data; GError *error = NULL; - g_autoptr(OtAutoArchiveRead) a = archive_read_new (); + g_autoptr (OtAutoArchiveRead) a = archive_read_new (); OstreeRepoImportArchiveOptions opts = { 0 }; - g_autoptr(OstreeRepoCommitModifier) modifier = NULL; + g_autoptr (OstreeRepoCommitModifier) modifier = NULL; char buf[7] = { 0 }; if (skip_if_no_xattr (td)) @@ -425,8 +426,7 @@ test_libarchive_xattr_callback (gconstpointer data) } modifier = ostree_repo_commit_modifier_new (0, NULL, NULL, NULL); - ostree_repo_commit_modifier_set_xattr_callback (modifier, xattr_cb, - NULL, NULL); + ostree_repo_commit_modifier_set_xattr_callback (modifier, xattr_cb, NULL, NULL); test_archive_setup (td->fd, a); @@ -450,16 +450,16 @@ test_libarchive_xattr_callback (gconstpointer data) g_assert_cmpstr (buf, ==, "mydata"); - out: +out: g_assert_no_error (error); } static void test_libarchive_xattr_import (gconstpointer data) { - TestData *td = (void*)data; + TestData *td = (void *)data; GError *error = NULL; - g_autoptr(OtAutoArchiveRead) a = archive_read_new (); + g_autoptr (OtAutoArchiveRead) a = archive_read_new (); OstreeRepoImportArchiveOptions opts = { 0 }; char buf[15] = { 0 }; @@ -495,20 +495,20 @@ test_libarchive_xattr_import (gconstpointer data) x = getxattr ("import-checkout/anotherfile", "user.b_key", buf, sizeof buf - 1); g_assert_cmpint (x, ==, 14); - g_assert (memcmp(buf, "contains\0nuls", 14) == 0); + g_assert (memcmp (buf, "contains\0nuls", 14) == 0); - out: +out: g_assert_no_error (error); } static void test_libarchive_xattr_import_skip_xattr (gconstpointer data) { - TestData *td = (void*)data; + TestData *td = (void *)data; GError *error = NULL; - g_autoptr(OtAutoArchiveRead) a = archive_read_new (); + g_autoptr (OtAutoArchiveRead) a = archive_read_new (); OstreeRepoImportArchiveOptions opts = { 0 }; - g_autoptr(OstreeRepoCommitModifier) modifier = NULL; + g_autoptr (OstreeRepoCommitModifier) modifier = NULL; if (skip_if_no_xattr (td)) goto out; @@ -523,8 +523,8 @@ test_libarchive_xattr_import_skip_xattr (gconstpointer data) opts.ignore_unsupported_content = TRUE; - modifier = ostree_repo_commit_modifier_new ( - OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS, NULL, NULL, NULL); + modifier = ostree_repo_commit_modifier_new (OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS, NULL, + NULL, NULL); if (!import_write_and_ref (td->repo, &opts, a, "baz", modifier, &error)) goto out; @@ -535,27 +535,27 @@ test_libarchive_xattr_import_skip_xattr (gconstpointer data) ssize_t n_attrs = listxattr ("import-checkout/anotherfile", NULL, 0); g_assert_cmpint (n_attrs, ==, 0); - out: +out: g_assert_no_error (error); } -static GVariant* -path_cb (OstreeRepo *repo, - const char *path, - GFileInfo *file_info, - gpointer user_data) +static GVariant * +path_cb (OstreeRepo *repo, const char *path, GFileInfo *file_info, gpointer user_data) { if (strcmp (path, "/etc/file") == 0) - *(gboolean*)user_data = TRUE; + *(gboolean *)user_data = TRUE; return NULL; } static void entry_pathname_test_helper (gconstpointer data, gboolean on) { - TestData *td = (void*)data; GError *error = NULL; - g_autoptr(OtAutoArchiveRead) a = archive_read_new (); - OstreeRepoImportArchiveOptions opts = { 0, }; + TestData *td = (void *)data; + GError *error = NULL; + g_autoptr (OtAutoArchiveRead) a = archive_read_new (); + OstreeRepoImportArchiveOptions opts = { + 0, + }; OstreeRepoCommitModifier *modifier = NULL; gboolean met_etc_file = FALSE; @@ -569,8 +569,7 @@ entry_pathname_test_helper (gconstpointer data, gboolean on) } modifier = ostree_repo_commit_modifier_new (0, NULL, NULL, NULL); - ostree_repo_commit_modifier_set_xattr_callback (modifier, path_cb, - NULL, &met_etc_file); + ostree_repo_commit_modifier_set_xattr_callback (modifier, path_cb, NULL, &met_etc_file); test_archive_setup (td->fd, a); @@ -601,7 +600,7 @@ entry_pathname_test_helper (gconstpointer data, gboolean on) } ostree_repo_commit_modifier_unref (modifier); - out: +out: g_assert_no_error (error); } @@ -620,12 +619,12 @@ test_libarchive_use_entry_pathname (gconstpointer data) static void test_libarchive_selinux (gconstpointer data) { - TestData *td = (void*)data; + TestData *td = (void *)data; GError *error = NULL; - g_autoptr(OtAutoArchiveRead) a = archive_read_new (); + g_autoptr (OtAutoArchiveRead) a = archive_read_new (); OstreeRepoImportArchiveOptions opts = { 0 }; glnx_unref_object OstreeSePolicy *sepol = NULL; - g_autoptr(OstreeRepoCommitModifier) modifier = NULL; + g_autoptr (OstreeRepoCommitModifier) modifier = NULL; char buf[64] = { 0 }; if (skip_if_no_xattr (td)) @@ -678,13 +677,16 @@ test_libarchive_selinux (gconstpointer data) buf[(sizeof buf) - 1] = '\0'; g_assert_cmpstr (buf, ==, "system_u:object_r:etc_t:s0"); - out: +out: g_assert_no_error (error); } -int main (int argc, char **argv) +int +main (int argc, char **argv) { - TestData td = {NULL,}; + TestData td = { + NULL, + }; int r; test_data_init (&td); @@ -697,17 +699,19 @@ int main (int argc, char **argv) g_test_add_data_func ("/libarchive/ignore-device-file", &td, test_libarchive_ignore_device_file); g_test_add_data_func ("/libarchive/ostree-convention", &td, test_libarchive_ostree_convention); g_test_add_data_func ("/libarchive/xattr-import", &td, test_libarchive_xattr_import); - g_test_add_data_func ("/libarchive/xattr-import-skip-xattr", &td, test_libarchive_xattr_import_skip_xattr); + g_test_add_data_func ("/libarchive/xattr-import-skip-xattr", &td, + test_libarchive_xattr_import_skip_xattr); g_test_add_data_func ("/libarchive/xattr-callback", &td, test_libarchive_xattr_callback); - g_test_add_data_func ("/libarchive/no-use-entry-pathname", &td, test_libarchive_no_use_entry_pathname); + g_test_add_data_func ("/libarchive/no-use-entry-pathname", &td, + test_libarchive_no_use_entry_pathname); g_test_add_data_func ("/libarchive/use-entry-pathname", &td, test_libarchive_use_entry_pathname); g_test_add_data_func ("/libarchive/selinux", &td, test_libarchive_selinux); - r = g_test_run(); + r = g_test_run (); g_clear_object (&td.repo); if (td.tmpd && g_getenv ("TEST_SKIP_CLEANUP") == NULL) - (void) glnx_shutil_rm_rf_at (AT_FDCWD, td.tmpd, NULL, NULL); + (void)glnx_shutil_rm_rf_at (AT_FDCWD, td.tmpd, NULL, NULL); g_free (td.tmpd); return r; } diff --git a/tests/test-lzma.c b/tests/test-lzma.c index c26bc8d2..5c1ce9dc 100644 --- a/tests/test-lzma.c +++ b/tests/test-lzma.c @@ -19,32 +19,33 @@ #include "config.h" #include "libglnx.h" -#include -#include -#include -#include #include "ostree-lzma-compressor.h" #include "ostree-lzma-decompressor.h" -#include +#include #include +#include +#include +#include +#include static void helper_test_compress_decompress (const guint8 *data, gssize data_size) { - g_autoptr(GError) error = NULL; - g_autoptr(GOutputStream) out_compress = g_memory_output_stream_new_resizable (); - g_autoptr(GOutputStream) out_decompress = NULL; - g_autoptr(GInputStream) in_compress = g_memory_input_stream_new_from_data (data, data_size, NULL); - g_autoptr(GInputStream) in_decompress = NULL; + g_autoptr (GError) error = NULL; + g_autoptr (GOutputStream) out_compress = g_memory_output_stream_new_resizable (); + g_autoptr (GOutputStream) out_decompress = NULL; + g_autoptr (GInputStream) in_compress + = g_memory_input_stream_new_from_data (data, data_size, NULL); + g_autoptr (GInputStream) in_decompress = NULL; { gssize n_bytes_written; - g_autoptr(GInputStream) convin = NULL; - g_autoptr(GConverter) compressor = (GConverter*)_ostree_lzma_compressor_new (NULL); - convin = g_converter_input_stream_new ((GInputStream*) in_compress, compressor); - n_bytes_written = g_output_stream_splice (out_compress, convin, - G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET | G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE, - NULL, &error); + g_autoptr (GInputStream) convin = NULL; + g_autoptr (GConverter) compressor = (GConverter *)_ostree_lzma_compressor_new (NULL); + convin = g_converter_input_stream_new ((GInputStream *)in_compress, compressor); + n_bytes_written = g_output_stream_splice ( + out_compress, convin, + G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET | G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE, NULL, &error); g_assert_cmpint (n_bytes_written, >, 0); g_assert_no_error (error); } @@ -53,25 +54,26 @@ helper_test_compress_decompress (const guint8 *data, gssize data_size) { gssize n_bytes_written; - g_autoptr(GInputStream) convin = NULL; - g_autoptr(GConverter) decompressor = (GConverter*)_ostree_lzma_decompressor_new (); - g_autoptr(GBytes) bytes = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (out_compress)); + g_autoptr (GInputStream) convin = NULL; + g_autoptr (GConverter) decompressor = (GConverter *)_ostree_lzma_decompressor_new (); + g_autoptr (GBytes) bytes + = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (out_compress)); in_decompress = g_memory_input_stream_new_from_bytes (bytes); - convin = g_converter_input_stream_new ((GInputStream*) in_decompress, decompressor); - n_bytes_written = g_output_stream_splice (out_decompress, convin, - G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET | G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE, - NULL, &error); + convin = g_converter_input_stream_new ((GInputStream *)in_decompress, decompressor); + n_bytes_written = g_output_stream_splice ( + out_decompress, convin, + G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET | G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE, NULL, &error); g_assert_cmpint (n_bytes_written, >, 0); g_assert_no_error (error); } - g_assert_cmpint (g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (out_decompress)), ==, data_size); + g_assert_cmpint (g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (out_decompress)), + ==, data_size); { gpointer new_data = g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (out_decompress)); g_assert_cmpint (memcmp (new_data, data, data_size), ==, 0); } - } static void @@ -79,11 +81,11 @@ test_lzma_random (void) { gssize i; guint8 buffer[4096]; - g_autoptr(GRand) r = g_rand_new (); - for (i = 0; i < sizeof(buffer); i++) + g_autoptr (GRand) r = g_rand_new (); + for (i = 0; i < sizeof (buffer); i++) buffer[i] = g_rand_int (r); - for (i = 2; i < (sizeof(buffer) - 1); i *= 2) + for (i = 2; i < (sizeof (buffer) - 1); i *= 2) { helper_test_compress_decompress (buffer, i - 1); helper_test_compress_decompress (buffer, i); @@ -97,16 +99,17 @@ test_lzma_big_buffer (void) const guint32 buffer_size = 1 << 21; g_autofree guint8 *buffer = g_new (guint8, buffer_size); - memset (buffer, (int) 'a', buffer_size); + memset (buffer, (int)'a', buffer_size); helper_test_compress_decompress (buffer, buffer_size); } -int main (int argc, char **argv) +int +main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); g_test_add_func ("/lzma/random-buffer", test_lzma_random); g_test_add_func ("/lzma/big-buffer", test_lzma_big_buffer); - return g_test_run(); + return g_test_run (); } diff --git a/tests/test-mock-gio.c b/tests/test-mock-gio.c index 719dc6cd..94682f2c 100644 --- a/tests/test-mock-gio.c +++ b/tests/test-mock-gio.c @@ -24,8 +24,8 @@ #include "config.h" #include -#include #include +#include #include #include "test-mock-gio.h" @@ -60,7 +60,7 @@ struct _OstreeMockVolumeMonitor GVolumeMonitor parent_instance; GList *mounts; /* (element-type OstreeMockMount) */ - GList *volumes; /* (element-type OstreeMockVolume) */ + GList *volumes; /* (element-type OstreeMockVolume) */ }; G_DEFINE_TYPE (OstreeMockVolumeMonitor, ostree_mock_volume_monitor, G_TYPE_VOLUME_MONITOR) @@ -69,14 +69,14 @@ static GList * ostree_mock_volume_monitor_get_mounts (GVolumeMonitor *monitor) { OstreeMockVolumeMonitor *self = OSTREE_MOCK_VOLUME_MONITOR (monitor); - return g_list_copy_deep (self->mounts, (GCopyFunc) g_object_ref, NULL); + return g_list_copy_deep (self->mounts, (GCopyFunc)g_object_ref, NULL); } static GList * ostree_mock_volume_monitor_get_volumes (GVolumeMonitor *monitor) { OstreeMockVolumeMonitor *self = OSTREE_MOCK_VOLUME_MONITOR (monitor); - return g_list_copy_deep (self->volumes, (GCopyFunc) g_object_ref, NULL); + return g_list_copy_deep (self->volumes, (GCopyFunc)g_object_ref, NULL); } static void @@ -128,14 +128,13 @@ ostree_mock_volume_monitor_class_init (OstreeMockVolumeMonitorClass *klass) * Since: 2017.8 */ GVolumeMonitor * -ostree_mock_volume_monitor_new (GList *mounts, - GList *volumes) +ostree_mock_volume_monitor_new (GList *mounts, GList *volumes) { - g_autoptr(OstreeMockVolumeMonitor) monitor = NULL; + g_autoptr (OstreeMockVolumeMonitor) monitor = NULL; monitor = g_object_new (OSTREE_TYPE_MOCK_VOLUME_MONITOR, NULL); - monitor->mounts = g_list_copy_deep (mounts, (GCopyFunc) g_object_ref, NULL); - monitor->volumes = g_list_copy_deep (volumes, (GCopyFunc) g_object_ref, NULL); + monitor->mounts = g_list_copy_deep (mounts, (GCopyFunc)g_object_ref, NULL); + monitor->volumes = g_list_copy_deep (volumes, (GCopyFunc)g_object_ref, NULL); return (GVolumeMonitor *)g_steal_pointer (&monitor); } @@ -147,8 +146,8 @@ struct _OstreeMockVolume GObject parent_instance; gchar *name; - GDrive *drive; /* (owned) (nullable) */ - GMount *mount; /* (owned) (nullable) */ + GDrive *drive; /* (owned) (nullable) */ + GMount *mount; /* (owned) (nullable) */ }; static void ostree_mock_volume_iface_init (GVolumeIface *iface); @@ -231,11 +230,9 @@ ostree_mock_volume_iface_init (GVolumeIface *iface) * Since: 2017.8 */ OstreeMockVolume * -ostree_mock_volume_new (const gchar *name, - GDrive *drive, - GMount *mount) +ostree_mock_volume_new (const gchar *name, GDrive *drive, GMount *mount) { - g_autoptr(OstreeMockVolume) volume = NULL; + g_autoptr (OstreeMockVolume) volume = NULL; volume = g_object_new (OSTREE_TYPE_MOCK_VOLUME, NULL); volume->name = g_strdup (name); @@ -302,7 +299,7 @@ ostree_mock_drive_iface_init (GDriveIface *iface) OstreeMockDrive * ostree_mock_drive_new (gboolean is_removable) { - g_autoptr(OstreeMockDrive) drive = NULL; + g_autoptr (OstreeMockDrive) drive = NULL; drive = g_object_new (OSTREE_TYPE_MOCK_DRIVE, NULL); drive->is_removable = is_removable; @@ -316,8 +313,8 @@ struct _OstreeMockMount { GObject parent_instance; - gchar *name; /* (owned) */ - GFile *root; /* (owned) */ + gchar *name; /* (owned) */ + GFile *root; /* (owned) */ }; static void ostree_mock_mount_iface_init (GMountIface *iface); @@ -387,10 +384,9 @@ ostree_mock_mount_iface_init (GMountIface *iface) * Since: 2017.8 */ OstreeMockMount * -ostree_mock_mount_new (const gchar *name, - GFile *root) +ostree_mock_mount_new (const gchar *name, GFile *root) { - g_autoptr(OstreeMockMount) mount = NULL; + g_autoptr (OstreeMockMount) mount = NULL; mount = g_object_new (OSTREE_TYPE_MOCK_MOUNT, NULL); mount->name = g_strdup (name); diff --git a/tests/test-mock-gio.h b/tests/test-mock-gio.h index 2cc38f15..fae260ab 100644 --- a/tests/test-mock-gio.h +++ b/tests/test-mock-gio.h @@ -23,8 +23,8 @@ #pragma once #include -#include #include +#include #include #include "ostree-types.h" @@ -35,24 +35,36 @@ G_BEGIN_DECLS /* Manually expanded version of the following, omitting autoptr support (for GLib < 2.44): G_GNUC_INTERNAL -G_DECLARE_FINAL_TYPE (OstreeMockVolumeMonitor, ostree_mock_volume_monitor, OSTREE, MOCK_VOLUME_MONITOR, GVolumeMonitor) */ +G_DECLARE_FINAL_TYPE (OstreeMockVolumeMonitor, ostree_mock_volume_monitor, OSTREE, +MOCK_VOLUME_MONITOR, GVolumeMonitor) */ G_GNUC_INTERNAL GType ostree_mock_volume_monitor_get_type (void); G_GNUC_BEGIN_IGNORE_DEPRECATIONS typedef struct _OstreeMockVolumeMonitor OstreeMockVolumeMonitor; -typedef struct { GVolumeMonitorClass parent_class; } OstreeMockVolumeMonitorClass; - -static inline OstreeMockVolumeMonitor *OSTREE_MOCK_VOLUME_MONITOR (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_mock_volume_monitor_get_type (), OstreeMockVolumeMonitor); } -static inline gboolean OSTREE_IS_MOCK_VOLUME_MONITOR (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_mock_volume_monitor_get_type ()); } +typedef struct +{ + GVolumeMonitorClass parent_class; +} OstreeMockVolumeMonitorClass; + +static inline OstreeMockVolumeMonitor * +OSTREE_MOCK_VOLUME_MONITOR (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_mock_volume_monitor_get_type (), + OstreeMockVolumeMonitor); +} +static inline gboolean +OSTREE_IS_MOCK_VOLUME_MONITOR (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_mock_volume_monitor_get_type ()); +} G_GNUC_END_IGNORE_DEPRECATIONS G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeMockVolumeMonitor, g_object_unref) G_GNUC_INTERNAL -GVolumeMonitor *ostree_mock_volume_monitor_new (GList *mounts, - GList *volumes); +GVolumeMonitor *ostree_mock_volume_monitor_new (GList *mounts, GList *volumes); #define OSTREE_TYPE_MOCK_VOLUME (ostree_mock_volume_get_type ()) @@ -65,18 +77,27 @@ GType ostree_mock_volume_get_type (void); G_GNUC_BEGIN_IGNORE_DEPRECATIONS typedef struct _OstreeMockVolume OstreeMockVolume; -typedef struct { GObjectClass parent_class; } OstreeMockVolumeClass; - -static inline OstreeMockVolume *OSTREE_MOCK_VOLUME (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_mock_volume_get_type (), OstreeMockVolume); } -static inline gboolean OSTREE_IS_MOCK_VOLUME (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_mock_volume_get_type ()); } +typedef struct +{ + GObjectClass parent_class; +} OstreeMockVolumeClass; + +static inline OstreeMockVolume * +OSTREE_MOCK_VOLUME (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_mock_volume_get_type (), OstreeMockVolume); +} +static inline gboolean +OSTREE_IS_MOCK_VOLUME (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_mock_volume_get_type ()); +} G_GNUC_END_IGNORE_DEPRECATIONS G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeMockVolume, g_object_unref) G_GNUC_INTERNAL -OstreeMockVolume *ostree_mock_volume_new (const gchar *name, - GDrive *drive, - GMount *mount); +OstreeMockVolume *ostree_mock_volume_new (const gchar *name, GDrive *drive, GMount *mount); #define OSTREE_TYPE_MOCK_DRIVE (ostree_mock_drive_get_type ()) @@ -89,10 +110,21 @@ GType ostree_mock_drive_get_type (void); G_GNUC_BEGIN_IGNORE_DEPRECATIONS typedef struct _OstreeMockDrive OstreeMockDrive; -typedef struct { GObjectClass parent_class; } OstreeMockDriveClass; - -static inline OstreeMockDrive *OSTREE_MOCK_DRIVE (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_mock_drive_get_type (), OstreeMockDrive); } -static inline gboolean OSTREE_IS_MOCK_DRIVE (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_mock_drive_get_type ()); } +typedef struct +{ + GObjectClass parent_class; +} OstreeMockDriveClass; + +static inline OstreeMockDrive * +OSTREE_MOCK_DRIVE (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_mock_drive_get_type (), OstreeMockDrive); +} +static inline gboolean +OSTREE_IS_MOCK_DRIVE (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_mock_drive_get_type ()); +} G_GNUC_END_IGNORE_DEPRECATIONS G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeMockDrive, g_object_unref) @@ -111,16 +143,26 @@ GType ostree_mock_mount_get_type (void); G_GNUC_BEGIN_IGNORE_DEPRECATIONS typedef struct _OstreeMockMount OstreeMockMount; -typedef struct { GObjectClass parent_class; } OstreeMockMountClass; - -static inline OstreeMockMount *OSTREE_MOCK_MOUNT (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_mock_mount_get_type (), OstreeMockMount); } -static inline gboolean OSTREE_IS_MOCK_MOUNT (gpointer ptr) { return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_mock_mount_get_type ()); } +typedef struct +{ + GObjectClass parent_class; +} OstreeMockMountClass; + +static inline OstreeMockMount * +OSTREE_MOCK_MOUNT (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_CAST (ptr, ostree_mock_mount_get_type (), OstreeMockMount); +} +static inline gboolean +OSTREE_IS_MOCK_MOUNT (gpointer ptr) +{ + return G_TYPE_CHECK_INSTANCE_TYPE (ptr, ostree_mock_mount_get_type ()); +} G_GNUC_END_IGNORE_DEPRECATIONS G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeMockMount, g_object_unref) G_GNUC_INTERNAL -OstreeMockMount *ostree_mock_mount_new (const gchar *name, - GFile *root); +OstreeMockMount *ostree_mock_mount_new (const gchar *name, GFile *root); G_END_DECLS diff --git a/tests/test-mutable-tree.c b/tests/test-mutable-tree.c index e5a6b040..4ef35930 100644 --- a/tests/test-mutable-tree.c +++ b/tests/test-mutable-tree.c @@ -20,16 +20,16 @@ #include "config.h" #include "libglnx.h" #include "ostree-mutable-tree.h" +#include "ot-unix-utils.h" +#include #include #include -#include #include -#include "ot-unix-utils.h" static void test_metadata_checksum (void) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; const char *checksum = "12345678901234567890123456789012"; glnx_unref_object OstreeMutableTree *tree = ostree_mutable_tree_new (); @@ -45,20 +45,16 @@ test_metadata_checksum (void) g_assert (ostree_mutable_tree_ensure_dir (tree, "subdir", &subdir, &error)); g_assert_nonnull (subdir); - ostree_mutable_tree_set_contents_checksum ( - subdir, "11111111111111111111111111111111"); - ostree_mutable_tree_set_metadata_checksum ( - subdir, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); - ostree_mutable_tree_set_contents_checksum ( - tree, "abcdefabcdefabcdefabcdefabcdefab"); + ostree_mutable_tree_set_contents_checksum (subdir, "11111111111111111111111111111111"); + ostree_mutable_tree_set_metadata_checksum (subdir, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + ostree_mutable_tree_set_contents_checksum (tree, "abcdefabcdefabcdefabcdefabcdefab"); g_assert_cmpstr (ostree_mutable_tree_get_contents_checksum (tree), ==, - "abcdefabcdefabcdefabcdefabcdefab"); - ostree_mutable_tree_set_metadata_checksum ( - subdir, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); + "abcdefabcdefabcdefabcdefabcdefab"); + ostree_mutable_tree_set_metadata_checksum (subdir, "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); g_assert_null (ostree_mutable_tree_get_contents_checksum (tree)); g_assert_cmpstr (ostree_mutable_tree_get_contents_checksum (subdir), ==, - "11111111111111111111111111111111"); + "11111111111111111111111111111111"); } static void @@ -66,16 +62,14 @@ test_mutable_tree_walk (void) { glnx_unref_object OstreeMutableTree *tree = ostree_mutable_tree_new (); glnx_unref_object OstreeMutableTree *parent = NULL; - g_autoptr(GPtrArray) split_path = NULL; + g_autoptr (GPtrArray) split_path = NULL; GError *error = NULL; const char *pathname = "a/b/c/d/e/f/g/i"; const char *checksum = "01234567890123456789012345678901"; g_assert (ot_util_path_split_validate (pathname, &split_path, &error)); - g_assert (ostree_mutable_tree_ensure_parent_dirs (tree, split_path, - checksum, &parent, - &error)); + g_assert (ostree_mutable_tree_ensure_parent_dirs (tree, split_path, checksum, &parent, &error)); { glnx_unref_object OstreeMutableTree *subdir = NULL; g_assert (ostree_mutable_tree_walk (tree, split_path, 0, &subdir, &error)); @@ -106,8 +100,8 @@ test_ensure_parent_dirs (void) { glnx_unref_object OstreeMutableTree *tree = ostree_mutable_tree_new (); glnx_unref_object OstreeMutableTree *parent = NULL; - g_autoptr(GPtrArray) split_path = NULL; - g_autoptr(GError) error = NULL; + g_autoptr (GPtrArray) split_path = NULL; + g_autoptr (GError) error = NULL; const char *pathname = "/foo/bar/baz"; const char *checksum = "01234567890123456789012345678901"; g_autofree char *source_checksum = NULL; @@ -117,15 +111,12 @@ test_ensure_parent_dirs (void) g_assert (ot_util_path_split_validate (pathname, &split_path, &error)); - g_assert (ostree_mutable_tree_ensure_parent_dirs (tree, split_path, - checksum, &parent, - &error)); + g_assert (ostree_mutable_tree_ensure_parent_dirs (tree, split_path, checksum, &parent, &error)); - g_assert (ostree_mutable_tree_lookup (tree, "foo", &source_checksum, - &source_subdir, &error)); + g_assert (ostree_mutable_tree_lookup (tree, "foo", &source_checksum, &source_subdir, &error)); - g_assert_false (ostree_mutable_tree_lookup (tree, "bar", &source_checksum2, - &source_subdir2, &error)); + g_assert_false ( + ostree_mutable_tree_lookup (tree, "bar", &source_checksum2, &source_subdir2, &error)); g_clear_error (&error); } @@ -134,7 +125,7 @@ test_ensure_dir (void) { glnx_unref_object OstreeMutableTree *tree = ostree_mutable_tree_new (); glnx_unref_object OstreeMutableTree *parent = NULL; - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; const char *dirname = "foo"; const char *filename = "bar"; const char *checksum = "01234567890123456789012345678901"; @@ -153,7 +144,7 @@ static void test_replace_file (void) { glnx_unref_object OstreeMutableTree *tree = ostree_mutable_tree_new (); - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; const char *filename = "bar"; const char *checksum = "01234567890123456789012345678901"; const char *checksum2 = "ABCDEF01234567890123456789012345"; @@ -195,7 +186,8 @@ test_contents_checksum (void) g_assert_null (ostree_mutable_tree_get_contents_checksum (tree)); } -int main (int argc, char **argv) +int +main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); g_test_add_func ("/mutable-tree/metadata-checksum", test_metadata_checksum); @@ -204,5 +196,5 @@ int main (int argc, char **argv) g_test_add_func ("/mutable-tree/walk", test_mutable_tree_walk); g_test_add_func ("/mutable-tree/ensure-dir", test_ensure_dir); g_test_add_func ("/mutable-tree/replace-file", test_replace_file); - return g_test_run(); + return g_test_run (); } diff --git a/tests/test-ot-opt-utils.c b/tests/test-ot-opt-utils.c index 45de154d..3a700f4d 100644 --- a/tests/test-ot-opt-utils.c +++ b/tests/test-ot-opt-utils.c @@ -18,13 +18,13 @@ */ #include "config.h" +#include "libglnx.h" #include "ostree-mutable-tree.h" +#include "ot-opt-utils.h" +#include #include #include -#include #include -#include "ot-opt-utils.h" -#include "libglnx.h" static GString *printerr_str = NULL; @@ -39,8 +39,8 @@ util_usage_error_printerr (const gchar *string) static void test_ot_util_usage_error (void) { - g_autoptr(GError) error = NULL; - g_autoptr(GOptionContext) context = g_option_context_new ("[TEST]"); + g_autoptr (GError) error = NULL; + g_autoptr (GOptionContext) context = g_option_context_new ("[TEST]"); GPrintFunc old_printerr = g_set_printerr_handler (util_usage_error_printerr); ot_util_usage_error (context, "find_me", &error); @@ -54,9 +54,10 @@ test_ot_util_usage_error (void) printerr_str = NULL; } -int main (int argc, char **argv) +int +main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); g_test_add_func ("/ot-opt-utils/ot-util-usage-error", test_ot_util_usage_error); - return g_test_run(); + return g_test_run (); } diff --git a/tests/test-ot-tool-util.c b/tests/test-ot-tool-util.c index 6eb3520e..f189b3c6 100644 --- a/tests/test-ot-tool-util.c +++ b/tests/test-ot-tool-util.c @@ -20,11 +20,11 @@ #include "config.h" #include "libglnx.h" #include "ostree-mutable-tree.h" +#include "ot-tool-util.h" +#include #include #include -#include #include -#include "ot-tool-util.h" /* @@ -42,7 +42,7 @@ ot_parse_keyvalue (const char *keyvalue, static void test_ot_parse_boolean (void) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; gboolean out = FALSE; g_assert_true (ot_parse_boolean ("yes", &out, &error)); g_assert_true (out); @@ -79,20 +79,17 @@ test_ot_parse_boolean (void) static void test_ot_parse_keyvalue (void) { - g_autoptr(GError) error = NULL; - char *keyvalue[] = {"foo=bar", "a=", "b=1231231"}; - char *key[] = {"foo", "a", "b"}; - char *value[] = {"bar", "", "1231231"}; + g_autoptr (GError) error = NULL; + char *keyvalue[] = { "foo=bar", "a=", "b=1231231" }; + char *key[] = { "foo", "a", "b" }; + char *value[] = { "bar", "", "1231231" }; guint i; for (i = 0; i < G_N_ELEMENTS (keyvalue); i++) { g_autofree char *out_key = NULL; g_autofree char *out_value = NULL; - g_assert_true (ot_parse_keyvalue (keyvalue[i], - &out_key, - &out_value, - &error)); + g_assert_true (ot_parse_keyvalue (keyvalue[i], &out_key, &out_value, &error)); g_assert_cmpstr (out_key, ==, key[i]); g_assert_cmpstr (out_value, ==, value[i]); } @@ -100,19 +97,17 @@ test_ot_parse_keyvalue (void) { g_autofree char *out_key = NULL; g_autofree char *out_value = NULL; - g_assert_false (ot_parse_keyvalue ("blabla", - &out_key, - &out_value, - &error)); + g_assert_false (ot_parse_keyvalue ("blabla", &out_key, &out_value, &error)); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_FAILED); g_clear_error (&error); } } -int main (int argc, char **argv) +int +main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); g_test_add_func ("/ot-tool-util/parse-boolean", test_ot_parse_boolean); g_test_add_func ("/ot-tool-util/parse-keyvalue", test_ot_parse_keyvalue); - return g_test_run(); + return g_test_run (); } diff --git a/tests/test-ot-unix-utils.c b/tests/test-ot-unix-utils.c index 3f16b55d..853e877f 100644 --- a/tests/test-ot-unix-utils.c +++ b/tests/test-ot-unix-utils.c @@ -26,14 +26,14 @@ static void test_ot_util_path_split_validate (void) { - const char *paths[] = {"foo/bar", "test", "foo/bar:", "a/b/c/d/e/f/g/h/i/l/m/n/o/p", NULL}; - int n_components[] = {2, 1, 2, 14, 0}; + const char *paths[] = { "foo/bar", "test", "foo/bar:", "a/b/c/d/e/f/g/h/i/l/m/n/o/p", NULL }; + int n_components[] = { 2, 1, 2, 14, 0 }; int i; for (i = 0; paths[i]; i++) { GError *error = NULL; - g_autoptr(GPtrArray) components = NULL; - if (! ot_util_path_split_validate (paths[i], &components, &error)) + g_autoptr (GPtrArray) components = NULL; + if (!ot_util_path_split_validate (paths[i], &components, &error)) { int j; g_assert_cmpint (components->len, ==, n_components[i]); @@ -49,7 +49,7 @@ test_ot_util_path_split_validate (void) static void test_ot_util_filename_validate (void) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; /* Check for valid inputs. */ g_assert (ot_util_filename_validate ("valid", &error)); @@ -74,10 +74,11 @@ test_ot_util_filename_validate (void) g_clear_error (&error); } -int main (int argc, char **argv) +int +main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); g_test_add_func ("/ot_util_path_split_validate", test_ot_util_path_split_validate); g_test_add_func ("/ot_util_filename_validate", test_ot_util_filename_validate); - return g_test_run(); + return g_test_run (); } diff --git a/tests/test-pull-c.c b/tests/test-pull-c.c index 037a1789..605c6363 100644 --- a/tests/test-pull-c.c +++ b/tests/test-pull-c.c @@ -19,14 +19,15 @@ #include "config.h" #include "libglnx.h" +#include #include #include -#include #include #include "libostreetest.h" -typedef struct { +typedef struct +{ OstreeRepo *repo; } TestData; @@ -52,18 +53,20 @@ test_data_init (TestData *td) repo_url = g_strconcat (http_address, "/ostree/gnomerepo", NULL); - { g_autoptr(GVariantBuilder) builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); - g_autoptr(GVariant) opts = NULL; + { + g_autoptr (GVariantBuilder) builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}")); + g_autoptr (GVariant) opts = NULL; - g_variant_builder_add (builder, "{s@v}", "gpg-verify", g_variant_new_variant (g_variant_new_boolean (FALSE))); + g_variant_builder_add (builder, "{s@v}", "gpg-verify", + g_variant_new_variant (g_variant_new_boolean (FALSE))); opts = g_variant_ref_sink (g_variant_builder_end (builder)); - if (!ostree_repo_remote_change (td->repo, NULL, OSTREE_REPO_REMOTE_CHANGE_ADD, - "origin", repo_url, opts, NULL, error)) + if (!ostree_repo_remote_change (td->repo, NULL, OSTREE_REPO_REMOTE_CHANGE_ADD, "origin", + repo_url, opts, NULL, error)) goto out; } - out: +out: g_assert_no_error (local_error); } @@ -72,17 +75,17 @@ test_pull_multi_nochange (gconstpointer data) { GError *local_error = NULL; GError **error = &local_error; - TestData *td = (void*)data; + TestData *td = (void *)data; char *refs[] = { "main", NULL }; - if (!ostree_repo_pull (td->repo, "origin", (char**)&refs, 0, NULL, NULL, error)) + if (!ostree_repo_pull (td->repo, "origin", (char **)&refs, 0, NULL, NULL, error)) goto out; - if (!ostree_repo_pull (td->repo, "origin", (char**)&refs, 0, NULL, NULL, error)) + if (!ostree_repo_pull (td->repo, "origin", (char **)&refs, 0, NULL, NULL, error)) goto out; - if (!ostree_repo_pull (td->repo, "origin", (char**)&refs, 0, NULL, NULL, error)) + if (!ostree_repo_pull (td->repo, "origin", (char **)&refs, 0, NULL, NULL, error)) goto out; - out: +out: g_assert_no_error (local_error); } @@ -92,32 +95,35 @@ test_pull_multi_error_then_ok (gconstpointer data) GError *local_error = NULL; GError **error = &local_error; - TestData *td = (void*)data; + TestData *td = (void *)data; char *ok_refs[] = { "main", NULL }; char *bad_refs[] = { "nosuchbranch", NULL }; for (guint i = 0; i < 3; i++) { - g_autoptr(GError) tmp_error = NULL; - if (!ostree_repo_pull (td->repo, "origin", (char**)&ok_refs, 0, NULL, NULL, error)) + g_autoptr (GError) tmp_error = NULL; + if (!ostree_repo_pull (td->repo, "origin", (char **)&ok_refs, 0, NULL, NULL, error)) goto out; - if (ostree_repo_pull (td->repo, "origin", (char**)&bad_refs, 0, NULL, NULL, &tmp_error)) + if (ostree_repo_pull (td->repo, "origin", (char **)&bad_refs, 0, NULL, NULL, &tmp_error)) g_assert_not_reached (); g_clear_error (&tmp_error); - if (ostree_repo_pull (td->repo, "origin", (char**)&bad_refs, 0, NULL, NULL, &tmp_error)) + if (ostree_repo_pull (td->repo, "origin", (char **)&bad_refs, 0, NULL, NULL, &tmp_error)) g_assert_not_reached (); g_clear_error (&tmp_error); - if (!ostree_repo_pull (td->repo, "origin", (char**)&ok_refs, 0, NULL, NULL, error)) + if (!ostree_repo_pull (td->repo, "origin", (char **)&ok_refs, 0, NULL, NULL, error)) goto out; } - out: +out: g_assert_no_error (local_error); } -int main (int argc, char **argv) +int +main (int argc, char **argv) { - TestData td = {NULL,}; + TestData td = { + NULL, + }; int r; test_data_init (&td); @@ -127,7 +133,7 @@ int main (int argc, char **argv) g_test_add_data_func ("/test-pull-c/multi-nochange", &td, test_pull_multi_nochange); g_test_add_data_func ("/test-pull-c/multi-ok-error-repeat", &td, test_pull_multi_error_then_ok); - r = g_test_run(); + r = g_test_run (); g_clear_object (&td.repo); return r; diff --git a/tests/test-repo-finder-avahi.c b/tests/test-repo-finder-avahi.c index 932c80b1..a187b2f0 100644 --- a/tests/test-repo-finder-avahi.c +++ b/tests/test-repo-finder-avahi.c @@ -23,15 +23,15 @@ #include "config.h" #include -#include #include +#include #include #include #include "ostree-autocleanups.h" -#include "ostree-repo-finder.h" -#include "ostree-repo-finder-avahi.h" #include "ostree-repo-finder-avahi-private.h" +#include "ostree-repo-finder-avahi.h" +#include "ostree-repo-finder.h" /* FIXME: Upstream this */ G_DEFINE_AUTOPTR_CLEANUP_FUNC (AvahiStringList, avahi_string_list_free) @@ -40,8 +40,8 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (AvahiStringList, avahi_string_list_free) static void test_repo_finder_avahi_init (void) { - g_autoptr(OstreeRepoFinderAvahi) finder = NULL; - g_autoptr(GMainContext) context = NULL; + g_autoptr (OstreeRepoFinderAvahi) finder = NULL; + g_autoptr (GMainContext) context = NULL; /* Default main context. */ finder = ostree_repo_finder_avahi_new (NULL); @@ -58,36 +58,34 @@ static void test_repo_finder_avahi_txt_records_parse (void) { struct - { - const guint8 *txt; - gsize txt_len; - const gchar *expected_key; /* (nullable) to indicate parse failure */ - const guint8 *expected_value; /* (nullable) to allow for valueless keys */ - gsize expected_value_len; - } - vectors[] = - { - { (const guint8 *) "", 0, NULL, NULL, 0 }, - { (const guint8 *) "\x00", 1, NULL, NULL, 0 }, - { (const guint8 *) "\xff", 1, NULL, NULL, 0 }, - { (const guint8 *) "k\x00", 2, NULL, NULL, 0 }, - { (const guint8 *) "k\xff", 2, NULL, NULL, 0 }, - { (const guint8 *) "=", 1, NULL, NULL, 0 }, - { (const guint8 *) "=value", 6, NULL, NULL, 0 }, - { (const guint8 *) "k=v", 3, "k", (const guint8 *) "v", 1 }, - { (const guint8 *) "key=value", 9, "key", (const guint8 *) "value", 5 }, - { (const guint8 *) "k=v=", 4, "k", (const guint8 *) "v=", 2 }, - { (const guint8 *) "k=", 2, "k", (const guint8 *) "", 0 }, - { (const guint8 *) "k", 1, "k", NULL, 0 }, - { (const guint8 *) "k==", 3, "k", (const guint8 *) "=", 1 }, - { (const guint8 *) "k=\x00\x01\x02", 5, "k", (const guint8 *) "\x00\x01\x02", 3 }, - }; + { + const guint8 *txt; + gsize txt_len; + const gchar *expected_key; /* (nullable) to indicate parse failure */ + const guint8 *expected_value; /* (nullable) to allow for valueless keys */ + gsize expected_value_len; + } vectors[] = { + { (const guint8 *)"", 0, NULL, NULL, 0 }, + { (const guint8 *)"\x00", 1, NULL, NULL, 0 }, + { (const guint8 *)"\xff", 1, NULL, NULL, 0 }, + { (const guint8 *)"k\x00", 2, NULL, NULL, 0 }, + { (const guint8 *)"k\xff", 2, NULL, NULL, 0 }, + { (const guint8 *)"=", 1, NULL, NULL, 0 }, + { (const guint8 *)"=value", 6, NULL, NULL, 0 }, + { (const guint8 *)"k=v", 3, "k", (const guint8 *)"v", 1 }, + { (const guint8 *)"key=value", 9, "key", (const guint8 *)"value", 5 }, + { (const guint8 *)"k=v=", 4, "k", (const guint8 *)"v=", 2 }, + { (const guint8 *)"k=", 2, "k", (const guint8 *)"", 0 }, + { (const guint8 *)"k", 1, "k", NULL, 0 }, + { (const guint8 *)"k==", 3, "k", (const guint8 *)"=", 1 }, + { (const guint8 *)"k=\x00\x01\x02", 5, "k", (const guint8 *)"\x00\x01\x02", 3 }, + }; gsize i; for (i = 0; i < G_N_ELEMENTS (vectors); i++) { - g_autoptr(AvahiStringList) string_list = NULL; - g_autoptr(GHashTable) attributes = NULL; + g_autoptr (AvahiStringList) string_list = NULL; + g_autoptr (GHashTable) attributes = NULL; g_test_message ("Vector %" G_GSIZE_FORMAT, i); @@ -98,18 +96,17 @@ test_repo_finder_avahi_txt_records_parse (void) if (vectors[i].expected_key != NULL) { GBytes *value; - g_autoptr(GBytes) expected_value = NULL; + g_autoptr (GBytes) expected_value = NULL; - g_assert_true (g_hash_table_lookup_extended (attributes, - vectors[i].expected_key, - NULL, - (gpointer *) &value)); + g_assert_true (g_hash_table_lookup_extended (attributes, vectors[i].expected_key, NULL, + (gpointer *)&value)); g_assert_cmpuint (g_hash_table_size (attributes), ==, 1); if (vectors[i].expected_value != NULL) { g_assert_nonnull (value); - expected_value = g_bytes_new_static (vectors[i].expected_value, vectors[i].expected_value_len); + expected_value + = g_bytes_new_static (vectors[i].expected_value, vectors[i].expected_value_len); g_assert_true (g_bytes_equal (value, expected_value)); } else @@ -129,10 +126,10 @@ test_repo_finder_avahi_txt_records_parse (void) static void test_repo_finder_avahi_txt_records_duplicates (void) { - g_autoptr(AvahiStringList) string_list = NULL; - g_autoptr(GHashTable) attributes = NULL; + g_autoptr (AvahiStringList) string_list = NULL; + g_autoptr (GHashTable) attributes = NULL; GBytes *value; - g_autoptr(GBytes) expected_value = NULL; + g_autoptr (GBytes) expected_value = NULL; /* Reverse the list before using it, as they are built in reverse order. * (See the #AvahiStringList documentation.) */ @@ -153,17 +150,14 @@ test_repo_finder_avahi_txt_records_duplicates (void) static void test_repo_finder_avahi_txt_records_case_sensitivity (void) { - g_autoptr(AvahiStringList) string_list = NULL; - g_autoptr(GHashTable) attributes = NULL; + g_autoptr (AvahiStringList) string_list = NULL; + g_autoptr (GHashTable) attributes = NULL; GBytes *value1, *value2; - g_autoptr(GBytes) expected_value1 = NULL, expected_value2 = NULL; + g_autoptr (GBytes) expected_value1 = NULL, expected_value2 = NULL; /* Reverse the list before using it, as they are built in reverse order. * (See the #AvahiStringList documentation.) */ - string_list = avahi_string_list_new ("k=value1", - "K=value2", - "KeY2=v", - NULL); + string_list = avahi_string_list_new ("k=value1", "K=value2", "KeY2=v", NULL); string_list = avahi_string_list_reverse (string_list); attributes = _ostree_txt_records_parse (string_list); @@ -189,14 +183,12 @@ test_repo_finder_avahi_txt_records_case_sensitivity (void) static void test_repo_finder_avahi_txt_records_empty_and_missing (void) { - g_autoptr(AvahiStringList) string_list = NULL; - g_autoptr(GHashTable) attributes = NULL; + g_autoptr (AvahiStringList) string_list = NULL; + g_autoptr (GHashTable) attributes = NULL; GBytes *value1, *value2; - g_autoptr(GBytes) expected_value1 = NULL; + g_autoptr (GBytes) expected_value1 = NULL; - string_list = avahi_string_list_new ("empty=", - "missing", - NULL); + string_list = avahi_string_list_new ("empty=", "missing", NULL); attributes = _ostree_txt_records_parse (string_list); g_assert_cmpuint (g_hash_table_size (attributes), ==, 2); @@ -206,22 +198,27 @@ test_repo_finder_avahi_txt_records_empty_and_missing (void) expected_value1 = g_bytes_new_static ("", 0); g_assert_true (g_bytes_equal (value1, expected_value1)); - g_assert_true (g_hash_table_lookup_extended (attributes, "missing", NULL, (gpointer *) &value2)); + g_assert_true (g_hash_table_lookup_extended (attributes, "missing", NULL, (gpointer *)&value2)); g_assert_null (value2); } -int main (int argc, char **argv) +int +main (int argc, char **argv) { setlocale (LC_ALL, ""); g_test_init (&argc, &argv, NULL); g_test_add_func ("/repo-finder-avahi/init", test_repo_finder_avahi_init); - g_test_add_func ("/repo-finder-avahi/txt-records/parse", test_repo_finder_avahi_txt_records_parse); - g_test_add_func ("/repo-finder-avahi/txt-records/duplicates", test_repo_finder_avahi_txt_records_duplicates); - g_test_add_func ("/repo-finder-avahi/txt-records/case-sensitivity", test_repo_finder_avahi_txt_records_case_sensitivity); - g_test_add_func ("/repo-finder-avahi/txt-records/empty-and-missing", test_repo_finder_avahi_txt_records_empty_and_missing); + g_test_add_func ("/repo-finder-avahi/txt-records/parse", + test_repo_finder_avahi_txt_records_parse); + g_test_add_func ("/repo-finder-avahi/txt-records/duplicates", + test_repo_finder_avahi_txt_records_duplicates); + g_test_add_func ("/repo-finder-avahi/txt-records/case-sensitivity", + test_repo_finder_avahi_txt_records_case_sensitivity); + g_test_add_func ("/repo-finder-avahi/txt-records/empty-and-missing", + test_repo_finder_avahi_txt_records_empty_and_missing); /* FIXME: Add tests for service processing, probably by splitting the * code in OstreeRepoFinderAvahi around found_services. */ - return g_test_run(); + return g_test_run (); } diff --git a/tests/test-repo-finder-config.c b/tests/test-repo-finder-config.c index 30f1b206..4b08b2eb 100644 --- a/tests/test-repo-finder-config.c +++ b/tests/test-repo-finder-config.c @@ -23,30 +23,29 @@ #include "config.h" #include -#include #include +#include #include #include #include #include "libostreetest.h" #include "ostree-autocleanups.h" -#include "ostree-repo-finder.h" #include "ostree-repo-finder-config.h" +#include "ostree-repo-finder.h" /* Test fixture. Creates a temporary directory. */ typedef struct { - OstreeRepo *parent_repo; /* owned */ - GLnxTmpDir tmpdir; /* owned */ - GFile *working_dir; /* owned */ + OstreeRepo *parent_repo; /* owned */ + GLnxTmpDir tmpdir; /* owned */ + GFile *working_dir; /* owned */ } Fixture; static void -setup (Fixture *fixture, - gconstpointer test_data) +setup (Fixture *fixture, gconstpointer test_data) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; (void)glnx_mkdtemp ("test-repo-finder-config-XXXXXX", 0700, &fixture->tmpdir, &error); g_assert_no_error (error); @@ -63,8 +62,7 @@ setup (Fixture *fixture, } static void -teardown (Fixture *fixture, - gconstpointer test_data) +teardown (Fixture *fixture, gconstpointer test_data) { /* Recursively remove the temporary directory. */ (void)glnx_tmpdir_delete (&fixture->tmpdir, NULL, NULL); @@ -83,16 +81,14 @@ teardown (Fixture *fixture, static void test_repo_finder_config_init (void) { - g_autoptr(OstreeRepoFinderConfig) finder = NULL; + g_autoptr (OstreeRepoFinderConfig) finder = NULL; /* Default everything. */ finder = ostree_repo_finder_config_new (); } static void -result_cb (GObject *source_object, - GAsyncResult *result, - gpointer user_data) +result_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { GAsyncResult **result_out = user_data; *result_out = g_object_ref (result); @@ -101,31 +97,29 @@ result_cb (GObject *source_object, /* Test that no remotes are found if there are no config files in the refs * directory. */ static void -test_repo_finder_config_no_configs (Fixture *fixture, - gconstpointer test_data) +test_repo_finder_config_no_configs (Fixture *fixture, gconstpointer test_data) { - g_autoptr(OstreeRepoFinderConfig) finder = NULL; - g_autoptr(GMainContext) context = NULL; - g_autoptr(GAsyncResult) result = NULL; - g_autoptr(GPtrArray) results = NULL; /* (element-type OstreeRepoFinderResult) */ - g_autoptr(GError) error = NULL; + g_autoptr (OstreeRepoFinderConfig) finder = NULL; + g_autoptr (GMainContext) context = NULL; + g_autoptr (GAsyncResult) result = NULL; + g_autoptr (GPtrArray) results = NULL; /* (element-type OstreeRepoFinderResult) */ + g_autoptr (GError) error = NULL; const OstreeCollectionRef ref1 = { "org.example.Os", "exampleos/x86_64/standard" }; const OstreeCollectionRef ref2 = { "org.example.Os", "exampleos/x86_64/buildmain/standard" }; - const OstreeCollectionRef * const refs[] = { &ref1, &ref2, NULL }; + const OstreeCollectionRef *const refs[] = { &ref1, &ref2, NULL }; context = g_main_context_new (); g_main_context_push_thread_default (context); finder = ostree_repo_finder_config_new (); - ostree_repo_finder_resolve_async (OSTREE_REPO_FINDER (finder), refs, - fixture->parent_repo, NULL, result_cb, &result); + ostree_repo_finder_resolve_async (OSTREE_REPO_FINDER (finder), refs, fixture->parent_repo, NULL, + result_cb, &result); while (result == NULL) g_main_context_iteration (context, TRUE); - results = ostree_repo_finder_resolve_finish (OSTREE_REPO_FINDER (finder), - result, &error); + results = ostree_repo_finder_resolve_finish (OSTREE_REPO_FINDER (finder), result, &error); g_assert_no_error (error); g_assert_nonnull (results); g_assert_cmpuint (results->len, ==, 0); @@ -136,36 +130,30 @@ test_repo_finder_config_no_configs (Fixture *fixture, /* Add configuration for a remote named @remote_name, at @remote_uri, with a * remote collection ID of @collection_id, to the given @repo. */ static void -assert_create_remote_config (OstreeRepo *repo, - const gchar *remote_name, - const gchar *remote_uri, +assert_create_remote_config (OstreeRepo *repo, const gchar *remote_name, const gchar *remote_uri, const gchar *collection_id) { - g_autoptr(GError) error = NULL; - g_autoptr(GVariant) options = NULL; + g_autoptr (GError) error = NULL; + g_autoptr (GVariant) options = NULL; if (collection_id != NULL) - options = g_variant_new_parsed ("@a{sv} { 'collection-id': <%s> }", - collection_id); + options = g_variant_new_parsed ("@a{sv} { 'collection-id': <%s> }", collection_id); ostree_repo_remote_add (repo, remote_name, remote_uri, options, NULL, &error); g_assert_no_error (error); } -static gchar *assert_create_remote (Fixture *fixture, - const gchar *collection_id, +static gchar *assert_create_remote (Fixture *fixture, const gchar *collection_id, ...) G_GNUC_NULL_TERMINATED; /* Create a new repository in a temporary directory with its collection ID set * to @collection_id, and containing the refs given in @... (which must be * %NULL-terminated). Return the `file://` URI of the new repository. */ static gchar * -assert_create_remote (Fixture *fixture, - const gchar *collection_id, - ...) +assert_create_remote (Fixture *fixture, const gchar *collection_id, ...) { va_list args; - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; const gchar *repo_name = (collection_id != NULL) ? collection_id : "no-collection"; glnx_shutil_mkdir_p_at (fixture->tmpdir.fd, repo_name, 0700, NULL, &error); @@ -174,8 +162,8 @@ assert_create_remote (Fixture *fixture, glnx_shutil_mkdir_p_at (fixture->tmpdir.fd, "empty", 0700, NULL, &error); g_assert_no_error (error); - g_autoptr(GFile) repo_path = g_file_get_child (fixture->working_dir, repo_name); - g_autoptr(OstreeRepo) repo = ostree_repo_new (repo_path); + g_autoptr (GFile) repo_path = g_file_get_child (fixture->working_dir, repo_name); + g_autoptr (OstreeRepo) repo = ostree_repo_new (repo_path); ostree_repo_set_collection_id (repo, collection_id, &error); g_assert_no_error (error); ostree_repo_create (repo, OSTREE_REPO_MODE_ARCHIVE, NULL, &error); @@ -184,24 +172,22 @@ assert_create_remote (Fixture *fixture, /* Set up the refs from @.... */ va_start (args, collection_id); - for (const gchar *ref_name = va_arg (args, const gchar *); - ref_name != NULL; + for (const gchar *ref_name = va_arg (args, const gchar *); ref_name != NULL; ref_name = va_arg (args, const gchar *)) { - OstreeCollectionRef collection_ref = { (gchar *) collection_id, (gchar *) ref_name }; + OstreeCollectionRef collection_ref = { (gchar *)collection_id, (gchar *)ref_name }; g_autofree gchar *checksum = NULL; - g_autoptr(OstreeMutableTree) mtree = NULL; - g_autoptr(OstreeRepoFile) repo_file = NULL; + g_autoptr (OstreeMutableTree) mtree = NULL; + g_autoptr (OstreeRepoFile) repo_file = NULL; mtree = ostree_mutable_tree_new (); ostree_repo_write_dfd_to_mtree (repo, fixture->tmpdir.fd, "empty", mtree, NULL, NULL, &error); g_assert_no_error (error); - ostree_repo_write_mtree (repo, mtree, (GFile **) &repo_file, NULL, &error); + ostree_repo_write_mtree (repo, mtree, (GFile **)&repo_file, NULL, &error); g_assert_no_error (error); - ostree_repo_write_commit (repo, NULL /* no parent */, ref_name, ref_name, - NULL /* no metadata */, repo_file, &checksum, - NULL, &error); + ostree_repo_write_commit (repo, NULL /* no parent */, ref_name, ref_name, + NULL /* no metadata */, repo_file, &checksum, NULL, &error); g_assert_no_error (error); if (collection_id != NULL) @@ -214,7 +200,7 @@ assert_create_remote (Fixture *fixture, va_end (args); /* Update the summary. */ - ostree_repo_regenerate_summary (repo, NULL /* no metadata */, NULL, &error); + ostree_repo_regenerate_summary (repo, NULL /* no metadata */, NULL, &error); g_assert_no_error (error); return g_file_get_uri (repo_path); @@ -223,54 +209,52 @@ assert_create_remote (Fixture *fixture, /* Test resolving the refs against a collection of config files, which contain * valid, invalid or duplicate repo information. */ static void -test_repo_finder_config_mixed_configs (Fixture *fixture, - gconstpointer test_data) +test_repo_finder_config_mixed_configs (Fixture *fixture, gconstpointer test_data) { - g_autoptr(OstreeRepoFinderConfig) finder = NULL; - g_autoptr(GMainContext) context = NULL; - g_autoptr(GAsyncResult) async_result = NULL; - g_autoptr(GPtrArray) results = NULL; /* (element-type OstreeRepoFinderResult) */ - g_autoptr(GError) error = NULL; + g_autoptr (OstreeRepoFinderConfig) finder = NULL; + g_autoptr (GMainContext) context = NULL; + g_autoptr (GAsyncResult) async_result = NULL; + g_autoptr (GPtrArray) results = NULL; /* (element-type OstreeRepoFinderResult) */ + g_autoptr (GError) error = NULL; gsize i; const OstreeCollectionRef ref0 = { "org.example.Collection0", "exampleos/x86_64/ref0" }; const OstreeCollectionRef ref1 = { "org.example.Collection0", "exampleos/x86_64/ref1" }; const OstreeCollectionRef ref2 = { "org.example.Collection1", "exampleos/x86_64/ref1" }; const OstreeCollectionRef ref3 = { "org.example.Collection1", "exampleos/x86_64/ref2" }; const OstreeCollectionRef ref4 = { "org.example.Collection2", "exampleos/x86_64/ref3" }; - const OstreeCollectionRef * const refs[] = { &ref0, &ref1, &ref2, &ref3, &ref4, NULL }; + const OstreeCollectionRef *const refs[] = { &ref0, &ref1, &ref2, &ref3, &ref4, NULL }; context = g_main_context_new (); g_main_context_push_thread_default (context); /* Put together various ref configuration files. */ - g_autofree gchar *collection0_uri = assert_create_remote (fixture, "org.example.Collection0", - "exampleos/x86_64/ref0", - "exampleos/x86_64/ref1", - NULL); - g_autofree gchar *collection1_uri = assert_create_remote (fixture, "org.example.Collection1", - "exampleos/x86_64/ref2", - NULL); - g_autofree gchar *no_collection_uri = assert_create_remote (fixture, NULL, - "exampleos/x86_64/ref3", - NULL); - - assert_create_remote_config (fixture->parent_repo, "remote0", collection0_uri, "org.example.Collection0"); - assert_create_remote_config (fixture->parent_repo, "remote1", collection1_uri, "org.example.Collection1"); - assert_create_remote_config (fixture->parent_repo, "remote0-copy", collection0_uri, "org.example.Collection0"); - assert_create_remote_config (fixture->parent_repo, "remote1-bad-copy", collection1_uri, "org.example.NotCollection1"); + g_autofree gchar *collection0_uri = assert_create_remote ( + fixture, "org.example.Collection0", "exampleos/x86_64/ref0", "exampleos/x86_64/ref1", NULL); + g_autofree gchar *collection1_uri + = assert_create_remote (fixture, "org.example.Collection1", "exampleos/x86_64/ref2", NULL); + g_autofree gchar *no_collection_uri + = assert_create_remote (fixture, NULL, "exampleos/x86_64/ref3", NULL); + + assert_create_remote_config (fixture->parent_repo, "remote0", collection0_uri, + "org.example.Collection0"); + assert_create_remote_config (fixture->parent_repo, "remote1", collection1_uri, + "org.example.Collection1"); + assert_create_remote_config (fixture->parent_repo, "remote0-copy", collection0_uri, + "org.example.Collection0"); + assert_create_remote_config (fixture->parent_repo, "remote1-bad-copy", collection1_uri, + "org.example.NotCollection1"); assert_create_remote_config (fixture->parent_repo, "remote2", no_collection_uri, NULL); finder = ostree_repo_finder_config_new (); /* Resolve the refs. */ - ostree_repo_finder_resolve_async (OSTREE_REPO_FINDER (finder), refs, - fixture->parent_repo, NULL, result_cb, &async_result); + ostree_repo_finder_resolve_async (OSTREE_REPO_FINDER (finder), refs, fixture->parent_repo, NULL, + result_cb, &async_result); while (async_result == NULL) g_main_context_iteration (context, TRUE); - results = ostree_repo_finder_resolve_finish (OSTREE_REPO_FINDER (finder), - async_result, &error); + results = ostree_repo_finder_resolve_finish (OSTREE_REPO_FINDER (finder), async_result, &error); g_assert_no_error (error); g_assert_nonnull (results); g_assert_cmpuint (results->len, ==, 3); @@ -281,8 +265,8 @@ test_repo_finder_config_mixed_configs (Fixture *fixture, { const OstreeRepoFinderResult *result = g_ptr_array_index (results, i); - if (g_strcmp0 (ostree_remote_get_name (result->remote), "remote0") == 0 || - g_strcmp0 (ostree_remote_get_name (result->remote), "remote0-copy") == 0) + if (g_strcmp0 (ostree_remote_get_name (result->remote), "remote0") == 0 + || g_strcmp0 (ostree_remote_get_name (result->remote), "remote0-copy") == 0) { g_assert_cmpuint (g_hash_table_size (result->ref_to_checksum), ==, 2); g_assert_true (g_hash_table_contains (result->ref_to_checksum, &ref0)); @@ -306,58 +290,57 @@ test_repo_finder_config_mixed_configs (Fixture *fixture, /* Test that using ostree_repo_find_remotes_async() works too.*/ static void -test_repo_finder_config_find_remotes (Fixture *fixture, - gconstpointer test_data) +test_repo_finder_config_find_remotes (Fixture *fixture, gconstpointer test_data) { - g_autoptr(GMainContext) context = NULL; - g_autoptr(GAsyncResult) result = NULL; - g_auto(OstreeRepoFinderResultv) results = NULL; - g_autoptr(GError) error = NULL; + g_autoptr (GMainContext) context = NULL; + g_autoptr (GAsyncResult) result = NULL; + g_auto (OstreeRepoFinderResultv) results = NULL; + g_autoptr (GError) error = NULL; gsize i; const OstreeCollectionRef ref0 = { "org.example.Collection0", "exampleos/x86_64/ref0" }; const OstreeCollectionRef ref1 = { "org.example.Collection0", "exampleos/x86_64/ref1" }; const OstreeCollectionRef ref2 = { "org.example.Collection1", "exampleos/x86_64/ref1" }; const OstreeCollectionRef ref3 = { "org.example.Collection1", "exampleos/x86_64/ref2" }; const OstreeCollectionRef ref4 = { "org.example.Collection2", "exampleos/x86_64/ref3" }; - const OstreeCollectionRef * const refs[] = { &ref0, &ref1, &ref2, &ref3, &ref4, NULL }; - OstreeRepoFinder *finders[2] = {NULL, }; + const OstreeCollectionRef *const refs[] = { &ref0, &ref1, &ref2, &ref3, &ref4, NULL }; + OstreeRepoFinder *finders[2] = { + NULL, + }; context = g_main_context_new (); g_main_context_push_thread_default (context); /* Put together various ref configuration files. */ - g_autofree gchar *collection0_uri = assert_create_remote (fixture, "org.example.Collection0", - "exampleos/x86_64/ref0", - "exampleos/x86_64/ref1", - NULL); - g_autofree gchar *collection1_uri = assert_create_remote (fixture, "org.example.Collection1", - "exampleos/x86_64/ref2", - NULL); - g_autofree gchar *no_collection_uri = assert_create_remote (fixture, NULL, - "exampleos/x86_64/ref3", - NULL); - - assert_create_remote_config (fixture->parent_repo, "remote0", collection0_uri, "org.example.Collection0"); - assert_create_remote_config (fixture->parent_repo, "remote1", collection1_uri, "org.example.Collection1"); - assert_create_remote_config (fixture->parent_repo, "remote0-copy", collection0_uri, "org.example.Collection0"); - assert_create_remote_config (fixture->parent_repo, "remote1-bad-copy", collection1_uri, "org.example.NotCollection1"); + g_autofree gchar *collection0_uri = assert_create_remote ( + fixture, "org.example.Collection0", "exampleos/x86_64/ref0", "exampleos/x86_64/ref1", NULL); + g_autofree gchar *collection1_uri + = assert_create_remote (fixture, "org.example.Collection1", "exampleos/x86_64/ref2", NULL); + g_autofree gchar *no_collection_uri + = assert_create_remote (fixture, NULL, "exampleos/x86_64/ref3", NULL); + + assert_create_remote_config (fixture->parent_repo, "remote0", collection0_uri, + "org.example.Collection0"); + assert_create_remote_config (fixture->parent_repo, "remote1", collection1_uri, + "org.example.Collection1"); + assert_create_remote_config (fixture->parent_repo, "remote0-copy", collection0_uri, + "org.example.Collection0"); + assert_create_remote_config (fixture->parent_repo, "remote1-bad-copy", collection1_uri, + "org.example.NotCollection1"); assert_create_remote_config (fixture->parent_repo, "remote2", no_collection_uri, NULL); finders[0] = OSTREE_REPO_FINDER (ostree_repo_finder_config_new ()); /* Resolve the refs. */ - ostree_repo_find_remotes_async (fixture->parent_repo, refs, - NULL, finders, - NULL, NULL, result_cb, &result); + ostree_repo_find_remotes_async (fixture->parent_repo, refs, NULL, finders, NULL, NULL, result_cb, + &result); while (result == NULL) g_main_context_iteration (context, TRUE); - results = ostree_repo_find_remotes_finish (fixture->parent_repo, - result, &error); + results = ostree_repo_find_remotes_finish (fixture->parent_repo, result, &error); g_assert_no_error (error); g_assert_nonnull (results); - g_assert_cmpuint (g_strv_length ((char **) results), ==, 3); + g_assert_cmpuint (g_strv_length ((char **)results), ==, 3); /* Check that the results are correct: the invalid refs should have been * ignored, and the valid results canonicalised and deduplicated. */ @@ -366,8 +349,8 @@ test_repo_finder_config_find_remotes (Fixture *fixture, const char *ref0_checksum, *ref1_checksum, *ref2_checksum, *ref3_checksum; guint64 *ref0_timestamp, *ref1_timestamp, *ref2_timestamp, *ref3_timestamp; - if (g_strcmp0 (ostree_remote_get_name (results[i]->remote), "remote0") == 0 || - g_strcmp0 (ostree_remote_get_name (results[i]->remote), "remote0-copy") == 0) + if (g_strcmp0 (ostree_remote_get_name (results[i]->remote), "remote0") == 0 + || g_strcmp0 (ostree_remote_get_name (results[i]->remote), "remote0-copy") == 0) { g_assert_cmpuint (g_hash_table_size (results[i]->ref_to_checksum), ==, 5); @@ -427,7 +410,8 @@ test_repo_finder_config_find_remotes (Fixture *fixture, g_main_context_pop_thread_default (context); } -int main (int argc, char **argv) +int +main (int argc, char **argv) { setlocale (LC_ALL, ""); g_test_init (&argc, &argv, NULL); @@ -440,5 +424,5 @@ int main (int argc, char **argv) g_test_add ("/repo-finder-config/find-remotes", Fixture, NULL, setup, test_repo_finder_config_find_remotes, teardown); - return g_test_run(); + return g_test_run (); } diff --git a/tests/test-repo-finder-mount.c b/tests/test-repo-finder-mount.c index 13797030..0bbcd844 100644 --- a/tests/test-repo-finder-mount.c +++ b/tests/test-repo-finder-mount.c @@ -23,16 +23,16 @@ #include "config.h" #include -#include #include +#include #include #include #include "libostreetest.h" #include "ostree-autocleanups.h" #include "ostree-remote-private.h" -#include "ostree-repo-finder.h" #include "ostree-repo-finder-mount.h" +#include "ostree-repo-finder.h" #include "ostree-types.h" #include "test-mock-gio.h" @@ -40,15 +40,14 @@ typedef struct { OstreeRepo *parent_repo; - GLnxTmpDir tmpdir; /* owned */ + GLnxTmpDir tmpdir; /* owned */ GFile *working_dir; /* Points at tmpdir */ } Fixture; static void -setup (Fixture *fixture, - gconstpointer test_data) +setup (Fixture *fixture, gconstpointer test_data) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; (void)glnx_mkdtemp ("test-repo-finder-mount-XXXXXX", 0700, &fixture->tmpdir, &error); g_assert_no_error (error); @@ -69,8 +68,7 @@ setup (Fixture *fixture, } static void -teardown (Fixture *fixture, - gconstpointer test_data) +teardown (Fixture *fixture, gconstpointer test_data) { /* Recursively remove the temporary directory. */ (void)glnx_tmpdir_delete (&fixture->tmpdir, NULL, NULL); @@ -89,8 +87,8 @@ teardown (Fixture *fixture, static void test_repo_finder_mount_init (void) { - g_autoptr(OstreeRepoFinderMount) finder = NULL; - g_autoptr(GVolumeMonitor) monitor = NULL; + g_autoptr (OstreeRepoFinderMount) finder = NULL; + g_autoptr (GVolumeMonitor) monitor = NULL; /* Default #GVolumeMonitor. */ finder = ostree_repo_finder_mount_new (NULL); @@ -103,9 +101,7 @@ test_repo_finder_mount_init (void) } static void -result_cb (GObject *source_object, - GAsyncResult *result, - gpointer user_data) +result_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { GAsyncResult **result_out = user_data; *result_out = g_object_ref (result); @@ -113,20 +109,20 @@ result_cb (GObject *source_object, /* Test that no remotes are found if the #GVolumeMonitor returns no mounts. */ static void -test_repo_finder_mount_no_mounts (Fixture *fixture, - gconstpointer test_data) +test_repo_finder_mount_no_mounts (Fixture *fixture, gconstpointer test_data) { - g_autoptr(OstreeRepoFinderMount) finder = NULL; - g_autoptr(GVolumeMonitor) monitor = NULL; - g_autoptr(GMainContext) context = NULL; - g_autoptr(GAsyncResult) result = NULL; - g_autoptr(GPtrArray) results = NULL; /* (element-type OstreeRepoFinderResult) */ - g_autoptr(GError) error = NULL; + g_autoptr (OstreeRepoFinderMount) finder = NULL; + g_autoptr (GVolumeMonitor) monitor = NULL; + g_autoptr (GMainContext) context = NULL; + g_autoptr (GAsyncResult) result = NULL; + g_autoptr (GPtrArray) results = NULL; /* (element-type OstreeRepoFinderResult) */ + g_autoptr (GError) error = NULL; const OstreeCollectionRef ref1 = { "org.example.Collection1", "exampleos/x86_64/standard" }; - const OstreeCollectionRef ref2 = { "org.example.Collection1", "exampleos/x86_64/buildmain/standard" }; + const OstreeCollectionRef ref2 + = { "org.example.Collection1", "exampleos/x86_64/buildmain/standard" }; const OstreeCollectionRef ref3 = { "org.example.Collection2", "exampleos/x86_64/standard" }; const OstreeCollectionRef ref4 = { "org.example.Collection2", "exampleos/arm64/standard" }; - const OstreeCollectionRef * const refs[] = { &ref1, &ref2, &ref3, &ref4, NULL }; + const OstreeCollectionRef *const refs[] = { &ref1, &ref2, &ref3, &ref4, NULL }; context = g_main_context_new (); g_main_context_push_thread_default (context); @@ -134,15 +130,13 @@ test_repo_finder_mount_no_mounts (Fixture *fixture, monitor = ostree_mock_volume_monitor_new (NULL, NULL); finder = ostree_repo_finder_mount_new (monitor); - ostree_repo_finder_resolve_async (OSTREE_REPO_FINDER (finder), refs, - fixture->parent_repo, - NULL, result_cb, &result); + ostree_repo_finder_resolve_async (OSTREE_REPO_FINDER (finder), refs, fixture->parent_repo, NULL, + result_cb, &result); while (result == NULL) g_main_context_iteration (context, TRUE); - results = ostree_repo_finder_resolve_finish (OSTREE_REPO_FINDER (finder), - result, &error); + results = ostree_repo_finder_resolve_finish (OSTREE_REPO_FINDER (finder), result, &error); g_assert_no_error (error); g_assert_nonnull (results); g_assert_cmpuint (results->len, ==, 0); @@ -152,13 +146,11 @@ test_repo_finder_mount_no_mounts (Fixture *fixture, /* Create a .ostree/repos.d directory under the given @mount_root, or abort. */ static gboolean -assert_create_repos_dir (Fixture *fixture, - const gchar *mount_root_name, - int *out_repos_dfd, - GMount **out_mount) +assert_create_repos_dir (Fixture *fixture, const gchar *mount_root_name, int *out_repos_dfd, + GMount **out_mount) { glnx_autofd int repos_dfd = -1; - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; g_autofree gchar *path = g_build_filename (mount_root_name, ".ostree", "repos.d", NULL); glnx_shutil_mkdir_p_at_open (fixture->tmpdir.fd, path, 0700, &repos_dfd, NULL, &error); @@ -167,7 +159,7 @@ assert_create_repos_dir (Fixture *fixture, g_assert_no_error (error); *out_repos_dfd = g_steal_fd (&repos_dfd); - g_autoptr(GFile) mount_root = g_file_get_child (fixture->working_dir, mount_root_name); + g_autoptr (GFile) mount_root = g_file_get_child (fixture->working_dir, mount_root_name); *out_mount = G_MOUNT (ostree_mock_mount_new (mount_root_name, mount_root)); return TRUE; @@ -178,13 +170,11 @@ assert_create_repos_dir (Fixture *fixture, * #OstreeCollectionRef in @... is followed by a gchar** return address for the * checksum committed for that ref. Return the new repository. */ static OstreeRepo * -assert_create_remote_va (Fixture *fixture, - GFile *repo_dir, - va_list args) +assert_create_remote_va (Fixture *fixture, GFile *repo_dir, va_list args) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; - g_autoptr(OstreeRepo) repo = ostree_repo_new (repo_dir); + g_autoptr (OstreeRepo) repo = ostree_repo_new (repo_dir); ostree_repo_create (repo, OSTREE_REPO_MODE_ARCHIVE, NULL, &error); g_assert_no_error (error); @@ -192,24 +182,22 @@ assert_create_remote_va (Fixture *fixture, g_assert_no_error (error); /* Set up the refs from @.... */ - for (const OstreeCollectionRef *ref = va_arg (args, const OstreeCollectionRef *); - ref != NULL; + for (const OstreeCollectionRef *ref = va_arg (args, const OstreeCollectionRef *); ref != NULL; ref = va_arg (args, const OstreeCollectionRef *)) { g_autofree gchar *checksum = NULL; - g_autoptr(OstreeMutableTree) mtree = NULL; - g_autoptr(OstreeRepoFile) repo_file = NULL; + g_autoptr (OstreeMutableTree) mtree = NULL; + g_autoptr (OstreeRepoFile) repo_file = NULL; gchar **out_checksum = va_arg (args, gchar **); mtree = ostree_mutable_tree_new (); ostree_repo_write_dfd_to_mtree (repo, fixture->tmpdir.fd, "empty", mtree, NULL, NULL, &error); g_assert_no_error (error); - ostree_repo_write_mtree (repo, mtree, (GFile **) &repo_file, NULL, &error); + ostree_repo_write_mtree (repo, mtree, (GFile **)&repo_file, NULL, &error); g_assert_no_error (error); - ostree_repo_write_commit (repo, NULL /* no parent */, ref->ref_name, ref->ref_name, - NULL /* no metadata */, repo_file, &checksum, - NULL, &error); + ostree_repo_write_commit (repo, NULL /* no parent */, ref->ref_name, ref->ref_name, + NULL /* no metadata */, repo_file, &checksum, NULL, &error); g_assert_no_error (error); if (ref->collection_id != NULL) @@ -223,34 +211,26 @@ assert_create_remote_va (Fixture *fixture, } /* Update the summary. */ - ostree_repo_regenerate_summary (repo, NULL /* no metadata */, NULL, &error); + ostree_repo_regenerate_summary (repo, NULL /* no metadata */, NULL, &error); g_assert_no_error (error); return g_steal_pointer (&repo); } -static OstreeRepo * -assert_create_repo_dir (Fixture *fixture, - int repos_dfd, - GMount *repos_mount, - const char *repo_name, - gchar **out_uri, - ...) G_GNUC_NULL_TERMINATED; +static OstreeRepo *assert_create_repo_dir (Fixture *fixture, int repos_dfd, GMount *repos_mount, + const char *repo_name, gchar **out_uri, + ...) G_GNUC_NULL_TERMINATED; /* Create a @repo_name directory under the given @repos_dfd, or abort. Create a * new repository in it with the refs given in @..., as per * assert_create_remote_va(). Return the URI of the repository. */ static OstreeRepo * -assert_create_repo_dir (Fixture *fixture, - int repos_dfd, - GMount *repos_mount, - const char *repo_name, - gchar **out_uri, - ...) +assert_create_repo_dir (Fixture *fixture, int repos_dfd, GMount *repos_mount, const char *repo_name, + gchar **out_uri, ...) { glnx_autofd int ref_dfd = -1; - g_autoptr(OstreeRepo) repo = NULL; - g_autoptr(GError) error = NULL; + g_autoptr (OstreeRepo) repo = NULL; + g_autoptr (GError) error = NULL; va_list args; glnx_shutil_mkdir_p_at_open (repos_dfd, repo_name, 0700, &ref_dfd, NULL, &error); @@ -258,9 +238,9 @@ assert_create_repo_dir (Fixture *fixture, g_clear_error (&error); g_assert_no_error (error); - g_autoptr(GFile) mount_root = g_mount_get_root (repos_mount); - g_autoptr(GFile) repos_dir = g_file_get_child (mount_root, ".ostree/repos.d"); - g_autoptr(GFile) repo_dir = g_file_get_child (repos_dir, repo_name); + g_autoptr (GFile) mount_root = g_mount_get_root (repos_mount); + g_autoptr (GFile) repos_dir = g_file_get_child (mount_root, ".ostree/repos.d"); + g_autoptr (GFile) repo_dir = g_file_get_child (repos_dir, repo_name); va_start (args, out_uri); repo = assert_create_remote_va (fixture, repo_dir, args); @@ -274,13 +254,11 @@ assert_create_repo_dir (Fixture *fixture, /* Create a @repo_name symlink under the given @repos_dfd, pointing to * @symlink_target_path, or abort. */ static void -assert_create_repo_symlink (int repos_dfd, - const char *repo_name, - const char *symlink_target_path) +assert_create_repo_symlink (int repos_dfd, const char *repo_name, const char *symlink_target_path) { if (TEMP_FAILURE_RETRY (symlinkat (symlink_target_path, repos_dfd, repo_name)) != 0) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; glnx_throw_errno_prefix (&error, "symlinkat"); g_assert_no_error (error); } @@ -289,17 +267,14 @@ assert_create_repo_symlink (int repos_dfd, /* Add configuration for a remote named @remote_name, at @remote_uri, with a * remote collection ID of @collection_id, to the given @repo. */ static void -assert_create_remote_config (OstreeRepo *repo, - const gchar *remote_name, - const gchar *remote_uri, +assert_create_remote_config (OstreeRepo *repo, const gchar *remote_name, const gchar *remote_uri, const gchar *collection_id) { - g_autoptr(GError) error = NULL; - g_autoptr(GVariant) options = NULL; + g_autoptr (GError) error = NULL; + g_autoptr (GVariant) options = NULL; if (collection_id != NULL) - options = g_variant_new_parsed ("@a{sv} { 'collection-id': <%s> }", - collection_id); + options = g_variant_new_parsed ("@a{sv} { 'collection-id': <%s> }", collection_id); ostree_repo_remote_add (repo, remote_name, remote_uri, options, NULL, &error); g_assert_no_error (error); @@ -309,39 +284,41 @@ assert_create_remote_config (OstreeRepo *repo, * are mounted, some of which are removable, some of which contain valid or * invalid repo information on the file system, etc. */ static void -test_repo_finder_mount_mixed_mounts (Fixture *fixture, - gconstpointer test_data) +test_repo_finder_mount_mixed_mounts (Fixture *fixture, gconstpointer test_data) { - g_autoptr(OstreeRepoFinderMount) finder = NULL; - g_autoptr(GVolumeMonitor) monitor = NULL; - g_autoptr(GMainContext) context = NULL; - g_autoptr(GAsyncResult) async_result = NULL; - g_autoptr(GPtrArray) results = NULL; /* (element-type OstreeRepoFinderResult) */ - g_autoptr(GError) error = NULL; - g_autoptr(GList) mounts = NULL; /* (element-type OstreeMockMount) */ - g_autoptr(GMount) non_removable_mount = NULL; - g_autoptr(GMount) no_repos_mount = NULL; - g_autoptr(GMount) repo1_mount = NULL; - g_autoptr(GMount) repo2_mount = NULL; - g_autoptr(GFile) non_removable_root = NULL; + g_autoptr (OstreeRepoFinderMount) finder = NULL; + g_autoptr (GVolumeMonitor) monitor = NULL; + g_autoptr (GMainContext) context = NULL; + g_autoptr (GAsyncResult) async_result = NULL; + g_autoptr (GPtrArray) results = NULL; /* (element-type OstreeRepoFinderResult) */ + g_autoptr (GError) error = NULL; + g_autoptr (GList) mounts = NULL; /* (element-type OstreeMockMount) */ + g_autoptr (GMount) non_removable_mount = NULL; + g_autoptr (GMount) no_repos_mount = NULL; + g_autoptr (GMount) repo1_mount = NULL; + g_autoptr (GMount) repo2_mount = NULL; + g_autoptr (GFile) non_removable_root = NULL; glnx_autofd int no_repos_repos = -1; glnx_autofd int repo1_repos = -1; glnx_autofd int repo2_repos = -1; - g_autoptr(OstreeRepo) repo1_repo_a = NULL, repo1_repo_b = NULL; - g_autoptr(OstreeRepo) repo2_repo_a = NULL; + g_autoptr (OstreeRepo) repo1_repo_a = NULL, repo1_repo_b = NULL; + g_autoptr (OstreeRepo) repo2_repo_a = NULL; g_autofree gchar *repo1_repo_a_uri = NULL, *repo1_repo_b_uri = NULL; g_autofree gchar *repo2_repo_a_uri = NULL; - g_autofree gchar *repo1_ref0_checksum = NULL, *repo1_ref1_checksum = NULL, *repo1_ref2_checksum = NULL; - g_autofree gchar *repo2_ref0_checksum = NULL, *repo2_ref1_checksum = NULL, *repo2_ref2_checksum = NULL; + g_autofree gchar *repo1_ref0_checksum = NULL, *repo1_ref1_checksum = NULL, + *repo1_ref2_checksum = NULL; + g_autofree gchar *repo2_ref0_checksum = NULL, *repo2_ref1_checksum = NULL, + *repo2_ref2_checksum = NULL; g_autofree gchar *repo1_ref5_checksum = NULL, *repo2_ref3_checksum = NULL; gsize i; const OstreeCollectionRef ref0 = { "org.example.Collection1", "exampleos/x86_64/ref0" }; const OstreeCollectionRef ref1 = { "org.example.Collection1", "exampleos/x86_64/ref1" }; const OstreeCollectionRef ref2 = { "org.example.Collection1", "exampleos/x86_64/ref2" }; const OstreeCollectionRef ref3 = { "org.example.Collection1", "exampleos/x86_64/ref3" }; - const OstreeCollectionRef ref4 = { "org.example.UnconfiguredCollection", "exampleos/x86_64/ref4" }; + const OstreeCollectionRef ref4 + = { "org.example.UnconfiguredCollection", "exampleos/x86_64/ref4" }; const OstreeCollectionRef ref5 = { "org.example.Collection3", "exampleos/x86_64/ref0" }; - const OstreeCollectionRef * const refs[] = { &ref0, &ref1, &ref2, &ref3, &ref4, &ref5, NULL }; + const OstreeCollectionRef *const refs[] = { &ref0, &ref1, &ref2, &ref3, &ref4, &ref5, NULL }; context = g_main_context_new (); g_main_context_push_thread_default (context); @@ -356,23 +333,18 @@ test_repo_finder_mount_mixed_mounts (Fixture *fixture, assert_create_repos_dir (fixture, "no-repos-mount", &no_repos_repos, &no_repos_mount); assert_create_repos_dir (fixture, "repo1-mount", &repo1_repos, &repo1_mount); - repo1_repo_a = assert_create_repo_dir (fixture, repo1_repos, repo1_mount, "repo1-repo-a", &repo1_repo_a_uri, - refs[0], &repo1_ref0_checksum, - refs[2], &repo1_ref2_checksum, - refs[5], &repo1_ref5_checksum, - NULL); - repo1_repo_b = assert_create_repo_dir (fixture, repo1_repos, repo1_mount, "repo1-repo-b", &repo1_repo_b_uri, - refs[1], &repo1_ref1_checksum, - NULL); + repo1_repo_a = assert_create_repo_dir (fixture, repo1_repos, repo1_mount, "repo1-repo-a", + &repo1_repo_a_uri, refs[0], &repo1_ref0_checksum, refs[2], + &repo1_ref2_checksum, refs[5], &repo1_ref5_checksum, NULL); + repo1_repo_b = assert_create_repo_dir (fixture, repo1_repos, repo1_mount, "repo1-repo-b", + &repo1_repo_b_uri, refs[1], &repo1_ref1_checksum, NULL); assert_create_repo_symlink (repo1_repos, "repo1-repo-a-alias", "repo1-repo-a"); assert_create_repos_dir (fixture, "repo2-mount", &repo2_repos, &repo2_mount); - repo2_repo_a = assert_create_repo_dir (fixture, repo2_repos, repo2_mount, "repo2-repo-a", &repo2_repo_a_uri, - refs[0], &repo2_ref0_checksum, - refs[1], &repo2_ref1_checksum, - refs[2], &repo2_ref2_checksum, - refs[3], &repo2_ref3_checksum, - NULL); + repo2_repo_a = assert_create_repo_dir (fixture, repo2_repos, repo2_mount, "repo2-repo-a", + &repo2_repo_a_uri, refs[0], &repo2_ref0_checksum, refs[1], + &repo2_ref1_checksum, refs[2], &repo2_ref2_checksum, + refs[3], &repo2_ref3_checksum, NULL); assert_create_repo_symlink (repo2_repos, "repo2-repo-a-alias", "repo2-repo-a"); assert_create_repo_symlink (repo2_repos, "dangling-symlink", "repo2-repo-b"); assert_create_repo_symlink (repo2_repos, "root", "/"); @@ -385,21 +357,22 @@ test_repo_finder_mount_mixed_mounts (Fixture *fixture, monitor = ostree_mock_volume_monitor_new (mounts, NULL); finder = ostree_repo_finder_mount_new (monitor); - assert_create_remote_config (fixture->parent_repo, "remote1", "https://nope1", "org.example.Collection1"); - assert_create_remote_config (fixture->parent_repo, "remote2", "https://nope2", "org.example.Collection2"); + assert_create_remote_config (fixture->parent_repo, "remote1", "https://nope1", + "org.example.Collection1"); + assert_create_remote_config (fixture->parent_repo, "remote2", "https://nope2", + "org.example.Collection2"); /* don’t configure org.example.UnconfiguredCollection */ - assert_create_remote_config (fixture->parent_repo, "remote3", "https://nope3", "org.example.Collection3"); + assert_create_remote_config (fixture->parent_repo, "remote3", "https://nope3", + "org.example.Collection3"); /* Resolve the refs. */ - ostree_repo_finder_resolve_async (OSTREE_REPO_FINDER (finder), refs, - fixture->parent_repo, - NULL, result_cb, &async_result); + ostree_repo_finder_resolve_async (OSTREE_REPO_FINDER (finder), refs, fixture->parent_repo, NULL, + result_cb, &async_result); while (async_result == NULL) g_main_context_iteration (context, TRUE); - results = ostree_repo_finder_resolve_finish (OSTREE_REPO_FINDER (finder), - async_result, &error); + results = ostree_repo_finder_resolve_finish (OSTREE_REPO_FINDER (finder), async_result, &error); g_assert_no_error (error); g_assert_nonnull (results); g_assert_cmpuint (results->len, ==, 4); @@ -416,38 +389,46 @@ test_repo_finder_mount_mixed_mounts (Fixture *fixture, g_assert_no_error (error); keyring = result->remote->keyring; - if (g_strcmp0 (uri, repo1_repo_a_uri) == 0 && - g_strcmp0 (keyring, "remote1.trustedkeys.gpg") == 0) + if (g_strcmp0 (uri, repo1_repo_a_uri) == 0 + && g_strcmp0 (keyring, "remote1.trustedkeys.gpg") == 0) { g_assert_cmpuint (g_hash_table_size (result->ref_to_checksum), ==, 2); - g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, refs[0]), ==, repo1_ref0_checksum); - g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, refs[2]), ==, repo1_ref2_checksum); + g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, refs[0]), ==, + repo1_ref0_checksum); + g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, refs[2]), ==, + repo1_ref2_checksum); } - else if (g_strcmp0 (uri, repo1_repo_a_uri) == 0 && - g_strcmp0 (keyring, "remote3.trustedkeys.gpg") == 0) + else if (g_strcmp0 (uri, repo1_repo_a_uri) == 0 + && g_strcmp0 (keyring, "remote3.trustedkeys.gpg") == 0) { g_assert_cmpuint (g_hash_table_size (result->ref_to_checksum), ==, 1); - g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, refs[5]), ==, repo1_ref5_checksum); + g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, refs[5]), ==, + repo1_ref5_checksum); } - else if (g_strcmp0 (uri, repo1_repo_b_uri) == 0 && - g_strcmp0 (keyring, "remote1.trustedkeys.gpg") == 0) + else if (g_strcmp0 (uri, repo1_repo_b_uri) == 0 + && g_strcmp0 (keyring, "remote1.trustedkeys.gpg") == 0) { g_assert_cmpuint (g_hash_table_size (result->ref_to_checksum), ==, 1); - g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, refs[1]), ==, repo1_ref1_checksum); + g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, refs[1]), ==, + repo1_ref1_checksum); } - else if (g_strcmp0 (uri, repo2_repo_a_uri) == 0 && - g_strcmp0 (keyring, "remote1.trustedkeys.gpg") == 0) + else if (g_strcmp0 (uri, repo2_repo_a_uri) == 0 + && g_strcmp0 (keyring, "remote1.trustedkeys.gpg") == 0) { g_assert_cmpuint (g_hash_table_size (result->ref_to_checksum), ==, 4); - g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, refs[0]), ==, repo2_ref0_checksum); - g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, refs[1]), ==, repo2_ref1_checksum); - g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, refs[2]), ==, repo2_ref2_checksum); - g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, refs[3]), ==, repo2_ref3_checksum); + g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, refs[0]), ==, + repo2_ref0_checksum); + g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, refs[1]), ==, + repo2_ref1_checksum); + g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, refs[2]), ==, + repo2_ref2_checksum); + g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, refs[3]), ==, + repo2_ref3_checksum); } else { - g_error ("Unknown result ‘%s’ with keyring ‘%s’", - result->remote->name, result->remote->keyring); + g_error ("Unknown result ‘%s’ with keyring ‘%s’", result->remote->name, + result->remote->keyring); } } @@ -458,25 +439,24 @@ test_repo_finder_mount_mixed_mounts (Fixture *fixture, * in the default repository paths ostree/repo and .ostree/repo, to check that * those paths are read */ static void -test_repo_finder_mount_well_known (Fixture *fixture, - gconstpointer test_data) +test_repo_finder_mount_well_known (Fixture *fixture, gconstpointer test_data) { - g_autoptr(OstreeRepoFinderMount) finder = NULL; - g_autoptr(GVolumeMonitor) monitor = NULL; - g_autoptr(GMainContext) context = NULL; - g_autoptr(GAsyncResult) async_result = NULL; - g_autoptr(GPtrArray) results = NULL; /* (element-type OstreeRepoFinderResult) */ - g_autoptr(GError) error = NULL; - g_autoptr(GList) mounts = NULL; /* (element-type OstreeMockMount) */ - g_autoptr(GMount) mount = NULL; + g_autoptr (OstreeRepoFinderMount) finder = NULL; + g_autoptr (GVolumeMonitor) monitor = NULL; + g_autoptr (GMainContext) context = NULL; + g_autoptr (GAsyncResult) async_result = NULL; + g_autoptr (GPtrArray) results = NULL; /* (element-type OstreeRepoFinderResult) */ + g_autoptr (GError) error = NULL; + g_autoptr (GList) mounts = NULL; /* (element-type OstreeMockMount) */ + g_autoptr (GMount) mount = NULL; glnx_autofd int repos = -1; - g_autoptr(OstreeRepo) repo_a = NULL, repo_b = NULL; + g_autoptr (OstreeRepo) repo_a = NULL, repo_b = NULL; g_autofree gchar *repo_a_uri = NULL, *repo_b_uri = NULL; g_autofree gchar *ref_a_checksum = NULL, *ref_b_checksum = NULL; gsize i; const OstreeCollectionRef ref_a = { "org.example.Collection1", "refA" }; const OstreeCollectionRef ref_b = { "org.example.Collection2", "refB" }; - const OstreeCollectionRef * const refs[] = { &ref_a, &ref_b, NULL }; + const OstreeCollectionRef *const refs[] = { &ref_a, &ref_b, NULL }; context = g_main_context_new (); g_main_context_push_thread_default (context); @@ -486,12 +466,10 @@ test_repo_finder_mount_well_known (Fixture *fixture, * file system from /tmp, so it’s an example of a symlink pointing outside * its mount point. */ assert_create_repos_dir (fixture, "mount", &repos, &mount); - repo_a = assert_create_repo_dir (fixture, repos, mount, "../../ostree/repo", &repo_a_uri, - &ref_a, &ref_a_checksum, - NULL); - repo_b = assert_create_repo_dir (fixture, repos, mount, "../../.ostree/repo", &repo_b_uri, - &ref_b, &ref_b_checksum, - NULL); + repo_a = assert_create_repo_dir (fixture, repos, mount, "../../ostree/repo", &repo_a_uri, &ref_a, + &ref_a_checksum, NULL); + repo_b = assert_create_repo_dir (fixture, repos, mount, "../../.ostree/repo", &repo_b_uri, &ref_b, + &ref_b_checksum, NULL); assert_create_repo_symlink (repos, "repo-a-alias", "../../ostree/repo"); mounts = g_list_prepend (mounts, mount); @@ -499,19 +477,19 @@ test_repo_finder_mount_well_known (Fixture *fixture, monitor = ostree_mock_volume_monitor_new (mounts, NULL); finder = ostree_repo_finder_mount_new (monitor); - assert_create_remote_config (fixture->parent_repo, "remote1", "https://nope1", "org.example.Collection1"); - assert_create_remote_config (fixture->parent_repo, "remote2", "https://nope2", "org.example.Collection2"); + assert_create_remote_config (fixture->parent_repo, "remote1", "https://nope1", + "org.example.Collection1"); + assert_create_remote_config (fixture->parent_repo, "remote2", "https://nope2", + "org.example.Collection2"); /* Resolve the refs. */ - ostree_repo_finder_resolve_async (OSTREE_REPO_FINDER (finder), refs, - fixture->parent_repo, - NULL, result_cb, &async_result); + ostree_repo_finder_resolve_async (OSTREE_REPO_FINDER (finder), refs, fixture->parent_repo, NULL, + result_cb, &async_result); while (async_result == NULL) g_main_context_iteration (context, TRUE); - results = ostree_repo_finder_resolve_finish (OSTREE_REPO_FINDER (finder), - async_result, &error); + results = ostree_repo_finder_resolve_finish (OSTREE_REPO_FINDER (finder), async_result, &error); g_assert_no_error (error); g_assert_nonnull (results); g_assert_cmpuint (results->len, ==, 2); @@ -528,22 +506,23 @@ test_repo_finder_mount_well_known (Fixture *fixture, g_assert_no_error (error); keyring = result->remote->keyring; - if (g_strcmp0 (uri, repo_a_uri) == 0 && - g_strcmp0 (keyring, "remote1.trustedkeys.gpg") == 0) + if (g_strcmp0 (uri, repo_a_uri) == 0 && g_strcmp0 (keyring, "remote1.trustedkeys.gpg") == 0) { g_assert_cmpuint (g_hash_table_size (result->ref_to_checksum), ==, 1); - g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, &ref_a), ==, ref_a_checksum); + g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, &ref_a), ==, + ref_a_checksum); } - else if (g_strcmp0 (uri, repo_b_uri) == 0 && - g_strcmp0 (keyring, "remote2.trustedkeys.gpg") == 0) + else if (g_strcmp0 (uri, repo_b_uri) == 0 + && g_strcmp0 (keyring, "remote2.trustedkeys.gpg") == 0) { g_assert_cmpuint (g_hash_table_size (result->ref_to_checksum), ==, 1); - g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, &ref_b), ==, ref_b_checksum); + g_assert_cmpstr (g_hash_table_lookup (result->ref_to_checksum, &ref_b), ==, + ref_b_checksum); } else { - g_test_message ("Unknown result ‘%s’ with keyring ‘%s’.", - result->remote->name, result->remote->keyring); + g_test_message ("Unknown result ‘%s’ with keyring ‘%s’.", result->remote->name, + result->remote->keyring); g_assert_not_reached (); } } @@ -551,7 +530,8 @@ test_repo_finder_mount_well_known (Fixture *fixture, g_main_context_pop_thread_default (context); } -int main (int argc, char **argv) +int +main (int argc, char **argv) { setlocale (LC_ALL, ""); g_test_init (&argc, &argv, NULL); @@ -560,12 +540,13 @@ int main (int argc, char **argv) g_test_add ("/repo-finder-mount/no-mounts", Fixture, NULL, setup, test_repo_finder_mount_no_mounts, teardown); #ifndef OSTREE_DISABLE_GPGME - /*`ostree_repo_resolve_keyring_for_collection()` fail the tests if no GPG support is compiled in. */ + /*`ostree_repo_resolve_keyring_for_collection()` fail the tests if no GPG support is compiled in. + */ g_test_add ("/repo-finder-mount/mixed-mounts", Fixture, NULL, setup, test_repo_finder_mount_mixed_mounts, teardown); g_test_add ("/repo-finder-mount/well-known", Fixture, NULL, setup, test_repo_finder_mount_well_known, teardown); #endif /* OSTREE_DISABLE_GPGME */ - return g_test_run(); + return g_test_run (); } diff --git a/tests/test-repo.c b/tests/test-repo.c index b8365ea9..1bc4cb81 100644 --- a/tests/test-repo.c +++ b/tests/test-repo.c @@ -23,8 +23,8 @@ #include "config.h" #include -#include #include +#include #include #include @@ -34,16 +34,15 @@ /* Test fixture. Creates a temporary directory. */ typedef struct { - GLnxTmpDir tmpdir; /* (owned) */ + GLnxTmpDir tmpdir; /* (owned) */ } Fixture; static void -setup (Fixture *fixture, - gconstpointer test_data) +setup (Fixture *fixture, gconstpointer test_data) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; - (void) glnx_mkdtemp ("test-repo-XXXXXX", 0700, &fixture->tmpdir, &error); + (void)glnx_mkdtemp ("test-repo-XXXXXX", 0700, &fixture->tmpdir, &error); g_assert_no_error (error); g_test_message ("Using temporary directory: %s", fixture->tmpdir.path); @@ -53,49 +52,41 @@ setup (Fixture *fixture, * set the locking timeout to 0 so lock failures don't block. */ static void -lock_setup (Fixture *fixture, - gconstpointer test_data) +lock_setup (Fixture *fixture, gconstpointer test_data) { setup (fixture, test_data); - g_autoptr(GError) error = NULL; - g_autoptr(OstreeRepo) repo = ostree_repo_create_at (fixture->tmpdir.fd, ".", - OSTREE_REPO_MODE_ARCHIVE, - NULL, - NULL, &error); + g_autoptr (GError) error = NULL; + g_autoptr (OstreeRepo) repo = ostree_repo_create_at ( + fixture->tmpdir.fd, ".", OSTREE_REPO_MODE_ARCHIVE, NULL, NULL, &error); g_assert_no_error (error); /* Set the lock timeout to 0 so failures don't block the test */ - g_autoptr(GKeyFile) config = ostree_repo_copy_config (repo); + g_autoptr (GKeyFile) config = ostree_repo_copy_config (repo); g_key_file_set_integer (config, "core", "lock-timeout-secs", 0); ostree_repo_write_config (repo, config, &error); g_assert_no_error (error); } static void -teardown (Fixture *fixture, - gconstpointer test_data) +teardown (Fixture *fixture, gconstpointer test_data) { /* Recursively remove the temporary directory. */ - (void) glnx_tmpdir_delete (&fixture->tmpdir, NULL, NULL); + (void)glnx_tmpdir_delete (&fixture->tmpdir, NULL, NULL); } /* Test that the hash values for two #OstreeRepo instances pointing at the same * repository are equal. We can’t test anything else, since hash collisions are * always a possibility. */ static void -test_repo_hash (Fixture *fixture, - gconstpointer test_data) +test_repo_hash (Fixture *fixture, gconstpointer test_data) { - g_autoptr(GError) error = NULL; - g_autoptr(OstreeRepo) repo1 = ostree_repo_create_at (fixture->tmpdir.fd, ".", - OSTREE_REPO_MODE_ARCHIVE, - NULL, - NULL, &error); + g_autoptr (GError) error = NULL; + g_autoptr (OstreeRepo) repo1 = ostree_repo_create_at ( + fixture->tmpdir.fd, ".", OSTREE_REPO_MODE_ARCHIVE, NULL, NULL, &error); g_assert_no_error (error); - g_autoptr(OstreeRepo) repo2 = ostree_repo_open_at (fixture->tmpdir.fd, ".", - NULL, &error); + g_autoptr (OstreeRepo) repo2 = ostree_repo_open_at (fixture->tmpdir.fd, ".", NULL, &error); g_assert_no_error (error); g_assert_cmpuint (ostree_repo_hash (repo1), ==, ostree_repo_hash (repo2)); @@ -103,13 +94,12 @@ test_repo_hash (Fixture *fixture, /* Test that trying to hash a closed repo results in an assertion failure. */ static void -test_repo_hash_closed (Fixture *fixture, - gconstpointer test_data) +test_repo_hash_closed (Fixture *fixture, gconstpointer test_data) { if (g_test_subprocess ()) { - g_autoptr(GFile) repo_path = g_file_new_for_path (fixture->tmpdir.path); - g_autoptr(OstreeRepo) repo = ostree_repo_new (repo_path); + g_autoptr (GFile) repo_path = g_file_new_for_path (fixture->tmpdir.path); + g_autoptr (OstreeRepo) repo = ostree_repo_new (repo_path); ostree_repo_hash (repo); @@ -123,10 +113,9 @@ test_repo_hash_closed (Fixture *fixture, /* Test that various repositories test equal (or not) with each other. */ static void -test_repo_equal (Fixture *fixture, - gconstpointer test_data) +test_repo_equal (Fixture *fixture, gconstpointer test_data) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; /* Create a few separate repos and some #OstreeRepo objects for them. */ glnx_ensure_dir (fixture->tmpdir.fd, "repo1", 0755, &error); @@ -134,24 +123,20 @@ test_repo_equal (Fixture *fixture, glnx_ensure_dir (fixture->tmpdir.fd, "repo2", 0755, &error); g_assert_no_error (error); - g_autoptr(OstreeRepo) repo1 = ostree_repo_create_at (fixture->tmpdir.fd, "repo1", - OSTREE_REPO_MODE_ARCHIVE, - NULL, - NULL, &error); + g_autoptr (OstreeRepo) repo1 = ostree_repo_create_at ( + fixture->tmpdir.fd, "repo1", OSTREE_REPO_MODE_ARCHIVE, NULL, NULL, &error); g_assert_no_error (error); - g_autoptr(OstreeRepo) repo1_alias = ostree_repo_open_at (fixture->tmpdir.fd, "repo1", - NULL, &error); + g_autoptr (OstreeRepo) repo1_alias + = ostree_repo_open_at (fixture->tmpdir.fd, "repo1", NULL, &error); g_assert_no_error (error); - g_autoptr(OstreeRepo) repo2 = ostree_repo_create_at (fixture->tmpdir.fd, "repo2", - OSTREE_REPO_MODE_ARCHIVE, - NULL, - NULL, &error); + g_autoptr (OstreeRepo) repo2 = ostree_repo_create_at ( + fixture->tmpdir.fd, "repo2", OSTREE_REPO_MODE_ARCHIVE, NULL, NULL, &error); g_assert_no_error (error); - g_autoptr(GFile) closed_repo_path = g_file_new_for_path (fixture->tmpdir.path); - g_autoptr(OstreeRepo) closed_repo = ostree_repo_new (closed_repo_path); + g_autoptr (GFile) closed_repo_path = g_file_new_for_path (fixture->tmpdir.path); + g_autoptr (OstreeRepo) closed_repo = ostree_repo_new (closed_repo_path); /* Test various equalities. */ g_assert_true (ostree_repo_equal (repo1, repo1)); @@ -173,30 +158,26 @@ test_repo_equal (Fixture *fixture, } static void -test_repo_get_min_free_space (Fixture *fixture, - gconstpointer test_data) +test_repo_get_min_free_space (Fixture *fixture, gconstpointer test_data) { g_autoptr (GKeyFile) config = NULL; - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; guint64 bytes = 0; typedef struct - { - const char *val; - gboolean should_succeed; - } min_free_space_value; + { + const char *val; + gboolean should_succeed; + } min_free_space_value; - g_autoptr(OstreeRepo) repo = ostree_repo_create_at (fixture->tmpdir.fd, ".", - OSTREE_REPO_MODE_ARCHIVE, - NULL, - NULL, &error); + g_autoptr (OstreeRepo) repo = ostree_repo_create_at ( + fixture->tmpdir.fd, ".", OSTREE_REPO_MODE_ARCHIVE, NULL, NULL, &error); g_assert_no_error (error); - min_free_space_value values_to_test[] = { - {"500MB", TRUE }, - { "0MB", TRUE }, - { "17179869185GB", FALSE }, /* Overflow parameter: bytes > G_MAXUINT64 */ - { NULL, FALSE } - }; + min_free_space_value values_to_test[] + = { { "500MB", TRUE }, + { "0MB", TRUE }, + { "17179869185GB", FALSE }, /* Overflow parameter: bytes > G_MAXUINT64 */ + { NULL, FALSE } }; config = ostree_repo_copy_config (repo); @@ -219,89 +200,94 @@ test_repo_get_min_free_space (Fixture *fixture, } static void -test_write_regfile_api (Fixture *fixture, - gconstpointer test_data) +test_write_regfile_api (Fixture *fixture, gconstpointer test_data) { g_autoptr (GKeyFile) config = NULL; - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; - g_autoptr(OstreeRepo) repo = ostree_repo_create_at (fixture->tmpdir.fd, ".", - OSTREE_REPO_MODE_ARCHIVE, - NULL, - NULL, &error); + g_autoptr (OstreeRepo) repo = ostree_repo_create_at ( + fixture->tmpdir.fd, ".", OSTREE_REPO_MODE_ARCHIVE, NULL, NULL, &error); g_assert_no_error (error); - g_auto(GVariantBuilder) xattrs_builder; - g_variant_builder_init (&xattrs_builder, (GVariantType*)"a(ayay)"); - g_variant_builder_add (&xattrs_builder, "(^ay^ay)", "security.selinux", "system_u:object_r:etc_t:s0"); - g_autoptr(GVariant) xattrs = g_variant_ref_sink (g_variant_builder_end (&xattrs_builder)); + g_auto (GVariantBuilder) xattrs_builder; + g_variant_builder_init (&xattrs_builder, (GVariantType *)"a(ayay)"); + g_variant_builder_add (&xattrs_builder, "(^ay^ay)", "security.selinux", + "system_u:object_r:etc_t:s0"); + g_autoptr (GVariant) xattrs = g_variant_ref_sink (g_variant_builder_end (&xattrs_builder)); // Current contents of /etc/networks in Fedora static const char contents[] = "default 0.0.0.0\nloopback 127.0.0.0\nlink-local 169.254.0.0\n"; // First with no xattrs - g_autofree char *checksum = ostree_repo_write_regfile_inline (repo, NULL, 0, 0, S_IFREG | 0644, NULL, (const guint8*)contents, sizeof (contents)-1, NULL, &error); + g_autofree char *checksum = ostree_repo_write_regfile_inline ( + repo, NULL, 0, 0, S_IFREG | 0644, NULL, (const guint8 *)contents, sizeof (contents) - 1, NULL, + &error); g_assert_no_error (error); - g_assert_cmpstr (checksum, ==, "8aaa9dc13a0c5839fe4a277756798c609c53fac6fa2290314ecfef9041065873"); + g_assert_cmpstr (checksum, ==, + "8aaa9dc13a0c5839fe4a277756798c609c53fac6fa2290314ecfef9041065873"); g_clear_pointer (&checksum, g_free); // Invalid checksum - checksum = ostree_repo_write_regfile_inline (repo, "3272139f889f6a7007b3d64adc74be9e2979bf6bbe663d1512e5bd43f4de24a1", - 0, 0, S_IFREG | 0644, NULL, (const guint8*)contents, sizeof (contents)-1, NULL, &error); + checksum = ostree_repo_write_regfile_inline ( + repo, "3272139f889f6a7007b3d64adc74be9e2979bf6bbe663d1512e5bd43f4de24a1", 0, 0, + S_IFREG | 0644, NULL, (const guint8 *)contents, sizeof (contents) - 1, NULL, &error); g_assert (checksum == NULL); g_assert (error != NULL); g_clear_error (&error); // Now with xattrs g_clear_pointer (&checksum, g_free); - checksum = ostree_repo_write_regfile_inline (repo, NULL, 0, 0, S_IFREG | 0644, xattrs, (const guint8*)contents, sizeof (contents)-1, NULL, &error); + checksum = ostree_repo_write_regfile_inline (repo, NULL, 0, 0, S_IFREG | 0644, xattrs, + (const guint8 *)contents, sizeof (contents) - 1, + NULL, &error); g_assert_no_error (error); - g_assert_cmpstr (checksum, ==, "4f600d252338f93279c51c964915cb2c26f0d09082164c54890d1a3c78cdeb1e"); + g_assert_cmpstr (checksum, ==, + "4f600d252338f93279c51c964915cb2c26f0d09082164c54890d1a3c78cdeb1e"); g_clear_pointer (&checksum, g_free); // Test symlinks g_clear_pointer (&xattrs, g_variant_unref); - g_variant_builder_init (&xattrs_builder, (GVariantType*)"a(ayay)"); - g_variant_builder_add (&xattrs_builder, "(^ay^ay)", "security.selinux", "system_u:object_r:bin_t:s0"); + g_variant_builder_init (&xattrs_builder, (GVariantType *)"a(ayay)"); + g_variant_builder_add (&xattrs_builder, "(^ay^ay)", "security.selinux", + "system_u:object_r:bin_t:s0"); xattrs = g_variant_ref_sink (g_variant_builder_end (&xattrs_builder)); g_clear_pointer (&checksum, g_free); checksum = ostree_repo_write_symlink (repo, NULL, 0, 0, xattrs, "bash", NULL, &error); g_assert_no_error (error); - g_assert_cmpstr (checksum, ==, "23a2e97d21d960ac7a4e39a8721b1baff7b213e00e5e5641334f50506012fcff"); + g_assert_cmpstr (checksum, ==, + "23a2e97d21d960ac7a4e39a8721b1baff7b213e00e5e5641334f50506012fcff"); } /* Just a sanity check of the C autolocking API */ static void -test_repo_autolock (Fixture *fixture, - gconstpointer test_data) +test_repo_autolock (Fixture *fixture, gconstpointer test_data) { - g_autoptr(GError) error = NULL; - g_autoptr(OstreeRepo) repo = ostree_repo_create_at (fixture->tmpdir.fd, ".", - OSTREE_REPO_MODE_ARCHIVE, - NULL, - NULL, &error); + g_autoptr (GError) error = NULL; + g_autoptr (OstreeRepo) repo = ostree_repo_create_at ( + fixture->tmpdir.fd, ".", OSTREE_REPO_MODE_ARCHIVE, NULL, NULL, &error); g_assert_no_error (error); { - g_autoptr(OstreeRepoAutoLock) lock = ostree_repo_auto_lock_push (repo, OSTREE_REPO_LOCK_EXCLUSIVE, NULL, &error); + g_autoptr (OstreeRepoAutoLock) lock + = ostree_repo_auto_lock_push (repo, OSTREE_REPO_LOCK_EXCLUSIVE, NULL, &error); g_assert_no_error (error); } - g_autoptr(OstreeRepoAutoLock) lock1 = ostree_repo_auto_lock_push (repo, OSTREE_REPO_LOCK_SHARED, NULL, &error); + g_autoptr (OstreeRepoAutoLock) lock1 + = ostree_repo_auto_lock_push (repo, OSTREE_REPO_LOCK_SHARED, NULL, &error); g_assert_no_error (error); - g_autoptr(OstreeRepoAutoLock) lock2 = ostree_repo_auto_lock_push (repo, OSTREE_REPO_LOCK_SHARED, NULL, &error); + g_autoptr (OstreeRepoAutoLock) lock2 + = ostree_repo_auto_lock_push (repo, OSTREE_REPO_LOCK_SHARED, NULL, &error); g_assert_no_error (error); } /* Locking from single thread with a single OstreeRepo */ static void -test_repo_lock_single (Fixture *fixture, - gconstpointer test_data) +test_repo_lock_single (Fixture *fixture, gconstpointer test_data) { - g_autoptr(GError) error = NULL; - g_autoptr(OstreeRepo) repo = ostree_repo_open_at (fixture->tmpdir.fd, ".", - NULL, &error); + g_autoptr (GError) error = NULL; + g_autoptr (OstreeRepo) repo = ostree_repo_open_at (fixture->tmpdir.fd, ".", NULL, &error); g_assert_no_error (error); /* Single thread on a single repo can freely recurse in any state */ @@ -321,14 +307,12 @@ test_repo_lock_single (Fixture *fixture, /* Unlocking without having ever locked */ static void -test_repo_lock_unlock_never_locked (Fixture *fixture, - gconstpointer test_data) +test_repo_lock_unlock_never_locked (Fixture *fixture, gconstpointer test_data) { if (g_test_subprocess ()) { - g_autoptr(GError) error = NULL; - g_autoptr(OstreeRepo) repo = ostree_repo_open_at (fixture->tmpdir.fd, ".", - NULL, &error); + g_autoptr (GError) error = NULL; + g_autoptr (OstreeRepo) repo = ostree_repo_open_at (fixture->tmpdir.fd, ".", NULL, &error); g_assert_no_error (error); ostree_repo_lock_pop (repo, OSTREE_REPO_LOCK_SHARED, NULL, &error); @@ -343,14 +327,12 @@ test_repo_lock_unlock_never_locked (Fixture *fixture, /* Unlocking after already unlocked */ static void -test_repo_lock_double_unlock (Fixture *fixture, - gconstpointer test_data) +test_repo_lock_double_unlock (Fixture *fixture, gconstpointer test_data) { if (g_test_subprocess ()) { - g_autoptr(GError) error = NULL; - g_autoptr(OstreeRepo) repo = ostree_repo_open_at (fixture->tmpdir.fd, ".", - NULL, &error); + g_autoptr (GError) error = NULL; + g_autoptr (OstreeRepo) repo = ostree_repo_open_at (fixture->tmpdir.fd, ".", NULL, &error); g_assert_no_error (error); ostree_repo_lock_push (repo, OSTREE_REPO_LOCK_SHARED, NULL, &error); @@ -369,14 +351,12 @@ test_repo_lock_double_unlock (Fixture *fixture, /* Unlocking the wrong type */ static void -test_repo_lock_unlock_wrong_type (Fixture *fixture, - gconstpointer test_data) +test_repo_lock_unlock_wrong_type (Fixture *fixture, gconstpointer test_data) { if (g_test_subprocess ()) { - g_autoptr(GError) error = NULL; - g_autoptr(OstreeRepo) repo = ostree_repo_open_at (fixture->tmpdir.fd, ".", - NULL, &error); + g_autoptr (GError) error = NULL; + g_autoptr (OstreeRepo) repo = ostree_repo_open_at (fixture->tmpdir.fd, ".", NULL, &error); g_assert_no_error (error); ostree_repo_lock_push (repo, OSTREE_REPO_LOCK_SHARED, NULL, &error); @@ -388,22 +368,20 @@ test_repo_lock_unlock_wrong_type (Fixture *fixture, g_test_trap_subprocess (NULL, 0, 0); g_test_trap_assert_failed (); - g_test_trap_assert_stderr ("*ERROR*Repo exclusive lock pop requested, but none have been taken\n"); + g_test_trap_assert_stderr ( + "*ERROR*Repo exclusive lock pop requested, but none have been taken\n"); } /* Locking with single thread and multiple OstreeRepos */ static void -test_repo_lock_multi_repo (Fixture *fixture, - gconstpointer test_data) +test_repo_lock_multi_repo (Fixture *fixture, gconstpointer test_data) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; /* Open two OstreeRepo instances */ - g_autoptr(OstreeRepo) repo1 = ostree_repo_open_at (fixture->tmpdir.fd, ".", - NULL, &error); + g_autoptr (OstreeRepo) repo1 = ostree_repo_open_at (fixture->tmpdir.fd, ".", NULL, &error); g_assert_no_error (error); - g_autoptr(OstreeRepo) repo2 = ostree_repo_open_at (fixture->tmpdir.fd, ".", - NULL, &error); + g_autoptr (OstreeRepo) repo2 = ostree_repo_open_at (fixture->tmpdir.fd, ".", NULL, &error); g_assert_no_error (error); /* Single thread with multiple OstreeRepo's conflict */ @@ -437,7 +415,8 @@ test_repo_lock_multi_repo (Fixture *fixture, } /* Locking from multiple threads with a single OstreeRepo */ -typedef struct { +typedef struct +{ OstreeRepo *repo; guint step; } LockThreadData; @@ -446,7 +425,7 @@ static gpointer lock_thread1 (gpointer thread_data) { LockThreadData *data = thread_data; - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; /* Step 0: Take an exclusive lock */ g_assert_cmpuint (data->step, ==, 0); @@ -481,7 +460,7 @@ static gpointer lock_thread2 (gpointer thread_data) { LockThreadData *data = thread_data; - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; /* Step 1: Wait for the other thread to acquire a lock and then take a * shared lock. @@ -505,18 +484,15 @@ lock_thread2 (gpointer thread_data) } static void -test_repo_lock_multi_thread (Fixture *fixture, - gconstpointer test_data) +test_repo_lock_multi_thread (Fixture *fixture, gconstpointer test_data) { - g_autoptr(GError) error = NULL; - g_autoptr(OstreeRepo) repo1 = ostree_repo_open_at (fixture->tmpdir.fd, ".", - NULL, &error); + g_autoptr (GError) error = NULL; + g_autoptr (OstreeRepo) repo1 = ostree_repo_open_at (fixture->tmpdir.fd, ".", NULL, &error); g_assert_no_error (error); - g_autoptr(OstreeRepo) repo2 = ostree_repo_open_at (fixture->tmpdir.fd, ".", - NULL, &error); + g_autoptr (OstreeRepo) repo2 = ostree_repo_open_at (fixture->tmpdir.fd, ".", NULL, &error); g_assert_no_error (error); - LockThreadData thread_data = {repo1, 0}; + LockThreadData thread_data = { repo1, 0 }; GThread *thread1 = g_thread_new ("lock-thread-1", lock_thread1, &thread_data); GThread *thread2 = g_thread_new ("lock-thread-2", lock_thread2, &thread_data); @@ -566,36 +542,29 @@ test_repo_lock_multi_thread (Fixture *fixture, } int -main (int argc, - char **argv) +main (int argc, char **argv) { setlocale (LC_ALL, ""); g_test_init (&argc, &argv, NULL); - g_test_add ("/repo/hash", Fixture, NULL, setup, - test_repo_hash, teardown); - g_test_add ("/repo/hash/closed", Fixture, NULL, setup, - test_repo_hash_closed, teardown); - g_test_add ("/repo/equal", Fixture, NULL, setup, - test_repo_equal, teardown); - g_test_add ("/repo/get_min_free_space", Fixture, NULL, setup, - test_repo_get_min_free_space, teardown); - g_test_add ("/repo/write_regfile_api", Fixture, NULL, setup, - test_write_regfile_api, teardown); - g_test_add ("/repo/autolock", Fixture, NULL, setup, - test_repo_autolock, teardown); - g_test_add ("/repo/lock/single", Fixture, NULL, lock_setup, - test_repo_lock_single, teardown); + g_test_add ("/repo/hash", Fixture, NULL, setup, test_repo_hash, teardown); + g_test_add ("/repo/hash/closed", Fixture, NULL, setup, test_repo_hash_closed, teardown); + g_test_add ("/repo/equal", Fixture, NULL, setup, test_repo_equal, teardown); + g_test_add ("/repo/get_min_free_space", Fixture, NULL, setup, test_repo_get_min_free_space, + teardown); + g_test_add ("/repo/write_regfile_api", Fixture, NULL, setup, test_write_regfile_api, teardown); + g_test_add ("/repo/autolock", Fixture, NULL, setup, test_repo_autolock, teardown); + g_test_add ("/repo/lock/single", Fixture, NULL, lock_setup, test_repo_lock_single, teardown); g_test_add ("/repo/lock/unlock-never-locked", Fixture, NULL, lock_setup, test_repo_lock_unlock_never_locked, teardown); - g_test_add ("/repo/lock/double-unlock", Fixture, NULL, lock_setup, - test_repo_lock_double_unlock, teardown); + g_test_add ("/repo/lock/double-unlock", Fixture, NULL, lock_setup, test_repo_lock_double_unlock, + teardown); g_test_add ("/repo/lock/unlock-wrong-type", Fixture, NULL, lock_setup, test_repo_lock_unlock_wrong_type, teardown); - g_test_add ("/repo/lock/multi-repo", Fixture, NULL, lock_setup, - test_repo_lock_multi_repo, teardown); - g_test_add ("/repo/lock/multi-thread", Fixture, NULL, lock_setup, - test_repo_lock_multi_thread, teardown); + g_test_add ("/repo/lock/multi-repo", Fixture, NULL, lock_setup, test_repo_lock_multi_repo, + teardown); + g_test_add ("/repo/lock/multi-thread", Fixture, NULL, lock_setup, test_repo_lock_multi_thread, + teardown); return g_test_run (); } diff --git a/tests/test-rfc2616-dates.c b/tests/test-rfc2616-dates.c index 55807f16..a47bca81 100644 --- a/tests/test-rfc2616-dates.c +++ b/tests/test-rfc2616-dates.c @@ -30,58 +30,57 @@ static void test_ostree_parse_rfc2616_date_time (void) { #if GLIB_CHECK_VERSION(2, 62, 0) -G_GNUC_BEGIN_IGNORE_DEPRECATIONS + G_GNUC_BEGIN_IGNORE_DEPRECATIONS const struct - { - const char *rfc2616; - const char *expected_iso8601; /* (nullable) if parsing is expected to fail */ - } - tests[] = - { - { "Wed, 21 Oct 2015 07:28:00 GMT", "2015-10-21T07:28:00Z" }, - { "Wed, 21 Oct 2015 07:28:00", NULL }, /* too short */ - { "Wed, 21 Oct 2015 07:28:00 CEST", NULL }, /* too long; not GMT */ - { "Cat, 21 Oct 2015 07:28:00 GMT", NULL }, /* invalid day */ - { "Wed 21 Oct 2015 07:28:00 GMT", NULL }, /* no comma */ - { "Wed,21 Oct 2015 07:28:00 GMT ", NULL }, /* missing space */ - { "Wed, xx Oct 2015 07:28:00 GMT", NULL }, /* no day-of-month */ - { "Wed, 011Oct 2015 07:28:00 GMT", NULL }, /* overlong day-of-month */ - { "Wed, 00 Oct 2015 07:28:00 GMT", NULL }, /* day-of-month underflow */ - { "Wed, 32 Oct 2015 07:28:00 GMT", NULL }, /* day-of-month overflow */ - { "Wed, 21,Oct 2015 07:28:00 GMT", NULL }, /* missing space */ - { "Wed, 21 Cat 2015 07:28:00 GMT", NULL }, /* invalid month */ - { "Wed, 21 Oct,2015 07:28:00 GMT", NULL }, /* missing space */ - { "Wed, 21 Oct xxxx 07:28:00 GMT", NULL }, /* no year */ - { "Wed, 21 Oct 0201507:28:00 GMT", NULL }, /* overlong year */ - { "Wed, 21 Oct 0000 07:28:00 GMT", NULL }, /* year underflow */ - { "Wed, 21 Oct 10000 07:28:00 GM", NULL }, /* year overflow */ - { "Wed, 21 Oct 2015,07:28:00 GMT", NULL }, /* missing space */ - { "Wed, 21 Oct 2015 07 28:00 GMT", NULL }, /* missing colon */ - { "Wed, 21 Oct 2015 007:28:00 GM", NULL }, /* overlong hour */ - { "Wed, 21 Oct 2015 xx:28:00 GMT", NULL }, /* missing hour */ - { "Wed, 21 Oct 2015 -1:28:00 GMT", NULL }, /* hour underflow */ - { "Wed, 21 Oct 2015 24:28:00 GMT", NULL }, /* hour overflow */ - { "Wed, 21 Oct 2015 07:28 00 GMT", NULL }, /* missing colon */ - { "Wed, 21 Oct 2015 07:028:00 GM", NULL }, /* overlong minute */ - { "Wed, 21 Oct 2015 07:xx:00 GMT", NULL }, /* missing minute */ - { "Wed, 21 Oct 2015 07:-1:00 GMT", NULL }, /* minute underflow */ - { "Wed, 21 Oct 2015 07:60:00 GMT", NULL }, /* minute overflow */ - { "Wed, 21 Oct 2015 07:28:00CEST", NULL }, /* missing space */ - { "Wed, 21 Oct 2015 07:28:000 GM", NULL }, /* overlong second */ - { "Wed, 21 Oct 2015 07:28:xx GMT", NULL }, /* missing second */ - { "Wed, 21 Oct 2015 07:28:-1 GMT", NULL }, /* seconds underflow */ - { "Wed, 21 Oct 2015 07:28:61 GMT", NULL }, /* seconds overflow */ - { "Wed, 21 Oct 2015 07:28:00 UTC", NULL }, /* invalid timezone (only GMT is allowed) */ - { "Thu, 01 Jan 1970 00:00:00 GMT", "1970-01-01T00:00:00Z" }, /* extreme but valid date */ - { "Mon, 31 Dec 9999 23:59:59 GMT", "9999-12-31T23:59:59Z" }, /* extreme but valid date */ - }; + { + const char *rfc2616; + const char *expected_iso8601; /* (nullable) if parsing is expected to fail */ + } tests[] = { + { "Wed, 21 Oct 2015 07:28:00 GMT", "2015-10-21T07:28:00Z" }, + { "Wed, 21 Oct 2015 07:28:00", NULL }, /* too short */ + { "Wed, 21 Oct 2015 07:28:00 CEST", NULL }, /* too long; not GMT */ + { "Cat, 21 Oct 2015 07:28:00 GMT", NULL }, /* invalid day */ + { "Wed 21 Oct 2015 07:28:00 GMT", NULL }, /* no comma */ + { "Wed,21 Oct 2015 07:28:00 GMT ", NULL }, /* missing space */ + { "Wed, xx Oct 2015 07:28:00 GMT", NULL }, /* no day-of-month */ + { "Wed, 011Oct 2015 07:28:00 GMT", NULL }, /* overlong day-of-month */ + { "Wed, 00 Oct 2015 07:28:00 GMT", NULL }, /* day-of-month underflow */ + { "Wed, 32 Oct 2015 07:28:00 GMT", NULL }, /* day-of-month overflow */ + { "Wed, 21,Oct 2015 07:28:00 GMT", NULL }, /* missing space */ + { "Wed, 21 Cat 2015 07:28:00 GMT", NULL }, /* invalid month */ + { "Wed, 21 Oct,2015 07:28:00 GMT", NULL }, /* missing space */ + { "Wed, 21 Oct xxxx 07:28:00 GMT", NULL }, /* no year */ + { "Wed, 21 Oct 0201507:28:00 GMT", NULL }, /* overlong year */ + { "Wed, 21 Oct 0000 07:28:00 GMT", NULL }, /* year underflow */ + { "Wed, 21 Oct 10000 07:28:00 GM", NULL }, /* year overflow */ + { "Wed, 21 Oct 2015,07:28:00 GMT", NULL }, /* missing space */ + { "Wed, 21 Oct 2015 07 28:00 GMT", NULL }, /* missing colon */ + { "Wed, 21 Oct 2015 007:28:00 GM", NULL }, /* overlong hour */ + { "Wed, 21 Oct 2015 xx:28:00 GMT", NULL }, /* missing hour */ + { "Wed, 21 Oct 2015 -1:28:00 GMT", NULL }, /* hour underflow */ + { "Wed, 21 Oct 2015 24:28:00 GMT", NULL }, /* hour overflow */ + { "Wed, 21 Oct 2015 07:28 00 GMT", NULL }, /* missing colon */ + { "Wed, 21 Oct 2015 07:028:00 GM", NULL }, /* overlong minute */ + { "Wed, 21 Oct 2015 07:xx:00 GMT", NULL }, /* missing minute */ + { "Wed, 21 Oct 2015 07:-1:00 GMT", NULL }, /* minute underflow */ + { "Wed, 21 Oct 2015 07:60:00 GMT", NULL }, /* minute overflow */ + { "Wed, 21 Oct 2015 07:28:00CEST", NULL }, /* missing space */ + { "Wed, 21 Oct 2015 07:28:000 GM", NULL }, /* overlong second */ + { "Wed, 21 Oct 2015 07:28:xx GMT", NULL }, /* missing second */ + { "Wed, 21 Oct 2015 07:28:-1 GMT", NULL }, /* seconds underflow */ + { "Wed, 21 Oct 2015 07:28:61 GMT", NULL }, /* seconds overflow */ + { "Wed, 21 Oct 2015 07:28:00 UTC", NULL }, /* invalid timezone (only GMT is allowed) */ + { "Thu, 01 Jan 1970 00:00:00 GMT", "1970-01-01T00:00:00Z" }, /* extreme but valid date */ + { "Mon, 31 Dec 9999 23:59:59 GMT", "9999-12-31T23:59:59Z" }, /* extreme but valid date */ + }; for (gsize i = 0; i < G_N_ELEMENTS (tests); i++) { g_test_message ("Test %" G_GSIZE_FORMAT ": %s", i, tests[i].rfc2616); /* Parse once with a trailing nul */ - g_autoptr(GDateTime) dt1 = _ostree_parse_rfc2616_date_time (tests[i].rfc2616, strlen (tests[i].rfc2616)); + g_autoptr (GDateTime) dt1 + = _ostree_parse_rfc2616_date_time (tests[i].rfc2616, strlen (tests[i].rfc2616)); if (tests[i].expected_iso8601 == NULL) g_assert_null (dt1); else @@ -94,7 +93,8 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS /* And parse again with no trailing nul */ g_autofree char *rfc2616_no_nul = g_malloc (strlen (tests[i].rfc2616)); memcpy (rfc2616_no_nul, tests[i].rfc2616, strlen (tests[i].rfc2616)); - g_autoptr(GDateTime) dt2 = _ostree_parse_rfc2616_date_time (rfc2616_no_nul, strlen (tests[i].rfc2616)); + g_autoptr (GDateTime) dt2 + = _ostree_parse_rfc2616_date_time (rfc2616_no_nul, strlen (tests[i].rfc2616)); if (tests[i].expected_iso8601 == NULL) g_assert_null (dt2); else @@ -104,7 +104,7 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS g_assert_cmpstr (iso8601, ==, tests[i].expected_iso8601); } } -G_GNUC_END_IGNORE_DEPRECATIONS + G_GNUC_END_IGNORE_DEPRECATIONS #else /* GLib 2.62 is needed for g_date_time_format_iso8601(). */ g_test_skip ("RFC 2616 date parsing test needs GLib ≥ 2.62.0"); @@ -112,8 +112,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS } int -main (int argc, - char **argv) +main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); g_test_add_func ("/ostree_parse_rfc2616_date_time", test_ostree_parse_rfc2616_date_time); diff --git a/tests/test-rollsum-cli.c b/tests/test-rollsum-cli.c index 2cf730d3..f906e991 100644 --- a/tests/test-rollsum-cli.c +++ b/tests/test-rollsum-cli.c @@ -26,7 +26,7 @@ int main (int argc, char **argv) { - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; GBytes *from_bytes = NULL; GBytes *to_bytes = NULL; @@ -57,12 +57,10 @@ main (int argc, char **argv) matches = _ostree_compute_rollsum_matches (from_bytes, to_bytes); - g_printerr ("rollsum crcs=%u bufs=%u total=%u matchsize=%llu\n", - matches->crcmatches, - matches->bufmatches, - matches->total, (unsigned long long)matches->match_size); + g_printerr ("rollsum crcs=%u bufs=%u total=%u matchsize=%llu\n", matches->crcmatches, + matches->bufmatches, matches->total, (unsigned long long)matches->match_size); - out: +out: if (local_error) { g_printerr ("%s\n", local_error->message); diff --git a/tests/test-rollsum.c b/tests/test-rollsum.c index 57f7aa06..a454e626 100644 --- a/tests/test-rollsum.c +++ b/tests/test-rollsum.c @@ -19,22 +19,23 @@ #include "config.h" -#include "libglnx.h" #include "bsdiff/bsdiff.h" #include "bsdiff/bspatch.h" +#include "bupsplit.h" +#include "libglnx.h" +#include "ostree-rollsum.h" +#include #include #include -#include #include -#include "ostree-rollsum.h" -#include "bupsplit.h" static void -test_rollsum_helper (const unsigned char *a, gsize size_a, const unsigned char *b, gsize size_b, gboolean expected_match) +test_rollsum_helper (const unsigned char *a, gsize size_a, const unsigned char *b, gsize size_b, + gboolean expected_match) { gsize i; - g_autoptr(GBytes) bytes_a = g_bytes_new_static (a, size_a); - g_autoptr(GBytes) bytes_b = g_bytes_new_static (b, size_b); + g_autoptr (GBytes) bytes_a = g_bytes_new_static (a, size_a); + g_autoptr (GBytes) bytes_b = g_bytes_new_static (b, size_b); OstreeRollsumMatches *matches; GPtrArray *matchlist; guint64 sum_matched = 0; @@ -75,16 +76,34 @@ test_rollsum (void) int len; g_autofree unsigned char *a = g_malloc (MAX_BUFFER_SIZE); g_autofree unsigned char *b = g_malloc (MAX_BUFFER_SIZE); - g_autoptr(GRand) rand = g_rand_new (); + g_autoptr (GRand) rand = g_rand_new (); /* These two buffers produce the same crc32. */ - const unsigned char conflicting_a[] = {0x35, 0x9b, 0x94, 0x5a, 0xa0, 0x5a, 0x34, 0xdc, 0x5c, 0x3, 0x46, 0xe, 0x34, 0x53, 0x85, 0x73, 0x64, 0xcc, 0x47, 0x10, 0x23, 0x8e, 0x7e, 0x6a, 0xca, 0xda, 0x7c, 0x12, 0x8a, 0x59, 0x7f, 0x7f, 0x4d, 0x1, 0xd8, 0xcc, 0x81, 0xcf, 0x2c, 0x7f, 0x10, 0xc2, 0xb4, 0x40, 0x1f, 0x2a, 0x0, 0x37, 0x85, 0xde, 0xfe, 0xa5, 0xc, 0x7c, 0xa1, 0x8, 0xd6, 0x75, 0xfd, 0x2, 0xcf, 0x2d, 0x53, 0x1b, 0x8a, 0x6b, 0x35, 0xad, 0xa, 0x8f, 0xad, 0x2d, 0x91, 0x87, 0x2b, 0x97, 0xcf, 0x1d, 0x7c, 0x61, 0xc4, 0xb2, 0x5e, 0xc3, 0xba, 0x5d, 0x2f, 0x3a, 0xeb, 0x41, 0x61, 0x4c, 0xa2, 0x34, 0xd, 0x43, 0xce, 0x10, 0xa3, 0x47, 0x4, 0xa0, 0x39, 0x77, 0xc2, 0xe8, 0x36, 0x1d, 0x87, 0xd1, 0x8f, 0x4d, 0x13, 0xa1, 0x34, 0xc3, 0x2c, 0xee, 0x1a, 0x10, 0x79, 0xb7, 0x97, 0x29, 0xe8, 0xf0, 0x5, 0xfc, 0xe6, 0x14, 0x87, 0x9c, 0x8f, 0x97, 0x23, 0xac, 0x1, 0xf2, 0xee, 0x69, 0xb2, 0xe5}; - - const unsigned char conflicting_b[] = {0xb2, 0x54, 0x81, 0x7d, 0x31, 0x83, 0xc7, 0xc, 0xcf, 0x7d, 0x90, 0x1c, 0x6b, 0xf6, 0x4e, 0xff, 0x49, 0xd1, 0xb6, 0xc, 0x9e, 0x85, 0xe3, 0x2d, 0xdb, 0x94, 0x8e, 0x1a, 0x17, 0x3f, 0x63, 0x59, 0xf9, 0x4b, 0x5f, 0x47, 0x97, 0x9c, 0x1c, 0xd7, 0x24, 0xd9, 0x42, 0x6, 0x1e, 0xf, 0x98, 0x10, 0xb4, 0xc, 0x50, 0xcb, 0xc5, 0x62, 0x53, 0x1, 0xd1, 0x5f, 0x16, 0x97, 0xaa, 0xd7, 0x57, 0x5e, 0xf2, 0xde, 0xae, 0x53, 0x58, 0x6, 0xb7, 0x9b, 0x8d, 0x2b, 0xd6, 0xb4, 0x55, 0x29, 0x3b, 0x27, 0x70, 0xd5, 0xf3, 0x8d, 0xdc, 0xad, 0x68, 0x63, 0xa5, 0x72, 0xce, 0x6b, 0x9, 0x2b, 0x60, 0x1b, 0x99, 0xd7, 0x86}; + const unsigned char conflicting_a[] + = { 0x35, 0x9b, 0x94, 0x5a, 0xa0, 0x5a, 0x34, 0xdc, 0x5c, 0x3, 0x46, 0xe, 0x34, 0x53, 0x85, + 0x73, 0x64, 0xcc, 0x47, 0x10, 0x23, 0x8e, 0x7e, 0x6a, 0xca, 0xda, 0x7c, 0x12, 0x8a, 0x59, + 0x7f, 0x7f, 0x4d, 0x1, 0xd8, 0xcc, 0x81, 0xcf, 0x2c, 0x7f, 0x10, 0xc2, 0xb4, 0x40, 0x1f, + 0x2a, 0x0, 0x37, 0x85, 0xde, 0xfe, 0xa5, 0xc, 0x7c, 0xa1, 0x8, 0xd6, 0x75, 0xfd, 0x2, + 0xcf, 0x2d, 0x53, 0x1b, 0x8a, 0x6b, 0x35, 0xad, 0xa, 0x8f, 0xad, 0x2d, 0x91, 0x87, 0x2b, + 0x97, 0xcf, 0x1d, 0x7c, 0x61, 0xc4, 0xb2, 0x5e, 0xc3, 0xba, 0x5d, 0x2f, 0x3a, 0xeb, 0x41, + 0x61, 0x4c, 0xa2, 0x34, 0xd, 0x43, 0xce, 0x10, 0xa3, 0x47, 0x4, 0xa0, 0x39, 0x77, 0xc2, + 0xe8, 0x36, 0x1d, 0x87, 0xd1, 0x8f, 0x4d, 0x13, 0xa1, 0x34, 0xc3, 0x2c, 0xee, 0x1a, 0x10, + 0x79, 0xb7, 0x97, 0x29, 0xe8, 0xf0, 0x5, 0xfc, 0xe6, 0x14, 0x87, 0x9c, 0x8f, 0x97, 0x23, + 0xac, 0x1, 0xf2, 0xee, 0x69, 0xb2, 0xe5 }; + + const unsigned char conflicting_b[] + = { 0xb2, 0x54, 0x81, 0x7d, 0x31, 0x83, 0xc7, 0xc, 0xcf, 0x7d, 0x90, 0x1c, 0x6b, 0xf6, 0x4e, + 0xff, 0x49, 0xd1, 0xb6, 0xc, 0x9e, 0x85, 0xe3, 0x2d, 0xdb, 0x94, 0x8e, 0x1a, 0x17, 0x3f, + 0x63, 0x59, 0xf9, 0x4b, 0x5f, 0x47, 0x97, 0x9c, 0x1c, 0xd7, 0x24, 0xd9, 0x42, 0x6, 0x1e, + 0xf, 0x98, 0x10, 0xb4, 0xc, 0x50, 0xcb, 0xc5, 0x62, 0x53, 0x1, 0xd1, 0x5f, 0x16, 0x97, + 0xaa, 0xd7, 0x57, 0x5e, 0xf2, 0xde, 0xae, 0x53, 0x58, 0x6, 0xb7, 0x9b, 0x8d, 0x2b, 0xd6, + 0xb4, 0x55, 0x29, 0x3b, 0x27, 0x70, 0xd5, 0xf3, 0x8d, 0xdc, 0xad, 0x68, 0x63, 0xa5, 0x72, + 0xce, 0x6b, 0x9, 0x2b, 0x60, 0x1b, 0x99, 0xd7, 0x86 }; + + test_rollsum_helper (conflicting_a, sizeof conflicting_a, conflicting_b, sizeof conflicting_b, + FALSE); - test_rollsum_helper (conflicting_a, sizeof conflicting_a, conflicting_b, sizeof conflicting_b, FALSE); - - for (i = 0; i < MAX_BUFFER_SIZE; i++) + for (i = 0; i < MAX_BUFFER_SIZE; i++) { a[i] = g_rand_int (rand); b[i] = a[i]; @@ -139,32 +158,33 @@ test_rollsum (void) #define BUP_SELFTEST_SIZE 100000 static void -test_bupsplit_sum(void) +test_bupsplit_sum (void) { - g_autofree uint8_t *buf = g_malloc (BUP_SELFTEST_SIZE); - uint32_t sum1a, sum1b, sum2a, sum2b, sum3a, sum3b; - unsigned count; - - for (count = 0; count < BUP_SELFTEST_SIZE; count++) - buf[count] = g_random_int_range (0, 256); - - sum1a = bupsplit_sum(buf, 0, BUP_SELFTEST_SIZE); - sum1b = bupsplit_sum(buf, 1, BUP_SELFTEST_SIZE); - sum2a = bupsplit_sum(buf, BUP_SELFTEST_SIZE - BUP_WINDOWSIZE*5/2, - BUP_SELFTEST_SIZE - BUP_WINDOWSIZE); - sum2b = bupsplit_sum(buf, 0, BUP_SELFTEST_SIZE - BUP_WINDOWSIZE); - sum3a = bupsplit_sum(buf, 0, BUP_WINDOWSIZE+3); - sum3b = bupsplit_sum(buf, 3, BUP_WINDOWSIZE+3); - - g_assert_cmpint (sum1a, ==, sum1b); - g_assert_cmpint (sum2a, ==, sum2b); - g_assert_cmpint (sum3a, ==, sum3b); + g_autofree uint8_t *buf = g_malloc (BUP_SELFTEST_SIZE); + uint32_t sum1a, sum1b, sum2a, sum2b, sum3a, sum3b; + unsigned count; + + for (count = 0; count < BUP_SELFTEST_SIZE; count++) + buf[count] = g_random_int_range (0, 256); + + sum1a = bupsplit_sum (buf, 0, BUP_SELFTEST_SIZE); + sum1b = bupsplit_sum (buf, 1, BUP_SELFTEST_SIZE); + sum2a = bupsplit_sum (buf, BUP_SELFTEST_SIZE - BUP_WINDOWSIZE * 5 / 2, + BUP_SELFTEST_SIZE - BUP_WINDOWSIZE); + sum2b = bupsplit_sum (buf, 0, BUP_SELFTEST_SIZE - BUP_WINDOWSIZE); + sum3a = bupsplit_sum (buf, 0, BUP_WINDOWSIZE + 3); + sum3b = bupsplit_sum (buf, 3, BUP_WINDOWSIZE + 3); + + g_assert_cmpint (sum1a, ==, sum1b); + g_assert_cmpint (sum2a, ==, sum2b); + g_assert_cmpint (sum3a, ==, sum3b); } -int main (int argc, char **argv) +int +main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); g_test_add_func ("/rollsum", test_rollsum); g_test_add_func ("/bupsum", test_bupsplit_sum); - return g_test_run(); + return g_test_run (); } diff --git a/tests/test-sysroot-c.c b/tests/test-sysroot-c.c index 82b4b1bf..34e86162 100644 --- a/tests/test-sysroot-c.c +++ b/tests/test-sysroot-c.c @@ -19,8 +19,8 @@ #include "config.h" -#include #include +#include #include #include "libglnx.h" @@ -40,8 +40,8 @@ run_sync (const char *cmdline, GError **error) static void test_sysroot_reload (gconstpointer data) { - OstreeSysroot *sysroot = (void*)data; - g_autoptr(GError) error = NULL; + OstreeSysroot *sysroot = (void *)data; + g_autoptr (GError) error = NULL; gboolean changed; if (!ostree_sysroot_load (sysroot, NULL, &error)) @@ -51,10 +51,14 @@ test_sysroot_reload (gconstpointer data) goto out; g_assert (!changed); - if (!run_sync ("ostree --repo=sysroot/ostree/repo pull-local --remote=testos testos-repo testos/buildmain/x86_64-runtime", &error)) + if (!run_sync ("ostree --repo=sysroot/ostree/repo pull-local --remote=testos testos-repo " + "testos/buildmain/x86_64-runtime", + &error)) goto out; - if (!run_sync ("ostree admin --sysroot=sysroot deploy --karg=root=LABEL=MOO --karg=quiet --os=testos testos:testos/buildmain/x86_64-runtime", &error)) + if (!run_sync ("ostree admin --sysroot=sysroot deploy --karg=root=LABEL=MOO --karg=quiet " + "--os=testos testos:testos/buildmain/x86_64-runtime", + &error)) goto out; if (!ostree_sysroot_load_if_changed (sysroot, &changed, NULL, &error)) @@ -65,14 +69,15 @@ test_sysroot_reload (gconstpointer data) goto out; g_assert (!changed); - out: +out: if (error) g_error ("%s", error->message); } -int main (int argc, char **argv) +int +main (int argc, char **argv) { - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; glnx_unref_object OstreeSysroot *sysroot = NULL; g_test_init (&argc, &argv, NULL); @@ -83,8 +88,8 @@ int main (int argc, char **argv) g_test_add_data_func ("/sysroot-reload", sysroot, test_sysroot_reload); - return g_test_run(); - out: + return g_test_run (); +out: if (error) g_error ("%s", error->message); return 1; diff --git a/tests/test-varint.c b/tests/test-varint.c index 3fea805e..9c42f64e 100644 --- a/tests/test-varint.c +++ b/tests/test-varint.c @@ -24,20 +24,21 @@ #include "ostree-varint.h" static void -check_one_roundtrip (guint64 val) +check_one_roundtrip (guint64 val) { - g_autoptr(GString) buf = g_string_new (NULL); + g_autoptr (GString) buf = g_string_new (NULL); guint64 newval; gsize bytes_read; _ostree_write_varuint64 (buf, val); if (g_test_verbose ()) { - g_autoptr(GVariant) v = g_variant_new_from_data (G_VARIANT_TYPE ("ay"), buf->str, buf->len, TRUE, NULL, NULL); + g_autoptr (GVariant) v + = g_variant_new_from_data (G_VARIANT_TYPE ("ay"), buf->str, buf->len, TRUE, NULL, NULL); g_autofree char *data = g_variant_print (v, FALSE); g_test_message ("%" G_GUINT64_FORMAT " -> %s", val, data); } - g_assert (_ostree_read_varuint64 ((guint8*)buf->str, buf->len, &newval, &bytes_read)); + g_assert (_ostree_read_varuint64 ((guint8 *)buf->str, buf->len, &newval, &bytes_read)); g_assert_cmpint (bytes_read, <=, 10); g_assert_cmpint (val, ==, newval); } @@ -45,9 +46,17 @@ check_one_roundtrip (guint64 val) static void test_roundtrips (void) { - const guint64 test_inputs[] = { 0, 1, 0x6F, 0xA0, 0xFF, 0xF0F0, 0xCAFE, - 0xCAFEBABE, G_MAXUINT64, G_MAXUINT64-1, - G_MAXUINT64 / 2}; + const guint64 test_inputs[] = { 0, + 1, + 0x6F, + 0xA0, + 0xFF, + 0xF0F0, + 0xCAFE, + 0xCAFEBABE, + G_MAXUINT64, + G_MAXUINT64 - 1, + G_MAXUINT64 / 2 }; guint i; for (i = 0; i < G_N_ELEMENTS (test_inputs); i++) -- cgit v1.2.1 From c1044a02b28982ef6dd58af98b23a40482d26487 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 1 May 2023 14:24:23 -0400 Subject: ci: Validate clang-format --- ci/codestyle.sh | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/ci/codestyle.sh b/ci/codestyle.sh index 850661e5..1db6c1f8 100755 --- a/ci/codestyle.sh +++ b/ci/codestyle.sh @@ -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) -- cgit v1.2.1