MCPcopy Index your code
hub / github.com/cavaliergopher/rpm

github.com/cavaliergopher/rpm @v1.3.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.3.0 ↗ · + Follow
159 symbols 405 edges 18 files 61 documented · 38% 3 cross-repo links updated 10mo agov1.3.0 · 2025-04-01★ 1753 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

rpm

Go Reference Build Status Go Report Card

Package rpm implements the rpm package file format.

$ go get github.com/cavaliergopher/rpm

See the package documentation or the examples programs in cmd/ to get started.

Extracting rpm packages

The following working example demonstrates how to extract files from an rpm package. In this example, only the cpio format and xz compression are supported which will cover most cases.

Implementations should consider additional formats and compressions algorithms, as well as support for extracting irregular file types and configuring permissions, uids and guids, etc.

package main

import (
    "io"
    "log"
    "os"
    "path/filepath"

    "github.com/cavaliergopher/cpio"
    "github.com/cavaliergopher/rpm"
    "github.com/ulikunitz/xz"
)

func ExtractRPM(name string) {
    // Open a package file for reading
    f, err := os.Open(name)
    if err != nil {
        log.Fatal(err)
    }
    defer f.Close()

    // Read the package headers
    pkg, err := rpm.Read(f)
    if err != nil {
        log.Fatal(err)
    }

    // Check the compression algorithm of the payload
    if compression := pkg.PayloadCompression(); compression != "xz" {
        log.Fatalf("Unsupported compression: %s", compression)
    }

    // Attach a reader to decompress the payload
    xzReader, err := xz.NewReader(f)
    if err != nil {
        log.Fatal(err)
    }

    // Check the archive format of the payload
    if format := pkg.PayloadFormat(); format != "cpio" {
        log.Fatalf("Unsupported payload format: %s", format)
    }

    // Attach a reader to unarchive each file in the payload
    cpioReader := cpio.NewReader(xzReader)
    for {
        // Move to the next file in the archive
        hdr, err := cpioReader.Next()
        if err == io.EOF {
            break // no more files
        }
        if err != nil {
            log.Fatal(err)
        }

        // Skip directories and other irregular file types in this example
        if !hdr.Mode.IsRegular() {
            continue
        }

        // Create the target directory
        if dirName := filepath.Dir(hdr.Name); dirName != "" {
            if err := os.MkdirAll(dirName, 0o755); err != nil {
                log.Fatal(err)
            }
        }

        // Create and write the file
        outFile, err := os.Create(hdr.Name)
        if err != nil {
            log.Fatal(err)
        }
        if _, err := io.Copy(outFile, cpioReader); err != nil {
            outFile.Close()
            log.Fatal(err)
        }
        outFile.Close()
    }
}

Extension points exported contracts — how you extend this code

Version (Interface)
Version is an interface which holds version information for a package in EVR form. [3 implementers]
version.go
Dependency (Interface)
See: https://github.com/rpm-software-management/rpm/blob/master/lib/rpmds.h#L25 Dependency is an interface which represe [2 …
dependency.go

Core symbols most depended-on inside this repo

GetTag
called by 58
header.go
String
called by 20
package.go
errorf
called by 20
util.go
StringSlice
called by 16
tag.go
ValueCount
called by 14
header.go
Int64
called by 11
tag.go
Name
called by 10
dependency.go
dependencies
called by 8
package.go

Shape

Method 103
Function 39
Struct 9
TypeAlias 6
Interface 2

Languages

Go99%
Python1%

Modules by API surface

package.go58 symbols
header.go13 symbols
fileinfo.go13 symbols
lead.go11 symbols
dependency.go10 symbols
version_test.go8 symbols
tag.go8 symbols
signature.go8 symbols
package_test.go7 symbols
version.go6 symbols
signature_test.go4 symbols
cmd/rpmdump/main.go4 symbols

Used by 3 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add rpm \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page