func (g Generator) generateFile(lockCtx *fsutil.LockContext, p Paths, pattern string, output string, generateFn generateFn) error {
	tmpFile, err := g.tempFile(p, pattern) // tmp output in case the process ends abruptly
	if err != nil {
		return err
	}

	tmpFn := tmpFile.Name()
	defer func() {
		_ = os.Remove(tmpFn)
	}()

	if err := generateFn(lockCtx, tmpFn); err != nil {
		return err
	}

	if err := fsutil.SafeMove(tmpFn, output); err != nil {
		return fmt.Errorf("moving %s to %s", tmpFn, output)
	}

	return nil
}
// generateFile performs a generate operation by generating a temporary file using p and pattern, then
// moving it to output on success.
generateFile performs a generate operation by generating a temporary file using p and pattern, then
moving it to output on success.
// generateFile performs a generate operation by generating a temporary file using p and pattern then // moving it to output on success .
func (g Generator) generateFile(lockCtx *fsutil.LockContext, p Paths, pattern string, output string, generateFn generateFn) error {
	tmpFile, err := g.tempFile(p, pattern) 
	if err != nil {
		return err
	}
	tmpFn := tmpFile.Name()
	defer func() {
		_ = os.Remove(tmpFn)
	}()
	if err := generateFn(lockCtx, tmpFn); err != nil {
		return err
	}
	if err := fsutil.SafeMove(tmpFn, output); err != nil {
		return fmt.Errorf("moving %s to %s", tmpFn, output)
	}
	return nil
}
func ( g Generator ) generateFile ( lockCtx * fsutil . LockContext , p Paths , pattern string , output string , generateFn generateFn ) error { tmpFile , err := g . tempFile ( p , pattern ) if err != nil { return err } tmpFn := tmpFile . Name ( ) defer func ( ) { _ = os . Remove ( tmpFn ) } ( ) if err := generateFn ( lockCtx , tmpFn ) ; err != nil { return err } if err := fsutil . SafeMove ( tmpFn , output ) ; err != nil { return fmt . Errorf ( " " , tmpFn , output ) } return nil }
generateFile performs a generate operation by generating a temporary file using p and pattern, then
moving it to output on success.
generateFile performs a generate operation by generating a temporary file using p and pattern then moving it to output on success .
// tmp output in case the process ends abruptly