mirror of
https://github.com/restic/restic.git
synced 2025-03-09 00:00:02 +01:00
Cleaned up patch for #55.
Changes to _test.go were not part of the patch. I added them to be able to run the tests after patching.
This commit is contained in:
parent
625c987d23
commit
af2e363480
9 changed files with 17 additions and 18 deletions
|
@ -11,13 +11,14 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/restic/chunker"
|
||||
"restic/backend"
|
||||
"restic/debug"
|
||||
"restic/pack"
|
||||
"restic/pipe"
|
||||
"restic/repository"
|
||||
|
||||
"github.com/restic/chunker"
|
||||
|
||||
"github.com/juju/errors"
|
||||
)
|
||||
|
||||
|
@ -624,7 +625,7 @@ func unique(items []string) []string {
|
|||
// Snapshot creates a snapshot of the given paths. If parentID is set, this is
|
||||
// used to compare the files to the ones archived at the time this snapshot was
|
||||
// taken.
|
||||
func (arch *Archiver) Snapshot(p *Progress, paths []string, parentID *backend.ID) (*Snapshot, backend.ID, error) {
|
||||
func (arch *Archiver) Snapshot(p *Progress, paths []string, parentID *backend.ID, comment string) (*Snapshot, backend.ID, error) {
|
||||
paths = unique(paths)
|
||||
sort.Strings(paths)
|
||||
|
||||
|
@ -644,6 +645,7 @@ func (arch *Archiver) Snapshot(p *Progress, paths []string, parentID *backend.ID
|
|||
if err != nil {
|
||||
return nil, backend.ID{}, err
|
||||
}
|
||||
sn.Comment = comment
|
||||
sn.Excludes = arch.Excludes
|
||||
|
||||
jobs := archivePipe{}
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/restic/chunker"
|
||||
"restic"
|
||||
"restic/backend"
|
||||
"restic/checker"
|
||||
|
@ -15,6 +14,8 @@ import (
|
|||
"restic/pack"
|
||||
"restic/repository"
|
||||
. "restic/test"
|
||||
|
||||
"github.com/restic/chunker"
|
||||
)
|
||||
|
||||
var testPol = chunker.Pol(0x3DA3358B4DC173)
|
||||
|
@ -112,7 +113,7 @@ func archiveDirectory(b testing.TB) {
|
|||
|
||||
arch := restic.NewArchiver(repo)
|
||||
|
||||
_, id, err := arch.Snapshot(nil, []string{BenchArchiveDirectory}, nil)
|
||||
_, id, err := arch.Snapshot(nil, []string{BenchArchiveDirectory}, nil, "")
|
||||
OK(b, err)
|
||||
|
||||
b.Logf("snapshot archived as %v", id)
|
||||
|
@ -210,7 +211,7 @@ func BenchmarkLoadTree(t *testing.B) {
|
|||
|
||||
// archive a few files
|
||||
arch := restic.NewArchiver(repo)
|
||||
sn, _, err := arch.Snapshot(nil, []string{BenchArchiveDirectory}, nil)
|
||||
sn, _, err := arch.Snapshot(nil, []string{BenchArchiveDirectory}, nil, "")
|
||||
OK(t, err)
|
||||
t.Logf("archived snapshot %v", sn.ID())
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ func TestCache(t *testing.T) {
|
|||
arch := restic.NewArchiver(repo)
|
||||
|
||||
// archive some files, this should automatically cache all blobs from the snapshot
|
||||
_, _, err = arch.Snapshot(nil, []string{BenchArchiveDirectory}, nil)
|
||||
_, _, err = arch.Snapshot(nil, []string{BenchArchiveDirectory}, nil, "")
|
||||
|
||||
// TODO: test caching index
|
||||
}
|
||||
|
|
|
@ -243,7 +243,7 @@ func TestCheckerModifiedData(t *testing.T) {
|
|||
OK(t, repo.Init(TestPassword))
|
||||
|
||||
arch := restic.NewArchiver(repo)
|
||||
_, id, err := arch.Snapshot(nil, []string{"."}, nil)
|
||||
_, id, err := arch.Snapshot(nil, []string{"."}, nil, "")
|
||||
OK(t, err)
|
||||
t.Logf("archived as %v", id.Str())
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ type CmdBackup struct {
|
|||
Parent string `short:"p" long:"parent" description:"use this parent snapshot (default: last snapshot in repo that has the same target)"`
|
||||
Force bool `short:"f" long:"force" description:"Force re-reading the target. Overrides the \"parent\" flag"`
|
||||
Excludes []string `short:"e" long:"exclude" description:"Exclude a pattern (can be specified multiple times)"`
|
||||
Comment string `short:"c" long:"comment" description:"Descriptive comment"`
|
||||
|
||||
global *GlobalOptions
|
||||
}
|
||||
|
@ -327,7 +328,7 @@ func (cmd CmdBackup) Execute(args []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
_, id, err := arch.Snapshot(cmd.newArchiveProgress(stat), target, parentSnapshotID)
|
||||
_, id, err := arch.Snapshot(cmd.newArchiveProgress(stat), target, parentSnapshotID, cmd.Comment)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ func (cmd CmdSnapshots) Execute(args []string) error {
|
|||
}
|
||||
|
||||
tab := NewTable()
|
||||
tab.Header = fmt.Sprintf("%-8s %-19s %-10s %s", "ID", "Date", "Source", "Directory")
|
||||
tab.Header = fmt.Sprintf("%-8s %-19s %-10s %s", "ID", "Date", "Source", "Comment")
|
||||
tab.RowFormat = "%-8s %-19s %-10s %s"
|
||||
|
||||
done := make(chan struct{})
|
||||
|
@ -119,13 +119,7 @@ func (cmd CmdSnapshots) Execute(args []string) error {
|
|||
continue
|
||||
}
|
||||
id := sn.ID()
|
||||
tab.Rows = append(tab.Rows, []interface{}{hex.EncodeToString(id[:plen/2]), sn.Time.Format(TimeFormat), sn.Hostname, sn.Paths[0]})
|
||||
|
||||
if len(sn.Paths) > 1 {
|
||||
for _, path := range sn.Paths[1:] {
|
||||
tab.Rows = append(tab.Rows, []interface{}{"", "", "", path})
|
||||
}
|
||||
}
|
||||
tab.Rows = append(tab.Rows, []interface{}{hex.EncodeToString(id[:plen/2]), sn.Time.Format(TimeFormat), sn.Hostname, sn.Comment})
|
||||
}
|
||||
|
||||
tab.Write(os.Stdout)
|
||||
|
|
|
@ -16,6 +16,7 @@ type Snapshot struct {
|
|||
Parent *backend.ID `json:"parent,omitempty"`
|
||||
Tree *backend.ID `json:"tree"`
|
||||
Paths []string `json:"paths"`
|
||||
Comment string `json:"comment"`
|
||||
Hostname string `json:"hostname,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
UID uint32 `json:"uid,omitempty"`
|
||||
|
|
|
@ -84,7 +84,7 @@ func TeardownRepo(repo *repository.Repository) {
|
|||
|
||||
func SnapshotDir(t testing.TB, repo *repository.Repository, path string, parent *backend.ID) *restic.Snapshot {
|
||||
arch := restic.NewArchiver(repo)
|
||||
sn, _, err := arch.Snapshot(nil, []string{path}, parent)
|
||||
sn, _, err := arch.Snapshot(nil, []string{path}, parent, "")
|
||||
OK(t, err)
|
||||
return sn
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ func TestWalkTree(t *testing.T) {
|
|||
|
||||
// archive a few files
|
||||
arch := restic.NewArchiver(repo)
|
||||
sn, _, err := arch.Snapshot(nil, dirs, nil)
|
||||
sn, _, err := arch.Snapshot(nil, dirs, nil, "")
|
||||
OK(t, err)
|
||||
|
||||
// flush repo, write all packs
|
||||
|
|
Loading…
Add table
Reference in a new issue