From ef60d54e4e8073338815fd347ee412429a4c5cc6 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Wed, 19 Aug 2015 09:27:10 +1000 Subject: [PATCH 1/3] Include /sbin/mount.fuse.gcsfuse as a symlink in Linux releases. For #116. --- tools/build_release/build.go | 38 +++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/tools/build_release/build.go b/tools/build_release/build.go index 502ff7a6f9..a1d1077bfa 100644 --- a/tools/build_release/build.go +++ b/tools/build_release/build.go @@ -48,7 +48,7 @@ func buildBinaries( }() // Create the target structure. - binDir, helperPath, err := makeTarballDirs(osys, dir) + binDir, helperPaths, err := makeTarballDirs(osys, dir) if err != nil { err = fmt.Errorf("makeTarballDirs: %v", err) return @@ -144,7 +144,7 @@ func buildBinaries( // Copy the mount(8) helper script into place. err = copyFile( - helperPath, + helperPaths[0], path.Join( gopath, fmt.Sprintf( @@ -157,24 +157,45 @@ func buildBinaries( return } + // Symlink any further mount(8) helpers to the first one. + for i := range helperPaths { + if i == 0 { + continue + } + + err = os.Symlink(helperPaths[0], helperPaths[i]) + if err != nil { + err = fmt.Errorf("Symlink: %v", err) + return + } + } + return } // Create the appropriate hierarchy for the tarball, returning the absolute // path of the directory to which the usual binaries should be written and the -// absolute path to which the mount(8) external helper should be written. +// absolute paths to which the mount(8) external helpers should be written. func makeTarballDirs( osys string, - baseDir string) (binDir string, helperPath string, err error) { + baseDir string) (binDir string, helperPaths []string, err error) { // Fill out the return values. switch osys { case "darwin": binDir = path.Join(baseDir, "usr/local/bin") - helperPath = path.Join(baseDir, "sbin/mount_gcsfuse") + helperPaths = append(helperPaths, path.Join(baseDir, "sbin/mount_gcsfuse")) case "linux": binDir = path.Join(baseDir, "usr/bin") - helperPath = path.Join(baseDir, "sbin/mount.gcsfuse") + helperPaths = append(helperPaths, path.Join(baseDir, "sbin/mount.gcsfuse")) + + // Also support `mount -t fuse.gcsfuse`. If there's no explicit helper for + // this type, /sbin/mount.fuse will call the gcsfuse executable directly, + // but it doesn't support the right argument format and doesn't daemonize. + // So we install an explicit helper. + helperPaths = append( + helperPaths, + path.Join(baseDir, "sbin/mount.fuse.gcsfuse")) default: err = fmt.Errorf("Don't know what directories to use for %s", osys) @@ -184,7 +205,10 @@ func makeTarballDirs( // Create the appropriate directories. dirs := []string{ binDir, - path.Dir(helperPath), + } + + for _, hp := range helperPaths { + dirs = append(dirs, path.Dir(hp)) } for _, d := range dirs { From d878da5f8d1419791cc1c6937685f285d67b4cfe Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Wed, 19 Aug 2015 09:37:13 +1000 Subject: [PATCH 2/3] Use a relative path for the target of the symlink. --- tools/build_release/build.go | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/tools/build_release/build.go b/tools/build_release/build.go index a1d1077bfa..814d581bc5 100644 --- a/tools/build_release/build.go +++ b/tools/build_release/build.go @@ -125,7 +125,7 @@ func buildBinaries( "go", "build", "-o", - path.Join(binDir, path.Base(bin)), + path.Join(dir, binDir, path.Base(bin)), bin) cmd.Env = []string{ @@ -144,7 +144,7 @@ func buildBinaries( // Copy the mount(8) helper script into place. err = copyFile( - helperPaths[0], + path.Join(dir, helperPaths[0]), path.Join( gopath, fmt.Sprintf( @@ -163,7 +163,7 @@ func buildBinaries( continue } - err = os.Symlink(helperPaths[0], helperPaths[i]) + err = os.Symlink(helperPaths[0], path.Join(dir, helperPaths[i])) if err != nil { err = fmt.Errorf("Symlink: %v", err) return @@ -173,29 +173,27 @@ func buildBinaries( return } -// Create the appropriate hierarchy for the tarball, returning the absolute +// Create the appropriate hierarchy for the tarball, returning the relative // path of the directory to which the usual binaries should be written and the -// absolute paths to which the mount(8) external helpers should be written. +// relative paths to which the mount(8) external helpers should be written. func makeTarballDirs( osys string, baseDir string) (binDir string, helperPaths []string, err error) { // Fill out the return values. switch osys { case "darwin": - binDir = path.Join(baseDir, "usr/local/bin") - helperPaths = append(helperPaths, path.Join(baseDir, "sbin/mount_gcsfuse")) + binDir = "usr/local/bin" + helperPaths = append(helperPaths, "sbin/mount_gcsfuse") case "linux": - binDir = path.Join(baseDir, "usr/bin") - helperPaths = append(helperPaths, path.Join(baseDir, "sbin/mount.gcsfuse")) + binDir = "usr/bin" + helperPaths = append(helperPaths, "sbin/mount.gcsfuse") // Also support `mount -t fuse.gcsfuse`. If there's no explicit helper for // this type, /sbin/mount.fuse will call the gcsfuse executable directly, // but it doesn't support the right argument format and doesn't daemonize. // So we install an explicit helper. - helperPaths = append( - helperPaths, - path.Join(baseDir, "sbin/mount.fuse.gcsfuse")) + helperPaths = append(helperPaths, "sbin/mount.fuse.gcsfuse") default: err = fmt.Errorf("Don't know what directories to use for %s", osys) @@ -212,7 +210,7 @@ func makeTarballDirs( } for _, d := range dirs { - err = os.MkdirAll(d, 0755) + err = os.MkdirAll(path.Join(baseDir, d), 0755) if err != nil { err = fmt.Errorf("MkdirAll: %v", err) return From 74a9228d00855f67ea153243c0da3b7848bfdc78 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Wed, 19 Aug 2015 09:47:49 +1000 Subject: [PATCH 3/3] Another try: don't include a directory in the symlink target. --- tools/build_release/build.go | 107 +++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 44 deletions(-) diff --git a/tools/build_release/build.go b/tools/build_release/build.go index 814d581bc5..745bfe9e65 100644 --- a/tools/build_release/build.go +++ b/tools/build_release/build.go @@ -48,7 +48,7 @@ func buildBinaries( }() // Create the target structure. - binDir, helperPaths, err := makeTarballDirs(osys, dir) + binDir, helperDir, err := makeTarballDirs(osys, dir) if err != nil { err = fmt.Errorf("makeTarballDirs: %v", err) return @@ -125,7 +125,7 @@ func buildBinaries( "go", "build", "-o", - path.Join(dir, binDir, path.Base(bin)), + path.Join(binDir, path.Base(bin)), bin) cmd.Env = []string{ @@ -143,57 +143,30 @@ func buildBinaries( } // Copy the mount(8) helper script into place. - err = copyFile( - path.Join(dir, helperPaths[0]), - path.Join( - gopath, - fmt.Sprintf( - "src/github.com/googlecloudplatform/gcsfuse/tools/mount_gcsfuse/%s.sh", - osys)), - 0755) - + err = writeMountHelper(osys, gopath, helperDir) if err != nil { - err = fmt.Errorf("Copying mount(8) helper script: %v", err) + err = fmt.Errorf("writeMountHelper: %v", err) return } - // Symlink any further mount(8) helpers to the first one. - for i := range helperPaths { - if i == 0 { - continue - } - - err = os.Symlink(helperPaths[0], path.Join(dir, helperPaths[i])) - if err != nil { - err = fmt.Errorf("Symlink: %v", err) - return - } - } - return } -// Create the appropriate hierarchy for the tarball, returning the relative -// path of the directory to which the usual binaries should be written and the -// relative paths to which the mount(8) external helpers should be written. +// Create the appropriate hierarchy for the tarball, returning the absolute +// paths of the directories to which the usual binaries and the mount(8) +// external helpers should be written. func makeTarballDirs( osys string, - baseDir string) (binDir string, helperPaths []string, err error) { + baseDir string) (binDir string, helperDir string, err error) { // Fill out the return values. switch osys { case "darwin": - binDir = "usr/local/bin" - helperPaths = append(helperPaths, "sbin/mount_gcsfuse") + binDir = path.Join(baseDir, "usr/local/bin") + helperDir = path.Join(baseDir, "sbin") case "linux": - binDir = "usr/bin" - helperPaths = append(helperPaths, "sbin/mount.gcsfuse") - - // Also support `mount -t fuse.gcsfuse`. If there's no explicit helper for - // this type, /sbin/mount.fuse will call the gcsfuse executable directly, - // but it doesn't support the right argument format and doesn't daemonize. - // So we install an explicit helper. - helperPaths = append(helperPaths, "sbin/mount.fuse.gcsfuse") + binDir = path.Join(baseDir, "usr/bin") + helperDir = path.Join(baseDir, "sbin") default: err = fmt.Errorf("Don't know what directories to use for %s", osys) @@ -203,14 +176,11 @@ func makeTarballDirs( // Create the appropriate directories. dirs := []string{ binDir, - } - - for _, hp := range helperPaths { - dirs = append(dirs, path.Dir(hp)) + helperDir, } for _, d := range dirs { - err = os.MkdirAll(path.Join(baseDir, d), 0755) + err = os.MkdirAll(d, 0755) if err != nil { err = fmt.Errorf("MkdirAll: %v", err) return @@ -252,3 +222,52 @@ func copyFile(dst string, src string, perm os.FileMode) (err error) { return } + +// Copy the mount(8) helper(s) into place from $GOPATH. +func writeMountHelper( + osys string, + gopath string, + helperDir string) (err error) { + // Choose the filename. + var filename string + switch osys { + case "darwin": + filename = "mount_gcsfuse" + + case "linux": + filename = "mount.gcsfuse" + + default: + err = fmt.Errorf("Unsupported OS: %q", osys) + return + } + + // Copy the file into place. + err = copyFile( + path.Join(helperDir, filename), + path.Join( + gopath, + fmt.Sprintf( + "src/github.com/googlecloudplatform/gcsfuse/tools/mount_gcsfuse/%s.sh", + osys)), + 0755) + + if err != nil { + err = fmt.Errorf("copyFile: %v", err) + return + } + + // On Linux, also support `mount -t fuse.gcsfuse`. If there's no explicit + // helper for this type, /sbin/mount.fuse will call the gcsfuse executable + // directly, but it doesn't support the right argument format and doesn't + // daemonize. So we install an explicit helper. + if osys == "linux" { + err = os.Symlink("mount.gcsfuse", path.Join(helperDir, "mount.fuse.gcsfuse")) + if err != nil { + err = fmt.Errorf("Symlink: %v", err) + return + } + } + + return +}