GetComposerCreateAllowedPaths gets all paths relative to the app root that are allowed to be present for a given apptype when running ddev composer create-project
()
| 383 | // GetComposerCreateAllowedPaths gets all paths relative to the app root that are allowed to be present |
| 384 | // for a given apptype when running ddev composer create-project |
| 385 | func (app *DdevApp) GetComposerCreateAllowedPaths() ([]string, error) { |
| 386 | var allowed []string |
| 387 | |
| 388 | // doc root |
| 389 | allowed = append(allowed, nodeps.PathWithSlashesToArray(app.GetRelativeDirectory(app.GetDocroot()))...) |
| 390 | |
| 391 | // composer root |
| 392 | allowed = append(allowed, nodeps.PathWithSlashesToArray(app.GetRelativeDirectory(app.GetComposerRoot(false, false)))...) |
| 393 | |
| 394 | // allow upload dirs |
| 395 | // upload dirs are probably always relative and with slashes, but we run |
| 396 | // it through GetRelativeDirectory() just in case. |
| 397 | uploadDirs := app.getUploadDirsRelative() |
| 398 | for _, uploadDir := range uploadDirs { |
| 399 | allowed = append(allowed, nodeps.PathWithSlashesToArray(app.GetRelativeDirectory(uploadDir))...) |
| 400 | } |
| 401 | |
| 402 | // Settings files |
| 403 | allowed = append(allowed, nodeps.PathWithSlashesToArray(app.GetRelativeDirectory(app.SiteSettingsPath))...) |
| 404 | allowed = append(allowed, nodeps.PathWithSlashesToArray(app.GetRelativeDirectory(app.SiteDdevSettingsFile))...) |
| 405 | |
| 406 | // If we have a function to do the settings creation, allow .gitignore |
| 407 | // see CreateSettingsFile |
| 408 | if appFuncs, ok := appTypeMatrix[app.GetType()]; ok && appFuncs.settingsCreator != nil { |
| 409 | // We don't create gitignore if it would be in top-level directory, where |
| 410 | // there is almost certainly already a gitignore (like Backdrop) |
| 411 | if path.Dir(app.SiteSettingsPath) != app.AppRoot { |
| 412 | allowed = append(allowed, nodeps.PathWithSlashesToArray(app.GetRelativeDirectory(filepath.Join(filepath.Dir(app.SiteSettingsPath), ".gitignore")))...) |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | if appFuncs, ok := appTypeMatrix[app.Type]; ok && appFuncs.composerCreateAllowedPaths != nil { |
| 417 | paths, err := appFuncs.composerCreateAllowedPaths(app) |
| 418 | if err != nil { |
| 419 | return []string{""}, err |
| 420 | } |
| 421 | for _, composerPath := range paths { |
| 422 | allowed = append(allowed, nodeps.PathWithSlashesToArray(app.GetRelativeDirectory(composerPath))...) |
| 423 | } |
| 424 | } |
| 425 | allowed = util.SliceToUniqueSlice(&allowed) |
| 426 | sort.Strings(allowed) |
| 427 | return allowed, nil |
| 428 | } |
| 429 | |
| 430 | // SetApptypeSettingsPaths chooses and sets the settings.php/settings.local.php |
| 431 | // and related paths for a given app. |
no test coverage detected