func (c Copyright) Walk(ctx context.Context, action Action, root string) error {
	noticeBody, err := c.compileNoticeBodyTemplate(c.NoticeBodyTemplateOrDefault())
	if err != nil {
		return err
	}

	c.Verbosef("using root: %s", root)
	c.Verbosef("using excludes: %s", strings.Join(c.Config.Excludes, ", "))
	c.Verbosef("using include files: %s", strings.Join(c.Config.IncludeFiles, ", "))
	c.Verbosef("using notice body:\n%s", noticeBody)

	// if the root is a file, just handle the file itself
	// otherwise walk the full tree
	if info, err := os.Stat(root); err != nil {
		return err
	} else if !info.IsDir() {
		c.Debugf("root is a file, processing and returning")
		return c.processFile(action, noticeBody, root, info)
	}

	var didFail bool
	err = filepath.Walk(root, func(path string, info os.FileInfo, fileErr error) error {
		if fileErr != nil {
			return fileErr
		}

		if skipErr := c.includeOrExclude(root, path, info); skipErr != nil {
			if skipErr == ErrWalkSkip {
				return nil
			}
			return skipErr
		}

		walkErr := c.processFile(action, noticeBody, path, info)
		if walkErr != nil {
			// if we don't exit on the first failure
			// check if the error is just a verification error
			// if so, mark that we've had a failure
			// and return nil so the walk continues
			if !c.Config.ExitFirstOrDefault() {
				// if it's a sentinel error
				// mark we've failed and return nil
				if walkErr == ErrFailure {
					didFail = true
					return nil
				}

				// this error might be an os issue / something else
				// return it
				return walkErr
			}

			// otherwise always return the error
			// this will abort the walk
			return walkErr
		}

		// no error no problem
		return nil
	})

	// if we had an error
	// return it
	if err != nil {
		return err
	}

	// if we failed at some point, ideally
	// because we're set to not exit first
	// return the sentinel error
	if didFail {
		return ErrFailure
	}
	return nil
}
// Walk traverses the tree recursively from the root and applies the given action.
//
// If the root is a file, it is handled singly and then walk will return.
Walk traverses the tree recursively from the root and applies the given action.

If the root is a file, it is handled singly and then walk will return.
// Walk traverses the tree recursively from the root and applies the given action . // // If the root is a file it is handled singly and then walk will return .
func (c Copyright) Walk(ctx context.Context, action Action, root string) error {
	noticeBody, err := c.compileNoticeBodyTemplate(c.NoticeBodyTemplateOrDefault())
	if err != nil {
		return err
	}
	c.Verbosef("using root: %s", root)
	c.Verbosef("using excludes: %s", strings.Join(c.Config.Excludes, ", "))
	c.Verbosef("using include files: %s", strings.Join(c.Config.IncludeFiles, ", "))
	c.Verbosef("using notice body:\n%s", noticeBody)
	if info, err := os.Stat(root); err != nil {
		return err
	} else if !info.IsDir() {
		c.Debugf("root is a file, processing and returning")
		return c.processFile(action, noticeBody, root, info)
	}
	var didFail bool
	err = filepath.Walk(root, func(path string, info os.FileInfo, fileErr error) error {
		if fileErr != nil {
			return fileErr
		}
		if skipErr := c.includeOrExclude(root, path, info); skipErr != nil {
			if skipErr == ErrWalkSkip {
				return nil
			}
			return skipErr
		}
		walkErr := c.processFile(action, noticeBody, path, info)
		if walkErr != nil {
			if !c.Config.ExitFirstOrDefault() {
				if walkErr == ErrFailure {
					didFail = true
					return nil
				}
				return walkErr
			}
			return walkErr
		}
		return nil
	})
	if err != nil {
		return err
	}
	if didFail {
		return ErrFailure
	}
	return nil
}
func ( c Copyright ) Walk ( ctx context . Context , action Action , root string ) error { noticeBody , err := c . compileNoticeBodyTemplate ( c . NoticeBodyTemplateOrDefault ( ) ) if err != nil { return err } c . Verbosef ( " " , root ) c . Verbosef ( " " , strings . Join ( c . Config . Excludes , " " ) ) c . Verbosef ( " " , strings . Join ( c . Config . IncludeFiles , " " ) ) c . Verbosef ( " \n " , noticeBody ) if info , err := os . Stat ( root ) ; err != nil { return err } else if ! info . IsDir ( ) { c . Debugf ( " " ) return c . processFile ( action , noticeBody , root , info ) } var didFail bool err = filepath . Walk ( root , func ( path string , info os . FileInfo , fileErr error ) error { if fileErr != nil { return fileErr } if skipErr := c . includeOrExclude ( root , path , info ) ; skipErr != nil { if skipErr == ErrWalkSkip { return nil } return skipErr } walkErr := c . processFile ( action , noticeBody , path , info ) if walkErr != nil { if ! c . Config . ExitFirstOrDefault ( ) { if walkErr == ErrFailure { didFail = true return nil } return walkErr } return walkErr } return nil } ) if err != nil { return err } if didFail { return ErrFailure } return nil }
Walk traverses the tree recursively from the root and applies the given action.
Walk traverses the tree recursively from the root and applies the given action .
// if the root is a file, just handle the file itself // otherwise walk the full tree // if we don't exit on the first failure // check if the error is just a verification error // if so, mark that we've had a failure // and return nil so the walk continues // if it's a sentinel error // mark we've failed and return nil // this error might be an os issue / something else // return it // otherwise always return the error // this will abort the walk // no error no problem // if we had an error // return it // if we failed at some point, ideally // because we're set to not exit first // return the sentinel error