Skip to content

Commit

Permalink
compare: before starting, check that new dir also exists
Browse files Browse the repository at this point in the history
  • Loading branch information
joonas-fi committed Jun 26, 2024
1 parent 4c1c437 commit 6777d8a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/dupfinder/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package main

import (
"crypto/sha1" // nolint:gosec // ok for non-secure comparisons
"errors"
"fmt"
"io"
"os"
"path/filepath"

"github.com/function61/gokit/fileexists"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -57,6 +59,12 @@ func compare(olddir string, newdir string) error {

r.info(fmt.Sprintf("olddir<%s> newdir<%s>", olddir, newdir))

// quick sanity check to see that new dir also exists. if we checked it after walking,
// olddir, we might have lots of wasted work
if newdirExists, err := fileexists.Exists(newdir); !newdirExists || err != nil {
return errors.New("newdir does not exist, or error accessing it")
}

r.info("Scanning olddir")

if err := filepath.Walk(olddir, stopOnErrors(func(path string, info os.FileInfo) error {
Expand Down

0 comments on commit 6777d8a

Please sign in to comment.