Beispiel #1
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
}
Beispiel #2
0
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)
}
Beispiel #3
0
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)
}