mirror of
https://github.com/ostreedev/ostree.git
synced 2025-01-09 01:18:35 +03:00
sample: try to extract a file from the repo
This commit is contained in:
parent
1cfca1582f
commit
ad11119563
@ -16,6 +16,7 @@ use glib::Error;
|
||||
// re-exports
|
||||
mod auto;
|
||||
pub use auto::*;
|
||||
pub use auto::functions::*;
|
||||
|
||||
mod repo;
|
||||
|
||||
|
@ -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<glib::Variant> = &mut *(hash_set as *mut HashSet<glib::Variant>);
|
||||
set.insert(value);
|
||||
}
|
||||
|
@ -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_());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user