Skip to content

Commit

Permalink
Exclude some top-level directories by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementNerma committed Apr 7, 2024
1 parent ac889df commit 5d1b2a9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trasher"
version = "3.2.0"
version = "3.2.1"
authors = ["Clément Nerma <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
Expand Down
23 changes: 22 additions & 1 deletion src/fsutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ const TRASH_DIR_NAME: &str = ".trasher";
/// Name of the transfer directory in the trash
pub const TRASH_TRANSFER_DIRNAME: &str = ".#PARTIAL";

/// Directories to never create a trash directory for
pub static ALWAYS_EXCLUDE_DIRS: &[&str] = &[
"/bin",
"/boot",
"/dev",
"/lost+found",
"/usr",
"/proc",
"/sbin",
"/snap",
"/sys",
];

/// Determine path to the trash directory for a given item and create it if required
pub fn determine_trash_dir_for(item: &Path, config: &Config) -> Result<PathBuf> {
debug!("Determining trasher directory for item: {}", item.display());
Expand All @@ -41,7 +54,7 @@ pub fn determine_mountpoint_for(item: &Path, config: &Config) -> Result<Option<P
let item = fs::canonicalize(item)
.with_context(|| format!("Failed to canonicalize item path: {}\n\nTip: you can exclude this directory using --exclude.", item.display()))?;

let exclude = config
let mut exclude = config
.exclude
.iter()
.filter_map(|dir| {
Expand All @@ -58,6 +71,14 @@ pub fn determine_mountpoint_for(item: &Path, config: &Config) -> Result<Option<P
})
.collect::<Result<Vec<_>, _>>()?;

// Add some directories to always exclude
exclude.extend(
ALWAYS_EXCLUDE_DIRS
.iter()
.map(Path::new)
.map(Path::to_owned),
);

let mountpoints = mountpaths().context("Failed to list system mountpoints")?;

for mountpoint in &mountpoints {
Expand Down

0 comments on commit 5d1b2a9

Please sign in to comment.