deepclean

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2023 License: MIT Imports: 4 Imported by: 0

README

deepclean

be disrespectful to filesystem dirt ✨🗑✨

I often have a bunch of junk dependency files sitting around in my source folder that I don't actually need. Periodically I want to clean them up on inactive projects, as I recently discovered when I wanted to transfer my src dir to a new computer, and it was taking forever due to over half a million junk files in node_modules directories.

Currently looks for the following:

  • .bundle (Ruby Bundler)
  • node_modules (NodeJS NPM)
  • target (Rust Cargo, Scala SBT)

However it's easy to overrride this list.

Deepclean is very fast -- it will take advantage of multiple cores on your machine by gathering statistics for matched directories in parallel.

Nothing is actually deleted at the moment due to paranoia, just surfaced in the UI so the user can decide on their own how to handle.

TODO: only recommend these for deletion if they are .gitignore'd, not tracked in git.

Installation

Grab a compiled binary from the releases page, or on macOS with homebrew you can brew install mroth/formulas/deepclean.

Usage

Usage: deepclean [options] [dir]

Options:
  -sort
      sort output
  -target string
      dirs to scan for (default "node_modules,.bundle,target")

Will scan the current directory or dir if provided.

Errata

Why not find?

It is possible to do something similar with a monster shell command.

find . \( \
      -name 'node_modules' \
      -o -name '.bundle' \
      -o -name 'target' \
    \)  -prune \
    -exec sh -c 'echo "$(find "$0" | wc -l)\t$(du -sh "$0")"' {} \;

On my machine that takes about ~3.5sec total. In contrast deepclean is ~670ms. I'm on a fairly fast machine[*] and don't have a super large src dir. I imagine that these numbers should scale similarly on very large directories or slower disks.

[*]: 8-core Xeon, 2xSSD array in RAID-0.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DirStats

type DirStats struct {
	Files uint64
	Bytes uint64
}

DirStats contains metadata for disk usage of a parent directory.

func Aggregate

func Aggregate(rs ...Result) DirStats

Aggregate totals the DirStats from multiple Results.

func Stat

func Stat(path string) (DirStats, error)

Stat walks the directory at path collecting the aggregate DirStats.

func (DirStats) Add

func (a DirStats) Add(b DirStats) DirStats

Add combines two DirStats together to total their results.

type Result

type Result struct {
	Path  string
	Stats DirStats
}

Result wraps DirStats with the Path that was used to stat the data.

It is used whenever a task may stat multiple directories and return the results out-of-order and/or asynchronously.

type Scanner

type Scanner struct {
	C <-chan Result
	// contains filtered or unexported fields
}

Scanner contains fields to access the results of an ongoing Scan.

If the underlying filepath Walk encounters a fatal error, the results channel will be closed and Err() will return a non-nil value. Always drain (*Scanner).C prior to checking Err().

If the underlying filepath Walk encounters a non-fatal error, the walked directory will be silently skipped (for now).

func Scan

func Scan(path string, targets []string) *Scanner

Scan walks the path searching for directories matching the targets strings, and then initiates a DirStats on the directory, returning the Results as they occur on the returned channel.

func (Scanner) Err

func (s Scanner) Err() error

Err returns the error status of the underlying filepath Walk performed by the scanner. This will only be set once the Walk has exited, indicated by the Results channel being closed.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL