Verified Commit f301426a authored by Morgan Adamiec's avatar Morgan Adamiec
Browse files

Initial commit

parents
target
*/target
**/*.rs.bk
*/Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "alpm"
version = "0.1.0"
dependencies = [
"alpm-sys 0.1.0",
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"libarchive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libarchive3-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "alpm-sys"
version = "0.1.0"
[[package]]
name = "bitflags"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libarchive"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libarchive3-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libarchive3-sys"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libc"
version = "0.2.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "pkg-config"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"checksum libarchive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3da06b22cd19af338a40f5d44a0aa6352ae43839d0855a049881cbc7e1b9c914"
"checksum libarchive3-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3cd3beae8f59a4c7a806523269b5392037577c150446e88d684dfa6de6031ca7"
"checksum libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319"
"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
[workspace]
members = [ "alpm-sys", "alpm" ]
This diff is collapsed.
[package]
name = "alpm-sys"
version = "0.1.0"
authors = ["morganamilo <morganamilo@gmail.com>"]
description = "Raw bindings for libalpm"
homepage = "http://github.com/Morganamilo/alpm.rs"
repository = "http://github.com/Morganamilo/alpm.rs"
documentation = "https://docs.rs/alpm_sys"
license = "GPL-3.0"
keywords = ["archlinux", "arch", "alpm", "pacman"]
categories = ["external-ffi-bindings"]
[features]
git = []
#!/bin/sh
bindgen /usr/include/alpm.h \
--whitelist-type '(alpm|ALPM).*' \
--whitelist-function '(alpm|ALPM).*' \
--rustified-enum '_alpm_[a-z_]+_t' \
--constified-enum-module '_alpm_siglevel_t' \
--constified-enum-module '_alpm_pkgvalidation_t' \
--constified-enum-module '_alpm_loglevel_t' \
--constified-enum-module '_alpm_question_type_t' \
--constified-enum-module '_alpm_transflag_t' \
--constified-enum-module '_alpm_db_usage_' \
--constified-enum-module '_alpm_db_usage_t' \
--constified-enum-module 'alpm_caps' \
--opaque-type alpm_handle_t \
--opaque-type alpm_db_t \
--opaque-type alpm_pkg_t \
--opaque-type alpm_trans_t \
fn main() {
println!("cargo:rustc-link-lib=alpm");
}
This diff is collapsed.
This diff is collapsed.
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#[cfg(not(feature = "git"))]
mod ffi;
#[cfg(feature = "git")]
mod ffi_git;
#[cfg(not(feature = "git"))]
pub use crate::ffi::*;
#[cfg(feature = "git")]
pub use crate::ffi_git::*;
[package]
name = "alpm"
version = "0.1.0"
authors = ["morganamilo <morganamilo@gmail.com>"]
edition = "2018"
description = "Rust bindings for libalpm"
homepage = "http://github.com/Morganamilo/alpm.rs"
repository = "http://github.com/Morganamilo/alpm.rs"
documentation = "https://docs.rs/alpm"
license = "GPL-3.0"
keywords = ["archlinux", "arch", "alpm", "pacman"]
categories = ["api-bindings"]
[features]
mtree = ["libarchive", "libarchive3-sys"]
[dependencies]
alpm-sys = { path = "../alpm-sys" }
bitflags = "1.0.4"
libarchive = { version = "0.1.1", optional = true }
libarchive3-sys = { version = "0.1.2", optional = true }
use crate::{Package, Result, Trans};
use alpm_sys::*;
impl<'a> Trans<'a> {
pub fn add_pkg(&mut self, pkg: Package) -> Result<()> {
let ret = unsafe { alpm_add_pkg(self.handle.handle, pkg.pkg) };
self.handle.check_ret(ret)
}
}
This diff is collapsed.
use crate::{Package, PackageReason, Result};
use alpm_sys::*;
use std::mem::transmute;
impl<'a> Package<'a> {
pub fn set_reason(&mut self, reason: PackageReason) -> Result<()> {
let reason = unsafe { transmute::<PackageReason, _alpm_pkgreason_t>(reason) };
let ret = unsafe { alpm_pkg_set_reason(self.pkg, reason) };
self.handle.check_ret(ret)
}
}
use crate::{Alpm, Package, Result, SigLevel};
use alpm_sys::*;
use std::ffi::CString;
use std::os::raw::c_int;
use std::ptr;
impl Alpm {
pub fn pkg_load<S: Into<String>>(
&self,
filename: S,
full: bool,
level: SigLevel,
) -> Result<Package> {
let filename = CString::new(filename.into())?;
let mut pkg = Package {
pkg: ptr::null_mut(),
handle: self,
drop: true,
};
let ret = unsafe {
alpm_pkg_load(
self.handle,
filename.as_ptr(),
full as c_int,
level.bits() as i32,
&mut pkg.pkg,
)
};
self.check_ret(ret)?;
Ok(pkg)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn load() {
let handle = Alpm::new("/", "tests/db").unwrap();
let pkg = handle
.pkg_load(
"tests/pacman-5.1.3-1-x86_64.pkg.tar.xz",
false,
SigLevel::NONE,
)
.unwrap();
assert_eq!(pkg.name(), "pacman");
}
}
use crate::{Db, Result};
use alpm_sys::*;
impl<'a> Db<'a> {
pub fn update(&mut self, force: bool) -> Result<()> {
let force = if force { 1 } else { 0 };
let ret = unsafe { alpm_db_update(force, self.db) };
self.handle.check_ret(ret)
}
}
use crate::utils::*;
use crate::{Alpm, AlpmList, Depend, FreeMethod, Package};
use alpm_sys::*;
use std::marker::PhantomData;
#[derive(Debug)]
pub struct Conflict {
pub(crate) inner: alpm_conflict_t,
pub(crate) drop: bool,
}
impl Drop for Conflict {
fn drop(&mut self) {
if self.drop {
unsafe { alpm_conflict_free(&mut self.inner) }
}
}
}
impl Conflict {
pub fn package1_hash(&self) -> u64 {
self.inner.package1_hash
}
pub fn package2_hash(&self) -> u64 {
self.inner.package2_hash
}
pub fn package1(&self) -> &str {
unsafe { from_cstr(self.inner.package1) }
}
pub fn package2(&self) -> &str {
unsafe { from_cstr(self.inner.package2) }
}
pub fn reason(&self) -> Depend<'_> {
Depend {
inner: self.inner.reason,
drop: false,
phantom: PhantomData,
}
}
}
impl Alpm {
pub fn check_conflicts(&self, pkgs: AlpmList<Package>) -> AlpmList<Conflict> {
let ret = unsafe { alpm_checkconflicts(self.handle, pkgs.item) };
AlpmList {
handle: self,
item: ret,
free: FreeMethod::FreeConflict,
_marker: PhantomData,
}
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment