From 672a3cf01d5dc1c91308342963b5c65bfc79b2e5 Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Fri, 21 Oct 2022 11:15:07 +0200 Subject: [PATCH 1/2] Fix c&p typo in issues_test.go NewFileSerialPortAttachment was mistakenly used in the 'NewSharedDirectory' test --- issues_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/issues_test.go b/issues_test.go index 95eb3fa..968b777 100644 --- a/issues_test.go +++ b/issues_test.go @@ -99,7 +99,7 @@ func TestIssue43(t *testing.T) { return err }, "NewSharedDirectory": func() error { - _, err := NewFileSerialPortAttachment(doesNotExists, false) + _, err := NewSharedDirectory(doesNotExists, false) return err }, "NewDiskImageStorageDeviceAttachment": func() error { @@ -113,7 +113,7 @@ func TestIssue43(t *testing.T) { if err == nil { t.Fatal("expected returns error") } - if !errors.Is(err, os.ErrNotExist) { + if !errors.Is(err, ErrUnsupportedOSVersion) && !errors.Is(err, os.ErrNotExist) { t.Errorf("want underlying error %q but got %q", os.ErrNotExist, err) } }) From 0842149a5932c8684f7461d977612361ed5213f4 Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Fri, 21 Oct 2022 10:39:13 +0200 Subject: [PATCH 2/2] console: Don't return error for non-existing files When using NewFileSerialPortAttachment(), the virtualization framework will create the log file if it does not exist yet. If a directory in the path is invalid, an error will be returned by the virtualization framework, not an exception.This means we don't need to check this in Code-Hex/vz. This commit removes the file existence check which was added in commit 117c12a. This fixes https://github.com/Code-Hex/vz/issues/84 --- console.go | 3 --- issues_test.go | 5 ----- 2 files changed, 8 deletions(-) diff --git a/console.go b/console.go index 9085d8f..1c81441 100644 --- a/console.go +++ b/console.go @@ -88,9 +88,6 @@ func NewFileSerialPortAttachment(path string, shouldAppend bool) (*FileSerialPor if macosMajorVersionLessThan(11) { return nil, ErrUnsupportedOSVersion } - if _, err := os.Stat(path); err != nil { - return nil, err - } cpath := charWithGoString(path) defer cpath.Free() diff --git a/issues_test.go b/issues_test.go index 968b777..f7c48c4 100644 --- a/issues_test.go +++ b/issues_test.go @@ -93,11 +93,6 @@ func TestIssue43(t *testing.T) { }) cases := map[string]func() error{ - // This is also fixed issue #71 - "NewFileSerialPortAttachment": func() error { - _, err := NewFileSerialPortAttachment(doesNotExists, false) - return err - }, "NewSharedDirectory": func() error { _, err := NewSharedDirectory(doesNotExists, false) return err