MCPcopy Index your code
hub / github.com/ddev/ddev / writeWordpressDdevSettingsFile

Function writeWordpressDdevSettingsFile

pkg/ddevapp/wordpress.go:178–209  ·  view source on GitHub ↗

writeWordpressDdevSettingsFile unconditionally creates the file that contains ddev-specific settings.

(filePath string)

Source from the content-addressed store, hash-verified

176
177// writeWordpressDdevSettingsFile unconditionally creates the file that contains ddev-specific settings.
178func writeWordpressDdevSettingsFile(filePath string) error {
179 if fileutil.FileExists(filePath) {
180 // Check if the file is managed by ddev.
181 signatureFound, err := fileutil.FgrepStringInFile(filePath, nodeps.DdevFileSignature)
182 if err != nil {
183 return err
184 }
185
186 // If the signature wasn't found, warn the user and return.
187 if !signatureFound {
188 util.Warning("%s already exists and is managed by the user.", filepath.Base(filePath))
189 return nil
190 }
191 }
192
193 content, err := bundledAssets.ReadFile("wordpress/wp-config-ddev.php")
194 if err != nil {
195 return err
196 }
197
198 // Ensure target directory exists and is writable
199 dir := filepath.Dir(filePath)
200 if err = util.Chmod(dir, 0755); os.IsNotExist(err) {
201 if err = os.MkdirAll(dir, 0755); err != nil {
202 return err
203 }
204 } else if err != nil {
205 return err
206 }
207
208 return os.WriteFile(filePath, content, 0644)
209}
210
211// setWordpressSiteSettingsPaths sets the expected settings files paths for
212// a WordPress site.

Callers 1

Calls 4

FileExistsFunction · 0.92
FgrepStringInFileFunction · 0.92
WarningFunction · 0.92
ChmodFunction · 0.92

Tested by

no test coverage detected