mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-23 03:18:59 +00:00
Refactor: multiple-if to switch
This commit is contained in:
parent
f2459e61dd
commit
bed6155c79
@ -257,29 +257,22 @@ func (w *Walker) walkAndHashFiles(fchan, dchan chan protocol.FileInfo) filepath.
|
|||||||
return skip
|
return skip
|
||||||
}
|
}
|
||||||
|
|
||||||
// Index wise symlinks are always files, regardless of what the target
|
switch {
|
||||||
// is, because symlinks carry their target path as their content.
|
case info.Mode()&os.ModeSymlink == os.ModeSymlink:
|
||||||
if info.Mode()&os.ModeSymlink == os.ModeSymlink {
|
var shouldSkip bool
|
||||||
if shouldSkip, err := w.walkSymlink(absPath, relPath, dchan); err != nil {
|
shouldSkip, err = w.walkSymlink(absPath, relPath, dchan)
|
||||||
return err
|
if err == nil && shouldSkip {
|
||||||
} else if shouldSkip {
|
|
||||||
return skip
|
return skip
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case info.Mode().IsDir():
|
||||||
|
err = w.walkDir(relPath, info, mtime, dchan)
|
||||||
|
|
||||||
|
case info.Mode().IsRegular():
|
||||||
|
err = w.walkRegular(relPath, info, mtime, fchan)
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.Mode().IsDir() {
|
return err
|
||||||
if err := w.walkDir(relPath, info, mtime, dchan); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if info.Mode().IsRegular() {
|
|
||||||
if err := w.walkRegular(relPath, info, mtime, fchan); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,11 +370,14 @@ func (w *Walker) walkDir(relPath string, info os.FileInfo, mtime time.Time, dcha
|
|||||||
}
|
}
|
||||||
|
|
||||||
// walkSymlinks returns true if the symlink should be skipped, or an error if
|
// walkSymlinks returns true if the symlink should be skipped, or an error if
|
||||||
// we should stop walking altogether.
|
// we should stop walking altogether. filepath.Walk isn't supposed to
|
||||||
|
// transcend into symlinks at all, but there are rumours that this may have
|
||||||
|
// happened anyway under some circumstances, possibly Windows reparse points
|
||||||
|
// or something. Hence the "skip" return from this one.
|
||||||
func (w *Walker) walkSymlink(absPath, relPath string, dchan chan protocol.FileInfo) (skip bool, err error) {
|
func (w *Walker) walkSymlink(absPath, relPath string, dchan chan protocol.FileInfo) (skip bool, err error) {
|
||||||
// If the target is a directory, do NOT descend down there. This
|
// If the target is a directory, do NOT descend down there. This will
|
||||||
// will cause files to get tracked, and removing the symlink will
|
// cause files to get tracked, and removing the symlink will as a result
|
||||||
// as a result remove files in their real location.
|
// remove files in their real location.
|
||||||
if !symlinks.Supported {
|
if !symlinks.Supported {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user