2017-05-15 17:13:34 -04:00
|
|
|
package fsutil
|
|
|
|
|
|
|
|
import (
|
2018-06-08 21:07:42 -04:00
|
|
|
"context"
|
2017-09-29 06:32:26 -04:00
|
|
|
"hash"
|
2017-05-15 17:13:34 -04:00
|
|
|
"os"
|
2018-10-05 05:05:42 -04:00
|
|
|
|
2020-02-12 09:57:13 -05:00
|
|
|
"github.com/pkg/errors"
|
2018-10-05 05:05:42 -04:00
|
|
|
"github.com/tonistiigi/fsutil/types"
|
2017-05-15 17:13:34 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type walkerFn func(ctx context.Context, pathC chan<- *currentPath) error
|
|
|
|
|
|
|
|
func Changes(ctx context.Context, a, b walkerFn, changeFn ChangeFunc) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type HandleChangeFn func(ChangeKind, string, os.FileInfo, error) error
|
|
|
|
|
2018-10-05 05:05:42 -04:00
|
|
|
type ContentHasher func(*types.Stat) (hash.Hash, error)
|
2017-09-29 06:32:26 -04:00
|
|
|
|
2020-11-17 05:31:07 -05:00
|
|
|
func getWalkerFn(root string) walkerFn {
|
2017-05-15 17:13:34 -04:00
|
|
|
return func(ctx context.Context, pathC chan<- *currentPath) error {
|
2020-11-17 05:31:07 -05:00
|
|
|
return errors.Wrap(Walk(ctx, root, nil, func(path string, f os.FileInfo, err error) error {
|
2017-05-15 17:13:34 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-12 09:57:13 -05:00
|
|
|
stat, ok := f.Sys().(*types.Stat)
|
|
|
|
if !ok {
|
|
|
|
return errors.Errorf("%T invalid file without stat information", f.Sys())
|
|
|
|
}
|
|
|
|
|
2017-05-15 17:13:34 -04:00
|
|
|
p := ¤tPath{
|
|
|
|
path: path,
|
2020-02-12 09:57:13 -05:00
|
|
|
stat: stat,
|
2017-05-15 17:13:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return ctx.Err()
|
|
|
|
case pathC <- p:
|
|
|
|
return nil
|
|
|
|
}
|
2020-11-17 05:31:07 -05:00
|
|
|
}), "failed to walk")
|
2017-05-15 17:13:34 -04:00
|
|
|
}
|
|
|
|
}
|
2017-09-29 06:32:26 -04:00
|
|
|
|
|
|
|
func emptyWalker(ctx context.Context, pathC chan<- *currentPath) error {
|
|
|
|
return nil
|
|
|
|
}
|