mirror of
https://github.com/restic/restic.git
synced 2025-08-12 11:47:43 +00:00
Use "pack file" instead of "data file" (#2885)
- changed variable names, especially changed DataFile into PackFile - changed in some comments - always use "pack file" in docu
This commit is contained in:
@@ -97,7 +97,7 @@ func (r *Repository) savePacker(ctx context.Context, t restic.BlobType, p *Packe
|
||||
}
|
||||
|
||||
id := restic.IDFromHash(p.hw.Sum(nil))
|
||||
h := restic.Handle{Type: restic.DataFile, Name: id.String()}
|
||||
h := restic.Handle{Type: restic.PackFile, Name: id.String()}
|
||||
|
||||
rd, err := restic.NewFileReader(p.tmpfile)
|
||||
if err != nil {
|
||||
|
@@ -34,7 +34,7 @@ func min(a, b int) int {
|
||||
}
|
||||
|
||||
func saveFile(t testing.TB, be Saver, length int, f *os.File, id restic.ID) {
|
||||
h := restic.Handle{Type: restic.DataFile, Name: id.String()}
|
||||
h := restic.Handle{Type: restic.PackFile, Name: id.String()}
|
||||
t.Logf("save file %v", h)
|
||||
|
||||
rd, err := restic.NewFileReader(f)
|
||||
|
@@ -26,7 +26,7 @@ func Repack(ctx context.Context, repo restic.Repository, packs restic.IDSet, kee
|
||||
|
||||
for packID := range packs {
|
||||
// load the complete pack into a temp file
|
||||
h := restic.Handle{Type: restic.DataFile, Name: packID.String()}
|
||||
h := restic.Handle{Type: restic.PackFile, Name: packID.String()}
|
||||
|
||||
tempfile, hash, packLength, err := DownloadAndHash(ctx, repo.Backend(), h)
|
||||
if err != nil {
|
||||
|
@@ -62,7 +62,7 @@ func selectBlobs(t *testing.T, repo restic.Repository, p float32) (list1, list2
|
||||
|
||||
blobs := restic.NewBlobSet()
|
||||
|
||||
err := repo.List(context.TODO(), restic.DataFile, func(id restic.ID, size int64) error {
|
||||
err := repo.List(context.TODO(), restic.PackFile, func(id restic.ID, size int64) error {
|
||||
entries, _, err := repo.ListPack(context.TODO(), id, size)
|
||||
if err != nil {
|
||||
t.Fatalf("error listing pack %v: %v", id, err)
|
||||
@@ -93,7 +93,7 @@ func selectBlobs(t *testing.T, repo restic.Repository, p float32) (list1, list2
|
||||
|
||||
func listPacks(t *testing.T, repo restic.Repository) restic.IDSet {
|
||||
list := restic.NewIDSet()
|
||||
err := repo.List(context.TODO(), restic.DataFile, func(id restic.ID, size int64) error {
|
||||
err := repo.List(context.TODO(), restic.PackFile, func(id restic.ID, size int64) error {
|
||||
list.Insert(id)
|
||||
return nil
|
||||
})
|
||||
@@ -130,7 +130,7 @@ func repack(t *testing.T, repo restic.Repository, packs restic.IDSet, blobs rest
|
||||
}
|
||||
|
||||
for id := range repackedBlobs {
|
||||
err = repo.Backend().Remove(context.TODO(), restic.Handle{Type: restic.DataFile, Name: id.String()})
|
||||
err = repo.Backend().Remove(context.TODO(), restic.Handle{Type: restic.PackFile, Name: id.String()})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@@ -130,7 +130,7 @@ func sortCachedPacksFirst(cache haver, blobs []restic.PackedBlob) {
|
||||
noncached := make([]restic.PackedBlob, 0, len(blobs)/2)
|
||||
|
||||
for _, blob := range blobs {
|
||||
if cache.Has(restic.Handle{Type: restic.DataFile, Name: blob.PackID.String()}) {
|
||||
if cache.Has(restic.Handle{Type: restic.PackFile, Name: blob.PackID.String()}) {
|
||||
cached = append(cached, blob)
|
||||
continue
|
||||
}
|
||||
@@ -164,7 +164,7 @@ func (r *Repository) LoadBlob(ctx context.Context, t restic.BlobType, id restic.
|
||||
}
|
||||
|
||||
// load blob from pack
|
||||
h := restic.Handle{Type: restic.DataFile, Name: blob.PackID.String()}
|
||||
h := restic.Handle{Type: restic.PackFile, Name: blob.PackID.String()}
|
||||
|
||||
switch {
|
||||
case cap(buf) < int(blob.Length):
|
||||
@@ -535,10 +535,10 @@ func (r *Repository) PrepareCache(indexIDs restic.IDSet) error {
|
||||
}
|
||||
}
|
||||
|
||||
// clear old data files
|
||||
err = r.Cache.Clear(restic.DataFile, packs)
|
||||
// clear old packs
|
||||
err = r.Cache.Clear(restic.PackFile, packs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error clearing data files in cache: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "error clearing pack files in cache: %v\n", err)
|
||||
}
|
||||
|
||||
treePacks := restic.NewIDSet()
|
||||
@@ -552,8 +552,8 @@ func (r *Repository) PrepareCache(indexIDs restic.IDSet) error {
|
||||
debug.Log("using readahead")
|
||||
cache := r.Cache.(*cache.Cache)
|
||||
cache.PerformReadahead = func(h restic.Handle) bool {
|
||||
if h.Type != restic.DataFile {
|
||||
debug.Log("no readahead for %v, is not data file", h)
|
||||
if h.Type != restic.PackFile {
|
||||
debug.Log("no readahead for %v, is not a pack file", h)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -670,7 +670,7 @@ func (r *Repository) List(ctx context.Context, t restic.FileType, fn func(restic
|
||||
// ListPack returns the list of blobs saved in the pack id and the length of
|
||||
// the file as stored in the backend.
|
||||
func (r *Repository) ListPack(ctx context.Context, id restic.ID, size int64) ([]restic.Blob, int64, error) {
|
||||
h := restic.Handle{Type: restic.DataFile, Name: id.String()}
|
||||
h := restic.Handle{Type: restic.PackFile, Name: id.String()}
|
||||
|
||||
blobs, err := pack.List(r.Key(), restic.ReaderAt(r.Backend(), h), size)
|
||||
if err != nil {
|
||||
|
@@ -27,15 +27,15 @@ func TestSortCachedPacksFirst(t *testing.T) {
|
||||
blobs[i] = restic.PackedBlob{PackID: id}
|
||||
|
||||
if i%3 == 0 {
|
||||
h := restic.Handle{Name: id.String(), Type: restic.DataFile}
|
||||
h := restic.Handle{Name: id.String(), Type: restic.PackFile}
|
||||
cache[h] = true
|
||||
}
|
||||
}
|
||||
|
||||
copy(sorted[:], blobs[:])
|
||||
sort.SliceStable(sorted[:], func(i, j int) bool {
|
||||
hi := restic.Handle{Type: restic.DataFile, Name: sorted[i].PackID.String()}
|
||||
hj := restic.Handle{Type: restic.DataFile, Name: sorted[j].PackID.String()}
|
||||
hi := restic.Handle{Type: restic.PackFile, Name: sorted[i].PackID.String()}
|
||||
hj := restic.Handle{Type: restic.PackFile, Name: sorted[j].PackID.String()}
|
||||
return cache.Has(hi) && !cache.Has(hj)
|
||||
})
|
||||
|
||||
@@ -58,7 +58,7 @@ func BenchmarkSortCachedPacksFirst(b *testing.B) {
|
||||
blobs[i] = restic.PackedBlob{PackID: id}
|
||||
|
||||
if i%3 == 0 {
|
||||
h := restic.Handle{Name: id.String(), Type: restic.DataFile}
|
||||
h := restic.Handle{Name: id.String(), Type: restic.PackFile}
|
||||
cache[h] = true
|
||||
}
|
||||
}
|
||||
|
@@ -224,7 +224,7 @@ func BenchmarkLoadAndDecrypt(b *testing.B) {
|
||||
|
||||
dataID := restic.Hash(buf)
|
||||
|
||||
storageID, err := repo.SaveUnpacked(context.TODO(), restic.DataFile, buf)
|
||||
storageID, err := repo.SaveUnpacked(context.TODO(), restic.PackFile, buf)
|
||||
rtest.OK(b, err)
|
||||
// rtest.OK(b, repo.Flush())
|
||||
|
||||
@@ -232,7 +232,7 @@ func BenchmarkLoadAndDecrypt(b *testing.B) {
|
||||
b.SetBytes(int64(length))
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
data, err := repo.LoadAndDecrypt(context.TODO(), nil, restic.DataFile, storageID)
|
||||
data, err := repo.LoadAndDecrypt(context.TODO(), nil, restic.PackFile, storageID)
|
||||
rtest.OK(b, err)
|
||||
|
||||
// See comment in BenchmarkLoadBlob.
|
||||
|
Reference in New Issue
Block a user