Skip to content

Commit

Permalink
fix: ensure code gen output is not inside template
Browse files Browse the repository at this point in the history
  • Loading branch information
wesbillman committed Nov 7, 2023
1 parent ce54482 commit a7e0887
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/ftl/cmd_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
"time"

"connectrpc.com/connect"
Expand Down Expand Up @@ -91,6 +93,19 @@ func (s *schemaGenerateCmd) Run(ctx context.Context, client ftlv1connect.Control
watch := watcher.New()
defer watch.Close()

absTemplatePath, err := filepath.Abs(s.Template)
if err != nil {
return errors.WithStack(err)
}
absDestPath, err := filepath.Abs(s.Dest)
if err != nil {
return errors.WithStack(err)
}

if strings.HasPrefix(absDestPath, absTemplatePath) {
return fmt.Errorf("destination directory %s must not be inside the template directory %s", absDestPath, absTemplatePath)
}

logger := log.FromContext(ctx)
logger.Infof("Watching %s", s.Template)

Expand Down

0 comments on commit a7e0887

Please sign in to comment.