Documentation
¶
Index ¶
- Constants
- func EnsureTrashDir(trashDir string) error
- func FilesPath(trashDir, name string) string
- func GetAllTrashDirs() ([]string, error)
- func GetTrashDirForPath(path string) (string, error)
- func HomeTrashDir() (string, error)
- func SameFilesystem(path1, path2 string) (bool, error)
- func SetMountsFilePath(path string)
- func TrashInfoPath(trashDir, name string) string
- func TrashVolumeName(trashDir string) string
- func VolumeTrashDir(path string) (string, error)
- type ItemType
- type Manager
- func (m *Manager) Delete(trashName string) error
- func (m *Manager) DeleteFromDir(trashDir, trashName string) error
- func (m *Manager) Empty() error
- func (m *Manager) EmptyDirOlderThan(trashDir string, days int) error
- func (m *Manager) EmptyOlderThan(days int) error
- func (m *Manager) FindByName(name string) ([]TrashItem, error)
- func (m *Manager) GetLargest(n int) ([]TrashItem, error)
- func (m *Manager) GetLast() (*TrashItem, error)
- func (m *Manager) GetOldestAndNewest() (oldest, newest time.Time, err error)
- func (m *Manager) List() ([]TrashItem, error)
- func (m *Manager) ListFromDir(trashDir string) ([]TrashItem, error)
- func (m *Manager) Move(path string) error
- func (m *Manager) Restore(trashName string, overwrite bool) error
- func (m *Manager) RestoreFromDir(trashDir, trashName string, overwrite bool) error
- func (m *Manager) SetVerboseCallback(cb VerboseCallback)
- func (m *Manager) Status() (count int, totalSize int64, err error)
- func (m *Manager) StatusFromDir(trashDir string) (count int, totalSize int64, err error)
- type TrashInfo
- type TrashItem
- type TrashRoot
- func (tr *TrashRoot) Close() error
- func (tr *TrashRoot) CountFiles(name string) (int, error)
- func (tr *TrashRoot) CreateFiles(name string) (*os.File, error)
- func (tr *TrashRoot) CreateInfo(name string) (*os.File, error)
- func (tr *TrashRoot) FilesPath(name string) string
- func (tr *TrashRoot) InfoPath(name string) string
- func (tr *TrashRoot) LstatFiles(name string) (os.FileInfo, error)
- func (tr *TrashRoot) LstatInfo(name string) (os.FileInfo, error)
- func (tr *TrashRoot) MkdirFiles() error
- func (tr *TrashRoot) MkdirInfo() error
- func (tr *TrashRoot) OpenFiles(name string) (*os.File, error)
- func (tr *TrashRoot) OpenInfo(name string) (*os.File, error)
- func (tr *TrashRoot) ReadDirFiles() ([]os.DirEntry, error)
- func (tr *TrashRoot) RemoveAllFiles(name string) error
- func (tr *TrashRoot) RemoveFiles(name string) error
- func (tr *TrashRoot) RemoveInfo(name string) error
- type VerboseCallback
Constants ¶
const TimeFormat = time.RFC3339
TimeFormat is the XDG Trash spec time format
Variables ¶
This section is empty.
Functions ¶
func EnsureTrashDir ¶
EnsureTrashDir creates the trash directory structure if it doesn't exist
func GetAllTrashDirs ¶
GetAllTrashDirs returns all trash directories that exist This includes home trash and any volume trash directories
func GetTrashDirForPath ¶
GetTrashDirForPath returns the appropriate trash directory for a given path
func HomeTrashDir ¶
HomeTrashDir returns the default XDG trash directory
func SameFilesystem ¶
SameFilesystem checks if two paths are on the same filesystem
func SetMountsFilePath ¶ added in v0.10.0
func SetMountsFilePath(path string)
SetMountsFilePath sets the path for mount points file (primarily for testing)
func TrashInfoPath ¶
TrashInfoPath returns the path to the .trashinfo file for a given trash name
func TrashVolumeName ¶ added in v0.12.0
TrashVolumeName returns a user-facing name for a trash directory's volume.
func VolumeTrashDir ¶
VolumeTrashDir returns the trash directory for a given path's volume For cross-device files, use $VOLUME/.Trash-$UID/
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles trash operations
func (*Manager) Delete ¶ added in v0.7.0
Delete permanently removes a file from trash (no recovery possible)
func (*Manager) DeleteFromDir ¶ added in v0.7.0
DeleteFromDir deletes from a specific trash directory
func (*Manager) EmptyDirOlderThan ¶
func (*Manager) EmptyOlderThan ¶
EmptyOlderThan clears items older than days days from all directories
func (*Manager) FindByName ¶
FindByName finds items in trash matching a name (supports partial match)
func (*Manager) GetLargest ¶
GetLargest returns the N largest items in trash
func (*Manager) GetOldestAndNewest ¶
GetOldestAndNewest returns the oldest and newest deletion dates
func (*Manager) ListFromDir ¶
ListFromDir returns items from a specific trash directory
func (*Manager) RestoreFromDir ¶
RestoreFromDir restores from a specific trash directory
func (*Manager) SetVerboseCallback ¶ added in v0.6.0
func (m *Manager) SetVerboseCallback(cb VerboseCallback)
type TrashInfo ¶
type TrashInfo struct {
Path string // Original absolute path
DeletionDate time.Time // When the file was trashed
}
TrashInfo represents the content of a .trashinfo file
func ParseTrashInfo ¶
ParseTrashInfo reads and parses a .trashinfo file
func ParseTrashInfoFromRoot ¶ added in v0.4.3
ParseTrashInfoFromRoot reads and parses a .trashinfo file using TrashRoot. This is traversal-resistant - the file must be within the trash root.
func (*TrashInfo) WriteExclusive ¶
WriteExclusive writes the TrashInfo to a .trashinfo file atomically using O_EXCL Returns os.ErrExist if the file already exists
type TrashItem ¶
type TrashItem struct {
Name string // Name in trash
OriginalPath string // Original absolute path
DeletionDate time.Time // When it was trashed
Size int64 // Size in bytes
Mode os.FileMode // File mode/type
IsDir bool // Is directory
TrashDir string // Trash directory containing this item
FileCount int // Number of files (for directories, includes nested files)
}
TrashItem represents a file in the trash
func (TrashItem) TypeString ¶ added in v0.11.0
TypeString returns a human-readable string of the item type
func (TrashItem) VolumeName ¶ added in v0.12.0
VolumeName returns a user-facing name for the volume containing the item.
type TrashRoot ¶ added in v0.4.3
type TrashRoot struct {
// contains filtered or unexported fields
}
TrashRoot provides os.Root-based access to trash directory. All operations are traversal-resistant - symlinks and ".." cannot escape the root.
func OpenTrashRoot ¶ added in v0.4.3
OpenTrashRoot opens a trash directory for os.Root-based operations. The trashDir must be an absolute path to the trash directory root (e.g., ~/.local/share/Trash or /volume/.Trash-$UID).
func (*TrashRoot) CountFiles ¶ added in v0.11.0
CountFiles returns the number of files in a trashed item. If it's a directory, it recursively counts all files inside.
func (*TrashRoot) CreateFiles ¶ added in v0.4.3
CreateFiles creates a new file in files/ directory.
func (*TrashRoot) CreateInfo ¶ added in v0.4.3
CreateInfo creates a new trashinfo file in info/ directory.
func (*TrashRoot) FilesPath ¶ added in v0.4.3
FilesPath returns the relative path for a file in the files/ directory.
func (*TrashRoot) InfoPath ¶ added in v0.4.3
InfoPath returns the relative path for a trashinfo file in the info/ directory.
func (*TrashRoot) LstatFiles ¶ added in v0.4.3
LstatFiles returns FileInfo for a file in files/ directory. Uses os.Root.Lstat - traversal-resistant, does not follow symlinks.
func (*TrashRoot) LstatInfo ¶ added in v0.4.3
LstatInfo returns FileInfo for a trashinfo file in info/ directory.
func (*TrashRoot) MkdirFiles ¶ added in v0.4.3
MkdirFiles creates files/ directory.
func (*TrashRoot) OpenFiles ¶ added in v0.4.3
OpenFiles opens a file in files/ directory for reading.
func (*TrashRoot) OpenInfo ¶ added in v0.4.3
OpenInfo opens a trashinfo file in info/ directory for reading.
func (*TrashRoot) ReadDirFiles ¶ added in v0.4.3
ReadDirFiles reads the files/ directory.
func (*TrashRoot) RemoveAllFiles ¶ added in v0.4.3
RemoveAllFiles recursively removes a file or directory from files/. Unlike os.RemoveAll, this uses os.Root operations which are traversal-resistant - symlinks cannot escape the root.
func (*TrashRoot) RemoveFiles ¶ added in v0.4.3
RemoveFiles removes a file from files/ directory.
func (*TrashRoot) RemoveInfo ¶ added in v0.4.3
RemoveInfo removes a trashinfo file from info/ directory.