MCPcopy Create free account
hub / github.com/UiPath/uipathcli / getModule

Method getModule

plugin/module_manager.go:114–155  ·  view source on GitHub ↗
(definition ModuleDefinition)

Source from the content-addressed store, hash-verified

112}
113
114func (m ModuleManager) getModule(definition ModuleDefinition) (string, error) {
115 moduleDirectory, err := m.moduleDirectory(definition)
116 if err != nil {
117 return "", fmt.Errorf("Could not download %s: %w", definition.Name, err)
118 }
119 path := filepath.Join(moduleDirectory, definition.Executable)
120 if _, err := os.Stat(path); err == nil {
121 return path, nil
122 }
123
124 tmpModuleDirectory := m.createTmpFolder(moduleDirectory, directoryPermissions)
125
126 archivePath := m.findLocalModule(definition)
127
128 nextStep := "extracting... "
129 if archivePath == "" {
130 nextStep = "downloading..."
131 }
132 progressBar := visualization.NewProgressBar(m.Logger)
133 defer progressBar.Remove()
134 progressBar.UpdatePercentage(nextStep, 0)
135
136 if archivePath == "" {
137 archivePath = filepath.Join(tmpModuleDirectory, definition.ArchiveName)
138 defer func() { _ = os.Remove(archivePath) }()
139 err = m.download(definition, archivePath, progressBar)
140 if err != nil {
141 return "", err
142 }
143 }
144
145 archive := newArchive(definition.ArchiveType)
146 err = archive.Extract(archivePath, tmpModuleDirectory, directoryPermissions)
147 if err != nil {
148 return "", fmt.Errorf("Could not extract %s archive: %w", definition.Name, err)
149 }
150 err = m.rename(tmpModuleDirectory, moduleDirectory)
151 if err != nil {
152 return "", fmt.Errorf("Could not install %s: %w", definition.Name, err)
153 }
154 return path, nil
155}
156
157func (m ModuleManager) rename(source string, target string) error {
158 return resiliency.RetryN(10, func(attempt int) error {

Callers 1

GetMethod · 0.95

Calls 10

moduleDirectoryMethod · 0.95
createTmpFolderMethod · 0.95
findLocalModuleMethod · 0.95
RemoveMethod · 0.95
UpdatePercentageMethod · 0.95
downloadMethod · 0.95
renameMethod · 0.95
NewProgressBarFunction · 0.92
newArchiveFunction · 0.85
ExtractMethod · 0.65

Tested by

no test coverage detected