Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filename method of Package should return Option<&str> #18

Closed
PhotonQuantum opened this issue Jun 1, 2021 · 5 comments
Closed

filename method of Package should return Option<&str> #18

PhotonQuantum opened this issue Jun 1, 2021 · 5 comments

Comments

@PhotonQuantum
Copy link

Local packages don't have a "filename" field. Therefore, calling filename() results in a panic.

Minimal reproducible example:

use alpm::Alpm;

fn main() {
    let alpm = Alpm::new("/", "/var/lib/pacman").unwrap();
    let pkg = alpm.localdb().pkgs().find_satisfier("systemd").unwrap();
    dbg!(pkg.name());
    dbg!(pkg.filename());
}

Output:

[src/main.rs:6] pkg.name() = "systemd"
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /home/lightquantum/.cargo/registry/src/github.com-1ecc6299db9ec823/alpm-2.0.0/src/utils.rs:7:10
stack backtrace:
   0: rust_begin_unwind
             at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/core/src/panicking.rs:50:5
   3: core::option::Option<T>::unwrap
             at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/core/src/option.rs:386:21
   4: alpm::utils::from_cstr
             at /home/lightquantum/.cargo/registry/src/github.com-1ecc6299db9ec823/alpm-2.0.0/src/utils.rs:5:5
   5: alpm::package::Pkg::filename
             at /home/lightquantum/.cargo/registry/src/github.com-1ecc6299db9ec823/alpm-2.0.0/src/package.rs:94:18
   6: alpm_rust_min_reprod::main
             at ./src/main.rs:7:10
   7: core::ops::function::FnOnce::call_once
             at /rustc/657bc01888e6297257655585f9c475a0801db6d2/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
@fosskers
Copy link
Contributor

fosskers commented Jun 1, 2021

Good find.

@Morganamilo
Copy link
Member

There's probably going to be a couple more of these. Paru is effected and I don't believe it calls that function.

@fosskers
Copy link
Contributor

fosskers commented Jun 1, 2021

Aura doesn't as of yet either.

@Morganamilo
Copy link
Member

"Fixed" with 6681b33

Will hold off on a proper fix until I find all the functions that may return null and as I don't want to push a v3 just yet.

@Morganamilo
Copy link
Member

This c413be4#diff-6d974fec9cd167345df12f3e136a7be85c0f1bcfe60805940d14e881dda30b6c is my fix for now. Basically the same concept as my last comment but easier to strip out when it comes time for v3.

Also I believe the functions mentioned in #19 are the only functions that should be an option so I think this is all solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants