trash

package
v0.4.101 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package trash keeps what the dashboard's Files deletes for thirty days, in the trash of the disk it was on. The layout is freedesktop.org's (.Trash-<uid>/files and .Trash-<uid>/info at the disk's mount point): moving there is a rename, even for a large folder, and Linux file managers see the same trash.

Index

Constants

View Source
const Retention = 30 * 24 * time.Hour

Retention is how long an item stays in the trash before Purge removes it.

Variables

View Source
var (
	// ErrUnavailable: the item cannot go to the trash (a read-only disk, a
	// trash folder that is not ours, already in the trash); only a permanent
	// delete removes it.
	ErrUnavailable = errors.New("cannot be moved to the trash")
	// ErrNotFound: no such item in that trash.
	ErrNotFound = errors.New("not in the trash")
	// ErrOutsideDisk: a trash entry says it came from another disk; it is not
	// restored there.
	ErrOutsideDisk = errors.New("the trash entry points outside its disk")
)

Functions

func Delete

func Delete(top, name string, allowed Allowed) error

Delete removes an item for good.

func Empty

func Empty(allowed Allowed) (int, error)

Empty removes every allowed item of every trash. With allowed nil, entries left without their info go too.

func Purge

func Purge(cutoff time.Time) (int, error)

Purge removes the items deleted before cutoff from every trash, and the infos whose item is gone. An item without a readable date stays.

func Put

func Put(path string, now time.Time) error

Put moves path into the trash of its disk, as deleted at now.

func Restore

func Restore(top, name string, allowed Allowed, check func(path string) (string, error)) (string, error)

Restore moves an item back where it was, and returns where it is now: under another name when that one is taken ("photo (restored).jpg"), its folder made again when it is gone. check vets the place first (the file API's roots), and may give it its canonical spelling. The way there is followed from the mount point without links: a folder replaced by a link is refused.

Types

type Allowed

type Allowed func(path string) bool

Allowed reports whether the item that was at path may be listed, restored or deleted; nil allows everything.

type Item

type Item struct {
	Trash     string    `json:"trash"` // the mount point that holds the trash
	Name      string    `json:"name"`  // its name in the trash
	Path      string    `json:"path"`  // where it was deleted from
	DeletedAt time.Time `json:"deleted_at"`
	IsDir     bool      `json:"is_dir"`
	Size      int64     `json:"size"`
}

Item is one entry of a trash.

func List

func List() []Item

List is every item of every trash, the last deleted first.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL