wip
Signed-off-by: Brian McGee <brian@bmcgee.ie>
This commit is contained in:
parent
12e795acf1
commit
efdfe9e808
8
cache/cache.go
vendored
8
cache/cache.go
vendored
|
@ -260,19 +260,17 @@ func ChangeSet(ctx context.Context, walker walk.Walker, filesCh chan<- *walk.Fil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is used to record updated cache information for the specified list of paths.
|
// Update is used to record updated cache information for the specified list of paths.
|
||||||
func Update(files []*walk.File) (int, error) {
|
func Update(files []*walk.File) error {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
logger.Infof("finished processing %v paths in %v", len(files), time.Since(start))
|
logger.Infof("finished processing %v paths in %v", len(files), time.Since(start))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if len(files) == 0 {
|
if len(files) == 0 {
|
||||||
return 0, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var changes int
|
return db.Update(func(tx *bolt.Tx) error {
|
||||||
|
|
||||||
return changes, db.Update(func(tx *bolt.Tx) error {
|
|
||||||
bucket := tx.Bucket([]byte(pathsBucket))
|
bucket := tx.Bucket([]byte(pathsBucket))
|
||||||
|
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
|
|
|
@ -214,17 +214,9 @@ func updateCache(ctx context.Context) func() error {
|
||||||
return func() error {
|
return func() error {
|
||||||
batch := make([]*walk.File, 0, BatchSize)
|
batch := make([]*walk.File, 0, BatchSize)
|
||||||
|
|
||||||
var changes int
|
|
||||||
|
|
||||||
processBatch := func() error {
|
processBatch := func() error {
|
||||||
if Cli.NoCache {
|
if err := cache.Update(batch); err != nil {
|
||||||
changes += len(batch)
|
return err
|
||||||
} else {
|
|
||||||
count, err := cache.Update(batch)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
changes += count
|
|
||||||
}
|
}
|
||||||
batch = batch[:0]
|
batch = batch[:0]
|
||||||
return nil
|
return nil
|
||||||
|
@ -253,7 +245,7 @@ func updateCache(ctx context.Context) func() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if Cli.FailOnChange && changes != 0 {
|
if Cli.FailOnChange && stats.Value(stats.Formatted) != 0 {
|
||||||
return ErrFailOnChange
|
return ErrFailOnChange
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -245,27 +245,26 @@ func TestChangeWorkingDirectory(t *testing.T) {
|
||||||
assertStats(t, as, out, 31, 31, 31, 0)
|
assertStats(t, as, out, 31, 31, 31, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
func TestFailOnChange(t *testing.T) {
|
||||||
//func TestFailOnChange(t *testing.T) {
|
as := require.New(t)
|
||||||
// as := require.New(t)
|
|
||||||
//
|
tempDir := test.TempExamples(t)
|
||||||
// tempDir := test.TempExamples(t)
|
configPath := tempDir + "/echo.toml"
|
||||||
// configPath := tempDir + "/echo.toml"
|
|
||||||
//
|
// test without any excludes
|
||||||
// // test without any excludes
|
cfg := config2.Config{
|
||||||
// cfg := config2.Config{
|
Formatters: map[string]*config2.Formatter{
|
||||||
// Formatters: map[string]*config2.Formatter{
|
"touch": {
|
||||||
// "echo": {
|
Command: "touch",
|
||||||
// Command: "echo",
|
Includes: []string{"*"},
|
||||||
// Includes: []string{"*"},
|
},
|
||||||
// },
|
},
|
||||||
// },
|
}
|
||||||
// }
|
|
||||||
//
|
test.WriteConfig(t, configPath, cfg)
|
||||||
// test.WriteConfig(t, configPath, cfg)
|
_, err := cmd(t, "--fail-on-change", "--config-file", configPath, "--tree-root", tempDir)
|
||||||
// _, err := cmd(t, "--fail-on-change", "--config-file", configPath, "--tree-root", tempDir)
|
as.ErrorIs(err, ErrFailOnChange)
|
||||||
// as.ErrorIs(err, ErrFailOnChange)
|
}
|
||||||
//}
|
|
||||||
|
|
||||||
func TestBustCacheOnFormatterChange(t *testing.T) {
|
func TestBustCacheOnFormatterChange(t *testing.T) {
|
||||||
as := require.New(t)
|
as := require.New(t)
|
||||||
|
|
Reference in New Issue
Block a user