@@ -43,8 +43,14 @@ func Run(dir, op, modName string, tag int, buildFlags []string) error {
43
43
if err != nil {
44
44
return errors .Wrap (err , "could not load package" )
45
45
}
46
+ ids := map [string ]struct {}{}
47
+ files := map [string ]struct {}{}
46
48
for _ , p := range pkgs {
47
- err = updateImportPath (p , modName , newModPath )
49
+ if _ , ok := ids [p .ID ]; ok {
50
+ continue
51
+ }
52
+ ids [p .ID ] = struct {}{}
53
+ err = updateImportPath (p , modName , newModPath , files )
48
54
if err != nil {
49
55
return err
50
56
}
@@ -127,8 +133,13 @@ func getPrevious(s string) string {
127
133
return strings .Join (ss [:len (ss )- 1 ], "/" ) + "/v" + strconv .Itoa (newV )
128
134
}
129
135
130
- func updateImportPath (p * packages.Package , old , new string ) error {
136
+ func updateImportPath (p * packages.Package , old , new string , files map [ string ] struct {} ) error {
131
137
for _ , syn := range p .Syntax {
138
+ goFileName := p .Fset .File (syn .Pos ()).Name ()
139
+ if _ , ok := files [goFileName ]; ok {
140
+ continue
141
+ }
142
+ files [goFileName ] = struct {}{}
132
143
var rewritten bool
133
144
for _ , i := range syn .Imports {
134
145
imp := strings .Replace (i .Path .Value , `"` , `` , 2 )
@@ -144,7 +155,6 @@ func updateImportPath(p *packages.Package, old, new string) error {
144
155
continue
145
156
}
146
157
147
- goFileName := p .Fset .File (syn .Pos ()).Name ()
148
158
f , err := os .Create (goFileName )
149
159
if err != nil {
150
160
return errors .Wrapf (err , "could not create go file %v" , goFileName )
0 commit comments