Skip to content

Commit c53f14e

Browse files
authored
fix: restore openbsd and freebsd support (GoogleCloudPlatform#191)
This is a port of GoogleCloudPlatform/cloud-sql-proxy#1442
1 parent 3347d3b commit c53f14e

File tree

7 files changed

+110
-21
lines changed

7 files changed

+110
-21
lines changed

.github/workflows/tests.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ on:
2424
- cron: '0 2 * * *'
2525

2626
jobs:
27+
compilation:
28+
if: "${{ (github.event.action != 'labeled' && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name) || github.event.label.name == 'tests: run' }}"
29+
name: FreeBSD and OpenBSD compilation check
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout code
33+
uses: 'actions/checkout@v3'
34+
35+
- name: Verify FreeBSD and OpenBSD Builds
36+
run: |
37+
CGO_ENABLED=0 GOOS=freebsd go build
38+
CGO_ENABLED=0 GOOS=openbsd go build
2739
integration:
2840
# run job on proper workflow event triggers (skip job for pull_request event from forks and only run pull_request_target for "tests: run" label)
2941
if: "${{ (github.event.action != 'labeled' && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name) || github.event.label.name == 'tests: run' }}"

internal/proxy/fuse.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
//go:build !windows
16-
// +build !windows
15+
//go:build !windows && !openbsd && !freebsd
16+
// +build !windows,!openbsd,!freebsd
1717

1818
package proxy
1919

internal/proxy/proxy_windows.go renamed to internal/proxy/fuse_freebsd.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,17 @@ package proxy
1717
import (
1818
"context"
1919
"errors"
20-
"path/filepath"
21-
"strings"
2220
)
2321

24-
var errFUSENotSupported = errors.New("FUSE is not supported on Windows")
22+
var errFUSENotSupported = errors.New("FUSE is not supported on FreeBSD")
2523

26-
// UnixAddress returns the Unix socket for a given instance in the provided
27-
// directory, by replacing all colons in the instance's name with periods.
28-
func UnixAddress(dir, inst string) string {
29-
inst2 := strings.ReplaceAll(inst, ":", ".")
30-
return filepath.Join(dir, inst2)
24+
// SupportsFUSE is false on FreeBSD.
25+
func SupportsFUSE() error {
26+
return errFUSENotSupported
3127
}
3228

3329
type fuseMount struct {
34-
// fuseDir is always an empty string on Windows.
30+
// fuseDir is always an empty string on FreeBSD.
3531
fuseDir string
3632
}
3733

internal/proxy/fuse_openbsd.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package proxy
16+
17+
import (
18+
"context"
19+
"errors"
20+
)
21+
22+
var errFUSENotSupported = errors.New("FUSE is not supported on OpenBSD")
23+
24+
// SupportsFUSE is false on OpenBSD.
25+
func SupportsFUSE() error {
26+
return errFUSENotSupported
27+
}
28+
29+
type fuseMount struct {
30+
// fuseDir is always an empty string on OpenBSD.
31+
fuseDir string
32+
}
33+
34+
func configureFUSE(c *Client, conf *Config) (*Client, error) { return nil, errFUSENotSupported }
35+
func (c *Client) fuseMounts() []*socketMount { return nil }
36+
func (c *Client) serveFuse(ctx context.Context, notify func()) error { return errFUSENotSupported }
37+
func (c *Client) unmountFUSE() error { return nil }
38+
func (c *Client) waitForFUSEMounts() {}

internal/proxy/fuse_windows.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,33 @@
1515
package proxy
1616

1717
import (
18+
"context"
1819
"errors"
20+
"path/filepath"
21+
"strings"
1922
)
2023

24+
var errFUSENotSupported = errors.New("FUSE is not supported on Windows")
25+
2126
// SupportsFUSE is false on Windows.
2227
func SupportsFUSE() error {
23-
return errors.New("fuse is not supported on Windows")
28+
return errFUSENotSupported
29+
}
30+
31+
// UnixAddress returns the Unix socket for a given instance in the provided
32+
// directory, by replacing all colons in the instance's name with periods.
33+
func UnixAddress(dir, inst string) string {
34+
inst2 := strings.ReplaceAll(inst, ":", ".")
35+
return filepath.Join(dir, inst2)
2436
}
37+
38+
type fuseMount struct {
39+
// fuseDir is always an empty string on Windows.
40+
fuseDir string
41+
}
42+
43+
func configureFUSE(c *Client, conf *Config) (*Client, error) { return nil, errFUSENotSupported }
44+
func (c *Client) fuseMounts() []*socketMount { return nil }
45+
func (c *Client) serveFuse(ctx context.Context, notify func()) error { return errFUSENotSupported }
46+
func (c *Client) unmountFUSE() error { return nil }
47+
func (c *Client) waitForFUSEMounts() {}

internal/proxy/proxy_other.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
//go:build !windows
16-
// +build !windows
15+
//go:build !windows && !openbsd && !freebsd
16+
// +build !windows,!openbsd,!freebsd
1717

1818
package proxy
1919

@@ -29,13 +29,6 @@ import (
2929
"github.com/hanwen/go-fuse/v2/fuse"
3030
)
3131

32-
// UnixAddress is defined as a function to distinguish between Linux-based
33-
// implementations where the dir and inst and simply joins, and Windows-based
34-
// implementations where the inst must be further altered.
35-
func UnixAddress(dir, inst string) string {
36-
return filepath.Join(dir, inst)
37-
}
38-
3932
type socketSymlink struct {
4033
socket *socketMount
4134
symlink *symlink

internal/proxy/unix.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build !windows
16+
// +build !windows
17+
18+
package proxy
19+
20+
import "path/filepath"
21+
22+
// UnixAddress is defined as a function to distinguish between Unix-based
23+
// implementations where the dir and inst are simply joined, and Windows-based
24+
// implementations where the inst must be further altered.
25+
func UnixAddress(dir, inst string) string {
26+
return filepath.Join(dir, inst)
27+
}

0 commit comments

Comments
 (0)