summaryrefslogtreecommitdiff
path: root/doWalk.go
blob: 913aea4f215d8f0a501bf961ba68fa48dda0c4a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main

import (
	"errors"
	"os"
	"path/filepath"
	"strings"

	"go.wit.com/lib/protobuf/zoopb"
	"go.wit.com/log"
)

var errStopWalk = errors.New("walk stopped by user")

func doWalk() (string, error) {
	os.Chdir(me.pb.BaseDir)

	var counter int
	err := filepath.Walk("pool", func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		if !info.IsDir() && strings.HasSuffix(info.Name(), ".deb") {
			found := me.pb.FindByFilename(path)
			if found != nil {
				return nil
			}
			counter += 1
			// if counter > 10 {
			// 	return errStopWalk
			// }
			newdeb := new(zoopb.Package)
			newdeb.Filename = path
			me.pb.AppendByFilename(newdeb)
			log.Info("added new", path)
		}
		return nil
	})

	if counter > 0 {
		me.pb.Save()
	}
	s := log.Sprintf("add %d new packages. Total packages.Len()=%d", counter, me.pb.Len())
	return s, err
}