mirror of
https://github.com/restic/restic.git
synced 2025-12-15 04:13:09 +00:00
repository: restrict SaveUnpacked and RemoveUnpacked
Those methods now only allow modifying snapshots. Internal data types used by the repository are now read-only. The repository-internal code can bypass the restrictions by wrapping the repository in an `internalRepository` type. The restriction itself is implemented by using a new datatype WriteableFileType in the SaveUnpacked and RemoveUnpacked methods. This statically ensures that code cannot bypass the access restrictions. The test changes are somewhat noisy as some of them modify repository internals and therefore require some way to bypass the access restrictions. This works by capturing an `internalRepository` or `Backend` when creating the Repository using a test helper function.
This commit is contained in:
@@ -65,7 +65,7 @@ func RepairPacks(ctx context.Context, repo *Repository, ids restic.IDSet, printe
|
||||
printer.P("removing salvaged pack files")
|
||||
// if we fail to delete the damaged pack files, then prune will remove them later on
|
||||
bar = printer.NewCounter("files deleted")
|
||||
_ = restic.ParallelRemove(ctx, repo, ids, restic.PackFile, nil, bar)
|
||||
_ = restic.ParallelRemove(ctx, &internalRepository{repo}, ids, restic.PackFile, nil, bar)
|
||||
bar.Done()
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user