Skip to content

Commit

Permalink
warn on directory walking errors instead of exiting (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepianka authored Nov 14, 2024
1 parent efcce5a commit 5178825
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
7 changes: 7 additions & 0 deletions cmd/drsz/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ func cli() Config {

csvArg := flag.String("o", "none", "save output to the provided CSV filepath")
concArg := flag.Int("c", 0, "number of concurrent directory size searches")
verArg := flag.Bool("v", false, "program version")
flag.Parse()

if *verArg {
fmt.Printf("drsz %s\n", drsz.Version)
os.Exit(0)
}

rootArg := flag.Arg(0)

// validate root arg
Expand Down
3 changes: 3 additions & 0 deletions constant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package drsz

const Version = "v2.0"
15 changes: 10 additions & 5 deletions drsz.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,6 @@ func (r *RootDir) CalcStats(concLimit uint8) error {

wg.Wait() // wait for goroutines to finish

if len(errors) != 0 {
// errors encountered, just return first one for simplicity for now
return fmt.Errorf("encountered %d errors, the first being: %v", len(errors), errors[0])
}

// print results using tabwriter
tw := tabwriter.NewWriter(os.Stdout, 0, 0, 5, ' ', 0)
// add blank row
Expand All @@ -205,6 +200,16 @@ func (r *RootDir) CalcStats(concLimit uint8) error {
for _, d := range r.TopDirs {
fmt.Fprintf(tw, "%s\t%s\t%s\n", d.Name(), d.SizeString(), d.LastModified.Local().String())
}

// print errors and their associated directories
if len(errors) != 0 {
fmt.Fprintln(tw, "")
fmt.Fprintln(tw, "***WARN*** Processing failed on the following directories ***WARN***")
for i, err := range errors {
fmt.Fprintf(tw, "%d: %v\n", i+1, err)
}
}

tw.Flush()

return nil
Expand Down

0 comments on commit 5178825

Please sign in to comment.