Skip to content

errmayank/junkyard

Repository files navigation

Junkyard

Cross-platform system trash API.

Usage

Discard

Move a single path to the trash:

use junkyard::discard;

std::fs::write("file.txt", b"junk")?;

let item = discard("file.txt")?;

assert_eq!(item.original_name(), "file.txt");
assert!(!std::fs::exists("file.txt")?);

Move multiple paths at once:

use junkyard::discard_all;

std::fs::write("first.txt", b"first")?;
std::fs::create_dir("directory")?;
std::fs::write("directory/second.txt", b"second")?;

let items = discard_all(["first.txt", "directory"])?;

assert_eq!(items.len(), 2);
assert_eq!(items[0].original_name(), "first.txt");
assert_eq!(items[1].original_name(), "directory");

All paths are resolved before any item is moved to the trash. If resolution fails, no items are moved. Once trashing begins, paths are processed in input order. If a later operation fails, earlier items may already be in the trash.

Symbolic links are moved as links; their targets are left in place.

Notes

  • Linux: Follows the Freedesktop trash specification.
  • macOS: Uses NSFileManager.
  • Windows: Uses the Shell Recycle Bin APIs.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Any contribution intentionally submitted for inclusion in this repository by you shall be dual-licensed as above, without any additional terms or conditions.

About

Cross-platform system trash API.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Contributors