diff --git a/cmd/pm/main.go b/cmd/pm/main.go index b234147..64292ea 100644 --- a/cmd/pm/main.go +++ b/cmd/pm/main.go @@ -235,8 +235,14 @@ func main() { fatalf("installing: %v\n", err) } case "ls": - if err := db.ListInstalled(root, os.Stdout); err != nil { - fatalf("listing installed: %v\n", err) + if len(os.Args[1:]) == 1 { + if err := db.ListInstalled(root, os.Stdout); err != nil { + fatalf("listing installed: %v\n", err) + } + } else { + if err := db.ListInstalledFiles(root, os.Stdout, os.Args[2:]); err != nil { + fatalf("listing installed: %v\n", err) + } } case "rm": if len(os.Args[1:]) < 2 { diff --git a/db/installed.go b/db/installed.go index c412ce3..5b2a8a3 100644 --- a/db/installed.go +++ b/db/installed.go @@ -6,6 +6,7 @@ import ( "io" "os" "path/filepath" + "sort" "github.com/pkg/errors" "mcquay.me/fs" @@ -58,6 +59,44 @@ func ListInstalled(root string, w io.Writer) error { return nil } +// ListInstalledFiles prints the contents of a package. +func ListInstalledFiles(root string, w io.Writer, names []string) error { + for _, name := range names { + ok, err := IsInstalled(root, pm.Meta{Name: pm.Name(name)}) + if err != nil { + return errors.Wrap(err, "is installed") + } + if !ok { + return fmt.Errorf("%v not installed", name) + } + } + + for _, name := range names { + fn := filepath.Join(root, "var", "lib", "pm", "installed", name, "bom.sha256") + f, err := os.Open(fn) + if err != nil { + return errors.Wrapf(err, "opening %v's bom", name) + } + bom, err := pm.ParseCS(f) + if err != nil { + return errors.Wrapf(err, "parsing %v's bom", name) + } + if err := f.Close(); err != nil { + return errors.Wrapf(err, "closing %v's bom", name) + } + + ks := []string{} + for k := range bom { + ks = append(ks, k) + } + sort.Strings(ks) + for _, k := range ks { + fmt.Fprintf(w, "%v\n", k) + } + } + return nil +} + func LoadInstalled(root string) (pm.Installed, error) { return loadi(root) }