@@ -109,9 +109,12 @@ func checkDirsNested(inputDirs []string) (string, bool) {
109109 return dirs [0 ], true
110110}
111111
112+ // A list of files we created that should be removed after we are done.
113+ var filesToRemove []string
114+
112115// Try to initialize a go.mod file for projects that do not already have one.
113116func initGoModForLegacyProject (path string ) {
114- log .Printf ("Project appears to be a legacy Go project, attempting to initialize go.mod" )
117+ log .Printf ("Project appears to be a legacy Go project, attempting to initialize go.mod in %s \n " , path )
115118
116119 modInit := toolchain .InitModule (path )
117120
@@ -120,6 +123,9 @@ func initGoModForLegacyProject(path string) {
120123 return
121124 }
122125
126+ // Add the go.mod file to a list of files we should remove later.
127+ filesToRemove = append (filesToRemove , filepath .Join (path , "go.mod" ))
128+
123129 modTidy := toolchain .TidyModule (path )
124130 out , err := modTidy .CombinedOutput ()
125131 log .Println (string (out ))
@@ -133,6 +139,18 @@ func initGoModForLegacyProject(path string) {
133139 }
134140}
135141
142+ // Attempts to remove all files that we created.
143+ func RemoveTemporaryExtractorFiles () {
144+ for _ , path := range filesToRemove {
145+ err := os .Remove (path )
146+ if err != nil {
147+ log .Printf ("Unable to remove file we created at %s: %s\n " , path , err .Error ())
148+ }
149+ }
150+
151+ filesToRemove = nil
152+ }
153+
136154// Find all go.work files in the working directory and its subdirectories
137155func findGoWorkFiles () []string {
138156 return util .FindAllFilesWithName ("." , "go.work" , "vendor" )
0 commit comments