Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: when settings files not set, don't chmod, fixes #5675 #5676

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 21 additions & 19 deletions pkg/ddevapp/apptypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func init() {
},

nodeps.AppTypePHP: {
postStartAction: phpPostStartAction,
postStartAction: nil,
},

nodeps.AppTypePython: {
Expand Down Expand Up @@ -253,27 +253,29 @@ func (app *DdevApp) CreateSettingsFile() (string, error) {
// Drupal and WordPress love to change settings files to be unwriteable.
// Chmod them to something we can work with in the event that they already
// exist.
chmodTargets := []string{filepath.Dir(app.SiteSettingsPath), app.SiteDdevSettingsFile}
for _, fp := range chmodTargets {
fileInfo, err := os.Stat(fp)
if err != nil {
// We're not doing anything about this error other than warning,
// and will have to deal with the same check in settingsCreator.
if !os.IsNotExist(err) {
util.Warning("Unable to ensure write permissions: %v", err)
if app.SiteSettingsPath != "" {
chmodTargets := []string{filepath.Dir(app.SiteSettingsPath), app.SiteDdevSettingsFile}
for _, fp := range chmodTargets {
fileInfo, err := os.Stat(fp)
if err != nil {
// We're not doing anything about this error other than warning,
// and will have to deal with the same check in settingsCreator.
if !os.IsNotExist(err) {
util.Warning("Unable to ensure write permissions: %v", err)
}

continue
}

continue
}

perms := 0644
if fileInfo.IsDir() {
perms = 0755
}
perms := 0644
if fileInfo.IsDir() {
perms = 0755
}

err = os.Chmod(fp, os.FileMode(perms))
if err != nil {
return "", fmt.Errorf("could not change permissions on file %s to make it writeable: %v", fp, err)
err = os.Chmod(fp, os.FileMode(perms))
if err != nil {
return "", fmt.Errorf("could not change permissions on file %s to make it writeable: %v", fp, err)
}
}
}

Expand Down
13 changes: 0 additions & 13 deletions pkg/ddevapp/php.go
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
package ddevapp

import (
"fmt"
)

func phpPostStartAction(app *DdevApp) error {
if !app.DisableSettingsManagement {
if _, err := app.CreateSettingsFile(); err != nil {
return fmt.Errorf("failed to write settings file %s: %v", app.SiteDdevSettingsFile, err)
}
}
return nil
}