diff --git a/cmd/ftl/cmd_schema.go b/cmd/ftl/cmd_schema.go index 5dda1834ce..15469dc3ce 100644 --- a/cmd/ftl/cmd_schema.go +++ b/cmd/ftl/cmd_schema.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "os" + "path/filepath" + "strings" "time" "connectrpc.com/connect" @@ -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)