(definition ModuleDefinition)
| 112 | } |
| 113 | |
| 114 | func (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 | |
| 157 | func (m ModuleManager) rename(source string, target string) error { |
| 158 | return resiliency.RetryN(10, func(attempt int) error { |
no test coverage detected