From 04d6b5da2fc16c0c61cf4337d685d3e79deab18b Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Wed, 21 Sep 2016 20:45:18 +0200 Subject: [PATCH] Remove more unused bits --- src/cmds/restic/cmd_backup.go | 11 ----- src/cmds/restic/integration_helpers_test.go | 19 -------- src/cmds/restic/integration_test.go | 21 --------- src/restic/blob.go | 2 + src/restic/checker/checker.go | 5 -- src/restic/config.go | 5 -- src/restic/crypto/crypto.go | 4 -- src/restic/id.go | 6 --- src/restic/node.go | 7 --- src/restic/repository/index.go | 34 -------------- src/restic/repository/repository.go | 7 --- src/restic/test/helpers.go | 51 --------------------- src/restic/tree.go | 6 --- src/restic/worker/pool.go | 5 -- 14 files changed, 2 insertions(+), 181 deletions(-) diff --git a/src/cmds/restic/cmd_backup.go b/src/cmds/restic/cmd_backup.go index 4f360c9c3..53c859fd5 100644 --- a/src/cmds/restic/cmd_backup.go +++ b/src/cmds/restic/cmd_backup.go @@ -95,17 +95,6 @@ func formatDuration(d time.Duration) string { return formatSeconds(sec) } -func printTree2(indent int, t *restic.Tree) { - for _, node := range t.Nodes { - if node.Tree() != nil { - fmt.Printf("%s%s/\n", strings.Repeat(" ", indent), node.Name) - printTree2(indent+1, node.Tree()) - } else { - fmt.Printf("%s%s\n", strings.Repeat(" ", indent), node.Name) - } - } -} - func (cmd CmdBackup) Usage() string { return "DIR/FILE [DIR/FILE] [...]" } diff --git a/src/cmds/restic/integration_helpers_test.go b/src/cmds/restic/integration_helpers_test.go index 15111d688..cac3e3592 100644 --- a/src/cmds/restic/integration_helpers_test.go +++ b/src/cmds/restic/integration_helpers_test.go @@ -178,15 +178,6 @@ func configureRestic(t testing.TB, cache, repo string) GlobalOptions { } } -func cleanupTempdir(t testing.TB, tempdir string) { - if !TestCleanupTempDirs { - t.Logf("leaving temporary directory %v used for test", tempdir) - return - } - - RemoveAll(t, tempdir) -} - // withTestEnvironment creates a test environment and calls f with it. After f has // returned, the temporary directory is removed. func withTestEnvironment(t testing.TB, f func(*testEnvironment, GlobalOptions)) { @@ -219,13 +210,3 @@ func withTestEnvironment(t testing.TB, f func(*testEnvironment, GlobalOptions)) RemoveAll(t, tempdir) } - -// removeFile resets the read-only flag and then deletes the file. -func removeFile(fn string) error { - err := os.Chmod(fn, 0666) - if err != nil { - return err - } - - return os.Remove(fn) -} diff --git a/src/cmds/restic/integration_test.go b/src/cmds/restic/integration_test.go index 0dd6c6165..56e0fc3b2 100644 --- a/src/cmds/restic/integration_test.go +++ b/src/cmds/restic/integration_test.go @@ -809,27 +809,6 @@ func TestRebuildIndexAlwaysFull(t *testing.T) { TestRebuildIndex(t) } -var optimizeTests = []struct { - testFilename string - snapshots restic.IDSet -}{ - { - filepath.Join("..", "..", "restic", "checker", "testdata", "checker-test-repo.tar.gz"), - restic.NewIDSet(restic.TestParseID("a13c11e582b77a693dd75ab4e3a3ba96538a056594a4b9076e4cacebe6e06d43")), - }, - { - filepath.Join("testdata", "old-index-repo.tar.gz"), - nil, - }, - { - filepath.Join("testdata", "old-index-repo.tar.gz"), - restic.NewIDSet( - restic.TestParseID("f7d83db709977178c9d1a09e4009355e534cde1a135b8186b8b118a3fc4fcd41"), - restic.TestParseID("51d249d28815200d59e4be7b3f21a157b864dc343353df9d8e498220c2499b02"), - ), - }, -} - func TestCheckRestoreNoLock(t *testing.T) { withTestEnvironment(t, func(env *testEnvironment, global GlobalOptions) { datafile := filepath.Join("testdata", "small-repo.tar.gz") diff --git a/src/restic/blob.go b/src/restic/blob.go index 6074b59b1..670fd2fdf 100644 --- a/src/restic/blob.go +++ b/src/restic/blob.go @@ -46,6 +46,8 @@ func (t BlobType) String() string { return "data" case TreeBlob: return "tree" + case InvalidBlob: + return "invalid" } return fmt.Sprintf("", t) diff --git a/src/restic/checker/checker.go b/src/restic/checker/checker.go index ebb416938..dcce67a3f 100644 --- a/src/restic/checker/checker.go +++ b/src/restic/checker/checker.go @@ -649,11 +649,6 @@ func (c *Checker) UnusedBlobs() (blobs restic.IDs) { return blobs } -// OrphanedPacks returns a slice of unused packs (only available after Packs() was run). -func (c *Checker) OrphanedPacks() restic.IDs { - return c.orphanedPacks -} - // CountPacks returns the number of packs in the repository. func (c *Checker) CountPacks() uint64 { return uint64(len(c.packs)) diff --git a/src/restic/config.go b/src/restic/config.go index 0afb5426b..0af6b7447 100644 --- a/src/restic/config.go +++ b/src/restic/config.go @@ -21,11 +21,6 @@ type Config struct { // is newly created with Init(). const RepoVersion = 1 -// JSONUnpackedSaver saves unpacked JSON. -type JSONUnpackedSaver interface { - SaveJSONUnpacked(FileType, interface{}) (ID, error) -} - // JSONUnpackedLoader loads unpacked JSON. type JSONUnpackedLoader interface { LoadJSONUnpacked(FileType, ID, interface{}) error diff --git a/src/restic/crypto/crypto.go b/src/restic/crypto/crypto.go index 57fdd6230..03d3d10a2 100644 --- a/src/restic/crypto/crypto.go +++ b/src/restic/crypto/crypto.go @@ -26,10 +26,6 @@ const ( var ( // ErrUnauthenticated is returned when ciphertext verification has failed. ErrUnauthenticated = errors.New("ciphertext verification failed") - - // ErrBufferTooSmall is returned when the destination slice is too small - // for the ciphertext. - ErrBufferTooSmall = errors.New("destination buffer too small") ) // Key holds encryption and message authentication keys for a repository. It is stored diff --git a/src/restic/id.go b/src/restic/id.go index 6d1f55de2..08cb6f64b 100644 --- a/src/restic/id.go +++ b/src/restic/id.go @@ -1,7 +1,6 @@ package restic import ( - "bytes" "crypto/rand" "crypto/sha256" "encoding/hex" @@ -95,11 +94,6 @@ func (id ID) EqualString(other string) (bool, error) { return id == id2, nil } -// Compare compares this ID to another one, returning -1, 0, or 1. -func (id ID) Compare(other ID) int { - return bytes.Compare(other[:], id[:]) -} - // MarshalJSON returns the JSON encoding of id. func (id ID) MarshalJSON() ([]byte, error) { return json.Marshal(id.String()) diff --git a/src/restic/node.go b/src/restic/node.go index 921be7382..19f6583eb 100644 --- a/src/restic/node.go +++ b/src/restic/node.go @@ -40,8 +40,6 @@ type Node struct { Error string `json:"error,omitempty"` - tree *Tree - Path string `json:"-"` } @@ -58,11 +56,6 @@ func (node Node) String() string { return fmt.Sprintf("", node.Type, node.Name) } -// Tree returns this node's tree object. -func (node Node) Tree() *Tree { - return node.tree -} - // NodeFromFileInfo returns a new node from the given path and FileInfo. func NodeFromFileInfo(path string, fi os.FileInfo) (*Node, error) { mask := os.ModePerm | os.ModeType | os.ModeSetuid | os.ModeSetgid | os.ModeSticky diff --git a/src/restic/repository/index.go b/src/restic/repository/index.go index a372f82aa..fb7ff1ee5 100644 --- a/src/restic/repository/index.go +++ b/src/restic/repository/index.go @@ -275,15 +275,6 @@ func (idx *Index) Count(t restic.BlobType) (n uint) { return } -// Length returns the number of entries in the Index. -func (idx *Index) Length() uint { - debug.Log("Index.Count", "counting blobs") - idx.m.Lock() - defer idx.m.Unlock() - - return uint(len(idx.pack)) -} - type packJSON struct { ID restic.ID `json:"id"` Blobs []blobJSON `json:"blobs"` @@ -550,28 +541,3 @@ func LoadIndexWithDecoder(repo restic.Repository, id restic.ID, fn func(io.Reade return idx, nil } - -// ConvertIndex loads the given index from the repo and converts them to the new -// format (if necessary). When the conversion is succcessful, the old index -// is removed. Returned is either the old id (if no conversion was needed) or -// the new id. -func ConvertIndex(repo *Repository, id restic.ID) (restic.ID, error) { - debug.Log("ConvertIndex", "checking index %v", id.Str()) - - idx, err := LoadIndexWithDecoder(repo, id, DecodeOldIndex) - if err != nil { - debug.Log("ConvertIndex", "LoadIndexWithDecoder(%v) returned error: %v", id.Str(), err) - return id, err - } - - buf := bytes.NewBuffer(nil) - idx.supersedes = restic.IDs{id} - - err = idx.Encode(buf) - if err != nil { - debug.Log("ConvertIndex", "oldIdx.Encode() returned error: %v", err) - return id, err - } - - return repo.SaveUnpacked(restic.IndexFile, buf.Bytes()) -} diff --git a/src/restic/repository/repository.go b/src/restic/repository/repository.go index fe36e345f..7097dc200 100644 --- a/src/restic/repository/repository.go +++ b/src/restic/repository/repository.go @@ -42,13 +42,6 @@ func (r *Repository) Config() restic.Config { return r.cfg } -// Find loads the list of all blobs of type t and searches for names which start -// with prefix. If none is found, nil and ErrNoIDPrefixFound is returned. If -// more than one is found, nil and ErrMultipleIDMatches is returned. -func (r *Repository) Find(t restic.FileType, prefix string) (string, error) { - return restic.Find(r.be, t, prefix) -} - // PrefixLength returns the number of bytes required so that all prefixes of // all IDs of type t are unique. func (r *Repository) PrefixLength(t restic.FileType) (int, error) { diff --git a/src/restic/test/helpers.go b/src/restic/test/helpers.go index d363e09c9..22489df01 100644 --- a/src/restic/test/helpers.go +++ b/src/restic/test/helpers.go @@ -3,7 +3,6 @@ package test import ( "compress/bzip2" "compress/gzip" - "crypto/rand" "fmt" "io" "io/ioutil" @@ -90,56 +89,6 @@ func Random(seed, count int) []byte { return p } -type rndReader struct { - src *mrand.Rand -} - -func (r *rndReader) Read(p []byte) (int, error) { - for i := 0; i < len(p); i += 8 { - val := r.src.Int63() - var data = []byte{ - byte((val >> 0) & 0xff), - byte((val >> 8) & 0xff), - byte((val >> 16) & 0xff), - byte((val >> 24) & 0xff), - byte((val >> 32) & 0xff), - byte((val >> 40) & 0xff), - byte((val >> 48) & 0xff), - byte((val >> 56) & 0xff), - } - - for j := range data { - cur := i + j - if len(p) >= cur { - break - } - p[cur] = data[j] - } - } - - return len(p), nil -} - -// RandomReader returns a reader that returns deterministic pseudo-random data -// derived from the seed. -func RandomReader(seed int) io.Reader { - return &rndReader{src: mrand.New(mrand.NewSource(int64(seed)))} -} - -// RandomLimitReader returns a reader that returns size bytes of deterministic -// pseudo-random data derived from the seed. -func RandomLimitReader(seed, size int) io.Reader { - return io.LimitReader(RandomReader(seed), int64(size)) -} - -// GenRandom returns a []byte filled with up to 1000 random bytes. -func GenRandom(t testing.TB) []byte { - buf := make([]byte, mrand.Intn(1000)) - _, err := io.ReadFull(rand.Reader, buf) - OK(t, err) - return buf -} - // SetupTarTestFixture extracts the tarFile to outputDir. func SetupTarTestFixture(t testing.TB, outputDir, tarFile string) { input, err := os.Open(tarFile) diff --git a/src/restic/tree.go b/src/restic/tree.go index f2c1c04a9..c88141b91 100644 --- a/src/restic/tree.go +++ b/src/restic/tree.go @@ -71,12 +71,6 @@ func (t Tree) binarySearch(name string) (int, *Node, error) { return pos, nil, errors.New("named node not found") } -// Find returns a node with the given name. -func (t Tree) Find(name string) (*Node, error) { - _, node, err := t.binarySearch(name) - return node, err -} - // Subtrees returns a slice of all subtree IDs of the tree. func (t Tree) Subtrees() (trees IDs) { for _, node := range t.Nodes { diff --git a/src/restic/worker/pool.go b/src/restic/worker/pool.go index d2331f587..2268ef8f8 100644 --- a/src/restic/worker/pool.go +++ b/src/restic/worker/pool.go @@ -94,11 +94,6 @@ func (p *Pool) runWorker(numWorker int) { } } -// Cancel signals termination to all worker goroutines. -func (p *Pool) Cancel() { - close(p.done) -} - // Wait waits for all worker goroutines to terminate, afterwards the output // channel is closed. func (p *Pool) Wait() {