From fd6c44e592fb9c7a4aa640e20caaef555cacb826 Mon Sep 17 00:00:00 2001 From: Eno Compton Date: Mon, 26 Sep 2022 16:02:38 -0600 Subject: [PATCH] fix: restore openbsd and freebsd support Related to #1438. --- internal/proxy/fuse.go | 4 +- .../{proxy_windows.go => fuse_freebsd.go} | 14 +++---- internal/proxy/fuse_openbsd.go | 38 +++++++++++++++++++ internal/proxy/fuse_windows.go | 25 +++++++++++- internal/proxy/proxy_other.go | 11 +----- internal/proxy/unix.go | 27 +++++++++++++ 6 files changed, 98 insertions(+), 21 deletions(-) rename internal/proxy/{proxy_windows.go => fuse_freebsd.go} (72%) create mode 100644 internal/proxy/fuse_openbsd.go create mode 100644 internal/proxy/unix.go diff --git a/internal/proxy/fuse.go b/internal/proxy/fuse.go index 07867a078..251ec4920 100644 --- a/internal/proxy/fuse.go +++ b/internal/proxy/fuse.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !windows -// +build !windows +//go:build !windows && !openbsd && !freebsd +// +build !windows,!openbsd,!freebsd package proxy diff --git a/internal/proxy/proxy_windows.go b/internal/proxy/fuse_freebsd.go similarity index 72% rename from internal/proxy/proxy_windows.go rename to internal/proxy/fuse_freebsd.go index 2f4fe9924..a398e36e9 100644 --- a/internal/proxy/proxy_windows.go +++ b/internal/proxy/fuse_freebsd.go @@ -17,21 +17,17 @@ package proxy import ( "context" "errors" - "path/filepath" - "strings" ) -var errFUSENotSupported = errors.New("FUSE is not supported on Windows") +var errFUSENotSupported = errors.New("FUSE is not supported on FreeBSD") -// UnixAddress returns the Unix socket for a given instance in the provided -// directory, by replacing all colons in the instance's name with periods. -func UnixAddress(dir, inst string) string { - inst2 := strings.ReplaceAll(inst, ":", ".") - return filepath.Join(dir, inst2) +// SupportsFUSE is false on FreeBSD. +func SupportsFUSE() error { + return errFUSENotSupported } type fuseMount struct { - // fuseDir is always an empty string on Windows. + // fuseDir is always an empty string on OpenBSD. fuseDir string } diff --git a/internal/proxy/fuse_openbsd.go b/internal/proxy/fuse_openbsd.go new file mode 100644 index 000000000..cebf80c92 --- /dev/null +++ b/internal/proxy/fuse_openbsd.go @@ -0,0 +1,38 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package proxy + +import ( + "context" + "errors" +) + +var errFUSENotSupported = errors.New("FUSE is not supported on OpenBSD") + +// SupportsFUSE is false on OpenBSD. +func SupportsFUSE() error { + return errFUSENotSupported +} + +type fuseMount struct { + // fuseDir is always an empty string on OpenBSD. + fuseDir string +} + +func configureFUSE(c *Client, conf *Config) (*Client, error) { return nil, errFUSENotSupported } +func (c *Client) fuseMounts() []*socketMount { return nil } +func (c *Client) serveFuse(ctx context.Context, notify func()) error { return errFUSENotSupported } +func (c *Client) unmountFUSE() error { return nil } +func (c *Client) waitForFUSEMounts() {} diff --git a/internal/proxy/fuse_windows.go b/internal/proxy/fuse_windows.go index 6e5289cf4..dd1e3b265 100644 --- a/internal/proxy/fuse_windows.go +++ b/internal/proxy/fuse_windows.go @@ -15,10 +15,33 @@ package proxy import ( + "context" "errors" + "path/filepath" + "strings" ) +var errFUSENotSupported = errors.New("FUSE is not supported on Windows") + // SupportsFUSE is false on Windows. func SupportsFUSE() error { - return errors.New("fuse is not supported on Windows") + return errFUSENotSupported +} + +// UnixAddress returns the Unix socket for a given instance in the provided +// directory, by replacing all colons in the instance's name with periods. +func UnixAddress(dir, inst string) string { + inst2 := strings.ReplaceAll(inst, ":", ".") + return filepath.Join(dir, inst2) } + +type fuseMount struct { + // fuseDir is always an empty string on Windows. + fuseDir string +} + +func configureFUSE(c *Client, conf *Config) (*Client, error) { return nil, errFUSENotSupported } +func (c *Client) fuseMounts() []*socketMount { return nil } +func (c *Client) serveFuse(ctx context.Context, notify func()) error { return errFUSENotSupported } +func (c *Client) unmountFUSE() error { return nil } +func (c *Client) waitForFUSEMounts() {} diff --git a/internal/proxy/proxy_other.go b/internal/proxy/proxy_other.go index 61bc1273f..e08f826d7 100644 --- a/internal/proxy/proxy_other.go +++ b/internal/proxy/proxy_other.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !windows -// +build !windows +//go:build !windows && !openbsd && !freebsd +// +build !windows,!openbsd,!freebsd package proxy @@ -29,13 +29,6 @@ import ( "github.com/hanwen/go-fuse/v2/fuse" ) -// UnixAddress is defined as a function to distinguish between Linux-based -// implementations where the dir and inst and simply joins, and Windows-based -// implementations where the inst must be further altered. -func UnixAddress(dir, inst string) string { - return filepath.Join(dir, inst) -} - type socketSymlink struct { socket *socketMount symlink *symlink diff --git a/internal/proxy/unix.go b/internal/proxy/unix.go new file mode 100644 index 000000000..782b6691e --- /dev/null +++ b/internal/proxy/unix.go @@ -0,0 +1,27 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build !windows +// +build !windows + +package proxy + +import "path/filepath" + +// UnixAddress is defined as a function to distinguish between Linux-based +// implementations where the dir and inst and simply joins, and Windows-based +// implementations where the inst must be further altered. +func UnixAddress(dir, inst string) string { + return filepath.Join(dir, inst) +}