Giter VIP home page Giter VIP logo

go-rpmdb's Introduction

go-rpmdb

Library for enumerating packages in an RPM DB Packages file (without bindings).

package main

import (
	"fmt"
	"log"

	rpmdb "github.com/knqyf263/go-rpmdb/pkg"
)

func main() {
	if err := run(); err != nil {
		log.Fatal(err)
	}
}
func run() error {
	db, err := rpmdb.Open("./Packages")
	if err != nil {
		return err
	}
	pkgList, err := db.ListPackages()
	if err != nil {
		return err
	}

	fmt.Println("Packages:")
	for _, pkg := range pkgList {
		fmt.Printf("\t%+v\n", *pkg)
		// {Epoch:0 Name:m4 Version:1.4.16 Release:10.el7 Arch:x86_64}
		// {Epoch:0 Name:zip Version:3.0 Release:11.el7 Arch:x86_64}
		// ...
	}
	fmt.Printf("[Total Packages: %d]\n", len(pkgList))
	return nil
}

go-rpmdb's People

Contributors

acornett21 avatar bcrochet avatar dirkmueller avatar djoreilly avatar dmitriylewen avatar eredwine avatar geremy-condra avatar jinroh avatar knqyf263 avatar kolyshkin avatar komish avatar mainek00n avatar masahiro331 avatar theopolis avatar tofay avatar wagoodman avatar westonsteimel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

go-rpmdb's Issues

Infinite loop when parsing bdb table

At https://github.com/knqyf263/go-rpmdb/blob/master/pkg/bdb/hash_page.go#L70

I believe this continue statement without any changes to the loop variables is causing an infinite loop for some types of corrupted bdb databases.

I am able to pretty consistently recreate this issue, though I am unable to give you an example at this time.

Adding "currentPageNo = currentPage.NextPageNo`" breaks the loop and causes this library to detect the corruption, though I'm not totally sure if that's the right solution. Please let me know.

SigMD5 ending in zeroes are truncated

Currently the UBI8 libuuid rpm has an SIGMD5 value of c1e561f13d39aee443a1f00258fba000.

rpm -qa --queryformat "\{Name: \"%{NAME}\", Digest: \"md5:%{SIGMD5}\"\}\n"
{Name: "libuuid", Digest: "md5:c1e561f13d39aee443a1f00258fba000"}

but the SIGMD5 value is loaded as c1e561f13d39aee443a1f00258fba0.

package main

import (
	"fmt"
	"log"

	rpmdb "github.com/knqyf263/go-rpmdb/pkg"
)

func main() {
	if err := run(); err != nil {
		log.Fatal(err)
	}
}

func run() error {
	db, err := rpmdb.Open("./Packages")
	if err != nil {
		return err
	}
	pkgList, err := db.ListPackages()
	if err != nil {
		return err
	}

	fmt.Println("Packages:")
	for _, pkg := range pkgList {
		fmt.Printf("\t%+s %+s\n", *&pkg.Name, *&pkg.SigMD5)
	}

	fmt.Printf("[Total Packages: %d]\n", len(pkgList))
	return nil
}
./package-checker 
Packages:
        libuuid c1e561f13d39aee443a1f00258fba0
[Total Packages: 1]

The attached Packages.zip file contains the libuuid rpm that is experiencing the error.

Request for Version Tagging in go-rpmdb

Hi @knqyf263,

I’ve been using your Go module, go-rpmdb, and I’ve found it really useful. I wanted to suggest adding version tags. This would help with being able to reference stable versions, make it easier to manage dependencies, and signal ongoing maintenance.

It’s a small change that could really enhance your module’s usability.

Thanks for considering this!

Best,
Ryan Currah

Support pageSize in z system

Hey @knqyf263 thank you for creating this project 👏

Scan tool anchore is using this module as a dependency in syft. When our team scans z system images, it failed with invalid page size error:

unable to catalog rpmdb package=/var/lib/rpm/Packages: unexpected page size: 1048576

My colleague finds the code here:

err := binary.Read(bytes.NewReader(data), binary.LittleEndian, &metadata)

it should have use BigEndian for reading the Packages file on s390x(z system), then it will get a normal pagesize 4096 just as x86.

It would be good if go-rpmdb can support z systems too.

ndb: unexpected NDB blob Magic for pkg error

On openSUSE Tumbleweed with the ndb backend. When zypper up runs and updates many packages there can be a lots of changes to the packages file. Attempting to use the library at the same time can fail with unexpected NDB blob Magic for pkg ...

Err: xerrors.Errorf("unexpected NDB blob Magic for pkg %d: %x", slot.PkgIndex, blobHeaderBuff.BlobMagic),

I think the rpm binary is using an exclusive file lock when updating the file
https://github.com/rpm-software-management/rpm/blob/rpm-4.17.0-release/lib/backend/ndb/rpmpkg.c

Adding a shared lock seems to fix the problem. I'll post a PR for review.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.