@@ -109,36 +109,13 @@ func uninstallTool(toolName string) error {
109
109
}
110
110
return fmt .Errorf ("unable to read file %s: %s" , filename , err )
111
111
}
112
- for _ , line := range strings .Split (string (data ), "\n " ) {
113
- line = strings .TrimSuffix (line , ".go-template" )
114
- logging .Debugf ("processing %s" , line )
115
- strippedLine := strings .TrimPrefix (line , "./" )
116
- strippedLine = strings .TrimPrefix (strippedLine , "usr/local/" )
117
- logging .Debugf ("stripped line %s" , strippedLine )
118
- if strippedLine == "" {
119
- continue
120
- }
121
- if strings .HasPrefix (strippedLine , "/" ) {
122
- logging .Warning .Printfln ("Skipping %s because it is not safe to remove" , strippedLine )
123
- continue
124
- }
125
-
126
- prefixedLine := viper .GetString ("prefix" ) + "/" + viper .GetString ("target" ) + "/" + strippedLine
127
- logging .Debugf ("prefixed line %s" , prefixedLine )
128
-
129
- _ , err := os .Lstat (prefixedLine )
130
- if err != nil {
131
- logging .Debugf ("Unable to stat %s: %s" , prefixedLine , err )
132
- continue
133
- }
134
-
135
- err = os .Remove (prefixedLine )
136
- if err != nil {
137
- if uninstallSpinner != nil {
138
- uninstallSpinner .Fail ()
139
- }
140
- return fmt .Errorf ("unable to remove %s: %s" , prefixedLine , err )
112
+ installedFiles := strings .Split (string (data ), "\n " )
113
+ err = uninstallFiles (installedFiles )
114
+ if err != nil {
115
+ if uninstallSpinner != nil {
116
+ uninstallSpinner .Fail ()
141
117
}
118
+ return fmt .Errorf ("unable to uninstall files: %s" , err )
142
119
}
143
120
144
121
} else {
@@ -215,3 +192,34 @@ func uninstallTool(toolName string) error {
215
192
216
193
return nil
217
194
}
195
+
196
+ func uninstallFiles (installedFiles []string ) error {
197
+ for _ , file := range installedFiles {
198
+ logging .Debugf ("processing %s" , file )
199
+
200
+ logging .Debugf ("stripped line %s" , file )
201
+ if file == "" {
202
+ continue
203
+ }
204
+ if strings .HasPrefix (file , "/" ) {
205
+ logging .Warning .Printfln ("Skipping %s because it is not safe to remove" , file )
206
+ continue
207
+ }
208
+
209
+ prefixedFile := viper .GetString ("prefix" ) + "/" + viper .GetString ("target" ) + "/" + file
210
+ logging .Debugf ("prefixed line %s" , prefixedFile )
211
+
212
+ _ , err := os .Lstat (prefixedFile )
213
+ if err != nil {
214
+ logging .Debugf ("Unable to stat %s: %s" , prefixedFile , err )
215
+ continue
216
+ }
217
+
218
+ err = os .Remove (prefixedFile )
219
+ if err != nil {
220
+ return fmt .Errorf ("unable to remove %s: %s" , prefixedFile , err )
221
+ }
222
+ }
223
+
224
+ return nil
225
+ }
0 commit comments