func getSnapshotNames(argNo int) ([]string, error) { if flag.NArg() > argNo { // Names of snapshots to leave are given in arguments. names := make([]string, 0, flag.NArg()-1) for i := argNo; i < flag.NArg(); i++ { name := flag.Arg(i) if !snapshot.IsValidName(name) { return nil, fmt.Errorf("invalid snapshot name %s", name) } names = append(names, name) } return names, nil } // All snapshots. return snapshot.GetNames() }
func listFiles() error { if flag.NArg() < 2 || flag.Arg(1) == "" { return fmt.Errorf("expecting snapshot name or directory ref") } var dirRef *block.Ref if snapshot.IsValidName(flag.Arg(1)) { // Given snapshot ref, fetch index ref. si, err := snapshot.LoadInfo(flag.Arg(1)) if err != nil { return err } dirRef = si.DirRef } else { dirRef = block.RefFromHex([]byte(flag.Arg(1))) if dirRef == nil { return fmt.Errorf("bad ref %q", flag.Arg(1)) } } return listDirectory("", dirRef) }