@@ -12,7 +12,6 @@ import (
1212 "strings"
1313
1414 "charm.land/lipgloss/v2"
15- "github.com/kballard/go-shellquote"
1615 "github.com/libops/sitectl/pkg/config"
1716 "github.com/libops/sitectl/pkg/docker"
1817 "github.com/libops/sitectl/pkg/plugin"
@@ -110,7 +109,7 @@ func init() {
110109 componentExtensionCmd .AddCommand (componentExtensionReconcileCmd )
111110 componentExtensionCmd .AddCommand (componentExtensionSetCmd )
112111
113- debugExtensionCmd .Flags ().StringVar (& drupalRootfsPath , "drupal-rootfs" , "drupal/rootfs/var/www/drupal " , "Drupal rootfs path override" )
112+ debugExtensionCmd .Flags ().StringVar (& drupalRootfsPath , "drupal-rootfs" , "" , "Drupal rootfs path override" )
114113}
115114
116115func renderDrupalDebug (runCtx context.Context ) (string , error ) {
@@ -130,8 +129,12 @@ func renderDrupalDebug(runCtx context.Context) (string, error) {
130129 }
131130 defer files .Close ()
132131
133- slog .Debug ("resolving drupal root" , "plugin" , "drupal" , "rootfs" , drupalRootfsPath )
134- drupalRoot := resolveDrupalRoot (files , ctx .ProjectDir , drupalRootfsPath )
132+ rootfs := strings .TrimSpace (drupalRootfsPath )
133+ if rootfs == "" {
134+ rootfs = ctx .EffectiveDrupalRootfs ()
135+ }
136+ slog .Debug ("resolving drupal root" , "plugin" , "drupal" , "rootfs" , rootfs )
137+ drupalRoot := ctx .ResolveProjectPath (rootfs )
135138 slog .Debug ("resolved drupal root" , "plugin" , "drupal" , "drupal_root" , drupalRoot )
136139 configDir := filepath .Join (drupalRoot , "config" , "sync" )
137140 body := []string {
@@ -182,14 +185,14 @@ func renderDrupalDebug(runCtx context.Context) (string, error) {
182185}
183186
184187func renderCachePageSummary (runCtx context.Context ) (string , error ) {
185- _ , cli , containerName , err := getDrupalContainerForSDK (runCtx )
188+ ctx , cli , containerName , err := getDrupalContainerForSDK (runCtx )
186189 if err != nil {
187190 return "" , err
188191 }
189192 defer cli .Close ()
190193
191194 query := "SELECT COALESCE(data_length + index_length, 0) FROM information_schema.TABLES WHERE table_schema = DATABASE() AND table_name = 'cache_page';"
192- output , err := execDrupalCommandCapture (runCtx , cli , containerName , []string {"drush" , "sql:query" , query , "--extra=--batch" , "--extra=--skip-column-names" })
195+ output , err := execDrupalCommandCapture (runCtx , cli , containerName , ctx . EffectiveDrupalContainerRoot (), []string {"drush" , "sql:query" , query , "--extra=--batch" , "--extra=--skip-column-names" })
193196 if err != nil {
194197 return "" , err
195198 }
@@ -234,17 +237,15 @@ func getDrupalContainerForSDK(runCtx context.Context) (ctx *config.Context, cli
234237 return ctx , cli , containerName , nil
235238}
236239
237- func execDrupalCommandCapture (runCtx context.Context , cli * docker.DockerClient , containerName string , cmd []string ) (string , error ) {
240+ func execDrupalCommandCapture (runCtx context.Context , cli * docker.DockerClient , containerName , containerRoot string , cmd []string ) (string , error ) {
238241 slog .Debug (strings .Join (cmd , " " ), "plugin" , "drupal" , "container" , containerName )
239242 var stdout bytes.Buffer
240243 var stderr bytes.Buffer
241244
242- wrappedCmd := []string {"bash" , "-lc" , fmt .Sprintf ("cd /var/www/drupal && %s" , shellquote .Join (cmd ... ))}
243-
244245 exitCode , err := cli .Exec (runCtx , docker.ExecOptions {
245246 Container : containerName ,
246- Cmd : wrappedCmd ,
247- WorkingDir : "/var/www/drupal" ,
247+ Cmd : cmd ,
248+ WorkingDir : containerRoot ,
248249 AttachStdout : true ,
249250 AttachStderr : true ,
250251 Stdout : & stdout ,
@@ -291,26 +292,6 @@ func humanBytes(size int64) string {
291292 return fmt .Sprintf ("%.1f%ciB" , float64 (size )/ float64 (div ), "KMGTPE" [exp ])
292293}
293294
294- func resolveDrupalRoot (files * plugin.FileAccessor , projectDir , drupalRootPath string ) string {
295- candidates := []string {}
296- if trimmed := strings .TrimSpace (drupalRootPath ); trimmed != "" {
297- if filepath .IsAbs (trimmed ) {
298- candidates = append (candidates , filepath .Clean (trimmed ))
299- } else {
300- candidates = append (candidates , filepath .Join (projectDir , trimmed ))
301- }
302- }
303- if strings .TrimSpace (projectDir ) != "" {
304- candidates = append (candidates , projectDir )
305- }
306- for _ , candidate := range candidates {
307- if _ , err := files .ReadFile (filepath .Join (candidate , "config" , "sync" , "core.extension.yml" )); err == nil {
308- return candidate
309- }
310- }
311- return ""
312- }
313-
314295func readCoreExtension (runCtx context.Context , files * plugin.FileAccessor , path string ) ([]string , []string , error ) {
315296 data , err := files .ReadFileContext (runCtx , path )
316297 if err != nil {
0 commit comments