From 387db0c820a2fbd4b0132f4f3cea2447bb4bc39d Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 5 Apr 2021 20:15:54 +0000 Subject: [PATCH] Require ostree v2021.2, use ostree-ext crate This uses the ostree and ostree-ext crates from git as a demo/WIP for https://mail.gnome.org/archives/ostree-list/2021-April/msg00000.html --- Cargo.lock | 153 ++++++++++++++++++++-- Cargo.toml | 4 +- configure.ac | 2 +- rust/ostree-host/Cargo.toml | 21 --- rust/ostree-host/LICENSE-APACHE | 176 ------------------------- rust/ostree-host/LICENSE-MIT | 23 ---- rust/ostree-host/README.md | 31 ----- rust/ostree-host/src/binding_fixes.rs | 77 ----------- rust/ostree-host/src/lib.rs | 18 --- rust/ostree-host/src/sysroot_ext.rs | 17 --- rust/src/builtins/apply_live.rs | 1 - rust/src/lib.rs | 1 - rust/src/live.rs | 18 +-- rust/src/ostree_diff.rs | 182 -------------------------- rust/src/treefile.rs | 2 +- 15 files changed, 154 insertions(+), 572 deletions(-) delete mode 100644 rust/ostree-host/Cargo.toml delete mode 100644 rust/ostree-host/LICENSE-APACHE delete mode 100644 rust/ostree-host/LICENSE-MIT delete mode 100644 rust/ostree-host/README.md delete mode 100644 rust/ostree-host/src/binding_fixes.rs delete mode 100644 rust/ostree-host/src/lib.rs delete mode 100644 rust/ostree-host/src/sysroot_ext.rs delete mode 100644 rust/src/ostree_diff.rs diff --git a/Cargo.lock b/Cargo.lock index f5332800..1edd46e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -65,6 +65,12 @@ dependencies = [ "version_check 0.1.5", ] +[[package]] +name = "camino" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4648c6d00a709aa069a236adcaae4f605a6241c72bf5bee79331a4b625921a9" + [[package]] name = "cc" version = "1.0.66" @@ -327,6 +333,18 @@ dependencies = [ "thiserror", ] +[[package]] +name = "filetime" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d34cfa13a63ae058bfa601fe9e313bbdb3746427c1459185464ce0fcf62e1e8" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall", + "winapi", +] + [[package]] name = "fn-error-context" version = "0.1.2" @@ -338,6 +356,15 @@ dependencies = [ "syn", ] +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared 0.1.1", +] + [[package]] name = "foreign-types" version = "0.5.0" @@ -345,7 +372,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" dependencies = [ "foreign-types-macros", - "foreign-types-shared", + "foreign-types-shared 0.3.0", ] [[package]] @@ -359,6 +386,12 @@ dependencies = [ "syn", ] +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "foreign-types-shared" version = "0.3.0" @@ -572,6 +605,26 @@ dependencies = [ "system-deps 1.3.2", ] +[[package]] +name = "gvariant" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f7a982b6b38ff2380ea1b1b480cb7f5b51dac917aceff2e16af0c207781e13a" +dependencies = [ + "gvariant-macro", + "memchr", + "ref-cast", +] + +[[package]] +name = "gvariant-macro" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9915719ccd7435a28103eea8dba78bcf35a25d5637c70273b47dbb49c6d2eb6d" +dependencies = [ + "syn", +] + [[package]] name = "hashbrown" version = "0.9.1" @@ -601,9 +654,9 @@ dependencies = [ [[package]] name = "hex" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "indicatif" @@ -837,6 +890,20 @@ dependencies = [ "rand 0.7.3", ] +[[package]] +name = "openssl" +version = "0.10.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a61075b62a23fef5a29815de7536d940aa35ce96d18ce0cc5076272db678a577" +dependencies = [ + "bitflags", + "cfg-if 1.0.0", + "foreign-types 0.3.2", + "libc", + "once_cell", + "openssl-sys", +] + [[package]] name = "openssl-probe" version = "0.1.2" @@ -845,9 +912,9 @@ checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" [[package]] name = "openssl-sys" -version = "0.9.60" +version = "0.9.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "921fc71883267538946025deffb622905ecad223c28efbfdef9bb59a0175f3e6" +checksum = "313752393519e876837e09e1fa183ddef0be7735868dced3196f4472d536277f" dependencies = [ "autocfg", "cc", @@ -876,10 +943,20 @@ dependencies = [ ] [[package]] -name = "ostree" -version = "0.9.1" +name = "os_pipe" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5d5597fdcbd16285ef7ce0eaa91eb7c0f51514846f107fd5f68164f28006dc7" +checksum = "fb233f06c2307e1f5ce2ecad9f8121cffbbee2c95428f44ea85222e460d0d213" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "ostree" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c424e3b6d40b39383b07e39b4e7972738a9250080e0cb416967023e565ebb1" dependencies = [ "bitflags", "gio", @@ -896,15 +973,27 @@ dependencies = [ ] [[package]] -name = "ostree-host" +name = "ostree-ext" version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d725db675a186b805818e8475171a17bc7ee7731ef55bdde19d0193481b09dc" dependencies = [ "anyhow", + "camino", + "fn-error-context", "gio", "glib", + "glib-sys", + "gvariant", + "hex", + "libc", + "openat", + "openat-ext", + "openssl", + "os_pipe", "ostree", "ostree-sys", - "tempfile", + "tar", ] [[package]] @@ -1192,6 +1281,26 @@ dependencies = [ "bitflags", ] +[[package]] +name = "ref-cast" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300f2a835d808734ee295d45007adacb9ebb29dd3ae2424acfa17930cae541da" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c38e3aecd2b21cb3959637b883bb3714bc7e43f0268b9a29d3743ee3e55cdd2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "regex" version = "1.4.3" @@ -1255,7 +1364,7 @@ dependencies = [ "openat-ext", "os-release", "ostree", - "ostree-host", + "ostree-ext", "ostree-sys", "paste", "phf", @@ -1510,7 +1619,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f722cabda922e471742300045f56dbaa53fafbb4520fca304e51258019bfe91d" dependencies = [ "cstr-argument", - "foreign-types", + "foreign-types 0.5.0", "libc", "libsystemd-sys", "log", @@ -1518,6 +1627,17 @@ dependencies = [ "utf8-cstr", ] +[[package]] +name = "tar" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0bcfbd6a598361fda270d82469fff3d65089dc33e175c9a131f7b4cd395f228" +dependencies = [ + "filetime", + "libc", + "xattr", +] + [[package]] name = "tempfile" version = "3.2.0" @@ -1709,6 +1829,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "xattr" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "244c3741f4240ef46274860397c7c74e50eb23624996930e484c16679633a54c" +dependencies = [ + "libc", +] + [[package]] name = "yaml-rust" version = "0.4.5" diff --git a/Cargo.toml b/Cargo.toml index e80f1d42..e88bc2bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,9 +49,9 @@ nix = "0.20.0" openat = "0.1.21" openat-ext = "^0.2.0" os-release = "0.1.0" -ostree = { version = "0.9.1", features = ["v2020_4"] } +ostree = { version = "0.11.0", features = ["v2021_1"] } ostree-sys = "0.7.3" -ostree-host = { path = "rust/ostree-host" } +ostree-ext = "0.1.0" paste = "1.0" phf = { version = "0.8", features = ["macros"] } rand = "0.8.3" diff --git a/configure.ac b/configure.ac index 1b22c7d2..fa900a85 100644 --- a/configure.ac +++ b/configure.ac @@ -45,7 +45,7 @@ PKG_PROG_PKG_CONFIG dnl Remember to update AM_CPPFLAGS in Makefile.am when bumping GIO req. PKG_CHECK_MODULES(PKGDEP_GIO_UNIX, [gio-unix-2.0]) dnl These are the dependencies of the public librpmostree-1.0.0 shared library -PKG_CHECK_MODULES(PKGDEP_LIBRPMOSTREE, [gio-unix-2.0 >= 2.50.0 json-glib-1.0 ostree-1 >= 2020.7 rpm]) +PKG_CHECK_MODULES(PKGDEP_LIBRPMOSTREE, [gio-unix-2.0 >= 2.50.0 json-glib-1.0 ostree-1 >= 2021.2 rpm]) dnl And these additional ones are used by for the rpmostreeinternals C/C++ library PKG_CHECK_MODULES(PKGDEP_RPMOSTREE, [polkit-gobject-1 libarchive]) diff --git a/rust/ostree-host/Cargo.toml b/rust/ostree-host/Cargo.toml deleted file mode 100644 index 012a66e5..00000000 --- a/rust/ostree-host/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "ostree-host" -version = "0.1.0" -authors = ["Colin Walters "] -edition = "2018" -license = "MIT OR Apache-2.0" -#rust = "1.48" - -[dependencies] -gio = "0.9.1" -glib = "0.10.3" -ostree = { version = "0.9.1", features = ["v2020_4"] } -ostree-sys = "0.7.3" - -[dev-dependencies] -anyhow = "1.0" -tempfile = "3.2.0" - -[lib] -name = "ostree_host" -path = "src/lib.rs" diff --git a/rust/ostree-host/LICENSE-APACHE b/rust/ostree-host/LICENSE-APACHE deleted file mode 100644 index 1b5ec8b7..00000000 --- a/rust/ostree-host/LICENSE-APACHE +++ /dev/null @@ -1,176 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS diff --git a/rust/ostree-host/LICENSE-MIT b/rust/ostree-host/LICENSE-MIT deleted file mode 100644 index 31aa7938..00000000 --- a/rust/ostree-host/LICENSE-MIT +++ /dev/null @@ -1,23 +0,0 @@ -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/rust/ostree-host/README.md b/rust/ostree-host/README.md deleted file mode 100644 index 52ff6bcf..00000000 --- a/rust/ostree-host/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# Extended OSTree APIs for host systems - -The OSTree project upstream will continue to be written -in C for the near future. The goal of this project -is to contain new Rust APIs that extend the "ostree-based host system" -case. In other words, some new OSTree functionality may be Rust only. - -At this time, this project only contains: - - - Extension traits for `ostree::Repo` and `ostree::Sysroot` that - have a few methods prefixed with `x_` that fix incorrect bindings. - - An extension trait for `ostree::Sysroot` that adds small new - API. - -In the future though, more complex functionality may live here -such as the model for `apply-live` changes. - -## License - -Licensed under either of - - * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) - * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) - -at your option. - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted -for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any -additional terms or conditions. diff --git a/rust/ostree-host/src/binding_fixes.rs b/rust/ostree-host/src/binding_fixes.rs deleted file mode 100644 index 07bdf8a5..00000000 --- a/rust/ostree-host/src/binding_fixes.rs +++ /dev/null @@ -1,77 +0,0 @@ -//! Extension traits fixing incorrectly bound things in ostree-rs -//! by defining a new function with an `x_` prefix. - -// SPDX-License-Identifier: Apache-2.0 OR MIT - -use glib::translate::*; -use std::ptr; - -/// Extension functions which fix incorrectly bound APIs. -pub trait RepoBindingExt { - fn x_resolve_ref_optional(&self, refspec: &str) -> Result, glib::Error>; -} - -impl RepoBindingExt for ostree::Repo { - fn x_resolve_ref_optional(&self, refspec: &str) -> Result, glib::Error> { - unsafe { - let mut out_rev = ptr::null_mut(); - let mut error = ptr::null_mut(); - let refspec = refspec.to_glib_none(); - let _ = ostree_sys::ostree_repo_resolve_rev( - self.to_glib_none().0, - refspec.0, - true.to_glib(), - &mut out_rev, - &mut error, - ); - if error.is_null() { - Ok(from_glib_full(out_rev)) - } else { - Err(from_glib_full(error)) - } - } - } -} - -/// Extension functions which fix incorectly bound APIs -pub trait SysrootBindingExt { - fn x_query_deployments_for( - &self, - osname: &str, - ) -> (Option, Option); -} - -impl SysrootBindingExt for ostree::Sysroot { - fn x_query_deployments_for( - &self, - osname: &str, - ) -> (Option, Option) { - unsafe { - let mut out_pending = ptr::null_mut(); - let mut out_rollback = ptr::null_mut(); - ostree_sys::ostree_sysroot_query_deployments_for( - self.to_glib_none().0, - osname.to_glib_none().0, - &mut out_pending, - &mut out_rollback, - ); - (from_glib_full(out_pending), from_glib_full(out_rollback)) - } - } -} - -#[cfg(test)] -mod test { - use super::*; - use anyhow::Result; - - #[test] - fn optional_ref() -> Result<()> { - let cancellable = gio::NONE_CANCELLABLE; - let td = tempfile::tempdir()?; - let r = ostree::Repo::new_for_path(td.path()); - r.create(ostree::RepoMode::Archive, cancellable)?; - assert!(r.x_resolve_ref_optional("someref")?.is_none()); - Ok(()) - } -} diff --git a/rust/ostree-host/src/lib.rs b/rust/ostree-host/src/lib.rs deleted file mode 100644 index f01332ed..00000000 --- a/rust/ostree-host/src/lib.rs +++ /dev/null @@ -1,18 +0,0 @@ -//! Helper APIs for interacting with ostree-based operating systems. - -// SPDX-License-Identifier: Apache-2.0 OR MIT - -#![deny(unused_must_use)] - -mod binding_fixes; -pub use binding_fixes::*; -mod sysroot_ext; -pub use sysroot_ext::*; - -/// This prelude currently just adds extension traits to various OSTree objects, -/// and like all preludes is intended to be quite "safe" to import and will avoid -/// likely naming clashes. -pub mod prelude { - pub use super::binding_fixes::*; - pub use super::sysroot_ext::*; -} diff --git a/rust/ostree-host/src/sysroot_ext.rs b/rust/ostree-host/src/sysroot_ext.rs deleted file mode 100644 index 7828a98e..00000000 --- a/rust/ostree-host/src/sysroot_ext.rs +++ /dev/null @@ -1,17 +0,0 @@ -//! Extension traits that add new APIs. - -// SPDX-License-Identifier: Apache-2.0 OR MIT - -/// Extension APIs for `ostree::Sysroot` -pub trait SysrootExt { - /// Require a booted deployment; reimplements https://github.com/ostreedev/ostree/pull/2301 - fn require_booted_deployment(&self) -> Result; -} - -impl SysrootExt for ostree::Sysroot { - fn require_booted_deployment(&self) -> Result { - self.get_booted_deployment().ok_or_else(|| { - glib::Error::new(gio::IOErrorEnum::Failed, "Not booted into an OSTree system") - }) - } -} diff --git a/rust/src/builtins/apply_live.rs b/rust/src/builtins/apply_live.rs index c30e00f7..efa81a26 100644 --- a/rust/src/builtins/apply_live.rs +++ b/rust/src/builtins/apply_live.rs @@ -5,7 +5,6 @@ use crate::live; use crate::{cxxrsutil::*, variant_utils}; use anyhow::{anyhow, Result}; use gio::DBusProxyExt; -use ostree_host::prelude::*; use structopt::StructOpt; #[derive(Debug, StructOpt)] diff --git a/rust/src/lib.rs b/rust/src/lib.rs index fe015e63..4c562d06 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -505,7 +505,6 @@ mod nameservice; // we're ready to try porting the C++ code. #[cfg(test)] mod origin; -mod ostree_diff; mod passwd; use passwd::*; mod console_progress; diff --git a/rust/src/live.rs b/rust/src/live.rs index 038cb05e..07245d05 100644 --- a/rust/src/live.rs +++ b/rust/src/live.rs @@ -16,7 +16,7 @@ use fn_error_context::context; use nix::sys::statvfs; use openat_ext::OpenatDirExt; use ostree::DeploymentUnlockedState; -use ostree_host::prelude::*; +use ostree_ext::diff::FileTreeDiff; use rayon::prelude::*; use std::borrow::Cow; use std::os::unix::io::AsRawFd; @@ -63,8 +63,8 @@ pub(crate) fn get_live_state( if !root.exists(&get_runstate_dir(deploy).join(LIVE_STATE_NAME))? { return Ok(None); } - let live_commit = repo.x_resolve_ref_optional(LIVE_REF)?; - let inprogress_commit = repo.x_resolve_ref_optional(LIVE_REF_INPROGRESS)?; + let live_commit = repo.resolve_rev(LIVE_REF, true)?; + let inprogress_commit = repo.resolve_rev(LIVE_REF_INPROGRESS, true)?; Ok(Some(LiveApplyState { commit: live_commit.map(|s| s.to_string()).unwrap_or_default(), inprogress: inprogress_commit.map(|s| s.to_string()).unwrap_or_default(), @@ -110,7 +110,7 @@ fn relpath_dir(p: &Path) -> Result<&Path> { } /// Return a path buffer we can provide to libostree for checkout -fn subpath(diff: &crate::ostree_diff::FileTreeDiff, p: &Path) -> Option { +fn subpath(diff: &FileTreeDiff, p: &Path) -> Option { if let Some(ref d) = diff.subdir { let p = p.strip_prefix("/").expect("prefix"); Some(Path::new(d).join(p)) @@ -122,7 +122,7 @@ fn subpath(diff: &crate::ostree_diff::FileTreeDiff, p: &Path) -> Option /// Given a diff, apply it to the target directory, which should be a checkout of the source commit. fn apply_diff( repo: &ostree::Repo, - diff: &crate::ostree_diff::FileTreeDiff, + diff: &FileTreeDiff, commit: &str, destdir: &openat::Dir, ) -> Result<()> { @@ -192,7 +192,7 @@ fn apply_diff( /// push apply-live down into libostree, this logic could be shared. fn update_etc( repo: &ostree::Repo, - diff: &crate::ostree_diff::FileTreeDiff, + diff: &FileTreeDiff, config_diff: &crate::dirdiff::Diff, sepolicy: &ostree::SePolicy, commit: &str, @@ -353,7 +353,7 @@ pub(crate) fn transaction_apply_live( let target_commit = if let Some(t) = target { Cow::Borrowed(t) } else { - match sysroot.x_query_deployments_for(osname.as_str()) { + match sysroot.query_deployments_for(Some(osname.as_str())) { (Some(pending), _) => { let pending_commit = pending.get_csum().expect("csum"); let pending_commit = pending_commit.as_str(); @@ -419,7 +419,7 @@ pub(crate) fn transaction_apply_live( .filter(|s| !s.is_empty()) .unwrap_or(booted_commit); // Compute the filesystem-level diff - let diff = crate::ostree_diff::diff(repo, source_commit, &target_commit, Some("/usr"))?; + let diff = ostree_ext::diff::diff(repo, source_commit, &target_commit, Some("/usr"))?; // And then the package-level diff let pkgdiff = { cxx::let_cxx_string!(from = source_commit); @@ -525,7 +525,7 @@ mod test { #[test] fn test_subpath() { - let d = crate::ostree_diff::FileTreeDiff { + let d = FileTreeDiff { subdir: Some("/usr".to_string()), ..Default::default() }; diff --git a/rust/src/ostree_diff.rs b/rust/src/ostree_diff.rs deleted file mode 100644 index 6b1b22f7..00000000 --- a/rust/src/ostree_diff.rs +++ /dev/null @@ -1,182 +0,0 @@ -//! Compute the difference between two OSTree commits. - -/* - * Copyright (C) 2020 Red Hat, Inc. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - */ - -use anyhow::{Context, Result}; -use fn_error_context::context; -use gio::prelude::*; -use ostree::RepoFileExt; -use serde_derive::{Deserialize, Serialize}; -use std::collections::BTreeSet; -use std::fmt; - -/// Like `g_file_query_info()`, but return None if the target doesn't exist. -fn query_info_optional( - f: &gio::File, - queryattrs: &str, - queryflags: gio::FileQueryInfoFlags, -) -> Result> { - let cancellable = gio::NONE_CANCELLABLE; - match f.query_info(queryattrs, queryflags, cancellable) { - Ok(i) => Ok(Some(i)), - Err(e) => { - if let Some(ref e2) = e.kind::() { - match e2 { - gio::IOErrorEnum::NotFound => Ok(None), - _ => Err(e.into()), - } - } else { - Err(e.into()) - } - } - } -} - -pub(crate) type FileSet = BTreeSet; - -/// Diff between two ostree commits. -#[derive(Debug, Default, Serialize, Deserialize)] -pub(crate) struct FileTreeDiff { - /// The prefix passed for diffing, e.g. /usr - pub(crate) subdir: Option, - /// Files that are new in an existing directory - pub(crate) added_files: FileSet, - /// New directories - pub(crate) added_dirs: FileSet, - /// Files removed - pub(crate) removed_files: FileSet, - /// Directories removed (recursively) - pub(crate) removed_dirs: FileSet, - /// Files that changed (in any way, metadata or content) - pub(crate) changed_files: FileSet, - /// Directories that changed mode/permissions - pub(crate) changed_dirs: FileSet, -} - -impl fmt::Display for FileTreeDiff { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "files(added:{} removed:{} changed:{}) dirs(added:{} removed:{} changed:{})", - self.added_files.len(), - self.removed_files.len(), - self.changed_files.len(), - self.added_dirs.len(), - self.removed_dirs.len(), - self.changed_dirs.len() - ) - } -} - -fn diff_recurse( - prefix: &str, - diff: &mut FileTreeDiff, - from: &ostree::RepoFile, - to: &ostree::RepoFile, -) -> Result<()> { - let cancellable = gio::NONE_CANCELLABLE; - let queryattrs = "standard::name,standard::type"; - let queryflags = gio::FileQueryInfoFlags::NOFOLLOW_SYMLINKS; - let from_iter = from.enumerate_children(queryattrs, queryflags, cancellable)?; - - // Iterate over the source (from) directory, and compare with the - // target (to) directory. This generates removals and changes. - while let Some(from_info) = from_iter.next_file(cancellable)? { - let from_child = from_iter.get_child(&from_info).expect("file"); - let name = from_info.get_name().expect("name"); - let name = name.to_str().expect("UTF-8 ostree name"); - let path = format!("{}{}", prefix, name); - let to_child = to.get_child(&name).expect("child"); - let to_info = query_info_optional(&to_child, queryattrs, queryflags) - .context("querying optional to")?; - let is_dir = matches!(from_info.get_file_type(), gio::FileType::Directory); - if to_info.is_some() { - let to_child = to_child.downcast::().expect("downcast"); - to_child.ensure_resolved()?; - let from_child = from_child.downcast::().expect("downcast"); - from_child.ensure_resolved()?; - - if is_dir { - let from_contents_checksum = - from_child.tree_get_contents_checksum().expect("checksum"); - let to_contents_checksum = to_child.tree_get_contents_checksum().expect("checksum"); - if from_contents_checksum != to_contents_checksum { - let subpath = format!("{}/", path); - diff_recurse(&subpath, diff, &from_child, &to_child)?; - } - let from_meta_checksum = from_child.tree_get_metadata_checksum().expect("checksum"); - let to_meta_checksum = to_child.tree_get_metadata_checksum().expect("checksum"); - if from_meta_checksum != to_meta_checksum { - diff.changed_dirs.insert(path); - } - } else { - let from_checksum = from_child.get_checksum().expect("checksum"); - let to_checksum = to_child.get_checksum().expect("checksum"); - if from_checksum != to_checksum { - diff.changed_files.insert(path); - } - } - } else if is_dir { - diff.removed_dirs.insert(path); - } else { - diff.removed_files.insert(path); - } - } - // Iterate over the target (to) directory, and find any - // files/directories which were not present in the source. - let to_iter = to.enumerate_children(queryattrs, queryflags, cancellable)?; - while let Some(to_info) = to_iter.next_file(cancellable)? { - let name = to_info.get_name().expect("name"); - let name = name.to_str().expect("UTF-8 ostree name"); - let path = format!("{}{}", prefix, name); - let from_child = from.get_child(name).expect("child"); - let from_info = query_info_optional(&from_child, queryattrs, queryflags) - .context("querying optional from")?; - if from_info.is_some() { - continue; - } - let is_dir = matches!(to_info.get_file_type(), gio::FileType::Directory); - if is_dir { - diff.added_dirs.insert(path); - } else { - diff.added_files.insert(path); - } - } - Ok(()) -} - -/// Given two ostree commits, compute the diff between them. -#[context("Computing ostree diff")] -pub(crate) fn diff>( - repo: &ostree::Repo, - from: &str, - to: &str, - subdir: Option

, -) -> Result { - let subdir = subdir.as_ref(); - let subdir = subdir.map(|s| s.as_ref()); - let (fromroot, _) = repo.read_commit(from, gio::NONE_CANCELLABLE)?; - let (toroot, _) = repo.read_commit(to, gio::NONE_CANCELLABLE)?; - let (fromroot, toroot) = if let Some(subdir) = subdir { - ( - fromroot.resolve_relative_path(subdir).expect("path"), - toroot.resolve_relative_path(subdir).expect("path"), - ) - } else { - (fromroot, toroot) - }; - let fromroot = fromroot.downcast::().expect("downcast"); - fromroot.ensure_resolved()?; - let toroot = toroot.downcast::().expect("downcast"); - toroot.ensure_resolved()?; - let mut diff = FileTreeDiff { - subdir: subdir.map(|s| s.to_string()), - ..Default::default() - }; - diff_recurse("/", &mut diff, &fromroot, &toroot)?; - Ok(diff) -} diff --git a/rust/src/treefile.rs b/rust/src/treefile.rs index 1562e0ae..f7da305e 100644 --- a/rust/src/treefile.rs +++ b/rust/src/treefile.rs @@ -710,7 +710,7 @@ impl Treefile { ); for v in it { - let rev = repo.resolve_rev(v, false)?; + let rev = repo.resolve_rev(v, false)?.unwrap(); let rev = rev.as_str(); let (commit, _) = repo.load_commit(rev)?; let content_checksum =