func doitem(r *items.Store, ids []string) { for _, id := range ids { item, err := r.Item(id) if err != nil { fmt.Printf("%s: Error %s\n", id, err.Error()) return } printitem(item) } }
func doblob(r *items.Store, id, blob string) { bid, _ := strconv.Atoi(blob) rc, _, err := r.Blob(id, items.BlobID(bid)) if err != nil { fmt.Printf("%s / %d: Error %s\n", id, bid, err.Error()) } else { io.Copy(os.Stdout, rc) rc.Close() } }
// add all the files to this item. Directories are automatically recursed into. // Files and directories which begin with a dot are skipped. func doadd(r *items.Store, id string, files []string, isset bool) { item, err := r.Item(id) if err != nil && err != items.ErrNoItem { fmt.Println(err.Error()) return } tx, err := r.Open(id, *creator) if err != nil { fmt.Println(err.Error()) return } defer tx.Close() if isset { tx.ClearSlots() } for _, name := range files { err := filepath.Walk(name, func(path string, info os.FileInfo, err error) error { if err != nil { return err } if strings.HasPrefix(info.Name(), ".") { if info.IsDir() { return filepath.SkipDir } return nil } if !info.IsDir() { slot := deriveSlotName(name, path) fmt.Printf("Adding %s\n", path) return addfile(item, tx, path, slot, info.Size()) } return nil }) if err != nil { fmt.Println(err) return } } }
// add all the files to this item. Directories are automatically recursed into. // Files and directories which begin with a dot are skipped. func dodelete(r *items.Store, id string, delblobs []string) { var delbid []items.BlobID for _, blobid := range delblobs { bid, err := strconv.Atoi(blobid) if err != nil { fmt.Println(err.Error()) return } delbid = append(delbid, items.BlobID(bid)) } tx, err := r.Open(id, *creator) if err != nil { fmt.Println(err.Error()) return } for _, bid := range delbid { tx.DeleteBlob(bid) // TODO(dbrower): also remove any slots pointing to this blob } err = tx.Close() if err != nil { fmt.Println(err.Error()) } }
func dolist(r *items.Store) { c := r.List() for name := range c { fmt.Println(name) } }