Skip to content

Commit

Permalink
Stop walking after finding path
Browse files Browse the repository at this point in the history
  • Loading branch information
minodisk committed Feb 5, 2016
1 parent cde9858 commit 2fb8cbc
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions model/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package model
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -197,15 +198,13 @@ func (post Post) findPath() (path string, err error) {
if err != nil {
return
}
found := false
filepath.Walk(dir, func(p string, info os.FileInfo, e error) (err error) {

found := errors.New("found")
err = filepath.Walk(dir, func(p string, info os.FileInfo, e error) (err error) {
if e != nil {
err = e
return
}
if found {
return filepath.SkipDir
}
if info.IsDir() {
return
}
Expand All @@ -220,11 +219,13 @@ func (post Post) findPath() (path string, err error) {
}
if postInLocal.ID == post.ID {
path = p
found = true
return filepath.SkipDir
return found
}
return
})
if err == found {
err = nil
}
return
}

Expand Down

0 comments on commit 2fb8cbc

Please sign in to comment.