parent
51c8c920a3
commit
9ceb1865f9
@ -235,9 +235,15 @@ func main() {
|
||||
fatalf("installing: %v\n", err)
|
||||
}
|
||||
case "ls":
|
||||
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 {
|
||||
fatalf("pm rm: insufficient args\n\nusage: pm rm [pkg1, pkg2, ..., pkgN]\n")
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user