Commit 5513fa7b authored by Boris Mühmer's avatar Boris Mühmer
Browse files

added special walk and locking

parent fd1f1eb3
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -7,7 +7,10 @@ import (
	"io"
	"log"
	"os"
	"path/filepath"
	"sync"

	//"path/filepath"
	"github.com/MichaelTJones/walk"
)

var (
@@ -38,6 +41,8 @@ type Status struct {
	Contents            map[HashArray]FileDatas
}

var m sync.Mutex

// FindFiles searches for files at the specific path.
func FindFiles(path string) (*Status, error) {

@@ -45,7 +50,7 @@ func FindFiles(path string) (*Status, error) {

	status.Contents = make(map[HashArray]FileDatas, 0)

	err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
	err := walk.Walk(path, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			status.NumberOfErrors++
			return err
@@ -70,12 +75,14 @@ func FindFiles(path string) (*Status, error) {
			Info: info,
		}

		m.Lock()
		entries := status.Contents[hash]
		if entries == nil {
			entries = make(FileDatas, 0)
		}
		entries = append(entries, entry)
		status.Contents[hash] = entries
		m.Unlock()

		return nil
	})
@@ -113,5 +120,7 @@ func hashFile(filename string) (HashArray, error) {
		ha[i] = t[i]
	}

	//f.Close()

	return ha, nil
}