@@ -292,31 +292,12 @@ func main() {
292
292
293
293
if depMode == GoGetWithModules {
294
294
// stat go.mod and go.sum
295
- var beforeGoModFileInfo , beforeGoSumFileInfo os.FileInfo
296
-
297
- beforeGoMod , beforeGoModerr := os .Open ("go.mod" )
298
- if beforeGoModerr == nil {
299
- var beforeGoModStatErr error
300
- beforeGoModFileInfo , beforeGoModStatErr = beforeGoMod .Stat ()
301
- if beforeGoModStatErr != nil {
302
- log .Println ("Failed to stat go.mod before running `go mod tidy -e`" )
303
- }
304
- } else {
305
- log .Println ("Failed to read go.mod before running `go mod tidy -e`" )
295
+ beforeGoModFileInfo , beforeGoModErr := os .Stat ("go.mod" )
296
+ if beforeGoModErr != nil {
297
+ log .Println ("Failed to stat go.mod before running `go mod tidy -e`" )
306
298
}
307
- beforeGoMod .Close ()
308
299
309
- beforeGoSum , beforeGoSumErr := os .Open ("go.sum" )
310
- if beforeGoSumErr == nil {
311
- var beforeGoSumStatErr error
312
- beforeGoSumFileInfo , beforeGoSumStatErr = beforeGoSum .Stat ()
313
- if beforeGoSumStatErr != nil {
314
- log .Println ("Failed to stat go.sum before running `go mod tidy -e`" )
315
- }
316
- }
317
- // don't print a warning if beforeGoSumErr != nil as it may be that the
318
- // file doesn't exist
319
- beforeGoSum .Close ()
300
+ beforeGoSumFileInfo , beforeGoSumErr := os .Stat ("go.sum" )
320
301
321
302
// run `go mod tidy -e`
322
303
res := util .RunCmd (exec .Command ("go" , "mod" , "tidy" , "-e" ))
@@ -325,38 +306,24 @@ func main() {
325
306
log .Println ("Failed to run `go mod tidy -e`" )
326
307
} else {
327
308
if beforeGoModFileInfo != nil {
328
- afterGoMod , afterGoModErr := os .Open ("go.mod" )
309
+ afterGoModFileInfo , afterGoModErr := os .Stat ("go.mod" )
329
310
if afterGoModErr != nil {
330
- log .Println ("Failed to read go.mod after running `go mod tidy -e`" )
331
- } else {
332
- afterGoModFileInfo , afterGoModStatErr := afterGoMod .Stat ()
333
- if afterGoModStatErr != nil {
334
- log .Println ("Failed to stat go.mod after running `go mod tidy -e`" )
335
- } else {
336
- if afterGoModFileInfo .ModTime ().After (beforeGoModFileInfo .ModTime ()) {
337
- // if go.mod has been changed then notify the user
338
- log .Println ("We have run `go mod tidy -e` and it altered go.mod. You may wish to check these changes into version control. " )
339
- }
340
- }
311
+ log .Println ("Failed to stat go.mod after running `go mod tidy -e`" )
312
+ } else if afterGoModFileInfo .ModTime ().After (beforeGoModFileInfo .ModTime ()) {
313
+ // if go.mod has been changed then notify the user
314
+ log .Println ("We have run `go mod tidy -e` and it altered go.mod. You may wish to check these changes into version control. " )
341
315
}
342
- afterGoMod .Close ()
343
316
}
344
317
345
- afterGoSum , afterGoSumErr := os .Open ("go.sum" )
318
+ afterGoSumFileInfo , afterGoSumErr := os .Stat ("go.sum" )
346
319
if afterGoSumErr != nil {
347
- log .Println ("Failed to read go.sum after running `go mod tidy -e`" )
320
+ log .Println ("Failed to stat go.sum after running `go mod tidy -e`" )
348
321
} else {
349
- afterGoSumFileInfo , afterGoSumStatErr := afterGoSum .Stat ()
350
- if afterGoSumStatErr != nil {
351
- log .Println ("Failed to stat go.sum after running `go mod tidy -e`" )
352
- } else {
353
- if beforeGoSumErr != nil || afterGoSumFileInfo .ModTime ().After (beforeGoSumFileInfo .ModTime ()) {
354
- // if go.sum has been changed then notify the user
355
- log .Println ("We have run `go mod tidy -e` and it altered go.sum. You may wish to check these changes into version control. " )
356
- }
322
+ if beforeGoSumErr != nil || afterGoSumFileInfo .ModTime ().After (beforeGoSumFileInfo .ModTime ()) {
323
+ // if go.sum has been changed then notify the user
324
+ log .Println ("We have run `go mod tidy -e` and it altered go.sum. You may wish to check these changes into version control. " )
357
325
}
358
326
}
359
- afterGoSum .Close ()
360
327
361
328
}
362
329
}
0 commit comments