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

Function PopulateGlobalCustomCommandFiles

pkg/ddevapp/commands.go:16–44  ·  view source on GitHub ↗

PopulateGlobalCustomCommandFiles sets up the custom command files in the project directories where they need to go.

()

Source from the content-addressed store, hash-verified

14// PopulateGlobalCustomCommandFiles sets up the custom command files in the project
15// directories where they need to go.
16func PopulateGlobalCustomCommandFiles() error {
17 sourceGlobalCommandPath := filepath.Join(globalconfig.GetGlobalDdevDir(), "commands")
18 err := os.MkdirAll(sourceGlobalCommandPath, 0755)
19 if err != nil {
20 return nil
21 }
22
23 // Remove contents of the directory, if the directory exists and has some contents
24 commandDirInVolume := "/mnt/ddev-global-cache/global-commands/"
25 _, _, err = performTaskInContainer([]string{"rm", "-rf", commandDirInVolume})
26 if err != nil {
27 return fmt.Errorf("unable to rm %s: %v", commandDirInVolume, err)
28 }
29
30 // Copy commands into container (this will create the directory if it's not there already)
31 uid, _, _ := dockerutil.GetContainerUser()
32 err = dockerutil.CopyIntoVolume(sourceGlobalCommandPath, "ddev-global-cache", "global-commands", uid, "host", false)
33 if err != nil {
34 return err
35 }
36
37 // Make sure all commands can be executed
38 _, stderr, err := performTaskInContainer([]string{"sh", "-c", "chmod -R u+rwx " + commandDirInVolume})
39 if err != nil {
40 return fmt.Errorf("unable to chmod %s: %v (stderr=%s)", commandDirInVolume, err, stderr)
41 }
42
43 return nil
44}
45
46// performTaskInContainer runs a command in the web container if it's available,
47// but uses an anonymous container otherwise.

Callers 2

StartMethod · 0.85

Calls 5

GetGlobalDdevDirFunction · 0.92
GetContainerUserFunction · 0.92
CopyIntoVolumeFunction · 0.92
performTaskInContainerFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected