Debian Codegraph @

proxy/fuse/fuse_darwin.go

raw
1 // Copyright 2021 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 fuse
16
17 import (
18 "os"
19
20 "github.com/GoogleCloudPlatform/cloudsql-proxy/logging"
21 )
22
23 const (
24 macfusePath = "/Library/Filesystems/macfuse.fs/Contents/Resources/mount_macfuse"
25 osxfusePath = "/Library/Filesystems/osxfuse.fs/Contents/Resources/mount_osxfuse"
26 )
27
28 // Supported checks if macfuse or osxfuse are installed on the host by looking
29 // for both in their known installation location.
30 func Supported() bool {
31 // This code follows the same strategy as hanwen/go-fuse.
32 // See https://github.com/hanwen/go-fuse/blob/0f728ba15b38579efefc3dc47821882ca18ffea7/fuse/mount_darwin.go#L121-L124.
33
34 // check for macfuse first (newer version of osxfuse)
35 if _, err := os.Stat(macfusePath); err != nil {
36 // if that fails, check for osxfuse next
37 if _, err := os.Stat(osxfusePath); err != nil {
38 logging.Errorf("Failed to find osxfuse or macfuse. Verify FUSE installation and try again (see https://osxfuse.github.io).")
39 return false
40 }
41 }
42 return true
43 }