Skip to content

Commit

Permalink
fix: avoid max read size reached error when cmp imported files (#618)
Browse files Browse the repository at this point in the history
The equalfile golang package defaults to max read size of 10**10
bytes unless both files use io.LimitedReader to set an upper bound
on the read.  In stacker import we already stat the two files being
compared and know the actual file size.  This PR constructs two
io.LimitedReader's for each file being compared.

Fixes: #617

Signed-off-by: Ryan Harper <[email protected]>
  • Loading branch information
raharper authored May 9, 2024
1 parent 676060a commit 25b859b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/stacker/import.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package stacker

import (
"io"
"io/fs"
"os"
"path"
Expand Down Expand Up @@ -59,7 +60,11 @@ func filesDiffer(p1 string, info1 os.FileInfo, p2 string, info2 os.FileInfo) (bo
}
defer f2.Close()

eq, err := equalfile.New(nil, equalfile.Options{}).CompareReader(f1, f2)
// use limited reader to prevent the default cap of 10**10 max file size
limf1R := io.LimitReader(f1, info1.Size())
limf2R := io.LimitReader(f2, info2.Size())

eq, err := equalfile.New(nil, equalfile.Options{}).CompareReader(limf1R, limf2R)
if err != nil {
return false, err
}
Expand Down

0 comments on commit 25b859b

Please sign in to comment.