Code Monkey home page Code Monkey logo

wastebasket's Introduction

Wastebasket

CI codecoverage

Wastebasket is a go library / CLI tool allowing you to interact with your system trashbin.

Dependencies

Golang

The library supports at least the 3 latest major Golang versions. Depending on your OS it might still work on an older version, but there are no guarantees.

Windows

There are no dependencies, it depends on the Shell32 API built into Windows.

No CGO required

Linux (Unix)

There are two (well, four) options you've got here. Wastebasket offers a native golang implementation of the FreeDesktop Trash specification.

Additionally, the custom implementation should also work for systems such as BSD and its derivatives. However, this has not been tested and I do not plan on doing so, simply because GitHub does not currently support running tests on any BSD derivatives.

If anyone is willing to host a custom runner (which I think is possible), then I'd be open to this though.

No CGO required

Mac OS

The only dependency is Finder, which is installed by default.

There are plans for a better implementation, that uses the Objective-C API provided by Mac OS, resulting in most likely much better performance.

No CGO required (Might change in the future)

Library usage

Grab it via

go get github.com/Bios-Marcel/wastebasket

and you are ready to go.

Minimal Go example that creates a file, deletes it and empties the trashbin:

package main

import (
    "fmt"
    "os"

    "github.com/Bios-Marcel/wastebasket"
)

func main() {
    os.WriteFile("test.txt", []byte("Test"), os.ModePerm)
    fmt.Println(wastebasket.Trash("test.txt"))
    wastebasket.Empty()
}

CLI usage

Wastebasket can also be used as a commandline interface. You can build executables for each subcommand (such as empty) separately, or build wastebasket as a whole.

In order to do so, run

go build ./cmd/CMD

where CMD is whichever command you want to build.

Autocompletion

The CLI offers autocompletion for flags and pre-defined arguments.

Bash; Write the following into your bash profile:

source <(wastebasket completion bash)

Additionally, completion is supported for zsh, powershell and fish. For information, see Cobra shell completions

Benchmarks

Run benchmarks using:

go test -bench=.

wastebasket's People

Contributors

bios-marcel avatar cdzombak avatar kkoreilly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

wastebasket's Issues

Implement lookup

APIL:

type TrashedFileInfo interface {
    AbsPath() string
    DeletionDate() time.Time
}

// Lookup checks whether there is any file with a matching path. The path can
// be relative or absolute. Since a path can be deleted multiple times,
// resulting in multiple trashed versions, the return value is an array. If
// the error is empty, there were no matches, in which case the `error` will
// be `nil`.
func Lookup(path string) ([]*TrashedFileInfo, error) {
    // ....
}

The interface TrashedFileInfo allows to have more concrete implementations, allowing the user to extract more information where required and possible, but still allow us to cross compile when using the bare minimum.

Linux build needs to be improved

Currently the linux unit tests are only tested against trash-cli as gio and gvfs-trash aren't available on Travis CI and i can't figure out why Cirlce CI can't find any commands on PATH.

Optimise batch deletion on Mac OS

I currently don't have access to any Mac OS machine, therefore no optimisations have been done here yet. We invoke finder N times, which is possibly rather slow.

Interesting for this purpose:

While Mac Driver doesn't implement this functionality, we might be able to contribute this.
However, additionally, we could potentially just rip out what we need.

On top of that, this will introduce Cgo, which we want to keep optional where we can.
Therefore, the bad tell "Finder" solution will probably persist.

Support batch delete

Currently, you'll have to call Trash multiple times, potentially causing a lot of overhead.
The function signature could simply be changed to Trash(path... string), which would still be backwards compatible. The errors would potentially changed, as there can be more than one.

Whether each tool invoked supports multifile, still needs to be figured out.

Remove unneeded println from wastebasket_windows.go

Hi, can you please remove the fmt.Println(psCommand) line in the wastebasket_windows.go file?
I am using your repo for a command line app which needs StdOut and StdErr to be clean, and that println statement pollutes it.
Thanks!

Invoking PowerShell opens a command line window

Write better tests for Trash(...)

Currently all we check is whether the file is gone, but part of successful trashing is also the possibility of a successful restoration.

This depends on #14

This is labeled as a bug, as we have to make sure the code is correct.

Write tests for Empty()

Currently we do not verify that calling Empty() actually empties the trashbin(s).

In order to do so, we need to implement either #8 or #13 first, even though #13 is preferred.

This is considered a bug, as it prevents secure usage of the library.

Implement listing

Support listing all trashed files from all trash bins that are readable.

API:

func List() ([]*TrashedFileInfo, error) {
    // ....
}

Depends on #13

Implement restore

Implement function to restore a file:

API:

// Restore will move the given file out of the trashbin back to its location
// before it was trashed. The path can be relative or absolute. If there is no
// matching file in any of the trashbins, an error is returned.
func Restore(path string) error {
    // ....
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.