From 483bc44bb6e14173e479f9a216bdf493a9f993ad Mon Sep 17 00:00:00 2001 From: deadprogram Date: Thu, 22 Aug 2024 18:08:07 +0200 Subject: [PATCH] fix: add wrapper for osfile.Truncate function to restore ability to build wazero bare metal using TinyGo 0.33 Signed-off-by: deadprogram --- internal/sysfs/osfile.go | 2 +- internal/sysfs/truncate.go | 9 +++++++++ internal/sysfs/truncate_tinygo.go | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 internal/sysfs/truncate.go create mode 100644 internal/sysfs/truncate_tinygo.go diff --git a/internal/sysfs/osfile.go b/internal/sysfs/osfile.go index 490f0fa681..1930f3c796 100644 --- a/internal/sysfs/osfile.go +++ b/internal/sysfs/osfile.go @@ -254,7 +254,7 @@ func (f *osFile) Pwrite(buf []byte, off int64) (n int, errno experimentalsys.Err // Truncate implements the same method as documented on sys.File func (f *osFile) Truncate(size int64) (errno experimentalsys.Errno) { - if errno = experimentalsys.UnwrapOSError(f.file.Truncate(size)); errno != 0 { + if errno = experimentalsys.UnwrapOSError(truncate(f.file, size)); errno != 0 { // Defer validation overhead until we've already had an error. errno = fileError(f, f.closed, errno) } diff --git a/internal/sysfs/truncate.go b/internal/sysfs/truncate.go new file mode 100644 index 0000000000..44a27202b1 --- /dev/null +++ b/internal/sysfs/truncate.go @@ -0,0 +1,9 @@ +//go:build !tinygo + +package sysfs + +import "os" + +func truncate(file *os.File, size int64) error { + return file.Truncate(size) +} diff --git a/internal/sysfs/truncate_tinygo.go b/internal/sysfs/truncate_tinygo.go new file mode 100644 index 0000000000..1bd36f9a54 --- /dev/null +++ b/internal/sysfs/truncate_tinygo.go @@ -0,0 +1,9 @@ +//go:build tinygo + +package sysfs + +import "os" + +func truncate(file *os.File, size int64) error { + return nil +}