Skip to content

Commit

Permalink
Fix for fmt and gocyclo
Browse files Browse the repository at this point in the history
  • Loading branch information
otiai10 committed Nov 9, 2022
1 parent 8749e2c commit fa129b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,9 @@ func TestOptions_CopyRateLimit(t *testing.T) {

start := time.Now()
err = Copy("test/data/case16", "test/data.copy/case16", opt)
elasped := time.Since(start)
elapsed := time.Since(start)
Expect(t, err).ToBe(nil)
Expect(t, elasped > 5*time.Second).ToBe(true)
Expect(t, elapsed > 5*time.Second).ToBe(true)
}

type SleepyReader struct {
Expand Down
33 changes: 21 additions & 12 deletions copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,10 @@ func fcopy(src, dest string, info os.FileInfo, opt Options) (err error) {
// and pass everything to "copy" recursively.
func dcopy(srcdir, destdir string, info os.FileInfo, opt Options) (err error) {

_, err = os.Stat(destdir)
if err == nil && opt.OnDirExists != nil && destdir != opt.intent.dest {
switch opt.OnDirExists(srcdir, destdir) {
case Replace:
if err := os.RemoveAll(destdir); err != nil {
return err
}
case Untouchable:
return nil
} // case "Merge" is default behaviour. Go through.
} else if err != nil && !os.IsNotExist(err) {
return err // Unwelcome error type...!
if skip, err := onDirExists(opt, srcdir, destdir); err != nil {
return err
} else if skip {
return nil
}

// Make dest dir with 0755 so that everything writable.
Expand Down Expand Up @@ -181,6 +173,23 @@ func dcopy(srcdir, destdir string, info os.FileInfo, opt Options) (err error) {
return
}

func onDirExists(opt Options, srcdir, destdir string) (bool, error) {
_, err := os.Stat(destdir)
if err == nil && opt.OnDirExists != nil && destdir != opt.intent.dest {
switch opt.OnDirExists(srcdir, destdir) {
case Replace:
if err := os.RemoveAll(destdir); err != nil {
return false, err
}
case Untouchable:
return true, nil
} // case "Merge" is default behaviour. Go through.
} else if err != nil && !os.IsNotExist(err) {
return true, err // Unwelcome error type...!
}
return false, nil
}

func onsymlink(src, dest string, opt Options) error {
switch opt.OnSymlink(src) {
case Shallow:
Expand Down

0 comments on commit fa129b1

Please sign in to comment.