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
- Variables
- func Delete(top, name string, allowed Allowed) error
- func Empty(allowed Allowed) (int, error)
- func Purge(cutoff time.Time) (int, error)
- func Put(path string, now time.Time) error
- func Restore(top, name string, allowed Allowed, check func(path string) (string, error)) (string, error)
- type Allowed
- type Item
Constants ¶
const Retention = 30 * 24 * time.Hour
Retention is how long an item stays in the trash before Purge removes it.
Variables ¶
var ( // 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 Empty ¶
Empty removes every allowed item of every trash. With allowed nil, entries left without their info go too.
func Purge ¶
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 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 ¶
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.