Documentation
¶
Overview ¶
Package trash restores, cleans and purges the trash can (decision 0010). Deleting an item moves its record here (internal/service/item), as does deleting a repository (Keep, internal/repos), and a trashed file keeps its blob reference, so it can be restored until its retention period passes. Purging an entry releases that reference, and the next garbage collection removes the content once nothing else holds it.
Index ¶
- Constants
- Variables
- func Newest(entries []types.TrashEntry) []types.TrashEntry
- func Settings(ctx context.Context, st store.Store) (types.TrashcanSettings, error)
- type Child
- type Destination
- type Node
- type Service
- func (s *Service) Below(ctx context.Context, dir string, deep bool, sees func(types.Item) bool) ([]Node, error)
- func (s *Service) Children(ctx context.Context, dir string, sees func(types.Item) bool) ([]Child, error)
- func (s *Service) Clean(ctx context.Context, repoKey, prefix string) (int, error)
- func (s *Service) Empty(ctx context.Context) (int, error)
- func (s *Service) Entries(ctx context.Context, repoKey, prefix string) ([]types.TrashEntry, error)
- func (s *Service) Find(ctx context.Context, repoKey, fullPath string) (types.TrashEntry, error)
- func (s *Service) Keep(ctx context.Context, c repo.Config, by string) (map[string]int64, error)
- func (s *Service) PurgeExpired(ctx context.Context) (int, error)
- func (s *Service) Restore(ctx context.Context, repoKey, from string, dst Destination, by string, ...) (int, error)
Constants ¶
const ( // Repository is the key Artifactory shows the trash can under. Repository = "auto-trashcan" // DefaultRetentionDays is Artifactory's default trash can retention. DefaultRetentionDays = 14 // DefaultBatch bounds the entries one transaction restores or purges, // so emptying a large trash can never holds one long transaction. DefaultBatch = 500 )
Variables ¶
var ErrNotPermitted = errors.New("trash: restoring an item is not permitted")
ErrNotPermitted is a restore that selected an item its permit refused.
var ErrNothingTrashed = errors.New("trash: nothing is trashed at the path")
ErrNothingTrashed is a restore from a path with no trashed items.
Functions ¶
func Newest ¶
func Newest(entries []types.TrashEntry) []types.TrashEntry
Newest keeps, for each original path, the most recently trashed entry, ordered so folders come before what they contain.
Types ¶
type Destination ¶
Destination is where a restore puts items: a repository and a path. With no path the items return to their original paths inside Repo; with one, the restored path lands there and what was below it below that.
type Node ¶
type Node struct {
Path string
Folder bool
// Entry is the newest entry trashed at Path. It is nil for a folder that
// only holds what was trashed below it, such as a repository's folder at
// the root, or the parent of a file deleted on its own.
Entry *types.TrashEntry
}
Node is one item of the trash can's tree, as Artifactory's auto-trashcan repository holds it: Path is the original repository key and the item's original path, joined.
type Service ¶
type Service struct {
Store store.Store
// Items recreates restored items; only Restore needs it.
Items *item.Service
// Now supplies the time; nil means time.Now.
Now func() time.Time
// Batch bounds the entries per transaction; zero means DefaultBatch.
Batch int
}
Service works on the trash can of one store.
func (*Service) Below ¶
func (s *Service) Below( ctx context.Context, dir string, deep bool, sees func(types.Item) bool, ) ([]Node, error)
Below lists the trash can's tree under dir ("" for its root): the direct children, or with deep every descendant, sorted by path.
sees filters the entries before the tree is derived from them, so a repository or folder shows only when an entry the caller sees lies at or below it. A nil sees shows every entry, for an administrator.
func (*Service) Children ¶
func (s *Service) Children( ctx context.Context, dir string, sees func(types.Item) bool, ) ([]Child, error)
Children lists what the trash can shows directly inside dir: the repositories with trashed items at its root ("" for dir), and below a repository the next path segment of every trashed path, as Artifactory's auto-trashcan repository does. sees filters as for Below.
func (*Service) Clean ¶
Clean purges every entry trashed from repoKey at or below prefix and returns how many it purged.
func (*Service) Entries ¶
Entries returns every entry trashed from repoKey at or below prefix ("" for the whole repository; a repoKey of "" for the whole trash can).
func (*Service) Keep ¶
Keep records every item of c's own content as trashed by by, as a delete of the repository's root through the item service records them, so a deleted repository can be restored. It changes nothing else: call it inside the transaction that then deletes the items, which hands each file's blob reference to its entry instead of releasing it. It returns how many references the entries hold per sha256, for that delete to release only the ones no entry took over.
It pages through the items rather than listing them at once, so a large repository costs one page of memory, not all of it.
func (*Service) PurgeExpired ¶
PurgeExpired purges the entries older than the retention period and returns how many it purged. It purges nothing while the trash can is off, as 7.x's small garbage collection, which expires the trash can, does not run then (KB "The complete Garbage Collection Guide"; 6.20's TrashServiceImpl.getGCCandidatesFromTrash). What was trashed before the trash can was turned off stays until it is turned on again and the entry expires, or until clean or empty removes it.
func (*Service) Restore ¶
func (s *Service) Restore( ctx context.Context, repoKey, from string, dst Destination, by string, permit func(types.Item) bool, ) (int, error)
Restore moves the newest trashed copy of everything at or below repoKey/from back into dst, each file with the sidecars its delete removed (format.SidecarKeeper), and returns how many items it restored. Each batch is one transaction that recreates the items and drops their entries; a conflict stops the restore with the earlier batches kept.
permit is asked about every selected item, at its original path, before any batch moves, so one refusal restores nothing and answers ErrNotPermitted. Asking per batch instead would leave the batches before the refused item restored. A nil permit allows every item, for a caller such as an administrator that may restore anything.