Update default erofs block size on macOS during erofs diff

Use the Linux default rather than the block size from the local macOS
system. The local macOS block size is not relevant as the erofs file
will not be mounted directly on macOS.

Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
Derek McGowan
2025-11-17 14:54:24 -08:00
parent 3b1af30190
commit 01b4c8102b

View File

@@ -22,6 +22,7 @@ import (
"io"
"os"
"path"
"runtime"
"strings"
"time"
@@ -82,6 +83,9 @@ func NewErofsDiffer(store content.Store, opts ...DifferOpt) differ {
opt(d)
}
// Add default block size on darwin if not already specified
d.mkfsExtraOpts = addDefaultMkfsOpts(d.mkfsExtraOpts)
return d
}
@@ -211,3 +215,21 @@ func (rc *readCounter) Read(p []byte) (n int, err error) {
rc.c += int64(n)
return
}
// addDefaultMkfsOpts adds default options for mkfs.erofs
func addDefaultMkfsOpts(mkfsExtraOpts []string) []string {
if runtime.GOOS != "darwin" {
return mkfsExtraOpts
}
// Check if -b argument is already present
for _, opt := range mkfsExtraOpts {
if strings.HasPrefix(opt, "-b") {
return mkfsExtraOpts
}
}
// Add -b4096 as the first option to prevent unusable block
// size from being used on macOS.
return append([]string{"-b4096"}, mkfsExtraOpts...)
}