PopulateGlobalCustomCommandFiles sets up the custom command files in the project directories where they need to go.
()
| 14 | // PopulateGlobalCustomCommandFiles sets up the custom command files in the project |
| 15 | // directories where they need to go. |
| 16 | func 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. |
no test coverage detected