From ad111195635734ef699e34dd4fba7202d7072f9a Mon Sep 17 00:00:00 2001 From: Felix Krull Date: Tue, 2 Oct 2018 22:37:42 +0200 Subject: [PATCH] sample: try to extract a file from the repo --- rust-bindings/rust/libostree/src/lib.rs | 1 + rust-bindings/rust/libostree/src/repo.rs | 1 + rust-bindings/rust/sample/src/main.rs | 40 ++++++++++++++++++++++-- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/rust-bindings/rust/libostree/src/lib.rs b/rust-bindings/rust/libostree/src/lib.rs index c61cacf9..cca9c9ca 100644 --- a/rust-bindings/rust/libostree/src/lib.rs +++ b/rust-bindings/rust/libostree/src/lib.rs @@ -16,6 +16,7 @@ use glib::Error; // re-exports mod auto; pub use auto::*; +pub use auto::functions::*; mod repo; diff --git a/rust-bindings/rust/libostree/src/repo.rs b/rust-bindings/rust/libostree/src/repo.rs index 8ace774a..5bce9fe0 100644 --- a/rust-bindings/rust/libostree/src/repo.rs +++ b/rust-bindings/rust/libostree/src/repo.rs @@ -12,6 +12,7 @@ use std::ptr; unsafe extern "C" fn read_variant_table(_key: glib_ffi::gpointer, value: glib_ffi::gpointer, hash_set: glib_ffi::gpointer) { let value: glib::Variant = from_glib_none(value as *const glib_ffi::GVariant); + // TODO: this set is degenerate because g_variant_hash for my Variants is always 0 let set: &mut HashSet = &mut *(hash_set as *mut HashSet); set.insert(value); } diff --git a/rust-bindings/rust/sample/src/main.rs b/rust-bindings/rust/sample/src/main.rs index 6735fc01..e6da49e1 100644 --- a/rust-bindings/rust/sample/src/main.rs +++ b/rust-bindings/rust/sample/src/main.rs @@ -1,11 +1,45 @@ extern crate gio; extern crate libostree; +use std::io::Write; +use std::fs::File; + +use gio::prelude::*; use libostree::prelude::*; fn main() { - let repo = libostree::Repo::new_for_str("test-repo"); + let repo = libostree::Repo::new_for_str("../../../repo-bare"); - let result = repo.create(libostree::RepoMode::Archive, Option::None); - result.expect("we did not expect this to fail :O"); + //let result = repo.create(libostree::RepoMode::Archive, Option::None); + //result.expect("we did not expect this to fail :O"); + + repo.open(None).expect("should have opened"); + + let (file, checksum) = repo.read_commit("test", None).unwrap(); + + println!("path: {:?}", file.get_path()); + + println!("sha256: {}", checksum); + + let objs = repo.traverse_commit_manual(checksum.as_str(), -1, None).unwrap(); + + for obj in objs { + let (name, obj_type) = libostree::object_name_deserialize(&obj); + println!(" {}", libostree::object_to_string(name.as_str(), obj_type).unwrap()); + + let (stream, size) = repo.load_object_stream(obj_type, name.as_str(), None).unwrap(); + println!(" bytes: {}", size); + + if obj_type == libostree::ObjectType::File { + let mut file = File::create("./object.file").unwrap(); + let mut read = 1; + let mut buffer = [0 as u8; 4096]; + while read != 0 { + read = stream.read(buffer.as_mut(), None).unwrap(); + file.write(&buffer[0 .. read]); + } + } + + //println!("{:?}", obj.type_()); + } }