MCPcopy
hub / github.com/cloudfoundry/cli / Execute

Method Execute

command/common/install_plugin_command.go:77–164  ·  view source on GitHub ↗
([]string)

Source from the content-addressed store, hash-verified

75}
76
77func (cmd InstallPluginCommand) Execute([]string) (err error) {
78 log.WithField("PluginHome", cmd.Config.PluginHome()).Info("making plugin dir")
79
80 var tempPluginDir string
81 tempPluginDir, err = os.MkdirTemp(cmd.Config.PluginHome(), "temp")
82 log.WithField("tempPluginDir", tempPluginDir).Debug("making tempPluginDir dir")
83
84 defer func() {
85 removed := false
86 var removeErr error
87 for i := 0; i < 50; i++ {
88 removeErr = os.RemoveAll(tempPluginDir)
89 if removeErr == nil {
90 removed = true
91 break
92 }
93
94 if os.IsNotExist(err) {
95 removed = true
96 break
97 }
98
99 if _, isPathError := removeErr.(*os.PathError); isPathError {
100 time.Sleep(50 * time.Millisecond)
101 } else {
102 err = removeErr
103 }
104 }
105
106 if !removed {
107 err = removeErr
108 }
109 }()
110
111 if err != nil {
112 return err
113 }
114
115 tempPluginPath, pluginSource, err := cmd.getPluginBinaryAndSource(tempPluginDir)
116 if _, ok := err.(cancelInstall); ok {
117 cmd.UI.DisplayText("Plugin installation cancelled.")
118 return nil
119 } else if err != nil {
120 return err
121 }
122 log.WithFields(log.Fields{"tempPluginPath": tempPluginPath, "pluginSource": pluginSource}).Debug("getPluginBinaryAndSource")
123
124 // copy twice when downloading from a URL to keep Windows specific code
125 // isolated to CreateExecutableCopy
126 executablePath, err := cmd.Actor.CreateExecutableCopy(tempPluginPath, tempPluginDir)
127 if err != nil {
128 return err
129 }
130 log.WithField("executablePath", executablePath).Debug("created executable copy")
131
132 rpcService, err := shared.NewRPCService(cmd.Config, cmd.UI)
133 if err != nil {
134 return err

Callers

nothing calls this directly

Calls 11

uninstallPluginMethod · 0.95
installPluginMethod · 0.95
NewRPCServiceFunction · 0.92
PluginHomeMethod · 0.65
DisplayTextMethod · 0.65
CreateExecutableCopyMethod · 0.65
GetAndValidatePluginMethod · 0.65
BinaryNameMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected