Commit 6c56c5bd authored by clabby's avatar clabby

Look for largest build info file rather than most recently modified

parent 64dc3554
This diff is collapsed.
...@@ -12,7 +12,6 @@ import ( ...@@ -12,7 +12,6 @@ import (
"regexp" "regexp"
"strings" "strings"
"text/template" "text/template"
"time"
"github.com/ethereum-optimism/optimism/op-bindings/ast" "github.com/ethereum-optimism/optimism/op-bindings/ast"
"github.com/ethereum-optimism/optimism/op-bindings/foundry" "github.com/ethereum-optimism/optimism/op-bindings/foundry"
...@@ -210,7 +209,7 @@ func main() { ...@@ -210,7 +209,7 @@ func main() {
log.Printf("wrote file %s\n", outfile.Name()) log.Printf("wrote file %s\n", outfile.Name())
} }
mostRecentBuildInfo, err := getMostRecentlyModifiedFile(f.ForgeBuildInfo) mostRecentBuildInfo, err := getLargestInDir(f.ForgeBuildInfo)
if err != nil { if err != nil {
log.Fatalf("Error getting most recently modified build info file: %v", err) log.Fatalf("Error getting most recently modified build info file: %v", err)
} }
...@@ -260,10 +259,10 @@ func main() { ...@@ -260,10 +259,10 @@ func main() {
log.Printf("wrote file %s\n", outfile.Name()) log.Printf("wrote file %s\n", outfile.Name())
} }
// getMostRecentlyModifiedFile returns the path of the most recently modified file in the given directory. // getLargestInDir returns the path of the largest file in a directory.
func getMostRecentlyModifiedFile(dirPath string) (string, error) { func getLargestInDir(dirPath string) (string, error) {
var mostRecentFile string var largestFile string
var mostRecentModTime time.Time var largestSize int64
err := filepath.Walk(dirPath, func(path string, info os.FileInfo, err error) error { err := filepath.Walk(dirPath, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
...@@ -272,17 +271,16 @@ func getMostRecentlyModifiedFile(dirPath string) (string, error) { ...@@ -272,17 +271,16 @@ func getMostRecentlyModifiedFile(dirPath string) (string, error) {
// Check if the current path is a regular file and not a directory // Check if the current path is a regular file and not a directory
if !info.IsDir() { if !info.IsDir() {
modTime := info.ModTime() if info.Size() > largestSize {
if modTime.After(mostRecentModTime) { largestFile = path
mostRecentModTime = modTime largestSize = info.Size()
mostRecentFile = path
} }
} }
return nil return nil
}) })
return mostRecentFile, err return largestFile, err
} }
var tmpl = `// Code generated - DO NOT EDIT. var tmpl = `// Code generated - DO NOT EDIT.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment