in tools/mount_gcsfuse/main.go [223:298]
func run(args []string) (err error) {
// If invoked with a single "--help" argument, print a usage message and exit
// successfully.
if len(args) == 2 && args[1] == "--help" {
fmt.Fprintf(
os.Stderr,
"Usage: %s [-o options] bucket_name mount_point\n",
args[0])
return
}
// Find the path to gcsfuse.
gcsfusePath, err := findGcsfuse()
if err != nil {
err = fmt.Errorf("findGcsfuse: %w", err)
return
}
// Find the path to fusermount.
fusermountPath, err := findFusermount()
if err != nil {
err = fmt.Errorf("findFusermount: %w", err)
return
}
// Attempt to parse arguments.
device, mountPoint, opts, err := parseArgs(args)
if err != nil {
err = fmt.Errorf("parseArgs: %w", err)
return
}
// Choose gcsfuse args.
gcsfuseArgs, err := makeGcsfuseArgs(device, mountPoint, opts)
if err != nil {
err = fmt.Errorf("makeGcsfuseArgs: %w", err)
return
}
fmt.Fprintf(
os.Stderr,
"Calling gcsfuse with arguments: %s\n",
strings.Join(gcsfuseArgs, " "))
// Run gcsfuse.
cmd := exec.Command(gcsfusePath, gcsfuseArgs...)
cmd.Env = append(cmd.Env, fmt.Sprintf("PATH=%s", path.Dir(fusermountPath)))
// Pass through the https_proxy/http_proxy environment variable,
// in case the host requires a proxy server to reach the GCS endpoint.
// http_proxy has precedence over http_proxy, in case both are set
if p, ok := os.LookupEnv("https_proxy"); ok {
cmd.Env = append(cmd.Env, fmt.Sprintf("https_proxy=%s", p))
} else if p, ok := os.LookupEnv("http_proxy"); ok {
cmd.Env = append(cmd.Env, fmt.Sprintf("http_proxy=%s", p))
}
// Pass through the no_proxy enviroment variable. Whenever
// using the http(s)_proxy environment variables. This should
// also be included to know for which hosts the use of proxies
// should be ignored.
if p, ok := os.LookupEnv("no_proxy"); ok {
cmd.Env = append(cmd.Env, fmt.Sprintf("no_proxy=%s", p))
}
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
err = fmt.Errorf("running gcsfuse: %w", err)
return
}
return
}