-// WalkFunc walks a directory tree, uploads each file found and adds it to the
-// CollectionWriter.
-func (m *WalkUpload) WalkFunc(path string, info os.FileInfo, err error) error {
- if err != nil {
- return err
- }
-
- targetPath, targetInfo := path, info
- if info.Mode()&os.ModeSymlink != 0 {
- // Update targetpath/info to reflect the symlink
- // target, not the symlink itself
- targetPath, err = filepath.EvalSymlinks(path)
- if err != nil {
- return err
- }
- targetInfo, err = os.Stat(targetPath)
- if err != nil {
- return fmt.Errorf("stat symlink %q target %q: %s", path, targetPath, err)
- }
- if targetInfo.Mode()&os.ModeDir != 0 {
- // Symlinks to directories don't get walked, so do it
- // here. We've previously checked that they stay in
- // the output directory and don't result in an endless
- // loop.
- var rd []os.FileInfo
- rd, err = ioutil.ReadDir(path)
- if err != nil {
- return err
- }
- for _, ent := range rd {
- err = filepath.Walk(filepath.Join(path, ent.Name()), m.WalkFunc)
- }
- }
- }
-
- if targetInfo.Mode()&os.ModeType != 0 {
- // Skip directories, pipes, other non-regular files
- return nil
- }
-