Example #1
0
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()
}
Example #2
0
func listSnapshots() error {
	names, err := snapshot.GetNames()
	if err != nil {
		return err
	}
	for _, name := range names {
		si, err := snapshot.LoadInfo(name)
		if err != nil {
			return err
		}

		comment := ""
		if si.Comment != "" {
			comment = "comment:      " + si.Comment + "\n"
		}

		fmt.Printf("snapshot:     %s\ndate:         %s\nsource path:  %s\nroot ref:     %s\n%s\n",
			name, si.Time.Local().Format(time.RFC1123), si.SourcePath, si.DirRef, comment)
	}
	return nil
}
Example #3
0
File: web.go Project: dchest/hesfic
func indexHandler(w http.ResponseWriter, req *http.Request) {
	// List snapshots.
	names, err := snapshot.GetNames()
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	rows := make([]snapshotDesc, len(names))
	for i, name := range names {
		var r snapshotDesc
		r.Name = name
		si, err := snapshot.LoadInfo(name)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		r.Comment = si.Comment
		r.SourcePath = si.SourcePath
		r.Time = si.Time.Local().Format("02 Jan 2006 15:04:05 Mon")
		r.DirRef = si.DirRef.String()
		r.DirRefPart = r.DirRef[:12] + "…"
		rows[len(rows)-1-i] = r // in reverse
	}

	var b bytes.Buffer
	if err := indexTemplate.Execute(&b,
		&struct {
			Title     string
			Snapshots []snapshotDesc
		}{
			"Snapshots",
			rows,
		}); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	b.WriteTo(w)
}