mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-23 03:18:59 +00:00
lib/scanner: Save one stat call per file (#6715)
This commit is contained in:
parent
6b4fe5c063
commit
0b65a616ba
@ -265,7 +265,7 @@ func (w *walker) walkAndHashFiles(ctx context.Context, toHashChan chan<- protoco
|
|||||||
|
|
||||||
if ignoredParent == "" {
|
if ignoredParent == "" {
|
||||||
// parent isn't ignored, nothing special
|
// parent isn't ignored, nothing special
|
||||||
return w.handleItem(ctx, path, toHashChan, finishedChan, skip)
|
return w.handleItem(ctx, path, info, toHashChan, finishedChan, skip)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Part of current path below the ignored (potential) parent
|
// Part of current path below the ignored (potential) parent
|
||||||
@ -274,17 +274,22 @@ func (w *walker) walkAndHashFiles(ctx context.Context, toHashChan chan<- protoco
|
|||||||
// ignored path isn't actually a parent of the current path
|
// ignored path isn't actually a parent of the current path
|
||||||
if rel == path {
|
if rel == path {
|
||||||
ignoredParent = ""
|
ignoredParent = ""
|
||||||
return w.handleItem(ctx, path, toHashChan, finishedChan, skip)
|
return w.handleItem(ctx, path, info, toHashChan, finishedChan, skip)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The previously ignored parent directories of the current, not
|
// The previously ignored parent directories of the current, not
|
||||||
// ignored path need to be handled as well.
|
// ignored path need to be handled as well.
|
||||||
if err = w.handleItem(ctx, ignoredParent, toHashChan, finishedChan, skip); err != nil {
|
// Prepend an empty string to handle ignoredParent without anything
|
||||||
return err
|
// appended in the first iteration.
|
||||||
}
|
for _, name := range append([]string{""}, strings.Split(rel, string(fs.PathSeparator))...) {
|
||||||
for _, name := range strings.Split(rel, string(fs.PathSeparator)) {
|
|
||||||
ignoredParent = filepath.Join(ignoredParent, name)
|
ignoredParent = filepath.Join(ignoredParent, name)
|
||||||
if err = w.handleItem(ctx, ignoredParent, toHashChan, finishedChan, skip); err != nil {
|
info, err = w.Filesystem.Lstat(ignoredParent)
|
||||||
|
// An error here would be weird as we've already gotten to this point, but act on it nonetheless
|
||||||
|
if err != nil {
|
||||||
|
w.handleError(ctx, "scan", ignoredParent, err, finishedChan)
|
||||||
|
return skip
|
||||||
|
}
|
||||||
|
if err = w.handleItem(ctx, ignoredParent, info, toHashChan, finishedChan, skip); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -294,16 +299,9 @@ func (w *walker) walkAndHashFiles(ctx context.Context, toHashChan chan<- protoco
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *walker) handleItem(ctx context.Context, path string, toHashChan chan<- protocol.FileInfo, finishedChan chan<- ScanResult, skip error) error {
|
func (w *walker) handleItem(ctx context.Context, path string, info fs.FileInfo, toHashChan chan<- protocol.FileInfo, finishedChan chan<- ScanResult, skip error) error {
|
||||||
info, err := w.Filesystem.Lstat(path)
|
|
||||||
// An error here would be weird as we've already gotten to this point, but act on it nonetheless
|
|
||||||
if err != nil {
|
|
||||||
w.handleError(ctx, "scan", path, err, finishedChan)
|
|
||||||
return skip
|
|
||||||
}
|
|
||||||
|
|
||||||
oldPath := path
|
oldPath := path
|
||||||
path, err = w.normalizePath(path, info)
|
path, err := w.normalizePath(path, info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.handleError(ctx, "normalizing path", oldPath, err, finishedChan)
|
w.handleError(ctx, "normalizing path", oldPath, err, finishedChan)
|
||||||
return skip
|
return skip
|
||||||
|
Loading…
Reference in New Issue
Block a user